]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_dnsbl.cpp
Add support for blacklists and whitelists, just http password auth to go (the most...
[user/henk/code/inspircd.git] / src / modules / m_dnsbl.cpp
index 5de6f2063218edd7e2e5429d9301ebe4d11d5281..b68767933619f25dfc5ad14e01f0ae03fad3c76b 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
 
 #include "inspircd.h"
 #include "xline.h"
-#include "dns.h"
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
 
 #ifndef WINDOWS
 #include <sys/types.h>
@@ -28,7 +24,7 @@
 /* $ModDesc: Provides handling of DNS blacklists */
 
 /* Class holding data for a single entry */
-class DNSBLConfEntry
+class DNSBLConfEntry : public classbase
 {
        public:
                enum EnumBanaction { I_UNKNOWN, I_KILL, I_ZLINE, I_KLINE, I_GLINE };
@@ -50,13 +46,13 @@ class DNSBLConfEntry
 class DNSBLResolver : public Resolver
 {
        int theirfd;
-       userrec* them;
+       User* them;
        DNSBLConfEntry *ConfEntry;
 
  public:
 
-       DNSBLResolver(Module *me, InspIRCd *ServerInstance, const std::string &hostname, userrec* u, int userfd, DNSBLConfEntry *conf, bool &cached)
-               : Resolver(ServerInstance, hostname, DNS_QUERY_A, cached, me)
+       DNSBLResolver(Module *me, InspIRCd *Instance, const std::string &hostname, User* u, int userfd, DNSBLConfEntry *conf, bool &cached)
+               : Resolver(Instance, hostname, DNS_QUERY_A, cached, me)
        {
                theirfd = userfd;
                them = u;
@@ -112,33 +108,43 @@ class DNSBLResolver : public Resolver
                                        {
                                                case DNSBLConfEntry::I_KILL:
                                                {
-                                                       userrec::QuitUser(ServerInstance, them, std::string("Killed (") + reason + ")");
+                                                       ServerInstance->Users->QuitUser(them, std::string("Killed (") + reason + ")");
                                                        break;
                                                }
                                                case DNSBLConfEntry::I_KLINE:
                                                {
-                                                       std::string ban = std::string("*@") + them->GetIPString();
-                                                       if (show)
-                                                               ServerInstance->XLines->apply_lines(APPLY_KLINES);                                                              
-                                                       show = ServerInstance->XLines->add_kline(ConfEntry->duration, ServerInstance->Config->ServerName, reason.c_str(), ban.c_str());
-                                                       FOREACH_MOD(I_OnAddKLine,OnAddKLine(ConfEntry->duration, NULL, reason, ban));
+                                                       KLine* kl = new KLine(ServerInstance, ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName, reason.c_str(),
+                                                                       "*", them->GetIPString());
+                                                       if (ServerInstance->XLines->AddLine(kl,NULL))
+                                                       {
+                                                               ServerInstance->XLines->ApplyLines();
+                                                       }
+                                                       else
+                                                               delete kl;
                                                        break;
                                                }
                                                case DNSBLConfEntry::I_GLINE:
                                                {
-                                                       std::string ban = std::string("*@") + them->GetIPString();
-                                                       show = ServerInstance->XLines->add_gline(ConfEntry->duration, ServerInstance->Config->ServerName, reason.c_str(), ban.c_str());
-                                                       if (show)
-                                                               ServerInstance->XLines->apply_lines(APPLY_GLINES);
-                                                       FOREACH_MOD(I_OnAddGLine,OnAddGLine(ConfEntry->duration, NULL, reason, ban));
+                                                       GLine* gl = new GLine(ServerInstance, ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName, reason.c_str(),
+                                                                       "*", them->GetIPString());
+                                                       if (ServerInstance->XLines->AddLine(gl,NULL))
+                                                       {
+                                                               ServerInstance->XLines->ApplyLines();
+                                                       }
+                                                       else
+                                                               delete gl;
                                                        break;
                                                }
                                                case DNSBLConfEntry::I_ZLINE:
                                                {
-                                                       show = ServerInstance->XLines->add_zline(ConfEntry->duration, ServerInstance->Config->ServerName, reason.c_str(), them->GetIPString());
-                                                       if (show)
-                                                               ServerInstance->XLines->apply_lines(APPLY_ZLINES);
-                                                       FOREACH_MOD(I_OnAddZLine,OnAddZLine(ConfEntry->duration, NULL, reason, them->GetIPString()));
+                                                       ZLine* zl = new ZLine(ServerInstance, ServerInstance->Time(), ConfEntry->duration, ServerInstance->Config->ServerName, reason.c_str(),
+                                                                       them->GetIPString());
+                                                       if (ServerInstance->XLines->AddLine(zl,NULL))
+                                                       {
+                                                               ServerInstance->XLines->ApplyLines();
+                                                       }
+                                                       else 
+                                                               delete zl;
                                                        break;
                                                }
                                                case DNSBLConfEntry::I_UNKNOWN:
@@ -150,7 +156,7 @@ class DNSBLResolver : public Resolver
 
                                        if (show)
                                        {
-                                               ServerInstance->WriteOpers("*** Connecting user %s detected as being on a DNS blacklist (%s) with result %d", them->GetFullRealHost(), ConfEntry->name.c_str(), bitmask);
+                                               ServerInstance->SNO->WriteToSnoMask('A', "Connecting user %s detected as being on a DNS blacklist (%s) with result %d", them->GetFullRealHost(), ConfEntry->name.c_str(), bitmask);
                                        }
                                }
                                else
@@ -195,6 +201,8 @@ class ModuleDNSBL : public Module
        ModuleDNSBL(InspIRCd *Me) : Module(Me)
        {
                ReadConf();
+               Implementation eventlist[] = { I_OnRehash, I_OnUserRegister, I_OnStats };
+               ServerInstance->Modules->Attach(eventlist, this, 3);
        }
 
        virtual ~ModuleDNSBL()
@@ -207,16 +215,11 @@ class ModuleDNSBL : public Module
                return Version(2, 0, 0, 1, VF_VENDOR, API_VERSION);
        }
 
-       void Implements(char* List)
-       {
-               List[I_OnRehash] = List[I_OnUserRegister] = List[I_OnStats] = 1;
-       }
 
        /** Clear entries and free the mem it was using
         */
        void ClearEntries()
        {
-               std::vector<DNSBLConfEntry *>::iterator i;
                for (std::vector<DNSBLConfEntry *>::iterator i = DNSBLConfEntries.begin(); i != DNSBLConfEntries.end(); i++)
                        delete *i;
                DNSBLConfEntries.clear();
@@ -260,25 +263,25 @@ class ModuleDNSBL : public Module
                        /* yeah, logic here is a little messy */
                        if (e->bitmask <= 0)
                        {
-                               ServerInstance->WriteOpers("*** DNSBL(#%d): invalid bitmask",i);
+                               ServerInstance->SNO->WriteToSnoMask('A', "DNSBL(#%d): invalid bitmask",i);
                        }
                        else if (e->name.empty())
                        {
-                               ServerInstance->WriteOpers("*** DNSBL(#%d): Invalid name",i);
+                               ServerInstance->SNO->WriteToSnoMask('A', "DNSBL(#%d): Invalid name",i);
                        }
                        else if (e->domain.empty())
                        {
-                               ServerInstance->WriteOpers("*** DNSBL(#%d): Invalid domain",i);
+                               ServerInstance->SNO->WriteToSnoMask('A', "DNSBL(#%d): Invalid domain",i);
                        }
                        else if (e->banaction == DNSBLConfEntry::I_UNKNOWN)
                        {
-                               ServerInstance->WriteOpers("*** DNSBL(#%d): Invalid banaction", i);
+                               ServerInstance->SNO->WriteToSnoMask('A', "DNSBL(#%d): Invalid banaction", i);
                        }
                        else
                        {
                                if (e->reason.empty())
                                {
-                                       ServerInstance->WriteOpers("*** DNSBL(#%d): empty reason, using defaults",i);
+                                       ServerInstance->SNO->WriteToSnoMask('A', "DNSBL(#%d): empty reason, using defaults",i);
                                        e->reason = "Your IP has been blacklisted.";
                                }
 
@@ -294,12 +297,12 @@ class ModuleDNSBL : public Module
                delete MyConf;
        }
 
-       virtual void OnRehash(userrec* user, const std::string &parameter)
+       virtual void OnRehash(User* user, const std::string &parameter)
        {
                ReadConf();
        }
 
-       virtual int OnUserRegister(userrec* user)
+       virtual int OnUserRegister(User* user)
        {
                /* only do lookups on local users */
                if (IS_LOCAL(user))
@@ -358,7 +361,7 @@ class ModuleDNSBL : public Module
                return 0;
        }
        
-       virtual int OnStats(char symbol, userrec* user, string_list &results)
+       virtual int OnStats(char symbol, User* user, string_list &results)
        {
                if (symbol != 'd')
                        return 0;