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