From 004c4cbe5f4c37cf455cb6d0caa434fbbb3406ea Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 2 Jan 2014 11:02:14 -0500 Subject: Move modules out of extras that dont have external dependencies --- modules/webcpanel/CMakeLists.txt | 6 + modules/webcpanel/pages/chanserv/access.cpp | 162 +++++++++++++ modules/webcpanel/pages/chanserv/access.h | 27 +++ modules/webcpanel/pages/chanserv/akick.cpp | 94 +++++++ modules/webcpanel/pages/chanserv/akick.h | 27 +++ modules/webcpanel/pages/chanserv/drop.cpp | 58 +++++ modules/webcpanel/pages/chanserv/drop.h | 25 ++ modules/webcpanel/pages/chanserv/info.cpp | 28 +++ modules/webcpanel/pages/chanserv/info.h | 25 ++ modules/webcpanel/pages/chanserv/modes.cpp | 108 +++++++++ modules/webcpanel/pages/chanserv/modes.h | 27 +++ modules/webcpanel/pages/chanserv/set.cpp | 155 ++++++++++++ modules/webcpanel/pages/chanserv/set.h | 27 +++ modules/webcpanel/pages/chanserv/utils.cpp | 45 ++++ modules/webcpanel/pages/chanserv/utils.h | 19 ++ modules/webcpanel/pages/confirm.cpp | 32 +++ modules/webcpanel/pages/confirm.h | 22 ++ modules/webcpanel/pages/hostserv/request.cpp | 36 +++ modules/webcpanel/pages/hostserv/request.h | 24 ++ modules/webcpanel/pages/index.cpp | 99 ++++++++ modules/webcpanel/pages/index.h | 22 ++ modules/webcpanel/pages/logout.cpp | 23 ++ modules/webcpanel/pages/logout.h | 20 ++ modules/webcpanel/pages/memoserv/memos.cpp | 115 +++++++++ modules/webcpanel/pages/memoserv/memos.h | 25 ++ modules/webcpanel/pages/nickserv/access.cpp | 40 +++ modules/webcpanel/pages/nickserv/access.h | 25 ++ modules/webcpanel/pages/nickserv/alist.cpp | 59 +++++ modules/webcpanel/pages/nickserv/alist.h | 25 ++ modules/webcpanel/pages/nickserv/cert.cpp | 43 ++++ modules/webcpanel/pages/nickserv/cert.h | 25 ++ modules/webcpanel/pages/nickserv/info.cpp | 118 +++++++++ modules/webcpanel/pages/nickserv/info.h | 25 ++ modules/webcpanel/pages/operserv/akill.cpp | 64 +++++ modules/webcpanel/pages/operserv/akill.h | 25 ++ modules/webcpanel/pages/register.cpp | 24 ++ modules/webcpanel/pages/register.h | 22 ++ modules/webcpanel/static_fileserver.cpp | 42 ++++ modules/webcpanel/static_fileserver.h | 19 ++ modules/webcpanel/template_fileserver.cpp | 261 ++++++++++++++++++++ modules/webcpanel/template_fileserver.h | 27 +++ .../templates/default/chanserv/access.html | 77 ++++++ .../templates/default/chanserv/akick.html | 61 +++++ .../templates/default/chanserv/chanlist.html | 17 ++ .../webcpanel/templates/default/chanserv/drop.html | 32 +++ .../webcpanel/templates/default/chanserv/main.html | 3 + .../templates/default/chanserv/modes.html | 56 +++++ .../webcpanel/templates/default/chanserv/set.html | 93 +++++++ modules/webcpanel/templates/default/confirm.html | 51 ++++ modules/webcpanel/templates/default/cubes.png | Bin 0 -> 723 bytes modules/webcpanel/templates/default/favicon.ico | Bin 0 -> 3774 bytes modules/webcpanel/templates/default/footer.html | 14 ++ modules/webcpanel/templates/default/header.html | 64 +++++ .../templates/default/hostserv/request.html | 45 ++++ modules/webcpanel/templates/default/login.html | 55 +++++ modules/webcpanel/templates/default/logo.png | Bin 0 -> 19247 bytes .../templates/default/memoserv/memos.html | 112 +++++++++ .../templates/default/nickserv/access.html | 42 ++++ .../templates/default/nickserv/alist.html | 23 ++ .../webcpanel/templates/default/nickserv/cert.html | 42 ++++ .../webcpanel/templates/default/nickserv/info.html | 72 ++++++ .../templates/default/operserv/akill.html | 77 ++++++ modules/webcpanel/templates/default/register.html | 65 +++++ modules/webcpanel/templates/default/style.css | 166 +++++++++++++ modules/webcpanel/webcpanel.cpp | 270 +++++++++++++++++++++ modules/webcpanel/webcpanel.h | 178 ++++++++++++++ 66 files changed, 3710 insertions(+) create mode 100644 modules/webcpanel/CMakeLists.txt create mode 100644 modules/webcpanel/pages/chanserv/access.cpp create mode 100644 modules/webcpanel/pages/chanserv/access.h create mode 100644 modules/webcpanel/pages/chanserv/akick.cpp create mode 100644 modules/webcpanel/pages/chanserv/akick.h create mode 100644 modules/webcpanel/pages/chanserv/drop.cpp create mode 100644 modules/webcpanel/pages/chanserv/drop.h create mode 100644 modules/webcpanel/pages/chanserv/info.cpp create mode 100644 modules/webcpanel/pages/chanserv/info.h create mode 100644 modules/webcpanel/pages/chanserv/modes.cpp create mode 100644 modules/webcpanel/pages/chanserv/modes.h create mode 100644 modules/webcpanel/pages/chanserv/set.cpp create mode 100644 modules/webcpanel/pages/chanserv/set.h create mode 100644 modules/webcpanel/pages/chanserv/utils.cpp create mode 100644 modules/webcpanel/pages/chanserv/utils.h create mode 100644 modules/webcpanel/pages/confirm.cpp create mode 100644 modules/webcpanel/pages/confirm.h create mode 100644 modules/webcpanel/pages/hostserv/request.cpp create mode 100644 modules/webcpanel/pages/hostserv/request.h create mode 100644 modules/webcpanel/pages/index.cpp create mode 100644 modules/webcpanel/pages/index.h create mode 100644 modules/webcpanel/pages/logout.cpp create mode 100644 modules/webcpanel/pages/logout.h create mode 100644 modules/webcpanel/pages/memoserv/memos.cpp create mode 100644 modules/webcpanel/pages/memoserv/memos.h create mode 100644 modules/webcpanel/pages/nickserv/access.cpp create mode 100644 modules/webcpanel/pages/nickserv/access.h create mode 100644 modules/webcpanel/pages/nickserv/alist.cpp create mode 100644 modules/webcpanel/pages/nickserv/alist.h create mode 100644 modules/webcpanel/pages/nickserv/cert.cpp create mode 100644 modules/webcpanel/pages/nickserv/cert.h create mode 100644 modules/webcpanel/pages/nickserv/info.cpp create mode 100644 modules/webcpanel/pages/nickserv/info.h create mode 100644 modules/webcpanel/pages/operserv/akill.cpp create mode 100644 modules/webcpanel/pages/operserv/akill.h create mode 100644 modules/webcpanel/pages/register.cpp create mode 100644 modules/webcpanel/pages/register.h create mode 100644 modules/webcpanel/static_fileserver.cpp create mode 100644 modules/webcpanel/static_fileserver.h create mode 100644 modules/webcpanel/template_fileserver.cpp create mode 100644 modules/webcpanel/template_fileserver.h create mode 100644 modules/webcpanel/templates/default/chanserv/access.html create mode 100644 modules/webcpanel/templates/default/chanserv/akick.html create mode 100644 modules/webcpanel/templates/default/chanserv/chanlist.html create mode 100644 modules/webcpanel/templates/default/chanserv/drop.html create mode 100644 modules/webcpanel/templates/default/chanserv/main.html create mode 100644 modules/webcpanel/templates/default/chanserv/modes.html create mode 100644 modules/webcpanel/templates/default/chanserv/set.html create mode 100644 modules/webcpanel/templates/default/confirm.html create mode 100644 modules/webcpanel/templates/default/cubes.png create mode 100644 modules/webcpanel/templates/default/favicon.ico create mode 100644 modules/webcpanel/templates/default/footer.html create mode 100644 modules/webcpanel/templates/default/header.html create mode 100644 modules/webcpanel/templates/default/hostserv/request.html create mode 100644 modules/webcpanel/templates/default/login.html create mode 100644 modules/webcpanel/templates/default/logo.png create mode 100644 modules/webcpanel/templates/default/memoserv/memos.html create mode 100644 modules/webcpanel/templates/default/nickserv/access.html create mode 100644 modules/webcpanel/templates/default/nickserv/alist.html create mode 100644 modules/webcpanel/templates/default/nickserv/cert.html create mode 100644 modules/webcpanel/templates/default/nickserv/info.html create mode 100644 modules/webcpanel/templates/default/operserv/akill.html create mode 100644 modules/webcpanel/templates/default/register.html create mode 100644 modules/webcpanel/templates/default/style.css create mode 100644 modules/webcpanel/webcpanel.cpp create mode 100644 modules/webcpanel/webcpanel.h (limited to 'modules/webcpanel') diff --git a/modules/webcpanel/CMakeLists.txt b/modules/webcpanel/CMakeLists.txt new file mode 100644 index 000000000..247973f61 --- /dev/null +++ b/modules/webcpanel/CMakeLists.txt @@ -0,0 +1,6 @@ +build_subdir(${CMAKE_CURRENT_SOURCE_DIR}) + +install(DIRECTORY templates + DESTINATION "${DB_DIR}/modules/webcpanel" +) + diff --git a/modules/webcpanel/pages/chanserv/access.cpp b/modules/webcpanel/pages/chanserv/access.cpp new file mode 100644 index 000000000..d87613ed7 --- /dev/null +++ b/modules/webcpanel/pages/chanserv/access.cpp @@ -0,0 +1,162 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" +#include "utils.h" + +WebCPanel::ChanServ::Access::Access(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + TemplateFileServer Page("chanserv/access.html"); + const Anope::string &chname = message.get_data["channel"]; + + BuildChanList(na, replacements); + + if (chname.empty()) + { + Page.Serve(server, page_name, client, message, reply, replacements); + return true; + } + + ChannelInfo *ci = ChannelInfo::Find(chname); + + if (!ci) + { + replacements["MESSAGES"] = "Channel not registered."; + Page.Serve(server, page_name, client, message, reply, replacements); + return true; + } + + 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) + { + replacements["MESSAGES"] = "Access denied."; + Page.Serve(server, page_name, client, message, reply, replacements); + return true; + } + + replacements["ACCESS_LIST"] = "YES"; + + const ChanAccess *highest = u_access.Highest(); + + if (u_access.HasPriv("ACCESS_CHANGE") || has_priv) + { + if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false) + { + std::vector params; + params.push_back(ci->name); + params.push_back("DEL"); + params.push_back(message.get_data["mask"]); + + WebPanel::RunCommand(na->nc->display, na->nc, "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::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 + delete acc; + break; + } + } + + + unsigned access_max = Config->GetModule("chanserv")->Get("accessmax", "1024"); + if (access_max && ci->GetAccessCount() >= access_max) + replacements["MESSAGES"] = "Sorry, you can only have " + stringify(access_max) + " 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->AccessUnserialize(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->AccessSerialize().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->AccessSerialize(); + } + } + } + } + } + } + + replacements["ESCAPED_CHANNEL"] = HTTPUtils::URLEncode(chname); + replacements["ACCESS_CHANGE"] = u_access.HasPriv("ACCESS_CHANGE") ? "YES" : "NO"; + + for (unsigned i = 0; i < ci->GetAccessCount(); ++i) + { + ChanAccess *access = ci->GetAccess(i); + + replacements["MASKS"] = HTTPUtils::Escape(access->mask); + replacements["ACCESSES"] = HTTPUtils::Escape(access->AccessSerialize()); + replacements["CREATORS"] = HTTPUtils::Escape(access->creator); + } + + for (std::list::const_iterator it = AccessProvider::GetProviders().begin(); it != AccessProvider::GetProviders().end(); ++it) + { + const AccessProvider *a = *it; + replacements["PROVIDERS"] = a->name; + } + + Page.Serve(server, page_name, client, message, reply, replacements); + return true; +} + +std::set WebCPanel::ChanServ::Access::GetData() +{ + std::set v; + v.insert("channel"); + return v; +} + diff --git a/modules/webcpanel/pages/chanserv/access.h b/modules/webcpanel/pages/chanserv/access.h new file mode 100644 index 000000000..7f81f2d39 --- /dev/null +++ b/modules/webcpanel/pages/chanserv/access.h @@ -0,0 +1,27 @@ +/* + * (C) 2003-2014 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); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; + + std::set GetData() anope_override; +}; + +} + +} + diff --git a/modules/webcpanel/pages/chanserv/akick.cpp b/modules/webcpanel/pages/chanserv/akick.cpp new file mode 100644 index 000000000..bff38910c --- /dev/null +++ b/modules/webcpanel/pages/chanserv/akick.cpp @@ -0,0 +1,94 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" +#include "utils.h" + +WebCPanel::ChanServ::Akick::Akick(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +bool 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"]; + TemplateFileServer Page("chanserv/akick.html"); + + BuildChanList(na, replacements); + + if (chname.empty()) + { + Page.Serve(server, page_name, client, message, reply, replacements); + return true; + } + + ChannelInfo *ci = ChannelInfo::Find(chname); + + if (!ci) + { + replacements["MESSAGES"] = "Channel not registered"; + Page.Serve(server, page_name, client, message, reply, replacements); + return true; + } + + 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) + { + replacements["MESSAGES"] = "Permission denied."; + Page.Serve(server, page_name, client, message, reply, replacements); + return true; + } + + replacements["AKICK"] = "YES"; + + if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false) + { + std::vector params; + params.push_back(ci->name); + params.push_back("DEL"); + params.push_back(message.get_data["mask"]); + + WebPanel::RunCommand(na->nc->display, na->nc, "ChanServ", "chanserv/akick", params, replacements); + } + else if (message.post_data["mask"].empty() == false) + { + std::vector 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.post_data["reason"]); + + WebPanel::RunCommand(na->nc->display, na->nc, "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); + } + + Page.Serve(server, page_name, client, message, reply, replacements); + return true; +} + +std::set WebCPanel::ChanServ::Akick::GetData() +{ + std::set v; + v.insert("channel"); + return v; +} + diff --git a/modules/webcpanel/pages/chanserv/akick.h b/modules/webcpanel/pages/chanserv/akick.h new file mode 100644 index 000000000..bd5b18132 --- /dev/null +++ b/modules/webcpanel/pages/chanserv/akick.h @@ -0,0 +1,27 @@ +/* + * (C) 2003-2014 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); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; + + std::set GetData() anope_override; +}; + +} + +} + diff --git a/modules/webcpanel/pages/chanserv/drop.cpp b/modules/webcpanel/pages/chanserv/drop.cpp new file mode 100644 index 000000000..5fa37b5a2 --- /dev/null +++ b/modules/webcpanel/pages/chanserv/drop.cpp @@ -0,0 +1,58 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" +#include "utils.h" + +WebCPanel::ChanServ::Drop::Drop(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage (cat, u) +{ +} + + +bool WebCPanel::ChanServ::Drop::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + + if (message.post_data.count("channel") > 0 && message.post_data.count("confChan") > 0) + { + if (message.post_data["channel"] == message.post_data["confChan"]) + { + std::vector params; + const Anope::string &channel = HTTPUtils::URLDecode(message.post_data["channel"]); + params.push_back(channel); + params.push_back(channel); + + WebPanel::RunCommand(na->nc->display, na->nc, "ChanServ", "chanserv/drop", params, replacements); + } + else + replacements["MESSAGES"] = "Invalid Confirmation"; + } + + std::deque queue; + na->nc->GetChannelReferences(queue); + for (unsigned i = 0; i < queue.size(); ++i) + { + ChannelInfo *ci = queue[i]; + if ((ci->HasExt("SECUREFOUNDER") ? ci->AccessFor(na->nc).founder : ci->AccessFor(na->nc).HasPriv("FOUNDER")) || (na->nc->IsServicesOper() && na->nc->o->ot->HasCommand("chanserv/drop"))) + { + replacements["CHANNEL_NAMES"] = ci->name; + replacements["ESCAPED_CHANNEL_NAMES"] = HTTPUtils::URLEncode(ci->name); + } + } + + if (message.get_data.count("channel") > 0) + { + const Anope::string &chname = message.get_data["channel"]; + + replacements["CHANNEL_DROP"] = chname; + replacements["ESCAPED_CHANNEL"] = HTTPUtils::URLEncode(chname); + } + + TemplateFileServer page("chanserv/drop.html"); + page.Serve(server, page_name, client, message, reply, replacements); + return true; + +} diff --git a/modules/webcpanel/pages/chanserv/drop.h b/modules/webcpanel/pages/chanserv/drop.h new file mode 100644 index 000000000..d418ade8f --- /dev/null +++ b/modules/webcpanel/pages/chanserv/drop.h @@ -0,0 +1,25 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + + namespace ChanServ + { + + class Drop : public WebPanelProtectedPage + { + public: + Drop(const Anope::string &cat, const Anope::string &u); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; + + }; + + } + +} diff --git a/modules/webcpanel/pages/chanserv/info.cpp b/modules/webcpanel/pages/chanserv/info.cpp new file mode 100644 index 000000000..c16c3eaec --- /dev/null +++ b/modules/webcpanel/pages/chanserv/info.cpp @@ -0,0 +1,28 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" +#include "utils.h" + +WebCPanel::ChanServ::Info::Info(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +bool WebCPanel::ChanServ::Info::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()) + replacements["ESCAPED_CHANNEL"] = HTTPUtils::URLEncode(chname); + + BuildChanList(na, replacements); + + TemplateFileServer page("chanserv/main.html"); + page.Serve(server, page_name, client, message, reply, replacements); + return true; +} + diff --git a/modules/webcpanel/pages/chanserv/info.h b/modules/webcpanel/pages/chanserv/info.h new file mode 100644 index 000000000..4302264d6 --- /dev/null +++ b/modules/webcpanel/pages/chanserv/info.h @@ -0,0 +1,25 @@ +/* + * (C) 2003-2014 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); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + +} + diff --git a/modules/webcpanel/pages/chanserv/modes.cpp b/modules/webcpanel/pages/chanserv/modes.cpp new file mode 100644 index 000000000..e3e93dd03 --- /dev/null +++ b/modules/webcpanel/pages/chanserv/modes.cpp @@ -0,0 +1,108 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" +#include "utils.h" + +WebCPanel::ChanServ::Modes::Modes(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +bool WebCPanel::ChanServ::Modes::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"]; + const Anope::string &mode = message.get_data["m"]; + TemplateFileServer Page("chanserv/modes.html"); + + BuildChanList(na, replacements); + + if (chname.empty()) + { + Page.Serve(server, page_name, client, message, reply, replacements); + return true; + } + + ChannelInfo *ci = ChannelInfo::Find(chname); + + if (!ci) + { + Page.Serve(server, page_name, client, message, reply, replacements); + return true; + } + + Channel *c = Channel::Find(chname); + + if (!c) + { + replacements["MESSAGES"] = Anope::printf(CHAN_X_NOT_IN_USE, chname.c_str()); + Page.Serve(server, page_name, client, message, reply, replacements); + return true; + } + + AccessGroup u_access = ci->AccessFor(na->nc); + bool has_priv = na->nc->IsServicesOper() && na->nc->o->ot->HasPriv("chanserv/administration"); + + if (!u_access.HasPriv("MODE") && !has_priv) + { + replacements["MESSAGES"] = "Access denied."; + Page.Serve(server, page_name, client, message, reply, replacements); + return true; + } + + replacements["MODE"] = "YES"; + + /* build a list with the names of all listmodes */ + for (std::vector::const_iterator it = ModeManager::GetChannelModes().begin(); it != ModeManager::GetChannelModes().end(); ++it) + { + /* "NAMEBASE" is a special mode from InspIRCds m_namedmodes, we dont want this here*/ + if ((*it) && (*it)->type == MODE_LIST && (*it)->name != "NAMEBASE") + replacements["LISTMODES"] = (*it)->mchar; + } + + ChannelMode *cm = ModeManager::FindChannelModeByName(mode); + if (cm) + { + if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false) + { + std::vector params; + params.push_back(ci->name); + params.push_back("SET"); + params.push_back("-" + Anope::string(cm->mchar)); + params.push_back(message.get_data["mask"]); + WebPanel::RunCommand(na->nc->display, na->nc, "ChanServ", "chanserv/mode", params, replacements); + } + else if (message.post_data["mask"].empty() == false) + { + std::vector params; + params.push_back(ci->name); + params.push_back("SET"); + params.push_back("+" + Anope::string(cm->mchar)); + params.push_back(message.post_data["mask"]); + WebPanel::RunCommand(na->nc->display, na->nc, "ChanServ", "chanserv/mode", params, replacements); + } + + for (Channel::ModeList::const_iterator it = c->GetModes().begin(); it != c->GetModes().end(); ++it) + { + if (it->first == mode) + replacements["MASKS"] = HTTPUtils::Escape(it->second); + } + } + + replacements["ESCAPED_CHANNEL"] = HTTPUtils::URLEncode(chname); + replacements["ESCAPED_MODE"] = HTTPUtils::URLEncode(mode); + + Page.Serve(server, page_name, client, message, reply, replacements); + return true; +} + +std::set WebCPanel::ChanServ::Modes::GetData() +{ + std::set v; + v.insert("channel"); + return v; +} + diff --git a/modules/webcpanel/pages/chanserv/modes.h b/modules/webcpanel/pages/chanserv/modes.h new file mode 100644 index 000000000..36f5a1d27 --- /dev/null +++ b/modules/webcpanel/pages/chanserv/modes.h @@ -0,0 +1,27 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + +namespace ChanServ +{ + +class Modes : public WebPanelProtectedPage +{ + public: + Modes(const Anope::string &cat, const Anope::string &u); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; + + std::set GetData() anope_override; +}; + +} + +} + diff --git a/modules/webcpanel/pages/chanserv/set.cpp b/modules/webcpanel/pages/chanserv/set.cpp new file mode 100644 index 000000000..f763ba13b --- /dev/null +++ b/modules/webcpanel/pages/chanserv/set.cpp @@ -0,0 +1,155 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" +#include "utils.h" + +WebCPanel::ChanServ::Set::Set(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +bool 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"]; + bool can_set = false; + TemplateFileServer page("chanserv/set.html"); + + BuildChanList(na, replacements); + + if (chname.empty()) + { + page.Serve(server, page_name, client, message, reply, replacements); + return true; + } + + ChannelInfo *ci = ChannelInfo::Find(chname); + + if (!ci) + { + page.Serve(server, page_name, client, message, reply, replacements); + return true; + } + + replacements["OKAY"]; + + if (ci->AccessFor(na->nc).HasPriv("SET")) + { + replacements["CAN_SET"]; + can_set = true; + } + + if (can_set && message.post_data.empty() == false) + { + if (ci->HasExt("KEEPTOPIC") != message.post_data.count("keeptopic")) + { + if (!ci->HasExt("KEEPTOPIC")) + ci->Extend("KEEPTOPIC"); + else + ci->Shrink("KEEPTOPIC"); + replacements["MESSAGES"] = "Secure updated"; + } + if (ci->HasExt("PEACE") != message.post_data.count("peace")) + { + if (!ci->HasExt("PEACE")) + ci->Extend("PEACE"); + else + ci->Shrink("PEACE"); + replacements["MESSAGES"] = "Peace updated"; + } + if (ci->HasExt("CS_PRIVATE") != message.post_data.count("private")) + { + if (!ci->HasExt("CS_PRIVATE")) + ci->Extend("CS_PRIVATE"); + else + ci->Shrink("CS_PRIVATE"); + replacements["MESSAGES"] = "Private updated"; + } + if (ci->HasExt("RESTRICTED") != message.post_data.count("restricted")) + { + if (!ci->HasExt("RESTRICTED")) + ci->Extend("RESTRICTED"); + else + ci->Shrink("RESTRICTED"); + replacements["MESSAGES"] = "Restricted updated"; + } + if (ci->HasExt("CS_SECURE") != message.post_data.count("secure")) + { + if (!ci->HasExt("CS_SECURE")) + ci->Extend("CS_SECURE"); + else + ci->Shrink("CS_SECURE"); + replacements["MESSAGES"] = "Secure updated"; + } + if (ci->HasExt("SECUREOPS") != message.post_data.count("secureops")) + { + if (!ci->HasExt("SECUREOPS")) + ci->Extend("SECUREOPS"); + else + ci->Shrink("SECUREOPS"); + replacements["MESSAGES"] = "Secureops updated"; + } + if (ci->HasExt("TOPICLOCK") != message.post_data.count("topiclock")) + { + if (!ci->HasExt("TOPICLOCK")) + ci->Extend("TOPICLOCK"); + else + ci->Shrink("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->GetSuccessor()) + replacements["SUCCESSOR"] = ci->GetSuccessor()->display; + replacements["TIME_REGISTERED"] = Anope::strftime(ci->time_registered, na->nc); + replacements["LAST_USED"] = Anope::strftime(ci->last_used, na->nc); + replacements["ESCAPED_CHANNEL"] = HTTPUtils::URLEncode(chname); + + if (!ci->last_topic.empty()) + { + replacements["LAST_TOPIC"] = HTTPUtils::Escape(ci->last_topic); + replacements["LAST_TOPIC_SETTER"] = HTTPUtils::Escape(ci->last_topic_setter); + } + + if (can_set) + { + if (ci->HasExt("KEEPTOPIC")) + replacements["KEEPTOPIC"]; + + if (ci->HasExt("PEACE")) + replacements["PEACE"]; + + if (ci->HasExt("CS_PRIVATE")) + replacements["PRIVATE"]; + + if (ci->HasExt("RESTRICTED")) + replacements["RESTRICTED"]; + + if (ci->HasExt("CS_SECURE")) + replacements["SECURE"]; + + if (ci->HasExt("SECUREOPS")) + replacements["SECUREOPS"]; + + if (ci->HasExt("TOPICLOCK")) + replacements["TOPICLOCK"]; + } + + page.Serve(server, page_name, client, message, reply, replacements); + return true; +} + +std::set WebCPanel::ChanServ::Set::GetData() +{ + std::set v; + v.insert("channel"); + return v; +} + diff --git a/modules/webcpanel/pages/chanserv/set.h b/modules/webcpanel/pages/chanserv/set.h new file mode 100644 index 000000000..dcd483419 --- /dev/null +++ b/modules/webcpanel/pages/chanserv/set.h @@ -0,0 +1,27 @@ +/* + * (C) 2003-2014 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); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; + + std::set GetData() anope_override; +}; + +} + +} + diff --git a/modules/webcpanel/pages/chanserv/utils.cpp b/modules/webcpanel/pages/chanserv/utils.cpp new file mode 100644 index 000000000..b4571b74c --- /dev/null +++ b/modules/webcpanel/pages/chanserv/utils.cpp @@ -0,0 +1,45 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" + +namespace +{ + bool ChannelSort(ChannelInfo *ci1, ChannelInfo *ci2) + { + return ci::less()(ci1->name, ci2->name); + } +} + +namespace WebCPanel +{ + +namespace ChanServ +{ + +void BuildChanList(NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + std::deque queue; + na->nc->GetChannelReferences(queue); + std::sort(queue.begin(), queue.end(), ChannelSort); + + for (unsigned i = 0; i < queue.size(); ++i) + { + ChannelInfo *ci = queue[i]; + + if (na->nc != ci->GetFounder() && ci->AccessFor(na->nc).empty()) + continue; + + replacements["CHANNEL_NAMES"] = ci->name; + replacements["ESCAPED_CHANNEL_NAMES"] = HTTPUtils::URLEncode(ci->name); + } +} + +} + +} + diff --git a/modules/webcpanel/pages/chanserv/utils.h b/modules/webcpanel/pages/chanserv/utils.h new file mode 100644 index 000000000..111abb4ad --- /dev/null +++ b/modules/webcpanel/pages/chanserv/utils.h @@ -0,0 +1,19 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + +namespace ChanServ +{ + +extern void BuildChanList(NickAlias *, TemplateFileServer::Replacements &); + +} + +} + diff --git a/modules/webcpanel/pages/confirm.cpp b/modules/webcpanel/pages/confirm.cpp new file mode 100644 index 000000000..7a4a3467e --- /dev/null +++ b/modules/webcpanel/pages/confirm.cpp @@ -0,0 +1,32 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../webcpanel.h" + +bool 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 params; + params.push_back(pass); + if (!email.empty()) + params.push_back(email); + + WebPanel::RunCommand(user, NULL, "NickServ", "nickserv/register", params, replacements); + } + + TemplateFileServer page("confirm.html"); + + page.Serve(server, page_name, client, message, reply, replacements); + return true; +} + diff --git a/modules/webcpanel/pages/confirm.h b/modules/webcpanel/pages/confirm.h new file mode 100644 index 000000000..eceeedee1 --- /dev/null +++ b/modules/webcpanel/pages/confirm.h @@ -0,0 +1,22 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "modules/httpd.h" + +namespace WebCPanel +{ + +class Confirm : public WebPanelPage +{ + public: + Confirm(const Anope::string &u) : WebPanelPage(u) { } + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override; +}; + +} + diff --git a/modules/webcpanel/pages/hostserv/request.cpp b/modules/webcpanel/pages/hostserv/request.cpp new file mode 100644 index 000000000..ee6356214 --- /dev/null +++ b/modules/webcpanel/pages/hostserv/request.cpp @@ -0,0 +1,36 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" + +WebCPanel::HostServ::Request::Request(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage (cat, u) +{ +} + +bool WebCPanel::HostServ::Request::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + if (message.post_data.count("req") > 0) + { + std::vector params; + params.push_back(HTTPUtils::URLDecode(message.post_data["req"])); + + WebPanel::RunCommand(na->nc->display, na->nc, "HostServ", "hostserv/request", params, replacements, "CMDR"); + } + + if (na->HasVhost()) + { + if (na->GetVhostIdent().empty() == false) + replacements["VHOST"] = na->GetVhostIdent() + "@" + na->GetVhostHost(); + else + replacements["VHOST"] = na->GetVhostHost(); + } + if (ServiceReference("Command", "hostserv/request")) + replacements["CAN_REQUEST"] = "YES"; + TemplateFileServer page("hostserv/request.html"); + page.Serve(server, page_name, client, message, reply, replacements); + return true; +} diff --git a/modules/webcpanel/pages/hostserv/request.h b/modules/webcpanel/pages/hostserv/request.h new file mode 100644 index 000000000..59d790937 --- /dev/null +++ b/modules/webcpanel/pages/hostserv/request.h @@ -0,0 +1,24 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + +namespace HostServ +{ + +class Request : public WebPanelProtectedPage +{ + public: + Request(const Anope::string &cat, const Anope::string &u); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + +} diff --git a/modules/webcpanel/pages/index.cpp b/modules/webcpanel/pages/index.cpp new file mode 100644 index 000000000..1b136c7fb --- /dev/null +++ b/modules/webcpanel/pages/index.cpp @@ -0,0 +1,99 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../webcpanel.h" + +class WebpanelRequest : public IdentifyRequest +{ + HTTPReply reply; + HTTPMessage message; + Reference server; + Anope::string page_name; + Reference client; + TemplateFileServer::Replacements replacements; + + public: + WebpanelRequest(Module *o, HTTPReply &r, HTTPMessage &m, HTTPProvider *s, const Anope::string &p_n, HTTPClient *c, TemplateFileServer::Replacements &re, const Anope::string &user, const Anope::string &pass) : IdentifyRequest(o, user, pass), reply(r), message(m), server(s), page_name(p_n), client(c), replacements(re) { } + + void OnSuccess() anope_override + { + if (!client || !server) + return; + NickAlias *na = NickAlias::Find(this->GetAccount()); + if (!na) + { + this->OnFail(); + return; + } + + Anope::string id; + for (int i = 0; i < 64; ++i) + { + char c; + do + c = 48 + (rand() % 75); + while (!isalnum(c)); + id += c; + } + + na->Extend("webcpanel_id", id); + na->Extend("webcpanel_ip", 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"] = Anope::string("http") + (server->IsSSL() ? "s" : "") + "://" + message.headers["Host"] + "/nickserv/info"; + + client->SendReply(&reply); + } + + void OnFail() anope_override + { + if (!client || !server) + return; + replacements["INVALID_LOGIN"] = "Invalid username or password"; + TemplateFileServer page("login.html"); + page.Serve(server, page_name, client, message, reply, replacements); + + client->SendReply(&reply); + } +}; + +bool 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. + + WebpanelRequest *req = new WebpanelRequest(me, reply, message, server, page_name, client, replacements, user, pass); + FOREACH_MOD(OnCheckAuthentication, (NULL, req)); + req->Dispatch(); + return false; + } + + TemplateFileServer page("login.html"); + page.Serve(server, page_name, client, message, reply, replacements); + return true; +} + diff --git a/modules/webcpanel/pages/index.h b/modules/webcpanel/pages/index.h new file mode 100644 index 000000000..b3c638d05 --- /dev/null +++ b/modules/webcpanel/pages/index.h @@ -0,0 +1,22 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "modules/httpd.h" + +namespace WebCPanel +{ + +class Index : public WebPanelPage +{ + public: + Index(const Anope::string &u) : WebPanelPage(u) { } + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override; +}; + +} + diff --git a/modules/webcpanel/pages/logout.cpp b/modules/webcpanel/pages/logout.cpp new file mode 100644 index 000000000..d9f5432a3 --- /dev/null +++ b/modules/webcpanel/pages/logout.cpp @@ -0,0 +1,23 @@ +/* + * (C) 2003-2014 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) +{ +} + +bool 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"] = Anope::string("http") + (server->IsSSL() ? "s" : "") + "://" + message.headers["Host"] + "/"; + return true; +} + diff --git a/modules/webcpanel/pages/logout.h b/modules/webcpanel/pages/logout.h new file mode 100644 index 000000000..ab324bdf9 --- /dev/null +++ b/modules/webcpanel/pages/logout.h @@ -0,0 +1,20 @@ +/* + * (C) 2003-2014 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); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + diff --git a/modules/webcpanel/pages/memoserv/memos.cpp b/modules/webcpanel/pages/memoserv/memos.cpp new file mode 100644 index 000000000..944864cdd --- /dev/null +++ b/modules/webcpanel/pages/memoserv/memos.cpp @@ -0,0 +1,115 @@ +/* + * (C) 2003-2014 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) +{ +} + +bool 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 = ChannelInfo::Find(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 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, "MemoServ", "memoserv/send", params, replacements, "CMDR"); + } + if (message.get_data.count("del") > 0 && message.get_data.count("number") > 0) + { + std::vector params; + if (!chname.empty()) + params.push_back(chname); + params.push_back(message.get_data["number"]); + + WebPanel::RunCommand(na->nc->display, na->nc, "MemoServ", "memoserv/del", params, replacements, "CMDR"); + } + if (message.get_data.count("read") > 0 && message.get_data.count("number") > 0) + { + std::vector params; + int number = -1; + + try + { + number = convertTo(message.get_data["number"]); + } + catch (const ConvertException &ex) + { + replacements["MESSAGES"] = "ERROR - invalid parameter for NUMBER"; + } + + if (number > 0) + { + m = mi->GetMemo(number-1); + + if (!m) + replacements["MESSAGES"] = "ERROR - invalid memo number."; + else if (message.get_data["read"] == "1") + m->unread = false; + else if (message.get_data["read"] == "2") + m->unread = true; + } + } + + for (unsigned i = 0; i < mi->memos->size(); ++i) + { + m = mi->GetMemo(i); + replacements["NUMBER"] = stringify(i+1); + replacements["SENDER"] = m->sender; + replacements["TIME"] = Anope::strftime(m->time); + replacements["TEXT"] = HTTPUtils::Escape(m->text); + if (m->unread) + replacements["UNREAD"] = "YES"; + else + replacements["UNREAD"] = "NO"; + } + + TemplateFileServer page("memoserv/memos.html"); + page.Serve(server, page_name, client, message, reply, replacements); + return true; +} + diff --git a/modules/webcpanel/pages/memoserv/memos.h b/modules/webcpanel/pages/memoserv/memos.h new file mode 100644 index 000000000..e55104823 --- /dev/null +++ b/modules/webcpanel/pages/memoserv/memos.h @@ -0,0 +1,25 @@ +/* + * (C) 2003-2014 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); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + +} + diff --git a/modules/webcpanel/pages/nickserv/access.cpp b/modules/webcpanel/pages/nickserv/access.cpp new file mode 100644 index 000000000..de7809591 --- /dev/null +++ b/modules/webcpanel/pages/nickserv/access.cpp @@ -0,0 +1,40 @@ +/* + * (C) 2003-2014 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) +{ +} + +bool 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 params; + params.push_back("ADD"); + params.push_back(message.post_data["access"]); + + WebPanel::RunCommand(na->nc->display, na->nc, "NickServ", "nickserv/access", params, replacements); + } + else if (message.get_data.count("del") > 0 && message.get_data.count("mask") > 0) + { + std::vector params; + params.push_back("DEL"); + params.push_back(message.get_data["mask"]); + + WebPanel::RunCommand(na->nc->display, na->nc, "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); + return true; +} + diff --git a/modules/webcpanel/pages/nickserv/access.h b/modules/webcpanel/pages/nickserv/access.h new file mode 100644 index 000000000..8c7337236 --- /dev/null +++ b/modules/webcpanel/pages/nickserv/access.h @@ -0,0 +1,25 @@ +/* + * (C) 2003-2014 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); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + +} + diff --git a/modules/webcpanel/pages/nickserv/alist.cpp b/modules/webcpanel/pages/nickserv/alist.cpp new file mode 100644 index 000000000..21e281f5f --- /dev/null +++ b/modules/webcpanel/pages/nickserv/alist.cpp @@ -0,0 +1,59 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" + +static bool ChannelSort(ChannelInfo *ci1, ChannelInfo *ci2) +{ + return ci::less()(ci1->name, ci2->name); +} + +WebCPanel::NickServ::Alist::Alist(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +bool WebCPanel::NickServ::Alist::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + std::deque queue; + na->nc->GetChannelReferences(queue); + std::sort(queue.begin(), queue.end(), ChannelSort); + + int chan_count = 0; + + for (unsigned q = 0; q < queue.size(); ++q) + { + ChannelInfo *ci = queue[q]; + + if (ci->GetFounder() == na->nc) + { + ++chan_count; + + replacements["NUMBERS"] = stringify(chan_count); + replacements["CHANNELS"] = (ci->HasExt("CS_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->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name; + Anope::string access_str; + for (unsigned i = 0; i < access.size(); ++i) + access_str += ", " + access[i]->AccessSerialize(); + replacements["ACCESSES"] = access_str.substr(2); + } + + TemplateFileServer page("nickserv/alist.html"); + page.Serve(server, page_name, client, message, reply, replacements); + return true; +} + diff --git a/modules/webcpanel/pages/nickserv/alist.h b/modules/webcpanel/pages/nickserv/alist.h new file mode 100644 index 000000000..357699f4e --- /dev/null +++ b/modules/webcpanel/pages/nickserv/alist.h @@ -0,0 +1,25 @@ +/* + * (C) 2003-2014 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); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + +} + diff --git a/modules/webcpanel/pages/nickserv/cert.cpp b/modules/webcpanel/pages/nickserv/cert.cpp new file mode 100644 index 000000000..eb86f4bd8 --- /dev/null +++ b/modules/webcpanel/pages/nickserv/cert.cpp @@ -0,0 +1,43 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" +#include "modules/ns_cert.h" + +WebCPanel::NickServ::Cert::Cert(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +bool 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 params; + params.push_back("ADD"); + params.push_back(message.post_data["certfp"]); + + WebPanel::RunCommand(na->nc->display, na->nc, "NickServ", "nickserv/cert", params, replacements); + } + else if (message.get_data.count("del") > 0 && message.get_data.count("mask") > 0) + { + std::vector params; + params.push_back("DEL"); + params.push_back(message.get_data["mask"]); + + WebPanel::RunCommand(na->nc->display, na->nc, "NickServ", "nickserv/cert", params, replacements); + } + + NSCertList *cl = na->nc->GetExt("certificates"); + if (cl) + for (unsigned i = 0; i < cl->GetCertCount(); ++i) + replacements["CERTS"] = cl->GetCert(i); + + TemplateFileServer page("nickserv/cert.html"); + page.Serve(server, page_name, client, message, reply, replacements); + return true; +} + diff --git a/modules/webcpanel/pages/nickserv/cert.h b/modules/webcpanel/pages/nickserv/cert.h new file mode 100644 index 000000000..7fa86e6eb --- /dev/null +++ b/modules/webcpanel/pages/nickserv/cert.h @@ -0,0 +1,25 @@ +/* + * (C) 2003-2014 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); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + +} + diff --git a/modules/webcpanel/pages/nickserv/info.cpp b/modules/webcpanel/pages/nickserv/info.cpp new file mode 100644 index 000000000..f8753d83f --- /dev/null +++ b/modules/webcpanel/pages/nickserv/info.cpp @@ -0,0 +1,118 @@ +/* + * (C) 2003-2014 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) +{ +} + +bool 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() && !Mail::Validate(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) + { + Anope::string *greet = na->nc->GetExt("greet"); + const Anope::string &post_greet = HTTPUtils::URLDecode(message.post_data["greet"].replace_all_cs("+", " ")); + + if (post_greet.empty()) + na->nc->Shrink("greet"); + else if (!greet || post_greet != *greet) + na->nc->Extend("greet", post_greet); + + replacements["MESSAGES"] = "Greet updated"; + } + if (na->nc->HasExt("AUTOOP") != message.post_data.count("autoop")) + { + if (!na->nc->HasExt("AUTOOP")) + na->nc->Extend("AUTOOP"); + else + na->nc->Shrink("AUTOOP"); + replacements["MESSAGES"] = "Autoop updated"; + } + if (na->nc->HasExt("NS_PRIVATE") != message.post_data.count("private")) + { + if (!na->nc->HasExt("NS_PRIVATE")) + na->nc->Extend("NS_PRIVATE"); + else + na->nc->Shrink("NS_PRIVATE"); + replacements["MESSAGES"] = "Private updated"; + } + if (na->nc->HasExt("NS_SECURE") != message.post_data.count("secure")) + { + if (!na->nc->HasExt("NS_SECURE")) + na->nc->Extend("NS_SECURE"); + else + na->nc->Shrink("NS_SECURE"); + replacements["MESSAGES"] = "Secure updated"; + } + if (message.post_data["kill"] == "on" && !na->nc->HasExt("KILLPROTECT")) + { + na->nc->Extend("KILLPROTECT"); + na->nc->Shrink("KILL_QUICK"); + replacements["MESSAGES"] = "Kill updated"; + } + else if (message.post_data["kill"] == "quick" && !na->nc->HasExt("KILL_QUICK")) + { + na->nc->Shrink("KILLPROTECT"); + na->nc->Extend("KILL_QUICK"); + replacements["MESSAGES"] = "Kill updated"; + } + else if (message.post_data["kill"] == "off" && (na->nc->HasExt("KILLPROTECT") || na->nc->HasExt("KILL_QUICK"))) + { + na->nc->Shrink("KILLPROTECT"); + na->nc->Shrink("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"] = Anope::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(); + } + Anope::string *greet = na->nc->GetExt("greet"); + if (greet) + replacements["GREET"] = HTTPUtils::Escape(*greet); + if (na->nc->HasExt("AUTOOP")) + replacements["AUTOOP"]; + if (na->nc->HasExt("NS_PRIVATE")) + replacements["PRIVATE"]; + if (na->nc->HasExt("NS_SECURE")) + replacements["SECURE"]; + if (na->nc->HasExt("KILLPROTECT")) + replacements["KILL_ON"]; + if (na->nc->HasExt("KILL_QUICK")) + replacements["KILL_QUICK"]; + if (!na->nc->HasExt("KILLPROTECT") && !na->nc->HasExt("KILL_QUICK")) + replacements["KILL_OFF"]; + + TemplateFileServer page("nickserv/info.html"); + page.Serve(server, page_name, client, message, reply, replacements); + return true; +} + diff --git a/modules/webcpanel/pages/nickserv/info.h b/modules/webcpanel/pages/nickserv/info.h new file mode 100644 index 000000000..46e588f8b --- /dev/null +++ b/modules/webcpanel/pages/nickserv/info.h @@ -0,0 +1,25 @@ +/* + * (C) 2003-2014 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); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + +} + diff --git a/modules/webcpanel/pages/operserv/akill.cpp b/modules/webcpanel/pages/operserv/akill.cpp new file mode 100644 index 000000000..24f1dbf63 --- /dev/null +++ b/modules/webcpanel/pages/operserv/akill.cpp @@ -0,0 +1,64 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" + +WebCPanel::OperServ::Akill::Akill(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +bool WebCPanel::OperServ::Akill::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + + static ServiceReference akills("XLineManager","xlinemanager/sgline"); + + if (!na->nc->IsServicesOper() && !(na->nc->o && na->nc->o->ot && na->nc->o->ot->HasPriv("operserv/akill"))) + { + replacements["NOACCESS"]; + } + else + { + if (akills->GetCount() == 0) + replacements["AKILLS"] = "No Akills to display."; + + if (message.post_data.count("mask") > 0 && message.post_data.count("expiry") > 0 && message.post_data.count("reason") > 0) + { + std::vector params; + std::stringstream cmdstr; + params.push_back("ADD"); + cmdstr << "+" << HTTPUtils::URLDecode(message.post_data["expiry"]); + cmdstr << " " << HTTPUtils::URLDecode(message.post_data["mask"]); + cmdstr << " " << HTTPUtils::URLDecode(message.post_data["reason"]); + params.push_back(cmdstr.str()); + WebPanel::RunCommand(na->nc->display, na->nc, "OperServ", "operserv/akill", params, replacements); + } + + if (message.get_data["del"] == "1" && message.get_data.count("number") > 0) + { + std::vector params; + params.push_back("DEL"); + params.push_back(HTTPUtils::URLDecode(message.get_data["number"])); + WebPanel::RunCommand(na->nc->display, na->nc, "OperServ", "operserv/akill", params, replacements); + } + + for (unsigned i = 0, end = akills->GetCount(); i < end; ++i) + { + const XLine *x = akills->GetEntry(i); + replacements["NUMBER"] = stringify(i + 1); + replacements["HOST"] = x->mask; + replacements["SETTER"] = x->by; + replacements["TIME"] = Anope::strftime(x->created, NULL, true); + replacements["EXPIRE"] = Anope::Expires(x->expires, na->nc); + replacements["REASON"] = x->reason; + } + } + + TemplateFileServer page("operserv/akill.html"); + page.Serve(server, page_name, client, message, reply, replacements); + return true; +} + diff --git a/modules/webcpanel/pages/operserv/akill.h b/modules/webcpanel/pages/operserv/akill.h new file mode 100644 index 000000000..9fd47d79a --- /dev/null +++ b/modules/webcpanel/pages/operserv/akill.h @@ -0,0 +1,25 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + +namespace OperServ +{ + +class Akill : public WebPanelProtectedPage +{ + public: + Akill(const Anope::string &cat, const Anope::string &u); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + +} + diff --git a/modules/webcpanel/pages/register.cpp b/modules/webcpanel/pages/register.cpp new file mode 100644 index 000000000..cd3494713 --- /dev/null +++ b/modules/webcpanel/pages/register.cpp @@ -0,0 +1,24 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../webcpanel.h" + +bool 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->GetModule("nickserv")->Get("forceemail", "yes")) + replacements["FORCE_EMAIL"] = "yes"; + + TemplateFileServer page("register.html"); + + page.Serve(server, page_name, client, message, reply, replacements); + return true; +} + diff --git a/modules/webcpanel/pages/register.h b/modules/webcpanel/pages/register.h new file mode 100644 index 000000000..38646c98c --- /dev/null +++ b/modules/webcpanel/pages/register.h @@ -0,0 +1,22 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "modules/httpd.h" + +namespace WebCPanel +{ + +class Register : public WebPanelPage +{ + public: + Register(const Anope::string &u) : WebPanelPage(u) { } + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override; +}; + +} + diff --git a/modules/webcpanel/static_fileserver.cpp b/modules/webcpanel/static_fileserver.cpp new file mode 100644 index 000000000..21f4e7052 --- /dev/null +++ b/modules/webcpanel/static_fileserver.cpp @@ -0,0 +1,42 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "webcpanel.h" +#include +#include + +#include +#include +#include + +StaticFileServer::StaticFileServer(const Anope::string &f_n, const Anope::string &u, const Anope::string &c_t) : HTTPPage(u, c_t), file_name(f_n) +{ +} + +bool 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 true; + } + + 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); + return true; +} + diff --git a/modules/webcpanel/static_fileserver.h b/modules/webcpanel/static_fileserver.h new file mode 100644 index 000000000..184c8661d --- /dev/null +++ b/modules/webcpanel/static_fileserver.h @@ -0,0 +1,19 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "modules/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); + + bool OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override; +}; + diff --git a/modules/webcpanel/template_fileserver.cpp b/modules/webcpanel/template_fileserver.cpp new file mode 100644 index 000000000..d4e5ec7e4 --- /dev/null +++ b/modules/webcpanel/template_fileserver.cpp @@ -0,0 +1,261 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "webcpanel.h" +#include +#include +#include + +#include +#include +#include + +struct ForLoop +{ + static std::vector Stack; + + size_t start; /* Index of start of this loop */ + std::vector vars; /* User defined variables */ + typedef std::pair range; + std::vector ranges; /* iterator ranges for each variable */ + + ForLoop(size_t s, TemplateFileServer::Replacements &r, const std::vector &v, const std::vector &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::Stack; + +std::stack 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; + + bool escaped = false; + for (unsigned j = 0; j < buf.length(); ++j) + { + if (buf[j] == '\\' && j + 1 < buf.length() && (buf[j + 1] == '{' || buf[j + 1] == '}')) + escaped = true; + else if (buf[j] == '{' && !escaped) + { + 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 tokens; + spacesepstream(content).GetTokens(tokens); + + 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]; + + bool stackok = IfStack.empty() || IfStack.top(); + IfStack.push(stackok && first == second); + } + else if (tokens.size() == 3 && tokens[1] == "EXISTS") + { + bool stackok = IfStack.empty() || IfStack.top(); + IfStack.push(stackok && 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() + bool stackok = IfStack.empty() || IfStack.top(); + IfStack.push(stackok && !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 tokens; + spacesepstream(content).GetTokens(tokens); + + if (tokens.size() != 4 || tokens[2] != "IN") + Log() << "Invalid FOR in web template " << this->file_name; + else + { + std::vector temp_variables, real_variables; + commasepstream(tokens[1]).GetTokens(temp_variables); + commasepstream(tokens[3]).GetTokens(real_variables); + + 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 tokens; + spacesepstream(content).GetTokens(tokens); + + 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 + { + escaped = false; + + // 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); + return; +} + diff --git a/modules/webcpanel/template_fileserver.h b/modules/webcpanel/template_fileserver.h new file mode 100644 index 000000000..0d2502e4f --- /dev/null +++ b/modules/webcpanel/template_fileserver.h @@ -0,0 +1,27 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "modules/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& 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/webcpanel/templates/default/chanserv/access.html b/modules/webcpanel/templates/default/chanserv/access.html new file mode 100644 index 000000000..c50434f8a --- /dev/null +++ b/modules/webcpanel/templates/default/chanserv/access.html @@ -0,0 +1,77 @@ +{INCLUDE header.html} +{INCLUDE chanserv/chanlist.html} +
Access List
+
+ {FOR M IN MESSAGES} +
+ {M}
+
+ {END FOR} + + {IF EQ ACCESS_LIST YES} + {IF EXISTS ACCESSES} + + + + + + + + + + + {FOR MASK,ACCESS,CREATOR IN MASKS,ACCESSES,CREATORS} + + + + + {IF EQ ACCESS_CHANGE YES} + + {ELSE} + + {END IF} + + {END FOR} + +
MaskAccessCreator
{MASK}{ACCESS}{CREATOR}Delete
+ {ELSE} + Access list is empty. + {END IF} + +
+ + {IF EQ ACCESS_CHANGE YES} +

