]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add support for blacklists and whitelists, just http password auth to go (the most...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Mon, 12 May 2008 19:37:50 +0000 (19:37 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Mon, 12 May 2008 19:37:50 +0000 (19:37 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9711 e03df62e-2008-0410-955e-edbf42e46eb7

src/modules/m_httpd_acl.cpp

index 18270507ca627840d5ce4c0069a58c2c8c885284..903e83f26e8ea1dc92b8a3a9da0d61f7264860a7 100644 (file)
@@ -91,6 +91,15 @@ class ModuleHTTPAccessList : public Module
                ServerInstance->Modules->Attach(eventlist, this, 2);
        }
 
+       void BlockAccess(HTTPRequest* http, Event* event)
+       {
+               std::stringstream data("Access to this resource is denied by an access control list. Please contact your IRC administrator.");
+               HTTPDocument response(http->sock, &data, 403);
+               response.headers.SetHeader("X-Powered-By", "m_httpd_acl.so");
+               Request req((char*)&response, (Module*)this, event->GetSource());
+               req.Send();
+       }
+
        void OnEvent(Event* event)
        {
                std::stringstream data("");
@@ -107,27 +116,43 @@ class ModuleHTTPAccessList : public Module
                                        if (!this_acl->blacklist.empty())
                                        {
                                                /* Blacklist */
+                                               irc::commasepstream sep(this_acl->blacklist);
+                                               std::string entry;
+
+                                               while (sep.GetToken(entry))
+                                               {
+                                                       if (match(http->GetIP(), entry))
+                                                       {
+                                                               BlockAccess(http, event);
+                                                               return;
+                                                       }
+                                               }
                                        }
                                        if (!this_acl->whitelist.empty())
                                        {
                                                /* Whitelist */
+                                               irc::commasepstream sep(this_acl->whitelist);
+                                               std::string entry;
+                                               bool allow_access = false;
+
+                                               while (sep.GetToken(entry))
+                                               {
+                                                       if (match(http->GetIP(), entry))
+                                                               allow_access = true;
+                                               }
+
+                                               if (!allow_access)
+                                               {
+                                                       BlockAccess(http, event);
+                                                       return;
+                                               }
                                        }
                                        if (!this_acl->password.empty())
                                        {
-                                               /* Password auth */
+                                               /* Password auth, first look to see if we have a basic authentication header */
                                        }
                                }
                        }
-
-                       //if ((http->GetURI() == "/stats") || (http->GetURI() == "/stats/"))
-                       //{
-                               /* Send the document back to m_httpd */
-                       //      HTTPDocument response(http->sock, &data, 200);
-                       //      response.headers.SetHeader("X-Powered-By", "m_httpd_stats.so");
-                       //      response.headers.SetHeader("Content-Type", "text/xml");
-                       //      Request req((char*)&response, (Module*)this, event->GetSource());
-                       //      req.Send();
-                       //}
                }
        }