]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_xline/core_xline.cpp
ab80ab4ed50bfeba7d1b72dfdbeaafcad6718eb4
[user/henk/code/inspircd.git] / src / coremods / core_xline / core_xline.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
5  *
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.
9  *
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
13  * details.
14  *
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/>.
17  */
18
19
20 #include "inspircd.h"
21 #include "xline.h"
22 #include "core_xline.h"
23
24 bool InsaneBan::MatchesEveryone(const std::string& mask, MatcherBase& test, User* user, const char* bantype, const char* confkey)
25 {
26         ConfigTag* insane = ServerInstance->Config->ConfValue("insane");
27
28         if (insane->getBool(confkey))
29                 return false;
30
31         float itrigger = insane->getFloat("trigger", 95.5, 0.0, 100.0);
32
33         long matches = test.Run(mask);
34
35         if (!matches)
36                 return false;
37
38         float percent = ((float)matches / (float)ServerInstance->Users->GetUsers().size()) * 100;
39         if (percent > itrigger)
40         {
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);
42                 return true;
43         }
44         return false;
45 }
46
47 bool InsaneBan::IPHostMatcher::Check(User* user, const std::string& mask) const
48 {
49         return ((InspIRCd::MatchCIDR(user->MakeHost(), mask, ascii_case_insensitive_map)) ||
50                         (InspIRCd::MatchCIDR(user->MakeHostIP(), mask, ascii_case_insensitive_map)));
51 }
52
53 class CoreModXLine : public Module
54 {
55         CommandEline cmdeline;
56         CommandGline cmdgline;
57         CommandKline cmdkline;
58         CommandQline cmdqline;
59         CommandZline cmdzline;
60
61  public:
62         CoreModXLine()
63                 : cmdeline(this), cmdgline(this), cmdkline(this), cmdqline(this), cmdzline(this)
64         {
65         }
66
67         ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) CXX11_OVERRIDE
68         {
69                 // Check Q-Lines (for local nick changes only, remote servers have our Q-Lines to enforce themselves)
70
71                 XLine* xline = ServerInstance->XLines->MatchesLine("Q", newnick);
72                 if (!xline)
73                         return MOD_RES_PASSTHRU; // No match
74
75                 // A Q-Line matched the new nick, tell opers if the user is registered
76                 if (user->registered == REG_ALL)
77                 {
78                         ServerInstance->SNO->WriteGlobalSno('a', "Q-Lined nickname %s from %s: %s",
79                                 newnick.c_str(), user->GetFullRealHost().c_str(), xline->reason.c_str());
80                 }
81
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()));
84                 return MOD_RES_DENY;
85         }
86
87         Version GetVersion() CXX11_OVERRIDE
88         {
89                 return Version("Provides the ELINE, GLINE, KLINE, QLINE, and ZLINE commands", VF_VENDOR|VF_CORE);
90         }
91 };
92
93 MODULE_INIT(CoreModXLine)