diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/extra/m_httpd.cpp | 64 | ||||
-rw-r--r-- | modules/extra/m_ssl.cpp | 21 | ||||
-rw-r--r-- | modules/extra/webcpanel/pages/chanserv/access.cpp | 2 | ||||
-rw-r--r-- | modules/extra/webcpanel/pages/chanserv/akick.cpp | 2 | ||||
-rw-r--r-- | modules/extra/webcpanel/pages/chanserv/set.cpp | 2 | ||||
-rw-r--r-- | modules/extra/webcpanel/pages/index.cpp | 6 | ||||
-rw-r--r-- | modules/extra/webcpanel/pages/logout.cpp | 2 | ||||
-rw-r--r-- | modules/extra/webcpanel/webcpanel.cpp | 2 | ||||
-rw-r--r-- | modules/extra/webcpanel/webcpanel.h | 3 |
9 files changed, 47 insertions, 57 deletions
diff --git a/modules/extra/m_httpd.cpp b/modules/extra/m_httpd.cpp index 6524a87b5..30e8b6ba9 100644 --- a/modules/extra/m_httpd.cpp +++ b/modules/extra/m_httpd.cpp @@ -45,8 +45,8 @@ class MyHTTPClient : public HTTPClient Reference<HTTPPage> page; Anope::string ip; + Anope::string inbuf; unsigned content_length; - Anope::string post_data; enum { @@ -111,23 +111,25 @@ class MyHTTPClient : public HTTPClient bool Read(const char *buffer, size_t l) anope_override { - Anope::string buf(buffer, l); + inbuf.append(buffer, l); - if (!this->header_done) + for (size_t nl; !this->header_done && (nl = inbuf.find('\n')) != Anope::string::npos;) { - Anope::string token; - sepstream sep(buf, '\n'); - while (sep.GetToken(token) && !token.trim().empty()) + Anope::string token = inbuf.substr(0, nl).trim(); + inbuf = inbuf.substr(nl + 1); + + if (token.empty()) + this->header_done = true; + else this->Read(token); - this->header_done = true; - buf = sep.GetRemaining(); } - this->post_data += buf; + if (!this->header_done) + return true; - if (this->post_data.length() >= this->content_length) + if (this->inbuf.length() >= this->content_length) { - sepstream sep(this->post_data, '&'); + sepstream sep(this->inbuf, '&'); Anope::string token; while (sep.GetToken(token)) @@ -286,7 +288,7 @@ class MyHTTPProvider : public HTTPProvider, public Timer std::list<Reference<MyHTTPClient> > clients; public: - MyHTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, const int t) : Socket(-1, i.find(':') != Anope::string::npos), HTTPProvider(c, n, i, p), Timer(c, 10, Anope::CurTime, true), timeout(t) { } + MyHTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, const int t, bool s) : Socket(-1, i.find(':') != Anope::string::npos), HTTPProvider(c, n, i, p, s), Timer(c, 10, Anope::CurTime, true), timeout(t) { } void Tick(time_t) anope_override { @@ -329,7 +331,7 @@ class MyHTTPProvider : public HTTPProvider, public Timer class HTTPD : public Module { ServiceReference<SSLService> sslref; - std::map<Anope::string, HTTPProvider *> providers; + std::map<Anope::string, MyHTTPProvider *> providers; public: HTTPD(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), sslref("SSLService", "ssl") { @@ -381,19 +383,13 @@ class HTTPD : public Module continue; } - if (ssl && !sslref) - { - Log(this) << "Could not enable SSL, is m_ssl loaded?"; - ssl = false; - } - - HTTPProvider *p; + MyHTTPProvider *p; if (this->providers.count(hname) == 0) { try { - p = new MyHTTPProvider(this, hname, ip, port, timeout); - if (ssl) + p = new MyHTTPProvider(this, hname, ip, port, timeout, ssl); + if (ssl && sslref) sslref->Init(p); } catch (const SocketException &ex) @@ -418,8 +414,8 @@ class HTTPD : public Module try { - p = new MyHTTPProvider(this, hname, ip, port, timeout); - if (ssl) + p = new MyHTTPProvider(this, hname, ip, port, timeout, ssl); + if (ssl && sslref) sslref->Init(p); } catch (const SocketException &ex) @@ -437,7 +433,7 @@ class HTTPD : public Module spacesepstream(ext_header).GetTokens(p->ext_headers); } - for (std::map<Anope::string, HTTPProvider *>::iterator it = this->providers.begin(), it_end = this->providers.end(); it != it_end;) + for (std::map<Anope::string, MyHTTPProvider *>::iterator it = this->providers.begin(), it_end = this->providers.end(); it != it_end;) { HTTPProvider *p = it->second; ++it; @@ -450,6 +446,24 @@ class HTTPD : public Module } } } + + void OnModuleLoad(User *u, Module *m) anope_override + { + if (m->name != "m_ssl") + return; + + for (std::map<Anope::string, MyHTTPProvider *>::iterator it = this->providers.begin(), it_end = this->providers.end(); it != it_end; ++it) + { + MyHTTPProvider *p = it->second; + + if (p->IsSSL() && sslref) + try + { + sslref->Init(p); + } + catch (const CoreException &) { } // Throws on reinitialization + } + } }; MODULE_INIT(HTTPD) diff --git a/modules/extra/m_ssl.cpp b/modules/extra/m_ssl.cpp index 10d1b5807..85b99d119 100644 --- a/modules/extra/m_ssl.cpp +++ b/modules/extra/m_ssl.cpp @@ -82,11 +82,6 @@ class SSLModule; static SSLModule *me; class SSLModule : public Module { - static int AlwaysAccept(int, X509_STORE_CTX *) - { - return 1; - } - Anope::string certfile, keyfile; public: @@ -110,13 +105,9 @@ class SSLModule : public Module SSL_CTX_set_mode(client_ctx, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); SSL_CTX_set_mode(server_ctx, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); - SSL_CTX_set_verify(client_ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, SSLModule::AlwaysAccept); - SSL_CTX_set_verify(server_ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, SSLModule::AlwaysAccept); - Anope::string context_name = "Anope"; SSL_CTX_set_session_id_context(client_ctx, reinterpret_cast<const unsigned char *>(context_name.c_str()), context_name.length()); SSL_CTX_set_session_id_context(server_ctx, reinterpret_cast<const unsigned char *>(context_name.c_str()), context_name.length()); - } ~SSLModule() @@ -144,11 +135,7 @@ class SSLModule : public Module if (Anope::IsFile(this->certfile.c_str())) { if (!SSL_CTX_use_certificate_file(client_ctx, this->certfile.c_str(), SSL_FILETYPE_PEM) || !SSL_CTX_use_certificate_file(server_ctx, this->certfile.c_str(), SSL_FILETYPE_PEM)) - { - SSL_CTX_free(client_ctx); - SSL_CTX_free(server_ctx); throw ConfigException("Error loading certificate"); - } else Log(LOG_DEBUG) << "m_ssl: Successfully loaded certificate " << this->certfile; } @@ -158,22 +145,14 @@ class SSLModule : public Module if (Anope::IsFile(this->keyfile.c_str())) { if (!SSL_CTX_use_PrivateKey_file(client_ctx, this->keyfile.c_str(), SSL_FILETYPE_PEM) || !SSL_CTX_use_PrivateKey_file(server_ctx, this->keyfile.c_str(), SSL_FILETYPE_PEM)) - { - SSL_CTX_free(client_ctx); - SSL_CTX_free(server_ctx); throw ConfigException("Error loading private key"); - } else Log(LOG_DEBUG) << "m_ssl: Successfully loaded private key " << this->keyfile; } else { if (Anope::IsFile(this->certfile.c_str())) - { - SSL_CTX_free(client_ctx); - SSL_CTX_free(server_ctx); throw ConfigException("Error loading private key " + this->keyfile + " - file not found"); - } else Log() << "Unable to open private key " << this->keyfile; } diff --git a/modules/extra/webcpanel/pages/chanserv/access.cpp b/modules/extra/webcpanel/pages/chanserv/access.cpp index cb050c223..06b363b53 100644 --- a/modules/extra/webcpanel/pages/chanserv/access.cpp +++ b/modules/extra/webcpanel/pages/chanserv/access.cpp @@ -18,7 +18,7 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s if (chname.empty()) { reply.error = HTTP_FOUND; - reply.headers["Location"] = Anope::string("http") + (use_ssl ? "s" : "") + "://" + message.headers["Host"] + "/chanserv/info"; + reply.headers["Location"] = Anope::string("http") + (server->IsSSL() ? "s" : "") + "://" + message.headers["Host"] + "/chanserv/info"; return true; } diff --git a/modules/extra/webcpanel/pages/chanserv/akick.cpp b/modules/extra/webcpanel/pages/chanserv/akick.cpp index 5acb8d6da..80a8a6a3d 100644 --- a/modules/extra/webcpanel/pages/chanserv/akick.cpp +++ b/modules/extra/webcpanel/pages/chanserv/akick.cpp @@ -18,7 +18,7 @@ bool WebCPanel::ChanServ::Akick::OnRequest(HTTPProvider *server, const Anope::st if (chname.empty()) { reply.error = HTTP_FOUND; - reply.headers["Location"] = Anope::string("http") + (use_ssl ? "s" : "") + "://" + message.headers["Host"] + "/chanserv/info"; + reply.headers["Location"] = Anope::string("http") + (server->IsSSL() ? "s" : "") + "://" + message.headers["Host"] + "/chanserv/info"; return true; } diff --git a/modules/extra/webcpanel/pages/chanserv/set.cpp b/modules/extra/webcpanel/pages/chanserv/set.cpp index cf3784d62..d0b54d15a 100644 --- a/modules/extra/webcpanel/pages/chanserv/set.cpp +++ b/modules/extra/webcpanel/pages/chanserv/set.cpp @@ -18,7 +18,7 @@ bool WebCPanel::ChanServ::Set::OnRequest(HTTPProvider *server, const Anope::stri if (chname.empty()) { reply.error = HTTP_FOUND; - reply.headers["Location"] = Anope::string("http") + (use_ssl ? "s" : "") + "://" + message.headers["Host"] + "/chanserv/info"; + reply.headers["Location"] = Anope::string("http") + (server->IsSSL() ? "s" : "") + "://" + message.headers["Host"] + "/chanserv/info"; return true; } diff --git a/modules/extra/webcpanel/pages/index.cpp b/modules/extra/webcpanel/pages/index.cpp index be4bbbc6d..44314afc3 100644 --- a/modules/extra/webcpanel/pages/index.cpp +++ b/modules/extra/webcpanel/pages/index.cpp @@ -21,7 +21,7 @@ class WebpanelRequest : public IdentifyRequest void OnSuccess() anope_override { - if (!client) + if (!client || !server) return; NickAlias *na = NickAlias::Find(this->GetAccount()); if (!na) @@ -58,14 +58,14 @@ class WebpanelRequest : public IdentifyRequest } reply.error = HTTP_FOUND; - reply.headers["Location"] = Anope::string("http") + (use_ssl ? "s" : "") + "://" + message.headers["Host"] + "/nickserv/info"; + reply.headers["Location"] = Anope::string("http") + (server->IsSSL() ? "s" : "") + "://" + message.headers["Host"] + "/nickserv/info"; client->SendReply(&reply); } void OnFail() anope_override { - if (!client) + if (!client || !server) return; replacements["INVALID_LOGIN"] = "Invalid username or password"; TemplateFileServer page("login.html"); diff --git a/modules/extra/webcpanel/pages/logout.cpp b/modules/extra/webcpanel/pages/logout.cpp index 8fafdcd4e..4cd6b1adf 100644 --- a/modules/extra/webcpanel/pages/logout.cpp +++ b/modules/extra/webcpanel/pages/logout.cpp @@ -17,7 +17,7 @@ bool WebCPanel::Logout::OnRequest(HTTPProvider *server, const Anope::string &pag na->Shrink<Anope::string>("webcpanel_ip"); reply.error = HTTP_FOUND; - reply.headers["Location"] = Anope::string("http") + (use_ssl ? "s" : "") + "://" + message.headers["Host"] + "/"; + reply.headers["Location"] = Anope::string("http") + (server->IsSSL() ? "s" : "") + "://" + message.headers["Host"] + "/"; return true; } diff --git a/modules/extra/webcpanel/webcpanel.cpp b/modules/extra/webcpanel/webcpanel.cpp index e69d91db8..c0bd841a0 100644 --- a/modules/extra/webcpanel/webcpanel.cpp +++ b/modules/extra/webcpanel/webcpanel.cpp @@ -9,7 +9,6 @@ Module *me; Anope::string provider_name, template_name, template_base, page_title; -bool use_ssl = false; class ModuleWebCPanel : public Module { @@ -59,7 +58,6 @@ class ModuleWebCPanel : public Module template_name = block->Get<const Anope::string>("template", "default"); template_base = Anope::DataDir + "/modules/webcpanel/templates/" + template_name; page_title = block->Get<const Anope::string>("title", "Anope IRC Services"); - use_ssl = block->Get<bool>("ssl", "no"); // This is dumb, is there a better way to do this? provider = ServiceReference<HTTPProvider>("HTTPProvider", provider_name); if (!provider) diff --git a/modules/extra/webcpanel/webcpanel.h b/modules/extra/webcpanel/webcpanel.h index e74b6c952..ebce325d2 100644 --- a/modules/extra/webcpanel/webcpanel.h +++ b/modules/extra/webcpanel/webcpanel.h @@ -14,7 +14,6 @@ extern Module *me; extern Anope::string provider_name, template_name, template_base, page_title; -extern bool use_ssl; struct SubSection { @@ -89,7 +88,7 @@ class WebPanelProtectedPage : public WebPanelPage if (!panel || !(na = panel->GetNickFromSession(client, message))) { reply.error = HTTP_FOUND; - reply.headers["Location"] = Anope::string("http") + (use_ssl ? "s" : "") + "://" + message.headers["Host"] + "/"; + reply.headers["Location"] = Anope::string("http") + (provider->IsSSL() ? "s" : "") + "://" + message.headers["Host"] + "/"; return true; // Access denied } |