Add an access entry

+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+ {END IF} + {END IF} +
+{INCLUDE footer.html} diff --git a/modules/webcpanel/templates/default/chanserv/akick.html b/modules/webcpanel/templates/default/chanserv/akick.html new file mode 100644 index 000000000..ddfea546c --- /dev/null +++ b/modules/webcpanel/templates/default/chanserv/akick.html @@ -0,0 +1,61 @@ +{INCLUDE header.html} +{INCLUDE chanserv/chanlist.html} +
Akick List
+
+ {FOR M IN MESSAGES} +
+ {M}
+
+ {END FOR} + + {IF EQ AKICK YES} + {IF EXISTS MASKS} + + + + + + + + + + + {FOR MASK,REASON,CREATOR IN MASKS,REASONS,CREATORS} + + + + + + + {END FOR} + +
MaskReasonCreator
{MASK}{REASON}{CREATOR}Delete
+ {ELSE} + Akick list is empty. + {END IF} + +
+ +

Add an akick entry

+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+ {END IF} +
+{INCLUDE footer.html} diff --git a/modules/webcpanel/templates/default/chanserv/chanlist.html b/modules/webcpanel/templates/default/chanserv/chanlist.html new file mode 100644 index 000000000..8f00f02ac --- /dev/null +++ b/modules/webcpanel/templates/default/chanserv/chanlist.html @@ -0,0 +1,17 @@ +
Channels you have access in
+
+ {IF EXISTS CHANNEL_NAMES} +
+

