1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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 */
19 /* $ModDep: httpd.h */
21 class ModuleHttpStats : public Module
24 std::string stylesheet;
31 ConfigReader c(ServerInstance);
32 this->stylesheet = c.ReadValue("httpstats", "stylesheet", 0);
35 ModuleHttpStats(InspIRCd* Me) : Module(Me)
39 Implementation eventlist[] = { I_OnEvent, I_OnRequest };
40 ServerInstance->Modules->Attach(eventlist, this, 2);
43 void OnEvent(Event* event)
45 std::stringstream data("");
47 if (event->GetEventID() == "httpd_url")
49 ServerInstance->Logs->Log("m_http_stats", DEBUG,"Handling httpd event");
50 HTTPRequest* http = (HTTPRequest*)event->GetData();
52 if ((http->GetURI() == "/stats") || (http->GetURI() == "/stats/"))
54 data << "<inspircdstats>";
56 data << "<server><name>" << ServerInstance->Config->ServerName << "</name><gecos>" << ServerInstance->Config->ServerDesc << "</gecos></server>";
59 data << "<usercount>" << ServerInstance->Users->clientlist->size() << "</usercount>";
60 data << "<channelcount>" << ServerInstance->chanlist->size() << "</channelcount>";
61 data << "<opercount>" << ServerInstance->Users->all_opers.size() << "</opercount>";
62 data << "<socketcount>" << (ServerInstance->SE->GetMaxFds() - ServerInstance->SE->GetRemainingFds()) << "</socketcount><socketmax>" << ServerInstance->SE->GetMaxFds() <<
63 "</socketmax><socketengine>" << ServerInstance->SE->GetName() << "</socketengine>";
65 time_t current_time = 0;
66 current_time = ServerInstance->Time();
67 time_t server_uptime = current_time - ServerInstance->startup_time;
69 stime = gmtime(&server_uptime);
70 data << "<uptime><days>" << stime->tm_yday << "</days><hours>" << stime->tm_hour << "</hours><mins>" << stime->tm_min << "</mins><secs>" << stime->tm_sec << "</secs></uptime>";
74 data << "<modulelist>";
75 std::vector<std::string> module_names = ServerInstance->Modules->GetAllModuleNames(0);
76 for (std::vector<std::string>::iterator i = module_names.begin(); i != module_names.end(); ++i)
78 Module* m = ServerInstance->Modules->Find(i->c_str());
79 Version v = m->GetVersion();
80 data << "<module><name>" << *i << "</name><version>" << v.Major << "." << v.Minor << "." << v.Revision << "." << v.Build << "</version></module>";
82 data << "</modulelist>";
83 data << "<channellist>";
85 for (chan_hash::const_iterator a = ServerInstance->chanlist->begin(); a != ServerInstance->chanlist->end(); ++a)
87 Channel* c = a->second;
90 data << "<usercount>" << c->GetUsers()->size() << "</usercount><channelname>" << c->name << "</channelname>";
91 data << "<channelops>" << c->GetOppedUsers()->size() << "</channelops>";
92 data << "<channelhalfops>" << c->GetHalfoppedUsers()->size() << "</channelhalfops>";
93 data << "<channelvoices>" << c->GetVoicedUsers()->size() << "</channelvoices>";
94 data << "<channeltopic>" << c->topic << "</channeltopic>";
95 data << "<channelmodes>" << c->ChanModes(false) << "</channelmodes>";
96 CUList* ulist = c->GetUsers();
98 for (CUList::iterator x = ulist->begin(); x != ulist->end(); ++x)
100 data << "<channelmember><uid>" << x->first->uuid << "</uid><privs>" << c->GetAllPrefixChars(x->first) << "</privs></channelmember>";
102 data << "</channel>";
105 data << "</channellist><userlist>";
107 for (user_hash::const_iterator a = ServerInstance->Users->clientlist->begin(); a != ServerInstance->Users->clientlist->end(); ++a)
112 data << "<nickname>" << u->nick << "</nickname><uuid>" << u->uuid << "</uuid><realhost>" << u->host << "</realhost><displayhost>" << u->dhost << "</displayhost>";
113 data << "<gecos>" << u->fullname << "</gecos><server>" << u->server << "</server><away>" << u->awaymsg << "</away><opertype>" << u->oper << "</opertype><modes>";
115 for (unsigned char n = 'A'; n <= 'z'; ++n)
119 data << modes << "</modes>";
123 data << "</userlist><serverlist>";
126 ServerInstance->PI->GetServerList(sl);
128 for (ProtoServerList::iterator b = sl.begin(); b != sl.end(); ++b)
131 data << "<servername>" << b->servername << "</servername>";
132 data << "<parentname>" << b->parentname << "</parentname>";
133 data << "<usercount>" << b->usercount << "</usercount>";
134 data << "<opercount>" << b->opercount << "</opercount>";
135 data << "<lagmillisecs>" << b->latencyms << "</lagmillisecs>";
138 data << "</serverlist>";
140 data << "</inspircdstats>";
142 /* Send the document back to m_httpd */
143 HTTPDocument response(http->sock, &data, 200);
144 response.headers.SetHeader("X-Powered-By", "m_httpd_stats.so");
145 response.headers.SetHeader("Content-Type", "text/xml");
146 Request req((char*)&response, (Module*)this, event->GetSource());
152 const char* OnRequest(Request* request)
158 virtual ~ModuleHttpStats()
162 virtual Version GetVersion()
164 return Version(1, 2, 0, 0, VF_VENDOR, API_VERSION);
168 MODULE_INIT(ModuleHttpStats)