1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/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;
32 this->stylesheet = c.ReadValue("httpstats", "stylesheet", 0);
38 Implementation eventlist[] = { I_OnEvent };
39 ServerInstance->Modules->Attach(eventlist, this, 1);
42 std::string Sanitize(const std::string &str)
46 for (std::string::const_iterator x = str.begin(); x != str.end(); ++x)
63 if (*x < 32 || *x > 126)
66 ret += ("&#" + ConvToStr(n) + ";");
76 void OnEvent(Event& event)
78 std::stringstream data("");
80 if (event.id == "httpd_url")
82 ServerInstance->Logs->Log("m_http_stats", DEBUG,"Handling httpd event");
83 HTTPRequest* http = (HTTPRequest*)&event;
85 if ((http->GetURI() == "/config") || (http->GetURI() == "/config/"))
87 data << "<html><head><title>InspIRCd Configuration</title></head><body>";
88 data << "<h1>InspIRCd Configuration</h1><p>";
90 for (ConfigDataHash::iterator x = ServerInstance->Config->config_data.begin(); x != ServerInstance->Config->config_data.end(); ++x)
92 data << "<" << x->first << " ";
93 ConfigTag* tag = x->second;
94 for (std::vector<KeyVal>::const_iterator j = tag->getItems().begin(); j != tag->getItems().end(); j++)
96 data << Sanitize(j->first) << "="" << Sanitize(j->second) << "" ";
101 data << "</body></html>";
102 /* Send the document back to m_httpd */
103 HTTPDocumentResponse response(this, *http, &data, 200);
104 response.headers.SetHeader("X-Powered-By", "m_httpd_config.so");
105 response.headers.SetHeader("Content-Type", "text/html");
111 virtual ~ModuleHttpStats()
115 virtual Version GetVersion()
117 return Version("Provides statistics over HTTP via m_httpd.so", VF_VENDOR);
121 MODULE_INIT(ModuleHttpStats)