]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_httpd_config.cpp
Update copyright headers.
[user/henk/code/inspircd.git] / src / modules / m_httpd_config.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
11  *
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.
15  *
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
19  * details.
20  *
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/>.
23  */
24
25
26 #include "inspircd.h"
27 #include "modules/httpd.h"
28
29 class ModuleHttpConfig : public Module, public HTTPRequestEventListener
30 {
31         HTTPdAPI API;
32
33  public:
34         ModuleHttpConfig()
35                 : HTTPRequestEventListener(this)
36                 , API(this)
37         {
38         }
39
40         ModResult OnHTTPRequest(HTTPRequest& request) CXX11_OVERRIDE
41         {
42                 if ((request.GetPath() != "/config") && (request.GetPath() != "/config/"))
43                         return MOD_RES_PASSTHRU;
44
45                 ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Handling request for the HTTP /config route");
46                 std::stringstream buffer;
47
48                 ConfigDataHash& config = ServerInstance->Config->config_data;
49                 for (ConfigDataHash::const_iterator citer = config.begin(); citer != config.end(); ++citer)
50                 {
51                         // Show the location of the tag in a comment.
52                         ConfigTag* tag = citer->second;
53                         buffer << "# " << tag->getTagLocation() << std::endl
54                                 << '<' << tag->tag << ' ';
55
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(); )
60                         {
61                                 ConfigItems::const_iterator curr = kiter++;
62                                 buffer << curr->first << "=\"" << ServerConfig::Escape(curr->second) << '"';
63                                 if (kiter != items.end())
64                                         buffer << std::endl << indent;
65                         }
66                         buffer << '>' << std::endl << std::endl;
67                 }
68
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);
73                 return MOD_RES_DENY;
74         }
75
76         Version GetVersion() CXX11_OVERRIDE
77         {
78                 return Version("Allows for the server configuration to be viewed over HTTP via m_httpd", VF_VENDOR);
79         }
80 };
81
82 MODULE_INIT(ModuleHttpConfig)