2012-04-19 20:58:29 +02:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
2008-05-13 20:53:06 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
|
|
|
|
* Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
|
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
|
|
|
{
|
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()
|
2015-02-11 17:13:08 +01:00
|
|
|
: HTTPRequestEventListener(this)
|
|
|
|
, API(this)
|
2013-05-24 19:34:25 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-15 11:06:26 +01:00
|
|
|
ModResult OnHTTPRequest(HTTPRequest& request) CXX11_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
|
|
|
|
2018-08-15 11:06:26 +01:00
|
|
|
ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Handling request for the HTTP /config route");
|
|
|
|
std::stringstream buffer;
|
2008-05-13 20:53:06 +00:00
|
|
|
|
2018-08-15 11:06:26 +01:00
|
|
|
ConfigDataHash& config = ServerInstance->Config->config_data;
|
|
|
|
for (ConfigDataHash::const_iterator citer = config.begin(); citer != config.end(); ++citer)
|
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.
|
|
|
|
ConfigTag* tag = citer->second;
|
|
|
|
buffer << "# " << tag->getTagLocation() << std::endl
|
|
|
|
<< '<' << tag->tag << ' ';
|
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.
|
|
|
|
const std::string indent(tag->tag.length() + 2, ' ');
|
|
|
|
const ConfigItems& items = tag->getItems();
|
|
|
|
for (ConfigItems::const_iterator kiter = items.begin(); kiter != items.end(); )
|
2008-05-13 20:53:06 +00:00
|
|
|
{
|
2018-08-15 11:06:26 +01:00
|
|
|
ConfigItems::const_iterator curr = kiter++;
|
|
|
|
buffer << curr->first << "=\"" << ServerConfig::Escape(curr->second) << '"';
|
|
|
|
if (kiter != items.end())
|
|
|
|
buffer << std::endl << indent;
|
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
|
|
|
}
|
|
|
|
|
2013-04-30 08:38:33 +01:00
|
|
|
Version GetVersion() CXX11_OVERRIDE
|
2008-05-13 20:53:06 +00:00
|
|
|
{
|
2017-08-27 13:25:29 +01:00
|
|
|
return Version("Allows for the server configuration to be viewed over HTTP via m_httpd", VF_VENDOR);
|
2008-05-13 20:53:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-02-02 19:03:07 +00:00
|
|
|
MODULE_INIT(ModuleHttpConfig)
|