Choose a channel to access it's Settings, Access or Akick pages.

+ {FOR CH,ECH IN CHANNEL_NAMES,ESCAPED_CHANNEL_NAMES} + {IF EQ PAGE_NAME /chanserv/info} + {CH} + {ELSE} + {CH} + {END IF} + {END FOR} +
+ {ELSE} + You don't have access in any channels.
+ {END IF} +
diff --git a/modules/webcpanel/templates/default/chanserv/drop.html b/modules/webcpanel/templates/default/chanserv/drop.html new file mode 100644 index 000000000..c28eb051a --- /dev/null +++ b/modules/webcpanel/templates/default/chanserv/drop.html @@ -0,0 +1,32 @@ +{INCLUDE header.html} +{INCLUDE chanserv/chanlist.html} +
Channels you can drop
+
+ {FOR M IN MESSAGES} +
+ {M}
+
+ {END FOR} + + {IF EXISTS CHANNEL_DROP} +
+

Drop Channel {CHANNEL_DROP}?

+
+ + +
+ +
+ +
+
+
+
+ +
+
+
+
+ {END IF} +
+{INCLUDE footer.html} \ No newline at end of file diff --git a/modules/webcpanel/templates/default/chanserv/main.html b/modules/webcpanel/templates/default/chanserv/main.html new file mode 100644 index 000000000..e77626f31 --- /dev/null +++ b/modules/webcpanel/templates/default/chanserv/main.html @@ -0,0 +1,3 @@ +{INCLUDE header.html} +{INCLUDE chanserv/chanlist.html} +{INCLUDE footer.html} diff --git a/modules/webcpanel/templates/default/chanserv/modes.html b/modules/webcpanel/templates/default/chanserv/modes.html new file mode 100644 index 000000000..3c7fe7ab3 --- /dev/null +++ b/modules/webcpanel/templates/default/chanserv/modes.html @@ -0,0 +1,56 @@ +{INCLUDE header.html} +{INCLUDE chanserv/chanlist.html} +
Channel Mode List
+
+ {FOR M IN MESSAGES} +
+ {M}
+
+ {END FOR} + + {IF EQ MODE YES} + {FOR LM IN LISTMODES} + +{LM} + {END FOR} +
+ + {IF EXISTS MASKS} + + + + + + + + + {FOR MASK IN MASKS} + + + + + {END FOR} + +
Mask
{MASK}Delete
+ {ELSE} + Nothing to display. + {END IF} + +
+ +

