X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmodules%2Fm_connectban.cpp;h=f831a3b77b1ba50873c374efe77a065f29d8d1ed;hb=44f42a13de52c8025942ddab42f51feb36821782;hp=19408046fcc4356889d07d8e31d5090140bfae68;hpb=0da6b3a13def40e8fd002b9fc60f955467f6372d;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_connectban.cpp b/src/modules/m_connectban.cpp index 19408046f..f831a3b77 100644 --- a/src/modules/m_connectban.cpp +++ b/src/modules/m_connectban.cpp @@ -1,16 +1,22 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://wiki.inspircd.org/Credits + * Copyright (C) 2008 Robin Burchell * - * This program is free but copyrighted software; see - * the file COPYING for details. + * 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 . */ + #include "inspircd.h" #include "xline.h" @@ -25,8 +31,7 @@ class ModuleConnectBan : public Module unsigned int ipv4_cidr; unsigned int ipv6_cidr; public: - ModuleConnectBan(InspIRCd* Me) : Module(Me) - { + ModuleConnectBan() { Implementation eventlist[] = { I_OnUserConnect, I_OnGarbageCollect, I_OnRehash }; ServerInstance->Modules->Attach(eventlist, this, 3); OnRehash(NULL); @@ -38,12 +43,12 @@ class ModuleConnectBan : public Module virtual Version GetVersion() { - return Version("$Id$", VF_VENDOR,API_VERSION); + return Version("Throttles the connections of any users who try connect flood", VF_VENDOR); } virtual void OnRehash(User* user) { - ConfigReader Conf(ServerInstance); + ConfigReader Conf; std::string duration; ipv4_cidr = Conf.ReadInteger("connectban", "ipv4cidr", 0, true); @@ -67,28 +72,23 @@ class ModuleConnectBan : public Module banduration = ServerInstance->Duration(duration); } - virtual void OnUserConnect(User *u) + virtual void OnUserConnect(LocalUser *u) { int range = 32; clonemap::iterator i; - switch (u->GetProtocolFamily()) + switch (u->client_sa.sa.sa_family) { - #ifdef SUPPORT_IP6LINKS case AF_INET6: - { range = ipv6_cidr; - } break; - #endif case AF_INET: - { range = ipv4_cidr; - } break; } - i = connects.find(u->GetCIDRMask(range)); + irc::sockets::cidr_mask mask(u->client_sa, range); + i = connects.find(mask); if (i != connects.end()) { @@ -97,19 +97,21 @@ class ModuleConnectBan : public Module if (i->second >= threshold) { // Create zline for set duration. - ZLine* zl = new ZLine(ServerInstance, ServerInstance->Time(), banduration, ServerInstance->Config->ServerName, "Connect flooding", u->GetCIDRMask(range)); + ZLine* zl = new ZLine(ServerInstance->Time(), banduration, ServerInstance->Config->ServerName, "Your IP range has been attempting to connect too many times in too short a duration. Wait a while, and you will be able to connect.", mask.str()); if (ServerInstance->XLines->AddLine(zl,NULL)) ServerInstance->XLines->ApplyLines(); else delete zl; - ServerInstance->SNO->WriteToSnoMask('x', "Connect flooding from IP range %s (%d)", u->GetCIDRMask(range), threshold); + ServerInstance->SNO->WriteGlobalSno('x',"Module m_connectban added Z:line on *@%s to expire on %s: Connect flooding", + mask.str().c_str(), ServerInstance->TimeString(zl->expiry).c_str()); + ServerInstance->SNO->WriteGlobalSno('a', "Connect flooding from IP range %s (%d)", mask.str().c_str(), threshold); connects.erase(i); } } else { - connects[u->GetCIDRMask(range)] = 1; + connects[mask] = 1; } }