]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_httpd_config.cpp
Fix some of the include guard names (requested by SaberUK)
[user/henk/code/inspircd.git] / src / modules / m_httpd_config.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "httpd.h"
16 #include "protocol.h"
17
18 /* $ModDesc: Provides statistics over HTTP via m_httpd.so */
19
20 class ModuleHttpConfig : public Module
21 {
22  public:
23         ModuleHttpConfig()      {
24                 Implementation eventlist[] = { I_OnEvent };
25                 ServerInstance->Modules->Attach(eventlist, this, 1);
26         }
27
28         std::string Sanitize(const std::string &str)
29         {
30                 std::string ret;
31
32                 for (std::string::const_iterator x = str.begin(); x != str.end(); ++x)
33                 {
34                         switch (*x)
35                         {
36                                 case '<':
37                                         ret += "&lt;";
38                                 break;
39                                 case '>':
40                                         ret += "&gt;";
41                                 break;
42                                 case '&':
43                                         ret += "&amp;";
44                                 break;
45                                 case '"':
46                                         ret += "&quot;";
47                                 break;
48                                 default:
49                                         if (*x < 32 || *x > 126)
50                                         {
51                                                 int n = *x;
52                                                 ret += ("&#" + ConvToStr(n) + ";");
53                                         }
54                                         else
55                                                 ret += *x;
56                                 break;
57                         }
58                 }
59                 return ret;
60         }
61
62         void OnEvent(Event& event)
63         {
64                 std::stringstream data("");
65
66                 if (event.id == "httpd_url")
67                 {
68                         ServerInstance->Logs->Log("m_http_stats", DEBUG,"Handling httpd event");
69                         HTTPRequest* http = (HTTPRequest*)&event;
70
71                         if ((http->GetURI() == "/config") || (http->GetURI() == "/config/"))
72                         {
73                                 data << "<html><head><title>InspIRCd Configuration</title></head><body>";
74                                 data << "<h1>InspIRCd Configuration</h1><p>";
75
76                                 for (ConfigDataHash::iterator x = ServerInstance->Config->config_data.begin(); x != ServerInstance->Config->config_data.end(); ++x)
77                                 {
78                                         data << "&lt;" << x->first << " ";
79                                         ConfigTag* tag = x->second;
80                                         for (std::vector<KeyVal>::const_iterator j = tag->getItems().begin(); j != tag->getItems().end(); j++)
81                                         {
82                                                 data << Sanitize(j->first) << "=&quot;" << Sanitize(j->second) << "&quot; ";
83                                         }
84                                         data << "&gt;<br>";
85                                 }
86
87                                 data << "</body></html>";
88                                 /* Send the document back to m_httpd */
89                                 HTTPDocumentResponse response(this, *http, &data, 200);
90                                 response.headers.SetHeader("X-Powered-By", "m_httpd_config.so");
91                                 response.headers.SetHeader("Content-Type", "text/html");
92                                 response.Send();
93                         }
94                 }
95         }
96
97         virtual ~ModuleHttpConfig()
98         {
99         }
100
101         virtual Version GetVersion()
102         {
103                 return Version("Provides configuration over HTTP via m_httpd.so", VF_VENDOR);
104         }
105 };
106
107 MODULE_INIT(ModuleHttpConfig)