Set a new mode

+
+
+ +
+ +
+
+
+
+ +
+
+
+ {END IF} +
+{INCLUDE footer.html} diff --git a/modules/webcpanel/templates/default/chanserv/set.html b/modules/webcpanel/templates/default/chanserv/set.html new file mode 100644 index 000000000..050c37f69 --- /dev/null +++ b/modules/webcpanel/templates/default/chanserv/set.html @@ -0,0 +1,93 @@ +{INCLUDE header.html} +{INCLUDE chanserv/chanlist.html} +
Channel Information
+
+ {FOR M IN MESSAGES} +
+ {M}
+
+ {END FOR} + + {IF EXISTS OKAY} + {IF EXISTS CAN_SET} +
+ {END IF} + + + + + + {IF EXISTS FOUNDER} + + + + + {END IF} + {IF EXISTS SUCCESSOR} + + + + + {END IF} + + + + + + + + + {IF EXISTS LAST_TOPIC} + + + + + + + + + {END IF} + {IF EXISTS CAN_SET} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {IF EXISTS CAN_SET} + + + + + {END IF} + {END IF} +
Channel Name{CHANNEL}
Founder{FOUNDER}
Succsesor{SUCCESSOR}
Time registered{TIME_REGISTERED}
Last used{LAST_USED}
Last topic{LAST_TOPIC}
Set by{LAST_TOPIC_SETTER}
Keep topic
Peace
Private
Restricted
Secure
Secure Ops
Topic Lock
+ + {IF EXISTS CAN_SET} +
+ {END IF} + {END IF} +
+{INCLUDE footer.html} diff --git a/modules/webcpanel/templates/default/confirm.html b/modules/webcpanel/templates/default/confirm.html new file mode 100644 index 000000000..f9f315fd3 --- /dev/null +++ b/modules/webcpanel/templates/default/confirm.html @@ -0,0 +1,51 @@ + + + + + + + + + + + + + {TITLE} + + +
+
+
+ + + + Back Home + +

