ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/operserv/rakill.C
Revision: 1.8
Committed: Sat Sep 22 14:27:28 2007 UTC (19 years ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +4 -4 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * rakill.C: Regexp-based AKILL implementation.
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 Robin Burchell <surreal.w00t@gmail.com>
10 * Rights to this code are as defined in doc/pod/license.pod.
11 *
12 * $Id: rakill.C,v 1.7 2007-09-16 18:54:44 pippijn Exp $
13 */
14
15 /*
16 * @makill regex!here.+ [akill reason]
17 * Matches `nick!user@host realname here' for each client against a given regex, and places akills.
18 * CHECK REGEX USING @RMATCH FIRST!
19 */
20
21 #include <boost/foreach.hpp>
22
23 #include "atheme.h"
24 #include <ermyth/module.h>
25 #include <ermyth/database.h>
26 #include <account/myuser.h>
27
28 static char const rcsid[] = "$Id: rakill.C,v 1.7 2007-09-16 18:54:44 pippijn Exp $";
29
30 REGISTER_MODULE ("operserv/rakill", false, "The Ermyth Team <http://ermyth.xinutec.org>");
31
32 E cmdvec os_cmdtree;
33 E helpvec os_helptree;
34
35 static void os_cmd_rakill (sourceinfo_t *si, int parc, char *parv[]);
36
37 command_t const os_rakill = { "RAKILL", N_("Sets a group of AKILLs against users matching a specific regex pattern."), PRIV_MASS_AKILL, 1, os_cmd_rakill };
38
39 bool
40 _modinit (module *m)
41 {
42 os_cmdtree << os_rakill;
43 help_addentry (os_helptree, "RAKILL", "help/operserv/rakill", NULL);
44
45 return true;
46 }
47
48 void
49 _moddeinit (void)
50 {
51 os_cmdtree >> os_rakill;
52 help_delentry (os_helptree, "RAKILL");
53 }
54
55 static void
56 os_cmd_rakill (sourceinfo_t *si, int parc, char *parv[])
57 {
58 regex_t *regex;
59 char usermask[512];
60 unsigned int matches = 0;
61 user_t *u;
62 char *args = parv[0];
63 char *pattern;
64 char *reason;
65 user_t *source;
66 int flags = 0;
67
68 /* make sure they could have done RMATCH */
69 if (!has_priv (si, PRIV_USER_AUSPEX))
70 {
71 command_fail (si, fault::noprivs, _("You do not have %s privilege."), PRIV_USER_AUSPEX);
72 return;
73 }
74
75 if (args == NULL)
76 {
77 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "RAKILL");
78 command_fail (si, fault::needmoreparams, _("Syntax: RAKILL /<regex>/[i] <reason>"));
79 return;
80 }
81
82 pattern = regex_extract (args, &args, &flags);
83 if (pattern == NULL)
84 {
85 command_fail (si, fault::badparams, STR_INVALID_PARAMS, "RAKILL");
86 command_fail (si, fault::badparams, _("Syntax: RAKILL /<regex>/[i] <reason>"));
87 return;
88 }
89
90 reason = args;
91 while (*reason == ' ')
92 reason++;
93 if (*reason == '\0')
94 {
95 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "RAKILL");
96 command_fail (si, fault::needmoreparams, _("Syntax: RAKILL /<regex>/[i] <reason>"));
97 return;
98 }
99
100 regex = regex_create (pattern, flags);
101 if (regex == NULL)
102 {
103 command_fail (si, fault::badparams, _("The provided regex \2%s\2 is invalid."), pattern);
104 return;
105 }
106
107 source = si->su;
108 /* try to find them on IRC, otherwise use operserv */
109 if (source == NULL)
110 source = si->smu != NULL && !si->smu->logins.empty ()
111 ? si->smu->logins.back ()
112 : si->service->me;
113 sprintf (usermask, "%s!%s@%s %s", source->nick, source->user, source->host, source->gecos);
114 if (regex_match (regex, (char *) usermask))
115 {
116 regex_destroy (regex);
117 command_fail (si, fault::noprivs, _("The provided regex matches you, refusing RAKILL."));
118 snoop ("RAKILL:REFUSED: \2%s\2 by \2%s\2 (%s) (matches self)", pattern, get_oper_name (si), reason);
119 wallops ("\2%s\2 attempted to do RAKILL on \2%s\2 matching self", get_oper_name (si), pattern);
120 logcommand (si, CMDLOG_ADMIN, "RAKILL %s %s (refused, matches self)", pattern, reason);
121 return;
122 }
123
124 snoop ("RAKILL: \2%s\2 by \2%s\2 (%s)", pattern, get_oper_name (si), reason);
125
126 foreach (user_t::pair_type &up, user_t::map)
127 {
128 u = up.second;
129 sprintf (usermask, "%s!%s@%s %s", u->nick, u->user, u->host, u->gecos);
130
131 if (regex_match (regex, (char *) usermask))
132 {
133 /* match */
134 command_success_nodata (si, _("\2Match:\2 %s!%s@%s %s - akilling"), u->nick, u->user, u->host, u->gecos);
135 phandler->kline_sts ("*", "*", u->host, 604800, reason);
136 matches++;
137 }
138 }
139
140 regex_destroy (regex);
141 command_success_nodata (si, _("\2%d\2 matches for %s akilled."), matches, pattern);
142 logcommand (si, CMDLOG_ADMIN, "RAKILL %s %s (%d matches)", pattern, reason, matches);
143 }