2012-04-19 20:58:29 +02:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
2008-05-13 20:53:06 +00:00
|
|
|
*
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
|
|
|
|
* Copyright (C) 2013, 2017-2018 Sadie Powell <sadie@witchery.services>
|
|
|
|
* Copyright (C) 2013, 2015 Attila Molnar <attilamolnar@hush.com>
|
|
|
|
* Copyright (C) 2012 Robby <robby@chatbelgie.be>
|
2012-04-19 20:58:29 +02:00
|
|
|
* Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
|
|
|
|
* Copyright (C) 2008, 2010 Craig Edwards <brain@inspircd.org>
|
2008-05-13 20:53:06 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This file is part of InspIRCd. InspIRCd is free software: you can
|
|
|
|
* redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.
|
2008-05-13 20:53:06 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-05-13 20:53:06 +00:00
|
|
|
*/
|
|
|
|
|
2012-04-19 20:58:29 +02:00
|
|
|
|
2008-05-13 20:53:06 +00:00
|
|
|
#include "inspircd.h"
|
2013-04-02 20:12:15 +01:00
|
|
|
#include "modules/httpd.h"
|
2008-05-13 20:53:06 +00:00
|
|
|
|
2015-02-11 17:13:08 +01:00
|
|
|
class ModuleHttpConfig : public Module, public HTTPRequestEventListener
|
2008-05-13 20:53:06 +00:00
|
|
|
{
|
2020-04-09 18:57:50 +01:00
|
|
|
private:
|
2013-05-24 19:34:25 +02:00
|
|
|
HTTPdAPI API;
|
|
|
|
|
2008-05-13 20:53:06 +00:00
|
|
|
public:
|
2013-05-24 19:34:25 +02:00
|
|
|
ModuleHttpConfig()
|
2020-04-11 14:00:48 +01:00
|
|
|
: Module(VF_VENDOR, "Allows the server configuration to be viewed over HTTP via the /config path.")
|
2020-04-09 18:57:50 +01:00
|
|
|
, HTTPRequestEventListener(this)
|
2015-02-11 17:13:08 +01:00
|
|
|
, API(this)
|
2013-05-24 19:34:25 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-25 02:52:11 +00:00
|
|
|
ModResult OnHTTPRequest(HTTPRequest& request) override
|
2008-05-13 20:53:06 +00:00
|
|
|
{
|
2019-02-06 04:33:06 -06:00
|
|
|
if ((request.GetPath() != "/config") && (request.GetPath() != "/config/"))
|
2018-08-15 11:06:26 +01:00
|
|
|
return MOD_RES_PASSTHRU;
|
2008-05-13 20:53:06 +00:00
|
|
|
|
2019-02-07 12:14:07 +00:00
|
|
|
ServerInstance->Logs.Log(MODNAME, LOG_DEBUG, "Handling request for the HTTP /config route");
|
2018-08-15 11:06:26 +01:00
|
|
|
std::stringstream buffer;
|
2008-05-13 20:53:06 +00:00
|
|
|
|
2020-10-31 23:21:15 +00:00
|
|
|
for (auto& [_, tag] : ServerInstance->Config->config_data)
|
2008-05-13 20:53:06 +00:00
|
|
|
{
|
2018-08-15 11:06:26 +01:00
|
|
|
// Show the location of the tag in a comment.
|
2020-11-03 19:40:42 +00:00
|
|
|
buffer << "# " << tag->source.str() << std::endl
|
2020-11-03 19:57:39 +00:00
|
|
|
<< '<' << tag->name << ' ';
|
2008-05-13 20:53:06 +00:00
|
|
|
|
2018-08-15 11:06:26 +01:00
|
|
|
// Print out the tag with all keys aligned vertically.
|
2020-11-03 19:57:39 +00:00
|
|
|
const std::string indent(tag->name.length() + 2, ' ');
|
2020-11-10 14:58:00 +00:00
|
|
|
bool first = true;
|
|
|
|
for (auto& [key, value] : tag->GetItems())
|
2008-05-13 20:53:06 +00:00
|
|
|
{
|
2020-11-10 14:58:00 +00:00
|
|
|
if (!first)
|
2018-08-15 11:06:26 +01:00
|
|
|
buffer << std::endl << indent;
|
2020-11-10 14:58:00 +00:00
|
|
|
|
|
|
|
buffer << key << "=\"" << ServerConfig::Escape(value) << '"';
|
|
|
|
first = false;
|
2008-05-13 20:53:06 +00:00
|
|
|
}
|
2018-08-15 11:06:26 +01:00
|
|
|
buffer << '>' << std::endl << std::endl;
|
2008-05-13 20:53:06 +00:00
|
|
|
}
|
2015-02-11 17:13:08 +01:00
|
|
|
|
2018-08-15 11:06:26 +01:00
|
|
|
HTTPDocumentResponse response(this, request, &buffer, 200);
|
|
|
|
response.headers.SetHeader("X-Powered-By", MODNAME);
|
|
|
|
response.headers.SetHeader("Content-Type", "text/plain");
|
|
|
|
API->SendResponse(response);
|
|
|
|
return MOD_RES_DENY;
|
2008-05-13 20:53:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-02-02 19:03:07 +00:00
|
|
|
MODULE_INIT(ModuleHttpConfig)
|