2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013, 2017-2018, 2020 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2013, 2015 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9 * Copyright (C) 2008, 2010 Craig Edwards <brain@inspircd.org>
11 * This file is part of InspIRCd. InspIRCd is free software: you can
12 * redistribute it and/or modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation, version 2.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "modules/httpd.h"
28 class ModuleHttpConfig : public Module, public HTTPRequestEventListener
34 : HTTPRequestEventListener(this)
39 ModResult OnHTTPRequest(HTTPRequest& request) CXX11_OVERRIDE
41 if (request.GetPath() != "/config")
42 return MOD_RES_PASSTHRU;
44 ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Handling HTTP request for %s", request.GetPath().c_str());
45 std::stringstream buffer;
47 ConfigDataHash& config = ServerInstance->Config->config_data;
48 for (ConfigDataHash::const_iterator citer = config.begin(); citer != config.end(); ++citer)
50 // Show the location of the tag in a comment.
51 ConfigTag* tag = citer->second;
52 buffer << "# " << tag->getTagLocation() << std::endl
53 << '<' << tag->tag << ' ';
55 // Print out the tag with all keys aligned vertically.
56 const std::string indent(tag->tag.length() + 2, ' ');
57 const ConfigItems& items = tag->getItems();
58 for (ConfigItems::const_iterator kiter = items.begin(); kiter != items.end(); )
60 ConfigItems::const_iterator curr = kiter++;
61 buffer << curr->first << "=\"" << ServerConfig::Escape(curr->second) << '"';
62 if (kiter != items.end())
63 buffer << std::endl << indent;
65 buffer << '>' << std::endl << std::endl;
68 HTTPDocumentResponse response(this, request, &buffer, 200);
69 response.headers.SetHeader("X-Powered-By", MODNAME);
70 response.headers.SetHeader("Content-Type", "text/plain");
71 API->SendResponse(response);
75 Version GetVersion() CXX11_OVERRIDE
77 return Version("Allows the server configuration to be viewed over HTTP via the /config path.", VF_VENDOR);
81 MODULE_INIT(ModuleHttpConfig)