| 1 |
/* |
| 2 |
* Copyright (c) 2005-2007 William Pitcock, et al. |
| 3 |
* Rights to this code are as documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* This file contains a CService UNBAN which can only unbans the source |
| 6 |
* user, not others. |
| 7 |
* Do not load chanserv/ban and chanserv/unban_self together. |
| 8 |
* |
| 9 |
*/ |
| 10 |
|
| 11 |
#include "atheme.h" |
| 12 |
|
| 13 |
DECLARE_MODULE_V1 |
| 14 |
( |
| 15 |
"chanserv/unban_self", false, _modinit, _moddeinit, |
| 16 |
PACKAGE_STRING, |
| 17 |
VENDOR_STRING |
| 18 |
); |
| 19 |
|
| 20 |
static void cs_cmd_unban(sourceinfo_t *si, int parc, char *parv[]); |
| 21 |
|
| 22 |
command_t cs_unban = { "UNBAN", N_("Unbans you on a channel."), |
| 23 |
AC_AUTHENTICATED, 2, cs_cmd_unban, { .path = "cservice/unban_self" } }; |
| 24 |
|
| 25 |
void _modinit(module_t *m) |
| 26 |
{ |
| 27 |
service_named_bind_command("chanserv", &cs_unban); |
| 28 |
} |
| 29 |
|
| 30 |
void _moddeinit(module_unload_intent_t intent) |
| 31 |
{ |
| 32 |
service_named_unbind_command("chanserv", &cs_unban); |
| 33 |
} |
| 34 |
|
| 35 |
static void cs_cmd_unban(sourceinfo_t *si, int parc, char *parv[]) |
| 36 |
{ |
| 37 |
const char *channel = parv[0]; |
| 38 |
const char *target = parv[1]; |
| 39 |
channel_t *c = channel_find(channel); |
| 40 |
mychan_t *mc = mychan_find(channel); |
| 41 |
user_t *tu; |
| 42 |
chanban_t *cb; |
| 43 |
|
| 44 |
if (si->su == NULL) |
| 45 |
{ |
| 46 |
command_fail(si, fault_noprivs, _("\2%s\2 can only be executed via IRC."), "UNBAN"); |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
if (!channel) |
| 51 |
{ |
| 52 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "UNBAN"); |
| 53 |
command_fail(si, fault_needmoreparams, _("Syntax: UNBAN <#channel>")); |
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
if (target && irccasecmp(target, si->su->nick)) |
| 58 |
{ |
| 59 |
command_fail(si, fault_noprivs, _("You may only unban yourself via %s."), si->service->nick); |
| 60 |
if (validhostmask(target)) |
| 61 |
command_fail(si, fault_noprivs, _("Try \2/mode %s -b %s\2"), channel, target); |
| 62 |
return; |
| 63 |
} |
| 64 |
target = si->su->nick; |
| 65 |
|
| 66 |
if (!mc) |
| 67 |
{ |
| 68 |
command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), channel); |
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
if (!c) |
| 73 |
{ |
| 74 |
command_fail(si, fault_nosuch_target, _("\2%s\2 is currently empty."), channel); |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
if (!si->smu) |
| 79 |
{ |
| 80 |
command_fail(si, fault_noprivs, _("You are not logged in.")); |
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
if (!chanacs_source_has_flag(mc, si, CA_REMOVE) && |
| 85 |
!chanacs_source_has_flag(mc, si, CA_EXEMPT)) |
| 86 |
{ |
| 87 |
command_fail(si, fault_noprivs, _("You are not authorized to perform this operation.")); |
| 88 |
return; |
| 89 |
} |
| 90 |
|
| 91 |
tu = si->su; |
| 92 |
{ |
| 93 |
mowgli_node_t *n, *tn; |
| 94 |
char hostbuf2[BUFSIZE]; |
| 95 |
int count = 0; |
| 96 |
|
| 97 |
snprintf(hostbuf2, BUFSIZE, "%s!%s@%s", tu->nick, tu->user, tu->vhost); |
| 98 |
for (n = next_matching_ban(c, tu, 'b', c->bans.head); n != NULL; n = next_matching_ban(c, tu, 'b', tn)) |
| 99 |
{ |
| 100 |
tn = n->next; |
| 101 |
cb = n->data; |
| 102 |
|
| 103 |
logcommand(si, CMDLOG_DO, "UNBAN: \2%s\2 \2%s\2 (for user \2%s\2)", mc->name, cb->mask, hostbuf2); |
| 104 |
modestack_mode_param(chansvs.nick, c, MTYPE_DEL, cb->type, cb->mask); |
| 105 |
chanban_delete(cb); |
| 106 |
count++; |
| 107 |
} |
| 108 |
if (count > 0) |
| 109 |
command_success_nodata(si, _("Unbanned \2%s\2 on \2%s\2 (%d ban%s removed)."), |
| 110 |
target, channel, count, (count != 1 ? "s" : "")); |
| 111 |
else |
| 112 |
command_success_nodata(si, _("No bans found matching \2%s\2 on \2%s\2."), target, channel); |
| 113 |
return; |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 118 |
* vim:ts=8 |
| 119 |
* vim:sw=8 |
| 120 |
* vim:noexpandtab |
| 121 |
*/ |