]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_xline/cmd_kline.cpp
71e21c0ef3da49f5c27253151b175353ec958908
[user/henk/code/inspircd.git] / src / coremods / core_xline / cmd_kline.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) 2018 Sadie Powell <sadie@witchery.services>
7  *   Copyright (C) 2012, 2018-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 Daniel De Graaf <danieldg@inspircd.org>
11  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
12  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
13  *   Copyright (C) 2006-2008, 2010 Craig Edwards <brain@inspircd.org>
14  *
15  * This file is part of InspIRCd.  InspIRCd is free software: you can
16  * redistribute it and/or modify it under the terms of the GNU General Public
17  * License as published by the Free Software Foundation, version 2.
18  *
19  * This program is distributed in the hope that it will be useful, but WITHOUT
20  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
22  * details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26  */
27
28
29 #include "inspircd.h"
30 #include "xline.h"
31 #include "core_xline.h"
32
33 CommandKline::CommandKline(Module* parent)
34         : Command(parent, "KLINE", 1, 3)
35 {
36         flags_needed = 'o';
37         syntax = "<user@host> [<duration> :<reason>]";
38 }
39
40 /** Handle /KLINE
41  */
42 CmdResult CommandKline::Handle(User* user, const Params& parameters)
43 {
44         std::string target = parameters[0];
45
46         if (parameters.size() >= 3)
47         {
48                 IdentHostPair ih;
49                 User* find = ServerInstance->FindNick(target);
50                 if ((find) && (find->registered == REG_ALL))
51                 {
52                         ih.first = "*";
53                         ih.second = find->GetIPString();
54                         target = std::string("*@") + find->GetIPString();
55                 }
56                 else
57                         ih = ServerInstance->XLines->IdentSplit(target);
58
59                 if (ih.first.empty())
60                 {
61                         user->WriteNotice("*** Target not found.");
62                         return CMD_FAILURE;
63                 }
64
65                 InsaneBan::IPHostMatcher matcher;
66                 if (InsaneBan::MatchesEveryone(ih.first+"@"+ih.second, matcher, user, "K", "hostmasks"))
67                         return CMD_FAILURE;
68
69                 if (target.find('!') != std::string::npos)
70                 {
71                         user->WriteNotice("*** K-line cannot operate on nick!user@host masks.");
72                         return CMD_FAILURE;
73                 }
74
75                 unsigned long duration;
76                 if (!InspIRCd::Duration(parameters[1], duration))
77                 {
78                         user->WriteNotice("*** Invalid duration for K-line.");
79                         return CMD_FAILURE;
80                 }
81                 KLine* kl = new KLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ih.first.c_str(), ih.second.c_str());
82                 if (ServerInstance->XLines->AddLine(kl,user))
83                 {
84                         if (!duration)
85                         {
86                                 ServerInstance->SNO->WriteToSnoMask('x', "%s added permanent K-line for %s: %s", user->nick.c_str(), target.c_str(), parameters[2].c_str());
87                         }
88                         else
89                         {
90                                 ServerInstance->SNO->WriteToSnoMask('x', "%s added timed K-line for %s, expires in %s (on %s): %s",
91                                         user->nick.c_str(), target.c_str(), InspIRCd::DurationString(duration).c_str(),
92                                         InspIRCd::TimeString(ServerInstance->Time() + duration).c_str(), parameters[2].c_str());
93                         }
94
95                         ServerInstance->XLines->ApplyLines();
96                 }
97                 else
98                 {
99                         delete kl;
100                         user->WriteNotice("*** K-line for " + target + " already exists.");
101                 }
102         }
103         else
104         {
105                 std::string reason;
106
107                 if (ServerInstance->XLines->DelLine(target.c_str(), "K", reason, user))
108                 {
109                         ServerInstance->SNO->WriteToSnoMask('x', "%s removed K-line on %s: %s", user->nick.c_str(), target.c_str(), reason.c_str());
110                 }
111                 else
112                 {
113                         user->WriteNotice("*** K-line " + target + " not found on the list.");
114                 }
115         }
116
117         return CMD_SUCCESS;
118 }