Anope IRC Services  Version 2.0
webcpanel.cpp
Go to the documentation of this file.
1 /*
2  * (C) 2003-2014 Anope Team
3  * Contact us at team@anope.org
4  *
5  * Please read COPYING and README for further details.
6  */
7 
8 #include "webcpanel.h"
9 
12 
13 class ModuleWebCPanel : public Module
14 {
18 
20 
25 
30 
37 
39 
41 
43 
44 
45  public:
46  ModuleWebCPanel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR),
47  panel(this, "webcpanel"), id(this, "webcpanel_id"), ip(this, "webcpanel_ip"),
48  style_css("style.css", "/static/style.css", "text/css"), logo_png("logo.png", "/static/logo.png", "image/png"), cubes_png("cubes.png", "/static/cubes.png", "image/png"), favicon_ico("favicon.ico", "/favicon.ico", "image/x-icon"),
49  index("/"), logout("/logout"), _register("/register"), confirm("/confirm"),
50  nickserv_info("NickServ", "/nickserv/info"), nickserv_cert("NickServ", "/nickserv/cert"), nickserv_access("NickServ", "/nickserv/access"), nickserv_alist("NickServ", "/nickserv/alist"),
51  chanserv_info("ChanServ", "/chanserv/info"), chanserv_set("ChanServ", "/chanserv/set"), chanserv_access("ChanServ", "/chanserv/access"), chanserv_akick("ChanServ", "/chanserv/akick"),
52  chanserv_modes("ChanServ", "/chanserv/modes"), chanserv_drop("ChanServ", "/chanserv/drop"), memoserv_memos("MemoServ", "/memoserv/memos"), hostserv_request("HostServ", "/hostserv/request"),
53  operserv_akill("OperServ", "/operserv/akill")
54  {
55 
56  me = this;
57 
58  Configuration::Block *block = Config->GetModule(this);
59  provider_name = block->Get<const Anope::string>("server", "httpd/main");
60  template_name = block->Get<const Anope::string>("template", "default");
61  template_base = Anope::DataDir + "/modules/webcpanel/templates/" + template_name;
62  page_title = block->Get<const Anope::string>("title", "Anope IRC Services");
63 
64  provider = ServiceReference<HTTPProvider>("HTTPProvider", provider_name);
65  if (!provider)
66  throw ModuleException("Unable to find HTTPD provider. Is m_httpd loaded?");
67 
68  provider->RegisterPage(&this->style_css);
69  provider->RegisterPage(&this->logo_png);
70  provider->RegisterPage(&this->cubes_png);
71  provider->RegisterPage(&this->favicon_ico);
72 
73  provider->RegisterPage(&this->index);
74  provider->RegisterPage(&this->logout);
75  provider->RegisterPage(&this->_register);
76  provider->RegisterPage(&this->confirm);
77 
78  BotInfo *NickServ = Config->GetClient("NickServ");
79  if (NickServ)
80  {
81  Section s;
82  s.name = NickServ->nick;
83 
84  SubSection ss;
85  ss.name = "Information";
86  ss.url = "/nickserv/info";
87  s.subsections.push_back(ss);
88  provider->RegisterPage(&this->nickserv_info);
89 
90  if (IRCD && IRCD->CanCertFP)
91  {
92  ss.name = "SSL Certificates";
93  ss.url = "/nickserv/cert";
94  s.subsections.push_back(ss);
95  provider->RegisterPage(&this->nickserv_cert);
96  }
97 
98  ss.name = "Access";
99  ss.url = "/nickserv/access";
100  s.subsections.push_back(ss);
101  provider->RegisterPage(&this->nickserv_access);
102 
103  ss.name = "AList";
104  ss.url = "/nickserv/alist";
105  s.subsections.push_back(ss);
106  provider->RegisterPage(&this->nickserv_alist);
107 
108  panel.sections.push_back(s);
109  }
110 
111  BotInfo *ChanServ = Config->GetClient("ChanServ");
112  if (ChanServ)
113  {
114  Section s;
115  s.name = ChanServ->nick;
116 
117  SubSection ss;
118  ss.name = "Channels";
119  ss.url = "/chanserv/info";
120  s.subsections.push_back(ss);
121  provider->RegisterPage(&this->chanserv_info);
122 
123  ss.name = "Settings";
124  ss.url = "/chanserv/set";
125  s.subsections.push_back(ss);
126  provider->RegisterPage(&this->chanserv_set);
127 
128  ss.name = "Access";
129  ss.url = "/chanserv/access";
130  s.subsections.push_back(ss);
131  provider->RegisterPage(&this->chanserv_access);
132 
133  ss.name = "Akick";
134  ss.url = "/chanserv/akick";
135  s.subsections.push_back(ss);
136  provider->RegisterPage(&this->chanserv_akick);
137 
138  ss.name = "Modes";
139  ss.url = "/chanserv/modes";
140  s.subsections.push_back(ss);
141  provider->RegisterPage(&this->chanserv_modes);
142 
143  ss.name = "Drop";
144  ss.url = "/chanserv/drop";
145  s.subsections.push_back(ss);
146  provider->RegisterPage(&this->chanserv_drop);
147 
148  panel.sections.push_back(s);
149  }
150 
151  BotInfo *MemoServ = Config->GetClient("MemoServ");
152  if (MemoServ)
153  {
154  Section s;
155  s.name = MemoServ->nick;
156 
157  SubSection ss;
158  ss.name = "Memos";
159  ss.url = "/memoserv/memos";
160  s.subsections.push_back(ss);
161  provider->RegisterPage(&this->memoserv_memos);
162 
163  panel.sections.push_back(s);
164  }
165 
166  BotInfo *HostServ = Config->GetClient("HostServ");
167  if (HostServ)
168  {
169  Section s;
170  s.name = HostServ->nick;
171 
172  SubSection ss;
173  ss.name = "vHost Request";
174  ss.url = "/hostserv/request";
175  s.subsections.push_back(ss);
176  provider->RegisterPage(&this->hostserv_request);
177 
178  panel.sections.push_back(s);
179  }
180 
181  BotInfo *OperServ = Config->GetClient("OperServ");
182  if (OperServ)
183  {
184  Section s;
185  s.name = OperServ->nick;
186 
187  SubSection ss;
188  ss.name = "Akill";
189  ss.url = "/operserv/akill";
190  s.subsections.push_back(ss);
191  provider->RegisterPage(&this->operserv_akill);
192 
193  panel.sections.push_back(s);
194  }
195  }
196 
198  {
199  if (provider)
200  {
201  provider->UnregisterPage(&this->style_css);
202  provider->UnregisterPage(&this->logo_png);
203  provider->UnregisterPage(&this->cubes_png);
204  provider->UnregisterPage(&this->favicon_ico);
205 
206  provider->UnregisterPage(&this->index);
207  provider->UnregisterPage(&this->logout);
208  provider->UnregisterPage(&this->_register);
209  provider->UnregisterPage(&this->confirm);
210 
211  provider->UnregisterPage(&this->nickserv_info);
212  provider->UnregisterPage(&this->nickserv_cert);
213  provider->UnregisterPage(&this->nickserv_access);
214  provider->UnregisterPage(&this->nickserv_alist);
215 
216  provider->UnregisterPage(&this->chanserv_info);
217  provider->UnregisterPage(&this->chanserv_set);
218  provider->UnregisterPage(&this->chanserv_access);
219  provider->UnregisterPage(&this->chanserv_akick);
220  provider->UnregisterPage(&this->chanserv_modes);
221  provider->UnregisterPage(&this->chanserv_drop);
222 
223  provider->UnregisterPage(&this->memoserv_memos);
224 
225  provider->UnregisterPage(&this->hostserv_request);
226 
227  provider->UnregisterPage(&this->operserv_akill);
228  }
229  }
230 };
231 
232 namespace WebPanel
233 {
234  void RunCommand(const Anope::string &user, NickCore *nc, const Anope::string &service, const Anope::string &c, const std::vector<Anope::string> &params, TemplateFileServer::Replacements &r, const Anope::string &key)
235  {
236  ServiceReference<Command> cmd("Command", c);
237  if (!cmd)
238  {
239  r[key] = "Unable to find command " + c;
240  return;
241  }
242 
243  if (params.size() < cmd->min_params)
244  return;
245 
246  BotInfo *bi = Config->GetClient(service);
247  if (!bi)
248  {
249  if (BotListByNick->empty())
250  return;
251  bi = BotListByNick->begin()->second; // Pick one...
252  }
253 
254  struct MyComandReply : CommandReply
255  {
257  const Anope::string &k;
258 
259  MyComandReply(TemplateFileServer::Replacements &_r, const Anope::string &_k) : re(_r), k(_k) { }
260 
261  void SendMessage(BotInfo *source, const Anope::string &msg) anope_override
262  {
263  re[k] = msg;
264  }
265  }
266  my_reply(r, key);
267 
268  CommandSource source(user, NULL, nc, &my_reply, bi);
269 
270  if (!cmd->AllowUnregistered() && !source.nc)
271  {
272  r[key] = "Access denied.";
273  return;
274  }
275 
276  cmd->Execute(source, params);
277  }
278 }
279 
Definition: bots.h:24
Anope::string template_name
Definition: webcpanel.cpp:11
WebCPanel::Confirm confirm
Definition: webcpanel.cpp:24
ModuleWebCPanel(const Anope::string &modname, const Anope::string &creator)
Definition: webcpanel.cpp:46
StaticFileServer cubes_png
Definition: webcpanel.cpp:19
Anope::string name
Definition: webcpanel.h:26
WebCPanel::Index index
Definition: webcpanel.cpp:21
WebCPanel::OperServ::Akill operserv_akill
Definition: webcpanel.cpp:42
void AllowUnregistered(bool b)
Definition: command.cpp:164
WebCPanel::NickServ::Info nickserv_info
Definition: webcpanel.cpp:26
virtual void Execute(CommandSource &source, const std::vector< Anope::string > &params)=0
Anope::string template_base
Definition: webcpanel.cpp:11
size_t min_params
Definition: commands.h:105
WebCPanel::ChanServ::Modes chanserv_modes
Definition: webcpanel.cpp:35
Anope::string url
Definition: webcpanel.h:21
WebCPanel::NickServ::Cert nickserv_cert
Definition: webcpanel.cpp:27
Module * me
Definition: webcpanel.cpp:10
StaticFileServer favicon_ico
Definition: webcpanel.cpp:19
PrimitiveExtensibleItem< Anope::string > id
Definition: webcpanel.cpp:17
WebCPanel::ChanServ::Info chanserv_info
Definition: webcpanel.cpp:31
Definition: Config.cs:26
bool CanCertFP
Definition: protocol.h:67
WebCPanel::ChanServ::Access chanserv_access
Definition: webcpanel.cpp:33
CoreExport Serialize::Checker< botinfo_map > BotListByNick
WebCPanel::ChanServ::Drop chanserv_drop
Definition: webcpanel.cpp:36
StaticFileServer style_css
Definition: webcpanel.cpp:19
void RunCommand(const Anope::string &user, NickCore *nc, const Anope::string &service, const Anope::string &c, const std::vector< Anope::string > &params, TemplateFileServer::Replacements &r, const Anope::string &key)
Definition: webcpanel.cpp:234
WebCPanel::ChanServ::Set chanserv_set
Definition: webcpanel.cpp:32
WebCPanel::NickServ::Alist nickserv_alist
Definition: webcpanel.cpp:29
#define anope_override
Definition: services.h:56
WebCPanel::NickServ::Access nickserv_access
Definition: webcpanel.cpp:28
CoreExport IRCDProto * IRCD
Definition: protocol.cpp:23
#define MODULE_INIT(x)
Definition: modules.h:45
PrimitiveExtensibleItem< Anope::string > ip
Definition: webcpanel.cpp:17
WebCPanel::ChanServ::Akick chanserv_akick
Definition: webcpanel.cpp:34
WebCPanel::Register _register
Definition: webcpanel.cpp:23
CoreExport Anope::string DataDir
Definition: init.cpp:33
Anope::string nick
Definition: users.h:62
WebCPanel::MemoServ::Memos memoserv_memos
Definition: webcpanel.cpp:38
Reference< NickCore > nc
Definition: commands.h:61
ServiceReference< HTTPProvider > provider
Definition: webcpanel.cpp:15
Anope::string name
Definition: webcpanel.h:20
T Get(const Anope::string &tag)
Definition: config.h:44
Anope::string page_title
Definition: webcpanel.cpp:11
WebCPanel::HostServ::Request hostserv_request
Definition: webcpanel.cpp:40
StaticFileServer logo_png
Definition: webcpanel.cpp:19
std::vector< Section > sections
Definition: webcpanel.h:36
std::vector< SubSection > subsections
Definition: webcpanel.h:27
WebCPanel::Logout logout
Definition: webcpanel.cpp:22
Definition: modules.h:163
Anope::string provider_name
Definition: webcpanel.cpp:11