+ ConfigTag* conf = ServerInstance->Config->ConfValue("httpstats");
+
+ // Parameterized queries may cause a performance issue
+ // Due to the sheer volume of data
+ // So default them to disabled
+ enableparams = conf->getBool("enableparams");
+ }
+
+ ModResult HandleRequest(HTTPRequest* http)
+ {
+ std::string path = http->GetPath();
+
+ if (path != "/stats" && path.substr(0, 7) != "/stats/")
+ return MOD_RES_PASSTHRU;
+
+ if (path[path.size() - 1] == '/')
+ path.erase(path.size() - 1, 1);
+
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Handling httpd event");
+
+ bool found = true;
+ std::stringstream data;
+ data << "<inspircdstats>";
+
+ if (path == "/stats")
+ {
+ data << Stats::ServerInfo << Stats::General
+ << Stats::XLines << Stats::Modules
+ << Stats::Channels << Stats::Users
+ << Stats::Servers << Stats::Commands;
+ }
+ else if (path == "/stats/general")
+ {
+ data << Stats::General;
+ }
+ else if (path == "/stats/users")
+ {
+ if (enableparams)
+ Stats::ListUsers(data, http->GetParsedURI().query_params);
+ else
+ data << Stats::Users;
+ }
+ else
+ {
+ found = false;
+ }
+
+ if (found)
+ {
+ data << "</inspircdstats>";
+ }
+ else
+ {
+ data.clear();
+ data.str(std::string());
+ }
+
+ /* Send the document back to m_httpd */
+ HTTPDocumentResponse response(this, *http, &data, found ? 200 : 404);
+ response.headers.SetHeader("X-Powered-By", MODNAME);
+ response.headers.SetHeader("Content-Type", "text/xml");
+ API->SendResponse(response);
+ return MOD_RES_DENY; // Handled