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/extra/m_httpd.cpp | 474 --------------------- modules/extra/m_proxyscan.cpp | 379 ---------------- modules/extra/m_sql_log.cpp | 109 +++++ modules/extra/m_xmlrpc.cpp | 186 -------- modules/extra/m_xmlrpc_main.cpp | 280 ------------ modules/extra/webcpanel/CMakeLists.txt | 6 - modules/extra/webcpanel/pages/chanserv/access.cpp | 162 ------- modules/extra/webcpanel/pages/chanserv/access.h | 27 -- modules/extra/webcpanel/pages/chanserv/akick.cpp | 94 ---- modules/extra/webcpanel/pages/chanserv/akick.h | 27 -- modules/extra/webcpanel/pages/chanserv/drop.cpp | 58 --- modules/extra/webcpanel/pages/chanserv/drop.h | 25 -- modules/extra/webcpanel/pages/chanserv/info.cpp | 28 -- modules/extra/webcpanel/pages/chanserv/info.h | 25 -- modules/extra/webcpanel/pages/chanserv/modes.cpp | 108 ----- modules/extra/webcpanel/pages/chanserv/modes.h | 27 -- modules/extra/webcpanel/pages/chanserv/set.cpp | 155 ------- modules/extra/webcpanel/pages/chanserv/set.h | 27 -- modules/extra/webcpanel/pages/chanserv/utils.cpp | 45 -- modules/extra/webcpanel/pages/chanserv/utils.h | 19 - modules/extra/webcpanel/pages/confirm.cpp | 32 -- modules/extra/webcpanel/pages/confirm.h | 22 - modules/extra/webcpanel/pages/hostserv/request.cpp | 36 -- modules/extra/webcpanel/pages/hostserv/request.h | 24 -- modules/extra/webcpanel/pages/index.cpp | 99 ----- modules/extra/webcpanel/pages/index.h | 22 - modules/extra/webcpanel/pages/logout.cpp | 23 - modules/extra/webcpanel/pages/logout.h | 20 - modules/extra/webcpanel/pages/memoserv/memos.cpp | 115 ----- modules/extra/webcpanel/pages/memoserv/memos.h | 25 -- modules/extra/webcpanel/pages/nickserv/access.cpp | 40 -- modules/extra/webcpanel/pages/nickserv/access.h | 25 -- modules/extra/webcpanel/pages/nickserv/alist.cpp | 59 --- modules/extra/webcpanel/pages/nickserv/alist.h | 25 -- modules/extra/webcpanel/pages/nickserv/cert.cpp | 43 -- modules/extra/webcpanel/pages/nickserv/cert.h | 25 -- modules/extra/webcpanel/pages/nickserv/info.cpp | 118 ----- modules/extra/webcpanel/pages/nickserv/info.h | 25 -- modules/extra/webcpanel/pages/operserv/akill.cpp | 64 --- modules/extra/webcpanel/pages/operserv/akill.h | 25 -- modules/extra/webcpanel/pages/register.cpp | 24 -- modules/extra/webcpanel/pages/register.h | 22 - modules/extra/webcpanel/static_fileserver.cpp | 42 -- modules/extra/webcpanel/static_fileserver.h | 19 - modules/extra/webcpanel/template_fileserver.cpp | 261 ------------ modules/extra/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 ---- .../extra/webcpanel/templates/default/confirm.html | 51 --- .../extra/webcpanel/templates/default/cubes.png | Bin 723 -> 0 bytes .../extra/webcpanel/templates/default/favicon.ico | Bin 3774 -> 0 bytes .../extra/webcpanel/templates/default/footer.html | 14 - .../extra/webcpanel/templates/default/header.html | 64 --- .../templates/default/hostserv/request.html | 45 -- .../extra/webcpanel/templates/default/login.html | 55 --- modules/extra/webcpanel/templates/default/logo.png | Bin 19247 -> 0 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 ---- .../webcpanel/templates/default/register.html | 65 --- .../extra/webcpanel/templates/default/style.css | 166 -------- modules/extra/webcpanel/webcpanel.cpp | 270 ------------ modules/extra/webcpanel/webcpanel.h | 178 -------- modules/m_httpd.cpp | 474 +++++++++++++++++++++ modules/m_proxyscan.cpp | 379 ++++++++++++++++ modules/m_sql_log.cpp | 109 ----- modules/m_xmlrpc.cpp | 186 ++++++++ modules/m_xmlrpc_main.cpp | 280 ++++++++++++ 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 ++++++++ 142 files changed, 5138 insertions(+), 5138 deletions(-) delete mode 100644 modules/extra/m_httpd.cpp delete mode 100644 modules/extra/m_proxyscan.cpp create mode 100644 modules/extra/m_sql_log.cpp delete mode 100644 modules/extra/m_xmlrpc.cpp delete mode 100644 modules/extra/m_xmlrpc_main.cpp delete mode 100644 modules/extra/webcpanel/CMakeLists.txt delete mode 100644 modules/extra/webcpanel/pages/chanserv/access.cpp delete mode 100644 modules/extra/webcpanel/pages/chanserv/access.h delete mode 100644 modules/extra/webcpanel/pages/chanserv/akick.cpp delete mode 100644 modules/extra/webcpanel/pages/chanserv/akick.h delete mode 100644 modules/extra/webcpanel/pages/chanserv/drop.cpp delete mode 100644 modules/extra/webcpanel/pages/chanserv/drop.h delete mode 100644 modules/extra/webcpanel/pages/chanserv/info.cpp delete mode 100644 modules/extra/webcpanel/pages/chanserv/info.h delete mode 100644 modules/extra/webcpanel/pages/chanserv/modes.cpp delete mode 100644 modules/extra/webcpanel/pages/chanserv/modes.h delete mode 100644 modules/extra/webcpanel/pages/chanserv/set.cpp delete mode 100644 modules/extra/webcpanel/pages/chanserv/set.h delete mode 100644 modules/extra/webcpanel/pages/chanserv/utils.cpp delete mode 100644 modules/extra/webcpanel/pages/chanserv/utils.h delete mode 100644 modules/extra/webcpanel/pages/confirm.cpp delete mode 100644 modules/extra/webcpanel/pages/confirm.h delete mode 100644 modules/extra/webcpanel/pages/hostserv/request.cpp delete mode 100644 modules/extra/webcpanel/pages/hostserv/request.h delete mode 100644 modules/extra/webcpanel/pages/index.cpp delete mode 100644 modules/extra/webcpanel/pages/index.h delete mode 100644 modules/extra/webcpanel/pages/logout.cpp delete mode 100644 modules/extra/webcpanel/pages/logout.h delete mode 100644 modules/extra/webcpanel/pages/memoserv/memos.cpp delete mode 100644 modules/extra/webcpanel/pages/memoserv/memos.h delete mode 100644 modules/extra/webcpanel/pages/nickserv/access.cpp delete mode 100644 modules/extra/webcpanel/pages/nickserv/access.h delete mode 100644 modules/extra/webcpanel/pages/nickserv/alist.cpp delete mode 100644 modules/extra/webcpanel/pages/nickserv/alist.h delete mode 100644 modules/extra/webcpanel/pages/nickserv/cert.cpp delete mode 100644 modules/extra/webcpanel/pages/nickserv/cert.h delete mode 100644 modules/extra/webcpanel/pages/nickserv/info.cpp delete mode 100644 modules/extra/webcpanel/pages/nickserv/info.h delete mode 100644 modules/extra/webcpanel/pages/operserv/akill.cpp delete mode 100644 modules/extra/webcpanel/pages/operserv/akill.h delete mode 100644 modules/extra/webcpanel/pages/register.cpp delete mode 100644 modules/extra/webcpanel/pages/register.h delete mode 100644 modules/extra/webcpanel/static_fileserver.cpp delete mode 100644 modules/extra/webcpanel/static_fileserver.h delete mode 100644 modules/extra/webcpanel/template_fileserver.cpp delete mode 100644 modules/extra/webcpanel/template_fileserver.h delete mode 100644 modules/extra/webcpanel/templates/default/chanserv/access.html delete mode 100644 modules/extra/webcpanel/templates/default/chanserv/akick.html delete mode 100644 modules/extra/webcpanel/templates/default/chanserv/chanlist.html delete mode 100644 modules/extra/webcpanel/templates/default/chanserv/drop.html delete mode 100644 modules/extra/webcpanel/templates/default/chanserv/main.html delete mode 100644 modules/extra/webcpanel/templates/default/chanserv/modes.html delete mode 100644 modules/extra/webcpanel/templates/default/chanserv/set.html delete mode 100644 modules/extra/webcpanel/templates/default/confirm.html delete mode 100644 modules/extra/webcpanel/templates/default/cubes.png delete mode 100644 modules/extra/webcpanel/templates/default/favicon.ico delete mode 100644 modules/extra/webcpanel/templates/default/footer.html delete mode 100644 modules/extra/webcpanel/templates/default/header.html delete mode 100644 modules/extra/webcpanel/templates/default/hostserv/request.html delete mode 100644 modules/extra/webcpanel/templates/default/login.html delete mode 100644 modules/extra/webcpanel/templates/default/logo.png delete mode 100644 modules/extra/webcpanel/templates/default/memoserv/memos.html delete mode 100644 modules/extra/webcpanel/templates/default/nickserv/access.html delete mode 100644 modules/extra/webcpanel/templates/default/nickserv/alist.html delete mode 100644 modules/extra/webcpanel/templates/default/nickserv/cert.html delete mode 100644 modules/extra/webcpanel/templates/default/nickserv/info.html delete mode 100644 modules/extra/webcpanel/templates/default/operserv/akill.html delete mode 100644 modules/extra/webcpanel/templates/default/register.html delete mode 100644 modules/extra/webcpanel/templates/default/style.css delete mode 100644 modules/extra/webcpanel/webcpanel.cpp delete mode 100644 modules/extra/webcpanel/webcpanel.h create mode 100644 modules/m_httpd.cpp create mode 100644 modules/m_proxyscan.cpp delete mode 100644 modules/m_sql_log.cpp create mode 100644 modules/m_xmlrpc.cpp create mode 100644 modules/m_xmlrpc_main.cpp 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') diff --git a/modules/extra/m_httpd.cpp b/modules/extra/m_httpd.cpp deleted file mode 100644 index e08452d81..000000000 --- a/modules/extra/m_httpd.cpp +++ /dev/null @@ -1,474 +0,0 @@ -/* - * (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 "modules/ssl.h" - -static Anope::string BuildDate() -{ - char timebuf[64]; - struct tm *tm = localtime(&Anope::CurTime); - strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S %Z", tm); - return timebuf; -} - -static Anope::string GetStatusFromCode(HTTPError err) -{ - switch (err) - { - case HTTP_ERROR_OK: - return "200 OK"; - case HTTP_FOUND: - return "302 Found"; - case HTTP_BAD_REQUEST: - return "400 Bad Request"; - case HTTP_PAGE_NOT_FOUND: - return "404 Not Found"; - case HTTP_NOT_SUPPORTED: - return "505 HTTP Version Not Supported"; - } - - return "501 Not Implemented"; -} - -class MyHTTPClient : public HTTPClient -{ - HTTPProvider *provider; - HTTPMessage message; - bool header_done, served; - Anope::string page_name; - Reference page; - Anope::string ip; - - unsigned content_length; - - enum - { - ACTION_NONE, - ACTION_GET, - ACTION_POST - } action; - - void Serve() - { - if (this->served) - return; - this->served = true; - - if (!this->page) - { - this->SendError(HTTP_PAGE_NOT_FOUND, "Page not found"); - return; - } - - if (this->ip == this->provider->ext_ip) - { - for (unsigned i = 0; i < this->provider->ext_headers.size(); ++i) - { - const Anope::string &token = this->provider->ext_headers[i]; - - if (this->message.headers.count(token)) - { - this->ip = this->message.headers[token]; - Log(LOG_DEBUG, "httpd") << "m_httpd: IP for connection " << this->GetFD() << " changed to " << this->ip; - break; - } - } - } - - Log(LOG_DEBUG, "httpd") << "m_httpd: Serving page " << this->page_name << " to " << this->ip; - - HTTPReply reply; - reply.content_type = this->page->GetContentType(); - - if (this->page->OnRequest(this->provider, this->page_name, this, this->message, reply)) - this->SendReply(&reply); - } - - public: - time_t created; - - MyHTTPClient(HTTPProvider *l, int f, const sockaddrs &a) : Socket(f, l->IsIPv6()), HTTPClient(l, f, a), provider(l), header_done(false), served(false), ip(a.addr()), content_length(0), action(ACTION_NONE), created(Anope::CurTime) - { - Log(LOG_DEBUG, "httpd") << "Accepted connection " << f << " from " << a.addr(); - } - - ~MyHTTPClient() - { - Log(LOG_DEBUG, "httpd") << "Closing connection " << this->GetFD() << " from " << this->ip; - } - - /* Close connection once all data is written */ - bool ProcessWrite() anope_override - { - return !BinarySocket::ProcessWrite() || this->write_buffer.empty() ? false : true; - } - - const Anope::string GetIP() anope_override - { - return this->ip; - } - - bool Read(const char *buffer, size_t l) anope_override - { - message.content.append(buffer, l); - - for (size_t nl; !this->header_done && (nl = message.content.find('\n')) != Anope::string::npos;) - { - Anope::string token = message.content.substr(0, nl).trim(); - message.content = message.content.substr(nl + 1); - - if (token.empty()) - this->header_done = true; - else - this->Read(token); - } - - if (!this->header_done) - return true; - - if (this->message.content.length() >= this->content_length) - { - sepstream sep(this->message.content, '&'); - Anope::string token; - - while (sep.GetToken(token)) - { - size_t sz = token.find('='); - if (sz == Anope::string::npos || !sz || sz + 1 >= token.length()) - continue; - this->message.post_data[token.substr(0, sz)] = HTTPUtils::URLDecode(token.substr(sz + 1)); - Log(LOG_DEBUG_2) << "HTTP POST from " << this->clientaddr.addr() << ": " << token.substr(0, sz) << ": " << this->message.post_data[token.substr(0, sz)]; - } - - this->Serve(); - } - - return true; - } - - bool Read(const Anope::string &buf) - { - Log(LOG_DEBUG_2) << "HTTP from " << this->clientaddr.addr() << ": " << buf; - - if (this->action == ACTION_NONE) - { - std::vector params; - spacesepstream(buf).GetTokens(params); - - if (params.empty() || (params[0] != "GET" && params[0] != "POST")) - { - this->SendError(HTTP_BAD_REQUEST, "Unknown operation"); - return true; - } - - if (params.size() != 3) - { - this->SendError(HTTP_BAD_REQUEST, "Invalid parameters"); - return true; - } - - if (params[0] == "GET") - this->action = ACTION_GET; - else if (params[0] == "POST") - this->action = ACTION_POST; - - Anope::string targ = params[1]; - size_t q = targ.find('?'); - if (q != Anope::string::npos) - { - sepstream sep(targ.substr(q + 1), '&'); - targ = targ.substr(0, q); - - Anope::string token; - while (sep.GetToken(token)) - { - size_t sz = token.find('='); - if (sz == Anope::string::npos || !sz || sz + 1 >= token.length()) - continue; - this->message.get_data[token.substr(0, sz)] = HTTPUtils::URLDecode(token.substr(sz + 1)); - } - } - - this->page = this->provider->FindPage(targ); - this->page_name = targ; - } - else if (buf.find("Cookie: ") == 0) - { - spacesepstream sep(buf.substr(8)); - Anope::string token; - - while (sep.GetToken(token)) - { - size_t sz = token.find('='); - if (sz == Anope::string::npos || !sz || sz + 1 >= token.length()) - continue; - size_t end = token.length() - (sz + 1); - if (!sep.StreamEnd()) - --end; // Remove trailing ; - this->message.cookies[token.substr(0, sz)] = token.substr(sz + 1, end); - } - } - else if (buf.find("Content-Length: ") == 0) - { - try - { - this->content_length = convertTo(buf.substr(16)); - } - catch (const ConvertException &ex) { } - } - else if (buf.find(':') != Anope::string::npos) - { - size_t sz = buf.find(':'); - if (sz + 2 < buf.length()) - this->message.headers[buf.substr(0, sz)] = buf.substr(sz + 2); - } - - return true; - } - - void SendError(HTTPError err, const Anope::string &msg) anope_override - { - HTTPReply h; - - h.error = err; - - h.Write(msg); - - this->SendReply(&h); - } - - void SendReply(HTTPReply *msg) anope_override - { - this->WriteClient("HTTP/1.1 " + GetStatusFromCode(msg->error)); - this->WriteClient("Date: " + BuildDate()); - this->WriteClient("Server: Anope-" + Anope::VersionShort()); - if (msg->content_type.empty()) - this->WriteClient("Content-Type: text/html"); - else - this->WriteClient("Content-Type: " + msg->content_type); - this->WriteClient("Content-Length: " + stringify(msg->length)); - - for (unsigned i = 0; i < msg->cookies.size(); ++i) - { - Anope::string buf = "Set-Cookie:"; - - for (HTTPReply::cookie::iterator it = msg->cookies[i].begin(), it_end = msg->cookies[i].end(); it != it_end; ++it) - buf += " " + it->first + "=" + it->second + ";"; - - buf.erase(buf.length() - 1); - - this->WriteClient(buf); - } - - typedef std::map map; - for (map::iterator it = msg->headers.begin(), it_end = msg->headers.end(); it != it_end; ++it) - this->WriteClient(it->first + ": " + it->second); - - this->WriteClient("Connection: Close"); - this->WriteClient(""); - - for (unsigned i = 0; i < msg->out.size(); ++i) - { - HTTPReply::Data* d = msg->out[i]; - - this->Write(d->buf, d->len); - - delete d; - } - - msg->out.clear(); - } -}; - -class MyHTTPProvider : public HTTPProvider, public Timer -{ - int timeout; - std::map pages; - std::list > clients; - - public: - MyHTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, const int t, bool s) : Socket(-1, i.find(':') != Anope::string::npos), HTTPProvider(c, n, i, p, s), Timer(c, 10, Anope::CurTime, true), timeout(t) { } - - void Tick(time_t) anope_override - { - while (!this->clients.empty()) - { - Reference& c = this->clients.front(); - if (c && c->created + this->timeout >= Anope::CurTime) - break; - - delete c; - this->clients.pop_front(); - } - } - - ClientSocket* OnAccept(int fd, const sockaddrs &addr) anope_override - { - MyHTTPClient *c = new MyHTTPClient(this, fd, addr); - this->clients.push_back(c); - return c; - } - - bool RegisterPage(HTTPPage *page) anope_override - { - return this->pages.insert(std::make_pair(page->GetURL(), page)).second; - } - - void UnregisterPage(HTTPPage *page) anope_override - { - this->pages.erase(page->GetURL()); - } - - HTTPPage* FindPage(const Anope::string &pname) - { - if (this->pages.count(pname) == 0) - return NULL; - return this->pages[pname]; - } -}; - -class HTTPD : public Module -{ - ServiceReference sslref; - std::map providers; - public: - HTTPD(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), sslref("SSLService", "ssl") - { - - } - - ~HTTPD() - { - for (std::map::const_iterator it = SocketEngine::Sockets.begin(), it_end = SocketEngine::Sockets.end(); it != it_end;) - { - Socket *s = it->second; - ++it; - - if (dynamic_cast(s) || dynamic_cast(s)) - delete s; - } - - this->providers.clear(); - } - - void OnReload(Configuration::Conf *config) anope_override - { - Configuration::Block *conf = config->GetModule(this); - std::set existing; - - for (int i = 0; i < conf->CountBlock("httpd"); ++i) - { - Configuration::Block *block = conf->GetBlock("httpd", i); - - - const Anope::string &hname = block->Get("name", "httpd/main"); - existing.insert(hname); - - Anope::string ip = block->Get("ip"); - int port = block->Get("port", "8080"); - int timeout = block->Get("timeout", "30"); - bool ssl = block->Get("ssl", "no"); - Anope::string ext_ip = block->Get("extforward_ip"); - Anope::string ext_header = block->Get("extforward_header"); - - if (ip.empty()) - { - Log(this) << "You must configure a bind IP for HTTP server " << hname; - continue; - } - else if (port <= 0 || port > 65535) - { - Log(this) << "You must configure a (valid) listen port for HTTP server " << hname; - continue; - } - - MyHTTPProvider *p; - if (this->providers.count(hname) == 0) - { - try - { - p = new MyHTTPProvider(this, hname, ip, port, timeout, ssl); - if (ssl && sslref) - sslref->Init(p); - } - catch (const SocketException &ex) - { - Log(this) << "Unable to create HTTP server " << hname << ": " << ex.GetReason(); - continue; - } - this->providers[hname] = p; - - Log(this) << "Created HTTP server " << hname; - } - else - { - p = this->providers[hname]; - - if (p->GetIP() != ip || p->GetPort() != port) - { - delete p; - this->providers.erase(hname); - - Log(this) << "Changing HTTP server " << hname << " to " << ip << ":" << port; - - try - { - p = new MyHTTPProvider(this, hname, ip, port, timeout, ssl); - if (ssl && sslref) - sslref->Init(p); - } - catch (const SocketException &ex) - { - Log(this) << "Unable to create HTTP server " << hname << ": " << ex.GetReason(); - continue; - } - - this->providers[hname] = p; - } - } - - - p->ext_ip = ext_ip; - spacesepstream(ext_header).GetTokens(p->ext_headers); - } - - for (std::map::iterator it = this->providers.begin(), it_end = this->providers.end(); it != it_end;) - { - HTTPProvider *p = it->second; - ++it; - - if (existing.count(p->name) == 0) - { - Log(this) << "Removing HTTP server " << p->name; - this->providers.erase(p->name); - delete p; - } - } - } - - void OnModuleLoad(User *u, Module *m) anope_override - { - if (m->name != "m_ssl") - return; - - for (std::map::iterator it = this->providers.begin(), it_end = this->providers.end(); it != it_end; ++it) - { - MyHTTPProvider *p = it->second; - - if (p->IsSSL() && sslref) - try - { - sslref->Init(p); - } - catch (const CoreException &) { } // Throws on reinitialization - } - } -}; - -MODULE_INIT(HTTPD) diff --git a/modules/extra/m_proxyscan.cpp b/modules/extra/m_proxyscan.cpp deleted file mode 100644 index 98178260c..000000000 --- a/modules/extra/m_proxyscan.cpp +++ /dev/null @@ -1,379 +0,0 @@ -/* - * (C) 2003-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - */ - -#include "module.h" - -struct ProxyCheck -{ - std::set types; - std::vector ports; - time_t duration; - Anope::string reason; -}; - -static Anope::string ProxyCheckString; -static Anope::string target_ip; -static unsigned short target_port; -static bool add_to_akill; - -class ProxyCallbackListener : public ListenSocket -{ - class ProxyCallbackClient : public ClientSocket, public BufferedSocket - { - public: - ProxyCallbackClient(ListenSocket *l, int f, const sockaddrs &a) : Socket(f, l->IsIPv6()), ClientSocket(l, a), BufferedSocket() - { - } - - void OnAccept() anope_override - { - this->Write(ProxyCheckString); - } - - bool ProcessWrite() anope_override - { - return !BufferedSocket::ProcessWrite() || this->write_buffer.empty() ? false : true; - } - }; - - public: - ProxyCallbackListener(const Anope::string &b, int p) : Socket(-1, b.find(':') != Anope::string::npos), ListenSocket(b, p, false) - { - } - - ClientSocket *OnAccept(int fd, const sockaddrs &addr) anope_override - { - return new ProxyCallbackClient(this, fd, addr); - } -}; - -class ProxyConnect : public ConnectionSocket -{ - static ServiceReference akills; - - public: - static std::set proxies; - - ProxyCheck proxy; - unsigned short port; - time_t created; - - ProxyConnect(ProxyCheck &p, unsigned short po) : Socket(-1), ConnectionSocket(), proxy(p), - port(po), created(Anope::CurTime) - { - proxies.insert(this); - } - - ~ProxyConnect() - { - proxies.erase(this); - } - - virtual void OnConnect() anope_override = 0; - virtual const Anope::string GetType() const = 0; - - protected: - void Ban() - { - Anope::string reason = this->proxy.reason; - - reason = reason.replace_all_cs("%t", this->GetType()); - reason = reason.replace_all_cs("%i", this->conaddr.addr()); - reason = reason.replace_all_cs("%p", stringify(this->conaddr.port())); - - BotInfo *OperServ = Config->GetClient("OperServ"); - Log(OperServ) << "PROXYSCAN: Open " << this->GetType() << " proxy found on " << this->conaddr.addr() << ":" << this->conaddr.port() << " (" << reason << ")"; - XLine *x = new XLine("*@" + this->conaddr.addr(), OperServ ? OperServ->nick : "", Anope::CurTime + this->proxy.duration, reason, XLineManager::GenerateUID()); - if (add_to_akill && akills) - { - akills->AddXLine(x); - akills->Send(NULL, x); - } - else - { - if (IRCD->CanSZLine) - IRCD->SendSZLine(NULL, x); - else - IRCD->SendAkill(NULL, x); - delete x; - } - } -}; -ServiceReference ProxyConnect::akills("XLineManager", "xlinemanager/sgline"); -std::set ProxyConnect::proxies; - -class HTTPProxyConnect : public ProxyConnect, public BufferedSocket -{ - public: - HTTPProxyConnect(ProxyCheck &p, unsigned short po) : Socket(-1), ProxyConnect(p, po), BufferedSocket() - { - } - - void OnConnect() anope_override - { - this->Write("CONNECT %s:%d HTTP/1.0", target_ip.c_str(), target_port); - this->Write("Content-length: 0"); - this->Write("Connection: close"); - this->Write(""); - } - - const Anope::string GetType() const anope_override - { - return "HTTP"; - } - - bool ProcessRead() anope_override - { - bool b = BufferedSocket::ProcessRead(); - if (this->GetLine() == ProxyCheckString) - { - this->Ban(); - return false; - } - return b; - } -}; - -class SOCKS5ProxyConnect : public ProxyConnect, public BinarySocket -{ - public: - SOCKS5ProxyConnect(ProxyCheck &p, unsigned short po) : Socket(-1), ProxyConnect(p, po), BinarySocket() - { - } - - void OnConnect() anope_override - { - sockaddrs target_addr; - char buf[4 + sizeof(target_addr.sa4.sin_addr.s_addr) + sizeof(target_addr.sa4.sin_port)]; - int ptr = 0; - target_addr.pton(AF_INET, target_ip, target_port); - if (!target_addr.valid()) - return; - - buf[ptr++] = 5; // Version - buf[ptr++] = 1; // # of methods - buf[ptr++] = 0; // No authentication - - this->Write(buf, ptr); - - ptr = 1; - buf[ptr++] = 1; // Connect - buf[ptr++] = 0; // Reserved - buf[ptr++] = 1; // IPv4 - memcpy(buf + ptr, &target_addr.sa4.sin_addr.s_addr, sizeof(target_addr.sa4.sin_addr.s_addr)); - ptr += sizeof(target_addr.sa4.sin_addr.s_addr); - memcpy(buf + ptr, &target_addr.sa4.sin_port, sizeof(target_addr.sa4.sin_port)); - ptr += sizeof(target_addr.sa4.sin_port); - - this->Write(buf, ptr); - } - - const Anope::string GetType() const anope_override - { - return "SOCKS5"; - } - - bool Read(const char *buffer, size_t l) anope_override - { - if (l >= ProxyCheckString.length() && !strncmp(buffer, ProxyCheckString.c_str(), ProxyCheckString.length())) - { - this->Ban(); - return false; - } - return true; - } -}; - -class ModuleProxyScan : public Module -{ - Anope::string listen_ip; - unsigned short listen_port; - Anope::string con_notice, con_source; - std::vector proxyscans; - - ProxyCallbackListener *listener; - - class ConnectionTimeout : public Timer - { - public: - ConnectionTimeout(Module *c, long timeout) : Timer(c, timeout, Anope::CurTime, true) - { - } - - void Tick(time_t) anope_override - { - for (std::set::iterator it = ProxyConnect::proxies.begin(), it_end = ProxyConnect::proxies.end(); it != it_end; ++it) - { - ProxyConnect *p = *it; - - if (p->created + this->GetSecs() < Anope::CurTime) - p->flags[SF_DEAD] = true; - } - } - } connectionTimeout; - - public: - ModuleProxyScan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), - connectionTimeout(this, 5) - { - - - this->listener = NULL; - } - - ~ModuleProxyScan() - { - for (std::set::iterator it = ProxyConnect::proxies.begin(), it_end = ProxyConnect::proxies.end(); it != it_end;) - { - ProxyConnect *p = *it; - ++it; - delete p; - } - - for (std::map::const_iterator it = SocketEngine::Sockets.begin(), it_end = SocketEngine::Sockets.end(); it != it_end;) - { - Socket *s = it->second; - ++it; - - ClientSocket *cs = dynamic_cast(s); - if (cs != NULL && cs->ls == this->listener) - delete s; - } - - delete this->listener; - } - - void OnReload(Configuration::Conf *conf) anope_override - { - Configuration::Block *config = Config->GetModule(this); - - Anope::string s_target_ip = config->Get("target_ip"); - if (s_target_ip.empty()) - throw ConfigException(this->name + " target_ip may not be empty"); - - int s_target_port = config->Get("target_port", "-1"); - if (s_target_port <= 0) - throw ConfigException(this->name + " target_port may not be empty and must be a positive number"); - - Anope::string s_listen_ip = config->Get("listen_ip"); - if (s_listen_ip.empty()) - throw ConfigException(this->name + " listen_ip may not be empty"); - - int s_listen_port = config->Get("listen_port", "-1"); - if (s_listen_port <= 0) - throw ConfigException(this->name + " listen_port may not be empty and must be a positive number"); - - target_ip = s_target_ip; - target_port = s_target_port; - this->listen_ip = s_listen_ip; - this->listen_port = s_listen_port; - this->con_notice = config->Get("connect_notice"); - this->con_source = config->Get("connect_source"); - add_to_akill = config->Get("add_to_akill", "true"); - this->connectionTimeout.SetSecs(config->Get("timeout", "5s")); - - ProxyCheckString = Config->GetBlock("networkinfo")->Get("networkname") + " proxy check"; - delete this->listener; - this->listener = NULL; - try - { - this->listener = new ProxyCallbackListener(this->listen_ip, this->listen_port); - } - catch (const SocketException &ex) - { - throw ConfigException("m_proxyscan: " + ex.GetReason()); - } - - this->proxyscans.clear(); - for (int i = 0; i < config->CountBlock("proxyscan"); ++i) - { - Configuration::Block *block = config->GetBlock("proxyscan", i); - ProxyCheck p; - Anope::string token; - - commasepstream sep(block->Get("type")); - while (sep.GetToken(token)) - { - if (!token.equals_ci("HTTP") && !token.equals_ci("SOCKS5")) - continue; - p.types.insert(token); - } - if (p.types.empty()) - continue; - - commasepstream sep2(block->Get("port")); - while (sep2.GetToken(token)) - { - try - { - unsigned short port = convertTo(token); - p.ports.push_back(port); - } - catch (const ConvertException &) { } - } - if (p.ports.empty()) - continue; - - p.duration = block->Get("time", "4h"); - p.reason = block->Get("reason"); - if (p.reason.empty()) - continue; - - this->proxyscans.push_back(p); - } - } - - void OnUserConnect(User *user, bool &exempt) anope_override - { - if (exempt || user->Quitting() || !Me->IsSynced() || !user->server->IsSynced()) - return; - - /* At this time we only support IPv4 */ - sockaddrs user_ip; - user_ip.pton(AF_INET, user->ip); - if (!user_ip.valid()) - /* User doesn't have a valid IPv4 IP (ipv6/spoof/etc) */ - return; - - if (!this->con_notice.empty() && !this->con_source.empty()) - { - BotInfo *bi = BotInfo::Find(this->con_source); - if (bi) - user->SendMessage(bi, this->con_notice); - } - - for (unsigned i = this->proxyscans.size(); i > 0; --i) - { - ProxyCheck &p = this->proxyscans[i - 1]; - - for (std::set::iterator it = p.types.begin(), it_end = p.types.end(); it != it_end; ++it) - { - for (unsigned k = 0; k < p.ports.size(); ++k) - { - try - { - ProxyConnect *con = NULL; - if (it->equals_ci("HTTP")) - con = new HTTPProxyConnect(p, p.ports[k]); - else if (it->equals_ci("SOCKS5")) - con = new SOCKS5ProxyConnect(p, p.ports[k]); - else - continue; - con->Connect(user->ip, p.ports[k]); - } - catch (const SocketException &ex) - { - Log(LOG_DEBUG) << "m_proxyscan: " << ex.GetReason(); - } - } - } - } - } -}; - -MODULE_INIT(ModuleProxyScan) - diff --git a/modules/extra/m_sql_log.cpp b/modules/extra/m_sql_log.cpp new file mode 100644 index 000000000..b0c6c037f --- /dev/null +++ b/modules/extra/m_sql_log.cpp @@ -0,0 +1,109 @@ +/* + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +#include "module.h" +#include "modules/sql.h" + +class SQLLog : public Module +{ + std::set inited; + Anope::string table; + + public: + SQLLog(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + { + } + + void OnReload(Configuration::Conf *conf) anope_override + { + Configuration::Block *config = conf->GetModule(this); + this->table = config->Get("table", "logs"); + } + + void OnLogMessage(LogInfo *li, const Log *l, const Anope::string &msg) anope_override + { + Anope::string ref_name; + ServiceReference SQL; + + for (unsigned i = 0; i < li->targets.size(); ++i) + { + const Anope::string &target = li->targets[i]; + size_t sz = target.find("sql_log:"); + if (!sz) + { + ref_name = target.substr(8); + SQL = ServiceReference("SQL::Provider", ref_name); + break; + } + } + + if (!SQL) + return; + + if (!inited.count(ref_name)) + { + inited.insert(ref_name); + + SQL::Query create("CREATE TABLE IF NOT EXISTS `" + table + "` (" + "`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP," + "`type` varchar(64) NOT NULL," + "`user` varchar(64) NOT NULL," + "`acc` varchar(64) NOT NULL," + "`command` varchar(64) NOT NULL," + "`channel` varchar(64) NOT NULL," + "`msg` text NOT NULL" + ")"); + + SQL->Run(NULL, create); + } + + SQL::Query insert("INSERT INTO `" + table + "` (`type`,`user`,`acc`,`command`,`channel`,`msg`)" + "VALUES (@type@, @user@, @acc@, @command@, @channel@, @msg@)"); + + switch (l->type) + { + case LOG_ADMIN: + insert.SetValue("type", "ADMIN"); + break; + case LOG_OVERRIDE: + insert.SetValue("type", "OVERRIDE"); + break; + case LOG_COMMAND: + insert.SetValue("type", "COMMAND"); + break; + case LOG_SERVER: + insert.SetValue("type", "SERVER"); + break; + case LOG_CHANNEL: + insert.SetValue("type", "CHANNEL"); + break; + case LOG_USER: + insert.SetValue("type", "USER"); + break; + case LOG_MODULE: + insert.SetValue("type", "MODULE"); + break; + case LOG_NORMAL: + insert.SetValue("type", "NORMAL"); + break; + default: + return; + } + + insert.SetValue("user", l->u ? l->u->nick : ""); + insert.SetValue("acc", l->nc ? l->nc->display : ""); + insert.SetValue("command", l->c ? l->c->name : ""); + insert.SetValue("channel", l->ci ? l->ci->name : ""); + insert.SetValue("msg", msg); + + SQL->Run(NULL, insert); + } +}; + +MODULE_INIT(SQLLog) diff --git a/modules/extra/m_xmlrpc.cpp b/modules/extra/m_xmlrpc.cpp deleted file mode 100644 index 36401b800..000000000 --- a/modules/extra/m_xmlrpc.cpp +++ /dev/null @@ -1,186 +0,0 @@ - -#include "module.h" -#include "modules/xmlrpc.h" -#include "modules/httpd.h" - -static struct special_chars -{ - Anope::string character; - Anope::string replace; - - special_chars(const Anope::string &c, const Anope::string &r) : character(c), replace(r) { } -} -special[] = { - special_chars("&", "&"), - special_chars("\"", """), - special_chars("<", "<"), - special_chars(">", "&qt;"), - special_chars("'", "'"), - special_chars("\n", " "), - special_chars("\002", ""), // bold - special_chars("\003", ""), // color - special_chars("\035", ""), // italics - special_chars("\037", ""), // underline - special_chars("\026", ""), // reverses - special_chars("", "") -}; - -class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage -{ - std::deque events; - - public: - MyXMLRPCServiceInterface(Module *creator, const Anope::string &sname) : XMLRPCServiceInterface(creator, sname), HTTPPage("/xmlrpc", "text/xml") { } - - void Register(XMLRPCEvent *event) - { - this->events.push_back(event); - } - - void Unregister(XMLRPCEvent *event) - { - std::deque::iterator it = std::find(this->events.begin(), this->events.end(), event); - - if (it != this->events.end()) - this->events.erase(it); - } - - Anope::string Sanitize(const Anope::string &string) anope_override - { - Anope::string ret = string; - for (int i = 0; special[i].character.empty() == false; ++i) - ret = ret.replace_all_cs(special[i].character, special[i].replace); - return ret; - } - - private: - static bool GetData(Anope::string &content, Anope::string &tag, Anope::string &data) - { - if (content.empty()) - return false; - - Anope::string prev, cur; - bool istag; - - do - { - prev = cur; - cur.clear(); - - int len = 0; - istag = false; - - if (content[0] == '<') - { - len = content.find_first_of('>'); - istag = true; - } - else if (content[0] != '>') - { - len = content.find_first_of('<'); - } - - if (len) - { - if (istag) - { - cur = content.substr(1, len - 1); - content.erase(0, len + 1); - while (!content.empty() && content[0] == ' ') - content.erase(content.begin()); - } - else - { - cur = content.substr(0,len); - content.erase(0, len); - } - } - } - while (istag && !content.empty()); - - tag = prev; - data = cur; - return !istag && !data.empty(); - } - - public: - bool OnRequest(HTTPProvider *provider, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) anope_override - { - Anope::string content = message.content, tname, data; - XMLRPCRequest request(reply); - - while (GetData(content, tname, data)) - { - Log(LOG_DEBUG) << "m_xmlrpc: Tag name: " << tname << ", data: " << data; - if (tname == "methodName") - request.name = data; - else if (tname == "name" && data == "id") - { - GetData(content, tname, data); - request.id = data; - } - else if (tname == "string") - request.data.push_back(data); - } - - for (unsigned i = 0; i < this->events.size(); ++i) - { - XMLRPCEvent *e = this->events[i]; - - if (!e->Run(this, client, request)) - return false; - else if (!request.get_replies().empty()) - { - this->Reply(request); - return true; - } - } - - reply.error = HTTP_PAGE_NOT_FOUND; - reply.Write("Unrecognized query"); - return true; - } - - void Reply(XMLRPCRequest &request) - { - if (!request.id.empty()) - request.reply("id", request.id); - - Anope::string r = "\n\n" + request.name + "\n\n\n\n\n"; - for (std::map::const_iterator it = request.get_replies().begin(); it != request.get_replies().end(); ++it) - r += "\n" + it->first + "\n\n" + this->Sanitize(it->second) + "\n\n\n"; - r += "\n\n\n\n"; - - request.r.Write(r); - } -}; - -class ModuleXMLRPC : public Module -{ - ServiceReference httpref; - public: - MyXMLRPCServiceInterface xmlrpcinterface; - - ModuleXMLRPC(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), - httpref("HTTPProvider", "httpd/main"), xmlrpcinterface(this, "xmlrpc") - { - if (!httpref) - throw ModuleException("Unable to find http reference, is m_httpd loaded?"); - httpref->RegisterPage(&xmlrpcinterface); - - } - - ~ModuleXMLRPC() - { - if (httpref) - httpref->UnregisterPage(&xmlrpcinterface); - } - - void OnReload(Configuration::Conf *conf) anope_override - { - this->httpref = ServiceReference("HTTPProvider", conf->GetModule(this)->Get("server", "httpd/main")); - } -}; - -MODULE_INIT(ModuleXMLRPC) - diff --git a/modules/extra/m_xmlrpc_main.cpp b/modules/extra/m_xmlrpc_main.cpp deleted file mode 100644 index 17dd8b96f..000000000 --- a/modules/extra/m_xmlrpc_main.cpp +++ /dev/null @@ -1,280 +0,0 @@ -#include "module.h" -#include "modules/xmlrpc.h" - -static Module *me; - -class XMLRPCIdentifyRequest : public IdentifyRequest -{ - XMLRPCRequest request; - HTTPReply repl; /* Request holds a reference to the HTTPReply, because we might exist long enough to invalidate it - we'll copy it here then reset the reference before we use it */ - Reference client; - Reference xinterface; - - public: - XMLRPCIdentifyRequest(Module *m, XMLRPCRequest& req, HTTPClient *c, XMLRPCServiceInterface* iface, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(m, acc, pass), request(req), repl(request.r), client(c), xinterface(iface) { } - - void OnSuccess() anope_override - { - if (!xinterface || !client) - return; - - request.r = this->repl; - - request.reply("result", "Success"); - request.reply("account", GetAccount()); - - xinterface->Reply(request); - client->SendReply(&request.r); - } - - void OnFail() anope_override - { - if (!xinterface || !client) - return; - - request.r = this->repl; - - request.reply("error", "Invalid password"); - - xinterface->Reply(request); - client->SendReply(&request.r); - } -}; - -class MyXMLRPCEvent : public XMLRPCEvent -{ - public: - bool Run(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) anope_override - { - if (request.name == "command") - this->DoCommand(iface, client, request); - else if (request.name == "checkAuthentication") - return this->DoCheckAuthentication(iface, client, request); - else if (request.name == "stats") - this->DoStats(iface, client, request); - else if (request.name == "channel") - this->DoChannel(iface, client, request); - else if (request.name == "user") - this->DoUser(iface, client, request); - else if (request.name == "opers") - this->DoOperType(iface, client, request); - - return true; - } - - private: - void DoCommand(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) - { - Anope::string service = request.data.size() > 0 ? request.data[0] : ""; - Anope::string user = request.data.size() > 1 ? request.data[1] : ""; - Anope::string command = request.data.size() > 2 ? request.data[2] : ""; - - if (service.empty() || user.empty() || command.empty()) - request.reply("error", "Invalid parameters"); - else - { - BotInfo *bi = BotInfo::Find(service); - if (!bi) - request.reply("error", "Invalid service"); - else - { - request.reply("result", "Success"); - - NickAlias *na = NickAlias::Find(user); - - Anope::string out; - - struct XMLRPCommandReply : CommandReply - { - Anope::string &str; - - XMLRPCommandReply(Anope::string &s) : str(s) { } - - void SendMessage(BotInfo *, const Anope::string &msg) anope_override - { - str += msg + "\n"; - }; - } - reply(out); - - CommandSource source(user, NULL, na ? *na->nc : NULL, &reply, bi); - Command::Run(source, command); - - if (!out.empty()) - request.reply("return", iface->Sanitize(out)); - } - } - } - - bool DoCheckAuthentication(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) - { - Anope::string username = request.data.size() > 0 ? request.data[0] : ""; - Anope::string password = request.data.size() > 1 ? request.data[1] : ""; - - if (username.empty() || password.empty()) - request.reply("error", "Invalid parameters"); - else - { - XMLRPCIdentifyRequest *req = new XMLRPCIdentifyRequest(me, request, client, iface, username, password); - FOREACH_MOD(OnCheckAuthentication, (NULL, req)); - req->Dispatch(); - return false; - } - - return true; - } - - void DoStats(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) - { - request.reply("uptime", stringify(Anope::CurTime - Anope::StartTime)); - request.reply("uplinkname", Me->GetLinks().front()->GetName()); - { - Anope::string buf; - for (std::set::iterator it = Servers::Capab.begin(); it != Servers::Capab.end(); ++it) - buf += " " + *it; - if (!buf.empty()) - buf.erase(buf.begin()); - request.reply("uplinkcapab", buf); - } - request.reply("usercount", stringify(UserListByNick.size())); - request.reply("maxusercount", stringify(MaxUserCount)); - request.reply("channelcount", stringify(ChannelList.size())); - } - - void DoChannel(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) - { - if (request.data.empty()) - return; - - Channel *c = Channel::Find(request.data[0]); - - request.reply("name", iface->Sanitize(c ? c->name : request.data[0])); - - if (c) - { - request.reply("bancount", stringify(c->HasMode("BAN"))); - int count = 0; - std::pair its = c->GetModeList("BAN"); - for (; its.first != its.second; ++its.first) - request.reply("ban" + stringify(++count), iface->Sanitize(its.first->second)); - - request.reply("exceptcount", stringify(c->HasMode("EXCEPT"))); - count = 0; - its = c->GetModeList("EXCEPT"); - for (; its.first != its.second; ++its.first) - request.reply("except" + stringify(++count), iface->Sanitize(its.first->second)); - - request.reply("invitecount", stringify(c->HasMode("INVITEOVERRIDE"))); - count = 0; - its = c->GetModeList("INVITEOVERRIDE"); - for (; its.first != its.second; ++its.first) - request.reply("invite" + stringify(++count), iface->Sanitize(its.first->second)); - - Anope::string users; - for (Channel::ChanUserList::const_iterator it = c->users.begin(); it != c->users.end(); ++it) - { - ChanUserContainer *uc = it->second; - users += uc->status.BuildModePrefixList() + uc->user->nick + " "; - } - if (!users.empty()) - { - users.erase(users.length() - 1); - request.reply("users", iface->Sanitize(users)); - } - - if (!c->topic.empty()) - request.reply("topic", iface->Sanitize(c->topic)); - - if (!c->topic_setter.empty()) - request.reply("topicsetter", iface->Sanitize(c->topic_setter)); - - request.reply("topictime", stringify(c->topic_time)); - request.reply("topicts", stringify(c->topic_ts)); - } - } - - void DoUser(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) - { - if (request.data.empty()) - return; - - User *u = User::Find(request.data[0]); - - request.reply("nick", iface->Sanitize(u ? u->nick : request.data[0])); - - if (u) - { - request.reply("ident", iface->Sanitize(u->GetIdent())); - request.reply("vident", iface->Sanitize(u->GetVIdent())); - request.reply("host", iface->Sanitize(u->host)); - if (!u->vhost.empty()) - request.reply("vhost", iface->Sanitize(u->vhost)); - if (!u->chost.empty()) - request.reply("chost", iface->Sanitize(u->chost)); - if (!u->ip.empty()) - request.reply("ip", u->ip); - request.reply("timestamp", stringify(u->timestamp)); - request.reply("signon", stringify(u->signon)); - if (u->Account()) - { - request.reply("account", iface->Sanitize(u->Account()->display)); - if (u->Account()->o) - request.reply("opertype", iface->Sanitize(u->Account()->o->ot->GetName())); - } - - Anope::string channels; - for (User::ChanUserList::const_iterator it = u->chans.begin(); it != u->chans.end(); ++it) - { - ChanUserContainer *cc = it->second; - channels += cc->status.BuildModePrefixList() + cc->chan->name + " "; - } - if (!channels.empty()) - { - channels.erase(channels.length() - 1); - request.reply("channels", channels); - } - } - } - - void DoOperType(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) - { - for (unsigned i = 0; i < Config->MyOperTypes.size(); ++i) - { - OperType *ot = Config->MyOperTypes[i]; - Anope::string perms; - for (std::list::const_iterator it2 = ot->GetPrivs().begin(), it2_end = ot->GetPrivs().end(); it2 != it2_end; ++it2) - perms += " " + *it2; - for (std::list::const_iterator it2 = ot->GetCommands().begin(), it2_end = ot->GetCommands().end(); it2 != it2_end; ++it2) - perms += " " + *it2; - request.reply(ot->GetName(), perms); - } - } -}; - -class ModuleXMLRPCMain : public Module -{ - ServiceReference xmlrpc; - - MyXMLRPCEvent stats; - - public: - ModuleXMLRPCMain(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), xmlrpc("XMLRPCServiceInterface", "xmlrpc") - { - me = this; - - if (!xmlrpc) - throw ModuleException("Unable to find xmlrpc reference, is m_xmlrpc loaded?"); - - xmlrpc->Register(&stats); - } - - ~ModuleXMLRPCMain() - { - if (xmlrpc) - xmlrpc->Unregister(&stats); - } -}; - -MODULE_INIT(ModuleXMLRPCMain) - diff --git a/modules/extra/webcpanel/CMakeLists.txt b/modules/extra/webcpanel/CMakeLists.txt deleted file mode 100644 index 247973f61..000000000 --- a/modules/extra/webcpanel/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -build_subdir(${CMAKE_CURRENT_SOURCE_DIR}) - -install(DIRECTORY templates - DESTINATION "${DB_DIR}/modules/webcpanel" -) - diff --git a/modules/extra/webcpanel/pages/chanserv/access.cpp b/modules/extra/webcpanel/pages/chanserv/access.cpp deleted file mode 100644 index d87613ed7..000000000 --- a/modules/extra/webcpanel/pages/chanserv/access.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * (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/extra/webcpanel/pages/chanserv/access.h b/modules/extra/webcpanel/pages/chanserv/access.h deleted file mode 100644 index 7f81f2d39..000000000 --- a/modules/extra/webcpanel/pages/chanserv/access.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * (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/extra/webcpanel/pages/chanserv/akick.cpp b/modules/extra/webcpanel/pages/chanserv/akick.cpp deleted file mode 100644 index bff38910c..000000000 --- a/modules/extra/webcpanel/pages/chanserv/akick.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * (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/extra/webcpanel/pages/chanserv/akick.h b/modules/extra/webcpanel/pages/chanserv/akick.h deleted file mode 100644 index bd5b18132..000000000 --- a/modules/extra/webcpanel/pages/chanserv/akick.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * (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/extra/webcpanel/pages/chanserv/drop.cpp b/modules/extra/webcpanel/pages/chanserv/drop.cpp deleted file mode 100644 index 5fa37b5a2..000000000 --- a/modules/extra/webcpanel/pages/chanserv/drop.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * (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/extra/webcpanel/pages/chanserv/drop.h b/modules/extra/webcpanel/pages/chanserv/drop.h deleted file mode 100644 index d418ade8f..000000000 --- a/modules/extra/webcpanel/pages/chanserv/drop.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * (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/extra/webcpanel/pages/chanserv/info.cpp b/modules/extra/webcpanel/pages/chanserv/info.cpp deleted file mode 100644 index c16c3eaec..000000000 --- a/modules/extra/webcpanel/pages/chanserv/info.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * (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/extra/webcpanel/pages/chanserv/info.h b/modules/extra/webcpanel/pages/chanserv/info.h deleted file mode 100644 index 4302264d6..000000000 --- a/modules/extra/webcpanel/pages/chanserv/info.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * (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/extra/webcpanel/pages/chanserv/modes.cpp b/modules/extra/webcpanel/pages/chanserv/modes.cpp deleted file mode 100644 index e3e93dd03..000000000 --- a/modules/extra/webcpanel/pages/chanserv/modes.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * (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/extra/webcpanel/pages/chanserv/modes.h b/modules/extra/webcpanel/pages/chanserv/modes.h deleted file mode 100644 index 36f5a1d27..000000000 --- a/modules/extra/webcpanel/pages/chanserv/modes.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * (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/extra/webcpanel/pages/chanserv/set.cpp b/modules/extra/webcpanel/pages/chanserv/set.cpp deleted file mode 100644 index f763ba13b..000000000 --- a/modules/extra/webcpanel/pages/chanserv/set.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - * (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/extra/webcpanel/pages/chanserv/set.h b/modules/extra/webcpanel/pages/chanserv/set.h deleted file mode 100644 index dcd483419..000000000 --- a/modules/extra/webcpanel/pages/chanserv/set.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * (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/extra/webcpanel/pages/chanserv/utils.cpp b/modules/extra/webcpanel/pages/chanserv/utils.cpp deleted file mode 100644 index b4571b74c..000000000 --- a/modules/extra/webcpanel/pages/chanserv/utils.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * (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/extra/webcpanel/pages/chanserv/utils.h b/modules/extra/webcpanel/pages/chanserv/utils.h deleted file mode 100644 index 111abb4ad..000000000 --- a/modules/extra/webcpanel/pages/chanserv/utils.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * (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/extra/webcpanel/pages/confirm.cpp b/modules/extra/webcpanel/pages/confirm.cpp deleted file mode 100644 index 7a4a3467e..000000000 --- a/modules/extra/webcpanel/pages/confirm.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * (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/extra/webcpanel/pages/confirm.h b/modules/extra/webcpanel/pages/confirm.h deleted file mode 100644 index eceeedee1..000000000 --- a/modules/extra/webcpanel/pages/confirm.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * (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/extra/webcpanel/pages/hostserv/request.cpp b/modules/extra/webcpanel/pages/hostserv/request.cpp deleted file mode 100644 index ee6356214..000000000 --- a/modules/extra/webcpanel/pages/hostserv/request.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * (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/extra/webcpanel/pages/hostserv/request.h b/modules/extra/webcpanel/pages/hostserv/request.h deleted file mode 100644 index 59d790937..000000000 --- a/modules/extra/webcpanel/pages/hostserv/request.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * (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/extra/webcpanel/pages/index.cpp b/modules/extra/webcpanel/pages/index.cpp deleted file mode 100644 index 1b136c7fb..000000000 --- a/modules/extra/webcpanel/pages/index.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * (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/extra/webcpanel/pages/index.h b/modules/extra/webcpanel/pages/index.h deleted file mode 100644 index b3c638d05..000000000 --- a/modules/extra/webcpanel/pages/index.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * (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/extra/webcpanel/pages/logout.cpp b/modules/extra/webcpanel/pages/logout.cpp deleted file mode 100644 index d9f5432a3..000000000 --- a/modules/extra/webcpanel/pages/logout.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * (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/extra/webcpanel/pages/logout.h b/modules/extra/webcpanel/pages/logout.h deleted file mode 100644 index ab324bdf9..000000000 --- a/modules/extra/webcpanel/pages/logout.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * (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/extra/webcpanel/pages/memoserv/memos.cpp b/modules/extra/webcpanel/pages/memoserv/memos.cpp deleted file mode 100644 index 944864cdd..000000000 --- a/modules/extra/webcpanel/pages/memoserv/memos.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * (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/extra/webcpanel/pages/memoserv/memos.h b/modules/extra/webcpanel/pages/memoserv/memos.h deleted file mode 100644 index e55104823..000000000 --- a/modules/extra/webcpanel/pages/memoserv/memos.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * (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/extra/webcpanel/pages/nickserv/access.cpp b/modules/extra/webcpanel/pages/nickserv/access.cpp deleted file mode 100644 index de7809591..000000000 --- a/modules/extra/webcpanel/pages/nickserv/access.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * (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/extra/webcpanel/pages/nickserv/access.h b/modules/extra/webcpanel/pages/nickserv/access.h deleted file mode 100644 index 8c7337236..000000000 --- a/modules/extra/webcpanel/pages/nickserv/access.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * (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/extra/webcpanel/pages/nickserv/alist.cpp b/modules/extra/webcpanel/pages/nickserv/alist.cpp deleted file mode 100644 index 21e281f5f..000000000 --- a/modules/extra/webcpanel/pages/nickserv/alist.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * (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/extra/webcpanel/pages/nickserv/alist.h b/modules/extra/webcpanel/pages/nickserv/alist.h deleted file mode 100644 index 357699f4e..000000000 --- a/modules/extra/webcpanel/pages/nickserv/alist.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * (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/extra/webcpanel/pages/nickserv/cert.cpp b/modules/extra/webcpanel/pages/nickserv/cert.cpp deleted file mode 100644 index eb86f4bd8..000000000 --- a/modules/extra/webcpanel/pages/nickserv/cert.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * (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/extra/webcpanel/pages/nickserv/cert.h b/modules/extra/webcpanel/pages/nickserv/cert.h deleted file mode 100644 index 7fa86e6eb..000000000 --- a/modules/extra/webcpanel/pages/nickserv/cert.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * (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/extra/webcpanel/pages/nickserv/info.cpp b/modules/extra/webcpanel/pages/nickserv/info.cpp deleted file mode 100644 index f8753d83f..000000000 --- a/modules/extra/webcpanel/pages/nickserv/info.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - * (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/extra/webcpanel/pages/nickserv/info.h b/modules/extra/webcpanel/pages/nickserv/info.h deleted file mode 100644 index 46e588f8b..000000000 --- a/modules/extra/webcpanel/pages/nickserv/info.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * (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/extra/webcpanel/pages/operserv/akill.cpp b/modules/extra/webcpanel/pages/operserv/akill.cpp deleted file mode 100644 index 24f1dbf63..000000000 --- a/modules/extra/webcpanel/pages/operserv/akill.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * (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/extra/webcpanel/pages/operserv/akill.h b/modules/extra/webcpanel/pages/operserv/akill.h deleted file mode 100644 index 9fd47d79a..000000000 --- a/modules/extra/webcpanel/pages/operserv/akill.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * (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/extra/webcpanel/pages/register.cpp b/modules/extra/webcpanel/pages/register.cpp deleted file mode 100644 index cd3494713..000000000 --- a/modules/extra/webcpanel/pages/register.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - * (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/extra/webcpanel/pages/register.h b/modules/extra/webcpanel/pages/register.h deleted file mode 100644 index 38646c98c..000000000 --- a/modules/extra/webcpanel/pages/register.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * (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/extra/webcpanel/static_fileserver.cpp b/modules/extra/webcpanel/static_fileserver.cpp deleted file mode 100644 index 21f4e7052..000000000 --- a/modules/extra/webcpanel/static_fileserver.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * (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/extra/webcpanel/static_fileserver.h b/modules/extra/webcpanel/static_fileserver.h deleted file mode 100644 index 184c8661d..000000000 --- a/modules/extra/webcpanel/static_fileserver.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * (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/extra/webcpanel/template_fileserver.cpp b/modules/extra/webcpanel/template_fileserver.cpp deleted file mode 100644 index d4e5ec7e4..000000000 --- a/modules/extra/webcpanel/template_fileserver.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/* - * (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/extra/webcpanel/template_fileserver.h b/modules/extra/webcpanel/template_fileserver.h deleted file mode 100644 index 0d2502e4f..000000000 --- a/modules/extra/webcpanel/template_fileserver.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * (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/extra/webcpanel/templates/default/chanserv/access.html b/modules/extra/webcpanel/templates/default/chanserv/access.html deleted file mode 100644 index c50434f8a..000000000 --- a/modules/extra/webcpanel/templates/default/chanserv/access.html +++ /dev/null @@ -1,77 +0,0 @@ -{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/extra/webcpanel/templates/default/chanserv/akick.html b/modules/extra/webcpanel/templates/default/chanserv/akick.html deleted file mode 100644 index ddfea546c..000000000 --- a/modules/extra/webcpanel/templates/default/chanserv/akick.html +++ /dev/null @@ -1,61 +0,0 @@ -{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/extra/webcpanel/templates/default/chanserv/chanlist.html b/modules/extra/webcpanel/templates/default/chanserv/chanlist.html deleted file mode 100644 index 8f00f02ac..000000000 --- a/modules/extra/webcpanel/templates/default/chanserv/chanlist.html +++ /dev/null @@ -1,17 +0,0 @@ -
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/extra/webcpanel/templates/default/chanserv/drop.html b/modules/extra/webcpanel/templates/default/chanserv/drop.html deleted file mode 100644 index c28eb051a..000000000 --- a/modules/extra/webcpanel/templates/default/chanserv/drop.html +++ /dev/null @@ -1,32 +0,0 @@ -{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/extra/webcpanel/templates/default/chanserv/main.html b/modules/extra/webcpanel/templates/default/chanserv/main.html deleted file mode 100644 index e77626f31..000000000 --- a/modules/extra/webcpanel/templates/default/chanserv/main.html +++ /dev/null @@ -1,3 +0,0 @@ -{INCLUDE header.html} -{INCLUDE chanserv/chanlist.html} -{INCLUDE footer.html} diff --git a/modules/extra/webcpanel/templates/default/chanserv/modes.html b/modules/extra/webcpanel/templates/default/chanserv/modes.html deleted file mode 100644 index 3c7fe7ab3..000000000 --- a/modules/extra/webcpanel/templates/default/chanserv/modes.html +++ /dev/null @@ -1,56 +0,0 @@ -{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/extra/webcpanel/templates/default/chanserv/set.html b/modules/extra/webcpanel/templates/default/chanserv/set.html deleted file mode 100644 index 050c37f69..000000000 --- a/modules/extra/webcpanel/templates/default/chanserv/set.html +++ /dev/null @@ -1,93 +0,0 @@ -{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/extra/webcpanel/templates/default/confirm.html b/modules/extra/webcpanel/templates/default/confirm.html deleted file mode 100644 index f9f315fd3..000000000 --- a/modules/extra/webcpanel/templates/default/confirm.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - {TITLE} - - -
-
-
- - - - Back Home - -

Register

- - {IF EXISTS MESSAGES} -
- {FOR M IN MESSAGES} - {M}
- {END FOR} -
- {END IF} - - Retry -
-
- -
-
-
- -
-
-
- - - - - diff --git a/modules/extra/webcpanel/templates/default/cubes.png b/modules/extra/webcpanel/templates/default/cubes.png deleted file mode 100644 index d75208db7..000000000 Binary files a/modules/extra/webcpanel/templates/default/cubes.png and /dev/null differ diff --git a/modules/extra/webcpanel/templates/default/favicon.ico b/modules/extra/webcpanel/templates/default/favicon.ico deleted file mode 100644 index be735614a..000000000 Binary files a/modules/extra/webcpanel/templates/default/favicon.ico and /dev/null differ diff --git a/modules/extra/webcpanel/templates/default/footer.html b/modules/extra/webcpanel/templates/default/footer.html deleted file mode 100644 index 57794a9ff..000000000 --- a/modules/extra/webcpanel/templates/default/footer.html +++ /dev/null @@ -1,14 +0,0 @@ -
- - - -
-
- -
-
- - - \ No newline at end of file diff --git a/modules/extra/webcpanel/templates/default/header.html b/modules/extra/webcpanel/templates/default/header.html deleted file mode 100644 index 0ccf477c5..000000000 --- a/modules/extra/webcpanel/templates/default/header.html +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - - - - - - - - - - {TITLE} - - -
- - -
-
- -
- -
-
diff --git a/modules/extra/webcpanel/templates/default/hostserv/request.html b/modules/extra/webcpanel/templates/default/hostserv/request.html deleted file mode 100644 index f557244d1..000000000 --- a/modules/extra/webcpanel/templates/default/hostserv/request.html +++ /dev/null @@ -1,45 +0,0 @@ -{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/extra/webcpanel/templates/default/login.html b/modules/extra/webcpanel/templates/default/login.html deleted file mode 100644 index 6a0b6d7a9..000000000 --- a/modules/extra/webcpanel/templates/default/login.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - {TITLE} - - -
-
-
- - - - -

Login to continue

- - {IF EXISTS INVALID_LOGIN} -
- {INVALID_LOGIN} -
- {END IF} - - -
-
- -
-
-
- -
-
-
- - - - - diff --git a/modules/extra/webcpanel/templates/default/logo.png b/modules/extra/webcpanel/templates/default/logo.png deleted file mode 100644 index f7c2ff92a..000000000 Binary files a/modules/extra/webcpanel/templates/default/logo.png and /dev/null differ diff --git a/modules/extra/webcpanel/templates/default/memoserv/memos.html b/modules/extra/webcpanel/templates/default/memoserv/memos.html deleted file mode 100644 index b3b54d948..000000000 --- a/modules/extra/webcpanel/templates/default/memoserv/memos.html +++ /dev/null @@ -1,112 +0,0 @@ -{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/extra/webcpanel/templates/default/nickserv/access.html b/modules/extra/webcpanel/templates/default/nickserv/access.html deleted file mode 100644 index d4be56279..000000000 --- a/modules/extra/webcpanel/templates/default/nickserv/access.html +++ /dev/null @@ -1,42 +0,0 @@ -{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/extra/webcpanel/templates/default/nickserv/alist.html b/modules/extra/webcpanel/templates/default/nickserv/alist.html deleted file mode 100644 index f3b2e0124..000000000 --- a/modules/extra/webcpanel/templates/default/nickserv/alist.html +++ /dev/null @@ -1,23 +0,0 @@ -{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/extra/webcpanel/templates/default/nickserv/cert.html b/modules/extra/webcpanel/templates/default/nickserv/cert.html deleted file mode 100644 index 6d41a44b4..000000000 --- a/modules/extra/webcpanel/templates/default/nickserv/cert.html +++ /dev/null @@ -1,42 +0,0 @@ -{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/extra/webcpanel/templates/default/nickserv/info.html b/modules/extra/webcpanel/templates/default/nickserv/info.html deleted file mode 100644 index 667c8b370..000000000 --- a/modules/extra/webcpanel/templates/default/nickserv/info.html +++ /dev/null @@ -1,72 +0,0 @@ -{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/extra/webcpanel/templates/default/operserv/akill.html b/modules/extra/webcpanel/templates/default/operserv/akill.html deleted file mode 100644 index ffc73f8e4..000000000 --- a/modules/extra/webcpanel/templates/default/operserv/akill.html +++ /dev/null @@ -1,77 +0,0 @@ -{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/extra/webcpanel/templates/default/register.html b/modules/extra/webcpanel/templates/default/register.html deleted file mode 100644 index bebf4e276..000000000 --- a/modules/extra/webcpanel/templates/default/register.html +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - {TITLE} - - -
-
-
- - - - Back Home - -

Register

- - {IF EXISTS MESSAGES} -
- {MESSAGES} -
- {END IF} - - -
-
- -
-
-
- -
-
-
- - - - - \ No newline at end of file diff --git a/modules/extra/webcpanel/templates/default/style.css b/modules/extra/webcpanel/templates/default/style.css deleted file mode 100644 index e425c3d8c..000000000 --- a/modules/extra/webcpanel/templates/default/style.css +++ /dev/null @@ -1,166 +0,0 @@ -@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/extra/webcpanel/webcpanel.cpp b/modules/extra/webcpanel/webcpanel.cpp deleted file mode 100644 index 0c1fc3903..000000000 --- a/modules/extra/webcpanel/webcpanel.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/* - * (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/extra/webcpanel/webcpanel.h b/modules/extra/webcpanel/webcpanel.h deleted file mode 100644 index 7e4b5a556..000000000 --- a/modules/extra/webcpanel/webcpanel.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * (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" diff --git a/modules/m_httpd.cpp b/modules/m_httpd.cpp new file mode 100644 index 000000000..e08452d81 --- /dev/null +++ b/modules/m_httpd.cpp @@ -0,0 +1,474 @@ +/* + * (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 "modules/ssl.h" + +static Anope::string BuildDate() +{ + char timebuf[64]; + struct tm *tm = localtime(&Anope::CurTime); + strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S %Z", tm); + return timebuf; +} + +static Anope::string GetStatusFromCode(HTTPError err) +{ + switch (err) + { + case HTTP_ERROR_OK: + return "200 OK"; + case HTTP_FOUND: + return "302 Found"; + case HTTP_BAD_REQUEST: + return "400 Bad Request"; + case HTTP_PAGE_NOT_FOUND: + return "404 Not Found"; + case HTTP_NOT_SUPPORTED: + return "505 HTTP Version Not Supported"; + } + + return "501 Not Implemented"; +} + +class MyHTTPClient : public HTTPClient +{ + HTTPProvider *provider; + HTTPMessage message; + bool header_done, served; + Anope::string page_name; + Reference page; + Anope::string ip; + + unsigned content_length; + + enum + { + ACTION_NONE, + ACTION_GET, + ACTION_POST + } action; + + void Serve() + { + if (this->served) + return; + this->served = true; + + if (!this->page) + { + this->SendError(HTTP_PAGE_NOT_FOUND, "Page not found"); + return; + } + + if (this->ip == this->provider->ext_ip) + { + for (unsigned i = 0; i < this->provider->ext_headers.size(); ++i) + { + const Anope::string &token = this->provider->ext_headers[i]; + + if (this->message.headers.count(token)) + { + this->ip = this->message.headers[token]; + Log(LOG_DEBUG, "httpd") << "m_httpd: IP for connection " << this->GetFD() << " changed to " << this->ip; + break; + } + } + } + + Log(LOG_DEBUG, "httpd") << "m_httpd: Serving page " << this->page_name << " to " << this->ip; + + HTTPReply reply; + reply.content_type = this->page->GetContentType(); + + if (this->page->OnRequest(this->provider, this->page_name, this, this->message, reply)) + this->SendReply(&reply); + } + + public: + time_t created; + + MyHTTPClient(HTTPProvider *l, int f, const sockaddrs &a) : Socket(f, l->IsIPv6()), HTTPClient(l, f, a), provider(l), header_done(false), served(false), ip(a.addr()), content_length(0), action(ACTION_NONE), created(Anope::CurTime) + { + Log(LOG_DEBUG, "httpd") << "Accepted connection " << f << " from " << a.addr(); + } + + ~MyHTTPClient() + { + Log(LOG_DEBUG, "httpd") << "Closing connection " << this->GetFD() << " from " << this->ip; + } + + /* Close connection once all data is written */ + bool ProcessWrite() anope_override + { + return !BinarySocket::ProcessWrite() || this->write_buffer.empty() ? false : true; + } + + const Anope::string GetIP() anope_override + { + return this->ip; + } + + bool Read(const char *buffer, size_t l) anope_override + { + message.content.append(buffer, l); + + for (size_t nl; !this->header_done && (nl = message.content.find('\n')) != Anope::string::npos;) + { + Anope::string token = message.content.substr(0, nl).trim(); + message.content = message.content.substr(nl + 1); + + if (token.empty()) + this->header_done = true; + else + this->Read(token); + } + + if (!this->header_done) + return true; + + if (this->message.content.length() >= this->content_length) + { + sepstream sep(this->message.content, '&'); + Anope::string token; + + while (sep.GetToken(token)) + { + size_t sz = token.find('='); + if (sz == Anope::string::npos || !sz || sz + 1 >= token.length()) + continue; + this->message.post_data[token.substr(0, sz)] = HTTPUtils::URLDecode(token.substr(sz + 1)); + Log(LOG_DEBUG_2) << "HTTP POST from " << this->clientaddr.addr() << ": " << token.substr(0, sz) << ": " << this->message.post_data[token.substr(0, sz)]; + } + + this->Serve(); + } + + return true; + } + + bool Read(const Anope::string &buf) + { + Log(LOG_DEBUG_2) << "HTTP from " << this->clientaddr.addr() << ": " << buf; + + if (this->action == ACTION_NONE) + { + std::vector params; + spacesepstream(buf).GetTokens(params); + + if (params.empty() || (params[0] != "GET" && params[0] != "POST")) + { + this->SendError(HTTP_BAD_REQUEST, "Unknown operation"); + return true; + } + + if (params.size() != 3) + { + this->SendError(HTTP_BAD_REQUEST, "Invalid parameters"); + return true; + } + + if (params[0] == "GET") + this->action = ACTION_GET; + else if (params[0] == "POST") + this->action = ACTION_POST; + + Anope::string targ = params[1]; + size_t q = targ.find('?'); + if (q != Anope::string::npos) + { + sepstream sep(targ.substr(q + 1), '&'); + targ = targ.substr(0, q); + + Anope::string token; + while (sep.GetToken(token)) + { + size_t sz = token.find('='); + if (sz == Anope::string::npos || !sz || sz + 1 >= token.length()) + continue; + this->message.get_data[token.substr(0, sz)] = HTTPUtils::URLDecode(token.substr(sz + 1)); + } + } + + this->page = this->provider->FindPage(targ); + this->page_name = targ; + } + else if (buf.find("Cookie: ") == 0) + { + spacesepstream sep(buf.substr(8)); + Anope::string token; + + while (sep.GetToken(token)) + { + size_t sz = token.find('='); + if (sz == Anope::string::npos || !sz || sz + 1 >= token.length()) + continue; + size_t end = token.length() - (sz + 1); + if (!sep.StreamEnd()) + --end; // Remove trailing ; + this->message.cookies[token.substr(0, sz)] = token.substr(sz + 1, end); + } + } + else if (buf.find("Content-Length: ") == 0) + { + try + { + this->content_length = convertTo(buf.substr(16)); + } + catch (const ConvertException &ex) { } + } + else if (buf.find(':') != Anope::string::npos) + { + size_t sz = buf.find(':'); + if (sz + 2 < buf.length()) + this->message.headers[buf.substr(0, sz)] = buf.substr(sz + 2); + } + + return true; + } + + void SendError(HTTPError err, const Anope::string &msg) anope_override + { + HTTPReply h; + + h.error = err; + + h.Write(msg); + + this->SendReply(&h); + } + + void SendReply(HTTPReply *msg) anope_override + { + this->WriteClient("HTTP/1.1 " + GetStatusFromCode(msg->error)); + this->WriteClient("Date: " + BuildDate()); + this->WriteClient("Server: Anope-" + Anope::VersionShort()); + if (msg->content_type.empty()) + this->WriteClient("Content-Type: text/html"); + else + this->WriteClient("Content-Type: " + msg->content_type); + this->WriteClient("Content-Length: " + stringify(msg->length)); + + for (unsigned i = 0; i < msg->cookies.size(); ++i) + { + Anope::string buf = "Set-Cookie:"; + + for (HTTPReply::cookie::iterator it = msg->cookies[i].begin(), it_end = msg->cookies[i].end(); it != it_end; ++it) + buf += " " + it->first + "=" + it->second + ";"; + + buf.erase(buf.length() - 1); + + this->WriteClient(buf); + } + + typedef std::map map; + for (map::iterator it = msg->headers.begin(), it_end = msg->headers.end(); it != it_end; ++it) + this->WriteClient(it->first + ": " + it->second); + + this->WriteClient("Connection: Close"); + this->WriteClient(""); + + for (unsigned i = 0; i < msg->out.size(); ++i) + { + HTTPReply::Data* d = msg->out[i]; + + this->Write(d->buf, d->len); + + delete d; + } + + msg->out.clear(); + } +}; + +class MyHTTPProvider : public HTTPProvider, public Timer +{ + int timeout; + std::map pages; + std::list > clients; + + public: + MyHTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, const int t, bool s) : Socket(-1, i.find(':') != Anope::string::npos), HTTPProvider(c, n, i, p, s), Timer(c, 10, Anope::CurTime, true), timeout(t) { } + + void Tick(time_t) anope_override + { + while (!this->clients.empty()) + { + Reference& c = this->clients.front(); + if (c && c->created + this->timeout >= Anope::CurTime) + break; + + delete c; + this->clients.pop_front(); + } + } + + ClientSocket* OnAccept(int fd, const sockaddrs &addr) anope_override + { + MyHTTPClient *c = new MyHTTPClient(this, fd, addr); + this->clients.push_back(c); + return c; + } + + bool RegisterPage(HTTPPage *page) anope_override + { + return this->pages.insert(std::make_pair(page->GetURL(), page)).second; + } + + void UnregisterPage(HTTPPage *page) anope_override + { + this->pages.erase(page->GetURL()); + } + + HTTPPage* FindPage(const Anope::string &pname) + { + if (this->pages.count(pname) == 0) + return NULL; + return this->pages[pname]; + } +}; + +class HTTPD : public Module +{ + ServiceReference sslref; + std::map providers; + public: + HTTPD(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), sslref("SSLService", "ssl") + { + + } + + ~HTTPD() + { + for (std::map::const_iterator it = SocketEngine::Sockets.begin(), it_end = SocketEngine::Sockets.end(); it != it_end;) + { + Socket *s = it->second; + ++it; + + if (dynamic_cast(s) || dynamic_cast(s)) + delete s; + } + + this->providers.clear(); + } + + void OnReload(Configuration::Conf *config) anope_override + { + Configuration::Block *conf = config->GetModule(this); + std::set existing; + + for (int i = 0; i < conf->CountBlock("httpd"); ++i) + { + Configuration::Block *block = conf->GetBlock("httpd", i); + + + const Anope::string &hname = block->Get("name", "httpd/main"); + existing.insert(hname); + + Anope::string ip = block->Get("ip"); + int port = block->Get("port", "8080"); + int timeout = block->Get("timeout", "30"); + bool ssl = block->Get("ssl", "no"); + Anope::string ext_ip = block->Get("extforward_ip"); + Anope::string ext_header = block->Get("extforward_header"); + + if (ip.empty()) + { + Log(this) << "You must configure a bind IP for HTTP server " << hname; + continue; + } + else if (port <= 0 || port > 65535) + { + Log(this) << "You must configure a (valid) listen port for HTTP server " << hname; + continue; + } + + MyHTTPProvider *p; + if (this->providers.count(hname) == 0) + { + try + { + p = new MyHTTPProvider(this, hname, ip, port, timeout, ssl); + if (ssl && sslref) + sslref->Init(p); + } + catch (const SocketException &ex) + { + Log(this) << "Unable to create HTTP server " << hname << ": " << ex.GetReason(); + continue; + } + this->providers[hname] = p; + + Log(this) << "Created HTTP server " << hname; + } + else + { + p = this->providers[hname]; + + if (p->GetIP() != ip || p->GetPort() != port) + { + delete p; + this->providers.erase(hname); + + Log(this) << "Changing HTTP server " << hname << " to " << ip << ":" << port; + + try + { + p = new MyHTTPProvider(this, hname, ip, port, timeout, ssl); + if (ssl && sslref) + sslref->Init(p); + } + catch (const SocketException &ex) + { + Log(this) << "Unable to create HTTP server " << hname << ": " << ex.GetReason(); + continue; + } + + this->providers[hname] = p; + } + } + + + p->ext_ip = ext_ip; + spacesepstream(ext_header).GetTokens(p->ext_headers); + } + + for (std::map::iterator it = this->providers.begin(), it_end = this->providers.end(); it != it_end;) + { + HTTPProvider *p = it->second; + ++it; + + if (existing.count(p->name) == 0) + { + Log(this) << "Removing HTTP server " << p->name; + this->providers.erase(p->name); + delete p; + } + } + } + + void OnModuleLoad(User *u, Module *m) anope_override + { + if (m->name != "m_ssl") + return; + + for (std::map::iterator it = this->providers.begin(), it_end = this->providers.end(); it != it_end; ++it) + { + MyHTTPProvider *p = it->second; + + if (p->IsSSL() && sslref) + try + { + sslref->Init(p); + } + catch (const CoreException &) { } // Throws on reinitialization + } + } +}; + +MODULE_INIT(HTTPD) diff --git a/modules/m_proxyscan.cpp b/modules/m_proxyscan.cpp new file mode 100644 index 000000000..98178260c --- /dev/null +++ b/modules/m_proxyscan.cpp @@ -0,0 +1,379 @@ +/* + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "module.h" + +struct ProxyCheck +{ + std::set types; + std::vector ports; + time_t duration; + Anope::string reason; +}; + +static Anope::string ProxyCheckString; +static Anope::string target_ip; +static unsigned short target_port; +static bool add_to_akill; + +class ProxyCallbackListener : public ListenSocket +{ + class ProxyCallbackClient : public ClientSocket, public BufferedSocket + { + public: + ProxyCallbackClient(ListenSocket *l, int f, const sockaddrs &a) : Socket(f, l->IsIPv6()), ClientSocket(l, a), BufferedSocket() + { + } + + void OnAccept() anope_override + { + this->Write(ProxyCheckString); + } + + bool ProcessWrite() anope_override + { + return !BufferedSocket::ProcessWrite() || this->write_buffer.empty() ? false : true; + } + }; + + public: + ProxyCallbackListener(const Anope::string &b, int p) : Socket(-1, b.find(':') != Anope::string::npos), ListenSocket(b, p, false) + { + } + + ClientSocket *OnAccept(int fd, const sockaddrs &addr) anope_override + { + return new ProxyCallbackClient(this, fd, addr); + } +}; + +class ProxyConnect : public ConnectionSocket +{ + static ServiceReference akills; + + public: + static std::set proxies; + + ProxyCheck proxy; + unsigned short port; + time_t created; + + ProxyConnect(ProxyCheck &p, unsigned short po) : Socket(-1), ConnectionSocket(), proxy(p), + port(po), created(Anope::CurTime) + { + proxies.insert(this); + } + + ~ProxyConnect() + { + proxies.erase(this); + } + + virtual void OnConnect() anope_override = 0; + virtual const Anope::string GetType() const = 0; + + protected: + void Ban() + { + Anope::string reason = this->proxy.reason; + + reason = reason.replace_all_cs("%t", this->GetType()); + reason = reason.replace_all_cs("%i", this->conaddr.addr()); + reason = reason.replace_all_cs("%p", stringify(this->conaddr.port())); + + BotInfo *OperServ = Config->GetClient("OperServ"); + Log(OperServ) << "PROXYSCAN: Open " << this->GetType() << " proxy found on " << this->conaddr.addr() << ":" << this->conaddr.port() << " (" << reason << ")"; + XLine *x = new XLine("*@" + this->conaddr.addr(), OperServ ? OperServ->nick : "", Anope::CurTime + this->proxy.duration, reason, XLineManager::GenerateUID()); + if (add_to_akill && akills) + { + akills->AddXLine(x); + akills->Send(NULL, x); + } + else + { + if (IRCD->CanSZLine) + IRCD->SendSZLine(NULL, x); + else + IRCD->SendAkill(NULL, x); + delete x; + } + } +}; +ServiceReference ProxyConnect::akills("XLineManager", "xlinemanager/sgline"); +std::set ProxyConnect::proxies; + +class HTTPProxyConnect : public ProxyConnect, public BufferedSocket +{ + public: + HTTPProxyConnect(ProxyCheck &p, unsigned short po) : Socket(-1), ProxyConnect(p, po), BufferedSocket() + { + } + + void OnConnect() anope_override + { + this->Write("CONNECT %s:%d HTTP/1.0", target_ip.c_str(), target_port); + this->Write("Content-length: 0"); + this->Write("Connection: close"); + this->Write(""); + } + + const Anope::string GetType() const anope_override + { + return "HTTP"; + } + + bool ProcessRead() anope_override + { + bool b = BufferedSocket::ProcessRead(); + if (this->GetLine() == ProxyCheckString) + { + this->Ban(); + return false; + } + return b; + } +}; + +class SOCKS5ProxyConnect : public ProxyConnect, public BinarySocket +{ + public: + SOCKS5ProxyConnect(ProxyCheck &p, unsigned short po) : Socket(-1), ProxyConnect(p, po), BinarySocket() + { + } + + void OnConnect() anope_override + { + sockaddrs target_addr; + char buf[4 + sizeof(target_addr.sa4.sin_addr.s_addr) + sizeof(target_addr.sa4.sin_port)]; + int ptr = 0; + target_addr.pton(AF_INET, target_ip, target_port); + if (!target_addr.valid()) + return; + + buf[ptr++] = 5; // Version + buf[ptr++] = 1; // # of methods + buf[ptr++] = 0; // No authentication + + this->Write(buf, ptr); + + ptr = 1; + buf[ptr++] = 1; // Connect + buf[ptr++] = 0; // Reserved + buf[ptr++] = 1; // IPv4 + memcpy(buf + ptr, &target_addr.sa4.sin_addr.s_addr, sizeof(target_addr.sa4.sin_addr.s_addr)); + ptr += sizeof(target_addr.sa4.sin_addr.s_addr); + memcpy(buf + ptr, &target_addr.sa4.sin_port, sizeof(target_addr.sa4.sin_port)); + ptr += sizeof(target_addr.sa4.sin_port); + + this->Write(buf, ptr); + } + + const Anope::string GetType() const anope_override + { + return "SOCKS5"; + } + + bool Read(const char *buffer, size_t l) anope_override + { + if (l >= ProxyCheckString.length() && !strncmp(buffer, ProxyCheckString.c_str(), ProxyCheckString.length())) + { + this->Ban(); + return false; + } + return true; + } +}; + +class ModuleProxyScan : public Module +{ + Anope::string listen_ip; + unsigned short listen_port; + Anope::string con_notice, con_source; + std::vector proxyscans; + + ProxyCallbackListener *listener; + + class ConnectionTimeout : public Timer + { + public: + ConnectionTimeout(Module *c, long timeout) : Timer(c, timeout, Anope::CurTime, true) + { + } + + void Tick(time_t) anope_override + { + for (std::set::iterator it = ProxyConnect::proxies.begin(), it_end = ProxyConnect::proxies.end(); it != it_end; ++it) + { + ProxyConnect *p = *it; + + if (p->created + this->GetSecs() < Anope::CurTime) + p->flags[SF_DEAD] = true; + } + } + } connectionTimeout; + + public: + ModuleProxyScan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), + connectionTimeout(this, 5) + { + + + this->listener = NULL; + } + + ~ModuleProxyScan() + { + for (std::set::iterator it = ProxyConnect::proxies.begin(), it_end = ProxyConnect::proxies.end(); it != it_end;) + { + ProxyConnect *p = *it; + ++it; + delete p; + } + + for (std::map::const_iterator it = SocketEngine::Sockets.begin(), it_end = SocketEngine::Sockets.end(); it != it_end;) + { + Socket *s = it->second; + ++it; + + ClientSocket *cs = dynamic_cast(s); + if (cs != NULL && cs->ls == this->listener) + delete s; + } + + delete this->listener; + } + + void OnReload(Configuration::Conf *conf) anope_override + { + Configuration::Block *config = Config->GetModule(this); + + Anope::string s_target_ip = config->Get("target_ip"); + if (s_target_ip.empty()) + throw ConfigException(this->name + " target_ip may not be empty"); + + int s_target_port = config->Get("target_port", "-1"); + if (s_target_port <= 0) + throw ConfigException(this->name + " target_port may not be empty and must be a positive number"); + + Anope::string s_listen_ip = config->Get("listen_ip"); + if (s_listen_ip.empty()) + throw ConfigException(this->name + " listen_ip may not be empty"); + + int s_listen_port = config->Get("listen_port", "-1"); + if (s_listen_port <= 0) + throw ConfigException(this->name + " listen_port may not be empty and must be a positive number"); + + target_ip = s_target_ip; + target_port = s_target_port; + this->listen_ip = s_listen_ip; + this->listen_port = s_listen_port; + this->con_notice = config->Get("connect_notice"); + this->con_source = config->Get("connect_source"); + add_to_akill = config->Get("add_to_akill", "true"); + this->connectionTimeout.SetSecs(config->Get("timeout", "5s")); + + ProxyCheckString = Config->GetBlock("networkinfo")->Get("networkname") + " proxy check"; + delete this->listener; + this->listener = NULL; + try + { + this->listener = new ProxyCallbackListener(this->listen_ip, this->listen_port); + } + catch (const SocketException &ex) + { + throw ConfigException("m_proxyscan: " + ex.GetReason()); + } + + this->proxyscans.clear(); + for (int i = 0; i < config->CountBlock("proxyscan"); ++i) + { + Configuration::Block *block = config->GetBlock("proxyscan", i); + ProxyCheck p; + Anope::string token; + + commasepstream sep(block->Get("type")); + while (sep.GetToken(token)) + { + if (!token.equals_ci("HTTP") && !token.equals_ci("SOCKS5")) + continue; + p.types.insert(token); + } + if (p.types.empty()) + continue; + + commasepstream sep2(block->Get("port")); + while (sep2.GetToken(token)) + { + try + { + unsigned short port = convertTo(token); + p.ports.push_back(port); + } + catch (const ConvertException &) { } + } + if (p.ports.empty()) + continue; + + p.duration = block->Get("time", "4h"); + p.reason = block->Get("reason"); + if (p.reason.empty()) + continue; + + this->proxyscans.push_back(p); + } + } + + void OnUserConnect(User *user, bool &exempt) anope_override + { + if (exempt || user->Quitting() || !Me->IsSynced() || !user->server->IsSynced()) + return; + + /* At this time we only support IPv4 */ + sockaddrs user_ip; + user_ip.pton(AF_INET, user->ip); + if (!user_ip.valid()) + /* User doesn't have a valid IPv4 IP (ipv6/spoof/etc) */ + return; + + if (!this->con_notice.empty() && !this->con_source.empty()) + { + BotInfo *bi = BotInfo::Find(this->con_source); + if (bi) + user->SendMessage(bi, this->con_notice); + } + + for (unsigned i = this->proxyscans.size(); i > 0; --i) + { + ProxyCheck &p = this->proxyscans[i - 1]; + + for (std::set::iterator it = p.types.begin(), it_end = p.types.end(); it != it_end; ++it) + { + for (unsigned k = 0; k < p.ports.size(); ++k) + { + try + { + ProxyConnect *con = NULL; + if (it->equals_ci("HTTP")) + con = new HTTPProxyConnect(p, p.ports[k]); + else if (it->equals_ci("SOCKS5")) + con = new SOCKS5ProxyConnect(p, p.ports[k]); + else + continue; + con->Connect(user->ip, p.ports[k]); + } + catch (const SocketException &ex) + { + Log(LOG_DEBUG) << "m_proxyscan: " << ex.GetReason(); + } + } + } + } + } +}; + +MODULE_INIT(ModuleProxyScan) + diff --git a/modules/m_sql_log.cpp b/modules/m_sql_log.cpp deleted file mode 100644 index b0c6c037f..000000000 --- a/modules/m_sql_log.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - * - * (C) 2003-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - */ - -#include "module.h" -#include "modules/sql.h" - -class SQLLog : public Module -{ - std::set inited; - Anope::string table; - - public: - SQLLog(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - { - } - - void OnReload(Configuration::Conf *conf) anope_override - { - Configuration::Block *config = conf->GetModule(this); - this->table = config->Get("table", "logs"); - } - - void OnLogMessage(LogInfo *li, const Log *l, const Anope::string &msg) anope_override - { - Anope::string ref_name; - ServiceReference SQL; - - for (unsigned i = 0; i < li->targets.size(); ++i) - { - const Anope::string &target = li->targets[i]; - size_t sz = target.find("sql_log:"); - if (!sz) - { - ref_name = target.substr(8); - SQL = ServiceReference("SQL::Provider", ref_name); - break; - } - } - - if (!SQL) - return; - - if (!inited.count(ref_name)) - { - inited.insert(ref_name); - - SQL::Query create("CREATE TABLE IF NOT EXISTS `" + table + "` (" - "`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP," - "`type` varchar(64) NOT NULL," - "`user` varchar(64) NOT NULL," - "`acc` varchar(64) NOT NULL," - "`command` varchar(64) NOT NULL," - "`channel` varchar(64) NOT NULL," - "`msg` text NOT NULL" - ")"); - - SQL->Run(NULL, create); - } - - SQL::Query insert("INSERT INTO `" + table + "` (`type`,`user`,`acc`,`command`,`channel`,`msg`)" - "VALUES (@type@, @user@, @acc@, @command@, @channel@, @msg@)"); - - switch (l->type) - { - case LOG_ADMIN: - insert.SetValue("type", "ADMIN"); - break; - case LOG_OVERRIDE: - insert.SetValue("type", "OVERRIDE"); - break; - case LOG_COMMAND: - insert.SetValue("type", "COMMAND"); - break; - case LOG_SERVER: - insert.SetValue("type", "SERVER"); - break; - case LOG_CHANNEL: - insert.SetValue("type", "CHANNEL"); - break; - case LOG_USER: - insert.SetValue("type", "USER"); - break; - case LOG_MODULE: - insert.SetValue("type", "MODULE"); - break; - case LOG_NORMAL: - insert.SetValue("type", "NORMAL"); - break; - default: - return; - } - - insert.SetValue("user", l->u ? l->u->nick : ""); - insert.SetValue("acc", l->nc ? l->nc->display : ""); - insert.SetValue("command", l->c ? l->c->name : ""); - insert.SetValue("channel", l->ci ? l->ci->name : ""); - insert.SetValue("msg", msg); - - SQL->Run(NULL, insert); - } -}; - -MODULE_INIT(SQLLog) diff --git a/modules/m_xmlrpc.cpp b/modules/m_xmlrpc.cpp new file mode 100644 index 000000000..36401b800 --- /dev/null +++ b/modules/m_xmlrpc.cpp @@ -0,0 +1,186 @@ + +#include "module.h" +#include "modules/xmlrpc.h" +#include "modules/httpd.h" + +static struct special_chars +{ + Anope::string character; + Anope::string replace; + + special_chars(const Anope::string &c, const Anope::string &r) : character(c), replace(r) { } +} +special[] = { + special_chars("&", "&"), + special_chars("\"", """), + special_chars("<", "<"), + special_chars(">", "&qt;"), + special_chars("'", "'"), + special_chars("\n", " "), + special_chars("\002", ""), // bold + special_chars("\003", ""), // color + special_chars("\035", ""), // italics + special_chars("\037", ""), // underline + special_chars("\026", ""), // reverses + special_chars("", "") +}; + +class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage +{ + std::deque events; + + public: + MyXMLRPCServiceInterface(Module *creator, const Anope::string &sname) : XMLRPCServiceInterface(creator, sname), HTTPPage("/xmlrpc", "text/xml") { } + + void Register(XMLRPCEvent *event) + { + this->events.push_back(event); + } + + void Unregister(XMLRPCEvent *event) + { + std::deque::iterator it = std::find(this->events.begin(), this->events.end(), event); + + if (it != this->events.end()) + this->events.erase(it); + } + + Anope::string Sanitize(const Anope::string &string) anope_override + { + Anope::string ret = string; + for (int i = 0; special[i].character.empty() == false; ++i) + ret = ret.replace_all_cs(special[i].character, special[i].replace); + return ret; + } + + private: + static bool GetData(Anope::string &content, Anope::string &tag, Anope::string &data) + { + if (content.empty()) + return false; + + Anope::string prev, cur; + bool istag; + + do + { + prev = cur; + cur.clear(); + + int len = 0; + istag = false; + + if (content[0] == '<') + { + len = content.find_first_of('>'); + istag = true; + } + else if (content[0] != '>') + { + len = content.find_first_of('<'); + } + + if (len) + { + if (istag) + { + cur = content.substr(1, len - 1); + content.erase(0, len + 1); + while (!content.empty() && content[0] == ' ') + content.erase(content.begin()); + } + else + { + cur = content.substr(0,len); + content.erase(0, len); + } + } + } + while (istag && !content.empty()); + + tag = prev; + data = cur; + return !istag && !data.empty(); + } + + public: + bool OnRequest(HTTPProvider *provider, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) anope_override + { + Anope::string content = message.content, tname, data; + XMLRPCRequest request(reply); + + while (GetData(content, tname, data)) + { + Log(LOG_DEBUG) << "m_xmlrpc: Tag name: " << tname << ", data: " << data; + if (tname == "methodName") + request.name = data; + else if (tname == "name" && data == "id") + { + GetData(content, tname, data); + request.id = data; + } + else if (tname == "string") + request.data.push_back(data); + } + + for (unsigned i = 0; i < this->events.size(); ++i) + { + XMLRPCEvent *e = this->events[i]; + + if (!e->Run(this, client, request)) + return false; + else if (!request.get_replies().empty()) + { + this->Reply(request); + return true; + } + } + + reply.error = HTTP_PAGE_NOT_FOUND; + reply.Write("Unrecognized query"); + return true; + } + + void Reply(XMLRPCRequest &request) + { + if (!request.id.empty()) + request.reply("id", request.id); + + Anope::string r = "\n\n" + request.name + "\n\n\n\n\n"; + for (std::map::const_iterator it = request.get_replies().begin(); it != request.get_replies().end(); ++it) + r += "\n" + it->first + "\n\n" + this->Sanitize(it->second) + "\n\n\n"; + r += "\n\n\n\n"; + + request.r.Write(r); + } +}; + +class ModuleXMLRPC : public Module +{ + ServiceReference httpref; + public: + MyXMLRPCServiceInterface xmlrpcinterface; + + ModuleXMLRPC(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), + httpref("HTTPProvider", "httpd/main"), xmlrpcinterface(this, "xmlrpc") + { + if (!httpref) + throw ModuleException("Unable to find http reference, is m_httpd loaded?"); + httpref->RegisterPage(&xmlrpcinterface); + + } + + ~ModuleXMLRPC() + { + if (httpref) + httpref->UnregisterPage(&xmlrpcinterface); + } + + void OnReload(Configuration::Conf *conf) anope_override + { + this->httpref = ServiceReference("HTTPProvider", conf->GetModule(this)->Get("server", "httpd/main")); + } +}; + +MODULE_INIT(ModuleXMLRPC) + diff --git a/modules/m_xmlrpc_main.cpp b/modules/m_xmlrpc_main.cpp new file mode 100644 index 000000000..17dd8b96f --- /dev/null +++ b/modules/m_xmlrpc_main.cpp @@ -0,0 +1,280 @@ +#include "module.h" +#include "modules/xmlrpc.h" + +static Module *me; + +class XMLRPCIdentifyRequest : public IdentifyRequest +{ + XMLRPCRequest request; + HTTPReply repl; /* Request holds a reference to the HTTPReply, because we might exist long enough to invalidate it + we'll copy it here then reset the reference before we use it */ + Reference client; + Reference xinterface; + + public: + XMLRPCIdentifyRequest(Module *m, XMLRPCRequest& req, HTTPClient *c, XMLRPCServiceInterface* iface, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(m, acc, pass), request(req), repl(request.r), client(c), xinterface(iface) { } + + void OnSuccess() anope_override + { + if (!xinterface || !client) + return; + + request.r = this->repl; + + request.reply("result", "Success"); + request.reply("account", GetAccount()); + + xinterface->Reply(request); + client->SendReply(&request.r); + } + + void OnFail() anope_override + { + if (!xinterface || !client) + return; + + request.r = this->repl; + + request.reply("error", "Invalid password"); + + xinterface->Reply(request); + client->SendReply(&request.r); + } +}; + +class MyXMLRPCEvent : public XMLRPCEvent +{ + public: + bool Run(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) anope_override + { + if (request.name == "command") + this->DoCommand(iface, client, request); + else if (request.name == "checkAuthentication") + return this->DoCheckAuthentication(iface, client, request); + else if (request.name == "stats") + this->DoStats(iface, client, request); + else if (request.name == "channel") + this->DoChannel(iface, client, request); + else if (request.name == "user") + this->DoUser(iface, client, request); + else if (request.name == "opers") + this->DoOperType(iface, client, request); + + return true; + } + + private: + void DoCommand(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) + { + Anope::string service = request.data.size() > 0 ? request.data[0] : ""; + Anope::string user = request.data.size() > 1 ? request.data[1] : ""; + Anope::string command = request.data.size() > 2 ? request.data[2] : ""; + + if (service.empty() || user.empty() || command.empty()) + request.reply("error", "Invalid parameters"); + else + { + BotInfo *bi = BotInfo::Find(service); + if (!bi) + request.reply("error", "Invalid service"); + else + { + request.reply("result", "Success"); + + NickAlias *na = NickAlias::Find(user); + + Anope::string out; + + struct XMLRPCommandReply : CommandReply + { + Anope::string &str; + + XMLRPCommandReply(Anope::string &s) : str(s) { } + + void SendMessage(BotInfo *, const Anope::string &msg) anope_override + { + str += msg + "\n"; + }; + } + reply(out); + + CommandSource source(user, NULL, na ? *na->nc : NULL, &reply, bi); + Command::Run(source, command); + + if (!out.empty()) + request.reply("return", iface->Sanitize(out)); + } + } + } + + bool DoCheckAuthentication(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) + { + Anope::string username = request.data.size() > 0 ? request.data[0] : ""; + Anope::string password = request.data.size() > 1 ? request.data[1] : ""; + + if (username.empty() || password.empty()) + request.reply("error", "Invalid parameters"); + else + { + XMLRPCIdentifyRequest *req = new XMLRPCIdentifyRequest(me, request, client, iface, username, password); + FOREACH_MOD(OnCheckAuthentication, (NULL, req)); + req->Dispatch(); + return false; + } + + return true; + } + + void DoStats(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) + { + request.reply("uptime", stringify(Anope::CurTime - Anope::StartTime)); + request.reply("uplinkname", Me->GetLinks().front()->GetName()); + { + Anope::string buf; + for (std::set::iterator it = Servers::Capab.begin(); it != Servers::Capab.end(); ++it) + buf += " " + *it; + if (!buf.empty()) + buf.erase(buf.begin()); + request.reply("uplinkcapab", buf); + } + request.reply("usercount", stringify(UserListByNick.size())); + request.reply("maxusercount", stringify(MaxUserCount)); + request.reply("channelcount", stringify(ChannelList.size())); + } + + void DoChannel(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) + { + if (request.data.empty()) + return; + + Channel *c = Channel::Find(request.data[0]); + + request.reply("name", iface->Sanitize(c ? c->name : request.data[0])); + + if (c) + { + request.reply("bancount", stringify(c->HasMode("BAN"))); + int count = 0; + std::pair its = c->GetModeList("BAN"); + for (; its.first != its.second; ++its.first) + request.reply("ban" + stringify(++count), iface->Sanitize(its.first->second)); + + request.reply("exceptcount", stringify(c->HasMode("EXCEPT"))); + count = 0; + its = c->GetModeList("EXCEPT"); + for (; its.first != its.second; ++its.first) + request.reply("except" + stringify(++count), iface->Sanitize(its.first->second)); + + request.reply("invitecount", stringify(c->HasMode("INVITEOVERRIDE"))); + count = 0; + its = c->GetModeList("INVITEOVERRIDE"); + for (; its.first != its.second; ++its.first) + request.reply("invite" + stringify(++count), iface->Sanitize(its.first->second)); + + Anope::string users; + for (Channel::ChanUserList::const_iterator it = c->users.begin(); it != c->users.end(); ++it) + { + ChanUserContainer *uc = it->second; + users += uc->status.BuildModePrefixList() + uc->user->nick + " "; + } + if (!users.empty()) + { + users.erase(users.length() - 1); + request.reply("users", iface->Sanitize(users)); + } + + if (!c->topic.empty()) + request.reply("topic", iface->Sanitize(c->topic)); + + if (!c->topic_setter.empty()) + request.reply("topicsetter", iface->Sanitize(c->topic_setter)); + + request.reply("topictime", stringify(c->topic_time)); + request.reply("topicts", stringify(c->topic_ts)); + } + } + + void DoUser(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) + { + if (request.data.empty()) + return; + + User *u = User::Find(request.data[0]); + + request.reply("nick", iface->Sanitize(u ? u->nick : request.data[0])); + + if (u) + { + request.reply("ident", iface->Sanitize(u->GetIdent())); + request.reply("vident", iface->Sanitize(u->GetVIdent())); + request.reply("host", iface->Sanitize(u->host)); + if (!u->vhost.empty()) + request.reply("vhost", iface->Sanitize(u->vhost)); + if (!u->chost.empty()) + request.reply("chost", iface->Sanitize(u->chost)); + if (!u->ip.empty()) + request.reply("ip", u->ip); + request.reply("timestamp", stringify(u->timestamp)); + request.reply("signon", stringify(u->signon)); + if (u->Account()) + { + request.reply("account", iface->Sanitize(u->Account()->display)); + if (u->Account()->o) + request.reply("opertype", iface->Sanitize(u->Account()->o->ot->GetName())); + } + + Anope::string channels; + for (User::ChanUserList::const_iterator it = u->chans.begin(); it != u->chans.end(); ++it) + { + ChanUserContainer *cc = it->second; + channels += cc->status.BuildModePrefixList() + cc->chan->name + " "; + } + if (!channels.empty()) + { + channels.erase(channels.length() - 1); + request.reply("channels", channels); + } + } + } + + void DoOperType(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) + { + for (unsigned i = 0; i < Config->MyOperTypes.size(); ++i) + { + OperType *ot = Config->MyOperTypes[i]; + Anope::string perms; + for (std::list::const_iterator it2 = ot->GetPrivs().begin(), it2_end = ot->GetPrivs().end(); it2 != it2_end; ++it2) + perms += " " + *it2; + for (std::list::const_iterator it2 = ot->GetCommands().begin(), it2_end = ot->GetCommands().end(); it2 != it2_end; ++it2) + perms += " " + *it2; + request.reply(ot->GetName(), perms); + } + } +}; + +class ModuleXMLRPCMain : public Module +{ + ServiceReference xmlrpc; + + MyXMLRPCEvent stats; + + public: + ModuleXMLRPCMain(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), xmlrpc("XMLRPCServiceInterface", "xmlrpc") + { + me = this; + + if (!xmlrpc) + throw ModuleException("Unable to find xmlrpc reference, is m_xmlrpc loaded?"); + + xmlrpc->Register(&stats); + } + + ~ModuleXMLRPCMain() + { + if (xmlrpc) + xmlrpc->Unregister(&stats); + } +}; + +MODULE_INIT(ModuleXMLRPCMain) + 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