ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/contrib/ns_ratelimitreg.C
Revision: 1.6
Committed: Sat Sep 22 14:27:27 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +3 -2 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * ns_ratelimitreg.C: Rate limits account registrations.
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 © 2007 Jilles Tjoelker
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: ns_ratelimitreg.C,v 1.5 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <libermyth.h>
17 #include <account/myuser.h>
18 #include <ermyth/module.h>
19
20 static char const rcsid[] = "$Id: ns_ratelimitreg.C,v 1.5 2007-09-16 18:54:43 pippijn Exp $";
21
22 REGISTER_MODULE ("contrib/ns_ratelimitreg", false, "Jilles Tjoelker <jilles -at- stack.nl>");
23
24 /* settings */
25 int ratelimitreg_max = 5; /* allow this many account registrations */
26 int ratelimitreg_period = 60; /* in this time */
27 int ratelimitreg_wallops_period = 3600; /* send wallops at most once an hour */
28
29 /* dynamic state */
30 int ratelimitreg_count = 0;
31 time_t ratelimitreg_firsttime = 0;
32
33 static bool
34 check_registration (sourceinfo_t *si, char const * const account, char const * const email)
35 {
36 bool approved = true;
37 static time_t lastwallops;
38
39 if (ratelimitreg_firsttime + ratelimitreg_period > NOW)
40 ratelimitreg_count = 0, ratelimitreg_firsttime = NOW;
41
42 if (ratelimitreg_count > ratelimitreg_max && !has_priv (si, PRIV_FLOOD))
43 {
44 command_fail (si, fault::toomany, "The system is currently too busy to process your registration, please try again later.");
45 approved = false;
46 snoop ("REGISTER:THROTTLED: %s by \2%s\2", account, si->su != NULL ? si->su->nick : get_source_name (si));
47 if (lastwallops + ratelimitreg_wallops_period < NOW)
48 {
49 wallops ("Registration of %s by %s was throttled.", account, get_oper_name (si));
50 lastwallops = NOW;
51 }
52 }
53
54 return approved;
55 }
56
57 static void
58 handle_register (myuser_t *mu)
59 {
60 if (ratelimitreg_firsttime + ratelimitreg_period > NOW)
61 ratelimitreg_count = 0, ratelimitreg_firsttime = NOW;
62 ratelimitreg_count++;
63 }
64
65 bool
66 _modinit (module *m)
67 {
68 user_t::callback.can_register.attach (check_registration);
69 myuser_t::callback.registered.attach (handle_register);
70
71 return true;
72 }
73
74 void
75 _moddeinit (void)
76 {
77 user_t::callback.can_register.detach (check_registration);
78 myuser_t::callback.registered.detach (handle_register);
79 }