diff options
author | Adam <Adam@anope.org> | 2012-09-01 18:54:51 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-09-01 18:54:51 -0400 |
commit | e3d5140dcc936ff411c438b7e3997104cb5f085a (patch) | |
tree | 49d7ee0b3e531a1c81e35fb10f25e6340fa781ba | |
parent | f81d0113a21187d68c5fa0f1262e5514465b1953 (diff) |
Added a web panel module + a default template
68 files changed, 3360 insertions, 34 deletions
diff --git a/data/modules.example.conf b/data/modules.example.conf index 2a06b1a99..d4d86c0ba 100644 --- a/data/modules.example.conf +++ b/data/modules.example.conf @@ -92,6 +92,38 @@ m_helpchan } /* + * m_httpd + * + * Allows services to serve web pages. By itself, this module does nothing useful. + * + * Note that using this will allow users to get the IP of your services. + * To prevent this we recommend using a reverse proxy or a tunnel. + */ +#module { name = "m_httpd" } +httpd +{ + /* Name of this service */ + name = "httpd/main" + + /* IP to listen on */ + ip = "0.0.0.0" + /* Port to listen on */ + port = 8080 + /* Time before connections to this server are timed out */ + timeout = 30 + + /* If you are using a reverse proxy that sends one of the + * extforward_headers set below, set this to its IP. + * This allows services to obtain the real IP of users by + * reading the forwarded-for HTTP header. + */ + #extforward_ip = "192.168.0.255" + + /* The header to look for. These probably work as is. */ + extforward_header = "X-Forwarded-For Forwarded-For" +} + +/* * m_ldap * * This module allows other modules to use LDAP. By itself, this module does nothing useful. @@ -440,3 +472,26 @@ ns_maxemail #maxemails = 1 } +/* + * webcpanel + * + * This module creates a web configuration panel that allows users and operators to perform any task + * as they could over IRC. If you are using the default configuration you should be able to access + * this panel by visiting http://127.0.0.1:8080 in your web browser from the machine Anope is running on. + * + * This module requires m_httpd. + */ +#module { name = "webcpanel" } +webcpanel +{ + /* Web server to use */ + server = "httpd/main"; + + /* Template to use */ + template = "default"; + + /* Page title */ + title = "Anope IRC Services"; +} + + diff --git a/include/access.h b/include/access.h index 18499b602..b29572dfc 100644 --- a/include/access.h +++ b/include/access.h @@ -53,6 +53,11 @@ class CoreExport AccessProvider : public Service AccessProvider(Module *o, const Anope::string &n); virtual ~AccessProvider(); virtual ChanAccess *Create() = 0; + + private: + static std::list<AccessProvider *> providers; + public: + static const std::list<AccessProvider *>& GetProviders(); }; class CoreExport ChanAccess : public Serializable diff --git a/include/anope.h b/include/anope.h index 2a51514e0..2ec6602ea 100644 --- a/include/anope.h +++ b/include/anope.h @@ -342,7 +342,7 @@ namespace Anope * @param dest The destination string */ extern CoreExport void Unhex(const string &src, string &dest); - extern CoreExport void Unhex(const string &src, char *dest); + extern CoreExport void Unhex(const string &src, char *dest, size_t sz); /** Base 64 encode a string * @param src The string to encode diff --git a/include/logger.h b/include/logger.h index 9364cfb7c..eea86f890 100644 --- a/include/logger.h +++ b/include/logger.h @@ -49,6 +49,7 @@ class CoreExport Log { public: const BotInfo *bi; + Anope::string nick; const User *u; const NickCore *nc; Command *c; diff --git a/include/services.h b/include/services.h index c03991a13..31ab1cf37 100644 --- a/include/services.h +++ b/include/services.h @@ -55,8 +55,10 @@ #ifdef __GXX_EXPERIMENTAL_CXX0X__ # define anope_override override +# define anope_final final #else # define anope_override +# define anope_final #endif /** diff --git a/include/sockets.h b/include/sockets.h index 16cd10a1a..8f863b59c 100644 --- a/include/sockets.h +++ b/include/sockets.h @@ -288,6 +288,9 @@ class CoreExport BufferedSocket : public virtual Socket /** Write to the socket * @param message The message */ + protected: + virtual void Write(const char *buffer, size_t l); + public: void Write(const char *message, ...); void Write(const Anope::string &message); @@ -304,8 +307,10 @@ class CoreExport BufferedSocket : public virtual Socket class CoreExport BinarySocket : public virtual Socket { + protected: struct DataBlock { + char *orig; char *buf; size_t len; @@ -338,7 +343,9 @@ class CoreExport BinarySocket : public virtual Socket * @param buffer The data to write * @param l The length of the data */ - void Write(const char *buffer, size_t l); + virtual void Write(const char *buffer, size_t l); + void Write(const char *message, ...); + void Write(const Anope::string &message); /** Called with data from the socket * @param buffer The data diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 3653a59f1..13eb83d5a 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -105,7 +105,7 @@ foreach(MODULE_FOLDER ${MODULES_FOLDERS}) foreach(SUBDIR ${SUBMODULE_DIRS}) if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}") - file(GLOB MODULES_SUBDIR_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${SUBDIR}/*.cpp") + file(GLOB_RECURSE MODULES_SUBDIR_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${SUBDIR}/*.cpp") sort_list(MODULES_SUBDIR_SRCS) # Set all the files to use C++ as well as set their compile flags (use the module-specific compile flags, though) @@ -195,6 +195,11 @@ foreach(MODULE_FOLDER ${MODULES_FOLDERS}) else(NOT SKIP_DEPENDS AND NOT SKIP_LIBRARIES AND HAS_FUNCTION) message(" This is not a fatal error - ${SUBDIR} will not be built.") endif(NOT SKIP_DEPENDS AND NOT SKIP_LIBRARIES AND HAS_FUNCTION) + + # Run the directories CMakeLists.txt if there is one + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}/CMakeLists.txt") + add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}") + endif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}/CMakeLists.txt") endif(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}") endforeach(SUBDIR) endif(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_FOLDER}") diff --git a/modules/commands/ns_register.cpp b/modules/commands/ns_register.cpp index 0d51ef20c..1a219c8ba 100644 --- a/modules/commands/ns_register.cpp +++ b/modules/commands/ns_register.cpp @@ -224,9 +224,12 @@ class CommandNSRegister : public Command } else if (Config->NSRegistration.equals_ci("none")) { - ircdproto->SendLogin(u); - if (!Config->NoNicknameOwnership && u && na->nc == u->Account() && na->nc->HasFlag(NI_UNCONFIRMED) == false) - u->SetMode(findbot(Config->NickServ), UMODE_REGISTERED); + if (u) + { + ircdproto->SendLogin(u); + if (!Config->NoNicknameOwnership && na->nc == u->Account() && na->nc->HasFlag(NI_UNCONFIRMED) == false) + u->SetMode(findbot(Config->NickServ), UMODE_REGISTERED); + } } if (u) diff --git a/modules/encryption/enc_sha256.cpp b/modules/encryption/enc_sha256.cpp index b119eeba6..cee21b01d 100644 --- a/modules/encryption/enc_sha256.cpp +++ b/modules/encryption/enc_sha256.cpp @@ -148,7 +148,7 @@ class ESHA256 : public Module size_t pos = password.find(':'); Anope::string buf = password.substr(password.find(':', pos + 1) + 1, password.length()); char buf2[33]; - Anope::Unhex(buf, buf2); + Anope::Unhex(buf, buf2, sizeof(buf2)); for (int i = 0 ; i < 8; ++i) PACK32(reinterpret_cast<unsigned char *>(&buf2[i << 2]), iv[i]); } diff --git a/modules/extra/httpd.h b/modules/extra/httpd.h new file mode 100644 index 000000000..684c11512 --- /dev/null +++ b/modules/extra/httpd.h @@ -0,0 +1,224 @@ +#ifndef ANOPE_HTTPD_H +#define ANOPE_HTTPD_H + +enum HTTPError +{ + HTTP_ERROR_OK = 200, + HTTP_FOUND = 302, + HTTP_BAD_REQUEST = 400, + HTTP_PAGE_NOT_FOUND = 404, + HTTP_NOT_SUPPORTED = 505 +}; + +/* A message to someone */ +struct HTTPReply +{ + HTTPError error; + Anope::string content_type; + std::map<Anope::string, Anope::string> headers; + typedef std::list<std::pair<Anope::string, Anope::string> > cookie; + std::vector<cookie> cookies; + + HTTPReply() : error(HTTP_ERROR_OK), length(0) { } + + struct Data + { + char *buf; + size_t len; + + Data(const char *b, size_t l) + { + this->buf = new char[l]; + memcpy(this->buf, b, l); + this->len = l; + } + + ~Data() + { + delete [] buf; + } + }; + + std::deque<Data *> out; + size_t length; + + void Write(const Anope::string &message) + { + this->out.push_back(new Data(message.c_str(), message.length())); + this->length += message.length(); + } + + void Write(const char *b, size_t l) + { + this->out.push_back(new Data(b, l)); + this->length += l; + } +}; + +/* A message from soneone */ +struct HTTPMessage +{ + std::map<Anope::string, Anope::string> headers; + std::map<Anope::string, Anope::string> cookies; + std::map<Anope::string, Anope::string> get_data; + std::map<Anope::string, Anope::string> post_data; + Anope::string content; +}; + +class HTTPClient; +class HTTPProvider; + +class HTTPPage : public Base +{ + Anope::string url; + Anope::string content_type; + + public: + HTTPPage(const Anope::string &u, const Anope::string &ct = "text/html") : url(u), content_type(ct) { } + + const Anope::string &GetURL() const { return this->url; } + + const Anope::string &GetContentType() const { return this->content_type; } + + /** Called when this page is requested + * @param The server this page is on + * @param The page name + * @param The client requesting the page + * @param The HTTP header sent from the client to request the page + * @param The HTTP header that will be sent back to the client + */ + virtual void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) = 0; +}; + +class HTTPClient : public ClientSocket, public BufferedSocket, public BinarySocket +{ + protected: + void WriteClient(const Anope::string &message) + { + BinarySocket::Write(message + "\r\n"); + } + + public: + HTTPClient(ListenSocket *l, int f, const sockaddrs &a) : ClientSocket(l, a), BufferedSocket(), BinarySocket() { } + + virtual const Anope::string GetIP() + { + return this->clientaddr.addr(); + } + + bool ProcessRead() anope_override + { + return BufferedSocket::ProcessRead(); + } + + bool ProcessWrite() anope_override + { + return !BinarySocket::ProcessWrite() || BinarySocket::WriteBuffer.empty() ? false : true; + } + + void Write(const char *buffer, size_t l) anope_override + { + BinarySocket::Write(buffer, l); + } + + virtual void SendError(HTTPError err, const Anope::string &msg) = 0; + virtual void SendReply(HTTPReply *) = 0; +}; + +class HTTPProvider : public Service, public ListenSocket +{ + Anope::string ip; + unsigned short port; + public: + Anope::string ext_ip; + std::vector<Anope::string> ext_headers; + + HTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p) : Service(c, "HTTPProvider", n), ListenSocket(i, p, i.find(':') != Anope::string::npos), ip(i), port(p) { } + + const Anope::string &GetIP() const + { + return this->ip; + } + + unsigned short GetPort() const + { + return this->port; + } + + virtual bool RegisterPage(HTTPPage *page) = 0; + virtual void UnregisterPage(HTTPPage *page) = 0; + virtual HTTPPage* FindPage(const Anope::string &name) = 0; +}; + +namespace HTTPUtils +{ + inline Anope::string URLDecode(const Anope::string &url) + { + Anope::string decoded; + + for (unsigned i = 0; i < url.length(); ++i) + { + const char& c = url[i]; + + if (c == '%' && i + 2 < url.length()) + { + Anope::string dest; + Anope::Unhex(url.substr(i + 1, 2), dest); + decoded += dest; + i += 2; + } + else if (c == '+') + decoded += ' '; + else + decoded += c; + } + + return decoded; + } + + inline Anope::string URLEncode(const Anope::string &url) + { + Anope::string encoded; + + for (unsigned i = 0; i < url.length(); ++i) + { + const char& c = url[i]; + + if (isalnum(c) || c == '.' || c == '-' || c == '*' || c == '_') + encoded += c; + else if (c == ' ') + encoded += '+'; + else + encoded += "%" + Anope::Hex(c); + } + + return encoded; + } + + inline Anope::string Escape(const Anope::string &src) + { + Anope::string dst; + + for (unsigned i = 0; i < src.length(); ++i) + { + switch (src[i]) + { + case '<': + dst += "<"; + break; + case '>': + dst += ">"; + break; + case '"': + dst += """; + break; + default: + dst += src[i]; + } + } + + return dst; + } +} + +#endif // ANOPE_HTTPD_H diff --git a/modules/extra/m_httpd.cpp b/modules/extra/m_httpd.cpp new file mode 100644 index 000000000..aec3ce4a1 --- /dev/null +++ b/modules/extra/m_httpd.cpp @@ -0,0 +1,415 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "module.h" +#include "httpd.h" + +static Anope::string BuildDate() +{ + char timebuf[64]; + struct tm *tm = localtime(&Anope::CurTime); + strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %T %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, public Base +{ + HTTPProvider *provider; + HTTPMessage header; + bool header_done; + Anope::string page_name; + dynamic_reference<HTTPPage> page; + Anope::string ip; + + enum + { + ACTION_NONE, + ACTION_GET, + ACTION_POST + } action; + + void Serve() + { + 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->header.headers.count(token)) + { + Log(LOG_DEBUG, "httpd") << "m_httpd: IP for connection " << this->GetFD() << " changed to " << this->ip; + this->ip = this->header.headers[token]; + break; + } + } + } + + Log(LOG_DEBUG, "httpd") << "m_httpd: Serving page " << this->page_name << " to " << this->ip; + + HTTPReply reply; + + this->page->OnRequest(this->provider, this->page_name, this, this->header, 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), ip(a.addr()), 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; + } + + const Anope::string GetIP() anope_override + { + return this->ip; + } + + bool Read(const Anope::string &buf) anope_override + { + Log(LOG_DEBUG_2) << "HTTP from " << this->clientaddr.addr() << ": " << buf; + + if (!this->header_done) + { + if (this->action == ACTION_NONE) + { + std::vector<Anope::string> params = BuildStringVector(buf); + + 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->header.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->header.cookies[token.substr(0, sz)] = token.substr(sz + 1, end); + } + } + else if (buf.find(':') != Anope::string::npos) + { + size_t sz = buf.find(':'); + if (sz + 2 < buf.length()) + this->header.headers[buf.substr(0, sz)] = buf.substr(sz + 2); + } + else if (buf.empty()) + { + this->header_done = true; + + if (this->action == ACTION_POST) + { + Log(LOG_DEBUG_2) << "HTTP POST from " << this->clientaddr.addr() << ": " << this->extrabuf; + + sepstream sep(this->extrabuf, '&'); + Anope::string token; + + while (sep.GetToken(token)) + { + size_t sz = token.find('='); + if (sz == Anope::string::npos || !sz || sz + 1 >= token.length()) + continue; + this->header.post_data[token.substr(0, sz)] = HTTPUtils::URLDecode(token.substr(sz + 1)); + } + } + + this->Serve(); + } + } + + 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 *message) anope_override + { + this->WriteClient("HTTP/1.1 " + GetStatusFromCode(message->error)); + this->WriteClient("Date: " + BuildDate()); + this->WriteClient("Server: Anope-" + Anope::VersionShort()); + if (message->content_type.empty()) + this->WriteClient("Content-Type: text/html"); + else + this->WriteClient("Content-Type: " + message->content_type); + this->WriteClient("Content-Length: " + stringify(message->length)); + + for (unsigned i = 0; i < message->cookies.size(); ++i) + { + Anope::string buf = "Set-Cookie:"; + + for (HTTPReply::cookie::iterator it = message->cookies[i].begin(), it_end = message->cookies[i].end(); it != it_end; ++it) + buf += " " + it->first + "=" + it->second + ";"; + + buf.erase(buf.length() - 1); + + this->WriteClient(buf); + } + + typedef std::map<Anope::string, Anope::string> map; + for (map::iterator it = message->headers.begin(), it_end = message->headers.end(); it != it_end; ++it) + this->WriteClient(it->first + ": " + it->second); + + this->WriteClient("Connection: Close"); + this->WriteClient(""); + + for (unsigned i = 0; i < message->out.size(); ++i) + { + HTTPReply::Data* d = message->out[i]; + + this->Write(d->buf, d->len); + + delete d; + } + + message->out.clear(); + } +}; + +class MyHTTPProvider : public HTTPProvider, public CallBack +{ + int timeout; + std::map<Anope::string, HTTPPage *> pages; + std::list<dynamic_reference<MyHTTPClient> > clients; + + public: + MyHTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, const int t) : HTTPProvider(c, n, i, p), CallBack(c, 10, Anope::CurTime, true), timeout(t) { } + + void Tick(time_t) anope_override + { + while (!this->clients.empty()) + { + dynamic_reference<MyHTTPClient>& 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 +{ + std::map<Anope::string, HTTPProvider *> providers; + public: + HTTPD(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED) + { + this->SetAuthor("Anope"); + + Implementation i[] = { I_OnReload }; + ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); + + this->OnReload(); + } + + ~HTTPD() + { + for (std::map<int, Socket *>::const_iterator it = SocketEngine::Sockets.begin(), it_end = SocketEngine::Sockets.end(); it != it_end;) + { + Socket *s = it->second; + ++it; + + if (dynamic_cast<MyHTTPProvider *>(s) || dynamic_cast<MyHTTPClient *>(s)) + delete s; + } + + this->providers.clear(); + } + + void OnReload() anope_override + { + ConfigReader config; + std::set<Anope::string> existing; + + for (int i = 0, num = config.Enumerate("httpd"); i < num; ++i) + { + Anope::string hname = config.ReadValue("httpd", "name", "httpd/main", i); + existing.insert(hname); + + Anope::string ip = config.ReadValue("httpd", "ip", "", i); + int port = config.ReadInteger("httpd", "port", "8080", i, true); + int timeout = config.ReadInteger("httpd", "timeout", "30", i, true); + Anope::string ext_ip = config.ReadValue("httpd", "extforward_ip", "", i); + Anope::string ext_header = config.ReadValue("httpd", "extforward_header", "", i); + + if (ip.empty()) + { + Log(LOG_NORMAL, "httpd") << "You must configure a bind IP for HTTP server " << hname; + continue; + } + else if (port <= 0 || port > 65535) + { + Log(LOG_NORMAL, "httpd") << "You must configure a (valid) listen port for HTTP server " << hname; + continue; + } + + HTTPProvider *p; + if (this->providers.count(hname) == 0) + { + try + { + p = new MyHTTPProvider(this, hname, ip, port, timeout); + } + catch (const SocketException &ex) + { + Log(LOG_NORMAL, "httpd") << "Unable to create HTTP server " << hname << ": " << ex.GetReason(); + continue; + } + this->providers[hname] = p; + + Log(LOG_NORMAL, "httpd") << "Created HTTP server " << hname; + } + else + { + p = this->providers[hname]; + + if (p->GetIP() != ip || p->GetPort() != port) + { + delete p; + this->providers.erase(hname); + + try + { + p = new MyHTTPProvider(this, hname, ip, port, timeout); + } + catch (const SocketException &ex) + { + Log(LOG_NORMAL, "httpd") << "Unable to create HTTP server " << hname << ": " << ex.GetReason(); + continue; + } + + this->providers[hname] = p; + } + } + + + p->ext_ip = ext_ip; + p->ext_headers = BuildStringVector(ext_header); + } + + for (std::map<Anope::string, HTTPProvider *>::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(LOG_NORMAL, "httpd") << "Removing HTTP server " << p->name; + this->providers.erase(p->name); + delete p; + } + } + } +}; + +MODULE_INIT(HTTPD) diff --git a/modules/extra/webcpanel/CMakeLists.txt b/modules/extra/webcpanel/CMakeLists.txt new file mode 100644 index 000000000..4437156ad --- /dev/null +++ b/modules/extra/webcpanel/CMakeLists.txt @@ -0,0 +1,5 @@ + +install(DIRECTORY templates + DESTINATION "${DB_DIR}/modules/webcpanel" +) + diff --git a/modules/extra/webcpanel/pages/chanserv/access.cpp b/modules/extra/webcpanel/pages/chanserv/access.cpp new file mode 100644 index 000000000..d3ec2ad99 --- /dev/null +++ b/modules/extra/webcpanel/pages/chanserv/access.cpp @@ -0,0 +1,147 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" + +WebCPanel::ChanServ::Access::Access(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +void WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + const Anope::string &chname = message.get_data["channel"]; + + if (chname.empty()) + { + reply.error = HTTP_FOUND; + reply.headers["Location"] = "http://" + message.headers["Host"] + "/chanserv/info"; + return; + } + + ChannelInfo *ci = cs_findchan(chname); + + if (!ci) + return; + + AccessGroup u_access = ci->AccessFor(na->nc); + bool has_priv = na->nc->IsServicesOper() && na->nc->o->ot->HasPriv("chanserv/access/modify"); + + if (!u_access.HasPriv("ACCESS_LIST") && !has_priv) + return; + + const ChanAccess *highest = u_access.Highest(); + + if (ci->AccessFor(na->nc).HasPriv("ACCESS_CHANGE") || has_priv) + { + if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false) + { + std::vector<Anope::string> params; + params.push_back(ci->name); + params.push_back("DEL"); + params.push_back(message.get_data["mask"]); + + WebPanel::RunCommand(na->nc->display, na->nc, Config->ChanServ, "chanserv/access", params, replacements); + } + else if (message.post_data["mask"].empty() == false && message.post_data["access"].empty() == false && message.post_data["provider"].empty() == false) + { + // Generic access add code here, works with any provider (so we can't call a command exactly) + AccessProvider *a = NULL; + for (std::list<AccessProvider *>::const_iterator it = AccessProvider::GetProviders().begin(); it != AccessProvider::GetProviders().end(); ++it) + if ((*it)->name == message.post_data["provider"]) + a = *it; + + if (a) + { + bool denied = false; + + for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i) + { + ChanAccess *acc = ci->GetAccess(i); + + if (acc->mask == message.post_data["mask"]) + { + if ((!highest || *acc >= *highest) && !u_access.Founder && !has_priv) + { + replacements["MESSAGES"] = "Access denied"; + denied = true; + } + else + ci->EraseAccess(acc); + break; + } + } + + if (ci->GetAccessCount() >= Config->CSAccessMax) + replacements["MESSAGES"] = "Sorry, you can only have " + stringify(Config->CSAccessMax) + " access entries on a channel."; + else if (!denied) + { + ChanAccess *new_acc = a->Create(); + new_acc->ci = ci; + new_acc->mask = message.post_data["mask"]; + new_acc->creator = na->nc->display; + try + { + new_acc->Unserialize(message.post_data["access"]); + } + catch (...) + { + replacements["MESSAGES"] = "Invalid access expression for the given type"; + delete new_acc; + new_acc = NULL; + } + if (new_acc) + { + new_acc->last_seen = 0; + new_acc->created = Anope::CurTime; + + if ((!highest || *highest <= *new_acc) && !u_access.Founder && !has_priv) + delete new_acc; + else if (new_acc->Serialize().empty()) + { + replacements["MESSAGES"] = "Invalid access expression for the given type"; + delete new_acc; + } + else + { + ci->AddAccess(new_acc); + replacements["MESSAGES"] = "Access for " + new_acc->mask + " set to " + new_acc->Serialize(); + } + } + } + } + } + } + + replacements["ESCAPED_CHANNEL"] = HTTPUtils::URLEncode(chname); + + for (unsigned i = 0; i < ci->GetAccessCount(); ++i) + { + ChanAccess *access = ci->GetAccess(i); + + replacements["MASKS"] = HTTPUtils::Escape(access->mask); + replacements["ACCESSES"] = HTTPUtils::Escape(access->Serialize()); + replacements["CREATORS"] = HTTPUtils::Escape(access->creator); + replacements["ACCESS_CHANGES"] = ci->AccessFor(na->nc).HasPriv("ACCESS_CHANGE") ? "YES" : "NO"; + } + + for (std::list<AccessProvider *>::const_iterator it = AccessProvider::GetProviders().begin(); it != AccessProvider::GetProviders().end(); ++it) + { + const AccessProvider *a = *it; + replacements["PROVIDERS"] = a->name; + } + + TemplateFileServer page("chanserv/access.html"); + page.Serve(server, page_name, client, message, reply, replacements); +} + +std::set<Anope::string> WebCPanel::ChanServ::Access::GetData() anope_override +{ + std::set<Anope::string> v; + v.insert("channel"); + return v; +} + diff --git a/modules/extra/webcpanel/pages/chanserv/access.h b/modules/extra/webcpanel/pages/chanserv/access.h new file mode 100644 index 000000000..50425aa40 --- /dev/null +++ b/modules/extra/webcpanel/pages/chanserv/access.h @@ -0,0 +1,27 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + +namespace ChanServ +{ + +class Access : public WebPanelProtectedPage +{ + public: + Access(const Anope::string &cat, const Anope::string &u); + + void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; + + std::set<Anope::string> GetData() anope_override; +}; + +} + +} + diff --git a/modules/extra/webcpanel/pages/chanserv/akick.cpp b/modules/extra/webcpanel/pages/chanserv/akick.cpp new file mode 100644 index 000000000..bc80437cc --- /dev/null +++ b/modules/extra/webcpanel/pages/chanserv/akick.cpp @@ -0,0 +1,81 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" + +WebCPanel::ChanServ::Akick::Akick(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +void WebCPanel::ChanServ::Akick::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + const Anope::string &chname = message.get_data["channel"]; + + if (chname.empty()) + { + reply.error = HTTP_FOUND; + reply.headers["Location"] = "http://" + message.headers["Host"] + "/chanserv/info"; + return; + } + + ChannelInfo *ci = cs_findchan(chname); + + if (!ci) + return; + + AccessGroup u_access = ci->AccessFor(na->nc); + bool has_priv = na->nc->IsServicesOper() && na->nc->o->ot->HasPriv("chanserv/access/modify"); + + if (!u_access.HasPriv("akick") && !has_priv) + return; + + if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false) + { + std::vector<Anope::string> params; + params.push_back(ci->name); + params.push_back("DEL"); + params.push_back(message.get_data["mask"]); + + WebPanel::RunCommand(na->nc->display, na->nc, Config->ChanServ, "chanserv/akick", params, replacements); + } + else if (message.post_data["mask"].empty() == false) + { + std::vector<Anope::string> params; + params.push_back(ci->name); + params.push_back("ADD"); + params.push_back(message.post_data["mask"]); + if (message.post_data["reason"].empty() == false) + params.push_back(message.get_data["reason"]); + + WebPanel::RunCommand(na->nc->display, na->nc, Config->ChanServ, "chanserv/akick", params, replacements); + } + + replacements["ESCAPED_CHANNEL"] = HTTPUtils::URLEncode(chname); + + for (unsigned i = 0; i < ci->GetAkickCount(); ++i) + { + AutoKick *akick = ci->GetAkick(i); + + if (akick->nc) + replacements["MASKS"] = HTTPUtils::Escape(akick->nc->display); + else + replacements["MASKS"] = HTTPUtils::Escape(akick->mask); + replacements["CREATORS"] = HTTPUtils::Escape(akick->creator); + replacements["REASONS"] = HTTPUtils::Escape(akick->reason); + } + + TemplateFileServer page("chanserv/akick.html"); + page.Serve(server, page_name, client, message, reply, replacements); +} + +std::set<Anope::string> WebCPanel::ChanServ::Akick::GetData() anope_override +{ + std::set<Anope::string> v; + v.insert("channel"); + return v; +} + diff --git a/modules/extra/webcpanel/pages/chanserv/akick.h b/modules/extra/webcpanel/pages/chanserv/akick.h new file mode 100644 index 000000000..ff4a4653e --- /dev/null +++ b/modules/extra/webcpanel/pages/chanserv/akick.h @@ -0,0 +1,27 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + +namespace ChanServ +{ + +class Akick : public WebPanelProtectedPage +{ + public: + Akick(const Anope::string &cat, const Anope::string &u); + + void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; + + std::set<Anope::string> GetData() anope_override; +}; + +} + +} + diff --git a/modules/extra/webcpanel/pages/chanserv/info.cpp b/modules/extra/webcpanel/pages/chanserv/info.cpp new file mode 100644 index 000000000..8db88f496 --- /dev/null +++ b/modules/extra/webcpanel/pages/chanserv/info.cpp @@ -0,0 +1,32 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" + +WebCPanel::ChanServ::Info::Info(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +void WebCPanel::ChanServ::Info::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + // XXX this is slightly inefficient + for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) + { + ChannelInfo *ci = it->second; + + if (ci->AccessFor(na->nc).HasPriv("SET") || ci->AccessFor(na->nc).HasPriv("ACCESS_LIST")) + { + replacements["CHANNEL_NAMES"] = ci->name; + replacements["ESCAPED_CHANNEL_NAMES"] = HTTPUtils::URLEncode(ci->name); + } + } + + + TemplateFileServer page("chanserv/main.html"); + page.Serve(server, page_name, client, message, reply, replacements); +} + diff --git a/modules/extra/webcpanel/pages/chanserv/info.h b/modules/extra/webcpanel/pages/chanserv/info.h new file mode 100644 index 000000000..87dc9836b --- /dev/null +++ b/modules/extra/webcpanel/pages/chanserv/info.h @@ -0,0 +1,25 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + +namespace ChanServ +{ + +class Info : public WebPanelProtectedPage +{ + public: + Info(const Anope::string &cat, const Anope::string &u); + + void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + +} + diff --git a/modules/extra/webcpanel/pages/chanserv/set.cpp b/modules/extra/webcpanel/pages/chanserv/set.cpp new file mode 100644 index 000000000..764eb13ac --- /dev/null +++ b/modules/extra/webcpanel/pages/chanserv/set.cpp @@ -0,0 +1,136 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" + +WebCPanel::ChanServ::Set::Set(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +void WebCPanel::ChanServ::Set::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + const Anope::string &chname = message.get_data["channel"]; + + if (chname.empty()) + { + reply.error = HTTP_FOUND; + reply.headers["Location"] = "http://" + message.headers["Host"] + "/chanserv/info"; + return; + } + + ChannelInfo *ci = cs_findchan(chname); + + if (!ci || !ci->AccessFor(na->nc).HasPriv("SET")) + return; + + if (message.post_data.empty() == false) + { + if (ci->HasFlag(CI_KEEPTOPIC) != message.post_data.count("keeptopic")) + { + if (!ci->HasFlag(CI_KEEPTOPIC)) + ci->SetFlag(CI_KEEPTOPIC); + else + ci->UnsetFlag(CI_KEEPTOPIC); + replacements["MESSAGES"] = "Secure updated"; + } + if (ci->HasFlag(CI_PEACE) != message.post_data.count("peace")) + { + if (!ci->HasFlag(CI_PEACE)) + ci->SetFlag(CI_PEACE); + else + ci->UnsetFlag(CI_PEACE); + replacements["MESSAGES"] = "Peace updated"; + } + if (ci->HasFlag(CI_PRIVATE) != message.post_data.count("private")) + { + if (!ci->HasFlag(CI_PRIVATE)) + ci->SetFlag(CI_PRIVATE); + else + ci->UnsetFlag(CI_PRIVATE); + replacements["MESSAGES"] = "Private updated"; + } + if (ci->HasFlag(CI_RESTRICTED) != message.post_data.count("restricted")) + { + if (!ci->HasFlag(CI_RESTRICTED)) + ci->SetFlag(CI_RESTRICTED); + else + ci->UnsetFlag(CI_RESTRICTED); + replacements["MESSAGES"] = "Restricted updated"; + } + if (ci->HasFlag(CI_SECURE) != message.post_data.count("secure")) + { + if (!ci->HasFlag(CI_SECURE)) + ci->SetFlag(CI_SECURE); + else + ci->UnsetFlag(CI_SECURE); + replacements["MESSAGES"] = "Secure updated"; + } + if (ci->HasFlag(CI_SECUREOPS) != message.post_data.count("secureops")) + { + if (!ci->HasFlag(CI_SECUREOPS)) + ci->SetFlag(CI_SECUREOPS); + else + ci->UnsetFlag(CI_SECUREOPS); + replacements["MESSAGES"] = "Secureops updated"; + } + if (ci->HasFlag(CI_TOPICLOCK) != message.post_data.count("topiclock")) + { + if (!ci->HasFlag(CI_TOPICLOCK)) + ci->SetFlag(CI_TOPICLOCK); + else + ci->UnsetFlag(CI_TOPICLOCK); + replacements["MESSAGES"] = "Topiclock updated"; + } + } + + replacements["CHANNEL"] = HTTPUtils::Escape(ci->name); + replacements["CHANNEL_ESCAPED"] = HTTPUtils::URLEncode(ci->name); + if (ci->GetFounder()) + replacements["FOUNDER"] = ci->GetFounder()->display; + if (ci->successor) + replacements["SUCCESSOR"] = ci->successor->display; + replacements["TIME_REGISTERED"] = do_strftime(ci->time_registered, na->nc); + replacements["LAST_USED"] = do_strftime(ci->last_used, na->nc); + + if (!ci->last_topic.empty()) + { + replacements["LAST_TOPIC"] = HTTPUtils::Escape(ci->last_topic); + replacements["LAST_TOPIC_SETTER"] = HTTPUtils::Escape(ci->last_topic_setter); + } + + if (ci->HasFlag(CI_KEEPTOPIC)) + replacements["KEEPTOPIC"]; + + if (ci->HasFlag(CI_PEACE)) + replacements["PEACE"]; + + if (ci->HasFlag(CI_PRIVATE)) + replacements["PRIVATE"]; + + if (ci->HasFlag(CI_RESTRICTED)) + replacements["RESTRICTED"]; + + if (ci->HasFlag(CI_SECURE)) + replacements["SECURE"]; + + if (ci->HasFlag(CI_SECUREOPS)) + replacements["SECUREOPS"]; + + if (ci->HasFlag(CI_TOPICLOCK)) + replacements["TOPICLOCK"]; + + TemplateFileServer page("chanserv/set.html"); + page.Serve(server, page_name, client, message, reply, replacements); +} + +std::set<Anope::string> WebCPanel::ChanServ::Set::GetData() anope_override +{ + std::set<Anope::string> v; + v.insert("channel"); + return v; +} + diff --git a/modules/extra/webcpanel/pages/chanserv/set.h b/modules/extra/webcpanel/pages/chanserv/set.h new file mode 100644 index 000000000..67e817493 --- /dev/null +++ b/modules/extra/webcpanel/pages/chanserv/set.h @@ -0,0 +1,27 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + +namespace ChanServ +{ + +class Set : public WebPanelProtectedPage +{ + public: + Set(const Anope::string &cat, const Anope::string &u); + + void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; + + std::set<Anope::string> GetData() anope_override; +}; + +} + +} + diff --git a/modules/extra/webcpanel/pages/confirm.cpp b/modules/extra/webcpanel/pages/confirm.cpp new file mode 100644 index 000000000..f18d28129 --- /dev/null +++ b/modules/extra/webcpanel/pages/confirm.cpp @@ -0,0 +1,31 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../webcpanel.h" + +void WebCPanel::Confirm::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) +{ + TemplateFileServer::Replacements replacements; + const Anope::string &user = message.post_data["username"], &pass = message.post_data["password"], &email = message.post_data["email"]; + + replacements["TITLE"] = page_title; + + if (!user.empty() && !pass.empty()) + { + std::vector<Anope::string> params; + params.push_back(pass); + if (!email.empty()) + params.push_back(email); + + WebPanel::RunCommand(user, NULL, Config->NickServ, "nickserv/register", params, replacements); + } + + TemplateFileServer page("confirm.html"); + + page.Serve(server, page_name, client, message, reply, replacements); +} + diff --git a/modules/extra/webcpanel/pages/confirm.h b/modules/extra/webcpanel/pages/confirm.h new file mode 100644 index 000000000..d4d19d9c6 --- /dev/null +++ b/modules/extra/webcpanel/pages/confirm.h @@ -0,0 +1,22 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../httpd.h" + +namespace WebCPanel +{ + +class Confirm : public WebPanelPage +{ + public: + Confirm(const Anope::string &u) : WebPanelPage(u) { } + + void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override; +}; + +} + diff --git a/modules/extra/webcpanel/pages/index.cpp b/modules/extra/webcpanel/pages/index.cpp new file mode 100644 index 000000000..525e564f6 --- /dev/null +++ b/modules/extra/webcpanel/pages/index.cpp @@ -0,0 +1,73 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../webcpanel.h" + +void WebCPanel::Index::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) +{ + TemplateFileServer::Replacements replacements; + const Anope::string &user = message.post_data["username"], &pass = message.post_data["password"]; + + replacements["TITLE"] = page_title; + + if (!user.empty() && !pass.empty()) + { + // Rate limit check. + + NickAlias *na = findnick(user); + + EventReturn MOD_RESULT = EVENT_CONTINUE; + + if (na) + { + FOREACH_RESULT(I_OnCheckAuthentication, OnCheckAuthentication(NULL, NULL, std::vector<Anope::string>(), na->nc->display, pass)); + } + + if (MOD_RESULT == EVENT_ALLOW) + { + Anope::string id; + for (int i = 0; i < 64; ++i) + { + char c; + do + c = 48 + (rand() % 123); + while (!isalnum(c)); + id += c; + } + + na->Extend("webcpanel_id", new ExtensibleItemClass<Anope::string>(id)); + na->Extend("webcpanel_ip", new ExtensibleItemClass<Anope::string>(client->GetIP())); + + { + HTTPReply::cookie c; + c.push_back(std::make_pair("account", na->nick)); + c.push_back(std::make_pair("Path", "/")); + reply.cookies.push_back(c); + } + + { + HTTPReply::cookie c; + c.push_back(std::make_pair("id", id)); + c.push_back(std::make_pair("Path", "/")); + reply.cookies.push_back(c); + } + + reply.error = HTTP_FOUND; + reply.headers["Location"] = "http://" + message.headers["Host"] + "/nickserv/info"; + return; + } + else + { + replacements["INVALID_LOGIN"] = "Invalid username or password"; + } + } + + TemplateFileServer page("login.html"); + + page.Serve(server, page_name, client, message, reply, replacements); +} + diff --git a/modules/extra/webcpanel/pages/index.h b/modules/extra/webcpanel/pages/index.h new file mode 100644 index 000000000..2f4d9c400 --- /dev/null +++ b/modules/extra/webcpanel/pages/index.h @@ -0,0 +1,22 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../httpd.h" + +namespace WebCPanel +{ + +class Index : public WebPanelPage +{ + public: + Index(const Anope::string &u) : WebPanelPage(u) { } + + void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override; +}; + +} + diff --git a/modules/extra/webcpanel/pages/logout.cpp b/modules/extra/webcpanel/pages/logout.cpp new file mode 100644 index 000000000..90a6a8a9b --- /dev/null +++ b/modules/extra/webcpanel/pages/logout.cpp @@ -0,0 +1,22 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../webcpanel.h" + +WebCPanel::Logout::Logout(const Anope::string &u) : WebPanelProtectedPage("", u) +{ +} + +void WebCPanel::Logout::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + na->Shrink("webcpanel_id"); + na->Shrink("webcpanel_ip"); + + reply.error = HTTP_FOUND; + reply.headers["Location"] = "http://" + message.headers["Host"]; +} + diff --git a/modules/extra/webcpanel/pages/logout.h b/modules/extra/webcpanel/pages/logout.h new file mode 100644 index 000000000..4f31e4a00 --- /dev/null +++ b/modules/extra/webcpanel/pages/logout.h @@ -0,0 +1,20 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + +class Logout : public WebPanelProtectedPage +{ + public: + Logout(const Anope::string &u); + + void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + diff --git a/modules/extra/webcpanel/pages/memoserv/memos.cpp b/modules/extra/webcpanel/pages/memoserv/memos.cpp new file mode 100644 index 000000000..eafbde3a5 --- /dev/null +++ b/modules/extra/webcpanel/pages/memoserv/memos.cpp @@ -0,0 +1,121 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" + +WebCPanel::MemoServ::Memos::Memos(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +void WebCPanel::MemoServ::Memos::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + const Anope::string &chname = message.get_data["channel"]; + ChannelInfo *ci; + const MemoInfo *mi; + Memo *m; + + for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) + { + ci = it->second; + + if (ci->AccessFor(na->nc).HasPriv("MEMO")) + { + replacements["CHANNEL_NAMES"] = ci->name; + replacements["ESCAPED_CHANNEL_NAMES"] = HTTPUtils::URLEncode(ci->name); + } + } + + if (chname.empty()) + { + replacements["MESSAGES"] = "No Channel specified, displaying the memos for your Nick"; + mi = &na->nc->memos; + } + else + { + ci = cs_findchan(chname); + if (ci) + { + replacements["MESSAGES"] = "Displaying the memos for " + chname + "."; + mi = &ci->memos; + } + else + { + replacements["MESSAGES"] = "Channel " + chname + " not found, displaying the memos for your nick"; + mi = &na->nc->memos; + } + + replacements["CHANNEL_NAME"] = ci->name; + replacements["ESCAPED_CHANNEL_NAME"] = HTTPUtils::URLEncode(ci->name); + } + if (message.post_data.count("receiver") > 0 && message.post_data.count("message") > 0) + { + std::vector<Anope::string> params; + params.push_back(HTTPUtils::URLDecode(message.post_data["receiver"])); + params.push_back(HTTPUtils::URLDecode(message.post_data["message"])); + + WebPanel::RunCommand(na->nc->display, na->nc, Config->MemoServ, "memoserv/send", params, replacements); + } + if (message.get_data.count("del") > 0 && message.get_data.count("number") > 0) + { + std::vector<Anope::string> params; + if (!chname.empty()) + params.push_back(chname); + params.push_back(message.get_data["number"]); + + WebPanel::RunCommand(na->nc->display, na->nc, Config->MemoServ, "memoserv/del", params, replacements); + } + if (message.get_data.count("read") > 0 && message.get_data.count("number") > 0) + { + std::vector<Anope::string> params; + int number; + bool error = false; + + try + { + number = convertTo<int>(message.get_data["number"]); + } + catch (const ConvertException &ex) + { + replacements["MESSAGES"] = "ERROR - invalid parameter for NUMBER"; + error = true; + } + + m = mi->GetMemo(number-1); + + if (!error && !m) + { + replacements["MESSAGES"] = "ERROR - invalid memo number."; + error = true; + } + + if (!error && message.get_data["read"] == "1") + { + m->UnsetFlag(MF_UNREAD); + } + else if (!error && message.get_data["read"] == "2") + { + m->SetFlag(MF_UNREAD); + } + } + + for (unsigned i = 0; i < mi->memos->size(); ++i) + { + m = mi->GetMemo(i); + replacements["NUMBER"] = stringify(i+1); + replacements["SENDER"] = m->sender; + replacements["TIME"] = do_strftime(m->time); + replacements["TEXT"] = m->text; + if (m->HasFlag(MF_UNREAD)) + replacements["UNREAD"] = "YES"; + else + replacements["UNREAD"] = "NO"; + } + + TemplateFileServer page("memoserv/memos.html"); + page.Serve(server, page_name, client, message, reply, replacements); +} + diff --git a/modules/extra/webcpanel/pages/memoserv/memos.h b/modules/extra/webcpanel/pages/memoserv/memos.h new file mode 100644 index 000000000..00c4c346b --- /dev/null +++ b/modules/extra/webcpanel/pages/memoserv/memos.h @@ -0,0 +1,25 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + +namespace MemoServ +{ + +class Memos : public WebPanelProtectedPage +{ + public: + Memos(const Anope::string &cat, const Anope::string &u); + + void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + +} + diff --git a/modules/extra/webcpanel/pages/nickserv/access.cpp b/modules/extra/webcpanel/pages/nickserv/access.cpp new file mode 100644 index 000000000..c18c5ccb0 --- /dev/null +++ b/modules/extra/webcpanel/pages/nickserv/access.cpp @@ -0,0 +1,39 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" + +WebCPanel::NickServ::Access::Access(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +void WebCPanel::NickServ::Access::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + if (message.post_data.count("access") > 0) + { + std::vector<Anope::string> params; + params.push_back("ADD"); + params.push_back(message.post_data["access"]); + + WebPanel::RunCommand(na->nc->display, na->nc, Config->NickServ, "nickserv/access", params, replacements); + } + else if (message.get_data.count("del") > 0 && message.get_data.count("mask") > 0) + { + std::vector<Anope::string> params; + params.push_back("DEL"); + params.push_back(message.get_data["mask"]); + + WebPanel::RunCommand(na->nc->display, na->nc, Config->NickServ, "nickserv/access", params, replacements); + } + + for (unsigned i = 0; i < na->nc->access.size(); ++i) + replacements["ACCESS"] = na->nc->access[i]; + + TemplateFileServer page("nickserv/access.html"); + page.Serve(server, page_name, client, message, reply, replacements); +} + diff --git a/modules/extra/webcpanel/pages/nickserv/access.h b/modules/extra/webcpanel/pages/nickserv/access.h new file mode 100644 index 000000000..3f4059aa4 --- /dev/null +++ b/modules/extra/webcpanel/pages/nickserv/access.h @@ -0,0 +1,25 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + +namespace NickServ +{ + +class Access : public WebPanelProtectedPage +{ + public: + Access(const Anope::string &cat, const Anope::string &u); + + void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + +} + diff --git a/modules/extra/webcpanel/pages/nickserv/alist.cpp b/modules/extra/webcpanel/pages/nickserv/alist.cpp new file mode 100644 index 000000000..d3c92dcf4 --- /dev/null +++ b/modules/extra/webcpanel/pages/nickserv/alist.cpp @@ -0,0 +1,49 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" + +WebCPanel::NickServ::Alist::Alist(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +void WebCPanel::NickServ::Alist::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + int chan_count = 0; + + for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) + { + ChannelInfo *ci = it->second; + + if (ci->GetFounder() && ci->GetFounder() == na->nc) + { + ++chan_count; + + replacements["NUMBERS"] = stringify(chan_count); + replacements["CHANNELS"] = (ci->HasFlag(CI_NO_EXPIRE) ? "!" : "") + ci->name; + replacements["ACCESSES"] = "Founder"; + continue; + } + + AccessGroup access = ci->AccessFor(na->nc); + if (access.empty()) + continue; + + ++chan_count; + + replacements["NUMBERS"] = stringify(chan_count); + replacements["CHANNELS"] = (ci->HasFlag(CI_NO_EXPIRE) ? "!" : "") + ci->name; + Anope::string access_str; + for (unsigned i = 0; i < access.size(); ++i) + access_str += ", " + access[i]->Serialize(); + replacements["ACCESSES"] = access_str.substr(2); + } + + TemplateFileServer page("nickserv/alist.html"); + page.Serve(server, page_name, client, message, reply, replacements); +} + diff --git a/modules/extra/webcpanel/pages/nickserv/alist.h b/modules/extra/webcpanel/pages/nickserv/alist.h new file mode 100644 index 000000000..5e4b31724 --- /dev/null +++ b/modules/extra/webcpanel/pages/nickserv/alist.h @@ -0,0 +1,25 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + +namespace NickServ +{ + +class Alist : public WebPanelProtectedPage +{ + public: + Alist(const Anope::string &cat, const Anope::string &u); + + void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + +} + diff --git a/modules/extra/webcpanel/pages/nickserv/cert.cpp b/modules/extra/webcpanel/pages/nickserv/cert.cpp new file mode 100644 index 000000000..e354addca --- /dev/null +++ b/modules/extra/webcpanel/pages/nickserv/cert.cpp @@ -0,0 +1,39 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" + +WebCPanel::NickServ::Cert::Cert(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +void WebCPanel::NickServ::Cert::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + if (message.post_data.count("certfp") > 0) + { + std::vector<Anope::string> params; + params.push_back("ADD"); + params.push_back(message.post_data["certfp"]); + + WebPanel::RunCommand(na->nc->display, na->nc, Config->NickServ, "nickserv/cert", params, replacements); + } + else if (message.get_data.count("del") > 0 && message.get_data.count("mask") > 0) + { + std::vector<Anope::string> params; + params.push_back("DEL"); + params.push_back(message.get_data["mask"]); + + WebPanel::RunCommand(na->nc->display, na->nc, Config->NickServ, "nickserv/cert", params, replacements); + } + + for (unsigned i = 0; i < na->nc->cert.size(); ++i) + replacements["CERTS"] = na->nc->cert[i]; + + TemplateFileServer page("nickserv/cert.html"); + page.Serve(server, page_name, client, message, reply, replacements); +} + diff --git a/modules/extra/webcpanel/pages/nickserv/cert.h b/modules/extra/webcpanel/pages/nickserv/cert.h new file mode 100644 index 000000000..1f9f1b4ad --- /dev/null +++ b/modules/extra/webcpanel/pages/nickserv/cert.h @@ -0,0 +1,25 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + +namespace NickServ +{ + +class Cert : public WebPanelProtectedPage +{ + public: + Cert(const Anope::string &cat, const Anope::string &u); + + void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + +} + diff --git a/modules/extra/webcpanel/pages/nickserv/info.cpp b/modules/extra/webcpanel/pages/nickserv/info.cpp new file mode 100644 index 000000000..7ae07ad28 --- /dev/null +++ b/modules/extra/webcpanel/pages/nickserv/info.cpp @@ -0,0 +1,111 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../webcpanel.h" + +WebCPanel::NickServ::Info::Info(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +{ +} + +void WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) +{ + if (message.post_data.empty() == false) + { + if (message.post_data.count("email") > 0) + { + if (message.post_data["email"] != na->nc->email) + { + if (!message.post_data["email"].empty() && !MailValidate(message.post_data["email"])) + replacements["ERRORS"] = "Invalid email"; + else + { + na->nc->email = message.post_data["email"]; + replacements["MESSAGES"] = "Email updated"; + } + } + } + if (message.post_data.count("greet") > 0) + { + if (message.post_data["greet"].replace_all_cs("+", " ") != na->nc->greet) + { + na->nc->greet = HTTPUtils::URLDecode(message.post_data["greet"]); + replacements["MESSAGES"] = "Greet updated"; + } + } + if (na->nc->HasFlag(NI_AUTOOP) != message.post_data.count("autoop")) + { + if (!na->nc->HasFlag(NI_AUTOOP)) + na->nc->SetFlag(NI_AUTOOP); + else + na->nc->UnsetFlag(NI_AUTOOP); + replacements["MESSAGES"] = "Autoop updated"; + } + if (na->nc->HasFlag(NI_PRIVATE) != message.post_data.count("private")) + { + if (!na->nc->HasFlag(NI_PRIVATE)) + na->nc->SetFlag(NI_PRIVATE); + else + na->nc->UnsetFlag(NI_PRIVATE); + replacements["MESSAGES"] = "Private updated"; + } + if (na->nc->HasFlag(NI_SECURE) != message.post_data.count("secure")) + { + if (!na->nc->HasFlag(NI_SECURE)) + na->nc->SetFlag(NI_SECURE); + else + na->nc->UnsetFlag(NI_SECURE); + replacements["MESSAGES"] = "Secure updated"; + } + if (message.post_data["kill"] == "on" && !na->nc->HasFlag(NI_KILLPROTECT)) + { + na->nc->SetFlag(NI_KILLPROTECT); + na->nc->UnsetFlag(NI_KILL_QUICK); + replacements["MESSAGES"] = "Kill updated"; + } + else if (message.post_data["kill"] == "quick" && !na->nc->HasFlag(NI_KILL_QUICK)) + { + na->nc->UnsetFlag(NI_KILLPROTECT); + na->nc->SetFlag(NI_KILL_QUICK); + replacements["MESSAGES"] = "Kill updated"; + } + else if (message.post_data["kill"] == "off" && (na->nc->HasFlag(NI_KILLPROTECT) || na->nc->HasFlag(NI_KILL_QUICK))) + { + na->nc->UnsetFlag(NI_KILLPROTECT); + na->nc->UnsetFlag(NI_KILL_QUICK); + replacements["MESSAGES"] = "Kill updated"; + } + } + + replacements["DISPLAY"] = HTTPUtils::Escape(na->nc->display); + if (na->nc->email.empty() == false) + replacements["EMAIL"] = HTTPUtils::Escape(na->nc->email); + replacements["TIME_REGISTERED"] = do_strftime(na->time_registered, na->nc); + if (na->HasVhost()) + { + if (na->GetVhostIdent().empty() == false) + replacements["VHOST"] = na->GetVhostIdent() + "@" + na->GetVhostHost(); + else + replacements["VHOST"] = na->GetVhostHost(); + } + replacements["GREET"] = HTTPUtils::Escape(na->nc->greet); + if (na->nc->HasFlag(NI_AUTOOP)) + replacements["AUTOOP"]; + if (na->nc->HasFlag(NI_PRIVATE)) + replacements["PRIVATE"]; + if (na->nc->HasFlag(NI_SECURE)) + replacements["SECURE"]; + if (na->nc->HasFlag(NI_KILLPROTECT)) + replacements["KILL_ON"]; + if (na->nc->HasFlag(NI_KILL_QUICK)) + replacements["KILL_QUICK"]; + if (!na->nc->HasFlag(NI_KILLPROTECT) && !na->nc->HasFlag(NI_KILL_QUICK)) + replacements["KILL_OFF"]; + + TemplateFileServer page("nickserv/info.html"); + page.Serve(server, page_name, client, message, reply, replacements); +} + diff --git a/modules/extra/webcpanel/pages/nickserv/info.h b/modules/extra/webcpanel/pages/nickserv/info.h new file mode 100644 index 000000000..05fc981ac --- /dev/null +++ b/modules/extra/webcpanel/pages/nickserv/info.h @@ -0,0 +1,25 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +namespace WebCPanel +{ + +namespace NickServ +{ + +class Info : public WebPanelProtectedPage +{ + public: + Info(const Anope::string &cat, const Anope::string &u); + + void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) anope_override; +}; + +} + +} + diff --git a/modules/extra/webcpanel/pages/register.cpp b/modules/extra/webcpanel/pages/register.cpp new file mode 100644 index 000000000..84efb3fc0 --- /dev/null +++ b/modules/extra/webcpanel/pages/register.cpp @@ -0,0 +1,23 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../webcpanel.h" + +void WebCPanel::Register::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) +{ + TemplateFileServer::Replacements replacements; + + replacements["TITLE"] = page_title; + + if (!Config->NSForceEmail) + replacements["EMAIL_TYPE"] = "hidden"; + + TemplateFileServer page("register.html"); + + page.Serve(server, page_name, client, message, reply, replacements); +} + diff --git a/modules/extra/webcpanel/pages/register.h b/modules/extra/webcpanel/pages/register.h new file mode 100644 index 000000000..0651bfba6 --- /dev/null +++ b/modules/extra/webcpanel/pages/register.h @@ -0,0 +1,22 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../../httpd.h" + +namespace WebCPanel +{ + +class Register : public WebPanelPage +{ + public: + Register(const Anope::string &u) : WebPanelPage(u) { } + + void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override; +}; + +} + diff --git a/modules/extra/webcpanel/static_fileserver.cpp b/modules/extra/webcpanel/static_fileserver.cpp new file mode 100644 index 000000000..3f51c8b40 --- /dev/null +++ b/modules/extra/webcpanel/static_fileserver.cpp @@ -0,0 +1,42 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "webcpanel.h" +#include <fstream> +#include <errno.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +StaticFileServer::StaticFileServer(const Anope::string &f_n, const Anope::string &u, const Anope::string &c_t) : HTTPPage(u, c_t), file_name(f_n) +{ +} + +void StaticFileServer::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) +{ + int fd = open((template_base + "/" + this->file_name).c_str(), O_RDONLY); + if (fd < 0) + { + Log(LOG_NORMAL, "httpd") << "Error serving file " << page_name << " (" << (template_base + "/" + this->file_name) << "): " << strerror(errno); + + client->SendError(HTTP_PAGE_NOT_FOUND, "Page not found"); + return; + } + + reply.content_type = this->GetContentType(); + reply.headers["Cache-Control"] = "public"; + + int i; + char buffer[BUFSIZE]; + while ((i = read(fd, buffer, sizeof(buffer))) > 0) + reply.Write(buffer, i); + + close(fd); +} + diff --git a/modules/extra/webcpanel/static_fileserver.h b/modules/extra/webcpanel/static_fileserver.h new file mode 100644 index 000000000..17fa7d6b2 --- /dev/null +++ b/modules/extra/webcpanel/static_fileserver.h @@ -0,0 +1,19 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../httpd.h" + +/* A basic file server. Used for serving static content on disk. */ +class StaticFileServer : public HTTPPage +{ + Anope::string file_name; + public: + StaticFileServer(const Anope::string &f_n, const Anope::string &u, const Anope::string &c_t); + + void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) anope_override; +}; + diff --git a/modules/extra/webcpanel/template_fileserver.cpp b/modules/extra/webcpanel/template_fileserver.cpp new file mode 100644 index 000000000..d3a974391 --- /dev/null +++ b/modules/extra/webcpanel/template_fileserver.cpp @@ -0,0 +1,244 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "webcpanel.h" +#include <fstream> +#include <stack> +#include <errno.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +struct ForLoop +{ + static std::vector<ForLoop> Stack; + + size_t start; /* Index of start of this loop */ + std::vector<Anope::string> vars; /* User defined variables */ + typedef std::pair<TemplateFileServer::Replacements::iterator, TemplateFileServer::Replacements::iterator> range; + std::vector<range> ranges; /* iterator ranges for each variable */ + + ForLoop(size_t s, TemplateFileServer::Replacements &r, const std::vector<Anope::string> &v, const std::vector<Anope::string> &r_names) : start(s), vars(v) + { + for (unsigned i = 0; i < r_names.size(); ++i) + ranges.push_back(r.equal_range(r_names[i])); + } + + void increment(const TemplateFileServer::Replacements &r) + { + for (unsigned i = 0; i < ranges.size(); ++i) + { + range &ra = ranges[i]; + + if (ra.first != r.end() && ra.first != ra.second) + ++ra.first; + } + } + + bool finished(const TemplateFileServer::Replacements &r) const + { + for (unsigned i = 0; i < ranges.size(); ++i) + { + const range &ra = ranges[i]; + + if (ra.first != r.end() && ra.first != ra.second) + return false; + } + + return true; + } +}; +std::vector<ForLoop> ForLoop::Stack; + +std::stack<bool> IfStack; + +static Anope::string FindReplacement(const TemplateFileServer::Replacements &r, const Anope::string &key) +{ + /* Search first through for loop stack then global replacements */ + for (unsigned i = ForLoop::Stack.size(); i > 0; --i) + { + ForLoop &fl = ForLoop::Stack[i - 1]; + + for (unsigned j = 0; j < fl.vars.size(); ++j) + { + const Anope::string &var_name = fl.vars[j]; + + if (key == var_name) + { + const ForLoop::range &range = fl.ranges[j]; + + if (range.first != r.end() && range.first != range.second) + { + return range.first->second; + } + } + } + } + + TemplateFileServer::Replacements::const_iterator it = r.find(key); + if (it != r.end()) + return it->second; + return ""; +} + +TemplateFileServer::TemplateFileServer(const Anope::string &f_n) : file_name(f_n) +{ +} + +void TemplateFileServer::Serve(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, Replacements &r) +{ + int fd = open((template_base + "/" + this->file_name).c_str(), O_RDONLY); + if (fd < 0) + { + Log(LOG_NORMAL, "httpd") << "Error serving file " << page_name << " (" << (template_base + "/" + this->file_name) << "): " << strerror(errno); + + client->SendError(HTTP_PAGE_NOT_FOUND, "Page not found"); + return; + } + + Anope::string buf; + + int i; + char buffer[BUFSIZE]; + while ((i = read(fd, buffer, sizeof(buffer) - 1)) > 0) + { + buffer[i] = 0; + buf += buffer; + } + + close(fd); + + Anope::string finished; + + for (unsigned j = 0; j < buf.length(); ++j) + { + if (buf[j] == '{') + { + size_t f = buf.substr(j).find('}'); + if (f == Anope::string::npos) + break; + const Anope::string &content = buf.substr(j + 1, f - 1); + + if (content.find("IF ") == 0) + { + std::vector<Anope::string> tokens = BuildStringVector(content); + + if (tokens.size() == 4 && tokens[1] == "EQ") + { + Anope::string first = FindReplacement(r, tokens[2]), second = FindReplacement(r, tokens[3]); + if (first.empty()) + first = tokens[2]; + if (second.empty()) + second = tokens[3]; + + IfStack.push(first == second); + } + else if (tokens.size() == 3 && tokens[1] == "EXISTS") + IfStack.push(r.count(tokens[2]) > 0); + else + Log() << "Invalid IF in web template " << this->file_name; + } + else if (content == "ELSE") + { + if (IfStack.empty()) + Log() << "Invalid ELSE with no stack in web template" << this->file_name; + else + { + bool old = IfStack.top(); + IfStack.pop(); // Pop off previous if() + IfStack.push(!old); // Push back the opposite of what was popped + } + } + else if (content == "END IF") + { + if (IfStack.empty()) + Log() << "END IF with empty stack?"; + else + IfStack.pop(); + } + else if (content.find("FOR ") == 0) + { + std::vector<Anope::string> tokens = BuildStringVector(content); + if (tokens.size() != 4 || tokens[2] != "IN") + Log() << "Invalid FOR in web template " << this->file_name; + else + { + std::vector<Anope::string> temp_variables = BuildStringVector(tokens[1], ','), + real_variables = BuildStringVector(tokens[3], ','); + if (temp_variables.size() != real_variables.size()) + Log() << "Invalid FOR in web template " << this->file_name << " variable mismatch"; + else + ForLoop::Stack.push_back(ForLoop(j + f, r, temp_variables, real_variables)); + } + } + else if (content == "END FOR") + { + if (ForLoop::Stack.empty()) + Log() << "END FOR with empty stack?"; + else + { + ForLoop &fl = ForLoop::Stack.back(); + if (fl.finished(r)) + ForLoop::Stack.pop_back(); + else + { + fl.increment(r); + if (fl.finished(r)) + ForLoop::Stack.pop_back(); + else + { + j = fl.start; // Move pointer back to start of the loop + continue; // To prevent skipping over this block which doesn't exist anymore + } + } + } + } + else if (content.find("INCLUDE ") == 0) + { + std::vector<Anope::string> tokens = BuildStringVector(content); + if (tokens.size() != 2) + Log() << "Invalid INCLUDE in web template " << this->file_name; + else + { + reply.Write(finished); // Write out what we have currently so we insert this files contents here + finished.clear(); + + TemplateFileServer tfs(tokens[1]); + tfs.Serve(server, page_name, client, message, reply, r); + } + } + else + { + // If the if stack is empty or we are in a true statement + bool ifok = IfStack.empty() || IfStack.top(); + bool forok = ForLoop::Stack.empty() || !ForLoop::Stack.back().finished(r); + + if (ifok && forok) + { + const Anope::string &replacement = FindReplacement(r, content.substr(0, f - 1)); + finished += replacement; + } + } + + j += f; // Skip over this whole block + } + else + { + // If the if stack is empty or we are in a true statement + bool ifok = IfStack.empty() || IfStack.top(); + bool forok = ForLoop::Stack.empty() || !ForLoop::Stack.back().finished(r); + + if (ifok && forok) + finished += buf[j]; + } + } + + reply.Write(finished); +} + diff --git a/modules/extra/webcpanel/template_fileserver.h b/modules/extra/webcpanel/template_fileserver.h new file mode 100644 index 000000000..58d6a4872 --- /dev/null +++ b/modules/extra/webcpanel/template_fileserver.h @@ -0,0 +1,27 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "../httpd.h" + +/* A basic file server. Used for serving non-static non-binary content on disk. */ +class TemplateFileServer +{ + Anope::string file_name; + public: + struct Replacements : std::multimap<Anope::string, Anope::string> + { + Anope::string& operator[](const Anope::string &key) + { + return insert(std::make_pair(key, ""))->second; + } + }; + + TemplateFileServer(const Anope::string &f_n); + + void Serve(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, Replacements &); +}; + diff --git a/modules/extra/webcpanel/templates/default/chanserv/access.html b/modules/extra/webcpanel/templates/default/chanserv/access.html new file mode 100644 index 000000000..13c0ba82b --- /dev/null +++ b/modules/extra/webcpanel/templates/default/chanserv/access.html @@ -0,0 +1,52 @@ +{INCLUDE header.html} + {FOR M IN MESSAGES} + {M}<br/> + {END FOR} + {IF EXISTS ACCESSES} + <b>Access List</b></br> + <table width="100%" height="100%"> + <tr> + <th>Mask</th> + <th>Access</th> + <th>Creator</th> + </tr> + {FOR MASK,ACCESS,CREATOR,ACCESS_CHANGE IN MASKS,ACCESSES,CREATORS,ACCESS_CHANGES} + <tr> + <td>{MASK}</td> + <td>{ACCESS}</td> + <td>{CREATOR}</td> + {IF EQ ACCESS_CHANGE YES} + <td><a href="/chanserv/access?channel={ESCAPED_CHANNEL}&mask={MASK}&del=1">Delete</a></td> + {END IF} + </tr> + {END FOR} + </table> + {ELSE} + <b>Access list is empty.</b> + {END IF} + + <br/><br/> + + <b>Add an access entry</b><br/> + <form method="post" action="/chanserv/access?channel={ESCAPED_CHANNEL}"> + <table width="100%" height="100%"> + <tr> + <th>Mask</th> + <th>Access</th> + <th>Provider</th> + </tr> + <tr> + <td><input type="text" name="mask"></td> + <td><input type="text" name="access"></td> + <td> + <select name="provider"> + {FOR PROVIDER IN PROVIDERS} + <option value="{PROVIDER}">{PROVIDER}</option> + {END FOR} + </select> + </td> + </tr> + </table> + <input type="submit" value="Add"> + </form> +{INCLUDE footer.html} diff --git a/modules/extra/webcpanel/templates/default/chanserv/akick.html b/modules/extra/webcpanel/templates/default/chanserv/akick.html new file mode 100644 index 000000000..23c1c1efd --- /dev/null +++ b/modules/extra/webcpanel/templates/default/chanserv/akick.html @@ -0,0 +1,42 @@ +{INCLUDE header.html} + {FOR M IN MESSAGES} + {M}<br/> + {END FOR} + {IF EXISTS MASKS} + <b>Akick List</b></br> + <table width="100%" height="100%"> + <tr> + <th>Mask</th> + <th>Creator</th> + <th>Reason</th> + </tr> + {FOR MASK,CREATOR,REASON IN MASKS,CREATORS,REASONS} + <tr> + <td>{MASK}</td> + <td>{CREATOR}</td> + <td>{REASON}</td> + <td><a href="/chanserv/akick?channel={ESCAPED_CHANNEL}&mask={MASK}&del=1">Delete</a></td> + </tr> + {END FOR} + </table> + {ELSE} + <b>Akick list is empty.</b> + {END IF} + + <br/><br/> + + <b>Add an akick entry</b><br/> + <form method="post" action="/chanserv/akick?channel={ESCAPED_CHANNEL}"> + <table width="100%" height="100%"> + <tr> + <th>Mask</th> + <th>Reason</th> + </tr> + <tr> + <td><input type="text" name="mask"></td> + <td><input type="text" name="access"></td> + </tr> + </table> + <input type="submit" value="Add"> + </form> +{INCLUDE footer.html} diff --git a/modules/extra/webcpanel/templates/default/chanserv/main.html b/modules/extra/webcpanel/templates/default/chanserv/main.html new file mode 100644 index 000000000..99fec7d75 --- /dev/null +++ b/modules/extra/webcpanel/templates/default/chanserv/main.html @@ -0,0 +1,6 @@ +{INCLUDE header.html} + <b>Channels you have access in:</b><br/> + {FOR CH,ECH IN CHANNEL_NAMES,ESCAPED_CHANNEL_NAMES} + <a href="/chanserv/set?channel={ECH}">{CH}</a></br> + {END FOR} +{INCLUDE footer.html} diff --git a/modules/extra/webcpanel/templates/default/chanserv/set.html b/modules/extra/webcpanel/templates/default/chanserv/set.html new file mode 100644 index 000000000..ec2a33929 --- /dev/null +++ b/modules/extra/webcpanel/templates/default/chanserv/set.html @@ -0,0 +1,100 @@ +{INCLUDE header.html} + {FOR M IN MESSAGES} + {M}<br/> + {END FOR} + <form method="post" action="/chanserv/set?channel={CHANNEL_ESCAPED}"> + <table width="100%" height="100%"> + <tr> + <td>Channel Name</td> + <td>{CHANNEL}</td> + </tr> + {IF EXISTS FOUNDER} + <tr> + <td>Founder</td> + <td>{FOUNDER}</td> + </tr> + {END IF} + {IF EXISTS SUCCESSOR} + <tr> + <td>Succsesor</td> + <td>{SUCCESSOR}</td> + </tr> + {END IF} + <tr> + <td>Time registered</td> + <td>{TIME_REGISTERED</td> + </tr> + <tr> + <td>Last used</td> + <td>{LAST_USED}</td> + </tr> + {IF EXISTS LAST_TOPIC} + <tr> + <td>Last topic</td> + <td>{LAST_TOPIC}</td> + </tr> + <tr> + <td>Set by</td> + <td>{LAST_TOPIC_SETTER}</td> + </tr> + {END IF} + <tr> + <td>Keep topic</td> + {IF EXISTS KEEPTOPIC} + <td><input type="checkbox" name="keeptopic" value="on" checked></td> + {ELSE} + <td><input type="checkbox" name="keeptopic" value="on"></td> + {END IF} + </tr> + <tr> + <td>Peace</td> + {IF EXISTS PEACE} + <td><input type="checkbox" name="peace" value="on" checked></td> + {ELSE} + <td><input type="checkbox" name="peace" value="on"></td> + {END IF} + </tr> + <tr> + <td>Private</td> + {IF EXISTS PRIVATE} + <td><input type="checkbox" name="private" value="on" checked></td> + {ELSE} + <td><input type="checkbox" name="private" value="on"></td> + {END IF} + </tr> + <tr> + <td>Restricted</td> + {IF EXISTS RESTRICTED} + <td><input type="checkbox" name="restricted" value="on" checked></td> + {ELSE} + <td><input type="checkbox" name="restricted" value="on"></td> + {END IF} + </tr> + <tr> + <td>Secure</td> + {IF EXISTS SECURE} + <td><input type="checkbox" name="secure" value="on" checked></td> + {ELSE} + <td><input type="checkbox" name="secure" value="on"></td> + {END IF} + </tr> + <tr> + <td>Secure Ops</td> + {IF EXISTS SECUREOPS} + <td><input type="checkbox" name="secureops" value="on" checked></td> + {ELSE} + <td><input type="checkbox" name="secureops" value="on"></td> + {END IF} + </tr> + <tr> + <td>Topic Lock</td> + {IF EXISTS TOPICLOCK} + <td><input type="checkbox" name="topiclock" value="on" checked></td> + {ELSE} + <td><input type="checkbox" name="topiclock" value="on"></td> + {END IF} + </tr> + </table> + <input type="submit" value="Save"> + </form> +{INCLUDE footer.html} diff --git a/modules/extra/webcpanel/templates/default/confirm.html b/modules/extra/webcpanel/templates/default/confirm.html new file mode 100644 index 000000000..918ccd971 --- /dev/null +++ b/modules/extra/webcpanel/templates/default/confirm.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<html> +<head> + <link href="/static/style.css" media="screen" rel="stylesheet" type="text/css" /> + <title>{TITLE}</title> +</head> +<body> + <div class="master"> + <div class="header"> + <div class="loggedinas"><a href="/">Home</a></div> + </div> + <table width="100%" height="100%"> + <tr> + <td> + <center> + <img src="static/logo.png"/> + <br/> + {FOR M IN MESSAGES} + {M}<br/> + {END FOR} + </center> + </td> + </tr> + </table> + </div> + <div class="footer"> + Anope IRC Services - © 2012 Anope Team - <a href="http://anope.org">http://anope.org</a> + </div> +</body> +</html> diff --git a/modules/extra/webcpanel/templates/default/favicon.ico b/modules/extra/webcpanel/templates/default/favicon.ico Binary files differnew file mode 100644 index 000000000..be735614a --- /dev/null +++ b/modules/extra/webcpanel/templates/default/favicon.ico diff --git a/modules/extra/webcpanel/templates/default/footer.html b/modules/extra/webcpanel/templates/default/footer.html new file mode 100644 index 000000000..65d23402a --- /dev/null +++ b/modules/extra/webcpanel/templates/default/footer.html @@ -0,0 +1,7 @@ + </div> + </div> + <div class="footer"> + Anope IRC Services - © 2012 Anope Team - <a href="http://anope.org">http://anope.org</a> + </div> +</body> +</html> diff --git a/modules/extra/webcpanel/templates/default/header.html b/modules/extra/webcpanel/templates/default/header.html new file mode 100644 index 000000000..38f367acc --- /dev/null +++ b/modules/extra/webcpanel/templates/default/header.html @@ -0,0 +1,24 @@ +<!DOCTYPE html> +<html> +<head> + <link href="/static/style.css" media="screen" rel="stylesheet" type="text/css" /> + <title>{TITLE}</title> +</head> +<body> + <div class="master"> + <div class="header"> + <ul id="button"> + {FOR CATEGORY_URL,CATEGORY_NAME IN CATEGORY_URLS,CATEGORY_NAMES} + <li><a href="{CATEGORY_URL}">{CATEGORY_NAME}</a></li> + {END FOR} + </ul> + <div class="loggedinas">Logged in as {ACCOUNT} <a href="/logout">(Logout)</a></div> + </div> + <div class="sidebar"> + <ul class="sidenav"> + {FOR SUBCATEGORY_URL,SUBCATEGORY_GET,SUBCATEGORY_NAME IN SUBCATEGORY_URLS,SUBCATEGORY_GETS,SUBCATEGORY_NAMES} + <li><a href="{SUBCATEGORY_URL}{SUBCATEGORY_GET}">{SUBCATEGORY_NAME}</a></li> + {END FOR} + </ul> + </div> + <div class="content"> diff --git a/modules/extra/webcpanel/templates/default/login.html b/modules/extra/webcpanel/templates/default/login.html new file mode 100644 index 000000000..7aa54aa9c --- /dev/null +++ b/modules/extra/webcpanel/templates/default/login.html @@ -0,0 +1,47 @@ +<!DOCTYPE html> +<html> +<head> + <link href="/static/style.css" media="screen" rel="stylesheet" type="text/css" /> + <title>{TITLE}</title> +</head> +<body> + <div class="master"> + <div class="header"> + <div class="loggedinas"><a href="/register">Register</a></div> + </div> + <table width="100%" height="100%"> + <tr> + <td> + <center> + <img src="static/logo.png"/> + <br> + <h2>Login</h2> + {INVALID_LOGIN}<br> + Login to continue. + <br> + <form action="/" method="post"> + <table> + <tr> + <td><div align="right">Username:</div></td> + <td><div align="left"><input name="username"/></div></td> + </tr> + <tr> + <td><div align="right">Password:</div></td> + <td><div align="left"><input name="password" type="password"/></div></td> + </tr> + <tr> + <td></td> + <td><div align="left"><input type="submit" value="Login"/></div></td> + </tr> + </table> + </form> + </center> + </td> + </tr> + </table> + </div> + <div class="footer"> + Anope IRC Services - © 2012 Anope Team - <a href="http://anope.org">http://anope.org</a> + </div> +</body> +</html> diff --git a/modules/extra/webcpanel/templates/default/logo.png b/modules/extra/webcpanel/templates/default/logo.png Binary files differnew file mode 100644 index 000000000..1ab5546c6 --- /dev/null +++ b/modules/extra/webcpanel/templates/default/logo.png diff --git a/modules/extra/webcpanel/templates/default/memoserv/memos.html b/modules/extra/webcpanel/templates/default/memoserv/memos.html new file mode 100644 index 000000000..559efd35b --- /dev/null +++ b/modules/extra/webcpanel/templates/default/memoserv/memos.html @@ -0,0 +1,50 @@ +{INCLUDE header.html} + <b>Channels you have access in:</b><br/> + {FOR CH,ECH IN CHANNEL_NAMES,ESCAPED_CHANNEL_NAMES} + <a href="/memoserv/memos?channel={ECH}">{CH}</a> + {END FOR} + <br/><br/> + {FOR M IN MESSAGES} + {M}</br> + {END FOR} + <br/> + {IF EXISTS NUMBER} + <b>Memos List:</b> + <table width="100%" height="100%"> + <tr> + <th>Number</th> + <th>Sender</th> + <th>Time/Message</th> + </tr> + {FOR I,S,T,TXT,U IN NUMBER,SENDER,TIME,TEXT,UNREAD} + <tr> + <td>{I}</td> + <td>{S}</td> + <td>{T}</td> + {IF EQ U YES} + <td><a href="/memoserv/memos?channel={ESCAPED_CHANNEL_NAME}&number={I}&read=1">Mark as Read</a></td> + {ELSE} + <td><a href="/memoserv/memos?channel={ESCAPED_CHANNEL_NAME}&number={I}&read=2">Mark as Unread</a></td> + {END IF} + <td><a href="/memoserv/memos?channel={ESCAPED_CHANNEL_NAME}&number={I}&del=1">Delete</a></td> + + </tr> + <tr> + <td></td><td></td> + <td>{TXT}</td> + </tr> + {END FOR} + </table> + {ELSE} + <b>No memos to show.</b> + {END IF} + + <br/><br/> + + <b>Send a new Memo</b> + <form method="post" action="/memoserv/memos?channel={ESCAPED_CHANNEL}"> + Receiver: <input type="text" name="receiver"> + Message: <input type="text" name="message"> + <input type="submit" value="Send"> + </form> +{INCLUDE footer.html} diff --git a/modules/extra/webcpanel/templates/default/nickserv/access.html b/modules/extra/webcpanel/templates/default/nickserv/access.html new file mode 100644 index 000000000..9948c3694 --- /dev/null +++ b/modules/extra/webcpanel/templates/default/nickserv/access.html @@ -0,0 +1,24 @@ +{INCLUDE header.html} + {FOR M IN MESSAGES} + {M}</br> + {END FOR} + {IF EXISTS ACCESS} + <b>Your access list:</b> + <table width="100%" height="100%"> + {FOR A IN ACCESS} + <tr> + <td>{A}</td> + <td><a href="/nickserv/access?mask={A}&del=1">Delete</a></td> + </tr> + {END FOR} + </table> + {ELSE} + <b>Your access list is empty.</b> + {END IF} + <br/><br/> + <b>Add an access entry:</b> + <form method="post" action="/nickserv/access"> + <input name="access"> + <input type="submit" value="Add"> + </form> +{INCLUDE footer.html} diff --git a/modules/extra/webcpanel/templates/default/nickserv/alist.html b/modules/extra/webcpanel/templates/default/nickserv/alist.html new file mode 100644 index 000000000..e36143458 --- /dev/null +++ b/modules/extra/webcpanel/templates/default/nickserv/alist.html @@ -0,0 +1,16 @@ +{INCLUDE header.html} + <table> + <tr> + <th>Number</th> + <th>Channel</th> + <th>Access</th> + </tr> + {FOR N,C,A IN NUMBERS,CHANNELS,ACCESSES} + <tr> + <td>{N}</td> + <td>{C}</td> + <td>{A}</td> + </tr> + {END FOR} + </table> +{INCLUDE footer.html} diff --git a/modules/extra/webcpanel/templates/default/nickserv/cert.html b/modules/extra/webcpanel/templates/default/nickserv/cert.html new file mode 100644 index 000000000..31f12b883 --- /dev/null +++ b/modules/extra/webcpanel/templates/default/nickserv/cert.html @@ -0,0 +1,19 @@ +{INCLUDE header.html} + {FOR M IN MESSAGES} + {M}</br> + {END FOR} + <b>Your certificate finrgerprints:</b> + <table width="100%" height="100%"> + {FOR CERT IN CERTS} + <tr> + <td>{CERT}</td> + <td><a href="/nickserv/cert?mask={CERT}&del=1">Delete</a></td> + </tr> + {END FOR} + </table> + <b>Add an certificate fingerprint</b> + <form method="post" action="/nickserv/cert"> + <input name="certfp"> + <input type="submit" value="Add"> + </form> +{INCLUDE footer.html} diff --git a/modules/extra/webcpanel/templates/default/nickserv/info.html b/modules/extra/webcpanel/templates/default/nickserv/info.html new file mode 100644 index 000000000..1dd051364 --- /dev/null +++ b/modules/extra/webcpanel/templates/default/nickserv/info.html @@ -0,0 +1,82 @@ +{INCLUDE header.html} + {FOR M IN ERRORS} + {M}<br/> + {END FOR} + {FOR M IN MESSAGES} + {M}<br/> + {END FOR} + <b>Your account information:</b> + <form method="post" action="/nickserv/info"> + <table width="100%" height="100%"> + <tr> + <td>Account:</td> + <td>{DISPLAY}</td> + </tr> + {IF EXISTS EMAIL} + <tr> + <td>EMail</td> + <td>{EMAIL}</td> + </tr> + {END IF} + <tr> + <td>Time registered</td> + <td>{TIME_REGISTERED}</td> + </tr> + {IF EXISTS VHOST} + <tr> + <td>Vhost</td> + <td>{VHOST}</td> + </tr> + {END IF} + <tr> + <td>Greet</td> + <td><input name="greet" value="{GREET}"></td> + </tr> + <tr> + <td>Auto op</td> + {IF EXISTS AUTOOP} + <td><input type="checkbox" name="autoop" value="on" checked></td> + {ELSE} + <td><input type="checkbox" name="autoop" value="on"></td> + {END IF} + </tr> + <tr> + <td>Private</td> + {IF EXISTS PRIVATE} + <td><input type="checkbox" name="private" value="on" checked></td> + {ELSE} + <td><input type="checkbox" name="private" value="on"></td> + {END IF} + </tr> + <tr> + <td>Secure</td> + {IF EXISTS SECURE} + <td><input type="checkbox" name="secure" value="on" checked></td> + {ELSE} + <td><input type="checkbox" name="secure" value="on"></td> + {END IF} + </tr> + <tr> + <td>Kill</td> + <td><select name="kill"> + {IF EXISTS KILL_ON} + <option value="on" selected>On</option> + {ELSE} + <option value="on">On</option> + {END IF} + {IF EXISTS KILL_QUICK} + <option value="quick" selected>Quick</option> + {ELSE} + <option value="quick">Quick</option> + {END IF} + {IF EXISTS KILL_OFF} + <option value="off" selected>Off</option> + {ELSE} + <option value="off">Off</option> + {END IF} + </select></td> + </tr> + </table> + <input type="submit" value="Save"> + </form> +{INCLUDE footer.html} diff --git a/modules/extra/webcpanel/templates/default/register.html b/modules/extra/webcpanel/templates/default/register.html new file mode 100644 index 000000000..8f6a5296a --- /dev/null +++ b/modules/extra/webcpanel/templates/default/register.html @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<html> +<head> + <link href="/static/style.css" media="screen" rel="stylesheet" type="text/css" /> + <title>{TITLE}</title> +</head> +<body> + <div class="master"> + <div class="header"> + <div class="loggedinas"><a href="/">Home</a></div> + </div> + <table width="100%" height="100%"> + <tr> + <td> + <center> + <img src="static/logo.png"/> + {MESSAGES} + <br> + <h2>Register</h2> + <br> + Fill out the following form to register. + <form action="/confirm" method="post"> + <table> + <tr> + <td><div align="right">Username:</div></td> + <td><div align="left"><input name="username"/></div></td> + </tr> + <tr> + <td><div align="right">Password:</div></td> + <td><div align="left"><input name="password" type="password"/></div></td> + </tr> + <tr> + <td><div align="right">Email</div></td> + <td><div align="left"><input type="{EMAIL_TYPE}" name="email"></div></td> + </tr> + <tr> + <td></td> + <td><div align="left"><input type="submit" value="Register"/></div></td> + </tr> + </table> + </form> + </center> + </td> + </tr> + </table> + </div> + <div class="footer"> + Anope IRC Services - © 2012 Anope Team - <a href="http://anope.org">http://anope.org</a> + </div> +</body> +</html> diff --git a/modules/extra/webcpanel/templates/default/style.css b/modules/extra/webcpanel/templates/default/style.css new file mode 100644 index 000000000..78c044995 --- /dev/null +++ b/modules/extra/webcpanel/templates/default/style.css @@ -0,0 +1,97 @@ +html {
+font-family: 'Cabin', Helvetica, Arial, sans-serif;
+}
+body {
+ overflow:hidden;
+}
+.master {
+ margin-left:0px;
+ margin-right:0px;
+ height:100%;
+ background: #FFF;
+ border-width: 1px;
+ border-style: solid;
+ overflow: hidden;
+}
+.header {
+ height: 33px;
+ padding-left: 5px;
+ width: auto;
+ background: #EEE;
+ border-width: 1px;
+ border-bottom-style: solid;
+}
+.sidebar {
+ width: 185px;
+ background: #EEE;
+ height: 500px;
+ border-width: 1px;
+ border-right-style: solid;
+ padding-top:15px;
+ padding-left:15px;
+}
+
+.loggedinas {
+ right:15px;
+ top:15px;
+ position:absolute;
+}
+
+#button {
+ padding: 0;
+ height:30px;
+ margin: 0px;
+ padding-bottom: 2px;
+}
+#button li {
+ display: inline;
+}
+
+#button li a {
+ font-family: Arial;
+ font-size:11px;
+ text-decoration: none;
+ float:left;
+ padding: 10px;
+ background-color: #EEE;
+ height:13px;
+ color: #000;
+}
+#button li a:hover {
+ background-color: #A8BEE3;
+ padding-bottom:10px;
+}
+#a.current {
+ color:navy;
+}
+
+.content {
+ left:220px;
+ top:50px;
+ position:absolute;
+}
+
+.footer {
+ margin-left:auto;
+ margin-right:auto;
+ text-align:center;
+ height: 30px;
+ width:100%;
+ background: #FFF;
+ overflow: hidden;
+}
+
+.sidenav {
+ list-style-type: none;
+ background: #EEE
+}
+
+.sidenav a {
+ color:black;
+ text-decoration:none;
+}
+.sidenav a:hover{
+ color:black;
+ background:#FFF;
+ text-decoration:underline;
+}
diff --git a/modules/extra/webcpanel/webcpanel.cpp b/modules/extra/webcpanel/webcpanel.cpp new file mode 100644 index 000000000..4970845cd --- /dev/null +++ b/modules/extra/webcpanel/webcpanel.cpp @@ -0,0 +1,209 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "webcpanel.h" + +Anope::string provider_name, template_name, template_base, page_title; + +class ModuleWebCPanel : public Module +{ + Panel panel; + + StaticFileServer style_css, logo_png, favicon_ico; + + WebCPanel::Index index; + WebCPanel::Logout logout; + WebCPanel::Register _register; + WebCPanel::Confirm confirm; + + WebCPanel::NickServ::Info nickserv_info; + WebCPanel::NickServ::Cert nickserv_cert; + WebCPanel::NickServ::Access nickserv_access; + WebCPanel::NickServ::Alist nickserv_alist; + + WebCPanel::ChanServ::Info chanserv_info; + WebCPanel::ChanServ::Set chanserv_set; + WebCPanel::ChanServ::Access chanserv_access; + WebCPanel::ChanServ::Akick chanserv_akick; + + WebCPanel::MemoServ::Memos memoserv_memos; + + public: + ModuleWebCPanel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED), + panel(this, "webcpanel"), + style_css("style.css", "/static/style.css", "text/css"), logo_png("logo.png", "/static/logo.png", "image/png"), favicon_ico("favicon.ico", "/favicon.ico", "image/x-icon"), + index("/"), logout("/logout"), _register("/register"), confirm("/confirm"), + nickserv_info(Config->NickServ, "/nickserv/info"), nickserv_cert(Config->NickServ, "/nickserv/cert"), nickserv_access(Config->NickServ, "/nickserv/access"), nickserv_alist(Config->NickServ, "/nickserv/alist"), + chanserv_info(Config->ChanServ, "/chanserv/info"), chanserv_set(Config->ChanServ, "/chanserv/set"), chanserv_access(Config->ChanServ, "/chanserv/access"), chanserv_akick(Config->ChanServ, "/chanserv/akick"), + memoserv_memos(Config->MemoServ, "/memoserv/memos") + { + this->SetAuthor("Anope"); + + ConfigReader reader; + provider_name = reader.ReadValue("webcpanel", "server", "httpd/main", 0); + template_name = reader.ReadValue("webcpanel", "template", "template", 0); + template_base = db_dir + "/modules/webcpanel/templates/" + template_name; + page_title = reader.ReadValue("webcpanel", "title", "Anope IRC Services", 0); + + service_reference<HTTPProvider> provider("HTTPProvider", provider_name); + if (!provider) + throw ModuleException("Unable to find HTTPD provider. Is m_httpd loaded?"); + + provider->RegisterPage(&this->style_css); + provider->RegisterPage(&this->logo_png); + provider->RegisterPage(&this->favicon_ico); + + provider->RegisterPage(&this->index); + provider->RegisterPage(&this->logout); + provider->RegisterPage(&this->_register); + provider->RegisterPage(&this->confirm); + + if (Config->NickServ.empty() == false) + { + Section s; + s.name = Config->NickServ; + + SubSection ss; + ss.name = "Information"; + ss.url = "/nickserv/info"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->nickserv_info); + + if (ircd && ircd->certfp) + { + ss.name = "SSL Certificates"; + ss.url = "/nickserv/cert"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->nickserv_cert); + } + + ss.name = "Access"; + ss.url = "/nickserv/access"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->nickserv_access); + + ss.name = "AList"; + ss.url = "/nickserv/alist"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->nickserv_alist); + + panel.sections.push_back(s); + } + if (Config->ChanServ.empty() == false) + { + Section s; + s.name = Config->ChanServ; + + SubSection ss; + ss.name = "Channels"; + ss.url = "/chanserv/info"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->chanserv_info); + + ss.name = "Settings"; + ss.url = "/chanserv/set"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->chanserv_set); + + ss.name = "Access"; + ss.url = "/chanserv/access"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->chanserv_access); + + ss.name = "Akick"; + ss.url = "/chanserv/akick"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->chanserv_akick); + + panel.sections.push_back(s); + } + + if (Config->MemoServ.empty() == false) + { + Section s; + s.name = Config->MemoServ; + + SubSection ss; + ss.name = "Memos"; + ss.url = "/memoserv/memos"; + s.subsections.push_back(ss); + provider->RegisterPage(&this->memoserv_memos); + + panel.sections.push_back(s); + } + } + + ~ModuleWebCPanel() + { + service_reference<HTTPProvider> provider("HTTPProvider", provider_name); + if (provider) + { + provider->UnregisterPage(&this->style_css); + provider->UnregisterPage(&this->logo_png); + provider->UnregisterPage(&this->favicon_ico); + + provider->UnregisterPage(&this->index); + provider->UnregisterPage(&this->logout); + provider->UnregisterPage(&this->_register); + provider->UnregisterPage(&this->confirm); + + provider->UnregisterPage(&this->nickserv_info); + provider->UnregisterPage(&this->nickserv_cert); + provider->UnregisterPage(&this->nickserv_access); + provider->UnregisterPage(&this->nickserv_alist); + + provider->UnregisterPage(&this->chanserv_info); + provider->UnregisterPage(&this->chanserv_set); + provider->UnregisterPage(&this->chanserv_access); + provider->UnregisterPage(&this->chanserv_akick); + + provider->UnregisterPage(&this->memoserv_memos); + } + } +}; + +namespace WebPanel +{ + void RunCommand(const Anope::string &user, NickCore *nc, const Anope::string &service, const Anope::string &c, const std::vector<Anope::string> ¶ms, TemplateFileServer::Replacements &r) + { + service_reference<Command> cmd("Command", c); + if (!cmd) + { + r["MESSAGSE"] = "Unable to find command " + c; + return; + } + + BotInfo *bi = findbot(service); + if (!bi) + { + if (BotListByNick->empty()) + return; + bi = BotListByNick->begin()->second; // Pick one... + } + + struct MyComandReply : CommandReply + { + TemplateFileServer::Replacements &re; + + MyComandReply(TemplateFileServer::Replacements &_r) : re(_r) { } + + void SendMessage(const BotInfo *source, const Anope::string &msg) anope_override + { + re["MESSAGES"] = msg; + } + } + my_reply(r); + + CommandSource source(user, NULL, nc, &my_reply); + source.owner = bi; + source.service = bi; + + cmd->Execute(source, params); + } +} + +MODULE_INIT(ModuleWebCPanel) diff --git a/modules/extra/webcpanel/webcpanel.h b/modules/extra/webcpanel/webcpanel.h new file mode 100644 index 000000000..79f902b0f --- /dev/null +++ b/modules/extra/webcpanel/webcpanel.h @@ -0,0 +1,163 @@ +/* + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "module.h" +#include "../httpd.h" + +#include "static_fileserver.h" +#include "template_fileserver.h" + +extern Anope::string provider_name, template_name, template_base, page_title; + +struct SubSection +{ + Anope::string name; + Anope::string url; +}; + +struct Section +{ + Anope::string name; + std::vector<SubSection> subsections; +}; + +/* An interface for this webpanel used by other modules */ +class Panel : public Section, public Service +{ + public: + Panel(Module *c, const Anope::string &n) : Service(c, "Panel", n) { } + + std::vector<Section> sections; + + NickAlias *GetNickFromSession(HTTPClient *client, HTTPMessage &msg) + { + if (!client) + return NULL; + + const Anope::string &acc = msg.cookies["account"], &id = msg.cookies["id"]; + + if (acc.empty() || id.empty()) + return NULL; + + NickAlias *na = findnick(acc); + if (na == NULL) + return NULL; + + Anope::string *n_id = na->GetExt<Anope::string *>("webcpanel_id"), *n_ip = na->GetExt<Anope::string *>("webcpanel_ip"); + if (n_id == NULL || n_ip == NULL) + return NULL; + else if (id != *n_id) + return NULL; + else if (client->GetIP() != *n_ip) + return NULL; + else + return na; + } +}; + +class WebPanelPage : public HTTPPage +{ + public: + WebPanelPage(const Anope::string &u, const Anope::string &ct = "text/html") : HTTPPage(u, ct) + { + } + + virtual void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &) = 0; +}; + +class WebPanelProtectedPage : public WebPanelPage +{ + Anope::string category; + + public: + WebPanelProtectedPage(const Anope::string &cat, const Anope::string &u, const Anope::string &ct = "text/html") : WebPanelPage(u, ct), category(cat) + { + } + + void OnRequest(HTTPProvider *provider, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) anope_override anope_final + { + service_reference<Panel> panel("Panel", "webcpanel"); + NickAlias *na; + + if (!panel || !(na = panel->GetNickFromSession(client, message))) + { + return; // Access denied + } + + TemplateFileServer::Replacements replacements; + + replacements["TITLE"] = page_title; + replacements["ACCOUNT"] = na->nc->display; + + Anope::string sections, get; + + for (std::map<Anope::string, Anope::string>::iterator it = message.get_data.begin(), it_end = message.get_data.end(); it != it_end; ++it) + if (this->GetData().count(it->first) > 0) + get += "&" + it->first + "=" + HTTPUtils::URLEncode(it->second); + if (get.empty() == false) + get = "?" + get.substr(1); + + Section *ns = NULL; + for (unsigned i = 0; i < panel->sections.size(); ++i) + { + Section& s = panel->sections[i]; + if (s.name == this->category) + ns = &s; + replacements["CATEGORY_URLS"] = s.subsections[0].url; + replacements["CATEGORY_NAMES"] = s.name; + } + + if (ns) + { + sections = ""; + for (unsigned i = 0; i < ns->subsections.size(); ++i) + { + SubSection& ss = ns->subsections[i]; + replacements["SUBCATEGORY_URLS"] = ss.url; + replacements["SUBCATEGORY_GETS"] = get; + replacements["SUBCATEGORY_NAMES"] = ss.name; + } + } + + this->OnRequest(provider, page_name, client, message, reply, na, replacements); + } + + virtual void OnRequest(HTTPProvider *, const Anope::string &, HTTPClient *, HTTPMessage &, HTTPReply &, NickAlias *, TemplateFileServer::Replacements &) = 0; + + /* What get data should be appended to links in the navbar */ + virtual std::set<Anope::string> GetData() { return std::set<Anope::string>(); } +}; + +namespace WebPanel +{ + /** Run a command + * @param User name to run command as, probably nc->display unless nc == NULL + * @param nc Nick core to run command from + * @param service Service for source.owner and source.service + * @param c Command to run (as a service name) + * @param params Command parameters + * @param r Replacements, reply from command goes back into r["MESSAGES"] + */ + extern void RunCommand(const Anope::string &user, NickCore *nc, const Anope::string &service, const Anope::string &c, const std::vector<Anope::string> ¶ms, TemplateFileServer::Replacements &r); +} + +#include "pages/index.h" +#include "pages/logout.h" +#include "pages/register.h" +#include "pages/confirm.h" + +#include "pages/nickserv/info.h" +#include "pages/nickserv/cert.h" +#include "pages/nickserv/access.h" +#include "pages/nickserv/alist.h" + +#include "pages/chanserv/info.h" +#include "pages/chanserv/set.h" +#include "pages/chanserv/access.h" +#include "pages/chanserv/akick.h" + +#include "pages/memoserv/memos.h"
\ No newline at end of file diff --git a/src/access.cpp b/src/access.cpp index 40e53a305..6ff842fd8 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -73,10 +73,21 @@ void PrivilegeManager::ClearPrivileges() AccessProvider::AccessProvider(Module *o, const Anope::string &n) : Service(o, "AccessProvider", n) { + providers.push_back(this); } AccessProvider::~AccessProvider() { + std::list<AccessProvider *>::iterator it = std::find(providers.begin(), providers.end(), this); + if (it != providers.end()) + providers.erase(it); +} + +std::list<AccessProvider *> AccessProvider::providers; + +const std::list<AccessProvider *>& AccessProvider::GetProviders() +{ + return providers; } ChanAccess::ChanAccess(AccessProvider *p) : provider(p) diff --git a/src/bots.cpp b/src/bots.cpp index 85d6e0700..53f9b78c1 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -239,7 +239,6 @@ void BotInfo::OnMessage(User *u, const Anope::string &message) return; CommandSource source(u->nick, u, u->Account(), u); - source.c = NULL; source.owner = this; source.service = this; diff --git a/src/command.cpp b/src/command.cpp index ae01ecda4..21901bd34 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -16,7 +16,8 @@ #include "access.h" #include "regchannel.h" -CommandSource::CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *r) : nick(n), u(user), nc(core), reply(r) +CommandSource::CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *r) : nick(n), u(user), nc(core), reply(r), + c(NULL), owner(NULL), service(NULL) { } @@ -90,7 +91,7 @@ void CommandSource::Reply(const char *message, ...) va_list args; char buf[4096]; // Messages can be really big. - const char *translated_message = translate(this->u, message); + const char *translated_message = translate(this->nc, message); va_start(args, message); vsnprintf(buf, sizeof(buf), translated_message, args); @@ -102,7 +103,7 @@ void CommandSource::Reply(const char *message, ...) void CommandSource::Reply(const Anope::string &message) { - const char *translated_message = translate(this->u, message.c_str()); + const char *translated_message = translate(this->nc, message.c_str()); sepstream sep(translated_message, '\n'); Anope::string tok; diff --git a/src/logger.cpp b/src/logger.cpp index d18b0731e..0624509d2 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -83,7 +83,7 @@ Log::Log(LogType type, const Anope::string &category, const BotInfo *b) : bi(b), this->Sources.push_back(bi->nick); } -Log::Log(LogType type, const CommandSource &source, Command *_c, const ChannelInfo *_ci) : u(source.GetUser()), nc(source.nc), c(_c), chan(NULL), ci(_ci), s(NULL), Type(type) +Log::Log(LogType type, const CommandSource &source, Command *_c, const ChannelInfo *_ci) : nick(source.GetNick()), u(source.GetUser()), nc(source.nc), c(_c), chan(NULL), ci(_ci), s(NULL), Type(type) { if (!c) throw CoreException("Invalid pointers passed to Log::Log"); @@ -210,7 +210,7 @@ Anope::string Log::BuildPrefix() const } case LOG_COMMAND: { - if (!this->c || !(this->u || this->nc)) + if (!this->c) break; buffer += "COMMAND: "; size_t sl = this->c->name.find('/'); @@ -219,6 +219,8 @@ Anope::string Log::BuildPrefix() const buffer += this->u->GetMask() + " used " + cname + " "; else if (this->nc) buffer += this->nc->display + " used " + cname + " "; + else + buffer += this->nick + " used " + cname + " "; if (this->ci) buffer += "on " + this->ci->name + " "; break; diff --git a/src/misc.cpp b/src/misc.cpp index 41f1370a1..ee091c249 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -758,9 +758,9 @@ void Anope::Unhex(const Anope::string &src, Anope::string &dest) { size_t len = src.length(); Anope::string rv; - for (size_t i = 0; i < len; i += 2) + for (size_t i = 0; i + 1 < len; i += 2) { - char h = src[i], l = src[i + 1]; + char h = std::tolower(src[i]), l = std::tolower(src[i + 1]); unsigned char byte = (h >= 'a' ? h - 'a' + 10 : h - '0') << 4; byte += (l >= 'a' ? l - 'a' + 10 : l - '0'); rv += byte; @@ -768,17 +768,12 @@ void Anope::Unhex(const Anope::string &src, Anope::string &dest) dest = rv; } -void Anope::Unhex(const Anope::string &src, char *dest) +void Anope::Unhex(const Anope::string &src, char *dest, size_t sz) { - size_t len = src.length(), destpos = 0; - for (size_t i = 0; i < len; i += 2) - { - char h = src[i], l = src[i + 1]; - unsigned char byte = (h >= 'a' ? h - 'a' + 10 : h - '0') << 4; - byte += (l >= 'a' ? l - 'a' + 10 : l - '0'); - dest[destpos++] = byte; - } - dest[destpos] = 0; + Anope::string d; + Anope::Unhex(src, d); + + strncpy(dest, d.c_str(), sz); } int Anope::LastErrorCode() diff --git a/src/socket_clients.cpp b/src/socket_clients.cpp index 847981510..4d3a1e3ee 100644 --- a/src/socket_clients.cpp +++ b/src/socket_clients.cpp @@ -60,7 +60,7 @@ void ConnectionSocket::OnError(const Anope::string &) { } -ClientSocket::ClientSocket(ListenSocket *ls, const sockaddrs &addr) : Socket(), LS(ls), clientaddr(addr) +ClientSocket::ClientSocket(ListenSocket *ls, const sockaddrs &addr) : LS(ls), clientaddr(addr) { } diff --git a/src/socket_transport.cpp b/src/socket_transport.cpp index b524c6a24..30af95226 100644 --- a/src/socket_transport.cpp +++ b/src/socket_transport.cpp @@ -56,7 +56,7 @@ bool BufferedSocket::ProcessRead() while (stream.GetToken(tbuf)) { tbuf.trim(); - if (!tbuf.empty() && !Read(tbuf)) + if (!Read(tbuf)) return false; } @@ -80,6 +80,12 @@ bool BufferedSocket::Read(const Anope::string &buf) return false; } +void BufferedSocket::Write(const char *buffer, size_t l) +{ + this->WriteBuffer += buffer + Anope::string("\r\n"); + SocketEngine::MarkWritable(this); +} + void BufferedSocket::Write(const char *message, ...) { va_list vi; @@ -89,17 +95,15 @@ void BufferedSocket::Write(const char *message, ...) return; va_start(vi, message); - vsnprintf(tbuffer, sizeof(tbuffer), message, vi); + int len = vsnprintf(tbuffer, sizeof(tbuffer), message, vi); va_end(vi); - Anope::string sbuf = tbuffer; - Write(sbuf); + this->Write(tbuffer, std::min(len, static_cast<int>(sizeof(tbuffer)))); } void BufferedSocket::Write(const Anope::string &message) { - this->WriteBuffer += message + "\r\n"; - SocketEngine::MarkWritable(this); + this->Write(message.c_str(), message.length()); } int BufferedSocket::ReadBufferLen() const @@ -115,14 +119,14 @@ int BufferedSocket::WriteBufferLen() const BinarySocket::DataBlock::DataBlock(const char *b, size_t l) { - this->buf = new char[l]; + this->orig = this->buf = new char[l]; memcpy(this->buf, b, l); this->len = l; } BinarySocket::DataBlock::~DataBlock() { - delete [] this->buf; + delete [] this->orig; } BinarySocket::BinarySocket() @@ -180,6 +184,26 @@ void BinarySocket::Write(const char *buffer, size_t l) SocketEngine::MarkWritable(this); } +void BinarySocket::Write(const char *message, ...) +{ + va_list vi; + char tbuffer[BUFSIZE]; + + if (!message) + return; + + va_start(vi, message); + int len = vsnprintf(tbuffer, sizeof(tbuffer), message, vi); + va_end(vi); + + this->Write(tbuffer, std::min(len, static_cast<int>(sizeof(tbuffer)))); +} + +void BinarySocket::Write(const Anope::string &message) +{ + this->Write(message.c_str(), message.length()); +} + bool BinarySocket::Read(const char *buffer, size_t l) { return true; |