Register

+ + {IF EXISTS MESSAGES} +
+ {FOR M IN MESSAGES} + {M}
+ {END FOR} +
+ {END IF} + + Retry +
+
+ +
+
+
+ +
+
+
+ + + + + diff --git a/modules/webcpanel/templates/default/cubes.png b/modules/webcpanel/templates/default/cubes.png new file mode 100644 index 000000000..d75208db7 Binary files /dev/null and b/modules/webcpanel/templates/default/cubes.png differ diff --git a/modules/webcpanel/templates/default/favicon.ico b/modules/webcpanel/templates/default/favicon.ico new file mode 100644 index 000000000..be735614a Binary files /dev/null and b/modules/webcpanel/templates/default/favicon.ico differ diff --git a/modules/webcpanel/templates/default/footer.html b/modules/webcpanel/templates/default/footer.html new file mode 100644 index 000000000..57794a9ff --- /dev/null +++ b/modules/webcpanel/templates/default/footer.html @@ -0,0 +1,14 @@ +
+ + + +
+
+ +
+
+ + + \ No newline at end of file diff --git a/modules/webcpanel/templates/default/header.html b/modules/webcpanel/templates/default/header.html new file mode 100644 index 000000000..0ccf477c5 --- /dev/null +++ b/modules/webcpanel/templates/default/header.html @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + {TITLE} + + +
+ + +
+
+ +
+ +
+
diff --git a/modules/webcpanel/templates/default/hostserv/request.html b/modules/webcpanel/templates/default/hostserv/request.html new file mode 100644 index 000000000..f557244d1 --- /dev/null +++ b/modules/webcpanel/templates/default/hostserv/request.html @@ -0,0 +1,45 @@ +{INCLUDE header.html} +
vHost Information
+
+ {FOR M IN MESSAGES} +
+ {M}
+
+ {END FOR} + + + + + + + + + {IF EXISTS CAN_REQUEST} + + + + + + + + {ELSE} + + + + {END IF} + +
Your current vHost: + {IF EXISTS VHOST} + {VHOST} + {ELSE} + None + {END IF} +
+ {IF EXISTS VHOST} + Request a new vHost + {ELSE} + Request a vHost + {END IF} +
vHost requests are disabled on this network.
+
+{INCLUDE footer.html} diff --git a/modules/webcpanel/templates/default/login.html b/modules/webcpanel/templates/default/login.html new file mode 100644 index 000000000..6a0b6d7a9 --- /dev/null +++ b/modules/webcpanel/templates/default/login.html @@ -0,0 +1,55 @@ + + + + + + + + + + + + + {TITLE} + + +
+
+
+ + + + +

