]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_httpd_stats.cpp
Basic html output other than chickens
[user/henk/code/inspircd.git] / src / modules / m_httpd_stats.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                     E-mail:
7  *              <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *          the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include <stdio.h>
20 #include "users.h"
21 #include "channels.h"
22 #include "modules.h"
23 #include "inspsocket.h"
24 #include "helperfuncs.h"
25 #include "httpd.h"
26
27 /* $ModDesc: Provides statistics over HTTP via m_httpd.so */
28
29 class ModuleHttpStats : public Module
30 {
31         Server* Srv;
32         std::string stylesheet;
33
34  public:
35
36         void ReadConfig()
37         {
38                 ConfigReader c;
39                 this->stylesheet = c.ReadValue("httpstats", "stylesheet", 0);
40         }
41
42         ModuleHttpStats(Server* Me) : Module::Module(Me)
43         {
44                 Srv = Me;
45                 ReadConfig();
46         }
47
48         void OnEvent(Event* event)
49         {
50                 std::stringstream data("");
51
52                 if (event->GetEventID() == "httpd_url")
53                 {
54                         log(DEBUG,"HTTP URL!");
55
56                         data << "<HTML><HEAD>";
57                         data << "<TITLE>InspIRCd server statisitics for " << Srv->GetServerName() << " (" << Srv->GetServerDescription() << ")</TITLE>";
58                         data << "</HEAD><BODY>";
59                         data << "<H1>InspIRCd server statisitics for " << Srv->GetServerName() << " (" << Srv->GetServerDescription() << ")</H1>";
60                         
61                         data << "</BODY>";
62                         data << "</HTML>";
63
64                         HTTPRequest* http = (HTTPRequest*)event->GetData();
65                         HTTPDocument response(http->sock, &data, 200, "X-Powered-By: m_http_stats.so\r\n");
66                         Request req((char*)&response, (Module*)this, event->GetSource());
67                         req.Send();
68
69                         log(DEBUG,"Sent");
70                 }
71         }
72
73         char* OnRequest(Request* request)
74         {
75                 return NULL;
76         }
77
78         void Implements(char* List)
79         {
80                 List[I_OnEvent] = List[I_OnRequest] = 1;
81         }
82
83         virtual ~ModuleHttpStats()
84         {
85         }
86
87         virtual Version GetVersion()
88         {
89                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
90         }
91 };
92
93
94 class ModuleHttpStatsFactory : public ModuleFactory
95 {
96  public:
97         ModuleHttpStatsFactory()
98         {
99         }
100         
101         ~ModuleHttpStatsFactory()
102         {
103         }
104         
105         virtual Module * CreateModule(Server* Me)
106         {
107                 return new ModuleHttpStats(Me);
108         }
109 };
110
111
112 extern "C" void * init_module( void )
113 {
114         return new ModuleHttpStatsFactory;
115 }