summaryrefslogtreecommitdiff
path: root/modules/extra/webcpanel
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
parentf81d0113a21187d68c5fa0f1262e5514465b1953 (diff)
Added a web panel module + a default template
Diffstat (limited to 'modules/extra/webcpanel')
-rw-r--r--modules/extra/webcpanel/CMakeLists.txt5
-rw-r--r--modules/extra/webcpanel/pages/chanserv/access.cpp147
-rw-r--r--modules/extra/webcpanel/pages/chanserv/access.h27
-rw-r--r--modules/extra/webcpanel/pages/chanserv/akick.cpp81
-rw-r--r--modules/extra/webcpanel/pages/chanserv/akick.h27
-rw-r--r--modules/extra/webcpanel/pages/chanserv/info.cpp32
-rw-r--r--modules/extra/webcpanel/pages/chanserv/info.h25
-rw-r--r--modules/extra/webcpanel/pages/chanserv/set.cpp136
-rw-r--r--modules/extra/webcpanel/pages/chanserv/set.h27
-rw-r--r--modules/extra/webcpanel/pages/confirm.cpp31
-rw-r--r--modules/extra/webcpanel/pages/confirm.h22
-rw-r--r--modules/extra/webcpanel/pages/index.cpp73
-rw-r--r--modules/extra/webcpanel/pages/index.h22
-rw-r--r--modules/extra/webcpanel/pages/logout.cpp22
-rw-r--r--modules/extra/webcpanel/pages/logout.h20
-rw-r--r--modules/extra/webcpanel/pages/memoserv/memos.cpp121
-rw-r--r--modules/extra/webcpanel/pages/memoserv/memos.h25
-rw-r--r--modules/extra/webcpanel/pages/nickserv/access.cpp39
-rw-r--r--modules/extra/webcpanel/pages/nickserv/access.h25
-rw-r--r--modules/extra/webcpanel/pages/nickserv/alist.cpp49
-rw-r--r--modules/extra/webcpanel/pages/nickserv/alist.h25
-rw-r--r--modules/extra/webcpanel/pages/nickserv/cert.cpp39
-rw-r--r--modules/extra/webcpanel/pages/nickserv/cert.h25
-rw-r--r--modules/extra/webcpanel/pages/nickserv/info.cpp111
-rw-r--r--modules/extra/webcpanel/pages/nickserv/info.h25
-rw-r--r--modules/extra/webcpanel/pages/register.cpp23
-rw-r--r--modules/extra/webcpanel/pages/register.h22
-rw-r--r--modules/extra/webcpanel/static_fileserver.cpp42
-rw-r--r--modules/extra/webcpanel/static_fileserver.h19
-rw-r--r--modules/extra/webcpanel/template_fileserver.cpp244
-rw-r--r--modules/extra/webcpanel/template_fileserver.h27
-rw-r--r--modules/extra/webcpanel/templates/default/chanserv/access.html52
-rw-r--r--modules/extra/webcpanel/templates/default/chanserv/akick.html42
-rw-r--r--modules/extra/webcpanel/templates/default/chanserv/main.html6
-rw-r--r--modules/extra/webcpanel/templates/default/chanserv/set.html100
-rw-r--r--modules/extra/webcpanel/templates/default/confirm.html30
-rw-r--r--modules/extra/webcpanel/templates/default/favicon.icobin0 -> 3774 bytes
-rw-r--r--modules/extra/webcpanel/templates/default/footer.html7
-rw-r--r--modules/extra/webcpanel/templates/default/header.html24
-rw-r--r--modules/extra/webcpanel/templates/default/login.html47
-rw-r--r--modules/extra/webcpanel/templates/default/logo.pngbin0 -> 16385 bytes
-rw-r--r--modules/extra/webcpanel/templates/default/memoserv/memos.html50
-rw-r--r--modules/extra/webcpanel/templates/default/nickserv/access.html24
-rw-r--r--modules/extra/webcpanel/templates/default/nickserv/alist.html16
-rw-r--r--modules/extra/webcpanel/templates/default/nickserv/cert.html19
-rw-r--r--modules/extra/webcpanel/templates/default/nickserv/info.html82
-rw-r--r--modules/extra/webcpanel/templates/default/register.html51
-rw-r--r--modules/extra/webcpanel/templates/default/style.css97
-rw-r--r--modules/extra/webcpanel/webcpanel.cpp209
-rw-r--r--modules/extra/webcpanel/webcpanel.h163
50 files changed, 2577 insertions, 0 deletions
diff --git a/modules/extra/webcpanel/CMakeLists.txt b/modules/extra/webcpanel/CMakeLists.txt
new file mode 100644
index 000000000..4437156ad
--- /dev/null
+++ b/modules/extra/webcpanel/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+install(DIRECTORY templates
+ DESTINATION "${DB_DIR}/modules/webcpanel"
+)
+
diff --git a/modules/extra/webcpanel/pages/chanserv/access.cpp b/modules/extra/webcpanel/pages/chanserv/access.cpp
new file mode 100644
index 000000000..d3ec2ad99
--- /dev/null
+++ b/modules/extra/webcpanel/pages/chanserv/access.cpp
@@ -0,0 +1,147 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../../webcpanel.h"
+
+WebCPanel::ChanServ::Access::Access(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
+{
+}
+
+void WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
+{
+ const Anope::string &chname = message.get_data["channel"];
+
+ if (chname.empty())
+ {
+ reply.error = HTTP_FOUND;
+ reply.headers["Location"] = "http://" + message.headers["Host"] + "/chanserv/info";
+ return;
+ }
+
+ ChannelInfo *ci = cs_findchan(chname);
+
+ if (!ci)
+ return;
+
+ AccessGroup u_access = ci->AccessFor(na->nc);
+ bool has_priv = na->nc->IsServicesOper() && na->nc->o->ot->HasPriv("chanserv/access/modify");
+
+ if (!u_access.HasPriv("ACCESS_LIST") && !has_priv)
+ return;
+
+ const ChanAccess *highest = u_access.Highest();
+
+ if (ci->AccessFor(na->nc).HasPriv("ACCESS_CHANGE") || has_priv)
+ {
+ if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false)
+ {
+ std::vector<Anope::string> params;
+ params.push_back(ci->name);
+ params.push_back("DEL");
+ params.push_back(message.get_data["mask"]);
+
+ WebPanel::RunCommand(na->nc->display, na->nc, Config->ChanServ, "chanserv/access", params, replacements);
+ }
+ else if (message.post_data["mask"].empty() == false && message.post_data["access"].empty() == false && message.post_data["provider"].empty() == false)
+ {
+ // Generic access add code here, works with any provider (so we can't call a command exactly)
+ AccessProvider *a = NULL;
+ for (std::list<AccessProvider *>::const_iterator it = AccessProvider::GetProviders().begin(); it != AccessProvider::GetProviders().end(); ++it)
+ if ((*it)->name == message.post_data["provider"])
+ a = *it;
+
+ if (a)
+ {
+ bool denied = false;
+
+ for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i)
+ {
+ ChanAccess *acc = ci->GetAccess(i);
+
+ if (acc->mask == message.post_data["mask"])
+ {
+ if ((!highest || *acc >= *highest) && !u_access.Founder && !has_priv)
+ {
+ replacements["MESSAGES"] = "Access denied";
+ denied = true;
+ }
+ else
+ ci->EraseAccess(acc);
+ break;
+ }
+ }
+
+ if (ci->GetAccessCount() >= Config->CSAccessMax)
+ replacements["MESSAGES"] = "Sorry, you can only have " + stringify(Config->CSAccessMax) + " access entries on a channel.";
+ else if (!denied)
+ {
+ ChanAccess *new_acc = a->Create();
+ new_acc->ci = ci;
+ new_acc->mask = message.post_data["mask"];
+ new_acc->creator = na->nc->display;
+ try
+ {
+ new_acc->Unserialize(message.post_data["access"]);
+ }
+ catch (...)
+ {
+ replacements["MESSAGES"] = "Invalid access expression for the given type";
+ delete new_acc;
+ new_acc = NULL;
+ }
+ if (new_acc)
+ {
+ new_acc->last_seen = 0;
+ new_acc->created = Anope::CurTime;
+
+ if ((!highest || *highest <= *new_acc) && !u_access.Founder && !has_priv)
+ delete new_acc;
+ else if (new_acc->Serialize().empty())
+ {
+ replacements["MESSAGES"] = "Invalid access expression for the given type";
+ delete new_acc;
+ }
+ else
+ {
+ ci->AddAccess(new_acc);
+ replacements["MESSAGES"] = "Access for " + new_acc->mask + " set to " + new_acc->Serialize();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ replacements["ESCAPED_CHANNEL"] = HTTPUtils::URLEncode(chname);
+
+ for (unsigned i = 0; i < ci->GetAccessCount(); ++i)
+ {
+ ChanAccess *access = ci->GetAccess(i);
+
+ replacements["MASKS"] = HTTPUtils::Escape(access->mask);
+ replacements["ACCESSES"] = HTTPUtils::Escape(access->Serialize());
+ replacements["CREATORS"] = HTTPUtils::Escape(access->creator);
+ replacements["ACCESS_CHANGES"] = ci->AccessFor(na->nc).HasPriv("ACCESS_CHANGE") ? "YES" : "NO";
+ }
+
+ for (std::list<AccessProvider *>::const_iterator it = AccessProvider::GetProviders().begin(); it != AccessProvider::GetProviders().end(); ++it)
+ {
+ const AccessProvider *a = *it;
+ replacements["PROVIDERS"] = a->name;
+ }
+
+ TemplateFileServer page("chanserv/access.html");
+ page.Serve(server, page_name, client, message, reply, replacements);
+}
+
+std::set<Anope::string> WebCPanel::ChanServ::Access::GetData() anope_override
+{
+ std::set<Anope::string> v;
+ v.insert("channel");
+ return v;
+}
+
diff --git a/modules/extra/webcpanel/pages/chanserv/access.h b/modules/extra/webcpanel/pages/chanserv/access.h
new file mode 100644
index 000000000..50425aa40
--- /dev/null
+++ b/modules/extra/webcpanel/pages/chanserv/access.h
@@ -0,0 +1,27 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+namespace WebCPanel
+{
+
+namespace ChanServ
+{
+
+class Access : public WebPanelProtectedPage
+{
+ public:
+ Access(const Anope::string &cat, const Anope::string &u);
+
+ void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
+
+ std::set<Anope::string> GetData() anope_override;
+};
+
+}
+
+}
+
diff --git a/modules/extra/webcpanel/pages/chanserv/akick.cpp b/modules/extra/webcpanel/pages/chanserv/akick.cpp
new file mode 100644
index 000000000..bc80437cc
--- /dev/null
+++ b/modules/extra/webcpanel/pages/chanserv/akick.cpp
@@ -0,0 +1,81 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../../webcpanel.h"
+
+WebCPanel::ChanServ::Akick::Akick(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
+{
+}
+
+void WebCPanel::ChanServ::Akick::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
+{
+ const Anope::string &chname = message.get_data["channel"];
+
+ if (chname.empty())
+ {
+ reply.error = HTTP_FOUND;
+ reply.headers["Location"] = "http://" + message.headers["Host"] + "/chanserv/info";
+ return;
+ }
+
+ ChannelInfo *ci = cs_findchan(chname);
+
+ if (!ci)
+ return;
+
+ AccessGroup u_access = ci->AccessFor(na->nc);
+ bool has_priv = na->nc->IsServicesOper() && na->nc->o->ot->HasPriv("chanserv/access/modify");
+
+ if (!u_access.HasPriv("akick") && !has_priv)
+ return;
+
+ if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false)
+ {
+ std::vector<Anope::string> params;
+ params.push_back(ci->name);
+ params.push_back("DEL");
+ params.push_back(message.get_data["mask"]);
+
+ WebPanel::RunCommand(na->nc->display, na->nc, Config->ChanServ, "chanserv/akick", params, replacements);
+ }
+ else if (message.post_data["mask"].empty() == false)
+ {
+ std::vector<Anope::string> params;
+ params.push_back(ci->name);
+ params.push_back("ADD");
+ params.push_back(message.post_data["mask"]);
+ if (message.post_data["reason"].empty() == false)
+ params.push_back(message.get_data["reason"]);
+
+ WebPanel::RunCommand(na->nc->display, na->nc, Config->ChanServ, "chanserv/akick", params, replacements);
+ }
+
+ replacements["ESCAPED_CHANNEL"] = HTTPUtils::URLEncode(chname);
+
+ for (unsigned i = 0; i < ci->GetAkickCount(); ++i)
+ {
+ AutoKick *akick = ci->GetAkick(i);
+
+ if (akick->nc)
+ replacements["MASKS"] = HTTPUtils::Escape(akick->nc->display);
+ else
+ replacements["MASKS"] = HTTPUtils::Escape(akick->mask);
+ replacements["CREATORS"] = HTTPUtils::Escape(akick->creator);
+ replacements["REASONS"] = HTTPUtils::Escape(akick->reason);
+ }
+
+ TemplateFileServer page("chanserv/akick.html");
+ page.Serve(server, page_name, client, message, reply, replacements);
+}
+
+std::set<Anope::string> WebCPanel::ChanServ::Akick::GetData() anope_override
+{
+ std::set<Anope::string> v;
+ v.insert("channel");
+ return v;
+}
+
diff --git a/modules/extra/webcpanel/pages/chanserv/akick.h b/modules/extra/webcpanel/pages/chanserv/akick.h
new file mode 100644
index 000000000..ff4a4653e
--- /dev/null
+++ b/modules/extra/webcpanel/pages/chanserv/akick.h
@@ -0,0 +1,27 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+namespace WebCPanel
+{
+
+namespace ChanServ
+{
+
+class Akick : public WebPanelProtectedPage
+{
+ public:
+ Akick(const Anope::string &cat, const Anope::string &u);
+
+ void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
+
+ std::set<Anope::string> GetData() anope_override;
+};
+
+}
+
+}
+
diff --git a/modules/extra/webcpanel/pages/chanserv/info.cpp b/modules/extra/webcpanel/pages/chanserv/info.cpp
new file mode 100644
index 000000000..8db88f496
--- /dev/null
+++ b/modules/extra/webcpanel/pages/chanserv/info.cpp
@@ -0,0 +1,32 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../../webcpanel.h"
+
+WebCPanel::ChanServ::Info::Info(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
+{
+}
+
+void WebCPanel::ChanServ::Info::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
+{
+ // XXX this is slightly inefficient
+ for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
+ {
+ ChannelInfo *ci = it->second;
+
+ if (ci->AccessFor(na->nc).HasPriv("SET") || ci->AccessFor(na->nc).HasPriv("ACCESS_LIST"))
+ {
+ replacements["CHANNEL_NAMES"] = ci->name;
+ replacements["ESCAPED_CHANNEL_NAMES"] = HTTPUtils::URLEncode(ci->name);
+ }
+ }
+
+
+ TemplateFileServer page("chanserv/main.html");
+ page.Serve(server, page_name, client, message, reply, replacements);
+}
+
diff --git a/modules/extra/webcpanel/pages/chanserv/info.h b/modules/extra/webcpanel/pages/chanserv/info.h
new file mode 100644
index 000000000..87dc9836b
--- /dev/null
+++ b/modules/extra/webcpanel/pages/chanserv/info.h
@@ -0,0 +1,25 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+namespace WebCPanel
+{
+
+namespace ChanServ
+{
+
+class Info : public WebPanelProtectedPage
+{
+ public:
+ Info(const Anope::string &cat, const Anope::string &u);
+
+ void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
+};
+
+}
+
+}
+
diff --git a/modules/extra/webcpanel/pages/chanserv/set.cpp b/modules/extra/webcpanel/pages/chanserv/set.cpp
new file mode 100644
index 000000000..764eb13ac
--- /dev/null
+++ b/modules/extra/webcpanel/pages/chanserv/set.cpp
@@ -0,0 +1,136 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../../webcpanel.h"
+
+WebCPanel::ChanServ::Set::Set(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
+{
+}
+
+void WebCPanel::ChanServ::Set::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
+{
+ const Anope::string &chname = message.get_data["channel"];
+
+ if (chname.empty())
+ {
+ reply.error = HTTP_FOUND;
+ reply.headers["Location"] = "http://" + message.headers["Host"] + "/chanserv/info";
+ return;
+ }
+
+ ChannelInfo *ci = cs_findchan(chname);
+
+ if (!ci || !ci->AccessFor(na->nc).HasPriv("SET"))
+ return;
+
+ if (message.post_data.empty() == false)
+ {
+ if (ci->HasFlag(CI_KEEPTOPIC) != message.post_data.count("keeptopic"))
+ {
+ if (!ci->HasFlag(CI_KEEPTOPIC))
+ ci->SetFlag(CI_KEEPTOPIC);
+ else
+ ci->UnsetFlag(CI_KEEPTOPIC);
+ replacements["MESSAGES"] = "Secure updated";
+ }
+ if (ci->HasFlag(CI_PEACE) != message.post_data.count("peace"))
+ {
+ if (!ci->HasFlag(CI_PEACE))
+ ci->SetFlag(CI_PEACE);
+ else
+ ci->UnsetFlag(CI_PEACE);
+ replacements["MESSAGES"] = "Peace updated";
+ }
+ if (ci->HasFlag(CI_PRIVATE) != message.post_data.count("private"))
+ {
+ if (!ci->HasFlag(CI_PRIVATE))
+ ci->SetFlag(CI_PRIVATE);
+ else
+ ci->UnsetFlag(CI_PRIVATE);
+ replacements["MESSAGES"] = "Private updated";
+ }
+ if (ci->HasFlag(CI_RESTRICTED) != message.post_data.count("restricted"))
+ {
+ if (!ci->HasFlag(CI_RESTRICTED))
+ ci->SetFlag(CI_RESTRICTED);
+ else
+ ci->UnsetFlag(CI_RESTRICTED);
+ replacements["MESSAGES"] = "Restricted updated";
+ }
+ if (ci->HasFlag(CI_SECURE) != message.post_data.count("secure"))
+ {
+ if (!ci->HasFlag(CI_SECURE))
+ ci->SetFlag(CI_SECURE);
+ else
+ ci->UnsetFlag(CI_SECURE);
+ replacements["MESSAGES"] = "Secure updated";
+ }
+ if (ci->HasFlag(CI_SECUREOPS) != message.post_data.count("secureops"))
+ {
+ if (!ci->HasFlag(CI_SECUREOPS))
+ ci->SetFlag(CI_SECUREOPS);
+ else
+ ci->UnsetFlag(CI_SECUREOPS);
+ replacements["MESSAGES"] = "Secureops updated";
+ }
+ if (ci->HasFlag(CI_TOPICLOCK) != message.post_data.count("topiclock"))
+ {
+ if (!ci->HasFlag(CI_TOPICLOCK))
+ ci->SetFlag(CI_TOPICLOCK);
+ else
+ ci->UnsetFlag(CI_TOPICLOCK);
+ replacements["MESSAGES"] = "Topiclock updated";
+ }
+ }
+
+ replacements["CHANNEL"] = HTTPUtils::Escape(ci->name);
+ replacements["CHANNEL_ESCAPED"] = HTTPUtils::URLEncode(ci->name);
+ if (ci->GetFounder())
+ replacements["FOUNDER"] = ci->GetFounder()->display;
+ if (ci->successor)
+ replacements["SUCCESSOR"] = ci->successor->display;
+ replacements["TIME_REGISTERED"] = do_strftime(ci->time_registered, na->nc);
+ replacements["LAST_USED"] = do_strftime(ci->last_used, na->nc);
+
+ if (!ci->last_topic.empty())
+ {
+ replacements["LAST_TOPIC"] = HTTPUtils::Escape(ci->last_topic);
+ replacements["LAST_TOPIC_SETTER"] = HTTPUtils::Escape(ci->last_topic_setter);
+ }
+
+ if (ci->HasFlag(CI_KEEPTOPIC))
+ replacements["KEEPTOPIC"];
+
+ if (ci->HasFlag(CI_PEACE))
+ replacements["PEACE"];
+
+ if (ci->HasFlag(CI_PRIVATE))
+ replacements["PRIVATE"];
+
+ if (ci->HasFlag(CI_RESTRICTED))
+ replacements["RESTRICTED"];
+
+ if (ci->HasFlag(CI_SECURE))
+ replacements["SECURE"];
+
+ if (ci->HasFlag(CI_SECUREOPS))
+ replacements["SECUREOPS"];
+
+ if (ci->HasFlag(CI_TOPICLOCK))
+ replacements["TOPICLOCK"];
+
+ TemplateFileServer page("chanserv/set.html");
+ page.Serve(server, page_name, client, message, reply, replacements);
+}
+
+std::set<Anope::string> WebCPanel::ChanServ::Set::GetData() anope_override
+{
+ std::set<Anope::string> v;
+ v.insert("channel");
+ return v;
+}
+
diff --git a/modules/extra/webcpanel/pages/chanserv/set.h b/modules/extra/webcpanel/pages/chanserv/set.h
new file mode 100644
index 000000000..67e817493
--- /dev/null
+++ b/modules/extra/webcpanel/pages/chanserv/set.h
@@ -0,0 +1,27 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+namespace WebCPanel
+{
+
+namespace ChanServ
+{
+
+class Set : public WebPanelProtectedPage
+{
+ public:
+ Set(const Anope::string &cat, const Anope::string &u);
+
+ void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
+
+ std::set<Anope::string> GetData() anope_override;
+};
+
+}
+
+}
+
diff --git a/modules/extra/webcpanel/pages/confirm.cpp b/modules/extra/webcpanel/pages/confirm.cpp
new file mode 100644
index 000000000..f18d28129
--- /dev/null
+++ b/modules/extra/webcpanel/pages/confirm.cpp
@@ -0,0 +1,31 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../webcpanel.h"
+
+void WebCPanel::Confirm::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply)
+{
+ TemplateFileServer::Replacements replacements;
+ const Anope::string &user = message.post_data["username"], &pass = message.post_data["password"], &email = message.post_data["email"];
+
+ replacements["TITLE"] = page_title;
+
+ if (!user.empty() && !pass.empty())
+ {
+ std::vector<Anope::string> params;
+ params.push_back(pass);
+ if (!email.empty())
+ params.push_back(email);
+
+ WebPanel::RunCommand(user, NULL, Config->NickServ, "nickserv/register", params, replacements);
+ }
+
+ TemplateFileServer page("confirm.html");
+
+ page.Serve(server, page_name, client, message, reply, replacements);
+}
+
diff --git a/modules/extra/webcpanel/pages/confirm.h b/modules/extra/webcpanel/pages/confirm.h
new file mode 100644
index 000000000..d4d19d9c6
--- /dev/null
+++ b/modules/extra/webcpanel/pages/confirm.h
@@ -0,0 +1,22 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../../httpd.h"
+
+namespace WebCPanel
+{
+
+class Confirm : public WebPanelPage
+{
+ public:
+ Confirm(const Anope::string &u) : WebPanelPage(u) { }
+
+ void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override;
+};
+
+}
+
diff --git a/modules/extra/webcpanel/pages/index.cpp b/modules/extra/webcpanel/pages/index.cpp
new file mode 100644
index 000000000..525e564f6
--- /dev/null
+++ b/modules/extra/webcpanel/pages/index.cpp
@@ -0,0 +1,73 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../webcpanel.h"
+
+void WebCPanel::Index::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply)
+{
+ TemplateFileServer::Replacements replacements;
+ const Anope::string &user = message.post_data["username"], &pass = message.post_data["password"];
+
+ replacements["TITLE"] = page_title;
+
+ if (!user.empty() && !pass.empty())
+ {
+ // Rate limit check.
+
+ NickAlias *na = findnick(user);
+
+ EventReturn MOD_RESULT = EVENT_CONTINUE;
+
+ if (na)
+ {
+ FOREACH_RESULT(I_OnCheckAuthentication, OnCheckAuthentication(NULL, NULL, std::vector<Anope::string>(), na->nc->display, pass));
+ }
+
+ if (MOD_RESULT == EVENT_ALLOW)
+ {
+ Anope::string id;
+ for (int i = 0; i < 64; ++i)
+ {
+ char c;
+ do
+ c = 48 + (rand() % 123);
+ while (!isalnum(c));
+ id += c;
+ }
+
+ na->Extend("webcpanel_id", new ExtensibleItemClass<Anope::string>(id));
+ na->Extend("webcpanel_ip", new ExtensibleItemClass<Anope::string>(client->GetIP()));
+
+ {
+ HTTPReply::cookie c;
+ c.push_back(std::make_pair("account", na->nick));
+ c.push_back(std::make_pair("Path", "/"));
+ reply.cookies.push_back(c);
+ }
+
+ {
+ HTTPReply::cookie c;
+ c.push_back(std::make_pair("id", id));
+ c.push_back(std::make_pair("Path", "/"));
+ reply.cookies.push_back(c);
+ }
+
+ reply.error = HTTP_FOUND;
+ reply.headers["Location"] = "http://" + message.headers["Host"] + "/nickserv/info";
+ return;
+ }
+ else
+ {
+ replacements["INVALID_LOGIN"] = "Invalid username or password";
+ }
+ }
+
+ TemplateFileServer page("login.html");
+
+ page.Serve(server, page_name, client, message, reply, replacements);
+}
+
diff --git a/modules/extra/webcpanel/pages/index.h b/modules/extra/webcpanel/pages/index.h
new file mode 100644
index 000000000..2f4d9c400
--- /dev/null
+++ b/modules/extra/webcpanel/pages/index.h
@@ -0,0 +1,22 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../../httpd.h"
+
+namespace WebCPanel
+{
+
+class Index : public WebPanelPage
+{
+ public:
+ Index(const Anope::string &u) : WebPanelPage(u) { }
+
+ void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override;
+};
+
+}
+
diff --git a/modules/extra/webcpanel/pages/logout.cpp b/modules/extra/webcpanel/pages/logout.cpp
new file mode 100644
index 000000000..90a6a8a9b
--- /dev/null
+++ b/modules/extra/webcpanel/pages/logout.cpp
@@ -0,0 +1,22 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../webcpanel.h"
+
+WebCPanel::Logout::Logout(const Anope::string &u) : WebPanelProtectedPage("", u)
+{
+}
+
+void WebCPanel::Logout::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
+{
+ na->Shrink("webcpanel_id");
+ na->Shrink("webcpanel_ip");
+
+ reply.error = HTTP_FOUND;
+ reply.headers["Location"] = "http://" + message.headers["Host"];
+}
+
diff --git a/modules/extra/webcpanel/pages/logout.h b/modules/extra/webcpanel/pages/logout.h
new file mode 100644
index 000000000..4f31e4a00
--- /dev/null
+++ b/modules/extra/webcpanel/pages/logout.h
@@ -0,0 +1,20 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+namespace WebCPanel
+{
+
+class Logout : public WebPanelProtectedPage
+{
+ public:
+ Logout(const Anope::string &u);
+
+ void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
+};
+
+}
+
diff --git a/modules/extra/webcpanel/pages/memoserv/memos.cpp b/modules/extra/webcpanel/pages/memoserv/memos.cpp
new file mode 100644
index 000000000..eafbde3a5
--- /dev/null
+++ b/modules/extra/webcpanel/pages/memoserv/memos.cpp
@@ -0,0 +1,121 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../../webcpanel.h"
+
+WebCPanel::MemoServ::Memos::Memos(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
+{
+}
+
+void WebCPanel::MemoServ::Memos::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
+{
+ const Anope::string &chname = message.get_data["channel"];
+ ChannelInfo *ci;
+ const MemoInfo *mi;
+ Memo *m;
+
+ for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
+ {
+ ci = it->second;
+
+ if (ci->AccessFor(na->nc).HasPriv("MEMO"))
+ {
+ replacements["CHANNEL_NAMES"] = ci->name;
+ replacements["ESCAPED_CHANNEL_NAMES"] = HTTPUtils::URLEncode(ci->name);
+ }
+ }
+
+ if (chname.empty())
+ {
+ replacements["MESSAGES"] = "No Channel specified, displaying the memos for your Nick";
+ mi = &na->nc->memos;
+ }
+ else
+ {
+ ci = cs_findchan(chname);
+ if (ci)
+ {
+ replacements["MESSAGES"] = "Displaying the memos for " + chname + ".";
+ mi = &ci->memos;
+ }
+ else
+ {
+ replacements["MESSAGES"] = "Channel " + chname + " not found, displaying the memos for your nick";
+ mi = &na->nc->memos;
+ }
+
+ replacements["CHANNEL_NAME"] = ci->name;
+ replacements["ESCAPED_CHANNEL_NAME"] = HTTPUtils::URLEncode(ci->name);
+ }
+ if (message.post_data.count("receiver") > 0 && message.post_data.count("message") > 0)
+ {
+ std::vector<Anope::string> params;
+ params.push_back(HTTPUtils::URLDecode(message.post_data["receiver"]));
+ params.push_back(HTTPUtils::URLDecode(message.post_data["message"]));
+
+ WebPanel::RunCommand(na->nc->display, na->nc, Config->MemoServ, "memoserv/send", params, replacements);
+ }
+ if (message.get_data.count("del") > 0 && message.get_data.count("number") > 0)
+ {
+ std::vector<Anope::string> params;
+ if (!chname.empty())
+ params.push_back(chname);
+ params.push_back(message.get_data["number"]);
+
+ WebPanel::RunCommand(na->nc->display, na->nc, Config->MemoServ, "memoserv/del", params, replacements);
+ }
+ if (message.get_data.count("read") > 0 && message.get_data.count("number") > 0)
+ {
+ std::vector<Anope::string> params;
+ int number;
+ bool error = false;
+
+ try
+ {
+ number = convertTo<int>(message.get_data["number"]);
+ }
+ catch (const ConvertException &ex)
+ {
+ replacements["MESSAGES"] = "ERROR - invalid parameter for NUMBER";
+ error = true;
+ }
+
+ m = mi->GetMemo(number-1);
+
+ if (!error && !m)
+ {
+ replacements["MESSAGES"] = "ERROR - invalid memo number.";
+ error = true;
+ }
+
+ if (!error && message.get_data["read"] == "1")
+ {
+ m->UnsetFlag(MF_UNREAD);
+ }
+ else if (!error && message.get_data["read"] == "2")
+ {
+ m->SetFlag(MF_UNREAD);
+ }
+ }
+
+ for (unsigned i = 0; i < mi->memos->size(); ++i)
+ {
+ m = mi->GetMemo(i);
+ replacements["NUMBER"] = stringify(i+1);
+ replacements["SENDER"] = m->sender;
+ replacements["TIME"] = do_strftime(m->time);
+ replacements["TEXT"] = m->text;
+ if (m->HasFlag(MF_UNREAD))
+ replacements["UNREAD"] = "YES";
+ else
+ replacements["UNREAD"] = "NO";
+ }
+
+ TemplateFileServer page("memoserv/memos.html");
+ page.Serve(server, page_name, client, message, reply, replacements);
+}
+
diff --git a/modules/extra/webcpanel/pages/memoserv/memos.h b/modules/extra/webcpanel/pages/memoserv/memos.h
new file mode 100644
index 000000000..00c4c346b
--- /dev/null
+++ b/modules/extra/webcpanel/pages/memoserv/memos.h
@@ -0,0 +1,25 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+namespace WebCPanel
+{
+
+namespace MemoServ
+{
+
+class Memos : public WebPanelProtectedPage
+{
+ public:
+ Memos(const Anope::string &cat, const Anope::string &u);
+
+ void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
+};
+
+}
+
+}
+
diff --git a/modules/extra/webcpanel/pages/nickserv/access.cpp b/modules/extra/webcpanel/pages/nickserv/access.cpp
new file mode 100644
index 000000000..c18c5ccb0
--- /dev/null
+++ b/modules/extra/webcpanel/pages/nickserv/access.cpp
@@ -0,0 +1,39 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../../webcpanel.h"
+
+WebCPanel::NickServ::Access::Access(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
+{
+}
+
+void WebCPanel::NickServ::Access::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
+{
+ if (message.post_data.count("access") > 0)
+ {
+ std::vector<Anope::string> params;
+ params.push_back("ADD");
+ params.push_back(message.post_data["access"]);
+
+ WebPanel::RunCommand(na->nc->display, na->nc, Config->NickServ, "nickserv/access", params, replacements);
+ }
+ else if (message.get_data.count("del") > 0 && message.get_data.count("mask") > 0)
+ {
+ std::vector<Anope::string> params;
+ params.push_back("DEL");
+ params.push_back(message.get_data["mask"]);
+
+ WebPanel::RunCommand(na->nc->display, na->nc, Config->NickServ, "nickserv/access", params, replacements);
+ }
+
+ for (unsigned i = 0; i < na->nc->access.size(); ++i)
+ replacements["ACCESS"] = na->nc->access[i];
+
+ TemplateFileServer page("nickserv/access.html");
+ page.Serve(server, page_name, client, message, reply, replacements);
+}
+
diff --git a/modules/extra/webcpanel/pages/nickserv/access.h b/modules/extra/webcpanel/pages/nickserv/access.h
new file mode 100644
index 000000000..3f4059aa4
--- /dev/null
+++ b/modules/extra/webcpanel/pages/nickserv/access.h
@@ -0,0 +1,25 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+namespace WebCPanel
+{
+
+namespace NickServ
+{
+
+class Access : public WebPanelProtectedPage
+{
+ public:
+ Access(const Anope::string &cat, const Anope::string &u);
+
+ void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
+};
+
+}
+
+}
+
diff --git a/modules/extra/webcpanel/pages/nickserv/alist.cpp b/modules/extra/webcpanel/pages/nickserv/alist.cpp
new file mode 100644
index 000000000..d3c92dcf4
--- /dev/null
+++ b/modules/extra/webcpanel/pages/nickserv/alist.cpp
@@ -0,0 +1,49 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../../webcpanel.h"
+
+WebCPanel::NickServ::Alist::Alist(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
+{
+}
+
+void WebCPanel::NickServ::Alist::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
+{
+ int chan_count = 0;
+
+ for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
+ {
+ ChannelInfo *ci = it->second;
+
+ if (ci->GetFounder() && ci->GetFounder() == na->nc)
+ {
+ ++chan_count;
+
+ replacements["NUMBERS"] = stringify(chan_count);
+ replacements["CHANNELS"] = (ci->HasFlag(CI_NO_EXPIRE) ? "!" : "") + ci->name;
+ replacements["ACCESSES"] = "Founder";
+ continue;
+ }
+
+ AccessGroup access = ci->AccessFor(na->nc);
+ if (access.empty())
+ continue;
+
+ ++chan_count;
+
+ replacements["NUMBERS"] = stringify(chan_count);
+ replacements["CHANNELS"] = (ci->HasFlag(CI_NO_EXPIRE) ? "!" : "") + ci->name;
+ Anope::string access_str;
+ for (unsigned i = 0; i < access.size(); ++i)
+ access_str += ", " + access[i]->Serialize();
+ replacements["ACCESSES"] = access_str.substr(2);
+ }
+
+ TemplateFileServer page("nickserv/alist.html");
+ page.Serve(server, page_name, client, message, reply, replacements);
+}
+
diff --git a/modules/extra/webcpanel/pages/nickserv/alist.h b/modules/extra/webcpanel/pages/nickserv/alist.h
new file mode 100644
index 000000000..5e4b31724
--- /dev/null
+++ b/modules/extra/webcpanel/pages/nickserv/alist.h
@@ -0,0 +1,25 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+namespace WebCPanel
+{
+
+namespace NickServ
+{
+
+class Alist : public WebPanelProtectedPage
+{
+ public:
+ Alist(const Anope::string &cat, const Anope::string &u);
+
+ void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
+};
+
+}
+
+}
+
diff --git a/modules/extra/webcpanel/pages/nickserv/cert.cpp b/modules/extra/webcpanel/pages/nickserv/cert.cpp
new file mode 100644
index 000000000..e354addca
--- /dev/null
+++ b/modules/extra/webcpanel/pages/nickserv/cert.cpp
@@ -0,0 +1,39 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../../webcpanel.h"
+
+WebCPanel::NickServ::Cert::Cert(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
+{
+}
+
+void WebCPanel::NickServ::Cert::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
+{
+ if (message.post_data.count("certfp") > 0)
+ {
+ std::vector<Anope::string> params;
+ params.push_back("ADD");
+ params.push_back(message.post_data["certfp"]);
+
+ WebPanel::RunCommand(na->nc->display, na->nc, Config->NickServ, "nickserv/cert", params, replacements);
+ }
+ else if (message.get_data.count("del") > 0 && message.get_data.count("mask") > 0)
+ {
+ std::vector<Anope::string> params;
+ params.push_back("DEL");
+ params.push_back(message.get_data["mask"]);
+
+ WebPanel::RunCommand(na->nc->display, na->nc, Config->NickServ, "nickserv/cert", params, replacements);
+ }
+
+ for (unsigned i = 0; i < na->nc->cert.size(); ++i)
+ replacements["CERTS"] = na->nc->cert[i];
+
+ TemplateFileServer page("nickserv/cert.html");
+ page.Serve(server, page_name, client, message, reply, replacements);
+}
+
diff --git a/modules/extra/webcpanel/pages/nickserv/cert.h b/modules/extra/webcpanel/pages/nickserv/cert.h
new file mode 100644
index 000000000..1f9f1b4ad
--- /dev/null
+++ b/modules/extra/webcpanel/pages/nickserv/cert.h
@@ -0,0 +1,25 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+namespace WebCPanel
+{
+
+namespace NickServ
+{
+
+class Cert : public WebPanelProtectedPage
+{
+ public:
+ Cert(const Anope::string &cat, const Anope::string &u);
+
+ void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
+};
+
+}
+
+}
+
diff --git a/modules/extra/webcpanel/pages/nickserv/info.cpp b/modules/extra/webcpanel/pages/nickserv/info.cpp
new file mode 100644
index 000000000..7ae07ad28
--- /dev/null
+++ b/modules/extra/webcpanel/pages/nickserv/info.cpp
@@ -0,0 +1,111 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../../webcpanel.h"
+
+WebCPanel::NickServ::Info::Info(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u)
+{
+}
+
+void WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements)
+{
+ if (message.post_data.empty() == false)
+ {
+ if (message.post_data.count("email") > 0)
+ {
+ if (message.post_data["email"] != na->nc->email)
+ {
+ if (!message.post_data["email"].empty() && !MailValidate(message.post_data["email"]))
+ replacements["ERRORS"] = "Invalid email";
+ else
+ {
+ na->nc->email = message.post_data["email"];
+ replacements["MESSAGES"] = "Email updated";
+ }
+ }
+ }
+ if (message.post_data.count("greet") > 0)
+ {
+ if (message.post_data["greet"].replace_all_cs("+", " ") != na->nc->greet)
+ {
+ na->nc->greet = HTTPUtils::URLDecode(message.post_data["greet"]);
+ replacements["MESSAGES"] = "Greet updated";
+ }
+ }
+ if (na->nc->HasFlag(NI_AUTOOP) != message.post_data.count("autoop"))
+ {
+ if (!na->nc->HasFlag(NI_AUTOOP))
+ na->nc->SetFlag(NI_AUTOOP);
+ else
+ na->nc->UnsetFlag(NI_AUTOOP);
+ replacements["MESSAGES"] = "Autoop updated";
+ }
+ if (na->nc->HasFlag(NI_PRIVATE) != message.post_data.count("private"))
+ {
+ if (!na->nc->HasFlag(NI_PRIVATE))
+ na->nc->SetFlag(NI_PRIVATE);
+ else
+ na->nc->UnsetFlag(NI_PRIVATE);
+ replacements["MESSAGES"] = "Private updated";
+ }
+ if (na->nc->HasFlag(NI_SECURE) != message.post_data.count("secure"))
+ {
+ if (!na->nc->HasFlag(NI_SECURE))
+ na->nc->SetFlag(NI_SECURE);
+ else
+ na->nc->UnsetFlag(NI_SECURE);
+ replacements["MESSAGES"] = "Secure updated";
+ }
+ if (message.post_data["kill"] == "on" && !na->nc->HasFlag(NI_KILLPROTECT))
+ {
+ na->nc->SetFlag(NI_KILLPROTECT);
+ na->nc->UnsetFlag(NI_KILL_QUICK);
+ replacements["MESSAGES"] = "Kill updated";
+ }
+ else if (message.post_data["kill"] == "quick" && !na->nc->HasFlag(NI_KILL_QUICK))
+ {
+ na->nc->UnsetFlag(NI_KILLPROTECT);
+ na->nc->SetFlag(NI_KILL_QUICK);
+ replacements["MESSAGES"] = "Kill updated";
+ }
+ else if (message.post_data["kill"] == "off" && (na->nc->HasFlag(NI_KILLPROTECT) || na->nc->HasFlag(NI_KILL_QUICK)))
+ {
+ na->nc->UnsetFlag(NI_KILLPROTECT);
+ na->nc->UnsetFlag(NI_KILL_QUICK);
+ replacements["MESSAGES"] = "Kill updated";
+ }
+ }
+
+ replacements["DISPLAY"] = HTTPUtils::Escape(na->nc->display);
+ if (na->nc->email.empty() == false)
+ replacements["EMAIL"] = HTTPUtils::Escape(na->nc->email);
+ replacements["TIME_REGISTERED"] = do_strftime(na->time_registered, na->nc);
+ if (na->HasVhost())
+ {
+ if (na->GetVhostIdent().empty() == false)
+ replacements["VHOST"] = na->GetVhostIdent() + "@" + na->GetVhostHost();
+ else
+ replacements["VHOST"] = na->GetVhostHost();
+ }
+ replacements["GREET"] = HTTPUtils::Escape(na->nc->greet);
+ if (na->nc->HasFlag(NI_AUTOOP))
+ replacements["AUTOOP"];
+ if (na->nc->HasFlag(NI_PRIVATE))
+ replacements["PRIVATE"];
+ if (na->nc->HasFlag(NI_SECURE))
+ replacements["SECURE"];
+ if (na->nc->HasFlag(NI_KILLPROTECT))
+ replacements["KILL_ON"];
+ if (na->nc->HasFlag(NI_KILL_QUICK))
+ replacements["KILL_QUICK"];
+ if (!na->nc->HasFlag(NI_KILLPROTECT) && !na->nc->HasFlag(NI_KILL_QUICK))
+ replacements["KILL_OFF"];
+
+ TemplateFileServer page("nickserv/info.html");
+ page.Serve(server, page_name, client, message, reply, replacements);
+}
+
diff --git a/modules/extra/webcpanel/pages/nickserv/info.h b/modules/extra/webcpanel/pages/nickserv/info.h
new file mode 100644
index 000000000..05fc981ac
--- /dev/null
+++ b/modules/extra/webcpanel/pages/nickserv/info.h
@@ -0,0 +1,25 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+namespace WebCPanel
+{
+
+namespace NickServ
+{
+
+class Info : public WebPanelProtectedPage
+{
+ public:
+ Info(const Anope::string &cat, const Anope::string &u);
+
+ void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override;
+};
+
+}
+
+}
+
diff --git a/modules/extra/webcpanel/pages/register.cpp b/modules/extra/webcpanel/pages/register.cpp
new file mode 100644
index 000000000..84efb3fc0
--- /dev/null
+++ b/modules/extra/webcpanel/pages/register.cpp
@@ -0,0 +1,23 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../webcpanel.h"
+
+void WebCPanel::Register::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply)
+{
+ TemplateFileServer::Replacements replacements;
+
+ replacements["TITLE"] = page_title;
+
+ if (!Config->NSForceEmail)
+ replacements["EMAIL_TYPE"] = "hidden";
+
+ TemplateFileServer page("register.html");
+
+ page.Serve(server, page_name, client, message, reply, replacements);
+}
+
diff --git a/modules/extra/webcpanel/pages/register.h b/modules/extra/webcpanel/pages/register.h
new file mode 100644
index 000000000..0651bfba6
--- /dev/null
+++ b/modules/extra/webcpanel/pages/register.h
@@ -0,0 +1,22 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../../httpd.h"
+
+namespace WebCPanel
+{
+
+class Register : public WebPanelPage
+{
+ public:
+ Register(const Anope::string &u) : WebPanelPage(u) { }
+
+ void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override;
+};
+
+}
+
diff --git a/modules/extra/webcpanel/static_fileserver.cpp b/modules/extra/webcpanel/static_fileserver.cpp
new file mode 100644
index 000000000..3f51c8b40
--- /dev/null
+++ b/modules/extra/webcpanel/static_fileserver.cpp
@@ -0,0 +1,42 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "webcpanel.h"
+#include <fstream>
+#include <errno.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+StaticFileServer::StaticFileServer(const Anope::string &f_n, const Anope::string &u, const Anope::string &c_t) : HTTPPage(u, c_t), file_name(f_n)
+{
+}
+
+void StaticFileServer::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply)
+{
+ int fd = open((template_base + "/" + this->file_name).c_str(), O_RDONLY);
+ if (fd < 0)
+ {
+ Log(LOG_NORMAL, "httpd") << "Error serving file " << page_name << " (" << (template_base + "/" + this->file_name) << "): " << strerror(errno);
+
+ client->SendError(HTTP_PAGE_NOT_FOUND, "Page not found");
+ return;
+ }
+
+ reply.content_type = this->GetContentType();
+ reply.headers["Cache-Control"] = "public";
+
+ int i;
+ char buffer[BUFSIZE];
+ while ((i = read(fd, buffer, sizeof(buffer))) > 0)
+ reply.Write(buffer, i);
+
+ close(fd);
+}
+
diff --git a/modules/extra/webcpanel/static_fileserver.h b/modules/extra/webcpanel/static_fileserver.h
new file mode 100644
index 000000000..17fa7d6b2
--- /dev/null
+++ b/modules/extra/webcpanel/static_fileserver.h
@@ -0,0 +1,19 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../httpd.h"
+
+/* A basic file server. Used for serving static content on disk. */
+class StaticFileServer : public HTTPPage
+{
+ Anope::string file_name;
+ public:
+ StaticFileServer(const Anope::string &f_n, const Anope::string &u, const Anope::string &c_t);
+
+ void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override;
+};
+
diff --git a/modules/extra/webcpanel/template_fileserver.cpp b/modules/extra/webcpanel/template_fileserver.cpp
new file mode 100644
index 000000000..d3a974391
--- /dev/null
+++ b/modules/extra/webcpanel/template_fileserver.cpp
@@ -0,0 +1,244 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "webcpanel.h"
+#include <fstream>
+#include <stack>
+#include <errno.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+struct ForLoop
+{
+ static std::vector<ForLoop> Stack;
+
+ size_t start; /* Index of start of this loop */
+ std::vector<Anope::string> vars; /* User defined variables */
+ typedef std::pair<TemplateFileServer::Replacements::iterator, TemplateFileServer::Replacements::iterator> range;
+ std::vector<range> ranges; /* iterator ranges for each variable */
+
+ ForLoop(size_t s, TemplateFileServer::Replacements &r, const std::vector<Anope::string> &v, const std::vector<Anope::string> &r_names) : start(s), vars(v)
+ {
+ for (unsigned i = 0; i < r_names.size(); ++i)
+ ranges.push_back(r.equal_range(r_names[i]));
+ }
+
+ void increment(const TemplateFileServer::Replacements &r)
+ {
+ for (unsigned i = 0; i < ranges.size(); ++i)
+ {
+ range &ra = ranges[i];
+
+ if (ra.first != r.end() && ra.first != ra.second)
+ ++ra.first;
+ }
+ }
+
+ bool finished(const TemplateFileServer::Replacements &r) const
+ {
+ for (unsigned i = 0; i < ranges.size(); ++i)
+ {
+ const range &ra = ranges[i];
+
+ if (ra.first != r.end() && ra.first != ra.second)
+ return false;
+ }
+
+ return true;
+ }
+};
+std::vector<ForLoop> ForLoop::Stack;
+
+std::stack<bool> IfStack;
+
+static Anope::string FindReplacement(const TemplateFileServer::Replacements &r, const Anope::string &key)
+{
+ /* Search first through for loop stack then global replacements */
+ for (unsigned i = ForLoop::Stack.size(); i > 0; --i)
+ {
+ ForLoop &fl = ForLoop::Stack[i - 1];
+
+ for (unsigned j = 0; j < fl.vars.size(); ++j)
+ {
+ const Anope::string &var_name = fl.vars[j];
+
+ if (key == var_name)
+ {
+ const ForLoop::range &range = fl.ranges[j];
+
+ if (range.first != r.end() && range.first != range.second)
+ {
+ return range.first->second;
+ }
+ }
+ }
+ }
+
+ TemplateFileServer::Replacements::const_iterator it = r.find(key);
+ if (it != r.end())
+ return it->second;
+ return "";
+}
+
+TemplateFileServer::TemplateFileServer(const Anope::string &f_n) : file_name(f_n)
+{
+}
+
+void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, Replacements &r)
+{
+ int fd = open((template_base + "/" + this->file_name).c_str(), O_RDONLY);
+ if (fd < 0)
+ {
+ Log(LOG_NORMAL, "httpd") << "Error serving file " << page_name << " (" << (template_base + "/" + this->file_name) << "): " << strerror(errno);
+
+ client->SendError(HTTP_PAGE_NOT_FOUND, "Page not found");
+ return;
+ }
+
+ Anope::string buf;
+
+ int i;
+ char buffer[BUFSIZE];
+ while ((i = read(fd, buffer, sizeof(buffer) - 1)) > 0)
+ {
+ buffer[i] = 0;
+ buf += buffer;
+ }
+
+ close(fd);
+
+ Anope::string finished;
+
+ for (unsigned j = 0; j < buf.length(); ++j)
+ {
+ if (buf[j] == '{')
+ {
+ size_t f = buf.substr(j).find('}');
+ if (f == Anope::string::npos)
+ break;
+ const Anope::string &content = buf.substr(j + 1, f - 1);
+
+ if (content.find("IF ") == 0)
+ {
+ std::vector<Anope::string> tokens = BuildStringVector(content);
+
+ if (tokens.size() == 4 && tokens[1] == "EQ")
+ {
+ Anope::string first = FindReplacement(r, tokens[2]), second = FindReplacement(r, tokens[3]);
+ if (first.empty())
+ first = tokens[2];
+ if (second.empty())
+ second = tokens[3];
+
+ IfStack.push(first == second);
+ }
+ else if (tokens.size() == 3 && tokens[1] == "EXISTS")
+ IfStack.push(r.count(tokens[2]) > 0);
+ else
+ Log() << "Invalid IF in web template " << this->file_name;
+ }
+ else if (content == "ELSE")
+ {
+ if (IfStack.empty())
+ Log() << "Invalid ELSE with no stack in web template" << this->file_name;
+ else
+ {
+ bool old = IfStack.top();
+ IfStack.pop(); // Pop off previous if()
+ IfStack.push(!old); // Push back the opposite of what was popped
+ }
+ }
+ else if (content == "END IF")
+ {
+ if (IfStack.empty())
+ Log() << "END IF with empty stack?";
+ else
+ IfStack.pop();
+ }
+ else if (content.find("FOR ") == 0)
+ {
+ std::vector<Anope::string> tokens = BuildStringVector(content);
+ if (tokens.size() != 4 || tokens[2] != "IN")
+ Log() << "Invalid FOR in web template " << this->file_name;
+ else
+ {
+ std::vector<Anope::string> temp_variables = BuildStringVector(tokens[1], ','),
+ real_variables = BuildStringVector(tokens[3], ',');
+ if (temp_variables.size() != real_variables.size())
+ Log() << "Invalid FOR in web template " << this->file_name << " variable mismatch";
+ else
+ ForLoop::Stack.push_back(ForLoop(j + f, r, temp_variables, real_variables));
+ }
+ }
+ else if (content == "END FOR")
+ {
+ if (ForLoop::Stack.empty())
+ Log() << "END FOR with empty stack?";
+ else
+ {
+ ForLoop &fl = ForLoop::Stack.back();
+ if (fl.finished(r))
+ ForLoop::Stack.pop_back();
+ else
+ {
+ fl.increment(r);
+ if (fl.finished(r))
+ ForLoop::Stack.pop_back();
+ else
+ {
+ j = fl.start; // Move pointer back to start of the loop
+ continue; // To prevent skipping over this block which doesn't exist anymore
+ }
+ }
+ }
+ }
+ else if (content.find("INCLUDE ") == 0)
+ {
+ std::vector<Anope::string> tokens = BuildStringVector(content);
+ if (tokens.size() != 2)
+ Log() << "Invalid INCLUDE in web template " << this->file_name;
+ else
+ {
+ reply.Write(finished); // Write out what we have currently so we insert this files contents here
+ finished.clear();
+
+ TemplateFileServer tfs(tokens[1]);
+ tfs.Serve(server, page_name, client, message, reply, r);
+ }
+ }
+ else
+ {
+ // If the if stack is empty or we are in a true statement
+ bool ifok = IfStack.empty() || IfStack.top();
+ bool forok = ForLoop::Stack.empty() || !ForLoop::Stack.back().finished(r);
+
+ if (ifok && forok)
+ {
+ const Anope::string &replacement = FindReplacement(r, content.substr(0, f - 1));
+ finished += replacement;
+ }
+ }
+
+ j += f; // Skip over this whole block
+ }
+ else
+ {
+ // If the if stack is empty or we are in a true statement
+ bool ifok = IfStack.empty() || IfStack.top();
+ bool forok = ForLoop::Stack.empty() || !ForLoop::Stack.back().finished(r);
+
+ if (ifok && forok)
+ finished += buf[j];
+ }
+ }
+
+ reply.Write(finished);
+}
+
diff --git a/modules/extra/webcpanel/template_fileserver.h b/modules/extra/webcpanel/template_fileserver.h
new file mode 100644
index 000000000..58d6a4872
--- /dev/null
+++ b/modules/extra/webcpanel/template_fileserver.h
@@ -0,0 +1,27 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "../httpd.h"
+
+/* A basic file server. Used for serving non-static non-binary content on disk. */
+class TemplateFileServer
+{
+ Anope::string file_name;
+ public:
+ struct Replacements : std::multimap<Anope::string, Anope::string>
+ {
+ Anope::string& operator[](const Anope::string &key)
+ {
+ return insert(std::make_pair(key, ""))->second;
+ }
+ };
+
+ TemplateFileServer(const Anope::string &f_n);
+
+ void Serve(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, Replacements &);
+};
+
diff --git a/modules/extra/webcpanel/templates/default/chanserv/access.html b/modules/extra/webcpanel/templates/default/chanserv/access.html
new file mode 100644
index 000000000..13c0ba82b
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/chanserv/access.html
@@ -0,0 +1,52 @@
+{INCLUDE header.html}
+ {FOR M IN MESSAGES}
+ {M}<br/>
+ {END FOR}
+ {IF EXISTS ACCESSES}
+ <b>Access List</b></br>
+ <table width="100%" height="100%">
+ <tr>
+ <th>Mask</th>
+ <th>Access</th>
+ <th>Creator</th>
+ </tr>
+ {FOR MASK,ACCESS,CREATOR,ACCESS_CHANGE IN MASKS,ACCESSES,CREATORS,ACCESS_CHANGES}
+ <tr>
+ <td>{MASK}</td>
+ <td>{ACCESS}</td>
+ <td>{CREATOR}</td>
+ {IF EQ ACCESS_CHANGE YES}
+ <td><a href="/chanserv/access?channel={ESCAPED_CHANNEL}&mask={MASK}&del=1">Delete</a></td>
+ {END IF}
+ </tr>
+ {END FOR}
+ </table>
+ {ELSE}
+ <b>Access list is empty.</b>
+ {END IF}
+
+ <br/><br/>
+
+ <b>Add an access entry</b><br/>
+ <form method="post" action="/chanserv/access?channel={ESCAPED_CHANNEL}">
+ <table width="100%" height="100%">
+ <tr>
+ <th>Mask</th>
+ <th>Access</th>
+ <th>Provider</th>
+ </tr>
+ <tr>
+ <td><input type="text" name="mask"></td>
+ <td><input type="text" name="access"></td>
+ <td>
+ <select name="provider">
+ {FOR PROVIDER IN PROVIDERS}
+ <option value="{PROVIDER}">{PROVIDER}</option>
+ {END FOR}
+ </select>
+ </td>
+ </tr>
+ </table>
+ <input type="submit" value="Add">
+ </form>
+{INCLUDE footer.html}
diff --git a/modules/extra/webcpanel/templates/default/chanserv/akick.html b/modules/extra/webcpanel/templates/default/chanserv/akick.html
new file mode 100644
index 000000000..23c1c1efd
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/chanserv/akick.html
@@ -0,0 +1,42 @@
+{INCLUDE header.html}
+ {FOR M IN MESSAGES}
+ {M}<br/>
+ {END FOR}
+ {IF EXISTS MASKS}
+ <b>Akick List</b></br>
+ <table width="100%" height="100%">
+ <tr>
+ <th>Mask</th>
+ <th>Creator</th>
+ <th>Reason</th>
+ </tr>
+ {FOR MASK,CREATOR,REASON IN MASKS,CREATORS,REASONS}
+ <tr>
+ <td>{MASK}</td>
+ <td>{CREATOR}</td>
+ <td>{REASON}</td>
+ <td><a href="/chanserv/akick?channel={ESCAPED_CHANNEL}&mask={MASK}&del=1">Delete</a></td>
+ </tr>
+ {END FOR}
+ </table>
+ {ELSE}
+ <b>Akick list is empty.</b>
+ {END IF}
+
+ <br/><br/>
+
+ <b>Add an akick entry</b><br/>
+ <form method="post" action="/chanserv/akick?channel={ESCAPED_CHANNEL}">
+ <table width="100%" height="100%">
+ <tr>
+ <th>Mask</th>
+ <th>Reason</th>
+ </tr>
+ <tr>
+ <td><input type="text" name="mask"></td>
+ <td><input type="text" name="access"></td>
+ </tr>
+ </table>
+ <input type="submit" value="Add">
+ </form>
+{INCLUDE footer.html}
diff --git a/modules/extra/webcpanel/templates/default/chanserv/main.html b/modules/extra/webcpanel/templates/default/chanserv/main.html
new file mode 100644
index 000000000..99fec7d75
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/chanserv/main.html
@@ -0,0 +1,6 @@
+{INCLUDE header.html}
+ <b>Channels you have access in:</b><br/>
+ {FOR CH,ECH IN CHANNEL_NAMES,ESCAPED_CHANNEL_NAMES}
+ <a href="/chanserv/set?channel={ECH}">{CH}</a></br>
+ {END FOR}
+{INCLUDE footer.html}
diff --git a/modules/extra/webcpanel/templates/default/chanserv/set.html b/modules/extra/webcpanel/templates/default/chanserv/set.html
new file mode 100644
index 000000000..ec2a33929
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/chanserv/set.html
@@ -0,0 +1,100 @@
+{INCLUDE header.html}
+ {FOR M IN MESSAGES}
+ {M}<br/>
+ {END FOR}
+ <form method="post" action="/chanserv/set?channel={CHANNEL_ESCAPED}">
+ <table width="100%" height="100%">
+ <tr>
+ <td>Channel Name</td>
+ <td>{CHANNEL}</td>
+ </tr>
+ {IF EXISTS FOUNDER}
+ <tr>
+ <td>Founder</td>
+ <td>{FOUNDER}</td>
+ </tr>
+ {END IF}
+ {IF EXISTS SUCCESSOR}
+ <tr>
+ <td>Succsesor</td>
+ <td>{SUCCESSOR}</td>
+ </tr>
+ {END IF}
+ <tr>
+ <td>Time registered</td>
+ <td>{TIME_REGISTERED</td>
+ </tr>
+ <tr>
+ <td>Last used</td>
+ <td>{LAST_USED}</td>
+ </tr>
+ {IF EXISTS LAST_TOPIC}
+ <tr>
+ <td>Last topic</td>
+ <td>{LAST_TOPIC}</td>
+ </tr>
+ <tr>
+ <td>Set by</td>
+ <td>{LAST_TOPIC_SETTER}</td>
+ </tr>
+ {END IF}
+ <tr>
+ <td>Keep topic</td>
+ {IF EXISTS KEEPTOPIC}
+ <td><input type="checkbox" name="keeptopic" value="on" checked></td>
+ {ELSE}
+ <td><input type="checkbox" name="keeptopic" value="on"></td>
+ {END IF}
+ </tr>
+ <tr>
+ <td>Peace</td>
+ {IF EXISTS PEACE}
+ <td><input type="checkbox" name="peace" value="on" checked></td>
+ {ELSE}
+ <td><input type="checkbox" name="peace" value="on"></td>
+ {END IF}
+ </tr>
+ <tr>
+ <td>Private</td>
+ {IF EXISTS PRIVATE}
+ <td><input type="checkbox" name="private" value="on" checked></td>
+ {ELSE}
+ <td><input type="checkbox" name="private" value="on"></td>
+ {END IF}
+ </tr>
+ <tr>
+ <td>Restricted</td>
+ {IF EXISTS RESTRICTED}
+ <td><input type="checkbox" name="restricted" value="on" checked></td>
+ {ELSE}
+ <td><input type="checkbox" name="restricted" value="on"></td>
+ {END IF}
+ </tr>
+ <tr>
+ <td>Secure</td>
+ {IF EXISTS SECURE}
+ <td><input type="checkbox" name="secure" value="on" checked></td>
+ {ELSE}
+ <td><input type="checkbox" name="secure" value="on"></td>
+ {END IF}
+ </tr>
+ <tr>
+ <td>Secure Ops</td>
+ {IF EXISTS SECUREOPS}
+ <td><input type="checkbox" name="secureops" value="on" checked></td>
+ {ELSE}
+ <td><input type="checkbox" name="secureops" value="on"></td>
+ {END IF}
+ </tr>
+ <tr>
+ <td>Topic Lock</td>
+ {IF EXISTS TOPICLOCK}
+ <td><input type="checkbox" name="topiclock" value="on" checked></td>
+ {ELSE}
+ <td><input type="checkbox" name="topiclock" value="on"></td>
+ {END IF}
+ </tr>
+ </table>
+ <input type="submit" value="Save">
+ </form>
+{INCLUDE footer.html}
diff --git a/modules/extra/webcpanel/templates/default/confirm.html b/modules/extra/webcpanel/templates/default/confirm.html
new file mode 100644
index 000000000..918ccd971
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/confirm.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <link href="/static/style.css" media="screen" rel="stylesheet" type="text/css" />
+ <title>{TITLE}</title>
+</head>
+<body>
+ <div class="master">
+ <div class="header">
+ <div class="loggedinas"><a href="/">Home</a></div>
+ </div>
+ <table width="100%" height="100%">
+ <tr>
+ <td>
+ <center>
+ <img src="static/logo.png"/>
+ <br/>
+ {FOR M IN MESSAGES}
+ {M}<br/>
+ {END FOR}
+ </center>
+ </td>
+ </tr>
+ </table>
+ </div>
+ <div class="footer">
+ Anope IRC Services - &copy; 2012 Anope Team - <a href="http://anope.org">http://anope.org</a>
+ </div>
+</body>
+</html>
diff --git a/modules/extra/webcpanel/templates/default/favicon.ico b/modules/extra/webcpanel/templates/default/favicon.ico
new file mode 100644
index 000000000..be735614a
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/favicon.ico
Binary files differ
diff --git a/modules/extra/webcpanel/templates/default/footer.html b/modules/extra/webcpanel/templates/default/footer.html
new file mode 100644
index 000000000..65d23402a
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/footer.html
@@ -0,0 +1,7 @@
+ </div>
+ </div>
+ <div class="footer">
+ Anope IRC Services - &copy; 2012 Anope Team - <a href="http://anope.org">http://anope.org</a>
+ </div>
+</body>
+</html>
diff --git a/modules/extra/webcpanel/templates/default/header.html b/modules/extra/webcpanel/templates/default/header.html
new file mode 100644
index 000000000..38f367acc
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/header.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <link href="/static/style.css" media="screen" rel="stylesheet" type="text/css" />
+ <title>{TITLE}</title>
+</head>
+<body>
+ <div class="master">
+ <div class="header">
+ <ul id="button">
+ {FOR CATEGORY_URL,CATEGORY_NAME IN CATEGORY_URLS,CATEGORY_NAMES}
+ <li><a href="{CATEGORY_URL}">{CATEGORY_NAME}</a></li>
+ {END FOR}
+ </ul>
+ <div class="loggedinas">Logged in as {ACCOUNT} <a href="/logout">(Logout)</a></div>
+ </div>
+ <div class="sidebar">
+ <ul class="sidenav">
+ {FOR SUBCATEGORY_URL,SUBCATEGORY_GET,SUBCATEGORY_NAME IN SUBCATEGORY_URLS,SUBCATEGORY_GETS,SUBCATEGORY_NAMES}
+ <li><a href="{SUBCATEGORY_URL}{SUBCATEGORY_GET}">{SUBCATEGORY_NAME}</a></li>
+ {END FOR}
+ </ul>
+ </div>
+ <div class="content">
diff --git a/modules/extra/webcpanel/templates/default/login.html b/modules/extra/webcpanel/templates/default/login.html
new file mode 100644
index 000000000..7aa54aa9c
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/login.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <link href="/static/style.css" media="screen" rel="stylesheet" type="text/css" />
+ <title>{TITLE}</title>
+</head>
+<body>
+ <div class="master">
+ <div class="header">
+ <div class="loggedinas"><a href="/register">Register</a></div>
+ </div>
+ <table width="100%" height="100%">
+ <tr>
+ <td>
+ <center>
+ <img src="static/logo.png"/>
+ <br>
+ <h2>Login</h2>
+ {INVALID_LOGIN}<br>
+ Login to continue.
+ <br>
+ <form action="/" method="post">
+ <table>
+ <tr>
+ <td><div align="right">Username:</div></td>
+ <td><div align="left"><input name="username"/></div></td>
+ </tr>
+ <tr>
+ <td><div align="right">Password:</div></td>
+ <td><div align="left"><input name="password" type="password"/></div></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td><div align="left"><input type="submit" value="Login"/></div></td>
+ </tr>
+ </table>
+ </form>
+ </center>
+ </td>
+ </tr>
+ </table>
+ </div>
+ <div class="footer">
+ Anope IRC Services - &copy; 2012 Anope Team - <a href="http://anope.org">http://anope.org</a>
+ </div>
+</body>
+</html>
diff --git a/modules/extra/webcpanel/templates/default/logo.png b/modules/extra/webcpanel/templates/default/logo.png
new file mode 100644
index 000000000..1ab5546c6
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/logo.png
Binary files differ
diff --git a/modules/extra/webcpanel/templates/default/memoserv/memos.html b/modules/extra/webcpanel/templates/default/memoserv/memos.html
new file mode 100644
index 000000000..559efd35b
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/memoserv/memos.html
@@ -0,0 +1,50 @@
+{INCLUDE header.html}
+ <b>Channels you have access in:</b><br/>
+ {FOR CH,ECH IN CHANNEL_NAMES,ESCAPED_CHANNEL_NAMES}
+ <a href="/memoserv/memos?channel={ECH}">{CH}</a>
+ {END FOR}
+ <br/><br/>
+ {FOR M IN MESSAGES}
+ {M}</br>
+ {END FOR}
+ <br/>
+ {IF EXISTS NUMBER}
+ <b>Memos List:</b>
+ <table width="100%" height="100%">
+ <tr>
+ <th>Number</th>
+ <th>Sender</th>
+ <th>Time/Message</th>
+ </tr>
+ {FOR I,S,T,TXT,U IN NUMBER,SENDER,TIME,TEXT,UNREAD}
+ <tr>
+ <td>{I}</td>
+ <td>{S}</td>
+ <td>{T}</td>
+ {IF EQ U YES}
+ <td><a href="/memoserv/memos?channel={ESCAPED_CHANNEL_NAME}&number={I}&read=1">Mark as Read</a></td>
+ {ELSE}
+ <td><a href="/memoserv/memos?channel={ESCAPED_CHANNEL_NAME}&number={I}&read=2">Mark as Unread</a></td>
+ {END IF}
+ <td><a href="/memoserv/memos?channel={ESCAPED_CHANNEL_NAME}&number={I}&del=1">Delete</a></td>
+
+ </tr>
+ <tr>
+ <td></td><td></td>
+ <td>{TXT}</td>
+ </tr>
+ {END FOR}
+ </table>
+ {ELSE}
+ <b>No memos to show.</b>
+ {END IF}
+
+ <br/><br/>
+
+ <b>Send a new Memo</b>
+ <form method="post" action="/memoserv/memos?channel={ESCAPED_CHANNEL}">
+ Receiver: <input type="text" name="receiver">
+ Message: <input type="text" name="message">
+ <input type="submit" value="Send">
+ </form>
+{INCLUDE footer.html}
diff --git a/modules/extra/webcpanel/templates/default/nickserv/access.html b/modules/extra/webcpanel/templates/default/nickserv/access.html
new file mode 100644
index 000000000..9948c3694
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/nickserv/access.html
@@ -0,0 +1,24 @@
+{INCLUDE header.html}
+ {FOR M IN MESSAGES}
+ {M}</br>
+ {END FOR}
+ {IF EXISTS ACCESS}
+ <b>Your access list:</b>
+ <table width="100%" height="100%">
+ {FOR A IN ACCESS}
+ <tr>
+ <td>{A}</td>
+ <td><a href="/nickserv/access?mask={A}&del=1">Delete</a></td>
+ </tr>
+ {END FOR}
+ </table>
+ {ELSE}
+ <b>Your access list is empty.</b>
+ {END IF}
+ <br/><br/>
+ <b>Add an access entry:</b>
+ <form method="post" action="/nickserv/access">
+ <input name="access">
+ <input type="submit" value="Add">
+ </form>
+{INCLUDE footer.html}
diff --git a/modules/extra/webcpanel/templates/default/nickserv/alist.html b/modules/extra/webcpanel/templates/default/nickserv/alist.html
new file mode 100644
index 000000000..e36143458
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/nickserv/alist.html
@@ -0,0 +1,16 @@
+{INCLUDE header.html}
+ <table>
+ <tr>
+ <th>Number</th>
+ <th>Channel</th>
+ <th>Access</th>
+ </tr>
+ {FOR N,C,A IN NUMBERS,CHANNELS,ACCESSES}
+ <tr>
+ <td>{N}</td>
+ <td>{C}</td>
+ <td>{A}</td>
+ </tr>
+ {END FOR}
+ </table>
+{INCLUDE footer.html}
diff --git a/modules/extra/webcpanel/templates/default/nickserv/cert.html b/modules/extra/webcpanel/templates/default/nickserv/cert.html
new file mode 100644
index 000000000..31f12b883
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/nickserv/cert.html
@@ -0,0 +1,19 @@
+{INCLUDE header.html}
+ {FOR M IN MESSAGES}
+ {M}</br>
+ {END FOR}
+ <b>Your certificate finrgerprints:</b>
+ <table width="100%" height="100%">
+ {FOR CERT IN CERTS}
+ <tr>
+ <td>{CERT}</td>
+ <td><a href="/nickserv/cert?mask={CERT}&del=1">Delete</a></td>
+ </tr>
+ {END FOR}
+ </table>
+ <b>Add an certificate fingerprint</b>
+ <form method="post" action="/nickserv/cert">
+ <input name="certfp">
+ <input type="submit" value="Add">
+ </form>
+{INCLUDE footer.html}
diff --git a/modules/extra/webcpanel/templates/default/nickserv/info.html b/modules/extra/webcpanel/templates/default/nickserv/info.html
new file mode 100644
index 000000000..1dd051364
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/nickserv/info.html
@@ -0,0 +1,82 @@
+{INCLUDE header.html}
+ {FOR M IN ERRORS}
+ {M}<br/>
+ {END FOR}
+ {FOR M IN MESSAGES}
+ {M}<br/>
+ {END FOR}
+ <b>Your account information:</b>
+ <form method="post" action="/nickserv/info">
+ <table width="100%" height="100%">
+ <tr>
+ <td>Account:</td>
+ <td>{DISPLAY}</td>
+ </tr>
+ {IF EXISTS EMAIL}
+ <tr>
+ <td>EMail</td>
+ <td>{EMAIL}</td>
+ </tr>
+ {END IF}
+ <tr>
+ <td>Time registered</td>
+ <td>{TIME_REGISTERED}</td>
+ </tr>
+ {IF EXISTS VHOST}
+ <tr>
+ <td>Vhost</td>
+ <td>{VHOST}</td>
+ </tr>
+ {END IF}
+ <tr>
+ <td>Greet</td>
+ <td><input name="greet" value="{GREET}"></td>
+ </tr>
+ <tr>
+ <td>Auto op</td>
+ {IF EXISTS AUTOOP}
+ <td><input type="checkbox" name="autoop" value="on" checked></td>
+ {ELSE}
+ <td><input type="checkbox" name="autoop" value="on"></td>
+ {END IF}
+ </tr>
+ <tr>
+ <td>Private</td>
+ {IF EXISTS PRIVATE}
+ <td><input type="checkbox" name="private" value="on" checked></td>
+ {ELSE}
+ <td><input type="checkbox" name="private" value="on"></td>
+ {END IF}
+ </tr>
+ <tr>
+ <td>Secure</td>
+ {IF EXISTS SECURE}
+ <td><input type="checkbox" name="secure" value="on" checked></td>
+ {ELSE}
+ <td><input type="checkbox" name="secure" value="on"></td>
+ {END IF}
+ </tr>
+ <tr>
+ <td>Kill</td>
+ <td><select name="kill">
+ {IF EXISTS KILL_ON}
+ <option value="on" selected>On</option>
+ {ELSE}
+ <option value="on">On</option>
+ {END IF}
+ {IF EXISTS KILL_QUICK}
+ <option value="quick" selected>Quick</option>
+ {ELSE}
+ <option value="quick">Quick</option>
+ {END IF}
+ {IF EXISTS KILL_OFF}
+ <option value="off" selected>Off</option>
+ {ELSE}
+ <option value="off">Off</option>
+ {END IF}
+ </select></td>
+ </tr>
+ </table>
+ <input type="submit" value="Save">
+ </form>
+{INCLUDE footer.html}
diff --git a/modules/extra/webcpanel/templates/default/register.html b/modules/extra/webcpanel/templates/default/register.html
new file mode 100644
index 000000000..8f6a5296a
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/register.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <link href="/static/style.css" media="screen" rel="stylesheet" type="text/css" />
+ <title>{TITLE}</title>
+</head>
+<body>
+ <div class="master">
+ <div class="header">
+ <div class="loggedinas"><a href="/">Home</a></div>
+ </div>
+ <table width="100%" height="100%">
+ <tr>
+ <td>
+ <center>
+ <img src="static/logo.png"/>
+ {MESSAGES}
+ <br>
+ <h2>Register</h2>
+ <br>
+ Fill out the following form to register.
+ <form action="/confirm" method="post">
+ <table>
+ <tr>
+ <td><div align="right">Username:</div></td>
+ <td><div align="left"><input name="username"/></div></td>
+ </tr>
+ <tr>
+ <td><div align="right">Password:</div></td>
+ <td><div align="left"><input name="password" type="password"/></div></td>
+ </tr>
+ <tr>
+ <td><div align="right">Email</div></td>
+ <td><div align="left"><input type="{EMAIL_TYPE}" name="email"></div></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td><div align="left"><input type="submit" value="Register"/></div></td>
+ </tr>
+ </table>
+ </form>
+ </center>
+ </td>
+ </tr>
+ </table>
+ </div>
+ <div class="footer">
+ Anope IRC Services - &copy; 2012 Anope Team - <a href="http://anope.org">http://anope.org</a>
+ </div>
+</body>
+</html>
diff --git a/modules/extra/webcpanel/templates/default/style.css b/modules/extra/webcpanel/templates/default/style.css
new file mode 100644
index 000000000..78c044995
--- /dev/null
+++ b/modules/extra/webcpanel/templates/default/style.css
@@ -0,0 +1,97 @@
+html {
+font-family: 'Cabin', Helvetica, Arial, sans-serif;
+}
+body {
+ overflow:hidden;
+}
+.master {
+ margin-left:0px;
+ margin-right:0px;
+ height:100%;
+ background: #FFF;
+ border-width: 1px;
+ border-style: solid;
+ overflow: hidden;
+}
+.header {
+ height: 33px;
+ padding-left: 5px;
+ width: auto;
+ background: #EEE;
+ border-width: 1px;
+ border-bottom-style: solid;
+}
+.sidebar {
+ width: 185px;
+ background: #EEE;
+ height: 500px;
+ border-width: 1px;
+ border-right-style: solid;
+ padding-top:15px;
+ padding-left:15px;
+}
+
+.loggedinas {
+ right:15px;
+ top:15px;
+ position:absolute;
+}
+
+#button {
+ padding: 0;
+ height:30px;
+ margin: 0px;
+ padding-bottom: 2px;
+}
+#button li {
+ display: inline;
+}
+
+#button li a {
+ font-family: Arial;
+ font-size:11px;
+ text-decoration: none;
+ float:left;
+ padding: 10px;
+ background-color: #EEE;
+ height:13px;
+ color: #000;
+}
+#button li a:hover {
+ background-color: #A8BEE3;
+ padding-bottom:10px;
+}
+#a.current {
+ color:navy;
+}
+
+.content {
+ left:220px;
+ top:50px;
+ position:absolute;
+}
+
+.footer {
+ margin-left:auto;
+ margin-right:auto;
+ text-align:center;
+ height: 30px;
+ width:100%;
+ background: #FFF;
+ overflow: hidden;
+}
+
+.sidenav {
+ list-style-type: none;
+ background: #EEE
+}
+
+.sidenav a {
+ color:black;
+ text-decoration:none;
+}
+.sidenav a:hover{
+ color:black;
+ background:#FFF;
+ text-decoration:underline;
+}
diff --git a/modules/extra/webcpanel/webcpanel.cpp b/modules/extra/webcpanel/webcpanel.cpp
new file mode 100644
index 000000000..4970845cd
--- /dev/null
+++ b/modules/extra/webcpanel/webcpanel.cpp
@@ -0,0 +1,209 @@
+/*
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "webcpanel.h"
+
+Anope::string provider_name, template_name, template_base, page_title;
+
+class ModuleWebCPanel : public Module
+{
+ Panel panel;
+
+ StaticFileServer style_css, logo_png, favicon_ico;
+
+ WebCPanel::Index index;
+ WebCPanel::Logout logout;
+ WebCPanel::Register _register;
+ WebCPanel::Confirm confirm;
+
+ WebCPanel::NickServ::Info nickserv_info;
+ WebCPanel::NickServ::Cert nickserv_cert;
+ WebCPanel::NickServ::Access nickserv_access;
+ WebCPanel::NickServ::Alist nickserv_alist;
+
+ WebCPanel::ChanServ::Info chanserv_info;
+ WebCPanel::ChanServ::Set chanserv_set;
+ WebCPanel::ChanServ::Access chanserv_access;
+ WebCPanel::ChanServ::Akick chanserv_akick;
+
+ WebCPanel::MemoServ::Memos memoserv_memos;
+
+ public:
+ ModuleWebCPanel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED),
+ panel(this, "webcpanel"),
+ style_css("style.css", "/static/style.css", "text/css"), logo_png("logo.png", "/static/logo.png", "image/png"), favicon_ico("favicon.ico", "/favicon.ico", "image/x-icon"),
+ index("/"), logout("/logout"), _register("/register"), confirm("/confirm"),
+ nickserv_info(Config->NickServ, "/nickserv/info"), nickserv_cert(Config->NickServ, "/nickserv/cert"), nickserv_access(Config->NickServ, "/nickserv/access"), nickserv_alist(Config->NickServ, "/nickserv/alist"),
+ chanserv_info(Config->ChanServ, "/chanserv/info"), chanserv_set(Config->ChanServ, "/chanserv/set"), chanserv_access(Config->ChanServ, "/chanserv/access"), chanserv_akick(Config->ChanServ, "/chanserv/akick"),
+ memoserv_memos(Config->MemoServ, "/memoserv/memos")
+ {
+ this->SetAuthor("Anope");
+
+ ConfigReader reader;
+ provider_name = reader.ReadValue("webcpanel", "server", "httpd/main", 0);
+ template_name = reader.ReadValue("webcpanel", "template", "template", 0);
+ template_base = db_dir + "/modules/webcpanel/templates/" + template_name;
+ page_title = reader.ReadValue("webcpanel", "title", "Anope IRC Services", 0);
+
+ service_reference<HTTPProvider> provider("HTTPProvider", provider_name);
+ if (!provider)
+ throw ModuleException("Unable to find HTTPD provider. Is m_httpd loaded?");
+
+ provider->RegisterPage(&this->style_css);
+ provider->RegisterPage(&this->logo_png);
+ provider->RegisterPage(&this->favicon_ico);
+
+ provider->RegisterPage(&this->index);
+ provider->RegisterPage(&this->logout);
+ provider->RegisterPage(&this->_register);
+ provider->RegisterPage(&this->confirm);
+
+ if (Config->NickServ.empty() == false)
+ {
+ Section s;
+ s.name = Config->NickServ;
+
+ SubSection ss;
+ ss.name = "Information";
+ ss.url = "/nickserv/info";
+ s.subsections.push_back(ss);
+ provider->RegisterPage(&this->nickserv_info);
+
+ if (ircd && ircd->certfp)
+ {
+ ss.name = "SSL Certificates";
+ ss.url = "/nickserv/cert";
+ s.subsections.push_back(ss);
+ provider->RegisterPage(&this->nickserv_cert);
+ }
+
+ ss.name = "Access";
+ ss.url = "/nickserv/access";
+ s.subsections.push_back(ss);
+ provider->RegisterPage(&this->nickserv_access);
+
+ ss.name = "AList";
+ ss.url = "/nickserv/alist";
+ s.subsections.push_back(ss);
+ provider->RegisterPage(&this->nickserv_alist);
+
+ panel.sections.push_back(s);
+ }
+ if (Config->ChanServ.empty() == false)
+ {
+ Section s;
+ s.name = Config->ChanServ;
+
+ SubSection ss;
+ ss.name = "Channels";
+ ss.url = "/chanserv/info";
+ s.subsections.push_back(ss);
+ provider->RegisterPage(&this->chanserv_info);
+
+ ss.name = "Settings";
+ ss.url = "/chanserv/set";
+ s.subsections.push_back(ss);
+ provider->RegisterPage(&this->chanserv_set);
+
+ ss.name = "Access";
+ ss.url = "/chanserv/access";
+ s.subsections.push_back(ss);
+ provider->RegisterPage(&this->chanserv_access);
+
+ ss.name = "Akick";
+ ss.url = "/chanserv/akick";
+ s.subsections.push_back(ss);
+ provider->RegisterPage(&this->chanserv_akick);
+
+ panel.sections.push_back(s);
+ }
+
+ if (Config->MemoServ.empty() == false)
+ {
+ Section s;
+ s.name = Config->MemoServ;
+
+ SubSection ss;
+ ss.name = "Memos";
+ ss.url = "/memoserv/memos";
+ s.subsections.push_back(ss);
+ provider->RegisterPage(&this->memoserv_memos);
+
+ panel.sections.push_back(s);
+ }
+ }
+
+ ~ModuleWebCPanel()
+ {
+ service_reference<HTTPProvider> provider("HTTPProvider", provider_name);
+ if (provider)
+ {
+ provider->UnregisterPage(&this->style_css);
+ provider->UnregisterPage(&this->logo_png);
+ provider->UnregisterPage(&this->favicon_ico);
+
+ provider->UnregisterPage(&this->index);
+ provider->UnregisterPage(&this->logout);
+ provider->UnregisterPage(&this->_register);
+ provider->UnregisterPage(&this->confirm);
+
+ provider->UnregisterPage(&this->nickserv_info);
+ provider->UnregisterPage(&this->nickserv_cert);
+ provider->UnregisterPage(&this->nickserv_access);
+ provider->UnregisterPage(&this->nickserv_alist);
+
+ provider->UnregisterPage(&this->chanserv_info);
+ provider->UnregisterPage(&this->chanserv_set);
+ provider->UnregisterPage(&this->chanserv_access);
+ provider->UnregisterPage(&this->chanserv_akick);
+
+ provider->UnregisterPage(&this->memoserv_memos);
+ }
+ }
+};
+
+namespace WebPanel
+{
+ 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)
+ {
+ service_reference<Command> cmd("Command", c);
+ if (!cmd)
+ {
+ r["MESSAGSE"] = "Unable to find command " + c;
+ return;
+ }
+
+ BotInfo *bi = findbot(service);
+ if (!bi)
+ {
+ if (BotListByNick->empty())
+ return;
+ bi = BotListByNick->begin()->second; // Pick one...
+ }
+
+ struct MyComandReply : CommandReply
+ {
+ TemplateFileServer::Replacements &re;
+
+ MyComandReply(TemplateFileServer::Replacements &_r) : re(_r) { }
+
+ void SendMessage(const BotInfo *source, const Anope::string &msg) anope_override
+ {
+ re["MESSAGES"] = msg;
+ }
+ }
+ my_reply(r);
+
+ CommandSource source(user, NULL, nc, &my_reply);
+ source.owner = bi;
+ source.service = bi;
+
+ cmd->Execute(source, params);
+ }
+}
+
+MODULE_INIT(ModuleWebCPanel)
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