/* +------------------------------------+ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * * InspIRCd: (C) 2002-2010 InspIRCd Development Team * See: http://wiki.inspircd.org/Credits * * 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 */ class ModuleHttpConfig : public Module { public: ModuleHttpConfig() { Implementation eventlist[] = { I_OnEvent }; ServerInstance->Modules->Attach(eventlist, this, 1); } 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; } void OnEvent(Event& event) { std::stringstream data(""); if (event.id == "httpd_url") { ServerInstance->Logs->Log("m_http_stats", DEBUG,"Handling httpd event"); HTTPRequest* http = (HTTPRequest*)&event; if ((http->GetURI() == "/config") || (http->GetURI() == "/config/")) { data << "
";
for (ConfigDataHash::iterator x = ServerInstance->Config->config_data.begin(); x != ServerInstance->Config->config_data.end(); ++x)
{
data << "<" << x->first << " ";
ConfigTag* tag = x->second;
for (std::vector
";
}
data << "";
/* Send the document back to m_httpd */
HTTPDocumentResponse response(this, *http, &data, 200);
response.headers.SetHeader("X-Powered-By", "m_httpd_config.so");
response.headers.SetHeader("Content-Type", "text/html");
response.Send();
}
}
}
virtual ~ModuleHttpConfig()
{
}
virtual Version GetVersion()
{
return Version("Provides configuration over HTTP via m_httpd.so", VF_VENDOR);
}
};
MODULE_INIT(ModuleHttpConfig)