Login to continue

+ + {IF EXISTS INVALID_LOGIN} +
+ {INVALID_LOGIN} +
+ {END IF} + + +
+
+ +
+
+
+ +
+
+
+ + + + + diff --git a/modules/webcpanel/templates/default/logo.png b/modules/webcpanel/templates/default/logo.png new file mode 100644 index 000000000..f7c2ff92a Binary files /dev/null and b/modules/webcpanel/templates/default/logo.png differ diff --git a/modules/webcpanel/templates/default/memoserv/memos.html b/modules/webcpanel/templates/default/memoserv/memos.html new file mode 100644 index 000000000..b3b54d948 --- /dev/null +++ b/modules/webcpanel/templates/default/memoserv/memos.html @@ -0,0 +1,112 @@ +{INCLUDE header.html} +
Memos List
+
+ {FOR M IN MESSAGES} +
+ {M}
+
+ {END FOR} + + {IF EXISTS NUMBER} + + + + + + + + + + + + + {FOR I,S,T,TXT,U IN NUMBER,SENDER,TIME,TEXT,UNREAD} + {IF EQ U YES} + + {ELSE} + + {END IF} + + + + + + {END FOR} + +
NumberSenderMessage (hover: Time)
{I}{S}{TXT} + {IF EQ U YES} + Reply + Mark as Read + Delete + {ELSE} + Reply + Mark as Unread + Delete + {END IF} +
+ {ELSE} + No memos to show. + {END IF} + +
+ +
+
+

