ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/operserv/rakill.C
Revision: 1.7
Committed: Sun Sep 16 18:54:44 2007 UTC (19 years ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.6: +10 -5 lines
Log Message:
#defines to enum

File Contents

# User Rev Content
1 pippijn 1.7 /**
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 pippijn 1.5 * Copyright © 2006 Robin Burchell <surreal.w00t@gmail.com>
10 pippijn 1.2 * Rights to this code are as defined in doc/pod/license.pod.
11 pippijn 1.1 *
12 pippijn 1.7 * $Id: rakill.C,v 1.6 2007-08-30 19:56:24 pippijn Exp $
13 pippijn 1.1 */
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 pippijn 1.5
21     #include <boost/foreach.hpp>
22    
23 pippijn 1.1 #include "atheme.h"
24 pippijn 1.5 #include <ermyth/module.h>
25     #include <ermyth/database.h>
26 pippijn 1.1 #include <account/myuser.h>
27    
28 pippijn 1.7 static char const rcsid[] = "$Id: rakill.C,v 1.6 2007-08-30 19:56:24 pippijn Exp $";
29 pippijn 1.1
30 pippijn 1.5 REGISTER_MODULE ("operserv/rakill", false, "The Ermyth Team <http://ermyth.schmorp.de>");
31 pippijn 1.1
32 pippijn 1.5 E cmdvec os_cmdtree;
33     E helpvec os_helptree;
34 pippijn 1.1
35     static void os_cmd_rakill (sourceinfo_t *si, int parc, char *parv[]);
36    
37 pippijn 1.5 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 pippijn 1.1
39 pippijn 1.5 bool
40     _modinit (module *m)
41 pippijn 1.1 {
42     os_cmdtree << os_rakill;
43 pippijn 1.4 help_addentry (os_helptree, "RAKILL", "help/operserv/rakill", NULL);
44 pippijn 1.5
45     return true;
46 pippijn 1.1 }
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 pippijn 1.6 command_fail (si, fault::noprivs, _("You do not have %s privilege."), PRIV_USER_AUSPEX);
72 pippijn 1.1 return;
73     }
74    
75     if (args == NULL)
76     {
77 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "RAKILL");
78     command_fail (si, fault::needmoreparams, _("Syntax: RAKILL /<regex>/[i] <reason>"));
79 pippijn 1.1 return;
80     }
81    
82     pattern = regex_extract (args, &args, &flags);
83     if (pattern == NULL)
84     {
85 pippijn 1.6 command_fail (si, fault::badparams, STR_INVALID_PARAMS, "RAKILL");
86     command_fail (si, fault::badparams, _("Syntax: RAKILL /<regex>/[i] <reason>"));
87 pippijn 1.1 return;
88     }
89    
90     reason = args;
91     while (*reason == ' ')
92     reason++;
93     if (*reason == '\0')
94     {
95 pippijn 1.6 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "RAKILL");
96     command_fail (si, fault::needmoreparams, _("Syntax: RAKILL /<regex>/[i] <reason>"));
97 pippijn 1.1 return;
98     }
99    
100     regex = regex_create (pattern, flags);
101     if (regex == NULL)
102     {
103 pippijn 1.6 command_fail (si, fault::badparams, _("The provided regex \2%s\2 is invalid."), pattern);
104 pippijn 1.1 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 pippijn 1.6 command_fail (si, fault::noprivs, _("The provided regex matches you, refusing RAKILL."));
118 pippijn 1.1 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 pippijn 1.5 foreach (user_pair &up, userlist)
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 pippijn 1.1 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     }