1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/*
* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
*
* This file is part of InspIRCd. InspIRCd is free software: you can
* redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "inspircd.h"
#include "xline.h"
#include "core_xline.h"
bool InsaneBan::MatchesEveryone(const std::string& mask, MatcherBase& test, User* user, const char* bantype, const char* confkey)
{
ConfigTag* insane = ServerInstance->Config->ConfValue("insane");
if (insane->getBool(confkey))
return false;
float itrigger = insane->getFloat("trigger", 95.5);
long matches = test.Run(mask);
if (!matches)
return false;
float percent = ((float)matches / (float)ServerInstance->Users->GetUsers().size()) * 100;
if (percent > itrigger)
{
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);
return true;
}
return false;
}
bool InsaneBan::IPHostMatcher::Check(User* user, const std::string& mask) const
{
return ((InspIRCd::MatchCIDR(user->MakeHost(), mask, ascii_case_insensitive_map)) ||
(InspIRCd::MatchCIDR(user->MakeHostIP(), mask, ascii_case_insensitive_map)));
}
class CoreModXLine : public Module
{
CommandEline cmdeline;
CommandGline cmdgline;
CommandKline cmdkline;
CommandQline cmdqline;
CommandZline cmdzline;
public:
CoreModXLine()
: cmdeline(this), cmdgline(this), cmdkline(this), cmdqline(this), cmdzline(this)
{
}
ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) CXX11_OVERRIDE
{
// Check Q-Lines (for local nick changes only, remote servers have our Q-Lines to enforce themselves)
XLine* xline = ServerInstance->XLines->MatchesLine("Q", newnick);
if (!xline)
return MOD_RES_PASSTHRU; // No match
// A Q-Line matched the new nick, tell opers if the user is registered
if (user->registered == REG_ALL)
{
ServerInstance->SNO->WriteGlobalSno('a', "Q-Lined nickname %s from %s: %s",
newnick.c_str(), user->GetFullRealHost().c_str(), xline->reason.c_str());
}
// Send a numeric because if we deny then the core doesn't reply anything
user->WriteNumeric(ERR_ERRONEUSNICKNAME, newnick, InspIRCd::Format("Invalid nickname: %s", xline->reason.c_str()));
return MOD_RES_DENY;
}
Version GetVersion() CXX11_OVERRIDE
{
return Version("Provides the ELINE, GLINE, KLINE, QLINE, and ZLINE commands", VF_VENDOR|VF_CORE);
}
};
MODULE_INIT(CoreModXLine)
|