/** * ignore.C: This file contains functionality which implements the OperServ IGNORE command. * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2006 Patrick Fish, et al * Rights to this code are documented in doc/pod/license.pod. * * $Id: ignore.C,v 1.8 2007/09/22 14:27:28 pippijn Exp $ */ #include "atheme.h" #include #include #include static char const rcsid[] = "$Id: ignore.C,v 1.8 2007/09/22 14:27:28 pippijn Exp $"; REGISTER_MODULE ("operserv/ignore", false, "The Ermyth Team "); static void os_cmd_ignore (sourceinfo_t *si, int parc, char *parv[]); static void os_cmd_ignore_add (sourceinfo_t *si, int parc, char *parv[]); static void os_cmd_ignore_del (sourceinfo_t *si, int parc, char *parv[]); static void os_cmd_ignore_list (sourceinfo_t *si, int parc, char *parv[]); static void os_cmd_ignore_clear (sourceinfo_t *si, int parc, char *parv[]); command_t const os_ignore = { "IGNORE", N_("Ignore a mask from services."), PRIV_ADMIN, 3, os_cmd_ignore }; command_t const os_ignore_add = { "ADD", N_("Add services ignore"), PRIV_ADMIN, 2, os_cmd_ignore_add }; command_t const os_ignore_del = { "DEL", N_("Delete services ignore"), PRIV_ADMIN, 1, os_cmd_ignore_del }; command_t const os_ignore_list = { "LIST", N_("List services ignores"), PRIV_ADMIN, 0, os_cmd_ignore_list }; command_t const os_ignore_clear = { "CLEAR", N_("Clear all services ignores"), PRIV_ADMIN, 0, os_cmd_ignore_clear }; E cmdvec os_cmdtree; E helpvec os_helptree; cmdvec os_ignore_cmds; bool _modinit (module *m) { os_cmdtree << os_ignore; help_addentry (os_helptree, "IGNORE", "help/operserv/ignore", NULL); /* Sub-commands */ os_ignore_cmds << os_ignore_add; os_ignore_cmds << os_ignore_del; os_ignore_cmds << os_ignore_clear; os_ignore_cmds << os_ignore_list; use_svsignore++; return true; } void _moddeinit () { os_cmdtree >> os_ignore; help_delentry (os_helptree, "IGNORE"); /* Sub-commands */ os_ignore_cmds >> os_ignore_add; os_ignore_cmds >> os_ignore_del; os_ignore_cmds >> os_ignore_list; os_ignore_cmds >> os_ignore_clear; use_svsignore--; } static void os_cmd_ignore (sourceinfo_t *si, int parc, char *parv[]) { char *cmd = parv[0]; command_t const *c; if (!cmd) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "IGNORE"); command_fail (si, fault::needmoreparams, _("Syntax: IGNORE ADD|DEL|LIST|CLEAR ")); return; } c = os_ignore_cmds.find (cmd); if (c == NULL) { 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); return; } c->exec (si->service, si, parc - 1, parv + 1); } static void os_cmd_ignore_add (sourceinfo_t *si, int parc, char *parv[]) { svsignore_vector::iterator it, it_end; char *target = parv[0]; char *reason = parv[1]; svsignore_t *svsignore; if (target == NULL) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "IGNORE"); command_fail (si, fault::needmoreparams, _("Syntax: IGNORE ADD|DEL|LIST|CLEAR ")); return; } if (!validhostmask (target)) { command_fail (si, fault::badparams, _("Invalid host mask, %s"), target); return; } /* Are we already ignoring this mask? */ for (it = svs_ignore_list.begin (), it_end = svs_ignore_list.end (); it != it_end; ++it) { svsignore = *it; /* We're here */ if (!strcasecmp (svsignore->mask, target)) { command_fail (si, fault::nochange, _("The mask \2%s\2 already exists on the services ignore list."), svsignore->mask); return; } } svsignore = svsignore_add (target, reason); svsignore->setby = sstrdup (get_oper_name (si)); svsignore->settime = NOW; command_success_nodata (si, _("\2%s\2 has been added to the services ignore list."), target); logcommand (si, CMDLOG_ADMIN, "IGNORE ADD %s %s", target, reason); wallops ("%s added a services ignore for \2%s\2 (%s).", get_oper_name (si), target, reason); snoop ("IGNORE:ADD: \2%s\2 by \2%s\2 (%s)", target, get_oper_name (si), reason); return; } static void os_cmd_ignore_del (sourceinfo_t *si, int parc, char *parv[]) { char *target = parv[0]; svsignore_vector::iterator it, it_end; svsignore_t *svsignore; if (target == NULL) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "IGNORE"); command_fail (si, fault::needmoreparams, _("Syntax: IGNORE ADD|DEL|LIST|CLEAR ")); return; } for (it = svs_ignore_list.begin (), it_end = svs_ignore_list.end (); it != it_end; ++it) { svsignore = *it; if (!strcasecmp (svsignore->mask, target)) { command_success_nodata (si, _("\2%s\2 has been removed from the services ignore list."), svsignore->mask); svsignore_delete (svsignore); wallops ("%s removed \2%s\2 from the services ignore list.", get_oper_name (si), target); snoop ("IGNORE:DEL: \2%s\2 by \2%s\2", target, get_oper_name (si)); logcommand (si, CMDLOG_ADMIN, "IGNORE DEL %s", target); return; } } command_fail (si, fault::nosuch_target, _("\2%s\2 was not found on the services ignore list."), target); return; } static void os_cmd_ignore_clear (sourceinfo_t *si, int parc, char *parv[]) { svsignore_vector::iterator it, it_end; svsignore_t *svsignore; if (svs_ignore_list.empty ()) { command_success_nodata (si, _("Services ignore list is empty.")); return; } while (!svs_ignore_list.empty ()) { svsignore = svs_ignore_list.back (); command_success_nodata (si, _("\2%s\2 has been removed from the services ignore list."), svsignore->mask); svs_ignore_list.erase (svsignore); sfree (svsignore->mask); sfree (svsignore->setby); sfree (svsignore->reason); } command_success_nodata (si, _("Services ignore list has been wiped!")); wallops ("\2%s\2 wiped the services ignore list.", get_oper_name (si)); snoop ("IGNORE:CLEAR: by \2%s\2", get_oper_name (si)); logcommand (si, CMDLOG_ADMIN, "IGNORE CLEAR"); return; } static void os_cmd_ignore_list (sourceinfo_t *si, int parc, char *parv[]) { svsignore_vector::iterator it, it_end; unsigned int i = 1; svsignore_t *svsignore; char strfbuf[32]; struct tm tm; if (svs_ignore_list.empty ()) { command_success_nodata (si, _("The services ignore list is empty.")); return; } command_success_nodata (si, _("Current Ignore list entries:")); command_success_nodata (si, "-------------------------"); for (it = svs_ignore_list.begin (), it_end = svs_ignore_list.end (); it != it_end; ++it) { svsignore = *it; tm = *localtime (&svsignore->settime); strftime (strfbuf, sizeof (strfbuf) - 1, "%b %d %H:%M:%S %Y", &tm); command_success_nodata (si, _("%d: %s by %s on %s (Reason: %s)"), i, svsignore->mask, svsignore->setby, strfbuf, svsignore->reason); i++; } command_success_nodata (si, "-------------------------"); logcommand (si, CMDLOG_ADMIN, "IGNORE LIST"); return; }