]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_httpd_stats.cpp
This will royally fuck 1.2's linking right now, but..
[user/henk/code/inspircd.git] / src / modules / m_httpd_stats.cpp
index 70b73e13dc333a1dce0e6311029c24eb755e3c4d..6bf5dc86840391c8e2630df8edad2251298aea80 100644 (file)
@@ -6,7 +6,7 @@
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ *         the file COPYING for details.
  *
  * ---------------------------------------------------
  */
@@ -20,6 +20,7 @@
 #include "httpd.h"
 
 /* $ModDesc: Provides statistics over HTTP via m_httpd.so */
+/* $ModDep: httpd.h */
 
 typedef std::map<irc::string,int> StatsHash;
 typedef StatsHash::iterator StatsIter;
@@ -30,6 +31,8 @@ typedef SortedList::iterator SortedIter;
 static StatsHash* sh = new StatsHash();
 static SortedList* so = new SortedList();
 
+static StatsHash* Servers = new StatsHash();
+
 class ModuleHttpStats : public Module
 {
        
@@ -46,7 +49,6 @@ class ModuleHttpStats : public Module
 
        ModuleHttpStats(InspIRCd* Me) : Module(Me)
        {
-               
                ReadConfig();
                this->changed = true;
        }
@@ -74,6 +76,18 @@ class ModuleHttpStats : public Module
                so->clear();
                for (StatsIter a = sh->begin(); a != sh->end(); a++)
                        InsertOrder(a->first, a->second);
+               for (user_hash::iterator u = ServerInstance->clientlist->begin(); u != ServerInstance->clientlist->end(); u++)
+               {
+                       StatsHash::iterator n = Servers->find(u->second->server);
+                       if (n != Servers->end())
+                       {
+                               n->second++;
+                       }
+                       else
+                       {
+                               Servers->insert(std::make_pair<irc::string,int>(u->second->server,1));
+                       }
+               }
                this->changed = false;
        }
 
@@ -96,13 +110,26 @@ class ModuleHttpStats : public Module
                                data << "<channelcount>" << ServerInstance->chanlist->size() << "</channelcount>";
                                data << "<opercount>" << ServerInstance->all_opers.size() << "</opercount>";
                                data << "<socketcount>" << (ServerInstance->SE->GetMaxFds() - ServerInstance->SE->GetRemainingFds()) << "</socketcount><socketmax>" << ServerInstance->SE->GetMaxFds() <<
-                                       "</socketmax><socketengine>" << ServerInstance->SE->GetName() << "')</socketengine>";
+                                       "</socketmax><socketengine>" << ServerInstance->SE->GetName() << "</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></uptime>";
+
+
                                data << "</general>";
                                data << "<modulelist>";
                                for (int i = 0; i <= ServerInstance->GetModuleCount(); i++)
                                {
                                        if (!ServerInstance->Config->module_names[i].empty())
-                                               data << "<module>" << ServerInstance->Config->module_names[i] << "</module>";
+                                       {
+                                               Version v = ServerInstance->modules[i]->GetVersion();
+                                               data << "<module><name>" << ServerInstance->Config->module_names[i] << "</name><version>" << 
+                                                       v.Major << "." <<  v.Minor << "." << v.Revision << "." << v.Build << "</version></module>";
+                                       }
                                }
                                data << "</modulelist>";
 
@@ -113,8 +140,7 @@ class ModuleHttpStats : public Module
                                if (this->changed)
                                        this->SortList();
 
-                               int n = 0;
-                               for (SortedIter a = so->begin(); ((a != so->end()) && (n < 25)); a++, n++)
+                               for (SortedIter a = so->begin(); a != so->end(); a++)
                                {
                                        chanrec* c = ServerInstance->FindChan(a->second.c_str());
                                        if (c && !c->IsModeSet('s') && !c->IsModeSet('p'))
@@ -125,15 +151,30 @@ class ModuleHttpStats : public Module
                                                data << "<channelhalfops>" << c->GetHalfoppedUsers()->size() << "</channelhalfops>";
                                                data << "<channelvoices>" << c->GetVoicedUsers()->size() << "</channelvoices>";
                                                data << "<channeltopic>" << c->topic << "</channeltopic>";
+                                               data << "<channelmodes>" << c->ChanModes(false) << "</channelmodes>";
                                                data << "</channel>";
                                        }
                                }
 
                                data << "</channellist>";
+
+                               data << "<serverlist>";
+                               
+                               for (StatsHash::iterator b = Servers->begin(); b != Servers->end(); b++)
+                               {
+                                       data << "<server>";
+                                       data << "<servername>" << b->first << "</servername>";
+                                       data << "<usercount>" << b->second << "</usercount>";
+                                       data << "</server>";
+                               }
+                               data << "</serverlist>";
+
                                data << "</inspircdstats>";
 
                                /* Send the document back to m_httpd */
-                               HTTPDocument response(http->sock, &data, 200, "X-Powered-By: m_http_stats.so\r\nContent-Type: text/xml\r\n");
+                               HTTPDocument response(http->sock, &data, 200);
+                               response.headers.SetHeader("X-Powered-By", "m_httpd_stats.so");
+                               response.headers.SetHeader("Content-Type", "text/xml");
                                Request req((char*)&response, (Module*)this, event->GetSource());
                                req.Send();
                        }