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 * ---------------------------------------------------
19 /* $ModDesc: Provides access control lists (passwording of resources, ip restrictions etc) to m_httpd.so dependent modules */
20 /* $ModDep: httpd.h */
22 class ACL : public Extensible
27 std::string whitelist;
28 std::string blacklist;
30 ACL(const std::string &set_path, const std::string &set_password,
31 const std::string &set_whitelist, const std::string &set_blacklist)
32 : path(set_path), password(set_password), whitelist(set_whitelist),
33 blacklist(set_blacklist) { }
38 class ModuleHTTPAccessList : public Module
41 std::string stylesheet;
43 std::vector<ACL> acl_list;
50 ConfigReader c(ServerInstance);
51 int n_items = c.Enumerate("httpacl");
52 for (int i = 0; i < n_items; ++i)
54 std::string path = c.ReadValue("httpacl", "path", i);
55 std::string types = c.ReadValue("httpacl", "types", i);
56 irc::commasepstream sep(types);
59 std::string whitelist;
60 std::string blacklist;
62 while (sep.GetToken(type))
64 if (type == "password")
66 password = c.ReadValue("httpacl", "password", i);
68 else if (type == "whitelist")
70 whitelist = c.ReadValue("httpacl", "whitelist", i);
72 else if (type == "blacklist")
74 blacklist = c.ReadValue("httpacl", "blacklist", i);
78 throw ModuleException("Invalid HTTP ACL type '" + type + "'");
82 acl_list.push_back(ACL(path, password, whitelist, blacklist));
86 ModuleHTTPAccessList(InspIRCd* Me) : Module(Me)
90 Implementation eventlist[] = { I_OnEvent, I_OnRequest };
91 ServerInstance->Modules->Attach(eventlist, this, 2);
94 void OnEvent(Event* event)
96 std::stringstream data("");
98 if (event->GetEventID() == "httpd_url")
100 ServerInstance->Logs->Log("m_http_stats", DEBUG,"Handling httpd event");
101 HTTPRequest* http = (HTTPRequest*)event->GetData();
103 for (std::vector<ACL>::const_iterator this_acl = acl_list.begin(); this_acl != acl_list.end(); ++this_acl)
105 if (match(http->GetURI(), this_acl->path))
107 if (!this_acl->blacklist.empty())
111 if (!this_acl->whitelist.empty())
115 if (!this_acl->password.empty())
122 //if ((http->GetURI() == "/stats") || (http->GetURI() == "/stats/"))
124 /* Send the document back to m_httpd */
125 // HTTPDocument response(http->sock, &data, 200);
126 // response.headers.SetHeader("X-Powered-By", "m_httpd_stats.so");
127 // response.headers.SetHeader("Content-Type", "text/xml");
128 // Request req((char*)&response, (Module*)this, event->GetSource());
134 const char* OnRequest(Request* request)
139 virtual ~ModuleHTTPAccessList()
143 virtual Version GetVersion()
145 return Version(1, 2, 0, 0, VF_VENDOR, API_VERSION);
149 MODULE_INIT(ModuleHTTPAccessList)