]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_httpd_stats.cpp
Merge pull request #1185 from SaberUK/master+lockserv
[user/henk/code/inspircd.git] / src / modules / m_httpd_stats.cpp
index ae65f0692fe10ef8203dde48f05ff532c9661e13..eb8e856acde4e150e28aab4917c916ed18673a31 100644 (file)
 #include "modules/httpd.h"
 #include "xline.h"
 
-class ModuleHttpStats : public Module
+class ModuleHttpStats : public Module, public HTTPRequestEventListener
 {
        static const insp::flat_map<char, char const*>& entities;
        HTTPdAPI API;
 
  public:
        ModuleHttpStats()
-               : API(this)
+               : HTTPRequestEventListener(this)
+               , API(this)
        {
        }
 
@@ -87,14 +88,12 @@ class ModuleHttpStats : public Module
                data << "</metadata>";
        }
 
-       void OnEvent(Event& event) CXX11_OVERRIDE
+       ModResult HandleRequest(HTTPRequest* http)
        {
                std::stringstream data("");
 
-               if (event.id == "httpd_url")
                {
                        ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Handling httpd event");
-                       HTTPRequest* http = (HTTPRequest*)&event;
 
                        if ((http->GetURI() == "/stats") || (http->GetURI() == "/stats/"))
                        {
@@ -107,19 +106,15 @@ class ModuleHttpStats : public Module
                                data << "<channelcount>" << ServerInstance->GetChans().size() << "</channelcount>";
                                data << "<opercount>" << ServerInstance->Users->all_opers.size() << "</opercount>";
                                data << "<socketcount>" << (SocketEngine::GetUsedFds()) << "</socketcount><socketmax>" << SocketEngine::GetMaxFds() << "</socketmax><socketengine>" INSPIRCD_SOCKETENGINE_NAME "</socketengine>";
-
-                               time_t current_time = 0;
-                               current_time = ServerInstance->Time();
-                               time_t server_uptime = current_time - ServerInstance->startup_time;
-                               struct tm* stime;
-                               stime = gmtime(&server_uptime);
-                               data << "<uptime><days>" << stime->tm_yday << "</days><hours>" << stime->tm_hour << "</hours><mins>" << stime->tm_min << "</mins><secs>" << stime->tm_sec << "</secs><boot_time_t>" << ServerInstance->startup_time << "</boot_time_t></uptime>";
+                               data << "<uptime><boot_time_t>" << ServerInstance->startup_time << "</boot_time_t></uptime>";
 
                                data << "<isupport>";
-                               const std::vector<std::string>& isupport = ServerInstance->ISupport.GetLines();
-                               for (std::vector<std::string>::const_iterator it = isupport.begin(); it != isupport.end(); it++)
+                               const std::vector<Numeric::Numeric>& isupport = ServerInstance->ISupport.GetLines();
+                               for (std::vector<Numeric::Numeric>::const_iterator i = isupport.begin(); i != isupport.end(); ++i)
                                {
-                                       data << Sanitize(*it) << std::endl;
+                                       const Numeric::Numeric& num = *i;
+                                       for (std::vector<std::string>::const_iterator j = num.GetParams().begin(); j != num.GetParams().end()-1; ++j)
+                                               data << "<token>" << Sanitize(*j) << "</token>" << std::endl;
                                }
                                data << "</isupport></general><xlines>";
                                std::vector<std::string> xltypes = ServerInstance->XLines->GetAllTypes();
@@ -224,15 +219,30 @@ class ModuleHttpStats : public Module
                                        data << "</server>";
                                }
 
-                               data << "</serverlist></inspircdstats>";
+                               data << "</serverlist><commandlist>";
+
+                               const CommandParser::CommandMap& commands = ServerInstance->Parser.GetCommands();
+                               for (CommandParser::CommandMap::const_iterator i = commands.begin(); i != commands.end(); ++i)
+                               {
+                                       data << "<command><name>" << i->second->name << "</name><usecount>" << i->second->use_count << "</usecount></command>";
+                               }
+
+                               data << "</commandlist></inspircdstats>";
 
                                /* Send the document back to m_httpd */
                                HTTPDocumentResponse response(this, *http, &data, 200);
                                response.headers.SetHeader("X-Powered-By", MODNAME);
                                response.headers.SetHeader("Content-Type", "text/xml");
                                API->SendResponse(response);
+                               return MOD_RES_DENY; // Handled
                        }
                }
+               return MOD_RES_PASSTHRU;
+       }
+
+       ModResult OnHTTPRequest(HTTPRequest& req) CXX11_OVERRIDE
+       {
+               return HandleRequest(&req);
        }
 
        Version GetVersion() CXX11_OVERRIDE