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