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 ModResult OnHTTPRequest(HTTPRequest& request) CXX11_OVERRIDE
37 if ((request.GetURI() != "/config") && (request.GetURI() != "/config/"))
38 return MOD_RES_PASSTHRU;
40 ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Handling request for the HTTP /config route");
41 std::stringstream buffer;
43 ConfigDataHash& config = ServerInstance->Config->config_data;
44 for (ConfigDataHash::const_iterator citer = config.begin(); citer != config.end(); ++citer)
46 // Show the location of the tag in a comment.
47 ConfigTag* tag = citer->second;
48 buffer << "# " << tag->getTagLocation() << std::endl
49 << '<' << tag->tag << ' ';
51 // Print out the tag with all keys aligned vertically.
52 const std::string indent(tag->tag.length() + 2, ' ');
53 const ConfigItems& items = tag->getItems();
54 for (ConfigItems::const_iterator kiter = items.begin(); kiter != items.end(); )
56 ConfigItems::const_iterator curr = kiter++;
57 buffer << curr->first << "=\"" << ServerConfig::Escape(curr->second) << '"';
58 if (kiter != items.end())
59 buffer << std::endl << indent;
61 buffer << '>' << std::endl << std::endl;
64 HTTPDocumentResponse response(this, request, &buffer, 200);
65 response.headers.SetHeader("X-Powered-By", MODNAME);
66 response.headers.SetHeader("Content-Type", "text/plain");
67 API->SendResponse(response);
71 Version GetVersion() CXX11_OVERRIDE
73 return Version("Allows for the server configuration to be viewed over HTTP via m_httpd", VF_VENDOR);
77 MODULE_INIT(ModuleHttpConfig)