2008-05-13 20:53:06 +00:00
|
|
|
/* +------------------------------------+
|
|
|
|
* | Inspire Internet Relay Chat Daemon |
|
|
|
|
* +------------------------------------+
|
|
|
|
*
|
2010-01-11 03:07:32 +00:00
|
|
|
* InspIRCd: (C) 2002-2010 InspIRCd Development Team
|
2009-03-15 12:42:35 +00:00
|
|
|
* See: http://wiki.inspircd.org/Credits
|
2008-05-13 20:53:06 +00:00
|
|
|
*
|
|
|
|
* This program is free but copyrighted software; see
|
|
|
|
* the file COPYING for details.
|
|
|
|
*
|
|
|
|
* ---------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "inspircd.h"
|
|
|
|
#include "httpd.h"
|
|
|
|
#include "protocol.h"
|
|
|
|
|
|
|
|
/* $ModDesc: Provides statistics over HTTP via m_httpd.so */
|
|
|
|
/* $ModDep: httpd.h */
|
|
|
|
|
|
|
|
class ModuleHttpStats : public Module
|
|
|
|
{
|
2008-06-11 11:35:23 +00:00
|
|
|
|
2008-05-13 20:53:06 +00:00
|
|
|
std::string stylesheet;
|
|
|
|
bool changed;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
void ReadConfig()
|
|
|
|
{
|
2009-09-26 14:13:13 +00:00
|
|
|
ConfigReader c;
|
2008-05-13 20:53:06 +00:00
|
|
|
this->stylesheet = c.ReadValue("httpstats", "stylesheet", 0);
|
|
|
|
}
|
|
|
|
|
2009-09-26 14:13:13 +00:00
|
|
|
ModuleHttpStats() {
|
2008-05-13 20:53:06 +00:00
|
|
|
ReadConfig();
|
|
|
|
this->changed = true;
|
2009-10-08 23:29:21 +00:00
|
|
|
Implementation eventlist[] = { I_OnEvent };
|
|
|
|
ServerInstance->Modules->Attach(eventlist, this, 1);
|
2008-05-13 20:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Sanitize(const std::string &str)
|
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
|
|
|
|
for (std::string::const_iterator x = str.begin(); x != str.end(); ++x)
|
|
|
|
{
|
|
|
|
switch (*x)
|
|
|
|
{
|
|
|
|
case '<':
|
|
|
|
ret += "<";
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
ret += ">";
|
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
ret += "&";
|
|
|
|
break;
|
|
|
|
case '"':
|
|
|
|
ret += """;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (*x < 32 || *x > 126)
|
|
|
|
{
|
|
|
|
int n = *x;
|
|
|
|
ret += ("&#" + ConvToStr(n) + ";");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret += *x;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-08 23:29:21 +00:00
|
|
|
void OnEvent(Event& event)
|
2008-05-13 20:53:06 +00:00
|
|
|
{
|
|
|
|
std::stringstream data("");
|
|
|
|
|
2009-10-08 23:29:21 +00:00
|
|
|
if (event.id == "httpd_url")
|
2008-05-13 20:53:06 +00:00
|
|
|
{
|
|
|
|
ServerInstance->Logs->Log("m_http_stats", DEBUG,"Handling httpd event");
|
2009-10-08 23:29:21 +00:00
|
|
|
HTTPRequest* http = (HTTPRequest*)&event;
|
2008-05-13 20:53:06 +00:00
|
|
|
|
|
|
|
if ((http->GetURI() == "/config") || (http->GetURI() == "/config/"))
|
|
|
|
{
|
|
|
|
data << "<html><head><title>InspIRCd Configuration</title></head><body>";
|
|
|
|
data << "<h1>InspIRCd Configuration</h1><p>";
|
|
|
|
|
|
|
|
for (ConfigDataHash::iterator x = ServerInstance->Config->config_data.begin(); x != ServerInstance->Config->config_data.end(); ++x)
|
|
|
|
{
|
|
|
|
data << "<" << x->first << " ";
|
2009-10-17 02:14:44 +00:00
|
|
|
ConfigTag* tag = x->second;
|
2009-10-23 19:07:40 +00:00
|
|
|
for (std::vector<KeyVal>::const_iterator j = tag->getItems().begin(); j != tag->getItems().end(); j++)
|
2008-05-13 20:53:06 +00:00
|
|
|
{
|
2009-10-17 02:14:44 +00:00
|
|
|
data << Sanitize(j->first) << "="" << Sanitize(j->second) << "" ";
|
2008-05-13 20:53:06 +00:00
|
|
|
}
|
|
|
|
data << "><br>";
|
|
|
|
}
|
|
|
|
|
|
|
|
data << "</body></html>";
|
|
|
|
/* Send the document back to m_httpd */
|
2009-10-08 23:29:21 +00:00
|
|
|
HTTPDocumentResponse response(this, *http, &data, 200);
|
2008-05-13 20:53:06 +00:00
|
|
|
response.headers.SetHeader("X-Powered-By", "m_httpd_config.so");
|
|
|
|
response.headers.SetHeader("Content-Type", "text/html");
|
2009-10-08 23:29:21 +00:00
|
|
|
response.Send();
|
2008-05-13 20:53:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~ModuleHttpStats()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Version GetVersion()
|
|
|
|
{
|
2009-10-17 17:53:31 +00:00
|
|
|
return Version("Provides statistics over HTTP via m_httpd.so", VF_VENDOR);
|
2008-05-13 20:53:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_INIT(ModuleHttpStats)
|