ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/operserv/rakill.C
Revision: 1.5
Committed: Tue Aug 28 17:08:11 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +30 -35 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

File Contents

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