1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
18 /* $ModDesc: Provides statistics over HTTP via m_httpd.so */
19 /* $ModDep: httpd.h */
21 class ModuleHttpStats : public Module
24 std::string stylesheet;
31 ConfigReader c(ServerInstance);
32 this->stylesheet = c.ReadValue("httpstats", "stylesheet", 0);
35 ModuleHttpStats(InspIRCd* Me) : Module(Me)
39 Implementation eventlist[] = { I_OnEvent, I_OnRequest };
40 ServerInstance->Modules->Attach(eventlist, this, 2);
43 std::string Sanitize(const std::string &str)
47 for (std::string::const_iterator x = str.begin(); x != str.end(); ++x)
64 if (*x < 32 || *x > 126)
67 ret += ("&#" + ConvToStr(n) + ";");
77 void OnEvent(Event* event)
79 std::stringstream data("");
81 if (event->GetEventID() == "httpd_url")
83 ServerInstance->Logs->Log("m_http_stats", DEBUG,"Handling httpd event");
84 HTTPRequest* http = (HTTPRequest*)event->GetData();
86 if ((http->GetURI() == "/config") || (http->GetURI() == "/config/"))
88 data << "<html><head><title>InspIRCd Configuration</title></head><body>";
89 data << "<h1>InspIRCd Configuration</h1><p>";
91 for (ConfigDataHash::iterator x = ServerInstance->Config->config_data.begin(); x != ServerInstance->Config->config_data.end(); ++x)
93 data << "<" << x->first << " ";
94 for (KeyValList::iterator j = x->second.begin(); j != x->second.end(); j++)
96 data << j->first << "="" << j->second << "" ";
101 data << "</body></html>";
102 /* Send the document back to m_httpd */
103 HTTPDocument response(http->sock, &data, 200);
104 response.headers.SetHeader("X-Powered-By", "m_httpd_config.so");
105 response.headers.SetHeader("Content-Type", "text/html");
106 Request req((char*)&response, (Module*)this, event->GetSource());
112 const char* OnRequest(Request* request)
118 virtual ~ModuleHttpStats()
122 virtual Version GetVersion()
124 return Version(1, 2, 0, 0, VF_VENDOR, API_VERSION);
128 MODULE_INIT(ModuleHttpStats)