| 1 |
/* |
| 2 |
* Copyright (c) 2006 Patrick Fish, et al |
| 3 |
* Rights to this code are documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* This file contains functionality which implements the OService IGNORE command. |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "atheme.h" |
| 10 |
|
| 11 |
DECLARE_MODULE_V1 |
| 12 |
( |
| 13 |
"operserv/ignore", false, _modinit, _moddeinit, |
| 14 |
PACKAGE_STRING, |
| 15 |
VENDOR_STRING |
| 16 |
); |
| 17 |
|
| 18 |
static void os_cmd_ignore(sourceinfo_t *si, int parc, char *parv[]); |
| 19 |
static void os_cmd_ignore_add(sourceinfo_t *si, int parc, char *parv[]); |
| 20 |
static void os_cmd_ignore_del(sourceinfo_t *si, int parc, char *parv[]); |
| 21 |
static void os_cmd_ignore_list(sourceinfo_t *si, int parc, char *parv[]); |
| 22 |
static void os_cmd_ignore_clear(sourceinfo_t *si, int parc, char *parv[]); |
| 23 |
|
| 24 |
command_t os_ignore = { "IGNORE", N_("Ignore a mask from services."), PRIV_ADMIN, 3, os_cmd_ignore, { .path = "oservice/ignore" } }; |
| 25 |
command_t os_ignore_add = { "ADD", N_("Add services ignore"), PRIV_ADMIN, 2, os_cmd_ignore_add, { .path = "" } }; |
| 26 |
command_t os_ignore_del = { "DEL", N_("Delete services ignore"), PRIV_ADMIN, 1, os_cmd_ignore_del, { .path = "" } }; |
| 27 |
command_t os_ignore_list = { "LIST", N_("List services ignores"), PRIV_ADMIN, 0, os_cmd_ignore_list, { .path = "" } }; |
| 28 |
command_t os_ignore_clear = { "CLEAR", N_("Clear all services ignores"), PRIV_ADMIN, 0, os_cmd_ignore_clear, { .path = "" } }; |
| 29 |
|
| 30 |
mowgli_patricia_t *os_ignore_cmds; |
| 31 |
mowgli_list_t svs_ignore_list; |
| 32 |
|
| 33 |
|
| 34 |
void _modinit(module_t *m) |
| 35 |
{ |
| 36 |
service_named_bind_command("operserv", &os_ignore); |
| 37 |
|
| 38 |
os_ignore_cmds = mowgli_patricia_create(strcasecanon); |
| 39 |
|
| 40 |
/* Sub-commands */ |
| 41 |
command_add(&os_ignore_add, os_ignore_cmds); |
| 42 |
command_add(&os_ignore_del, os_ignore_cmds); |
| 43 |
command_add(&os_ignore_clear, os_ignore_cmds); |
| 44 |
command_add(&os_ignore_list, os_ignore_cmds); |
| 45 |
|
| 46 |
use_svsignore++; |
| 47 |
} |
| 48 |
|
| 49 |
void _moddeinit(module_unload_intent_t intent) |
| 50 |
{ |
| 51 |
service_named_unbind_command("operserv", &os_ignore); |
| 52 |
|
| 53 |
/* Sub-commands */ |
| 54 |
command_delete(&os_ignore_add, os_ignore_cmds); |
| 55 |
command_delete(&os_ignore_del, os_ignore_cmds); |
| 56 |
command_delete(&os_ignore_list, os_ignore_cmds); |
| 57 |
command_delete(&os_ignore_clear, os_ignore_cmds); |
| 58 |
|
| 59 |
use_svsignore--; |
| 60 |
|
| 61 |
mowgli_patricia_destroy(os_ignore_cmds, NULL, NULL); |
| 62 |
} |
| 63 |
|
| 64 |
static void os_cmd_ignore(sourceinfo_t *si, int parc, char *parv[]) |
| 65 |
{ |
| 66 |
char *cmd = parv[0]; |
| 67 |
command_t *c; |
| 68 |
|
| 69 |
if (!cmd) |
| 70 |
{ |
| 71 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "IGNORE"); |
| 72 |
command_fail(si, fault_needmoreparams, _("Syntax: IGNORE ADD|DEL|LIST|CLEAR <mask>")); |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
c = command_find(os_ignore_cmds, cmd); |
| 77 |
if (c == NULL) |
| 78 |
{ |
| 79 |
command_fail(si, fault_badparams, _("Invalid command. Use \2/%s%s help\2 for a command listing."), (ircd->uses_rcommand == false) ? "msg " : "", si->service->disp); |
| 80 |
return; |
| 81 |
} |
| 82 |
|
| 83 |
command_exec(si->service, si, c, parc - 1, parv + 1); |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
static void os_cmd_ignore_add(sourceinfo_t *si, int parc, char *parv[]) |
| 88 |
{ |
| 89 |
mowgli_node_t *n; |
| 90 |
char *target = parv[0]; |
| 91 |
char *reason = parv[1]; |
| 92 |
svsignore_t *svsignore; |
| 93 |
|
| 94 |
if (parc < 2) |
| 95 |
{ |
| 96 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "IGNORE"); |
| 97 |
command_fail(si, fault_needmoreparams, _("Syntax: IGNORE ADD <mask> <reason>")); |
| 98 |
return; |
| 99 |
} |
| 100 |
|
| 101 |
if (!validhostmask(target)) |
| 102 |
{ |
| 103 |
command_fail(si, fault_badparams, _("Invalid host mask, %s"), target); |
| 104 |
return; |
| 105 |
} |
| 106 |
|
| 107 |
/* Are we already ignoring this mask? */ |
| 108 |
MOWGLI_ITER_FOREACH(n, svs_ignore_list.head) |
| 109 |
{ |
| 110 |
svsignore = (svsignore_t *)n->data; |
| 111 |
|
| 112 |
/* We're here */ |
| 113 |
if (!strcasecmp(svsignore->mask, target)) |
| 114 |
{ |
| 115 |
command_fail(si, fault_nochange, _("The mask \2%s\2 already exists on the services ignore list."), svsignore->mask); |
| 116 |
return; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
svsignore = svsignore_add(target, reason); |
| 121 |
svsignore->setby = sstrdup(get_storage_oper_name(si)); |
| 122 |
svsignore->settime = CURRTIME; |
| 123 |
|
| 124 |
command_success_nodata(si, _("\2%s\2 has been added to the services ignore list."), target); |
| 125 |
|
| 126 |
logcommand(si, CMDLOG_ADMIN, "IGNORE:ADD: \2%s\2 (reason: \2%s\2)", target, reason); |
| 127 |
wallops("%s added a services ignore for \2%s\2 (%s).", get_oper_name(si), target, reason); |
| 128 |
|
| 129 |
return; |
| 130 |
} |
| 131 |
|
| 132 |
static void os_cmd_ignore_del(sourceinfo_t *si, int parc, char *parv[]) |
| 133 |
{ |
| 134 |
char *target = parv[0]; |
| 135 |
mowgli_node_t *n, *tn; |
| 136 |
svsignore_t *svsignore; |
| 137 |
|
| 138 |
if (target == NULL) |
| 139 |
{ |
| 140 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "IGNORE"); |
| 141 |
command_fail(si, fault_needmoreparams, _("Syntax: IGNORE ADD|DEL|LIST|CLEAR <mask>")); |
| 142 |
return; |
| 143 |
} |
| 144 |
|
| 145 |
MOWGLI_ITER_FOREACH_SAFE(n, tn, svs_ignore_list.head) |
| 146 |
{ |
| 147 |
svsignore = (svsignore_t *)n->data; |
| 148 |
|
| 149 |
if (!strcasecmp(svsignore->mask,target)) |
| 150 |
{ |
| 151 |
command_success_nodata(si, _("\2%s\2 has been removed from the services ignore list."), svsignore->mask); |
| 152 |
|
| 153 |
svsignore_delete(svsignore); |
| 154 |
|
| 155 |
wallops("%s removed \2%s\2 from the services ignore list.", get_oper_name(si), target); |
| 156 |
logcommand(si, CMDLOG_ADMIN, "IGNORE:DEL: \2%s\2", target); |
| 157 |
|
| 158 |
return; |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
command_fail(si, fault_nosuch_target, _("\2%s\2 was not found on the services ignore list."), target); |
| 163 |
return; |
| 164 |
} |
| 165 |
|
| 166 |
static void os_cmd_ignore_clear(sourceinfo_t *si, int parc, char *parv[]) |
| 167 |
{ |
| 168 |
mowgli_node_t *n, *tn; |
| 169 |
svsignore_t *svsignore; |
| 170 |
|
| 171 |
if (MOWGLI_LIST_LENGTH(&svs_ignore_list) == 0) |
| 172 |
{ |
| 173 |
command_success_nodata(si, _("Services ignore list is empty.")); |
| 174 |
return; |
| 175 |
} |
| 176 |
|
| 177 |
MOWGLI_ITER_FOREACH_SAFE(n, tn, svs_ignore_list.head) |
| 178 |
{ |
| 179 |
svsignore = (svsignore_t *)n->data; |
| 180 |
|
| 181 |
command_success_nodata(si, _("\2%s\2 has been removed from the services ignore list."), svsignore->mask); |
| 182 |
mowgli_node_delete(n,&svs_ignore_list); |
| 183 |
mowgli_node_free(n); |
| 184 |
free(svsignore->mask); |
| 185 |
free(svsignore->setby); |
| 186 |
free(svsignore->reason); |
| 187 |
|
| 188 |
} |
| 189 |
|
| 190 |
command_success_nodata(si, _("Services ignore list has been wiped!")); |
| 191 |
|
| 192 |
wallops("\2%s\2 wiped the services ignore list.", get_oper_name(si)); |
| 193 |
logcommand(si, CMDLOG_ADMIN, "IGNORE:CLEAR"); |
| 194 |
|
| 195 |
return; |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
static void os_cmd_ignore_list(sourceinfo_t *si, int parc, char *parv[]) |
| 200 |
{ |
| 201 |
mowgli_node_t *n; |
| 202 |
unsigned int i = 1; |
| 203 |
svsignore_t *svsignore; |
| 204 |
char strfbuf[BUFSIZE]; |
| 205 |
struct tm tm; |
| 206 |
|
| 207 |
if (MOWGLI_LIST_LENGTH(&svs_ignore_list) == 0) |
| 208 |
{ |
| 209 |
command_success_nodata(si, _("The services ignore list is empty.")); |
| 210 |
return; |
| 211 |
} |
| 212 |
|
| 213 |
command_success_nodata(si, _("Current Ignore list entries:")); |
| 214 |
command_success_nodata(si, "-------------------------"); |
| 215 |
|
| 216 |
MOWGLI_ITER_FOREACH(n, svs_ignore_list.head) |
| 217 |
{ |
| 218 |
svsignore = (svsignore_t *)n->data; |
| 219 |
|
| 220 |
tm = *localtime(&svsignore->settime); |
| 221 |
strftime(strfbuf, sizeof strfbuf, TIME_FORMAT, &tm); |
| 222 |
|
| 223 |
command_success_nodata(si, _("%d: %s by %s on %s (Reason: %s)"), i, svsignore->mask, svsignore->setby, strfbuf, svsignore->reason); |
| 224 |
i++; |
| 225 |
} |
| 226 |
|
| 227 |
command_success_nodata(si, "-------------------------"); |
| 228 |
|
| 229 |
logcommand(si, CMDLOG_ADMIN, "IGNORE:LIST"); |
| 230 |
|
| 231 |
return; |
| 232 |
} |
| 233 |
|
| 234 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 235 |
* vim:ts=8 |
| 236 |
* vim:sw=8 |
| 237 |
* vim:noexpandtab |
| 238 |
*/ |