restricted kill and gline command from SpamServ
[srvx.git] / src / spamserv.h
1 /* spamserv.h - anti spam service
2  * Copyright 2004 feigling
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.  Important limitations are
8  * listed in the COPYING file that accompanies this software.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, email srvx-maintainers@srvx.net.
17  *
18  * $Id: spamserv.h,v 1.3 2004/06/27 22:20:00 feigling Exp $
19  */
20
21 #ifndef _spamserv_h
22 #define _spamserv_h
23
24 #ifdef HAVE_ARPA_INET_H
25 #include <arpa/inet.h>
26 #endif
27
28 /***********************************************/
29 /*                   Channel                   */
30 /***********************************************/
31
32 enum channelinfo
33 {
34     ci_SpamLimit = 0,
35     ci_AdvReaction,
36     ci_WarnReaction,
37     ci_Max
38 };
39
40 #define CHAN_INFO_SIZE          (ci_Max + 1)
41 #define CHAN_INFO_DEFAULT       "bls"
42
43 #define CHAN_SPAMSCAN           0x00000001
44 #define CHAN_FLOODSCAN          0x00000002
45 #define CHAN_JOINFLOOD          0x00000004
46 #define CHAN_ADV_SCAN           0x00000008
47 #define CHAN_SCAN_CHANOPS       0x00000010
48 #define CHAN_SCAN_VOICED        0x00000020
49 #define CHAN_SUSPENDED          0x00000040
50
51 #define CHAN_FLAGS_DEFAULT      (CHAN_SPAMSCAN | CHAN_FLOODSCAN | CHAN_JOINFLOOD)
52
53 #define CHECK_SPAM(x)           ((x)->flags & CHAN_SPAMSCAN)
54 #define CHECK_FLOOD(x)          ((x)->flags & CHAN_FLOODSCAN)
55 #define CHECK_JOINFLOOD(x)      ((x)->flags & CHAN_JOINFLOOD)
56 #define CHECK_ADV(x)            ((x)->flags & CHAN_ADV_SCAN)
57 #define CHECK_CHANOPS(x)        ((x)->flags & CHAN_SCAN_CHANOPS)
58 #define CHECK_VOICED(x)         ((x)->flags & CHAN_SCAN_VOICED)
59 #define CHECK_SUSPENDED(x)      ((x)->flags & CHAN_SUSPENDED)
60
61 #define BADACTION_KICK   0
62 #define BADACTION_BAN    1
63 #define BADACTION_KILL   2
64 #define BADACTION_GLINE  3
65
66 struct chanInfo
67 {
68     struct chanNode        *channel;
69     struct string_list     *exceptions;
70     dict_t                         badwords;
71     unsigned int           flags : 30;
72     unsigned int           exceptlevel;
73     char                   info[CHAN_INFO_SIZE];
74     unsigned long          suspend_expiry;
75     unsigned int                   last_badword_id;
76 };
77
78 /***********************************************/
79 /*                    User                     */
80 /***********************************************/
81
82 #define USER_KICK           0x00000001
83 #define USER_KICKBAN        0x00000002
84 #define USER_SHORT_TBAN     0x00000004
85 #define USER_LONG_TBAN      0x00000008
86 #define USER_KILL           0x00000010
87 #define USER_GLINE          0x00000020
88 #define USER_WARNED         0x00000040
89 #define USER_KILLED         0x00000080
90 #define USER_ADV_WARNED     0x00000100
91
92 #define CHECK_KICK(x)           ((x)->flags & USER_KICK)
93 #define CHECK_KICKBAN(x)        ((x)->flags & USER_KICKBAN)
94 #define CHECK_SHORT_TBAN(x)     ((x)->flags & USER_SHORT_TBAN)
95 #define CHECK_LONG_TBAN(x)      ((x)->flags & USER_LONG_TBAN)
96 #define CHECK_KILL(x)           ((x)->flags & USER_KILL)
97 #define CHECK_GLINE(x)          ((x)->flags & USER_GLINE)
98 #define CHECK_WARNED(x)         ((x)->flags & USER_WARNED)
99 #define CHECK_KILLED(x)         ((x)->flags & USER_KILLED)
100 #define CHECK_ADV_WARNED(x)     ((x)->flags & USER_ADV_WARNED)
101
102 #define SPAM_WARNLEVEL          1
103
104 #define FLOOD_TIMEQ_FREQ        5
105 #define FLOOD_EXPIRE            5
106 #define FLOOD_WARNLEVEL         1
107 #define FLOOD_MAX_LINES         8
108
109 #define JOINFLOOD_TIMEQ_FREQ    225
110 #define JOINFLOOD_EXPIRE        450
111 #define JOINFLOOD_MAX           3
112 #define JOINFLOOD_B_DURATION    900
113
114 #define ADV_TIMEQ_FREQ          300
115 #define ADV_EXPIRE              900
116 #define ADV_WARNLEVEL           2
117
118 #define WARNLEVEL_TIMEQ_FREQ    1800
119 #define MAX_WARNLEVEL           6
120
121 #define KILL_TIMEQ_FREQ         450
122 #define KILL_EXPIRE             1800
123 #define KILL_WARNLEVEL          3
124
125 struct spamNode
126 {
127         struct chanNode         *channel;
128         unsigned long           crc32;
129         unsigned int            count;
130         struct spamNode         *prev;
131         struct spamNode         *next;
132 };
133
134 struct floodNode
135 {
136         struct chanNode         *channel;
137         struct userNode         *owner;
138         unsigned int            count;
139         time_t                  time;
140         struct floodNode        *prev;
141         struct floodNode        *next;
142 };
143
144 struct killNode
145 {
146         unsigned int            warnlevel;
147         time_t                  time;
148 };
149
150 struct userInfo
151 {
152     struct userNode             *user;
153         struct spamNode         *spam;
154         struct floodNode        *flood;
155         struct floodNode        *joinflood;
156         unsigned int            flags : 30;
157         unsigned int            warnlevel;
158         time_t                  lastadv;
159 };
160
161 struct badword {
162     char *id;
163     char *badword_mask;
164     unsigned int triggered : 29;
165     unsigned int action : 3;
166 };
167
168 /***********************************************/
169 /*                 Other Stuff                 */
170 /***********************************************/
171
172 enum cs_unreg
173 {
174     manually,
175     expire,
176     lost_all_users
177 };
178
179 void init_spamserv(const char *nick);
180 struct chanInfo *get_chanInfo(const char *channelname);
181 void spamserv_channel_message(struct chanNode *channel, struct userNode *user, char *text);
182 void spamserv_cs_suspend(struct chanNode *channel, time_t expiry, int suspend, char *reason);
183 int  spamserv_cs_move_merge(struct userNode *user, struct chanNode *channel, struct chanNode *target, int move);
184 void spamserv_cs_unregister(struct userNode *user, struct chanNode *channel, enum cs_unreg type, char *reason);
185 static struct badword *add_badword(struct chanInfo *cInfo, const char *badword_mask, unsigned int triggered, unsigned int action, const char *id);
186
187 #endif