2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
5 * Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
6 * Copyright (C) 2018-2019 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2017-2020 Sadie Powell <sadie@witchery.services>
8 * Copyright (C) 2014, 2016 Attila Molnar <attilamolnar@hush.com>
10 * This file is part of InspIRCd. InspIRCd is free software: you can
11 * redistribute it and/or modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation, version 2.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "core_xline.h"
28 bool InsaneBan::MatchesEveryone(const std::string& mask, MatcherBase& test, User* user, const char* bantype, const char* confkey)
30 ConfigTag* insane = ServerInstance->Config->ConfValue("insane");
32 if (insane->getBool(confkey))
35 float itrigger = insane->getFloat("trigger", 95.5, 0.0, 100.0);
37 long matches = test.Run(mask);
42 float percent = ((float)matches / (float)ServerInstance->Users->GetUsers().size()) * 100;
43 if (percent > itrigger)
45 ServerInstance->SNO->WriteToSnoMask('a', "\002WARNING\002: %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);
51 bool InsaneBan::IPHostMatcher::Check(User* user, const std::string& mask) const
53 return ((InspIRCd::MatchCIDR(user->MakeHost(), mask, ascii_case_insensitive_map)) ||
54 (InspIRCd::MatchCIDR(user->MakeHostIP(), mask, ascii_case_insensitive_map)));
57 class CoreModXLine : public Module
59 CommandEline cmdeline;
60 CommandGline cmdgline;
61 CommandKline cmdkline;
62 CommandQline cmdqline;
63 CommandZline cmdzline;
67 : cmdeline(this), cmdgline(this), cmdkline(this), cmdqline(this), cmdzline(this)
71 void OnSetUserIP(LocalUser* user) CXX11_OVERRIDE
76 user->exempt = (ServerInstance->XLines->MatchesLine("E", user) != NULL);
77 user->CheckLines(true);
80 void OnChangeRealHost(User* user, const std::string& newhost) CXX11_OVERRIDE
82 LocalUser* luser = IS_LOCAL(user);
83 if (!luser || luser->quitting)
86 luser->exempt = (ServerInstance->XLines->MatchesLine("E", user) != NULL);
87 luser->CheckLines(false);
90 ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) CXX11_OVERRIDE
92 // Check Q-lines (for local nick changes only, remote servers have our Q-lines to enforce themselves)
94 XLine* xline = ServerInstance->XLines->MatchesLine("Q", newnick);
96 return MOD_RES_PASSTHRU; // No match
98 // A Q-line matched the new nick, tell opers if the user is registered
99 if (user->registered == REG_ALL)
101 ServerInstance->SNO->WriteGlobalSno('x', "Q-lined nickname %s from %s: %s",
102 newnick.c_str(), user->GetFullRealHost().c_str(), xline->reason.c_str());
105 // Send a numeric because if we deny then the core doesn't reply anything
106 user->WriteNumeric(ERR_ERRONEUSNICKNAME, newnick, InspIRCd::Format("Invalid nickname: %s", xline->reason.c_str()));
110 void OnGarbageCollect() CXX11_OVERRIDE
112 // HACK: ELines are not expired properly at the moment but it can't be fixed
113 // as the XLine system is a spaghetti nightmare. Instead we skip over expired
114 // ELines in XLineManager::CheckELines() and expire them here instead.
115 ServerInstance->XLines->GetAll("E");
118 Version GetVersion() CXX11_OVERRIDE
120 return Version("Provides the ELINE, GLINE, KLINE, QLINE, and ZLINE commands", VF_VENDOR|VF_CORE);
124 MODULE_INIT(CoreModXLine)