1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/*
* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2012 Chin Lee <kwangchin@gmail.com>
*
* This file is part of InspIRCd. InspIRCd is free software: you can
* redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* $ModDesc: Provides rehash over HTTP via m_httpd.so */
#include "inspircd.h"
#include "threadengine.h"
#include "httpd.h"
#include "protocol.h"
class ModuleHttpRehash : public Module
{
public:
void init()
{
Implementation eventlist[] = { I_OnEvent };
ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
}
void OnEvent(Event& event)
{
std::stringstream data("");
if (event.id == "httpd_url")
{
ServerInstance->Logs->Log("m_http_stats", DEBUG,"Handling httpd rehash event");
HTTPRequest* http = (HTTPRequest*)&event;
if ((http->GetURI() == "/rehash") || (http->GetURI() == "/rehash/"))
{
if (!ServerInstance->PendingRehash)
{
data << "Rehashed";
ServerInstance->SNO->WriteToSnoMask('a', "Rehashing config file %s from HTTP request from %s", ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()), http->GetIP().c_str());
ServerInstance->PendingRehash = new ConfigReaderThread("");
ServerInstance->Threads->Submit(ServerInstance->PendingRehash);
} else {
data << "Rehashing";
}
/* Send the document back to m_httpd */
HTTPDocumentResponse response(&data, 200);
response.headers.SetHeader("X-Powered-By", "m_httpd_rehash.so");
response.headers.SetHeader("Content-Type", "text/html");
http->Respond(response);
}
}
}
virtual ~ModuleHttpRehash()
{
}
virtual Version GetVersion()
{
return Version("Provides rehash over HTTP via m_httpd.so", VF_VENDOR);
}
};
MODULE_INIT(ModuleHttpRehash)
|