Memos for channel

+ {IF EXISTS CHANNEL_NAMES} +
+
    + {FOR CH,ECH IN CHANNEL_NAMES,ESCAPED_CHANNEL_NAMES} +
  • {CH}
  • + {END FOR} +
+
+ {ELSE} + You don't have access in any channel
+ {END IF} + +
+
+

Send a new Memo

+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+
+ + {IF EXISTS CMDR} +
+ {CMDR} +
+ {END IF} +
+{INCLUDE footer.html} diff --git a/modules/webcpanel/templates/default/nickserv/access.html b/modules/webcpanel/templates/default/nickserv/access.html new file mode 100644 index 000000000..d4be56279 --- /dev/null +++ b/modules/webcpanel/templates/default/nickserv/access.html @@ -0,0 +1,42 @@ +{INCLUDE header.html} +
Nick access list
+
+ {FOR M IN MESSAGES} +
+ {M}
+
+ {END FOR} + + {IF EXISTS ACCESS} + + + {FOR A IN ACCESS} + + + + + {END FOR} + +
{A}Delete
+ {ELSE} + Your access list is empty. + {END IF} + +
+ +

Add an access entry

+
+
+ +
+ +
+
+
+
+ +
+
+
+
+{INCLUDE footer.html} diff --git a/modules/webcpanel/templates/default/nickserv/alist.html b/modules/webcpanel/templates/default/nickserv/alist.html new file mode 100644 index 000000000..f3b2e0124 --- /dev/null +++ b/modules/webcpanel/templates/default/nickserv/alist.html @@ -0,0 +1,23 @@ +{INCLUDE header.html} +
Channel access list
+
+ + + + + + + + + + {FOR N,C,A IN NUMBERS,CHANNELS,ACCESSES} + + + + + + {END FOR} + +
NumberChannelAccess
{N}{C}{A}
+
+{INCLUDE footer.html} diff --git a/modules/webcpanel/templates/default/nickserv/cert.html b/modules/webcpanel/templates/default/nickserv/cert.html new file mode 100644 index 000000000..6d41a44b4 --- /dev/null +++ b/modules/webcpanel/templates/default/nickserv/cert.html @@ -0,0 +1,42 @@ +{INCLUDE header.html} +
Your certificate fingerprints
+
+ {FOR M IN MESSAGES} +
+ {M}
+
+ {END FOR} + + {IF EXISTS CERTS} + + + {FOR CERT IN CERTS} + + + + + {END FOR} + +
{CERT}Delete
+ {ELSE} + Certificates list is empty. + {END IF} + +
+ +

Add a certificate fingerprint

+
+
+ +
+ +
+
+
+
+ +
+
+
+
+{INCLUDE footer.html} diff --git a/modules/webcpanel/templates/default/nickserv/info.html b/modules/webcpanel/templates/default/nickserv/info.html new file mode 100644 index 000000000..667c8b370 --- /dev/null +++ b/modules/webcpanel/templates/default/nickserv/info.html @@ -0,0 +1,72 @@ +{INCLUDE header.html} +
Your account information
+
+ {FOR M IN ERRORS} +
+ {M}
+
+ {END FOR} + + {FOR M IN MESSAGES} +
+ {M}
+
+ {END FOR} + +
+ + + + + + + {IF EXISTS EMAIL} + + + + + {END IF} + + + + + {IF EXISTS VHOST} + + + + + {END IF} + + + + + + + + + + + + + + + + + + + + + +
Account:{DISPLAY}
E-mail:{EMAIL}
Time registered:{TIME_REGISTERED}
Vhost:{VHOST}
Greet:
Auto op:
Private:
Secure:
Kill: + +
+
+ +
+
+
+{INCLUDE footer.html} diff --git a/modules/webcpanel/templates/default/operserv/akill.html b/modules/webcpanel/templates/default/operserv/akill.html new file mode 100644 index 000000000..ffc73f8e4 --- /dev/null +++ b/modules/webcpanel/templates/default/operserv/akill.html @@ -0,0 +1,77 @@ +{INCLUDE header.html} +
Akill List
+
+ {IF EXISTS NOACCESS} +

Access denied.

+ {ELSE} + + {FOR M IN MESSAGES} +
+ {M}
+
+ {END FOR} + + + + {IF EXISTS AKILLS} + {AKILLS} + {ELSE} + + + + + + + + + + + + {FOR N,H,S,T,E,R IN NUMBER,HOST,SETTER,TIME,EXPIRE,REASON} + + + + + + + + {END FOR} + +
NumberHostmask (hover: Reason)Expires (hover: Set Date)Setter
{N}{H}{E}{S}Delete
+ {END IF} + +
+ +

Add a new Akill

+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+ {END IF} +
+{INCLUDE footer.html} diff --git a/modules/webcpanel/templates/default/register.html b/modules/webcpanel/templates/default/register.html new file mode 100644 index 000000000..bebf4e276 --- /dev/null +++ b/modules/webcpanel/templates/default/register.html @@ -0,0 +1,65 @@ + + + + + + + + + + + + + {TITLE} + + +
+
+
+ + + + Back Home + +

Register

