1 /* spamserv.c - anti spam service
2 * Copyright 2004 feigling
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.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, email evilnet-devel@lists.sourceforge.net.
33 #define SPAMSERV_CONF_NAME "services/spamserv"
35 #define KEY_EXCEPTIONS "exceptions"
36 #define KEY_BADWORDS "badwords"
37 #define KEY_FLAGS "flags"
38 #define KEY_INFO "info"
39 #define KEY_EXPIRY "expiry"
40 #define KEY_TRUSTED_HOSTS "trusted"
41 #define KEY_CHANNELS "channel"
42 #define KEY_ISSUER "issuer"
43 #define KEY_ISSUED "issued"
44 #define KEY_TRUSTED_ACCOUNTS "trusted"
45 #define KEY_DEBUG_CHANNEL "debug_channel"
46 #define KEY_GLOBAL_EXCEPTIONS "global_exceptions"
47 #define KEY_GLOBAL_BADWORDS "global_badwords"
48 #define KEY_NETWORK_RULES "network_rules"
49 #define KEY_TRIGGER "trigger"
50 #define KEY_SHORT_BAN_DURATION "short_ban_duration"
51 #define KEY_LONG_BAN_DURATION "long_ban_duration"
52 #define KEY_GLINE_DURATION "gline_duration"
53 #define KEY_EXCEPTION_MAX "exception_max"
54 #define KEY_EXCEPTION_MIN_LEN "exception_min_len"
55 #define KEY_EXCEPTION_MAX_LEN "exception_max_len"
56 #define KEY_BADWORD_MAX "badword_max"
57 #define KEY_BADWORD_MIN_LEN "badword_min_len"
58 #define KEY_BADWORD_MAX_LEN "badword_max_len"
59 #define KEY_ADV_CHAN_MUST_EXIST "adv_chan_must_exist"
60 #define KEY_STRIP_MIRC_CODES "strip_mirc_codes"
61 #define KEY_ALLOW_MOVE_MERGE "allow_move_merge"
62 #define KEY_CAPSMIN "capsmin"
63 #define KEY_CAPSPERCENT "capspercent"
64 #define KEY_EXCEPTLEVEL "exceptlevel"
65 #define KEY_EXCEPTSPAMLEVEL "exceptspamlevel"
66 #define KEY_EXCEPTFLOODLEVEL "exceptfloodlevel"
67 #define KEY_EXCEPTADVLEVEL "exceptadvlevel"
68 #define KEY_EXCEPTBADWORDLEVEL "exceptbadwordlevel"
69 #define KEY_EXCEPTCAPSLEVEL "exceptcapslevel"
71 #define SPAMSERV_FUNC(NAME) MODCMD_FUNC(NAME)
72 #define SPAMSERV_SYNTAX() svccmd_send_help(user, spamserv, cmd)
73 #define SPAMSERV_MIN_PARMS(N) do { \
76 ss_reply(MSG_MISSING_PARAMS, argv[0]); \
78 return 0; } } while(0)
80 struct userNode
*spamserv
;
81 static struct module *spamserv_module
;
82 static struct service
*spamserv_service
;
83 static struct log_type
*SS_LOG
;
84 static unsigned long crc_table
[256];
86 dict_t registered_channels_dict
;
87 dict_t connected_users_dict
;
88 dict_t killed_users_dict
;
90 #define SSFUNC_ARGS user, channel, argc, argv, cmd
92 #define spamserv_notice(target, format...) send_message(target , spamserv , ## format)
93 #define spamserv_debug(format...) do { if(spamserv_conf.debug_channel) send_channel_notice(spamserv_conf.debug_channel , spamserv , ## format); } while(0)
94 #define ss_reply(format...) send_message(user , spamserv , ## format)
96 #define SET_SUBCMDS_SIZE 20
98 const char *set_subcommands
[SET_SUBCMDS_SIZE
] = {"EXCEPTLEVEL", "EXCEPTADVLEVEL", "EXCEPTBADWORDLEVEL", "EXCEPTCAPSLEVEL", "EXCEPTFLOODLEVEL", "EXCEPTSPAMLEVEL", "SPAMLIMIT", "BADREACTION", "CAPSREACTION", "ADVREACTION", "WARNREACTION", "ADVSCAN", "CAPSSCAN", "SPAMSCAN", "BADWORDSCAN", "CHANFLOODSCAN", "JOINFLOODSCAN", "CAPSMIN", "CAPSPERCENT"};
100 extern struct string_list
*autojoin_channels
;
101 static void spamserv_clear_spamNodes(struct chanNode
*channel
);
102 static void spamserv_punish(struct chanNode
*channel
, struct userNode
*user
, time_t expires
, char *reason
, int ban
);
103 static unsigned long crc32(const char *text
);
105 #define BINARY_OPTION(arguments...) return binary_option(arguments, user, channel, argc, argv);
106 #define MULTIPLE_OPTION(arguments...) return multiple_option(arguments, values, ArrayLength(values), user, channel, argc, argv);
108 static const struct message_entry msgtab
[] = {
109 { "SSMSG_CHANNEL_OPTIONS", "Channel Options:" },
110 { "SSMSG_STRING_VALUE", "$b%s$b%s" },
111 { "SSMSG_NUMERIC_VALUE", "$b%s$b%d - %s" },
112 { "SSMSG_INVALID_NUM_SET", "$b'%d'$b is an invalid %s setting." },
113 { "SSMSG_INVALID_OPTION", "$b%s$b is not a valid %s option." },
114 { "SSMSG_INVALID_BINARY", "$b%s$b is an invalid binary value." },
116 { "SSMSG_NOT_REGISTERED", "$b%s$b has not been registered with $b$X$b." },
117 { "SSMSG_NOT_REGISTERED_CS", "$b%s$b has not been registered with $b$C$b." },
118 { "SSMSG_ALREADY_REGISTERED", "$b%s$b is already registered." },
119 { "SSMSG_DEBUG_CHAN", "You may not register the debug channel." },
120 { "SSMSG_SUSPENDED_CS", "$b$C$b access to $b%s$b has been temporarily suspended, thus you can't %s it." },
121 { "SSMSG_SUSPENDED", "$b$X$b access to $b%s$b has been temporarily suspended." },
122 { "SSMSG_NO_REGISTER", "Due to an error it was not possible to register $b%s$b." },
123 { "SSMSG_REG_SUCCESS", "Channel $b%s$b registered." },
124 { "SSMSG_UNREG_SUCCESS", "$b%s$b has been unregistered." },
125 { "SSMSG_NO_ACCESS", "You lack sufficient access to use this command." },
126 { "SSMSG_MUST_BE_OPER", "You must be an irc operator to set this option." },
127 { "SSMSG_CONFIRM_UNREG", "To confirm this unregistration, you must append 'CONFIRM' to the end of your command. For example, 'unregister CONFIRM'." },
129 { "SSMSG_NO_EXCEPTIONS", "No words found in the exception list." },
130 { "SSMSG_NO_SUCH_EXCEPTION", "Word $b%s$b not found in the exception list." },
131 { "SSMSG_EXCEPTION_LIST", "The following words are in the exception list:" },
132 { "SSMSG_EXCEPTION_ADDED", "Word $b%s$b added to the exception list." },
133 { "SSMSG_EXCEPTION_DELETED", "Word $b%s$b deleted from the exception list." },
134 { "SSMSG_EXCEPTION_IN_LIST", "The word $b%s$b is already in the exception list." },
135 { "SSMSG_EXCEPTION_MAX", "The exception list has reached the maximum exceptions (max %lu). Delete a word to add another one." },
136 { "SSMSG_EXCEPTION_TOO_SHORT", "The word must be at least %lu characters long." },
137 { "SSMSG_EXCEPTION_TOO_LONG", "The word may not be longer than %lu characters." },
139 { "SSMSG_NO_BADWORDS", "No words found in the badword list." },
140 { "SSMSG_NO_SUCH_BADWORD", "Word $b%s$b not found in the badword list." },
141 { "SSMSG_BADWORD_LIST", "The following words are in the badword list:" },
142 { "SSMSG_BADWORD_ADDED", "Word $b%s$b added to the badword list." },
143 { "SSMSG_BADWORD_DELETED", "Word $b%s$b deleted from the badword list." },
144 { "SSMSG_BADWORD_IN_LIST", "The word $b%s$b is already in the badword list." },
145 { "SSMSG_BADWORD_MAX", "The badword list has reached the maximum badwords (max %lu). Delete a word to add another one." },
146 { "SSMSG_BADWORD_TOO_SHORT", "The word must be at least %lu characters long." },
147 { "SSMSG_BADWORD_TOO_LONG", "The word may not be longer than %lu characters." },
149 { "SSMSG_STATUS", "$bStatus:$b" },
150 { "SSMSG_STATUS_USERS", "Total Users Online: %u" },
151 { "SSMSG_STATUS_CHANNELS", "Registered Channels: %u" },
152 { "SSMSG_STATUS_MEMORY", "$bMemory Information:$b" },
153 { "SSMSG_STATUS_CHANNEL_LIST", "$bRegistered Channels:$b" },
154 { "SSMSG_STATUS_NO_CHANNEL", "No channels registered." },
156 { "SSMSG_WARNING_T", "%s is against the network rules" },
157 { "SSMSG_WARNING_2_T", "You are violating the network rules" },
158 { "SSMSG_WARNING_RULES_T", "%s is against the network rules. Read the network rules at %s" },
159 { "SSMSG_WARNING_RULES_2_T", "You are violating the network rules. Read the network rules at %s" },
161 { "SSMSG_ALREADY_TRUSTED", "Account $b%s$b is already trusted." },
162 { "SSMSG_NOT_TRUSTED", "Account $b%s$b is not trusted." },
163 { "SSMSG_ADDED_TRUSTED", "Added %s to the global trusted-accounts list" },
164 { "SSMSG_ADDED_TRUSTED_CHANNEL", "Added %s to the trusted-accounts list for channel %s." },
165 { "SSMSG_REMOVED_TRUSTED", "Removed %s from the global trusted-accounts list." },
166 { "SSMSG_REMOVED_TRUSTED_CHANNEL", "Removed %s from channel %s trusted-account list." },
167 { "SSMSG_TRUSTED_LIST", "$bTrusted Accounts$b" },
168 { "SSMSG_TRUSTED_LIST_HEADER", "Account Added By Time" },
169 { "SSMSG_HOST_IS_TRUSTED", "%-15s %-10s set %s ago" },
170 { "SSMSG_TRUSTED_LIST_BAR", "----------------------------------------" },
171 { "SSMSG_TRUSTED_LIST_END", "---------End of Trusted Accounts--------" },
172 { "SSMSG_HOST_NOT_TRUSTED", "%s does not have a special trust." },
174 { "SSMSG_MUST_BE_HELPING", "You must have security override (helping mode) on to use this command." },
176 { "SSMSG_SET_CAPSMIN", "$bCapsMin$b %d - atleast this min caps and atleast CapsPercent of the total line." },
177 { "SSMSG_SET_CAPSPERCENT", "$bCapsPercent$b %d - atleast CapsPercent of the total line." },
178 { "SSMSG_SET_EXCEPTLEVEL" , "$bExceptLevel$b %d - level and above will be excepted from all checks." },
179 { "SSMSG_SET_EXCEPTADVLEVEL", "$bExceptAdvLevel$b %d - and above will be excepted from advertising checks." },
180 { "SSMSG_SET_EXCEPTBADWORDLEVEL", "$bExceptBadWordLevel$b %d - and above will be excepted from badword checks." },
181 { "SSMSG_SET_EXCEPTCAPSLEVEL" , "$bExceptCapsLevel$b %d - and above will be excepted from caps checks." },
182 { "SSMSG_SET_EXCEPTFLOODLEVEL", "$bExceptFloodLevel$b %d - and above will be excepted from flood checks." },
183 { "SSMSG_SET_EXCEPTSPAMLEVEL", "$bExceptSpamLevel$b %d - and above will be excepted from spam checks." },
188 #define SSMSG_DEBUG_KICK "Kicked user $b%s$b from $b%s$b, reason: %s"
189 #define SSMSG_DEBUG_BAN "Banned user $b%s$b from $b%s$b, reason: %s"
190 #define SSMSG_DEBUG_KILL "Killed user $b%s$b, last violation in $b%s$b"
191 #define SSMSG_DEBUG_GLINE "Glined user $b%s$b, host $b%s$b, last violation in $b%s$b"
192 #define SSMSG_DEBUG_RECONNECT "Killed user $b%s$b reconnected to the network"
194 #define SSMSG_SPAM "Spamming"
195 #define SSMSG_FLOOD "Flooding the channel/network"
196 #define SSMSG_ADV "Advertising"
197 #define SSMSG_BAD "Badwords"
198 #define SSMSG_CAPS "Caps"
199 #define SSMSG_JOINFLOOD "Join flooding the channel"
201 #define SSMSG_WARNING "%s is against the network rules"
202 #define SSMSG_WARNING_2 "You are violating the network rules"
203 #define SSMSG_WARNING_RULES "%s is against the network rules. Read the network rules at %s"
204 #define SSMSG_WARNING_RULES_2 "You are violating the network rules. Read the network rules at %s"
207 #define SSMSG_WARNING "SSMSG_WARNING_T"
208 #define SSMSG_WARNING_2 "SSMSG_WARNING_2_T"
209 #define SSMSG_WARNING_RULES "SSMSG_WARNING_RULES_T"
210 #define SSMSG_WARNING_RULES_2 "SSMSG_WARNING_RULES_2_T"
213 static dict_t spamserv_trusted_accounts
;
217 struct chanNode
*debug_channel
;
218 struct string_list
*global_exceptions
;
219 struct string_list
*global_badwords
;
220 const char *network_rules
;
221 unsigned char trigger
;
222 unsigned long short_ban_duration
;
223 unsigned long long_ban_duration
;
224 unsigned long gline_duration
;
225 unsigned long exception_max
;
226 unsigned long exception_min_len
;
227 unsigned long exception_max_len
;
228 unsigned long badword_max
;
229 unsigned long badword_min_len
;
230 unsigned long badword_max_len
;
231 unsigned int adv_chan_must_exist
: 1;
232 unsigned int strip_mirc_codes
: 1;
233 unsigned int allow_move_merge
: 1;
234 unsigned long untrusted_max
;
237 struct trusted_account
{
239 struct string_list
*channel
;
245 /***********************************************/
247 /***********************************************/
250 get_chanInfo(const char *channelname
)
252 return dict_find(registered_channels_dict
, channelname
, 0);
256 spamserv_join_channel(struct chanNode
*channel
)
258 struct mod_chanmode change
;
259 mod_chanmode_init(&change
);
261 change
.args
[0].mode
= MODE_CHANOP
;
262 change
.args
[0].u
.member
= AddChannelUser(spamserv
, channel
);
263 mod_chanmode_announce(spamserv
, channel
, &change
);
267 spamserv_part_channel(struct chanNode
*channel
, char *reason
)
269 /* we only have to clear the spamNodes because every other node expires on it's own */
270 spamserv_clear_spamNodes(channel
);
271 DelChannelUser(spamserv
, channel
, reason
, 0);
274 static struct chanInfo
*
275 spamserv_register_channel(struct chanNode
*channel
, struct string_list
*exceptions
, struct string_list
*badwords
, unsigned int flags
, char *info
)
277 struct chanInfo
*cInfo
= malloc(sizeof(struct chanInfo
));
281 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for cInfo; channel: %s", channel
->name
);
285 cInfo
->channel
= channel
;
286 cInfo
->exceptions
= exceptions
? string_list_copy(exceptions
) : alloc_string_list(1);
287 cInfo
->badwords
= badwords
? string_list_copy(badwords
) : alloc_string_list(1);
288 cInfo
->flags
= flags
;
289 cInfo
->exceptlevel
= 300;
290 cInfo
->exceptspamlevel
= 100;
291 cInfo
->exceptadvlevel
= 100;
292 cInfo
->exceptbadwordlevel
= 100;
293 cInfo
->exceptcapslevel
= 100;
294 cInfo
->exceptfloodlevel
= 100;
296 cInfo
->capspercent
= 25;
297 if (strlen(info
) < 5)
300 safestrncpy(cInfo
->info
, info
, sizeof(cInfo
->info
));
301 cInfo
->suspend_expiry
= 0;
302 dict_insert(registered_channels_dict
, strdup(cInfo
->channel
->name
), cInfo
);
308 spamserv_unregister_channel(struct chanInfo
*cInfo
)
313 free_string_list(cInfo
->exceptions
);
314 free_string_list(cInfo
->badwords
);
315 dict_remove(registered_channels_dict
, cInfo
->channel
->name
);
320 spamserv_cs_suspend(struct chanNode
*channel
, time_t expiry
, int suspend
, char *reason
)
322 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
328 cInfo
->flags
|= CHAN_SUSPENDED
;
329 cInfo
->suspend_expiry
= expiry
;
330 spamserv_part_channel(channel
, reason
);
334 if(CHECK_SUSPENDED(cInfo
))
336 cInfo
->flags
&= ~CHAN_SUSPENDED
;
337 cInfo
->suspend_expiry
= 0;
344 spamserv_cs_move_merge(struct userNode
*user
, struct chanNode
*channel
, struct chanNode
*target
, int move
)
346 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
352 if(!spamserv_conf
.allow_move_merge
|| get_chanInfo(target
->name
))
355 snprintf(reason
, sizeof(reason
), "unregistered due to a channel move to %s", target
->name
);
357 snprintf(reason
, sizeof(reason
), "unregistered due to a channel merge into %s", target
->name
);
359 spamserv_cs_unregister(user
, channel
, manually
, reason
);
363 cInfo
->channel
= target
;
365 dict_remove(registered_channels_dict
, channel
->name
);
366 dict_insert(registered_channels_dict
, strdup(target
->name
), cInfo
);
370 snprintf(reason
, sizeof(reason
), "Channel moved to %s by %s.", target
->name
, user
->handle_info
->handle
);
374 spamserv_join_channel(target
);
375 snprintf(reason
, sizeof(reason
), "%s merged into %s by %s.", channel
->name
, target
->name
, user
->handle_info
->handle
);
378 if(!CHECK_SUSPENDED(cInfo
))
379 spamserv_part_channel(channel
, reason
);
382 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
,
383 "SSMSG_CHANNEL_MOVED", channel
->name
, target
->name
,
384 user
->handle_info
->handle
);
386 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
,
387 "SSMSG_CHANNEL_MERGED", channel
->name
, target
->name
,
388 user
->handle_info
->handle
);
397 spamserv_cs_unregister(struct userNode
*user
, struct chanNode
*channel
, enum cs_unreg type
, char *reason
)
399 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
403 char partmsg
[MAXLEN
];
408 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, "SSMSG_UNREG_MANUAL",
409 channel
->name
, reason
, user
->handle_info
->handle
);
410 snprintf(partmsg
, sizeof(partmsg
), "%s %s by %s.", channel
->name
, reason
, user
->handle_info
->handle
);
413 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, "SSMSG_REG_EXPIRED",
415 snprintf(partmsg
, sizeof(partmsg
), "%s registration expired.", channel
->name
);
418 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, "SSMSG_LOST_ALL_USERS",
420 snprintf(partmsg
, sizeof(partmsg
), "%s lost all users.", channel
->name
);
424 if(!CHECK_SUSPENDED(cInfo
))
425 spamserv_part_channel(channel
, partmsg
);
427 spamserv_unregister_channel(cInfo
);
431 /***********************************************/
433 /***********************************************/
435 static struct userInfo
*
436 get_userInfo(const char *nickname
)
438 return dict_find(connected_users_dict
, nickname
, 0);
442 spamserv_create_spamNode(struct chanNode
*channel
, struct userInfo
*uInfo
, char *text
)
444 struct spamNode
*sNode
= malloc(sizeof(struct spamNode
));
448 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for sNode; channel: %s; user: %s", channel
->name
, uInfo
->user
->nick
);
452 sNode
->channel
= channel
;
453 sNode
->crc32
= crc32(text
);
459 struct spamNode
*temp
= uInfo
->spam
;
475 spamserv_delete_spamNode(struct userInfo
*uInfo
, struct spamNode
*sNode
)
480 if(sNode
== uInfo
->spam
)
481 uInfo
->spam
= sNode
->next
;
484 sNode
->next
->prev
= sNode
->prev
;
486 sNode
->prev
->next
= sNode
->next
;
492 spamserv_clear_spamNodes(struct chanNode
*channel
)
494 struct userInfo
*uInfo
;
495 struct spamNode
*sNode
;
498 for(i
= 0; i
< channel
->members
.used
; i
++)
500 if((uInfo
= get_userInfo(channel
->members
.list
[i
]->user
->nick
)))
502 if((sNode
= uInfo
->spam
))
504 for(; sNode
; sNode
= sNode
->next
)
505 if(sNode
->channel
== channel
)
509 spamserv_delete_spamNode(uInfo
, sNode
);
516 spamserv_create_floodNode(struct chanNode
*channel
, struct userNode
*user
, struct floodNode
**uI_fNode
)
518 struct floodNode
*fNode
= malloc(sizeof(struct floodNode
));
522 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for fNode; channel: %s; user: %s", channel
->name
, user
->nick
);
526 fNode
->channel
= channel
;
534 struct floodNode
*temp
= *uI_fNode
;
550 spamserv_delete_floodNode(struct floodNode
**uI_fNode
, struct floodNode
*fNode
)
555 if(fNode
== *uI_fNode
)
556 *uI_fNode
= fNode
->next
;
559 fNode
->next
->prev
= fNode
->prev
;
561 fNode
->prev
->next
= fNode
->next
;
567 spamserv_create_user(struct userNode
*user
)
569 struct userInfo
*uInfo
= malloc(sizeof(struct userInfo
));
570 struct killNode
*kNode
= dict_find(killed_users_dict
, irc_ntoa(&user
->ip
), 0);
574 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for uInfo; nick: %s", user
->nick
);
579 spamserv_debug(SSMSG_DEBUG_RECONNECT
, user
->nick
);
584 uInfo
->joinflood
= NULL
;
585 uInfo
->flags
= kNode
? USER_KILLED
: 0;
586 uInfo
->warnlevel
= kNode
? kNode
->warnlevel
: 0;
591 dict_insert(connected_users_dict
, strdup(user
->nick
), uInfo
);
595 dict_remove(killed_users_dict
, irc_ntoa(&user
->ip
));
601 spamserv_delete_user(struct userInfo
*uInfo
)
608 spamserv_delete_spamNode(uInfo
, uInfo
->spam
);
612 spamserv_delete_floodNode(&uInfo
->flood
, uInfo
->flood
);
615 while(uInfo
->joinflood
)
616 spamserv_delete_floodNode(&uInfo
->joinflood
, uInfo
->joinflood
);
618 dict_remove(connected_users_dict
, uInfo
->user
->nick
);
623 spamserv_new_user_func(struct userNode
*user
)
626 spamserv_create_user(user
);
632 spamserv_del_user_func(struct userNode
*user
, struct userNode
*killer
, UNUSED_ARG(const char *why
))
634 struct userInfo
*uInfo
= get_userInfo(user
->nick
);
635 struct killNode
*kNode
;
637 if(killer
== spamserv
)
639 kNode
= malloc(sizeof(struct killNode
));
643 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for killNode - nickname %s", user
->nick
);
644 spamserv_delete_user(uInfo
);
648 if(uInfo
->warnlevel
> KILL_WARNLEVEL
)
649 kNode
->warnlevel
= uInfo
->warnlevel
- KILL_WARNLEVEL
;
651 kNode
->warnlevel
= 0;
655 dict_insert(killed_users_dict
, strdup(irc_ntoa(&user
->ip
)), kNode
);
658 spamserv_delete_user(uInfo
);
662 spamserv_nick_change_func(struct userNode
*user
, const char *old_nick
)
664 struct userInfo
*uInfo
= get_userInfo(old_nick
);
667 dict_remove(connected_users_dict
, old_nick
);
668 dict_insert(connected_users_dict
, strdup(user
->nick
), uInfo
);
673 spamserv_user_join(struct modeNode
*mNode
)
675 struct chanNode
*channel
= mNode
->channel
;
676 struct userNode
*user
= mNode
->user
;
677 struct chanInfo
*cInfo
;
678 struct userInfo
*uInfo
;
679 struct floodNode
*jfNode
;
681 if(user
->uplink
->burst
|| !(cInfo
= get_chanInfo(channel
->name
)) || !CHECK_JOINFLOOD(cInfo
) || !(uInfo
= get_userInfo(user
->nick
)))
684 if(!(jfNode
= uInfo
->joinflood
))
686 spamserv_create_floodNode(channel
, user
, &uInfo
->joinflood
);
690 for(; jfNode
; jfNode
= jfNode
->next
)
691 if(jfNode
->channel
== channel
)
696 spamserv_create_floodNode(channel
, user
, &uInfo
->joinflood
);
703 if(jfNode
->count
> JOINFLOOD_MAX
)
707 spamserv_delete_floodNode(&uInfo
->joinflood
, jfNode
);
708 snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_JOINFLOOD
, spamserv_conf
.network_rules
);
709 spamserv_punish(channel
, user
, JOINFLOOD_B_DURATION
, reason
, 1);
718 spamserv_user_part(struct modeNode
*mn
, UNUSED_ARG(const char *reason
))
720 struct userNode
*user
= mn
->user
;
721 struct chanNode
*channel
= mn
->channel
;
722 struct userInfo
*uInfo
;
723 struct spamNode
*sNode
;
724 struct floodNode
*fNode
;
726 if(user
->dead
|| !get_chanInfo(channel
->name
) || !(uInfo
= get_userInfo(user
->nick
)))
729 if((sNode
= uInfo
->spam
))
731 for(; sNode
; sNode
= sNode
->next
)
732 if(sNode
->channel
== channel
)
736 spamserv_delete_spamNode(uInfo
, sNode
);
739 if((fNode
= uInfo
->flood
))
741 for(; fNode
; fNode
= fNode
->next
)
742 if(fNode
->channel
== channel
)
746 spamserv_delete_floodNode(&uInfo
->flood
, fNode
);
750 /***********************************************/
752 /***********************************************/
760 for(i
= 0; i
< 256; i
++)
764 for(j
= 8; j
> 0; j
--)
768 crc
= (crc
>> 1) ^ 0xEDB88320L
;
781 crc32(const char *text
)
783 register unsigned long crc
= 0xFFFFFFFF;
784 unsigned int c
, i
= 0;
786 while((c
= (unsigned int)text
[i
++]) != 0)
787 crc
= ((crc
>> 8) & 0x00FFFFFF) ^ crc_table
[(crc
^c
) & 0xFF];
789 return (crc
^0xFFFFFFFF);
793 timeq_flood(UNUSED_ARG(void *data
))
796 struct userInfo
*uInfo
;
797 struct floodNode
*fNode
;
799 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
801 uInfo
= iter_data(it
);
806 if(!(fNode
= uInfo
->flood
))
809 for(; fNode
; fNode
= fNode
->next
)
811 if(now
- fNode
->time
> FLOOD_EXPIRE
)
813 if(!(--fNode
->count
))
814 spamserv_delete_floodNode(&uInfo
->flood
, fNode
);
819 timeq_add(now
+ FLOOD_TIMEQ_FREQ
, timeq_flood
, NULL
);
823 timeq_joinflood(UNUSED_ARG(void *data
))
826 struct userInfo
*uInfo
;
827 struct floodNode
*fNode
, *nextnode
;
829 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
831 uInfo
= iter_data(it
);
833 if(!(fNode
= uInfo
->joinflood
))
836 for(; fNode
; fNode
= nextnode
)
838 nextnode
= fNode
->next
;
839 if(now
- fNode
->time
> JOINFLOOD_EXPIRE
)
841 if(!(--fNode
->count
))
842 spamserv_delete_floodNode(&uInfo
->joinflood
, fNode
);
847 timeq_add(now
+ JOINFLOOD_TIMEQ_FREQ
, timeq_joinflood
, NULL
);
851 timeq_bad(UNUSED_ARG(void *data
))
854 struct userInfo
*uInfo
;
856 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
858 uInfo
= iter_data(it
);
860 if(uInfo
->lastbad
&& uInfo
->lastbad
- now
> BAD_EXPIRE
)
863 uInfo
->flags
&= ~USER_BAD_WARNED
;
867 timeq_add(now
+ BAD_TIMEQ_FREQ
, timeq_bad
, NULL
);
871 timeq_caps(UNUSED_ARG(void *data
))
874 struct userInfo
*uInfo
;
876 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
878 uInfo
= iter_data(it
);
880 if(uInfo
->lastcaps
&& uInfo
->lastcaps
- now
> CAPS_EXPIRE
)
883 uInfo
->flags
&= ~USER_CAPS_WARNED
;
887 timeq_add(now
+ CAPS_TIMEQ_FREQ
, timeq_caps
, NULL
);
891 timeq_adv(UNUSED_ARG(void *data
))
894 struct userInfo
*uInfo
;
896 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
898 uInfo
= iter_data(it
);
900 if(uInfo
->lastadv
&& uInfo
->lastadv
- now
> ADV_EXPIRE
)
903 uInfo
->flags
&= ~USER_ADV_WARNED
;
907 timeq_add(now
+ ADV_TIMEQ_FREQ
, timeq_adv
, NULL
);
911 timeq_warnlevel(UNUSED_ARG(void *data
))
914 struct userInfo
*uInfo
;
916 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
918 uInfo
= iter_data(it
);
920 if(uInfo
->warnlevel
> 0)
924 timeq_add(now
+ WARNLEVEL_TIMEQ_FREQ
, timeq_warnlevel
, NULL
);
928 timeq_kill(UNUSED_ARG(void *data
))
931 struct killNode
*kNode
;
934 for(it
= dict_first(killed_users_dict
); it
; it
= iter_next(it
))
936 kNode
= iter_data(it
);
938 if(now
- kNode
->time
> KILL_EXPIRE
) {
939 dict_remove(killed_users_dict
, iter_key(it
));
940 /* have to restart the loop because next is
941 * now invalid. FIXME: how could we do this better? */
942 break; /* out of for() loop */
945 /* no more killed_users to delete, so stop while loop */
946 break; /* out of while() loop */
949 timeq_add(now
+ KILL_TIMEQ_FREQ
, timeq_kill
, NULL
);
953 binary_option(char *name
, unsigned long mask
, struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[])
955 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
960 if(enabled_string(argv
[1]))
962 cInfo
->flags
|= mask
;
965 else if(disabled_string(argv
[1]))
967 cInfo
->flags
&= ~mask
;
972 spamserv_notice(user
, "SSMSG_INVALID_BINARY", argv
[1]);
978 value
= (cInfo
->flags
& mask
) ? 1 : 0;
981 spamserv_notice(user
, "SSMSG_STRING_VALUE", name
, value
? "Enabled." : "Disabled.");
993 multiple_option(char *name
, char *description
, enum channelinfo info
, struct valueData
*values
, int count
, struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[])
995 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1000 index
= atoi(argv
[1]);
1002 if(index
< 0 || index
>= count
)
1004 spamserv_notice(user
, "SSMSG_INVALID_NUM_SET", index
, description
);
1006 for(index
= 0; index
< count
; index
++)
1007 spamserv_notice(user
, "SSMSG_NUMERIC_VALUE", name
, index
, values
[index
].description
);
1012 if(values
[index
].oper_only
&& !IsOper(user
))
1014 spamserv_notice(user
, "SSMSG_MUST_BE_OPER");
1018 cInfo
->info
[info
] = values
[index
].value
;
1022 for(index
= 0; index
< count
&& cInfo
->info
[info
] != values
[index
].value
; index
++);
1025 spamserv_notice(user
, "SSMSG_NUMERIC_VALUE", name
, index
, values
[index
].description
);
1030 show_exceptions(struct userNode
*user
, struct chanInfo
*cInfo
)
1032 struct helpfile_table table
;
1035 if(!cInfo
->exceptions
->used
)
1037 spamserv_notice(user
, "SSMSG_NO_EXCEPTIONS");
1041 spamserv_notice(user
, "SSMSG_EXCEPTION_LIST");
1045 table
.flags
= TABLE_REPEAT_ROWS
| TABLE_NO_FREE
| TABLE_NO_HEADERS
;
1046 table
.contents
= alloca(cInfo
->exceptions
->used
* sizeof(*table
.contents
));
1048 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1050 table
.contents
[table
.length
] = alloca(table
.width
* sizeof(**table
.contents
));
1051 table
.contents
[table
.length
][0] = cInfo
->exceptions
->list
[i
];
1055 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
1061 show_badwords(struct userNode
*user
, struct chanInfo
*cInfo
)
1063 struct helpfile_table table
;
1066 if(!cInfo
->badwords
->used
)
1068 spamserv_notice(user
, "SSMSG_NO_BADWORDS");
1072 spamserv_notice(user
, "SSMSG_BADWORD_LIST");
1076 table
.flags
= TABLE_REPEAT_ROWS
| TABLE_NO_FREE
| TABLE_NO_HEADERS
;
1077 table
.contents
= alloca(cInfo
->badwords
->used
* sizeof(*table
.contents
));
1079 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1081 table
.contents
[table
.length
] = alloca(table
.width
* sizeof(**table
.contents
));
1082 table
.contents
[table
.length
][0] = cInfo
->badwords
->list
[i
];
1086 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
1092 show_memory_usage(struct userNode
*user
)
1095 struct helpfile_table table
;
1096 struct chanInfo
*cInfo
;
1097 struct userInfo
*uInfo
;
1098 struct spamNode
*sNode
;
1099 struct floodNode
*fNode
;
1100 double channel_size
= 0, user_size
, size
;
1101 unsigned int spamcount
= 0, floodcount
= 0, i
, j
;
1104 for(it
= dict_first(registered_channels_dict
); it
; it
= iter_next(it
))
1106 cInfo
= iter_data(it
);
1108 if(!cInfo
->exceptions
->used
)
1111 if(!cInfo
->badwords
->used
)
1114 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1115 channel_size
+= strlen(cInfo
->exceptions
->list
[i
]) * sizeof(char);
1117 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1118 channel_size
+= strlen(cInfo
->badwords
->list
[i
]) * sizeof(char);
1121 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
1123 uInfo
= iter_data(it
);
1125 for(sNode
= uInfo
->spam
; sNode
; sNode
= sNode
->next
, spamcount
++);
1126 for(fNode
= uInfo
->flood
; fNode
; fNode
= fNode
->next
, floodcount
++);
1127 for(fNode
= uInfo
->joinflood
; fNode
; fNode
= fNode
->next
, floodcount
++);
1130 channel_size
+= dict_size(registered_channels_dict
) * sizeof(struct chanInfo
);
1132 user_size
= dict_size(connected_users_dict
) * sizeof(struct userInfo
) +
1133 dict_size(killed_users_dict
) * sizeof(struct killNode
) +
1134 spamcount
* sizeof(struct spamNode
) +
1135 floodcount
* sizeof(struct floodNode
);
1137 size
= channel_size
+ user_size
;
1139 ss_reply("SSMSG_STATUS_MEMORY");
1143 table
.flags
= TABLE_NO_FREE
| TABLE_NO_HEADERS
| TABLE_PAD_LEFT
;
1144 table
.contents
= calloc(table
.length
, sizeof(char**));
1147 table
.contents
[0] = calloc(table
.width
, sizeof(char*));
1148 snprintf(buffer
, sizeof(buffer
), "Channel Memory Usage:");
1149 table
.contents
[0][0] = strdup(buffer
);
1150 snprintf(buffer
, sizeof(buffer
), " %g Byte; ", channel_size
);
1151 table
.contents
[0][1] = strdup(buffer
);
1152 snprintf(buffer
, sizeof(buffer
), "%g KiloByte; ", channel_size
/ 1024);
1153 table
.contents
[0][2] = strdup(buffer
);
1154 snprintf(buffer
, sizeof(buffer
), "%g MegaByte", channel_size
/ 1024 / 1024);
1155 table
.contents
[0][3] = strdup(buffer
);
1158 table
.contents
[1] = calloc(table
.width
, sizeof(char*));
1159 snprintf(buffer
, sizeof(buffer
), "User Memory Usage :");
1160 table
.contents
[1][0] = strdup(buffer
);
1161 snprintf(buffer
, sizeof(buffer
), " %g Byte; ", user_size
);
1162 table
.contents
[1][1] = strdup(buffer
);
1163 snprintf(buffer
, sizeof(buffer
), "%g KiloByte; ", user_size
/ 1024);
1164 table
.contents
[1][2] = strdup(buffer
);
1165 snprintf(buffer
, sizeof(buffer
), "%g MegaByte", user_size
/ 1024 / 1024);
1166 table
.contents
[1][3] = strdup(buffer
);
1168 // total memory usage
1169 table
.contents
[2] = calloc(table
.width
, sizeof(char*));
1170 snprintf(buffer
, sizeof(buffer
), "Total Memory Usage :");
1171 table
.contents
[2][0] = strdup(buffer
);
1172 snprintf(buffer
, sizeof(buffer
), " %g Byte; ", size
);
1173 table
.contents
[2][1] = strdup(buffer
);
1174 snprintf(buffer
, sizeof(buffer
), "%g KiloByte; ", size
/ 1024);
1175 table
.contents
[2][2] = strdup(buffer
);
1176 snprintf(buffer
, sizeof(buffer
), "%g MegaByte", size
/ 1024 / 1024);
1177 table
.contents
[2][3] = strdup(buffer
);
1179 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
1181 for(i
= 0; i
< table
.length
; i
++)
1183 for(j
= 0; j
< table
.width
; j
++)
1184 free((char*)table
.contents
[i
][j
]);
1186 free(table
.contents
[i
]);
1189 free(table
.contents
);
1193 show_registered_channels(struct userNode
*user
)
1195 struct helpfile_table table
;
1198 spamserv_notice(user
, "SSMSG_STATUS_CHANNEL_LIST");
1200 if(!dict_size(registered_channels_dict
))
1202 spamserv_notice(user
, "SSMSG_STATUS_NO_CHANNEL");
1208 table
.flags
= TABLE_REPEAT_ROWS
| TABLE_NO_FREE
| TABLE_NO_HEADERS
;
1209 table
.contents
= alloca(dict_size(registered_channels_dict
) * sizeof(*table
.contents
));
1211 for(it
= dict_first(registered_channels_dict
); it
; it
= iter_next(it
))
1213 struct chanInfo
*cInfo
= iter_data(it
);
1215 table
.contents
[table
.length
] = alloca(table
.width
* sizeof(**table
.contents
));
1216 table
.contents
[table
.length
][0] = cInfo
->channel
->name
;
1220 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
1223 /***********************************************/
1225 /***********************************************/
1228 SPAMSERV_FUNC(cmd_register
)
1230 struct chanInfo
*cInfo
;
1232 if(!channel
|| !channel
->channel_info
)
1234 ss_reply("SSMSG_NOT_REGISTERED_CS", channel
->name
);
1238 if(get_chanInfo(channel
->name
))
1240 ss_reply("SSMSG_ALREADY_REGISTERED", channel
->name
);
1244 if(IsSuspended(channel
->channel_info
))
1246 ss_reply("SSMSG_SUSPENDED_CS", channel
->name
, "register");
1250 if(channel
== spamserv_conf
.debug_channel
)
1252 ss_reply("SSMSG_DEBUG_CHAN");
1256 if(!(cInfo
= spamserv_register_channel(channel
, spamserv_conf
.global_exceptions
, spamserv_conf
.global_badwords
, CHAN_FLAGS_DEFAULT
, CHAN_INFO_DEFAULT
)))
1258 ss_reply("SSMSG_NO_REGISTER", channel
->name
);
1262 spamserv_join_channel(cInfo
->channel
);
1264 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, "SSMSG_REGISTERED_BY",
1265 channel
->name
, user
->handle_info
->handle
);
1266 ss_reply("SSMSG_REG_SUCCESS", channel
->name
);
1272 SPAMSERV_FUNC(cmd_unregister
)
1274 struct chanInfo
*cInfo
;
1275 struct chanData
*cData
;
1276 struct userData
*uData
;
1277 char reason
[MAXLEN
];
1279 if(!channel
|| !(cData
= channel
->channel_info
) || !(cInfo
= get_chanInfo(channel
->name
)))
1281 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1285 if(!(uData
= GetChannelUser(cData
, user
->handle_info
)) || (uData
->access
< UL_OWNER
))
1287 ss_reply("SSMSG_NO_ACCESS");
1291 if(!IsHelping(user
))
1293 if(IsSuspended(cData
))
1295 ss_reply("SSMSG_SUSPENDED_CS", channel
->name
, "unregister");
1299 if(argc
< 2 || strcasecmp(argv
[1], "CONFIRM"))
1301 ss_reply("SSMSG_CONFIRM_UNREG");
1306 if(!CHECK_SUSPENDED(cInfo
))
1308 snprintf(reason
, sizeof(reason
), "%s unregistered by %s.", spamserv
->nick
, user
->handle_info
->handle
);
1309 spamserv_part_channel(channel
, reason
);
1312 spamserv_unregister_channel(cInfo
);
1314 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, "SSMSG_UNREGISTERED_BY",
1315 channel
->name
, user
->handle_info
->handle
);
1316 ss_reply("SSMSG_UNREG_SUCCESS", channel
->name
);
1322 SPAMSERV_FUNC(cmd_status
)
1324 ss_reply("SSMSG_STATUS");
1325 ss_reply("SSMSG_STATUS_USERS", dict_size(connected_users_dict
));
1326 ss_reply("SSMSG_STATUS_CHANNELS", dict_size(registered_channels_dict
));
1328 if(IsOper(user
) && argc
> 1)
1330 if(!irccasecmp(argv
[1], "memory"))
1331 show_memory_usage(user
);
1332 else if(!irccasecmp(argv
[1], "channels"))
1333 show_registered_channels(user
);
1340 SPAMSERV_FUNC(cmd_addexception
)
1342 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1343 struct userData
*uData
;
1346 if(!cInfo
|| !channel
->channel_info
)
1348 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1352 if(CHECK_SUSPENDED(cInfo
))
1354 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1358 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1360 ss_reply("SSMSG_NO_ACCESS");
1365 return show_exceptions(user
, cInfo
);
1367 if(cInfo
->exceptions
->used
== spamserv_conf
.exception_max
&& !IsOper(user
))
1369 ss_reply("SSMSG_EXCEPTION_MAX", spamserv_conf
.exception_max
);
1373 if(strlen(argv
[1]) < spamserv_conf
.exception_min_len
)
1375 ss_reply("SSMSG_EXCEPTION_TOO_SHORT", spamserv_conf
.exception_min_len
);
1378 else if(strlen(argv
[1]) > spamserv_conf
.exception_max_len
)
1380 ss_reply("SSMSG_EXCEPTION_TOO_LONG", spamserv_conf
.exception_max_len
);
1384 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1386 if(!irccasecmp(argv
[1], cInfo
->exceptions
->list
[i
]))
1388 ss_reply("SSMSG_EXCEPTION_IN_LIST", argv
[1]);
1393 string_list_append(cInfo
->exceptions
, strdup(argv
[1]));
1394 ss_reply("SSMSG_EXCEPTION_ADDED", argv
[1]);
1400 SPAMSERV_FUNC(cmd_delexception
)
1402 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1403 struct userData
*uData
;
1407 if(!cInfo
|| !channel
->channel_info
)
1409 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1413 if(CHECK_SUSPENDED(cInfo
))
1415 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1419 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1421 ss_reply("SSMSG_NO_ACCESS");
1426 return show_exceptions(user
, cInfo
);
1428 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1430 if(!irccasecmp(argv
[1], cInfo
->exceptions
->list
[i
]))
1439 ss_reply("SSMSG_NO_SUCH_EXCEPTION", argv
[1]);
1443 string_list_delete(cInfo
->exceptions
, i
);
1444 ss_reply("SSMSG_EXCEPTION_DELETED", argv
[1]);
1450 SPAMSERV_FUNC(cmd_addbadword
)
1452 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1453 struct userData
*uData
;
1456 if(!cInfo
|| !channel
->channel_info
)
1458 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1462 if(CHECK_SUSPENDED(cInfo
))
1464 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1468 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1470 ss_reply("SSMSG_NO_ACCESS");
1475 return show_badwords(user
, cInfo
);
1477 if(cInfo
->badwords
->used
== spamserv_conf
.badword_max
&& !IsOper(user
))
1479 ss_reply("SSMSG_BADWORD_MAX", spamserv_conf
.badword_max
);
1483 if(strlen(argv
[1]) < spamserv_conf
.badword_min_len
)
1485 ss_reply("SSMSG_BADWORD_TOO_SHORT", spamserv_conf
.badword_min_len
);
1488 else if(strlen(argv
[1]) > spamserv_conf
.badword_max_len
)
1490 ss_reply("SSMSG_BADWORD_TOO_LONG", spamserv_conf
.badword_max_len
);
1494 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1496 if(!irccasecmp(argv
[1], cInfo
->badwords
->list
[i
]))
1498 ss_reply("SSMSG_BADWORD_IN_LIST", argv
[1]);
1503 string_list_append(cInfo
->badwords
, strdup(argv
[1]));
1504 ss_reply("SSMSG_BADWORD_ADDED", argv
[1]);
1510 SPAMSERV_FUNC(cmd_delbadword
)
1512 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1513 struct userData
*uData
;
1517 if(!cInfo
|| !channel
->channel_info
)
1519 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1523 if(CHECK_SUSPENDED(cInfo
))
1525 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1529 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1531 ss_reply("SSMSG_NO_ACCESS");
1536 return show_badwords(user
, cInfo
);
1538 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1540 if(!irccasecmp(argv
[1], cInfo
->badwords
->list
[i
]))
1549 ss_reply("SSMSG_NO_SUCH_BADWORD", argv
[1]);
1553 string_list_delete(cInfo
->badwords
, i
);
1554 ss_reply("SSMSG_BADWORD_DELETED", argv
[1]);
1560 SPAMSERV_FUNC(cmd_set
)
1562 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1563 struct userData
*uData
;
1564 struct svccmd
*subcmd
;
1565 char cmd_name
[MAXLEN
];
1570 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1574 if(CHECK_SUSPENDED(cInfo
))
1576 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1580 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1582 ss_reply("SSMSG_NO_ACCESS");
1588 ss_reply("SSMSG_CHANNEL_OPTIONS");
1590 for(i
= 0; i
< SET_SUBCMDS_SIZE
; i
++)
1592 sprintf(cmd_name
, "%s %s", cmd
->name
, set_subcommands
[i
]);
1594 if((subcmd
= dict_find(cmd
->parent
->commands
, cmd_name
, NULL
)))
1595 subcmd
->command
->func(user
, channel
, 1, argv
+ 1, subcmd
);
1601 sprintf(cmd_name
, "%s %s", cmd
->name
, argv
[1]);
1602 subcmd
= dict_find(cmd
->parent
->commands
, cmd_name
, NULL
);
1606 reply("SSMSG_INVALID_OPTION", argv
[1], argv
[0]);
1610 return subcmd
->command
->func(user
, channel
, argc
- 1, argv
+ 1, subcmd
);
1613 int ss_check_user_level(struct chanNode
*channel
, struct userNode
*user
, unsigned int minimum
, int allow_override
, int exempt_owner
)
1615 struct userData
*uData
;
1616 struct chanData
*cData
= channel
->channel_info
;
1619 uData
= _GetChannelUser(cData
, user
->handle_info
, allow_override
, 0);
1622 if(minimum
<= uData
->access
)
1624 if((minimum
> UL_OWNER
) && (uData
->access
== UL_OWNER
) && exempt_owner
)
1631 channel_except_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1633 struct chanData
*cData
= channel
->channel_info
;
1634 struct chanInfo
*cInfo
;
1635 struct userData
*uData
;
1636 unsigned short value
;
1638 cInfo
= get_chanInfo(channel
->name
);
1642 if(!ss_check_user_level(channel
, user
, cInfo
->exceptlevel
, 1, 1))
1644 reply("SSMSG_CANNOT_SET");
1647 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1648 if(!value
&& strcmp(argv
[1], "0"))
1650 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1653 uData
= GetChannelUser(cData
, user
->handle_info
);
1654 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1656 reply("SSMSG_BAD_SETLEVEL");
1659 cInfo
->exceptlevel
= value
;
1661 reply("SSMSG_SET_EXCEPTLEVEL", cInfo
->exceptlevel
);
1666 channel_except_adv_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1668 struct chanData
*cData
= channel
->channel_info
;
1669 struct chanInfo
*cInfo
;
1670 struct userData
*uData
;
1671 unsigned short value
;
1673 cInfo
= get_chanInfo(channel
->name
);
1677 if(!ss_check_user_level(channel
, user
, cInfo
->exceptadvlevel
, 1, 1))
1679 reply("SSMSG_CANNOT_SET");
1682 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1683 if(!value
&& strcmp(argv
[1], "0"))
1685 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1688 uData
= GetChannelUser(cData
, user
->handle_info
);
1689 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1691 reply("SSMSG_BAD_SETLEVEL");
1694 cInfo
->exceptadvlevel
= value
;
1696 reply("SSMSG_SET_EXCEPTADVLEVEL", cInfo
->exceptadvlevel
);
1701 channel_except_badword_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1703 struct chanData
*cData
= channel
->channel_info
;
1704 struct chanInfo
*cInfo
;
1705 struct userData
*uData
;
1706 unsigned short value
;
1708 cInfo
= get_chanInfo(channel
->name
);
1712 if(!ss_check_user_level(channel
, user
, cInfo
->exceptbadwordlevel
, 1, 1))
1714 reply("SSMSG_CANNOT_SET");
1717 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1718 if(!value
&& strcmp(argv
[1], "0"))
1720 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1723 uData
= GetChannelUser(cData
, user
->handle_info
);
1724 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1726 reply("SSMSG_BAD_SETLEVEL");
1729 cInfo
->exceptbadwordlevel
= value
;
1731 reply("SSMSG_SET_EXCEPTBADWORDLEVEL", cInfo
->exceptbadwordlevel
);
1736 channel_except_caps_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1738 struct chanData
*cData
= channel
->channel_info
;
1739 struct chanInfo
*cInfo
;
1740 struct userData
*uData
;
1741 unsigned short value
;
1743 cInfo
= get_chanInfo(channel
->name
);
1747 if(!ss_check_user_level(channel
, user
, cInfo
->exceptcapslevel
, 1, 1))
1749 reply("SSMSG_CANNOT_SET");
1752 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1753 if(!value
&& strcmp(argv
[1], "0"))
1755 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1758 uData
= GetChannelUser(cData
, user
->handle_info
);
1759 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1761 reply("SSMSG_BAD_SETLEVEL");
1764 cInfo
->exceptcapslevel
= value
;
1766 reply("SSMSG_SET_EXCEPTCAPSLEVEL", cInfo
->exceptcapslevel
);
1771 channel_except_flood_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1773 struct chanData
*cData
= channel
->channel_info
;
1774 struct chanInfo
*cInfo
;
1775 struct userData
*uData
;
1776 unsigned short value
;
1778 cInfo
= get_chanInfo(channel
->name
);
1782 if(!ss_check_user_level(channel
, user
, cInfo
->exceptfloodlevel
, 1, 1))
1784 reply("SSMSG_CANNOT_SET");
1787 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1788 if(!value
&& strcmp(argv
[1], "0"))
1790 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1793 uData
= GetChannelUser(cData
, user
->handle_info
);
1794 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1796 reply("SSMSG_BAD_SETLEVEL");
1799 cInfo
->exceptfloodlevel
= value
;
1801 reply("SSMSG_SET_EXCEPTFLOODLEVEL", cInfo
->exceptfloodlevel
);
1806 channel_except_spam_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1808 struct chanData
*cData
= channel
->channel_info
;
1809 struct chanInfo
*cInfo
;
1810 struct userData
*uData
;
1811 unsigned short value
;
1813 cInfo
= get_chanInfo(channel
->name
);
1817 if(!ss_check_user_level(channel
, user
, cInfo
->exceptspamlevel
, 1, 1))
1819 reply("SSMSG_CANNOT_SET");
1822 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1823 if(!value
&& strcmp(argv
[1], "0"))
1825 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1828 uData
= GetChannelUser(cData
, user
->handle_info
);
1829 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1831 reply("SSMSG_BAD_SETLEVEL");
1834 cInfo
->exceptspamlevel
= value
;
1836 reply("SSMSG_SET_EXCEPTSPAMLEVEL", cInfo
->exceptspamlevel
);
1841 SPAMSERV_FUNC(opt_capsmin
)
1843 struct chanInfo
*cInfo
;
1845 cInfo
= get_chanInfo(channel
->name
);
1849 char *mask
= strdup(argv
[1]);
1850 unsigned int old
= cInfo
->capsmin
;
1852 if (isdigit(*mask
) && strspn(mask
, "1234567890,-") == strlen(mask
)) {
1853 cInfo
->capsmin
= mask
? strtoul(mask
, NULL
, 0) : 10;
1855 if (cInfo
->capsmin
< 0) {
1856 cInfo
->capsmin
= old
;
1857 reply("SSMSG_BAD_SETLEVEL");
1861 reply("SSMSG_BAD_SETLEVEL");
1865 reply("SSMSG_SET_CAPSMIN", cInfo
->capsmin
);
1870 SPAMSERV_FUNC(opt_capspercent
)
1872 struct chanInfo
*cInfo
;
1874 cInfo
= get_chanInfo(channel
->name
);
1878 char *mask
= strdup(argv
[1]);
1879 unsigned int old
= cInfo
->capspercent
;
1881 if (isdigit(*mask
) && strspn(mask
, "1234567890,-") == strlen(mask
)) {
1882 cInfo
->capspercent
= mask
? strtoul(mask
, NULL
, 0) : 10;
1884 if ((cInfo
->capspercent
< 0) || (cInfo
->capspercent
> 100)) {
1885 cInfo
->capspercent
= old
;
1886 reply("SSMSG_BAD_SETLEVEL");
1890 reply("SSMSG_BAD_SETLEVEL");
1894 reply("SSMSG_SET_CAPSPERCENT", cInfo
->capspercent
);
1899 SPAMSERV_FUNC(opt_exceptlevel
)
1901 return channel_except_level(SSFUNC_ARGS
);
1905 SPAMSERV_FUNC(opt_exceptadvlevel
)
1907 return channel_except_adv_level(SSFUNC_ARGS
);
1911 SPAMSERV_FUNC(opt_exceptbadwordlevel
)
1913 return channel_except_badword_level(SSFUNC_ARGS
);
1917 SPAMSERV_FUNC(opt_exceptcapslevel
)
1919 return channel_except_caps_level(SSFUNC_ARGS
);
1923 SPAMSERV_FUNC(opt_exceptfloodlevel
)
1925 return channel_except_flood_level(SSFUNC_ARGS
);
1929 SPAMSERV_FUNC(opt_exceptspamlevel
)
1931 return channel_except_spam_level(SSFUNC_ARGS
);
1935 SPAMSERV_FUNC(opt_spamlimit
)
1937 struct valueData values
[] =
1939 {"Users may send the same message $b2$b times.", 'a', 0},
1940 {"Users may send the same message $b3$b times.", 'b', 0},
1941 {"Users may send the same message $b4$b times.", 'c', 0},
1942 {"Users may send the same message $b5$b times.", 'd', 0},
1943 {"Users may send the same message $b6$b times.", 'e', 0}
1946 MULTIPLE_OPTION("SpamLimit ", "SpamLimit", ci_SpamLimit
);
1950 SPAMSERV_FUNC(opt_advreaction
)
1952 struct valueData values
[] =
1954 {"Kick on disallowed advertising.", 'k', 0},
1955 {"Kickban on disallowed advertising.", 'b', 0},
1956 {"Short timed ban on disallowed advertising.", 's', 0},
1957 {"Long timed ban on disallowed advertising.", 'l', 0},
1958 {"Kill on disallowed advertising.", 'd', 1}
1961 MULTIPLE_OPTION("AdvReaction ", "AdvReaction", ci_AdvReaction
);
1965 SPAMSERV_FUNC(opt_warnreaction
)
1967 struct valueData values
[] =
1969 {"Kick after warning.", 'k', 0},
1970 {"Kickban after warning.", 'b', 0},
1971 {"Short timed ban after warning.", 's', 0},
1972 {"Long timed ban after warning.", 'l', 0},
1973 {"Kill after warning.", 'd', 1}
1976 MULTIPLE_OPTION("WarnReaction ", "WarnReaction", ci_WarnReaction
);
1980 SPAMSERV_FUNC(opt_badreaction
)
1982 struct valueData values
[] =
1984 {"Kick on disallowed badwords.", 'k', 0},
1985 {"Kickban on disallowed badwords.", 'b', 0},
1986 {"Short timed ban on disallowed badwords.", 's', 0},
1987 {"Long timed ban on disallowed badwords.", 'l', 0},
1988 {"Kill on disallowed badwords.", 'd', 1}
1991 MULTIPLE_OPTION("BadReaction ", "BadReaction", ci_BadReaction
);
1995 SPAMSERV_FUNC(opt_capsreaction
)
1997 struct valueData values
[] =
1999 {"Kick on disallowed caps.", 'k', 0},
2000 {"Kickban on disallowed caps.", 'b', 0},
2001 {"Short timed ban on disallowed caps.", 's', 0},
2002 {"Long timed ban on disallowed caps.", 'l', 0},
2003 {"Kill on disallowed caps.", 'd', 1}
2006 MULTIPLE_OPTION("CapsReaction ", "CapsReaction", ci_CapsReaction
);
2010 SPAMSERV_FUNC(opt_advscan
)
2012 BINARY_OPTION("AdvScan ", CHAN_ADV_SCAN
);
2016 SPAMSERV_FUNC(opt_capsscan
)
2018 BINARY_OPTION("CapsScan ", CHAN_CAPSSCAN
);
2022 SPAMSERV_FUNC(opt_spamscan
)
2024 BINARY_OPTION("SpamScan ", CHAN_SPAMSCAN
);
2028 SPAMSERV_FUNC(opt_badwordscan
)
2030 BINARY_OPTION("BadWordScan ", CHAN_BADWORDSCAN
);
2034 SPAMSERV_FUNC(opt_chanfloodscan
)
2036 BINARY_OPTION("ChanFloodScan ", CHAN_CHANFLOODSCAN
);
2040 SPAMSERV_FUNC(opt_joinflood
)
2042 BINARY_OPTION("JoinFloodScan ", CHAN_JOINFLOOD
);
2046 spamserv_add_trusted_account(const char *account
, struct string_list
*channel
, const char *issuer
, time_t issued
)
2048 struct trusted_account
*ta
;
2049 ta
= calloc(1, sizeof(*ta
));
2052 ta
->account
= strdup(account
);
2053 ta
->channel
= channel
? string_list_copy(channel
) : alloc_string_list(1);
2054 ta
->issuer
= strdup(issuer
);
2055 ta
->issued
= issued
;
2056 dict_insert(spamserv_trusted_accounts
, strdup(ta
->account
), ta
);
2061 free_trusted_account(void *data)
2063 struct trusted_account *ta = data;
2065 free_string_list(ta->channel);
2071 static SPAMSERV_FUNC(cmd_addtrust
)
2074 struct userData
*uData
;
2075 struct chanData
*cData
;
2076 struct chanInfo
*cInfo
;
2077 struct trusted_account
*ta
;
2078 struct string_list
*templist
;
2079 struct handle_info
*hi
;
2081 if (!(channel
= GetChannel(argv
[2]))) {
2082 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2086 cInfo
= get_chanInfo(channel
->name
);
2087 cData
= channel
->channel_info
;
2088 uData
= GetChannelUser(cData
, user
->handle_info
);
2090 if (!cInfo
|| !channel
->channel_info
) {
2091 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2095 if (CHECK_SUSPENDED(cInfo
)) {
2096 ss_reply("SSMSG_SUSPENDED", channel
->name
);
2100 if (!uData
|| (uData
->access
< UL_MANAGER
)) {
2101 ss_reply("SSMSG_NO_ACCESS");
2105 if (!(hi
= modcmd_get_handle_info(user
, argv
[1]))) {
2109 if ((ta
= dict_find(spamserv_trusted_accounts
, argv
[1], NULL
))) {
2110 if (ta
->channel
->used
&& (argc
> 1)) {
2111 for (i
=0; i
< ta
->channel
->used
; i
++) {
2112 if (!strcmp(ta
->channel
->list
[i
], argv
[2])) {
2113 ss_reply("SSMSG_ALREADY_TRUSTED", hi
->handle
);
2119 string_list_append(ta
->channel
, argv
[2]);
2120 ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2124 templist
= alloc_string_list(sizeof(argv
[2])+1);
2125 // templist = alloc_string_list(1);
2126 string_list_append(templist
, argv
[2]);
2128 spamserv_add_trusted_account(hi
->handle
, templist
, user
->handle_info
->handle
, now
);
2129 ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2133 static SPAMSERV_FUNC(cmd_oaddtrust
)
2135 unsigned int i
, global
= 0;
2136 struct chanInfo
*cInfo
;
2137 struct chanData
*cData
;
2138 struct trusted_account
*ta
;
2139 struct string_list
*templist
;
2140 struct handle_info
*hi
;
2142 if (!strcmp(argv
[2], "global"))
2145 if (!(channel
= GetChannel(argv
[2])) && (global
== 0)) {
2146 ss_reply("SSMSG_NOT_REGISTERED", channel
? channel
->name
: (global
? "global" : ""));
2151 cInfo
= get_chanInfo(channel
->name
);
2152 cData
= channel
->channel_info
;
2154 if (!cInfo
|| !channel
->channel_info
) {
2155 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2160 if (!(hi
= modcmd_get_handle_info(user
, argv
[1]))) {
2164 if ((ta
= dict_find(spamserv_trusted_accounts
, argv
[1], NULL
))) {
2165 if (ta
->channel
->used
&& (argc
> 1)) {
2166 for (i
=0; i
< ta
->channel
->used
; i
++) {
2167 if (!strcmp(ta
->channel
->list
[i
], argv
[2])) {
2168 ss_reply("SSMSG_ALREADY_TRUSTED", argv
[1]);
2174 string_list_append(ta
->channel
, argv
[2]);
2177 ss_reply("SSMSG_ADDED_TRUSTED", argv
[1]);
2179 ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", argv
[1], argv
[2]);
2184 templist
= alloc_string_list(sizeof(argv
[2])+1);
2185 // templist = alloc_string_list(1);
2186 string_list_append(templist
, argv
[2]);
2188 spamserv_add_trusted_account(hi
->handle
, templist
, user
->handle_info
->handle
, now
);
2191 ss_reply("SSMSG_ADDED_TRUSTED", hi
->handle
);
2193 ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2198 static SPAMSERV_FUNC(cmd_deltrust
)
2202 struct trusted_account
*ta
;
2203 struct userData
*uData
;
2204 struct chanData
*cData
;
2205 struct chanInfo
*cInfo
;
2206 struct handle_info
*hi
;
2208 if (!(channel
= GetChannel(argv
[2]))) {
2209 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2213 cInfo
= get_chanInfo(channel
->name
);
2214 cData
= channel
->channel_info
;
2215 uData
= GetChannelUser(cData
, user
->handle_info
);
2217 if (!cInfo
|| !channel
->channel_info
) {
2218 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2222 if (CHECK_SUSPENDED(cInfo
)) {
2223 ss_reply("SSMSG_SUSPENDED", channel
->name
);
2227 if (!uData
|| (uData
->access
< UL_MANAGER
)) {
2228 ss_reply("SSMSG_NO_ACCESS");
2232 if (!(hi
= modcmd_get_handle_info(user
, argv
[1]))) {
2236 ta
= dict_find(spamserv_trusted_accounts
, hi
->handle
, NULL
);
2239 ss_reply("SSMSG_NOT_TRUSTED", argv
[2]);
2244 if (ta
->channel
->used
) {
2245 for (i
=0; i
< ta
->channel
->used
; i
++) {
2246 if (!strcmp(ta
->channel
->list
[i
], argv
[2])) {
2247 string_list_delete(ta
->channel
, i
);
2254 ss_reply("SSMSG_REMOVED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2256 ss_reply("SSMSG_NOT_TRUSTED", hi
->handle
, argv
[2]);
2260 dict_remove(spamserv_trusted_accounts
, hi
->handle
);
2261 ss_reply("SSMSG_REMOVED_TRUSTED", hi
->handle
);
2267 static SPAMSERV_FUNC(cmd_odeltrust
)
2270 int rem
= 0, global
= 0;
2271 struct trusted_account
*ta
;
2272 struct chanInfo
*cInfo
;
2273 struct chanData
*cData
;
2274 struct handle_info
*hi
;
2276 if (!strcmp(argv
[2], "global"))
2279 if (!(channel
= GetChannel(argv
[2])) && (global
== 0)) {
2280 ss_reply("SSMSG_NOT_REGISTERED", channel
? channel
->name
: (global
? "global" : ""));
2285 cInfo
= get_chanInfo(channel
->name
);
2286 cData
= channel
->channel_info
;
2288 if (!cInfo
|| !channel
->channel_info
) {
2289 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2294 if (!(hi
= modcmd_get_handle_info(user
, argv
[1]))) {
2298 ta
= dict_find(spamserv_trusted_accounts
, hi
->handle
, NULL
);
2301 ss_reply("SSMSG_NOT_TRUSTED", argv
[2]);
2306 if (ta
->channel
->used
) {
2307 for (i
=0; i
< ta
->channel
->used
; i
++) {
2308 if (!strcmp(ta
->channel
->list
[i
], argv
[2])) {
2309 string_list_delete(ta
->channel
, i
);
2316 ss_reply("SSMSG_REMOVED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2318 ss_reply("SSMSG_NOT_TRUSTED", argv
[2]);
2322 dict_remove(spamserv_trusted_accounts
, hi
->handle
);
2323 ss_reply("SSMSG_REMOVED_TRUSTED", hi
->handle
);
2329 static SPAMSERV_FUNC(cmd_listtrust
) {
2331 struct trusted_account
*ta
;
2332 char issued
[INTERVALLEN
];
2337 if (!strcmp(argv
[1], "global")) {
2338 if (!IsHelping(user
)) {
2339 reply("SSMSG_MUST_BE_HELPING");
2344 channel
= GetChannel(argv
[1]);
2346 chan
= strdup(channel
->name
);
2348 ss_reply("SSMSG_NOT_REGISTERED", argv
[1]);
2353 reply("MSG_INVALID_CHANNEL");
2357 reply("SSMSG_TRUSTED_LIST");
2358 reply("SSMSG_TRUSTED_LIST_BAR");
2359 reply("SSMSG_TRUSTED_LIST_HEADER");
2360 reply("SSMSG_TRUSTED_LIST_BAR");
2361 for (it
= dict_first(spamserv_trusted_accounts
); it
; it
= iter_next(it
)) {
2364 if (ta
->channel
->used
) {
2365 for (i
=0; i
< ta
->channel
->used
; i
++) {
2367 if (!strcmp(ta
->channel
->list
[i
], chan
)) {
2369 intervalString(issued
, now
- ta
->issued
, user
->handle_info
);
2371 ss_reply("SSMSG_HOST_IS_TRUSTED", iter_key(it
),
2372 (ta
->issuer
? ta
->issuer
: "<unknown>"),
2373 (ta
->issued
? issued
: "some time"));
2375 } else if (!strcmp(ta
->channel
->list
[i
], "global") && (!strcmp(chan
, "global"))) {
2377 intervalString(issued
, now
- ta
->issued
, user
->handle_info
);
2379 ss_reply("SSMSG_HOST_IS_TRUSTED", iter_key(it
),
2380 (ta
->issuer
? ta
->issuer
: "<unknown>"),
2381 (ta
->issued
? issued
: 0));
2386 ss_reply("SSMSG_TRUSTED_LIST_END");
2391 to_lower(char *message
)
2393 unsigned int i
, diff
= 'a' - 'A';
2395 for(i
= 0; i
< strlen(message
); i
++)
2397 if((message
[i
] >= 'A') && (message
[i
] <= 'Z'))
2398 message
[i
] = message
[i
] + diff
;
2403 strip_mirc_codes(char *text
)
2405 // taken from xchat and modified
2406 int nc
= 0, i
= 0, col
= 0, len
= strlen(text
);
2407 static char new_str
[MAXLEN
];
2411 if((col
&& isdigit(*text
) && nc
< 2) ||
2412 (col
&& *text
== ',' && isdigit(*(text
+ 1)) && nc
< 3))
2451 is_in_exception_list(struct chanInfo
*cInfo
, char *message
)
2455 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
2456 if(strstr(message
, cInfo
->exceptions
->list
[i
]))
2463 is_in_badword_list(struct chanInfo
*cInfo
, char *message
)
2467 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
2468 if(strstr(message
, cInfo
->badwords
->list
[i
]))
2475 check_caps(struct chanInfo
*cInfo
, char *message
)
2479 if ( (c
= strlen(message
)) >= cInfo
->capsmin
) {
2481 char *s
= strdup(message
);
2488 if (i
>= cInfo
->capsmin
&& i
* 100 / c
>= cInfo
->capspercent
)
2496 check_badwords(struct chanInfo
*cInfo
, char *message
)
2498 if(spamserv_conf
.strip_mirc_codes
)
2499 message
= strip_mirc_codes(message
);
2501 /* This needs improving */
2502 if(is_in_exception_list(cInfo
, message
))
2505 if(is_in_badword_list(cInfo
, message
))
2512 check_advertising(struct chanInfo
*cInfo
, char *message
)
2516 if(spamserv_conf
.strip_mirc_codes
)
2517 message
= strip_mirc_codes(message
);
2519 if(is_in_exception_list(cInfo
, message
))
2522 while(message
[i
] != 0)
2524 if(message
[i
] == '#')
2526 char channelname
[CHANNELLEN
];
2529 if(!spamserv_conf
.adv_chan_must_exist
)
2532 /* only return 1, if the channel does exist */
2534 while((message
[i
] != 0) && (message
[i
] != ' '))
2536 channelname
[j
] = message
[i
];
2541 channelname
[j
] = '\0';
2543 if(GetChannel(channelname
))
2546 else if((message
[i
] == 'w') && (message
[i
+1] == 'w') && (message
[i
+2] == 'w') && (message
[i
+3] == '.'))
2548 else if((message
[i
] == 'h') && (message
[i
+1] == 't') && (message
[i
+2] == 't') && (message
[i
+3] == 'p') && (message
[i
+4] == ':'))
2550 else if((message
[i
] == 'f') && (message
[i
+1] == 't') && (message
[i
+2] == 'p') && ((message
[i
+3] == '.') || (message
[i
+3] == ':')))
2560 spamserv_punish(struct chanNode
*channel
, struct userNode
*user
, time_t expires
, char *reason
, int ban
)
2564 struct mod_chanmode change
;
2565 char *hostmask
= generate_hostmask(user
, GENMASK_STRICT_HOST
| GENMASK_ANY_IDENT
);
2567 sanitize_ircmask(hostmask
);
2570 add_channel_ban(channel
->channel_info
, hostmask
, spamserv
->nick
, now
, now
, now
+ expires
, reason
);
2572 mod_chanmode_init(&change
);
2574 change
.args
[0].mode
= MODE_BAN
;
2575 change
.args
[0].u
.hostmask
= hostmask
;
2576 mod_chanmode_announce(spamserv
, channel
, &change
);
2580 spamserv_debug(SSMSG_DEBUG_BAN
, user
->nick
, channel
->name
, reason
);
2583 spamserv_debug(SSMSG_DEBUG_KICK
, user
->nick
, channel
->name
, reason
);
2585 KickChannelUser(user
, channel
, spamserv
, reason
);
2589 spamserv_channel_message(struct chanNode
*channel
, struct userNode
*user
, char *text
)
2591 struct chanData
*cData
;
2592 struct chanInfo
*cInfo
;
2593 struct userInfo
*uInfo
;
2594 struct userData
*uData
;
2595 struct spamNode
*sNode
;
2596 struct floodNode
*fNode
;
2597 struct trusted_account
*ta
;
2598 unsigned int violation
= 0;
2599 char reason
[MAXLEN
];
2601 /* make sure: spamserv is not disabled; x3 is running; spamserv is in the chan; chan is regged, user does exist */
2602 if(!spamserv
|| quit_services
|| !GetUserMode(channel
, spamserv
) || IsOper(user
) || !(cInfo
= get_chanInfo(channel
->name
)) || !(uInfo
= get_userInfo(user
->nick
)))
2605 cData
= channel
->channel_info
;
2606 uData
= GetChannelUser(cData
, user
->handle_info
);
2608 if (user
->handle_info
) {
2609 ta
= dict_find(spamserv_trusted_accounts
, user
->handle_info
->handle
, NULL
);
2612 for (i
=0; i
< ta
->channel
->used
; i
++) {
2613 if (!strcmp(ta
->channel
->list
[i
], channel
->name
))
2616 if (!strcmp(ta
->channel
->list
[i
], "global"))
2623 if(uData
&& (uData
->access
>= cInfo
->exceptlevel
))
2626 if(CHECK_CAPSSCAN(cInfo
) && check_caps(cInfo
, text
))
2628 if(uData
&& (uData
->access
>= cInfo
->exceptcapslevel
))
2631 if(CHECK_CAPS_WARNED(uInfo
))
2633 switch(cInfo
->info
[ci_CapsReaction
])
2635 case 'k': uInfo
->flags
|= USER_KICK
; break;
2636 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2637 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2638 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2639 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2642 uInfo
->warnlevel
+= CAPS_WARNLEVEL
;
2647 uInfo
->flags
|= USER_CAPS_WARNED
;
2648 uInfo
->lastcaps
= now
;
2649 uInfo
->warnlevel
+= CAPS_WARNLEVEL
;
2651 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2652 if (spamserv_conf
.network_rules
)
2653 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_CAPS
, spamserv_conf
.network_rules
);
2655 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_CAPS
, spamserv_conf
.network_rules
);
2663 if(CHECK_SPAM(cInfo
))
2665 if(uData
&& (uData
->access
>= cInfo
->exceptspamlevel
))
2668 if(!(sNode
= uInfo
->spam
))
2670 spamserv_create_spamNode(channel
, uInfo
, text
);
2674 for(; sNode
; sNode
= sNode
->next
)
2675 if(sNode
->channel
== channel
)
2680 spamserv_create_spamNode(channel
, uInfo
, text
);
2684 unsigned long crc
= crc32(text
);
2686 if(crc
== sNode
->crc32
)
2688 unsigned int spamlimit
= 2;
2691 switch(cInfo
->info
[ci_SpamLimit
])
2693 case 'a': spamlimit
= 2; break;
2694 case 'b': spamlimit
= 3; break;
2695 case 'c': spamlimit
= 4; break;
2696 case 'd': spamlimit
= 5; break;
2697 case 'e': spamlimit
= 6; break;
2700 if(sNode
->count
== spamlimit
)
2702 uInfo
->warnlevel
+= SPAM_WARNLEVEL
;
2704 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2705 if (spamserv_conf
.network_rules
)
2706 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_SPAM
, spamserv_conf
.network_rules
);
2708 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_SPAM
, spamserv_conf
.network_rules
);
2711 else if(sNode
->count
> spamlimit
)
2713 switch(cInfo
->info
[ci_WarnReaction
])
2715 case 'k': uInfo
->flags
|= USER_KICK
; break;
2716 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2717 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2718 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2719 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2722 spamserv_delete_spamNode(uInfo
, sNode
);
2723 uInfo
->warnlevel
+= SPAM_WARNLEVEL
;
2736 if(CHECK_FLOOD(cInfo
))
2738 if(uData
&& (uData
->access
>= cInfo
->exceptfloodlevel
))
2741 if(!(fNode
= uInfo
->flood
))
2743 spamserv_create_floodNode(channel
, user
, &uInfo
->flood
);
2747 for(; fNode
; fNode
= fNode
->next
)
2748 if(fNode
->channel
== channel
)
2752 spamserv_create_floodNode(channel
, user
, &uInfo
->flood
);
2754 if(((now
- fNode
->time
) < FLOOD_EXPIRE
)) {
2757 if(fNode
->count
== FLOOD_MAX_LINES
- 1) {
2758 uInfo
->warnlevel
+= FLOOD_WARNLEVEL
;
2760 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2761 if (spamserv_conf
.network_rules
)
2762 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_FLOOD
, spamserv_conf
.network_rules
);
2764 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_FLOOD
, spamserv_conf
.network_rules
);
2768 else if(fNode
->count
> FLOOD_MAX_LINES
) {
2769 switch(cInfo
->info
[ci_WarnReaction
]) {
2770 case 'k': uInfo
->flags
|= USER_KICK
; break;
2771 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2772 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2773 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2774 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2777 spamserv_delete_floodNode(&uInfo
->flood
, fNode
);
2778 uInfo
->warnlevel
+= FLOOD_WARNLEVEL
;
2788 if(CHECK_BADWORDSCAN(cInfo
) && check_badwords(cInfo
, text
))
2790 if(uData
&& (uData
->access
>= cInfo
->exceptbadwordlevel
))
2793 if(CHECK_BAD_WARNED(uInfo
))
2795 switch(cInfo
->info
[ci_BadReaction
])
2797 case 'k': uInfo
->flags
|= USER_KICK
; break;
2798 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2799 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2800 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2801 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2804 uInfo
->warnlevel
+= BAD_WARNLEVEL
;
2809 uInfo
->flags
|= USER_BAD_WARNED
;
2810 uInfo
->lastbad
= now
;
2811 uInfo
->warnlevel
+= BAD_WARNLEVEL
;
2813 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2814 if (spamserv_conf
.network_rules
)
2815 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_BAD
, spamserv_conf
.network_rules
);
2817 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_BAD
, spamserv_conf
.network_rules
);
2822 if(CHECK_ADV(cInfo
) && check_advertising(cInfo
, text
))
2824 if(uData
&& (uData
->access
>= cInfo
->exceptspamlevel
))
2827 if(CHECK_ADV_WARNED(uInfo
))
2829 switch(cInfo
->info
[ci_AdvReaction
])
2831 case 'k': uInfo
->flags
|= USER_KICK
; break;
2832 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2833 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2834 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2835 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2838 uInfo
->warnlevel
+= ADV_WARNLEVEL
;
2843 uInfo
->flags
|= USER_ADV_WARNED
;
2844 uInfo
->lastadv
= now
;
2845 uInfo
->warnlevel
+= ADV_WARNLEVEL
;
2847 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2848 if (spamserv_conf
.network_rules
)
2849 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_ADV
, spamserv_conf
.network_rules
);
2851 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_ADV
, spamserv_conf
.network_rules
);
2856 if(!CHECK_WARNED(uInfo
) && !CHECK_KILL(uInfo
) && !CHECK_GLINE(uInfo
) && uInfo
->warnlevel
== MAX_WARNLEVEL
)
2858 uInfo
->flags
|= USER_WARNED
;
2859 if (spamserv_conf
.network_rules
)
2860 snprintf(reason
, sizeof(reason
), SSMSG_WARNING_RULES_2
, spamserv_conf
.network_rules
);
2862 snprintf(reason
, sizeof(reason
), SSMSG_WARNING_2
);
2863 irc_notice(spamserv
, user
->numeric
, reason
);
2864 irc_privmsg(spamserv
, user
->numeric
, reason
);
2866 else if(uInfo
->warnlevel
> MAX_WARNLEVEL
)
2868 if(CHECK_KILLED(uInfo
))
2869 uInfo
->flags
|= USER_GLINE
;
2871 uInfo
->flags
|= USER_KILL
;
2882 case 1: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_SPAM
, spamserv_conf
.network_rules
); break;
2883 case 2: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_FLOOD
, spamserv_conf
.network_rules
); break;
2884 case 3: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_ADV
, spamserv_conf
.network_rules
); break;
2885 case 4: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_BAD
, spamserv_conf
.network_rules
); break;
2886 case 5: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_CAPS
, spamserv_conf
.network_rules
); break;
2887 default: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES_2
: SSMSG_WARNING_2
, spamserv_conf
.network_rules
); break;
2890 if(CHECK_GLINE(uInfo
))
2892 int size
= strlen(user
->hostname
) + 3;
2893 char *mask
= alloca(size
);
2894 snprintf(mask
, size
, "*@%s", user
->hostname
);
2895 gline_add(spamserv
->nick
, mask
, spamserv_conf
.gline_duration
, reason
, now
, 1, 0);
2896 spamserv_debug(SSMSG_DEBUG_GLINE
, user
->nick
, user
->hostname
, channel
->name
);
2898 else if(CHECK_KILL(uInfo
))
2900 DelUser(user
, spamserv
, 1, reason
);
2901 spamserv_debug(SSMSG_DEBUG_KILL
, user
->nick
, channel
->name
);
2903 else if(CHECK_LONG_TBAN(uInfo
))
2905 spamserv_punish(channel
, user
, spamserv_conf
.long_ban_duration
, reason
, 1);
2907 else if(CHECK_SHORT_TBAN(uInfo
))
2909 spamserv_punish(channel
, user
, spamserv_conf
.short_ban_duration
, reason
, 1);
2911 else if(CHECK_KICKBAN(uInfo
))
2913 spamserv_punish(channel
, user
, 0, reason
, 1);
2915 else if(CHECK_KICK(uInfo
))
2917 spamserv_punish(channel
, user
, 0, reason
, 0);
2922 trusted_account_read(const char *account
, void *data
, UNUSED_ARG(void *extra
))
2924 struct record_data
*rd
= data
;
2925 const char *str
, *issuer
;
2926 struct string_list
*strlist
;
2929 if (rd
->type
== RECDB_OBJECT
) {
2930 dict_t obj
= GET_RECORD_OBJECT(rd
);
2931 /* new style structure */
2932 strlist
= database_get_data(obj
, KEY_CHANNELS
, RECDB_STRING_LIST
);
2933 issuer
= database_get_data(obj
, KEY_ISSUER
, RECDB_QSTRING
);
2934 str
= database_get_data(obj
, KEY_ISSUED
, RECDB_QSTRING
);
2935 issued
= str
? ParseInterval(str
) : 0;
2939 spamserv_add_trusted_account(account
, strlist
, issuer
, issued
);
2944 spamserv_saxdb_read(struct dict
*database
)
2947 struct record_data
*hir
;
2948 struct chanNode
*channel
;
2949 struct chanInfo
*cInfo
;
2950 struct string_list
*strlist
, *strlist2
;
2952 unsigned int exceptlevel
, exceptadvlevel
, exceptbadwordlevel
;
2953 unsigned int exceptfloodlevel
, exceptspamlevel
, exceptcapslevel
;
2954 unsigned int capsmin
, capspercent
;
2959 if ((object
= database_get_data(database
, KEY_TRUSTED_HOSTS
, RECDB_OBJECT
)))
2960 dict_foreach(object
, trusted_account_read
, spamserv_trusted_accounts
);
2962 for(it
= dict_first(database
); it
; it
= iter_next(it
))
2964 hir
= iter_data(it
);
2966 if(hir
->type
!= RECDB_OBJECT
)
2968 log_module(SS_LOG
, LOG_WARNING
, "Unexpected rectype %d for %s.", hir
->type
, iter_key(it
));
2972 channel
= GetChannel(iter_key(it
));
2973 if (!strcmp("trusted", iter_key(it
)))
2976 strlist
= database_get_data(hir
->d
.object
, KEY_EXCEPTIONS
, RECDB_STRING_LIST
);
2977 strlist2
= database_get_data(hir
->d
.object
, KEY_BADWORDS
, RECDB_STRING_LIST
);
2979 str
= database_get_data(hir
->d
.object
, KEY_FLAGS
, RECDB_QSTRING
);
2980 flags
= str
? atoi(str
) : 0;
2982 info
= database_get_data(hir
->d
.object
, KEY_INFO
, RECDB_QSTRING
);
2984 str
= database_get_data(hir
->d
.object
, KEY_EXPIRY
, RECDB_QSTRING
);
2985 expiry
= str
? strtoul(str
, NULL
, 0) : 0;
2987 str
= database_get_data(hir
->d
.object
, KEY_CAPSMIN
, RECDB_QSTRING
);
2988 capsmin
= str
? strtoul(str
, NULL
, 0) : 10;
2990 str
= database_get_data(hir
->d
.object
, KEY_CAPSPERCENT
, RECDB_QSTRING
);
2991 capspercent
= str
? strtoul(str
, NULL
, 0) : 25;
2993 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTLEVEL
, RECDB_QSTRING
);
2994 exceptlevel
= str
? strtoul(str
, NULL
, 0) : UL_MANAGER
;
2996 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTADVLEVEL
, RECDB_QSTRING
);
2997 exceptadvlevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
2999 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTBADWORDLEVEL
, RECDB_QSTRING
);
3000 exceptbadwordlevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
3002 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTCAPSLEVEL
, RECDB_QSTRING
);
3003 exceptcapslevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
3005 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTFLOODLEVEL
, RECDB_QSTRING
);
3006 exceptfloodlevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
3008 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTSPAMLEVEL
, RECDB_QSTRING
);
3009 exceptspamlevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
3013 if((cInfo
= spamserv_register_channel(channel
, strlist
, strlist2
, flags
, info
)))
3015 /* if the channel is suspended and expiry = 0 it means: channel will
3016 never expire ! it does NOT mean, the channel is not suspended */
3017 if(CHECK_SUSPENDED(cInfo
) && expiry
&& (expiry
< now
))
3019 cInfo
->flags
&= ~CHAN_SUSPENDED
;
3020 spamserv_join_channel(cInfo
->channel
);
3022 else if(!CHECK_SUSPENDED(cInfo
))
3023 spamserv_join_channel(cInfo
->channel
);
3025 cInfo
->suspend_expiry
= expiry
;
3027 cInfo
->capsmin
= capsmin
;
3028 cInfo
->capspercent
= capspercent
;
3029 cInfo
->exceptlevel
= exceptlevel
;
3030 cInfo
->exceptadvlevel
= exceptadvlevel
;
3031 cInfo
->exceptbadwordlevel
= exceptbadwordlevel
;
3032 cInfo
->exceptcapslevel
= exceptcapslevel
;
3033 cInfo
->exceptfloodlevel
= exceptfloodlevel
;
3034 cInfo
->exceptspamlevel
= exceptspamlevel
;
3038 log_module(SS_LOG
, LOG_ERROR
, "Couldn't register channel %s. Channel or info invalid.", iter_key(it
));
3045 spamserv_saxdb_write(struct saxdb_context
*ctx
)
3049 if (dict_size(spamserv_trusted_accounts
)) {
3050 saxdb_start_record(ctx
, KEY_TRUSTED_ACCOUNTS
, 1);
3051 for (it
= dict_first(spamserv_trusted_accounts
); it
; it
= iter_next(it
)) {
3052 struct trusted_account
*ta
= iter_data(it
);
3053 saxdb_start_record(ctx
, iter_key(it
), 0);
3054 if (ta
->channel
) saxdb_write_string_list(ctx
, KEY_CHANNELS
, ta
->channel
);
3055 if (ta
->issued
) saxdb_write_int(ctx
, KEY_ISSUED
, ta
->issued
);
3056 if (ta
->issuer
) saxdb_write_string(ctx
, KEY_ISSUER
, ta
->issuer
);
3057 saxdb_end_record(ctx
);
3059 saxdb_end_record(ctx
);
3062 for(it
= dict_first(registered_channels_dict
); it
; it
= iter_next(it
))
3064 struct chanInfo
*cInfo
= iter_data(it
);
3066 saxdb_start_record(ctx
, cInfo
->channel
->name
, 1);
3068 if(cInfo
->exceptions
->used
)
3069 saxdb_write_string_list(ctx
, KEY_EXCEPTIONS
, cInfo
->exceptions
);
3071 if(cInfo
->badwords
->used
)
3072 saxdb_write_string_list(ctx
, KEY_BADWORDS
, cInfo
->badwords
);
3075 saxdb_write_int(ctx
, KEY_FLAGS
, cInfo
->flags
);
3078 saxdb_write_int(ctx
, KEY_CAPSMIN
, cInfo
->capsmin
);
3080 if(cInfo
->capspercent
)
3081 saxdb_write_int(ctx
, KEY_CAPSPERCENT
, cInfo
->capspercent
);
3083 if(cInfo
->exceptlevel
)
3084 saxdb_write_int(ctx
, KEY_EXCEPTLEVEL
, cInfo
->exceptlevel
);
3086 if(cInfo
->exceptadvlevel
)
3087 saxdb_write_int(ctx
, KEY_EXCEPTADVLEVEL
, cInfo
->exceptadvlevel
);
3089 if(cInfo
->exceptbadwordlevel
)
3090 saxdb_write_int(ctx
, KEY_EXCEPTBADWORDLEVEL
, cInfo
->exceptbadwordlevel
);
3092 if(cInfo
->exceptcapslevel
)
3093 saxdb_write_int(ctx
, KEY_EXCEPTCAPSLEVEL
, cInfo
->exceptcapslevel
);
3095 if(cInfo
->exceptfloodlevel
)
3096 saxdb_write_int(ctx
, KEY_EXCEPTFLOODLEVEL
, cInfo
->exceptfloodlevel
);
3098 if(cInfo
->exceptspamlevel
)
3099 saxdb_write_int(ctx
, KEY_EXCEPTSPAMLEVEL
, cInfo
->exceptspamlevel
);
3101 saxdb_write_string(ctx
, KEY_INFO
, cInfo
->info
);
3103 if(cInfo
->suspend_expiry
)
3104 saxdb_write_int(ctx
, KEY_EXPIRY
, cInfo
->suspend_expiry
);
3106 saxdb_end_record(ctx
);
3112 spamserv_conf_read(void)
3117 if(!(conf_node
= conf_get_data(SPAMSERV_CONF_NAME
, RECDB_OBJECT
)))
3119 log_module(SS_LOG
, LOG_ERROR
, "config node `%s' is missing or has wrong type.", SPAMSERV_CONF_NAME
);
3123 str
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL
, RECDB_QSTRING
);
3127 spamserv_conf
.debug_channel
= AddChannel(str
, now
, "+tinms", NULL
, NULL
);
3129 if(spamserv_conf
.debug_channel
)
3130 spamserv_join_channel(spamserv_conf
.debug_channel
);
3134 spamserv_conf
.debug_channel
= NULL
;
3137 spamserv_conf
.global_exceptions
= database_get_data(conf_node
, KEY_GLOBAL_EXCEPTIONS
, RECDB_STRING_LIST
);
3139 spamserv_conf
.global_badwords
= database_get_data(conf_node
, KEY_GLOBAL_BADWORDS
, RECDB_STRING_LIST
);
3141 str
= database_get_data(conf_node
, KEY_NETWORK_RULES
, RECDB_QSTRING
);
3142 spamserv_conf
.network_rules
= str
? str
: NULL
;
3144 str
= database_get_data(conf_node
, KEY_TRIGGER
, RECDB_QSTRING
);
3145 spamserv_conf
.trigger
= str
? str
[0] : 0;
3147 str
= database_get_data(conf_node
, KEY_SHORT_BAN_DURATION
, RECDB_QSTRING
);
3148 spamserv_conf
.short_ban_duration
= str
? ParseInterval(str
) : ParseInterval("15m");
3150 str
= database_get_data(conf_node
, KEY_LONG_BAN_DURATION
, RECDB_QSTRING
);
3151 spamserv_conf
.long_ban_duration
= str
? ParseInterval(str
) : ParseInterval("1h");
3153 str
= database_get_data(conf_node
, KEY_GLINE_DURATION
, RECDB_QSTRING
);
3154 spamserv_conf
.gline_duration
= str
? ParseInterval(str
) : ParseInterval("1h");
3156 str
= database_get_data(conf_node
, KEY_EXCEPTION_MAX
, RECDB_QSTRING
);
3157 spamserv_conf
.exception_max
= str
? strtoul(str
, NULL
, 0) : 10;
3159 str
= database_get_data(conf_node
, KEY_EXCEPTION_MIN_LEN
, RECDB_QSTRING
);
3160 spamserv_conf
.exception_min_len
= str
? strtoul(str
, NULL
, 0) : 4;
3162 str
= database_get_data(conf_node
, KEY_EXCEPTION_MAX_LEN
, RECDB_QSTRING
);
3163 spamserv_conf
.exception_max_len
= str
? strtoul(str
, NULL
, 0) : 15;
3165 str
= database_get_data(conf_node
, KEY_BADWORD_MAX
, RECDB_QSTRING
);
3166 spamserv_conf
.badword_max
= str
? strtoul(str
, NULL
, 0) : 10;
3168 str
= database_get_data(conf_node
, KEY_BADWORD_MIN_LEN
, RECDB_QSTRING
);
3169 spamserv_conf
.badword_min_len
= str
? strtoul(str
, NULL
, 0) : 4;
3171 str
= database_get_data(conf_node
, KEY_BADWORD_MAX_LEN
, RECDB_QSTRING
);
3172 spamserv_conf
.badword_max_len
= str
? strtoul(str
, NULL
, 0) : 15;
3174 str
= database_get_data(conf_node
, KEY_ADV_CHAN_MUST_EXIST
, RECDB_QSTRING
);
3175 spamserv_conf
.adv_chan_must_exist
= str
? enabled_string(str
) : 1;
3177 str
= database_get_data(conf_node
, KEY_STRIP_MIRC_CODES
, RECDB_QSTRING
);
3178 spamserv_conf
.strip_mirc_codes
= str
? enabled_string(str
) : 0;
3180 str
= database_get_data(conf_node
, KEY_ALLOW_MOVE_MERGE
, RECDB_QSTRING
);
3181 spamserv_conf
.allow_move_merge
= str
? enabled_string(str
) : 0;
3185 spamserv_db_cleanup(void)
3189 while((it
= dict_first(registered_channels_dict
)))
3191 spamserv_unregister_channel(iter_data(it
));
3194 /* now handled automatically
3195 * while((it = dict_first(killed_users_dict)))
3197 free(iter_data(it));
3201 dict_delete(registered_channels_dict
);
3202 dict_delete(connected_users_dict
);
3203 dict_delete(killed_users_dict
);
3204 dict_delete(spamserv_trusted_accounts
);
3208 init_spamserv(const char *nick
)
3210 struct chanNode
*chan
;
3216 const char *modes
= conf_get_data("services/spamserv/modes", RECDB_QSTRING
);
3217 spamserv
= AddService(nick
, modes
? modes
: NULL
, "Anti Spam Services", NULL
);
3218 spamserv_service
= service_register(spamserv
);
3220 conf_register_reload(spamserv_conf_read
);
3222 SS_LOG
= log_register_type("SpamServ", "file:spamserv.log");
3224 /* auto-free the keys for these dicts,
3225 * and auto-free the keys AND data for killed_users_dict.
3226 * other data need free'd manually. */
3227 registered_channels_dict
= dict_new();
3228 dict_set_free_keys(registered_channels_dict
, free
);
3229 connected_users_dict
= dict_new();
3230 dict_set_free_keys(connected_users_dict
, free
);
3231 killed_users_dict
= dict_new();
3232 dict_set_free_keys(killed_users_dict
, free
);
3233 dict_set_free_data(killed_users_dict
, free
);
3234 spamserv_trusted_accounts
= dict_new();
3235 dict_set_free_keys(spamserv_trusted_accounts
, free
);
3236 dict_set_free_data(spamserv_trusted_accounts
, free
);
3238 saxdb_register("SpamServ", spamserv_saxdb_read
, spamserv_saxdb_write
);
3240 reg_new_user_func(spamserv_new_user_func
);
3241 reg_del_user_func(spamserv_del_user_func
);
3242 reg_nick_change_func(spamserv_nick_change_func
);
3243 reg_join_func(spamserv_user_join
);
3244 reg_part_func(spamserv_user_part
);
3246 timeq_add(now
+ FLOOD_TIMEQ_FREQ
, timeq_flood
, NULL
);
3247 timeq_add(now
+ JOINFLOOD_TIMEQ_FREQ
, timeq_joinflood
, NULL
);
3248 timeq_add(now
+ ADV_TIMEQ_FREQ
, timeq_adv
, NULL
);
3249 timeq_add(now
+ BAD_TIMEQ_FREQ
, timeq_bad
, NULL
);
3250 timeq_add(now
+ CAPS_TIMEQ_FREQ
, timeq_caps
, NULL
);
3251 timeq_add(now
+ WARNLEVEL_TIMEQ_FREQ
, timeq_warnlevel
, NULL
);
3252 timeq_add(now
+ KILL_TIMEQ_FREQ
, timeq_kill
, NULL
);
3254 spamserv_module
= module_register("SpamServ", SS_LOG
, "spamserv.help", NULL
);
3256 modcmd_register(spamserv_module
, "ADDTRUST", cmd_addtrust
, 3, MODCMD_REQUIRE_AUTHED
, "flags", "+acceptchan", NULL
);
3257 modcmd_register(spamserv_module
, "DELTRUST", cmd_deltrust
, 3, MODCMD_REQUIRE_AUTHED
, "flags", "+acceptchan", NULL
);
3258 modcmd_register(spamserv_module
, "OADDTRUST", cmd_oaddtrust
, 3, MODCMD_REQUIRE_AUTHED
, "flags", "+acceptchan,+helping", NULL
);
3259 modcmd_register(spamserv_module
, "ODELTRUST", cmd_odeltrust
, 3, MODCMD_REQUIRE_AUTHED
, "flags", "+acceptchan,+helping", NULL
);
3260 modcmd_register(spamserv_module
, "LISTTRUST", cmd_listtrust
, 2, MODCMD_REQUIRE_AUTHED
, NULL
);
3261 modcmd_register(spamserv_module
, "REGISTER", cmd_register
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, "flags", "+acceptchan,+helping", NULL
);
3262 modcmd_register(spamserv_module
, "UNREGISTER", cmd_unregister
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, "flags", "+loghostmask", NULL
);
3263 modcmd_register(spamserv_module
, "ADDEXCEPTION", cmd_addexception
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3264 modcmd_register(spamserv_module
, "DELEXCEPTION", cmd_delexception
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3265 modcmd_register(spamserv_module
, "ADDBADWORD", cmd_addbadword
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3266 modcmd_register(spamserv_module
, "DELBADWORD", cmd_delbadword
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3267 modcmd_register(spamserv_module
, "STATUS", cmd_status
, 1, 0, NULL
);
3268 modcmd_register(spamserv_module
, "SET", cmd_set
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3269 modcmd_register(spamserv_module
, "SET EXCEPTLEVEL", opt_exceptlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3270 modcmd_register(spamserv_module
, "SET EXCEPTADVLEVEL", opt_exceptadvlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3271 modcmd_register(spamserv_module
, "SET EXCEPTBADWORDLEVEL", opt_exceptbadwordlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3272 modcmd_register(spamserv_module
, "SET EXCEPTCAPSLEVEL", opt_exceptcapslevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3273 modcmd_register(spamserv_module
, "SET EXCEPTFLOODLEVEL", opt_exceptfloodlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3274 modcmd_register(spamserv_module
, "SET EXCEPTSPAMLEVEL", opt_exceptspamlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3275 modcmd_register(spamserv_module
, "SET SPAMLIMIT", opt_spamlimit
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3276 modcmd_register(spamserv_module
, "SET BADREACTION", opt_badreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3277 modcmd_register(spamserv_module
, "SET CAPSREACTION", opt_capsreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3278 modcmd_register(spamserv_module
, "SET ADVREACTION", opt_advreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3279 modcmd_register(spamserv_module
, "SET WARNREACTION", opt_warnreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3280 modcmd_register(spamserv_module
, "SET ADVSCAN", opt_advscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3281 modcmd_register(spamserv_module
, "SET CAPSSCAN", opt_capsscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3282 modcmd_register(spamserv_module
, "SET BADWORDSCAN", opt_badwordscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3283 modcmd_register(spamserv_module
, "SET SPAMSCAN", opt_spamscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3284 modcmd_register(spamserv_module
, "SET CHANFLOODSCAN", opt_chanfloodscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3285 modcmd_register(spamserv_module
, "SET JOINFLOODSCAN", opt_joinflood
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3286 modcmd_register(spamserv_module
, "SET CAPSMIN", opt_capsmin
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3287 modcmd_register(spamserv_module
, "SET CAPSPERCENT", opt_capspercent
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3289 spamserv_service
->trigger
= spamserv_conf
.trigger
;
3292 if (autojoin_channels
&& spamserv
) {
3293 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
3294 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
3295 AddChannelUser(spamserv
, chan
)->modes
|= MODE_CHANOP
;
3299 reg_exit_func(spamserv_db_cleanup
);
3300 message_register_table(msgtab
);