]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_xline/cmd_zline.cpp
Fix a bunch of weird indentation and spacing issues.
[user/henk/code/inspircd.git] / src / coremods / core_xline / cmd_zline.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
5  *   Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
6  *   Copyright (C) 2017-2018 Sadie Powell <sadie@witchery.services>
7  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2012, 2014 Attila Molnar <attilamolnar@hush.com>
9  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
10  *   Copyright (C) 2009 Matt Smith <dz@inspircd.org>
11  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
12  *   Copyright (C) 2007-2008, 2010 Craig Edwards <brain@inspircd.org>
13  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
14  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
15  *
16  * This file is part of InspIRCd.  InspIRCd is free software: you can
17  * redistribute it and/or modify it under the terms of the GNU General Public
18  * License as published by the Free Software Foundation, version 2.
19  *
20  * This program is distributed in the hope that it will be useful, but WITHOUT
21  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
23  * details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27  */
28
29
30 #include "inspircd.h"
31 #include "xline.h"
32 #include "core_xline.h"
33
34 CommandZline::CommandZline(Module* parent)
35         : Command(parent, "ZLINE", 1, 3)
36 {
37         flags_needed = 'o';
38         syntax = "<ipmask> [<duration> :<reason>]";
39 }
40
41 CmdResult CommandZline::Handle(User* user, const Params& parameters)
42 {
43         std::string target = parameters[0];
44
45         if (parameters.size() >= 3)
46         {
47                 if (target.find('!') != std::string::npos)
48                 {
49                         user->WriteNotice("*** You cannot include a nickname in a Z-line, a Z-line must ban only an IP mask.");
50                         return CMD_FAILURE;
51                 }
52
53                 User *u = ServerInstance->FindNick(target);
54
55                 if ((u) && (u->registered == REG_ALL))
56                 {
57                         target = u->GetIPString();
58                 }
59
60                 const char* ipaddr = target.c_str();
61
62                 if (strchr(ipaddr,'@'))
63                 {
64                         while (*ipaddr != '@')
65                                 ipaddr++;
66                         ipaddr++;
67                 }
68
69                 IPMatcher matcher;
70                 if (InsaneBan::MatchesEveryone(ipaddr, matcher, user, "Z", "ipmasks"))
71                         return CMD_FAILURE;
72
73                 unsigned long duration;
74                 if (!InspIRCd::Duration(parameters[1], duration))
75                 {
76                         user->WriteNotice("*** Invalid duration for Z-line.");
77                         return CMD_FAILURE;
78                 }
79                 ZLine* zl = new ZLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ipaddr);
80                 if (ServerInstance->XLines->AddLine(zl,user))
81                 {
82                         if (!duration)
83                         {
84                                 ServerInstance->SNO->WriteToSnoMask('x', "%s added permanent Z-line for %s: %s", user->nick.c_str(), ipaddr, parameters[2].c_str());
85                         }
86                         else
87                         {
88                                 ServerInstance->SNO->WriteToSnoMask('x', "%s added timed Z-line for %s, expires in %s (on %s): %s",
89                                         user->nick.c_str(), ipaddr, InspIRCd::DurationString(duration).c_str(),
90                                         InspIRCd::TimeString(ServerInstance->Time() + duration).c_str(), parameters[2].c_str());
91                         }
92                         ServerInstance->XLines->ApplyLines();
93                 }
94                 else
95                 {
96                         delete zl;
97                         user->WriteNotice("*** Z-line for " + std::string(ipaddr) + " already exists.");
98                 }
99         }
100         else
101         {
102                 std::string reason;
103
104                 if (ServerInstance->XLines->DelLine(target.c_str(), "Z", reason, user))
105                 {
106                         ServerInstance->SNO->WriteToSnoMask('x', "%s removed Z-line on %s: %s", user->nick.c_str(), target.c_str(), reason.c_str());
107                 }
108                 else
109                 {
110                         user->WriteNotice("*** Z-line " + target + " not found on the list.");
111                         return CMD_FAILURE;
112                 }
113         }
114
115         return CMD_SUCCESS;
116 }
117
118 bool CommandZline::IPMatcher::Check(User* user, const std::string& ip) const
119 {
120         return InspIRCd::MatchCIDR(user->GetIPString(), ip, ascii_case_insensitive_map);
121 }