+ + {IF EXISTS MESSAGES} +
+ {MESSAGES} +
+ {END IF} + + +
+
+ +
+
+
+ +
+
+
+ + + + + \ No newline at end of file diff --git a/modules/webcpanel/templates/default/style.css b/modules/webcpanel/templates/default/style.css new file mode 100644 index 000000000..e425c3d8c --- /dev/null +++ b/modules/webcpanel/templates/default/style.css @@ -0,0 +1,166 @@ +@import url(//fonts.googleapis.com/css?family=Open+Sans:300,400); +@import url(//fonts.googleapis.com/css?family=Port+Lligat+Slab); + +*, html, body, h1, h2, h3, h4, div, p, span, a, button { + font-family: 'Open Sans', sans-serif; +} +body { + background-color: #eee; + background-image: url('/static/cubes.png'); +} + +/* RANDOM STUFF */ +#frontPages { + padding-top: 20px; +} + +h2 { + margin: 0 0 10px 0; +} +h4 { + margin-top: 30px; +} +.popover { + max-width: 450px; + -webkit-box-shadow: 0 1px 10px rgba(0, 0, 0, 0.8); + box-shadow: 0 1px 10px rgba(0, 0, 0, 0.8); +} + +.label { + font-size: 13px; + font-weight: normal; +} + +.label-info { + background-color: #4EA4EE; +} + +.label-info[href]:hover, .label-info[href]:focus { + background-color: #428BCA; +} + +/* LOGIN FORM */ +.form-signin .form-signin-heading, .form-signin .checkbox { + margin-bottom: 10px; +} +.form-signin .checkbox { + font-weight: normal; +} +.form-signin .form-control { + position: relative; + font-size: 16px; + height: auto; + padding: 10px; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} +.form-signin .form-control:focus { + z-index: 2; +} +/* FOOTER */ +.footer { + margin-top: 20px; +} + +/* Control Panel */ +.panel-default .panel-heading { + font-size: 24px; +} +#loggedIn { + margin: 15px 15px 0 0; +} + +#navPanel { + margin: 0; + padding: 0; +} +.table thead > tr:first-child > th, .table tbody > tr:first-child > th, .table tfoot > tr:first-child > th, .table thead > tr:first-child > td, .table tbody > tr:first-child > td, .table tfoot > tr:first-child > td { + vertical-align: top; + border-top: 0; +} +#tableInfo td { + vertical-align: middle; +} +#tableInfo td:first-child { + font-weight: bold; + padding-right: 10px; + text-align: right; + width: 25%; +} + +#tableInfoNorm td { + vertical-align: middle; +} +#tableInfoNorm td:first-child { + font-weight: bold; + padding-right: 10px; +} + +#tableInfoMemos td { + vertical-align: top; +} +#tableInfoMemos td:first-child { + font-weight: bold; + padding-right: 10px; +} +#tableInfoMemos th small { + font-weight: normal; +} + +#tableNSAccess td { + vertical-align: middle; +} +#tableNSAccess td:first-child { + padding-right: 10px; + text-align: left; +} +#tableNSAccess td:last-child { + padding-right: 10px; + text-align: right; +} +#tableNSAccess th small { + font-weight: normal; +} + +#channelList li { + margin-top: 10px; +} + +/* NAVBAR */ +.navbar, .well { + background-color: white; +} + +.navbar { + -webkit-box-shadow: 0 8px 6px -8px black; + -moz-box-shadow: 0 8px 6px -8px black; + box-shadow: 0 8px 6px -8px black; +} +.navbar-brand { + font-size: 25px; +} +.navbar-brand, .navbar-brand small { + font-family: 'Port Lligat Slab', serif; +} + +.navbar-default .nav { + margin-bottom: -1px; +} + +.navbar-default .nav > li > a { + color: #428BCA; +} + +.navbar-default .nav > li > a:hover, .navbar-default .nav > li > a:focus { + color: #428BCA; + border-top: 3px solid #0082D9; + margin-top: -3px; +} + +.navbar-default .nav > li.active > a, .navbar-default .nav > li.active > a:hover, .navbar-default .nav > li.active > a:focus { + color: #428BCA; + background-color: transparent; + background-color: rgba(66, 139, 202, 0.1); + border-bottom-color: transparent; +} diff --git a/modules/webcpanel/webcpanel.cpp b/modules/webcpanel/webcpanel.cpp new file mode 100644 index 000000000..0c1fc3903 --- /dev/null +++ b/modules/webcpanel/webcpanel.cpp @@ -0,0 +1,270 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "webcpanel.h" + +Module *me; +Anope::string provider_name, template_name, template_base, page_title; + +class ModuleWebCPanel : public Module +{ + ServiceReference provider; + Panel panel; + PrimitiveExtensibleItem id, ip; + + StaticFileServer style_css, logo_png, cubes_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::ChanServ::Modes chanserv_modes; + WebCPanel::ChanServ::Drop chanserv_drop; + + WebCPanel::MemoServ::Memos memoserv_memos; + + WebCPanel::HostServ::Request hostserv_request; + + WebCPanel::OperServ::Akill operserv_akill; + + + public: + ModuleWebCPanel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), + panel(this, "webcpanel"), id(this, "webcpanel_id"), ip(this, "webcpanel_ip"), + 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"), + index("/"), logout("/logout"), _register("/register"), confirm("/confirm"), + nickserv_info("NickServ", "/nickserv/info"), nickserv_cert("NickServ", "/nickserv/cert"), nickserv_access("NickServ", "/nickserv/access"), nickserv_alist("NickServ", "/nickserv/alist"), + chanserv_info("ChanServ", "/chanserv/info"), chanserv_set("ChanServ", "/chanserv/set"), chanserv_access("ChanServ", "/chanserv/access"), chanserv_akick("ChanServ", "/chanserv/akick"), + chanserv_modes("ChanServ", "/chanserv/modes"), chanserv_drop("ChanServ", "/chanserv/drop"), memoserv_memos("MemoServ", "/memoserv/memos"), hostserv_request("HostServ", "/hostserv/request"), + operserv_akill("OperServ", "/operserv/akill") + { + + me = this; + + Configuration::Block *block = Config->GetModule(this); + provider_name = block->Get("server", "httpd/main"); + template_name = block->Get("template", "default"); + template_base = Anope::DataDir + "/modules/webcpanel/templates/" + template_name; + page_title = block->Get("title", "Anope IRC Services"); + + provider = ServiceReference("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->cubes_png); + provider->RegisterPage(&this->favicon_ico); + + provider->RegisterPage(&this->index); + provider->RegisterPage(&this->logout); + provider->RegisterPage(&this->_register); + provider->RegisterPage(&this->confirm); + + BotInfo *NickServ = Config->GetClient("NickServ"); + if (NickServ) + { + Section s; + s.name = NickServ->nick; + + SubSection ss; + ss.name = "Information"; + ss.url = "/nickserv/info"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->nickserv_info); + + if (IRCD && IRCD->CanCertFP) + { + 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); + } + + BotInfo *ChanServ = Config->GetClient("ChanServ"); + if (ChanServ) + { + Section s; + s.name = ChanServ->nick; + + 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); + + ss.name = "Modes"; + ss.url = "/chanserv/modes"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->chanserv_modes); + + ss.name = "Drop"; + ss.url = "/chanserv/drop"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->chanserv_drop); + + panel.sections.push_back(s); + } + + BotInfo *MemoServ = Config->GetClient("MemoServ"); + if (MemoServ) + { + Section s; + s.name = MemoServ->nick; + + SubSection ss; + ss.name = "Memos"; + ss.url = "/memoserv/memos"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->memoserv_memos); + + panel.sections.push_back(s); + } + + BotInfo *HostServ = Config->GetClient("HostServ"); + if (HostServ) + { + Section s; + s.name = HostServ->nick; + + SubSection ss; + ss.name = "vHost Request"; + ss.url = "/hostserv/request"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->hostserv_request); + + panel.sections.push_back(s); + } + + BotInfo *OperServ = Config->GetClient("OperServ"); + if (OperServ) + { + Section s; + s.name = OperServ->nick; + + SubSection ss; + ss.name = "Akill"; + ss.url = "/operserv/akill"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->operserv_akill); + + panel.sections.push_back(s); + } + } + + ~ModuleWebCPanel() + { + if (provider) + { + provider->UnregisterPage(&this->style_css); + provider->UnregisterPage(&this->logo_png); + provider->UnregisterPage(&this->cubes_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->chanserv_modes); + provider->UnregisterPage(&this->chanserv_drop); + + provider->UnregisterPage(&this->memoserv_memos); + + provider->UnregisterPage(&this->hostserv_request); + + provider->UnregisterPage(&this->operserv_akill); + } + } +}; + +namespace WebPanel +{ + void RunCommand(const Anope::string &user, NickCore *nc, const Anope::string &service, const Anope::string &c, const std::vector ¶ms, TemplateFileServer::Replacements &r, const Anope::string &key) + { + ServiceReference cmd("Command", c); + if (!cmd) + { + r[key] = "Unable to find command " + c; + return; + } + + BotInfo *bi = Config->GetClient(service); + if (!bi) + { + if (BotListByNick->empty()) + return; + bi = BotListByNick->begin()->second; // Pick one... + } + + struct MyComandReply : CommandReply + { + TemplateFileServer::Replacements &re; + const Anope::string &k; + + MyComandReply(TemplateFileServer::Replacements &_r, const Anope::string &_k) : re(_r), k(_k) { } + + void SendMessage(BotInfo *source, const Anope::string &msg) anope_override + { + re[k] = msg; + } + } + my_reply(r, key); + + CommandSource source(user, NULL, nc, &my_reply, bi); + cmd->Execute(source, params); + } +} + +MODULE_INIT(ModuleWebCPanel) diff --git a/modules/webcpanel/webcpanel.h b/modules/webcpanel/webcpanel.h new file mode 100644 index 000000000..7e4b5a556 --- /dev/null +++ b/modules/webcpanel/webcpanel.h @@ -0,0 +1,178 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "module.h" +#include "modules/httpd.h" + +#include "static_fileserver.h" +#include "template_fileserver.h" + +extern Module *me; + +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 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
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 = NickAlias::Find(acc); + if (na == NULL) + return NULL; + + Anope::string *n_id = na->GetExt("webcpanel_id"), *n_ip = na->GetExt("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 bool 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) + { + } + + bool OnRequest(HTTPProvider *provider, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) anope_override anope_final + { + ServiceReference panel("Panel", "webcpanel"); + NickAlias *na; + + if (!panel || !(na = panel->GetNickFromSession(client, message))) + { + reply.error = HTTP_FOUND; + reply.headers["Location"] = Anope::string("http") + (provider->IsSSL() ? "s" : "") + "://" + message.headers["Host"] + "/"; + return true; // Access denied + } + + TemplateFileServer::Replacements replacements; + + replacements["TITLE"] = page_title; + replacements["ACCOUNT"] = na->nc->display; + replacements["PAGE_NAME"] = page_name; + replacements["CATEGORY"] = category; + if (na->nc->IsServicesOper()) + replacements["IS_OPER"]; + + Anope::string sections, get; + + for (std::map::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; + } + } + + return this->OnRequest(provider, page_name, client, message, reply, na, replacements); + } + + virtual bool 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 GetData() { return std::set(); } +}; + +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 here into key + * @param key The key to put the replies into r + */ + extern void RunCommand(const Anope::string &user, NickCore *nc, const Anope::string &service, const Anope::string &c, const std::vector ¶ms, TemplateFileServer::Replacements &r, const Anope::string &key = "MESSAGES"); +} + +#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/chanserv/modes.h" +#include "pages/chanserv/drop.h" + +#include "pages/memoserv/memos.h" + +#include "pages/hostserv/request.h" + +#include "pages/operserv/akill.h" -- cgit