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