summaryrefslogtreecommitdiff
path: root/modules/extra/webcpanel/webcpanel.h
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-09-01 18:54:51 -0400
committerAdam <Adam@anope.org>2012-09-01 18:54:51 -0400
commite3d5140dcc936ff411c438b7e3997104cb5f085a (patch)
tree49d7ee0b3e531a1c81e35fb10f25e6340fa781ba /modules/extra/webcpanel/webcpanel.h
parentf81d0113a21187d68c5fa0f1262e5514465b1953 (diff)
Added a web panel module + a default template
Diffstat (limited to 'modules/extra/webcpanel/webcpanel.h')
-rw-r--r--modules/extra/webcpanel/webcpanel.h163
1 files changed, 163 insertions, 0 deletions
diff --git a/modules/extra/webcpanel/webcpanel.h b/modules/extra/webcpanel/webcpanel.h
new file mode 100644
index 000000000..79f902b0f
--- /dev/null
+++ b/modules/extra/webcpanel/webcpanel.h
@@ -0,0 +1,163 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "module.h"
+#include "../httpd.h"
+
+#include "static_fileserver.h"
+#include "template_fileserver.h"
+
+extern Anope::string provider_name, template_name, template_base, page_title;
+
+struct SubSection
+{
+ Anope::string name;
+ Anope::string url;
+};
+
+struct Section
+{
+ Anope::string name;
+ std::vector<SubSection> subsections;
+};
+
+/* An interface for this webpanel used by other modules */
+class Panel : public Section, public Service
+{
+ public:
+ Panel(Module *c, const Anope::string &n) : Service(c, "Panel", n) { }
+
+ std::vector<Section> sections;
+
+ NickAlias *GetNickFromSession(HTTPClient *client, HTTPMessage &msg)
+ {
+ if (!client)
+ return NULL;
+
+ const Anope::string &acc = msg.cookies["account"], &id = msg.cookies["id"];
+
+ if (acc.empty() || id.empty())
+ return NULL;
+
+ NickAlias *na = findnick(acc);
+ if (na == NULL)
+ return NULL;
+
+ Anope::string *n_id = na->GetExt<Anope::string *>("webcpanel_id"), *n_ip = na->GetExt<Anope::string *>("webcpanel_ip");
+ if (n_id == NULL || n_ip == NULL)
+ return NULL;
+ else if (id != *n_id)
+ return NULL;
+ else if (client->GetIP() != *n_ip)
+ return NULL;
+ else
+ return na;
+ }
+};
+
+class WebPanelPage : public HTTPPage
+{
+ public:
+ WebPanelPage(const Anope::string &u, const Anope::string &ct = "text/html") : HTTPPage(u, ct)
+ {
+ }
+
+ virtual void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) = 0;
+};
+
+class WebPanelProtectedPage : public WebPanelPage
+{
+ Anope::string category;
+
+ public:
+ WebPanelProtectedPage(const Anope::string &cat, const Anope::string &u, const Anope::string &ct = "text/html") : WebPanelPage(u, ct), category(cat)
+ {
+ }
+
+ void OnRequest(HTTPProvider *provider, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) anope_override anope_final
+ {
+ service_reference<Panel> panel("Panel", "webcpanel");
+ NickAlias *na;
+
+ if (!panel || !(na = panel->GetNickFromSession(client, message)))
+ {
+ return; // Access denied
+ }
+
+ TemplateFileServer::Replacements replacements;
+
+ replacements["TITLE"] = page_title;
+ replacements["ACCOUNT"] = na->nc->display;
+
+ Anope::string sections, get;
+
+ for (std::map<Anope::string, Anope::string>::iterator it = message.get_data.begin(), it_end = message.get_data.end(); it != it_end; ++it)
+ if (this->GetData().count(it->first) > 0)
+ get += "&" + it->first + "=" + HTTPUtils::URLEncode(it->second);
+ if (get.empty() == false)
+ get = "?" + get.substr(1);
+
+ Section *ns = NULL;
+ for (unsigned i = 0; i < panel->sections.size(); ++i)
+ {
+ Section& s = panel->sections[i];
+ if (s.name == this->category)
+ ns = &s;
+ replacements["CATEGORY_URLS"] = s.subsections[0].url;
+ replacements["CATEGORY_NAMES"] = s.name;
+ }
+
+ if (ns)
+ {
+ sections = "";
+ for (unsigned i = 0; i < ns->subsections.size(); ++i)
+ {
+ SubSection& ss = ns->subsections[i];
+ replacements["SUBCATEGORY_URLS"] = ss.url;
+ replacements["SUBCATEGORY_GETS"] = get;
+ replacements["SUBCATEGORY_NAMES"] = ss.name;
+ }
+ }
+
+ this->OnRequest(provider, page_name, client, message, reply, na, replacements);
+ }
+
+ virtual void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) = 0;
+
+ /* What get data should be appended to links in the navbar */
+ virtual std::set<Anope::string> GetData() { return std::set<Anope::string>(); }
+};
+
+namespace WebPanel
+{
+ /** Run a command
+ * @param User name to run command as, probably nc->display unless nc == NULL
+ * @param nc Nick core to run command from
+ * @param service Service for source.owner and source.service
+ * @param c Command to run (as a service name)
+ * @param params Command parameters
+ * @param r Replacements, reply from command goes back into r["MESSAGES"]
+ */
+ extern 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);
+}
+
+#include "pages/index.h"
+#include "pages/logout.h"
+#include "pages/register.h"
+#include "pages/confirm.h"
+
+#include "pages/nickserv/info.h"
+#include "pages/nickserv/cert.h"
+#include "pages/nickserv/access.h"
+#include "pages/nickserv/alist.h"
+
+#include "pages/chanserv/info.h"
+#include "pages/chanserv/set.h"
+#include "pages/chanserv/access.h"
+#include "pages/chanserv/akick.h"
+
+#include "pages/memoserv/memos.h" \ No newline at end of file