2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "modules/httpd.h"
24 class ModuleHttpConfig : public Module, public HTTPRequestEventListener
30 : HTTPRequestEventListener(this)
35 std::string Sanitize(const std::string &str)
39 for (std::string::const_iterator x = str.begin(); x != str.end(); ++x)
56 if (*x < 32 || *x > 126)
59 ret += ("&#" + ConvToStr(n) + ";");
69 ModResult HandleRequest(HTTPRequest* http)
71 std::stringstream data("");
74 ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Handling httpd event");
76 if ((http->GetURI() == "/config") || (http->GetURI() == "/config/"))
78 data << "<html><head><title>InspIRCd Configuration</title></head><body>";
79 data << "<h1>InspIRCd Configuration</h1><p>";
81 for (ConfigDataHash::iterator x = ServerInstance->Config->config_data.begin(); x != ServerInstance->Config->config_data.end(); ++x)
83 data << "<" << x->first << " ";
84 const ConfigItems& items = x->second->getItems();
85 for (ConfigItems::const_iterator j = items.begin(); j != items.end(); j++)
87 data << Sanitize(j->first) << "="" << Sanitize(j->second) << "" ";
92 data << "</body></html>";
93 /* Send the document back to m_httpd */
94 HTTPDocumentResponse response(this, *http, &data, 200);
95 response.headers.SetHeader("X-Powered-By", MODNAME);
96 response.headers.SetHeader("Content-Type", "text/html");
97 API->SendResponse(response);
98 return MOD_RES_DENY; // Handled
101 return MOD_RES_PASSTHRU;
104 ModResult OnHTTPRequest(HTTPRequest& req) CXX11_OVERRIDE
106 return HandleRequest(&req);
109 Version GetVersion() CXX11_OVERRIDE
111 return Version("Allows for the server configuration to be viewed over HTTP via m_httpd.so", VF_VENDOR);
115 MODULE_INIT(ModuleHttpConfig)