1 |
/** |
2 |
* ignore.C: This file contains functionality which implements the OperServ IGNORE command. |
3 |
* |
4 |
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
5 |
* Rights to this code are as documented in COPYING. |
6 |
* |
7 |
* |
8 |
* Portions of this file were derived from sources bearing the following license: |
9 |
* Copyright © 2006 Patrick Fish, et al |
10 |
* Rights to this code are documented in doc/pod/license.pod. |
11 |
* |
12 |
* $Id: ignore.C,v 1.7 2007-09-16 18:54:44 pippijn Exp $ |
13 |
*/ |
14 |
|
15 |
#include "atheme.h" |
16 |
#include <libermyth.h> |
17 |
#include <ermyth/module.h> |
18 |
#include <account/svsignore.h> |
19 |
|
20 |
static char const rcsid[] = "$Id: ignore.C,v 1.7 2007-09-16 18:54:44 pippijn Exp $"; |
21 |
|
22 |
REGISTER_MODULE ("operserv/ignore", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
23 |
|
24 |
static void os_cmd_ignore (sourceinfo_t *si, int parc, char *parv[]); |
25 |
static void os_cmd_ignore_add (sourceinfo_t *si, int parc, char *parv[]); |
26 |
static void os_cmd_ignore_del (sourceinfo_t *si, int parc, char *parv[]); |
27 |
static void os_cmd_ignore_list (sourceinfo_t *si, int parc, char *parv[]); |
28 |
static void os_cmd_ignore_clear (sourceinfo_t *si, int parc, char *parv[]); |
29 |
|
30 |
command_t const os_ignore = { "IGNORE", N_("Ignore a mask from services."), PRIV_ADMIN, 3, os_cmd_ignore }; |
31 |
command_t const os_ignore_add = { "ADD", N_("Add services ignore"), PRIV_ADMIN, 2, os_cmd_ignore_add }; |
32 |
command_t const os_ignore_del = { "DEL", N_("Delete services ignore"), PRIV_ADMIN, 1, os_cmd_ignore_del }; |
33 |
command_t const os_ignore_list = { "LIST", N_("List services ignores"), PRIV_ADMIN, 0, os_cmd_ignore_list }; |
34 |
command_t const os_ignore_clear = { "CLEAR", N_("Clear all services ignores"), PRIV_ADMIN, 0, os_cmd_ignore_clear }; |
35 |
|
36 |
E cmdvec os_cmdtree; |
37 |
E helpvec os_helptree; |
38 |
cmdvec os_ignore_cmds; |
39 |
|
40 |
bool |
41 |
_modinit (module *m) |
42 |
{ |
43 |
os_cmdtree << os_ignore; |
44 |
help_addentry (os_helptree, "IGNORE", "help/operserv/ignore", NULL); |
45 |
|
46 |
/* Sub-commands */ |
47 |
os_ignore_cmds << os_ignore_add; |
48 |
os_ignore_cmds << os_ignore_del; |
49 |
os_ignore_cmds << os_ignore_clear; |
50 |
os_ignore_cmds << os_ignore_list; |
51 |
|
52 |
use_svsignore++; |
53 |
|
54 |
return true; |
55 |
} |
56 |
|
57 |
void |
58 |
_moddeinit () |
59 |
{ |
60 |
os_cmdtree >> os_ignore; |
61 |
help_delentry (os_helptree, "IGNORE"); |
62 |
|
63 |
/* Sub-commands */ |
64 |
os_ignore_cmds >> os_ignore_add; |
65 |
os_ignore_cmds >> os_ignore_del; |
66 |
os_ignore_cmds >> os_ignore_list; |
67 |
os_ignore_cmds >> os_ignore_clear; |
68 |
|
69 |
use_svsignore--; |
70 |
} |
71 |
|
72 |
static void |
73 |
os_cmd_ignore (sourceinfo_t *si, int parc, char *parv[]) |
74 |
{ |
75 |
char *cmd = parv[0]; |
76 |
command_t const *c; |
77 |
|
78 |
if (!cmd) |
79 |
{ |
80 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "IGNORE"); |
81 |
command_fail (si, fault::needmoreparams, _("Syntax: IGNORE ADD|DEL|LIST|CLEAR <mask>")); |
82 |
return; |
83 |
} |
84 |
|
85 |
c = os_ignore_cmds.find (cmd); |
86 |
if (c == NULL) |
87 |
{ |
88 |
command_fail (si, fault::badparams, _("Invalid command. Use \2/%s%s help\2 for a command listing."), (ircd->uses_rcommand == false) ? "msg " : "", opersvs.me->disp); |
89 |
return; |
90 |
} |
91 |
|
92 |
c->exec (si->service, si, parc - 1, parv + 1); |
93 |
|
94 |
} |
95 |
|
96 |
static void |
97 |
os_cmd_ignore_add (sourceinfo_t *si, int parc, char *parv[]) |
98 |
{ |
99 |
svsignore_vector::iterator it, it_end; |
100 |
char *target = parv[0]; |
101 |
char *reason = parv[1]; |
102 |
svsignore_t *svsignore; |
103 |
|
104 |
if (target == NULL) |
105 |
{ |
106 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "IGNORE"); |
107 |
command_fail (si, fault::needmoreparams, _("Syntax: IGNORE ADD|DEL|LIST|CLEAR <mask>")); |
108 |
return; |
109 |
} |
110 |
|
111 |
if (!validhostmask (target)) |
112 |
{ |
113 |
command_fail (si, fault::badparams, _("Invalid host mask, %s"), target); |
114 |
return; |
115 |
} |
116 |
|
117 |
/* Are we already ignoring this mask? */ |
118 |
for (it = svs_ignore_list.begin (), it_end = svs_ignore_list.end (); it != it_end; ++it) |
119 |
{ |
120 |
svsignore = *it; |
121 |
|
122 |
/* We're here */ |
123 |
if (!strcasecmp (svsignore->mask, target)) |
124 |
{ |
125 |
command_fail (si, fault::nochange, _("The mask \2%s\2 already exists on the services ignore list."), svsignore->mask); |
126 |
return; |
127 |
} |
128 |
} |
129 |
|
130 |
svsignore = svsignore_add (target, reason); |
131 |
svsignore->setby = sstrdup (get_oper_name (si)); |
132 |
svsignore->settime = NOW; |
133 |
|
134 |
command_success_nodata (si, _("\2%s\2 has been added to the services ignore list."), target); |
135 |
|
136 |
logcommand (si, CMDLOG_ADMIN, "IGNORE ADD %s %s", target, reason); |
137 |
wallops ("%s added a services ignore for \2%s\2 (%s).", get_oper_name (si), target, reason); |
138 |
snoop ("IGNORE:ADD: \2%s\2 by \2%s\2 (%s)", target, get_oper_name (si), reason); |
139 |
|
140 |
return; |
141 |
} |
142 |
|
143 |
static void |
144 |
os_cmd_ignore_del (sourceinfo_t *si, int parc, char *parv[]) |
145 |
{ |
146 |
char *target = parv[0]; |
147 |
svsignore_vector::iterator it, it_end; |
148 |
svsignore_t *svsignore; |
149 |
|
150 |
if (target == NULL) |
151 |
{ |
152 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "IGNORE"); |
153 |
command_fail (si, fault::needmoreparams, _("Syntax: IGNORE ADD|DEL|LIST|CLEAR <mask>")); |
154 |
return; |
155 |
} |
156 |
|
157 |
for (it = svs_ignore_list.begin (), it_end = svs_ignore_list.end (); it != it_end; ++it) |
158 |
{ |
159 |
svsignore = *it; |
160 |
|
161 |
if (!strcasecmp (svsignore->mask, target)) |
162 |
{ |
163 |
command_success_nodata (si, _("\2%s\2 has been removed from the services ignore list."), svsignore->mask); |
164 |
|
165 |
svsignore_delete (svsignore); |
166 |
|
167 |
wallops ("%s removed \2%s\2 from the services ignore list.", get_oper_name (si), target); |
168 |
snoop ("IGNORE:DEL: \2%s\2 by \2%s\2", target, get_oper_name (si)); |
169 |
logcommand (si, CMDLOG_ADMIN, "IGNORE DEL %s", target); |
170 |
|
171 |
return; |
172 |
} |
173 |
} |
174 |
|
175 |
command_fail (si, fault::nosuch_target, _("\2%s\2 was not found on the services ignore list."), target); |
176 |
return; |
177 |
} |
178 |
|
179 |
static void |
180 |
os_cmd_ignore_clear (sourceinfo_t *si, int parc, char *parv[]) |
181 |
{ |
182 |
svsignore_vector::iterator it, it_end; |
183 |
svsignore_t *svsignore; |
184 |
|
185 |
if (svs_ignore_list.empty ()) |
186 |
{ |
187 |
command_success_nodata (si, _("Services ignore list is empty.")); |
188 |
return; |
189 |
} |
190 |
|
191 |
while (!svs_ignore_list.empty ()) |
192 |
{ |
193 |
svsignore = svs_ignore_list.back (); |
194 |
|
195 |
command_success_nodata (si, _("\2%s\2 has been removed from the services ignore list."), svsignore->mask); |
196 |
svs_ignore_list.erase (svsignore); |
197 |
sfree (svsignore->mask); |
198 |
sfree (svsignore->setby); |
199 |
sfree (svsignore->reason); |
200 |
} |
201 |
|
202 |
command_success_nodata (si, _("Services ignore list has been wiped!")); |
203 |
|
204 |
wallops ("\2%s\2 wiped the services ignore list.", get_oper_name (si)); |
205 |
snoop ("IGNORE:CLEAR: by \2%s\2", get_oper_name (si)); |
206 |
logcommand (si, CMDLOG_ADMIN, "IGNORE CLEAR"); |
207 |
|
208 |
return; |
209 |
} |
210 |
|
211 |
|
212 |
static void |
213 |
os_cmd_ignore_list (sourceinfo_t *si, int parc, char *parv[]) |
214 |
{ |
215 |
svsignore_vector::iterator it, it_end; |
216 |
unsigned int i = 1; |
217 |
svsignore_t *svsignore; |
218 |
char strfbuf[32]; |
219 |
struct tm tm; |
220 |
|
221 |
if (svs_ignore_list.empty ()) |
222 |
{ |
223 |
command_success_nodata (si, _("The services ignore list is empty.")); |
224 |
return; |
225 |
} |
226 |
|
227 |
command_success_nodata (si, _("Current Ignore list entries:")); |
228 |
command_success_nodata (si, "-------------------------"); |
229 |
|
230 |
for (it = svs_ignore_list.begin (), it_end = svs_ignore_list.end (); it != it_end; ++it) |
231 |
{ |
232 |
svsignore = *it; |
233 |
|
234 |
tm = *localtime (&svsignore->settime); |
235 |
strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm); |
236 |
|
237 |
command_success_nodata (si, _("%d: %s by %s on %s (Reason: %s)"), i, svsignore->mask, svsignore->setby, strfbuf, svsignore->reason); |
238 |
i++; |
239 |
} |
240 |
|
241 |
command_success_nodata (si, "-------------------------"); |
242 |
|
243 |
logcommand (si, CMDLOG_ADMIN, "IGNORE LIST"); |
244 |
|
245 |
return; |
246 |
} |