1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 /* $ModDesc: Throttles the connections of any users who try connect flood */
19 class ModuleConnectBan : public Module
23 unsigned int threshold;
24 unsigned int banduration;
25 unsigned int ipv4_cidr;
26 unsigned int ipv6_cidr;
29 Implementation eventlist[] = { I_OnUserConnect, I_OnGarbageCollect, I_OnRehash };
30 ServerInstance->Modules->Attach(eventlist, this, 3);
34 virtual ~ModuleConnectBan()
38 virtual Version GetVersion()
40 return Version("Throttles the connections of any users who try connect flood", VF_VENDOR);
43 virtual void OnRehash(User* user)
48 ipv4_cidr = Conf.ReadInteger("connectban", "ipv4cidr", 0, true);
52 ipv6_cidr = Conf.ReadInteger("connectban", "ipv6cidr", 0, true);
56 threshold = Conf.ReadInteger("connectban", "threshold", 0, true);
61 duration = Conf.ReadValue("connectban", "duration", 0, true);
66 banduration = ServerInstance->Duration(duration);
69 virtual void OnUserConnect(LocalUser *u)
74 switch (u->client_sa.sa.sa_family)
84 irc::sockets::cidr_mask mask(u->client_sa, range);
85 i = connects.find(mask);
87 if (i != connects.end())
91 if (i->second >= threshold)
93 // Create zline for set duration.
94 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());
95 if (ServerInstance->XLines->AddLine(zl,NULL))
96 ServerInstance->XLines->ApplyLines();
100 ServerInstance->SNO->WriteGlobalSno('x',"Module m_connectban added Z:line on *@%s to expire on %s: Connect flooding",
101 mask.str().c_str(), ServerInstance->TimeString(zl->expiry).c_str());
102 ServerInstance->SNO->WriteGlobalSno('a', "Connect flooding from IP range %s (%d)", mask.str().c_str(), threshold);
112 virtual void OnGarbageCollect()
114 ServerInstance->Logs->Log("m_connectban",DEBUG, "Clearing map.");
119 MODULE_INIT(ModuleConnectBan)