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