1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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 */
20 class ModuleHttpConfig : public Module
24 Implementation eventlist[] = { I_OnEvent };
25 ServerInstance->Modules->Attach(eventlist, this, 1);
28 std::string Sanitize(const std::string &str)
32 for (std::string::const_iterator x = str.begin(); x != str.end(); ++x)
49 if (*x < 32 || *x > 126)
52 ret += ("&#" + ConvToStr(n) + ";");
62 void OnEvent(Event& event)
64 std::stringstream data("");
66 if (event.id == "httpd_url")
68 ServerInstance->Logs->Log("m_http_stats", DEBUG,"Handling httpd event");
69 HTTPRequest* http = (HTTPRequest*)&event;
71 if ((http->GetURI() == "/config") || (http->GetURI() == "/config/"))
73 data << "<html><head><title>InspIRCd Configuration</title></head><body>";
74 data << "<h1>InspIRCd Configuration</h1><p>";
76 for (ConfigDataHash::iterator x = ServerInstance->Config->config_data.begin(); x != ServerInstance->Config->config_data.end(); ++x)
78 data << "<" << x->first << " ";
79 ConfigTag* tag = x->second;
80 for (std::vector<KeyVal>::const_iterator j = tag->getItems().begin(); j != tag->getItems().end(); j++)
82 data << Sanitize(j->first) << "="" << Sanitize(j->second) << "" ";
87 data << "</body></html>";
88 /* Send the document back to m_httpd */
89 HTTPDocumentResponse response(this, *http, &data, 200);
90 response.headers.SetHeader("X-Powered-By", "m_httpd_config.so");
91 response.headers.SetHeader("Content-Type", "text/html");
97 virtual ~ModuleHttpConfig()
101 virtual Version GetVersion()
103 return Version("Provides configuration over HTTP via m_httpd.so", VF_VENDOR);
107 MODULE_INIT(ModuleHttpConfig)