2 * InspIRCd -- Internet Relay Chat Daemon
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>
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.
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
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/>.
32 #include "core_xline.h"
34 CommandZline::CommandZline(Module* parent)
35 : Command(parent, "ZLINE", 1, 3)
38 syntax = "<ipmask> [<duration> :<reason>]";
41 CmdResult CommandZline::Handle(User* user, const Params& parameters)
43 std::string target = parameters[0];
45 if (parameters.size() >= 3)
47 if (target.find('!') != std::string::npos)
49 user->WriteNotice("*** You cannot include a nickname in a Z-line, a Z-line must ban only an IP mask.");
53 User *u = ServerInstance->FindNick(target);
55 if ((u) && (u->registered == REG_ALL))
57 target = u->GetIPString();
60 const char* ipaddr = target.c_str();
62 if (strchr(ipaddr,'@'))
64 while (*ipaddr != '@')
70 if (InsaneBan::MatchesEveryone(ipaddr, matcher, user, "Z", "ipmasks"))
73 unsigned long duration;
74 if (!InspIRCd::Duration(parameters[1], duration))
76 user->WriteNotice("*** Invalid duration for Z-line.");
79 ZLine* zl = new ZLine(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), ipaddr);
80 if (ServerInstance->XLines->AddLine(zl,user))
84 ServerInstance->SNO->WriteToSnoMask('x', "%s added permanent Z-line for %s: %s", user->nick.c_str(), ipaddr, parameters[2].c_str());
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());
92 ServerInstance->XLines->ApplyLines();
97 user->WriteNotice("*** Z-line for " + std::string(ipaddr) + " already exists.");
104 if (ServerInstance->XLines->DelLine(target.c_str(), "Z", reason, user))
106 ServerInstance->SNO->WriteToSnoMask('x', "%s removed Z-line on %s: %s", user->nick.c_str(), target.c_str(), reason.c_str());
110 user->WriteNotice("*** Z-line " + target + " not found on the list.");
118 bool CommandZline::IPMatcher::Check(User* user, const std::string& ip) const
120 return InspIRCd::MatchCIDR(user->GetIPString(), ip, ascii_case_insensitive_map);