2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "core_xline.h"
24 bool InsaneBan::MatchesEveryone(const std::string& mask, MatcherBase& test, User* user, const char* bantype, const char* confkey)
26 ConfigTag* insane = ServerInstance->Config->ConfValue("insane");
28 if (insane->getBool(confkey))
31 float itrigger = insane->getFloat("trigger", 95.5);
33 long matches = test.Run(mask);
38 float percent = ((float)matches / (float)ServerInstance->Users->GetUsers().size()) * 100;
39 if (percent > itrigger)
41 ServerInstance->SNO->WriteToSnoMask('a', "\2WARNING\2: %s tried to set a %s-line mask of %s, which covers %.2f%% of the network!", user->nick.c_str(), bantype, mask.c_str(), percent);
47 bool InsaneBan::IPHostMatcher::Check(User* user, const std::string& mask) const
49 return ((InspIRCd::Match(user->MakeHost(), mask, ascii_case_insensitive_map)) ||
50 (InspIRCd::Match(user->MakeHostIP(), mask, ascii_case_insensitive_map)));
53 class CoreModXLine : public Module
55 CommandEline cmdeline;
56 CommandGline cmdgline;
57 CommandKline cmdkline;
58 CommandQline cmdqline;
59 CommandZline cmdzline;
63 : cmdeline(this), cmdgline(this), cmdkline(this), cmdqline(this), cmdzline(this)
67 ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) CXX11_OVERRIDE
69 // Check Q-Lines (for local nick changes only, remote servers have our Q-Lines to enforce themselves)
71 XLine* xline = ServerInstance->XLines->MatchesLine("Q", newnick);
73 return MOD_RES_PASSTHRU; // No match
75 // A Q-Line matched the new nick, tell opers if the user is registered
76 if (user->registered == REG_ALL)
78 ServerInstance->SNO->WriteGlobalSno('a', "Q-Lined nickname %s from %s: %s",
79 newnick.c_str(), user->GetFullRealHost().c_str(), xline->reason.c_str());
82 // Send a numeric because if we deny then the core doesn't reply anything
83 user->WriteNumeric(ERR_ERRONEUSNICKNAME, newnick, InspIRCd::Format("Invalid nickname: %s", xline->reason.c_str()));
87 Version GetVersion() CXX11_OVERRIDE
89 return Version("Provides the ELINE, GLINE, KLINE, QLINE, and ZLINE commands", VF_VENDOR|VF_CORE);
93 MODULE_INIT(CoreModXLine)