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 3 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;
298 /* XXX Rewrite the flag system */
299 if (strlen(info
) < 5)
301 if (strlen(info
) < 6)
304 safestrncpy(cInfo
->info
, info
, sizeof(cInfo
->info
));
305 cInfo
->suspend_expiry
= 0;
306 dict_insert(registered_channels_dict
, strdup(cInfo
->channel
->name
), cInfo
);
312 spamserv_unregister_channel(struct chanInfo
*cInfo
)
317 free_string_list(cInfo
->exceptions
);
318 free_string_list(cInfo
->badwords
);
319 dict_remove(registered_channels_dict
, cInfo
->channel
->name
);
324 spamserv_cs_suspend(struct chanNode
*channel
, time_t expiry
, int suspend
, char *reason
)
326 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
332 cInfo
->flags
|= CHAN_SUSPENDED
;
333 cInfo
->suspend_expiry
= expiry
;
334 spamserv_part_channel(channel
, reason
);
338 if(CHECK_SUSPENDED(cInfo
))
340 cInfo
->flags
&= ~CHAN_SUSPENDED
;
341 cInfo
->suspend_expiry
= 0;
348 spamserv_cs_move_merge(struct userNode
*user
, struct chanNode
*channel
, struct chanNode
*target
, int move
)
350 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
356 if(!spamserv_conf
.allow_move_merge
|| get_chanInfo(target
->name
))
359 snprintf(reason
, sizeof(reason
), "unregistered due to a channel move to %s", target
->name
);
361 snprintf(reason
, sizeof(reason
), "unregistered due to a channel merge into %s", target
->name
);
363 spamserv_cs_unregister(user
, channel
, manually
, reason
);
367 cInfo
->channel
= target
;
369 dict_remove(registered_channels_dict
, channel
->name
);
370 dict_insert(registered_channels_dict
, strdup(target
->name
), cInfo
);
374 snprintf(reason
, sizeof(reason
), "Channel moved to %s by %s.", target
->name
, user
->handle_info
->handle
);
378 spamserv_join_channel(target
);
379 snprintf(reason
, sizeof(reason
), "%s merged into %s by %s.", channel
->name
, target
->name
, user
->handle_info
->handle
);
382 if(!CHECK_SUSPENDED(cInfo
))
383 spamserv_part_channel(channel
, reason
);
386 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
,
387 "SSMSG_CHANNEL_MOVED", channel
->name
, target
->name
,
388 user
->handle_info
->handle
);
390 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
,
391 "SSMSG_CHANNEL_MERGED", channel
->name
, target
->name
,
392 user
->handle_info
->handle
);
401 spamserv_cs_unregister(struct userNode
*user
, struct chanNode
*channel
, enum cs_unreg type
, char *reason
)
403 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
407 char partmsg
[MAXLEN
];
412 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, "SSMSG_UNREG_MANUAL",
413 channel
->name
, reason
, user
->handle_info
->handle
);
414 snprintf(partmsg
, sizeof(partmsg
), "%s %s by %s.", channel
->name
, reason
, user
->handle_info
->handle
);
417 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, "SSMSG_REG_EXPIRED",
419 snprintf(partmsg
, sizeof(partmsg
), "%s registration expired.", channel
->name
);
422 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, "SSMSG_LOST_ALL_USERS",
424 snprintf(partmsg
, sizeof(partmsg
), "%s lost all users.", channel
->name
);
428 if(!CHECK_SUSPENDED(cInfo
))
429 spamserv_part_channel(channel
, partmsg
);
431 spamserv_unregister_channel(cInfo
);
435 /***********************************************/
437 /***********************************************/
439 static struct userInfo
*
440 get_userInfo(const char *nickname
)
442 return dict_find(connected_users_dict
, nickname
, 0);
446 spamserv_create_spamNode(struct chanNode
*channel
, struct userInfo
*uInfo
, char *text
)
448 struct spamNode
*sNode
= malloc(sizeof(struct spamNode
));
452 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for sNode; channel: %s; user: %s", channel
->name
, uInfo
->user
->nick
);
456 sNode
->channel
= channel
;
457 sNode
->crc32
= crc32(text
);
463 struct spamNode
*temp
= uInfo
->spam
;
479 spamserv_delete_spamNode(struct userInfo
*uInfo
, struct spamNode
*sNode
)
484 if(sNode
== uInfo
->spam
)
485 uInfo
->spam
= sNode
->next
;
488 sNode
->next
->prev
= sNode
->prev
;
490 sNode
->prev
->next
= sNode
->next
;
496 spamserv_clear_spamNodes(struct chanNode
*channel
)
498 struct userInfo
*uInfo
;
499 struct spamNode
*sNode
;
502 for(i
= 0; i
< channel
->members
.used
; i
++)
504 if((uInfo
= get_userInfo(channel
->members
.list
[i
]->user
->nick
)))
506 if((sNode
= uInfo
->spam
))
508 for(; sNode
; sNode
= sNode
->next
)
509 if(sNode
->channel
== channel
)
513 spamserv_delete_spamNode(uInfo
, sNode
);
520 spamserv_create_floodNode(struct chanNode
*channel
, struct userNode
*user
, struct floodNode
**uI_fNode
)
522 struct floodNode
*fNode
= malloc(sizeof(struct floodNode
));
526 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for fNode; channel: %s; user: %s", channel
->name
, user
->nick
);
530 fNode
->channel
= channel
;
538 struct floodNode
*temp
= *uI_fNode
;
554 spamserv_delete_floodNode(struct floodNode
**uI_fNode
, struct floodNode
*fNode
)
559 if(fNode
== *uI_fNode
)
560 *uI_fNode
= fNode
->next
;
563 fNode
->next
->prev
= fNode
->prev
;
565 fNode
->prev
->next
= fNode
->next
;
571 spamserv_create_user(struct userNode
*user
)
573 struct userInfo
*uInfo
= malloc(sizeof(struct userInfo
));
574 struct killNode
*kNode
= dict_find(killed_users_dict
, irc_ntoa(&user
->ip
), 0);
578 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for uInfo; nick: %s", user
->nick
);
583 spamserv_debug(SSMSG_DEBUG_RECONNECT
, user
->nick
);
588 uInfo
->joinflood
= NULL
;
589 uInfo
->flags
= kNode
? USER_KILLED
: 0;
590 uInfo
->warnlevel
= kNode
? kNode
->warnlevel
: 0;
595 dict_insert(connected_users_dict
, strdup(user
->nick
), uInfo
);
599 /* free(kNode); dict_remove does this */
600 dict_remove(killed_users_dict
, irc_ntoa(&user
->ip
));
605 spamserv_delete_user(struct userInfo
*uInfo
)
612 spamserv_delete_spamNode(uInfo
, uInfo
->spam
);
616 spamserv_delete_floodNode(&uInfo
->flood
, uInfo
->flood
);
619 while(uInfo
->joinflood
)
620 spamserv_delete_floodNode(&uInfo
->joinflood
, uInfo
->joinflood
);
622 dict_remove(connected_users_dict
, uInfo
->user
->nick
);
627 spamserv_new_user_func(struct userNode
*user
)
630 spamserv_create_user(user
);
636 spamserv_del_user_func(struct userNode
*user
, struct userNode
*killer
, UNUSED_ARG(const char *why
))
638 struct userInfo
*uInfo
= get_userInfo(user
->nick
);
639 struct killNode
*kNode
;
641 if(killer
== spamserv
)
643 kNode
= malloc(sizeof(struct killNode
));
647 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for killNode - nickname %s", user
->nick
);
648 spamserv_delete_user(uInfo
);
652 if(uInfo
->warnlevel
> KILL_WARNLEVEL
)
653 kNode
->warnlevel
= uInfo
->warnlevel
- KILL_WARNLEVEL
;
655 kNode
->warnlevel
= 0;
659 dict_insert(killed_users_dict
, strdup(irc_ntoa(&user
->ip
)), kNode
);
662 spamserv_delete_user(uInfo
);
666 spamserv_nick_change_func(struct userNode
*user
, const char *old_nick
)
668 struct userInfo
*uInfo
= get_userInfo(old_nick
);
671 dict_remove(connected_users_dict
, old_nick
);
672 dict_insert(connected_users_dict
, strdup(user
->nick
), uInfo
);
677 spamserv_user_join(struct modeNode
*mNode
)
679 struct chanNode
*channel
= mNode
->channel
;
680 struct userNode
*user
= mNode
->user
;
681 struct chanInfo
*cInfo
;
682 struct userInfo
*uInfo
;
683 struct floodNode
*jfNode
;
685 if(user
->uplink
->burst
|| !(cInfo
= get_chanInfo(channel
->name
)) || !CHECK_JOINFLOOD(cInfo
) || !(uInfo
= get_userInfo(user
->nick
)))
688 if(!(jfNode
= uInfo
->joinflood
))
690 spamserv_create_floodNode(channel
, user
, &uInfo
->joinflood
);
694 for(; jfNode
; jfNode
= jfNode
->next
)
695 if(jfNode
->channel
== channel
)
700 spamserv_create_floodNode(channel
, user
, &uInfo
->joinflood
);
707 if(jfNode
->count
> JOINFLOOD_MAX
)
711 spamserv_delete_floodNode(&uInfo
->joinflood
, jfNode
);
712 snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_JOINFLOOD
, spamserv_conf
.network_rules
);
713 spamserv_punish(channel
, user
, JOINFLOOD_B_DURATION
, reason
, 1);
722 spamserv_user_part(struct modeNode
*mn
, UNUSED_ARG(const char *reason
))
724 struct userNode
*user
= mn
->user
;
725 struct chanNode
*channel
= mn
->channel
;
726 struct userInfo
*uInfo
;
727 struct spamNode
*sNode
;
728 struct floodNode
*fNode
;
730 if(user
->dead
|| !get_chanInfo(channel
->name
) || !(uInfo
= get_userInfo(user
->nick
)))
733 if((sNode
= uInfo
->spam
))
735 for(; sNode
; sNode
= sNode
->next
)
736 if(sNode
->channel
== channel
)
740 spamserv_delete_spamNode(uInfo
, sNode
);
743 if((fNode
= uInfo
->flood
))
745 for(; fNode
; fNode
= fNode
->next
)
746 if(fNode
->channel
== channel
)
750 spamserv_delete_floodNode(&uInfo
->flood
, fNode
);
754 /***********************************************/
756 /***********************************************/
764 for(i
= 0; i
< 256; i
++)
768 for(j
= 8; j
> 0; j
--)
772 crc
= (crc
>> 1) ^ 0xEDB88320L
;
785 crc32(const char *text
)
787 register unsigned long crc
= 0xFFFFFFFF;
788 unsigned int c
, i
= 0;
790 while((c
= (unsigned int)text
[i
++]) != 0)
791 crc
= ((crc
>> 8) & 0x00FFFFFF) ^ crc_table
[(crc
^c
) & 0xFF];
793 return (crc
^0xFFFFFFFF);
797 timeq_flood(UNUSED_ARG(void *data
))
800 struct userInfo
*uInfo
;
801 struct floodNode
*fNode
;
803 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
805 uInfo
= iter_data(it
);
810 if(!(fNode
= uInfo
->flood
))
813 for(; fNode
; fNode
= fNode
->next
)
815 if(now
- fNode
->time
> FLOOD_EXPIRE
)
817 if(!(--fNode
->count
))
818 spamserv_delete_floodNode(&uInfo
->flood
, fNode
);
823 timeq_add(now
+ FLOOD_TIMEQ_FREQ
, timeq_flood
, NULL
);
827 timeq_joinflood(UNUSED_ARG(void *data
))
830 struct userInfo
*uInfo
;
831 struct floodNode
*fNode
, *nextnode
;
833 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
835 uInfo
= iter_data(it
);
837 if(!(fNode
= uInfo
->joinflood
))
840 for(; fNode
; fNode
= nextnode
)
842 nextnode
= fNode
->next
;
843 if(now
- fNode
->time
> JOINFLOOD_EXPIRE
)
845 if(!(--fNode
->count
))
846 spamserv_delete_floodNode(&uInfo
->joinflood
, fNode
);
851 timeq_add(now
+ JOINFLOOD_TIMEQ_FREQ
, timeq_joinflood
, NULL
);
855 timeq_bad(UNUSED_ARG(void *data
))
858 struct userInfo
*uInfo
;
860 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
862 uInfo
= iter_data(it
);
864 if(uInfo
->lastbad
&& uInfo
->lastbad
- now
> BAD_EXPIRE
)
867 uInfo
->flags
&= ~USER_BAD_WARNED
;
871 timeq_add(now
+ BAD_TIMEQ_FREQ
, timeq_bad
, NULL
);
875 timeq_caps(UNUSED_ARG(void *data
))
878 struct userInfo
*uInfo
;
880 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
882 uInfo
= iter_data(it
);
884 if(uInfo
->lastcaps
&& uInfo
->lastcaps
- now
> CAPS_EXPIRE
)
887 uInfo
->flags
&= ~USER_CAPS_WARNED
;
891 timeq_add(now
+ CAPS_TIMEQ_FREQ
, timeq_caps
, NULL
);
895 timeq_adv(UNUSED_ARG(void *data
))
898 struct userInfo
*uInfo
;
900 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
902 uInfo
= iter_data(it
);
904 if(uInfo
->lastadv
&& uInfo
->lastadv
- now
> ADV_EXPIRE
)
907 uInfo
->flags
&= ~USER_ADV_WARNED
;
911 timeq_add(now
+ ADV_TIMEQ_FREQ
, timeq_adv
, NULL
);
915 timeq_warnlevel(UNUSED_ARG(void *data
))
918 struct userInfo
*uInfo
;
920 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
922 uInfo
= iter_data(it
);
924 if(uInfo
->warnlevel
> 0)
928 timeq_add(now
+ WARNLEVEL_TIMEQ_FREQ
, timeq_warnlevel
, NULL
);
932 timeq_kill(UNUSED_ARG(void *data
))
935 struct killNode
*kNode
;
938 for(it
= dict_first(killed_users_dict
); it
; it
= iter_next(it
))
940 kNode
= iter_data(it
);
942 if(now
- kNode
->time
> KILL_EXPIRE
) {
943 dict_remove(killed_users_dict
, iter_key(it
));
944 /* have to restart the loop because next is
945 * now invalid. FIXME: how could we do this better? */
946 break; /* out of for() loop */
949 /* no more killed_users to delete, so stop while loop */
950 break; /* out of while() loop */
953 timeq_add(now
+ KILL_TIMEQ_FREQ
, timeq_kill
, NULL
);
957 binary_option(char *name
, unsigned long mask
, struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[])
959 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
964 if(enabled_string(argv
[1]))
966 cInfo
->flags
|= mask
;
969 else if(disabled_string(argv
[1]))
971 cInfo
->flags
&= ~mask
;
976 spamserv_notice(user
, "SSMSG_INVALID_BINARY", argv
[1]);
982 value
= (cInfo
->flags
& mask
) ? 1 : 0;
985 spamserv_notice(user
, "SSMSG_STRING_VALUE", name
, value
? "Enabled." : "Disabled.");
997 multiple_option(char *name
, char *description
, enum channelinfo info
, struct valueData
*values
, int count
, struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[])
999 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1004 index
= atoi(argv
[1]);
1006 if(index
< 0 || index
>= count
)
1008 spamserv_notice(user
, "SSMSG_INVALID_NUM_SET", index
, description
);
1010 for(index
= 0; index
< count
; index
++)
1011 spamserv_notice(user
, "SSMSG_NUMERIC_VALUE", name
, index
, values
[index
].description
);
1016 if(values
[index
].oper_only
&& !IsOper(user
))
1018 spamserv_notice(user
, "SSMSG_MUST_BE_OPER");
1022 cInfo
->info
[info
] = values
[index
].value
;
1026 for(index
= 0; index
< count
&& cInfo
->info
[info
] != values
[index
].value
; index
++);
1029 spamserv_notice(user
, "SSMSG_NUMERIC_VALUE", name
, index
, values
[index
].description
);
1034 show_exceptions(struct userNode
*user
, struct chanInfo
*cInfo
)
1036 struct helpfile_table table
;
1039 if(!cInfo
->exceptions
->used
)
1041 spamserv_notice(user
, "SSMSG_NO_EXCEPTIONS");
1045 spamserv_notice(user
, "SSMSG_EXCEPTION_LIST");
1049 table
.flags
= TABLE_REPEAT_ROWS
| TABLE_NO_FREE
| TABLE_NO_HEADERS
;
1050 table
.contents
= alloca(cInfo
->exceptions
->used
* sizeof(*table
.contents
));
1052 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1054 table
.contents
[table
.length
] = alloca(table
.width
* sizeof(**table
.contents
));
1055 table
.contents
[table
.length
][0] = cInfo
->exceptions
->list
[i
];
1059 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
1065 show_badwords(struct userNode
*user
, struct chanInfo
*cInfo
)
1067 struct helpfile_table table
;
1070 if(!cInfo
->badwords
->used
)
1072 spamserv_notice(user
, "SSMSG_NO_BADWORDS");
1076 spamserv_notice(user
, "SSMSG_BADWORD_LIST");
1080 table
.flags
= TABLE_REPEAT_ROWS
| TABLE_NO_FREE
| TABLE_NO_HEADERS
;
1081 table
.contents
= alloca(cInfo
->badwords
->used
* sizeof(*table
.contents
));
1083 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1085 table
.contents
[table
.length
] = alloca(table
.width
* sizeof(**table
.contents
));
1086 table
.contents
[table
.length
][0] = cInfo
->badwords
->list
[i
];
1090 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
1096 show_memory_usage(struct userNode
*user
)
1099 struct helpfile_table table
;
1100 struct chanInfo
*cInfo
;
1101 struct userInfo
*uInfo
;
1102 struct spamNode
*sNode
;
1103 struct floodNode
*fNode
;
1104 double channel_size
= 0, user_size
, size
;
1105 unsigned int spamcount
= 0, floodcount
= 0, i
, j
;
1108 for(it
= dict_first(registered_channels_dict
); it
; it
= iter_next(it
))
1110 cInfo
= iter_data(it
);
1112 if(!cInfo
->exceptions
->used
)
1115 if(!cInfo
->badwords
->used
)
1118 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1119 channel_size
+= strlen(cInfo
->exceptions
->list
[i
]) * sizeof(char);
1121 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1122 channel_size
+= strlen(cInfo
->badwords
->list
[i
]) * sizeof(char);
1125 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
1127 uInfo
= iter_data(it
);
1129 for(sNode
= uInfo
->spam
; sNode
; sNode
= sNode
->next
, spamcount
++);
1130 for(fNode
= uInfo
->flood
; fNode
; fNode
= fNode
->next
, floodcount
++);
1131 for(fNode
= uInfo
->joinflood
; fNode
; fNode
= fNode
->next
, floodcount
++);
1134 channel_size
+= dict_size(registered_channels_dict
) * sizeof(struct chanInfo
);
1136 user_size
= dict_size(connected_users_dict
) * sizeof(struct userInfo
) +
1137 dict_size(killed_users_dict
) * sizeof(struct killNode
) +
1138 spamcount
* sizeof(struct spamNode
) +
1139 floodcount
* sizeof(struct floodNode
);
1141 size
= channel_size
+ user_size
;
1143 ss_reply("SSMSG_STATUS_MEMORY");
1147 table
.flags
= TABLE_NO_FREE
| TABLE_NO_HEADERS
| TABLE_PAD_LEFT
;
1148 table
.contents
= calloc(table
.length
, sizeof(char**));
1151 table
.contents
[0] = calloc(table
.width
, sizeof(char*));
1152 snprintf(buffer
, sizeof(buffer
), "Channel Memory Usage:");
1153 table
.contents
[0][0] = strdup(buffer
);
1154 snprintf(buffer
, sizeof(buffer
), " %g Byte; ", channel_size
);
1155 table
.contents
[0][1] = strdup(buffer
);
1156 snprintf(buffer
, sizeof(buffer
), "%g KiloByte; ", channel_size
/ 1024);
1157 table
.contents
[0][2] = strdup(buffer
);
1158 snprintf(buffer
, sizeof(buffer
), "%g MegaByte", channel_size
/ 1024 / 1024);
1159 table
.contents
[0][3] = strdup(buffer
);
1162 table
.contents
[1] = calloc(table
.width
, sizeof(char*));
1163 snprintf(buffer
, sizeof(buffer
), "User Memory Usage :");
1164 table
.contents
[1][0] = strdup(buffer
);
1165 snprintf(buffer
, sizeof(buffer
), " %g Byte; ", user_size
);
1166 table
.contents
[1][1] = strdup(buffer
);
1167 snprintf(buffer
, sizeof(buffer
), "%g KiloByte; ", user_size
/ 1024);
1168 table
.contents
[1][2] = strdup(buffer
);
1169 snprintf(buffer
, sizeof(buffer
), "%g MegaByte", user_size
/ 1024 / 1024);
1170 table
.contents
[1][3] = strdup(buffer
);
1172 // total memory usage
1173 table
.contents
[2] = calloc(table
.width
, sizeof(char*));
1174 snprintf(buffer
, sizeof(buffer
), "Total Memory Usage :");
1175 table
.contents
[2][0] = strdup(buffer
);
1176 snprintf(buffer
, sizeof(buffer
), " %g Byte; ", size
);
1177 table
.contents
[2][1] = strdup(buffer
);
1178 snprintf(buffer
, sizeof(buffer
), "%g KiloByte; ", size
/ 1024);
1179 table
.contents
[2][2] = strdup(buffer
);
1180 snprintf(buffer
, sizeof(buffer
), "%g MegaByte", size
/ 1024 / 1024);
1181 table
.contents
[2][3] = strdup(buffer
);
1183 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
1185 for(i
= 0; i
< table
.length
; i
++)
1187 for(j
= 0; j
< table
.width
; j
++)
1188 free((char*)table
.contents
[i
][j
]);
1190 free(table
.contents
[i
]);
1193 free(table
.contents
);
1197 show_registered_channels(struct userNode
*user
)
1199 struct helpfile_table table
;
1202 spamserv_notice(user
, "SSMSG_STATUS_CHANNEL_LIST");
1204 if(!dict_size(registered_channels_dict
))
1206 spamserv_notice(user
, "SSMSG_STATUS_NO_CHANNEL");
1212 table
.flags
= TABLE_REPEAT_ROWS
| TABLE_NO_FREE
| TABLE_NO_HEADERS
;
1213 table
.contents
= alloca(dict_size(registered_channels_dict
) * sizeof(*table
.contents
));
1215 for(it
= dict_first(registered_channels_dict
); it
; it
= iter_next(it
))
1217 struct chanInfo
*cInfo
= iter_data(it
);
1219 table
.contents
[table
.length
] = alloca(table
.width
* sizeof(**table
.contents
));
1220 table
.contents
[table
.length
][0] = cInfo
->channel
->name
;
1224 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
1227 /***********************************************/
1229 /***********************************************/
1232 SPAMSERV_FUNC(cmd_register
)
1234 struct chanInfo
*cInfo
;
1236 if(!channel
|| !channel
->channel_info
)
1238 ss_reply("SSMSG_NOT_REGISTERED_CS", channel
->name
);
1242 if(get_chanInfo(channel
->name
))
1244 ss_reply("SSMSG_ALREADY_REGISTERED", channel
->name
);
1248 if(IsSuspended(channel
->channel_info
))
1250 ss_reply("SSMSG_SUSPENDED_CS", channel
->name
, "register");
1254 if(channel
== spamserv_conf
.debug_channel
)
1256 ss_reply("SSMSG_DEBUG_CHAN");
1260 if(!(cInfo
= spamserv_register_channel(channel
, spamserv_conf
.global_exceptions
, spamserv_conf
.global_badwords
, CHAN_FLAGS_DEFAULT
, CHAN_INFO_DEFAULT
)))
1262 ss_reply("SSMSG_NO_REGISTER", channel
->name
);
1266 spamserv_join_channel(cInfo
->channel
);
1268 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, "SSMSG_REGISTERED_BY",
1269 channel
->name
, user
->handle_info
->handle
);
1270 ss_reply("SSMSG_REG_SUCCESS", channel
->name
);
1276 SPAMSERV_FUNC(cmd_unregister
)
1278 struct chanInfo
*cInfo
;
1279 struct chanData
*cData
;
1280 struct userData
*uData
;
1281 char reason
[MAXLEN
];
1283 if(!channel
|| !(cData
= channel
->channel_info
) || !(cInfo
= get_chanInfo(channel
->name
)))
1285 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1289 if(!(uData
= GetChannelUser(cData
, user
->handle_info
)) || (uData
->access
< UL_OWNER
))
1291 ss_reply("SSMSG_NO_ACCESS");
1295 if(!IsHelping(user
))
1297 if(IsSuspended(cData
))
1299 ss_reply("SSMSG_SUSPENDED_CS", channel
->name
, "unregister");
1303 if(argc
< 2 || strcasecmp(argv
[1], "CONFIRM"))
1305 ss_reply("SSMSG_CONFIRM_UNREG");
1310 if(!CHECK_SUSPENDED(cInfo
))
1312 snprintf(reason
, sizeof(reason
), "%s unregistered by %s.", spamserv
->nick
, user
->handle_info
->handle
);
1313 spamserv_part_channel(channel
, reason
);
1316 spamserv_unregister_channel(cInfo
);
1318 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, "SSMSG_UNREGISTERED_BY",
1319 channel
->name
, user
->handle_info
->handle
);
1320 ss_reply("SSMSG_UNREG_SUCCESS", channel
->name
);
1326 SPAMSERV_FUNC(cmd_status
)
1328 ss_reply("SSMSG_STATUS");
1329 ss_reply("SSMSG_STATUS_USERS", dict_size(connected_users_dict
));
1330 ss_reply("SSMSG_STATUS_CHANNELS", dict_size(registered_channels_dict
));
1332 if(IsOper(user
) && argc
> 1)
1334 if(!irccasecmp(argv
[1], "memory"))
1335 show_memory_usage(user
);
1336 else if(!irccasecmp(argv
[1], "channels"))
1337 show_registered_channels(user
);
1344 SPAMSERV_FUNC(cmd_addexception
)
1346 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1347 struct userData
*uData
;
1350 if(!cInfo
|| !channel
->channel_info
)
1352 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1356 if(CHECK_SUSPENDED(cInfo
))
1358 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1362 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1364 ss_reply("SSMSG_NO_ACCESS");
1369 return show_exceptions(user
, cInfo
);
1371 if(cInfo
->exceptions
->used
== spamserv_conf
.exception_max
&& !IsOper(user
))
1373 ss_reply("SSMSG_EXCEPTION_MAX", spamserv_conf
.exception_max
);
1377 if(strlen(argv
[1]) < spamserv_conf
.exception_min_len
)
1379 ss_reply("SSMSG_EXCEPTION_TOO_SHORT", spamserv_conf
.exception_min_len
);
1382 else if(strlen(argv
[1]) > spamserv_conf
.exception_max_len
)
1384 ss_reply("SSMSG_EXCEPTION_TOO_LONG", spamserv_conf
.exception_max_len
);
1388 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1390 if(!irccasecmp(argv
[1], cInfo
->exceptions
->list
[i
]))
1392 ss_reply("SSMSG_EXCEPTION_IN_LIST", argv
[1]);
1397 string_list_append(cInfo
->exceptions
, strdup(argv
[1]));
1398 ss_reply("SSMSG_EXCEPTION_ADDED", argv
[1]);
1404 SPAMSERV_FUNC(cmd_delexception
)
1406 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1407 struct userData
*uData
;
1411 if(!cInfo
|| !channel
->channel_info
)
1413 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1417 if(CHECK_SUSPENDED(cInfo
))
1419 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1423 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1425 ss_reply("SSMSG_NO_ACCESS");
1430 return show_exceptions(user
, cInfo
);
1432 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1434 if(!irccasecmp(argv
[1], cInfo
->exceptions
->list
[i
]))
1443 ss_reply("SSMSG_NO_SUCH_EXCEPTION", argv
[1]);
1447 string_list_delete(cInfo
->exceptions
, i
);
1448 ss_reply("SSMSG_EXCEPTION_DELETED", argv
[1]);
1454 SPAMSERV_FUNC(cmd_addbadword
)
1456 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1457 struct userData
*uData
;
1460 if(!cInfo
|| !channel
->channel_info
)
1462 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1466 if(CHECK_SUSPENDED(cInfo
))
1468 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1472 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1474 ss_reply("SSMSG_NO_ACCESS");
1479 return show_badwords(user
, cInfo
);
1481 if(cInfo
->badwords
->used
== spamserv_conf
.badword_max
&& !IsOper(user
))
1483 ss_reply("SSMSG_BADWORD_MAX", spamserv_conf
.badword_max
);
1487 if(strlen(argv
[1]) < spamserv_conf
.badword_min_len
)
1489 ss_reply("SSMSG_BADWORD_TOO_SHORT", spamserv_conf
.badword_min_len
);
1492 else if(strlen(argv
[1]) > spamserv_conf
.badword_max_len
)
1494 ss_reply("SSMSG_BADWORD_TOO_LONG", spamserv_conf
.badword_max_len
);
1498 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1500 if(!irccasecmp(argv
[1], cInfo
->badwords
->list
[i
]))
1502 ss_reply("SSMSG_BADWORD_IN_LIST", argv
[1]);
1507 string_list_append(cInfo
->badwords
, strdup(argv
[1]));
1508 ss_reply("SSMSG_BADWORD_ADDED", argv
[1]);
1514 SPAMSERV_FUNC(cmd_delbadword
)
1516 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1517 struct userData
*uData
;
1521 if(!cInfo
|| !channel
->channel_info
)
1523 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1527 if(CHECK_SUSPENDED(cInfo
))
1529 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1533 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1535 ss_reply("SSMSG_NO_ACCESS");
1540 return show_badwords(user
, cInfo
);
1542 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1544 if(!irccasecmp(argv
[1], cInfo
->badwords
->list
[i
]))
1553 ss_reply("SSMSG_NO_SUCH_BADWORD", argv
[1]);
1557 string_list_delete(cInfo
->badwords
, i
);
1558 ss_reply("SSMSG_BADWORD_DELETED", argv
[1]);
1564 SPAMSERV_FUNC(cmd_set
)
1566 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1567 struct userData
*uData
;
1568 struct svccmd
*subcmd
;
1569 char cmd_name
[MAXLEN
];
1574 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1578 if(CHECK_SUSPENDED(cInfo
))
1580 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1584 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1586 ss_reply("SSMSG_NO_ACCESS");
1592 ss_reply("SSMSG_CHANNEL_OPTIONS");
1594 for(i
= 0; i
< SET_SUBCMDS_SIZE
; i
++)
1596 sprintf(cmd_name
, "%s %s", cmd
->name
, set_subcommands
[i
]);
1598 if((subcmd
= dict_find(cmd
->parent
->commands
, cmd_name
, NULL
)))
1599 subcmd
->command
->func(user
, channel
, 1, argv
+ 1, subcmd
);
1605 sprintf(cmd_name
, "%s %s", cmd
->name
, argv
[1]);
1606 subcmd
= dict_find(cmd
->parent
->commands
, cmd_name
, NULL
);
1610 reply("SSMSG_INVALID_OPTION", argv
[1], argv
[0]);
1614 return subcmd
->command
->func(user
, channel
, argc
- 1, argv
+ 1, subcmd
);
1617 int ss_check_user_level(struct chanNode
*channel
, struct userNode
*user
, unsigned int minimum
, int allow_override
, int exempt_owner
)
1619 struct userData
*uData
;
1620 struct chanData
*cData
= channel
->channel_info
;
1623 uData
= _GetChannelUser(cData
, user
->handle_info
, allow_override
, 0);
1626 if(minimum
<= uData
->access
)
1628 if((minimum
> UL_OWNER
) && (uData
->access
== UL_OWNER
) && exempt_owner
)
1635 channel_except_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1637 struct chanData
*cData
= channel
->channel_info
;
1638 struct chanInfo
*cInfo
;
1639 struct userData
*uData
;
1640 unsigned short value
;
1642 cInfo
= get_chanInfo(channel
->name
);
1646 if(!ss_check_user_level(channel
, user
, cInfo
->exceptlevel
, 1, 1))
1648 reply("SSMSG_CANNOT_SET");
1651 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1652 if(!value
&& strcmp(argv
[1], "0"))
1654 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1657 uData
= GetChannelUser(cData
, user
->handle_info
);
1658 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1660 reply("SSMSG_BAD_SETLEVEL");
1663 cInfo
->exceptlevel
= value
;
1665 reply("SSMSG_SET_EXCEPTLEVEL", cInfo
->exceptlevel
);
1670 channel_except_adv_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1672 struct chanData
*cData
= channel
->channel_info
;
1673 struct chanInfo
*cInfo
;
1674 struct userData
*uData
;
1675 unsigned short value
;
1677 cInfo
= get_chanInfo(channel
->name
);
1681 if(!ss_check_user_level(channel
, user
, cInfo
->exceptadvlevel
, 1, 1))
1683 reply("SSMSG_CANNOT_SET");
1686 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1687 if(!value
&& strcmp(argv
[1], "0"))
1689 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1692 uData
= GetChannelUser(cData
, user
->handle_info
);
1693 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1695 reply("SSMSG_BAD_SETLEVEL");
1698 cInfo
->exceptadvlevel
= value
;
1700 reply("SSMSG_SET_EXCEPTADVLEVEL", cInfo
->exceptadvlevel
);
1705 channel_except_badword_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1707 struct chanData
*cData
= channel
->channel_info
;
1708 struct chanInfo
*cInfo
;
1709 struct userData
*uData
;
1710 unsigned short value
;
1712 cInfo
= get_chanInfo(channel
->name
);
1716 if(!ss_check_user_level(channel
, user
, cInfo
->exceptbadwordlevel
, 1, 1))
1718 reply("SSMSG_CANNOT_SET");
1721 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1722 if(!value
&& strcmp(argv
[1], "0"))
1724 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1727 uData
= GetChannelUser(cData
, user
->handle_info
);
1728 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1730 reply("SSMSG_BAD_SETLEVEL");
1733 cInfo
->exceptbadwordlevel
= value
;
1735 reply("SSMSG_SET_EXCEPTBADWORDLEVEL", cInfo
->exceptbadwordlevel
);
1740 channel_except_caps_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1742 struct chanData
*cData
= channel
->channel_info
;
1743 struct chanInfo
*cInfo
;
1744 struct userData
*uData
;
1745 unsigned short value
;
1747 cInfo
= get_chanInfo(channel
->name
);
1751 if(!ss_check_user_level(channel
, user
, cInfo
->exceptcapslevel
, 1, 1))
1753 reply("SSMSG_CANNOT_SET");
1756 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1757 if(!value
&& strcmp(argv
[1], "0"))
1759 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1762 uData
= GetChannelUser(cData
, user
->handle_info
);
1763 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1765 reply("SSMSG_BAD_SETLEVEL");
1768 cInfo
->exceptcapslevel
= value
;
1770 reply("SSMSG_SET_EXCEPTCAPSLEVEL", cInfo
->exceptcapslevel
);
1775 channel_except_flood_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1777 struct chanData
*cData
= channel
->channel_info
;
1778 struct chanInfo
*cInfo
;
1779 struct userData
*uData
;
1780 unsigned short value
;
1782 cInfo
= get_chanInfo(channel
->name
);
1786 if(!ss_check_user_level(channel
, user
, cInfo
->exceptfloodlevel
, 1, 1))
1788 reply("SSMSG_CANNOT_SET");
1791 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1792 if(!value
&& strcmp(argv
[1], "0"))
1794 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1797 uData
= GetChannelUser(cData
, user
->handle_info
);
1798 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1800 reply("SSMSG_BAD_SETLEVEL");
1803 cInfo
->exceptfloodlevel
= value
;
1805 reply("SSMSG_SET_EXCEPTFLOODLEVEL", cInfo
->exceptfloodlevel
);
1810 channel_except_spam_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1812 struct chanData
*cData
= channel
->channel_info
;
1813 struct chanInfo
*cInfo
;
1814 struct userData
*uData
;
1815 unsigned short value
;
1817 cInfo
= get_chanInfo(channel
->name
);
1821 if(!ss_check_user_level(channel
, user
, cInfo
->exceptspamlevel
, 1, 1))
1823 reply("SSMSG_CANNOT_SET");
1826 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1827 if(!value
&& strcmp(argv
[1], "0"))
1829 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1832 uData
= GetChannelUser(cData
, user
->handle_info
);
1833 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1835 reply("SSMSG_BAD_SETLEVEL");
1838 cInfo
->exceptspamlevel
= value
;
1840 reply("SSMSG_SET_EXCEPTSPAMLEVEL", cInfo
->exceptspamlevel
);
1845 SPAMSERV_FUNC(opt_capsmin
)
1847 struct chanInfo
*cInfo
;
1849 cInfo
= get_chanInfo(channel
->name
);
1853 char *mask
= strdup(argv
[1]);
1854 unsigned int old
= cInfo
->capsmin
;
1856 if (isdigit(*mask
) && strspn(mask
, "1234567890,-") == strlen(mask
)) {
1857 cInfo
->capsmin
= mask
? strtoul(mask
, NULL
, 0) : 10;
1859 if (cInfo
->capsmin
< 0) {
1860 cInfo
->capsmin
= old
;
1861 reply("SSMSG_BAD_SETLEVEL");
1865 reply("SSMSG_BAD_SETLEVEL");
1869 reply("SSMSG_SET_CAPSMIN", cInfo
->capsmin
);
1874 SPAMSERV_FUNC(opt_capspercent
)
1876 struct chanInfo
*cInfo
;
1878 cInfo
= get_chanInfo(channel
->name
);
1882 char *mask
= strdup(argv
[1]);
1883 unsigned int old
= cInfo
->capspercent
;
1885 if (isdigit(*mask
) && strspn(mask
, "1234567890,-") == strlen(mask
)) {
1886 cInfo
->capspercent
= mask
? strtoul(mask
, NULL
, 0) : 10;
1888 if ((cInfo
->capspercent
< 0) || (cInfo
->capspercent
> 100)) {
1889 cInfo
->capspercent
= old
;
1890 reply("SSMSG_BAD_SETLEVEL");
1894 reply("SSMSG_BAD_SETLEVEL");
1898 reply("SSMSG_SET_CAPSPERCENT", cInfo
->capspercent
);
1903 SPAMSERV_FUNC(opt_exceptlevel
)
1905 return channel_except_level(SSFUNC_ARGS
);
1909 SPAMSERV_FUNC(opt_exceptadvlevel
)
1911 return channel_except_adv_level(SSFUNC_ARGS
);
1915 SPAMSERV_FUNC(opt_exceptbadwordlevel
)
1917 return channel_except_badword_level(SSFUNC_ARGS
);
1921 SPAMSERV_FUNC(opt_exceptcapslevel
)
1923 return channel_except_caps_level(SSFUNC_ARGS
);
1927 SPAMSERV_FUNC(opt_exceptfloodlevel
)
1929 return channel_except_flood_level(SSFUNC_ARGS
);
1933 SPAMSERV_FUNC(opt_exceptspamlevel
)
1935 return channel_except_spam_level(SSFUNC_ARGS
);
1939 SPAMSERV_FUNC(opt_spamlimit
)
1941 struct valueData values
[] =
1943 {"Users may send the same message $b2$b times.", 'a', 0},
1944 {"Users may send the same message $b3$b times.", 'b', 0},
1945 {"Users may send the same message $b4$b times.", 'c', 0},
1946 {"Users may send the same message $b5$b times.", 'd', 0},
1947 {"Users may send the same message $b6$b times.", 'e', 0}
1950 MULTIPLE_OPTION("SpamLimit ", "SpamLimit", ci_SpamLimit
);
1954 SPAMSERV_FUNC(opt_advreaction
)
1956 struct valueData values
[] =
1958 {"Kick on disallowed advertising.", 'k', 0},
1959 {"Kickban on disallowed advertising.", 'b', 0},
1960 {"Short timed ban on disallowed advertising.", 's', 0},
1961 {"Long timed ban on disallowed advertising.", 'l', 0},
1962 {"Kill on disallowed advertising.", 'd', 1}
1965 MULTIPLE_OPTION("AdvReaction ", "AdvReaction", ci_AdvReaction
);
1969 SPAMSERV_FUNC(opt_warnreaction
)
1971 struct valueData values
[] =
1973 {"Kick after warning.", 'k', 0},
1974 {"Kickban after warning.", 'b', 0},
1975 {"Short timed ban after warning.", 's', 0},
1976 {"Long timed ban after warning.", 'l', 0},
1977 {"Kill after warning.", 'd', 1}
1980 MULTIPLE_OPTION("WarnReaction ", "WarnReaction", ci_WarnReaction
);
1984 SPAMSERV_FUNC(opt_badreaction
)
1986 struct valueData values
[] =
1988 {"Kick on disallowed badwords.", 'k', 0},
1989 {"Kickban on disallowed badwords.", 'b', 0},
1990 {"Short timed ban on disallowed badwords.", 's', 0},
1991 {"Long timed ban on disallowed badwords.", 'l', 0},
1992 {"Kill on disallowed badwords.", 'd', 1}
1995 MULTIPLE_OPTION("BadReaction ", "BadReaction", ci_BadReaction
);
1999 SPAMSERV_FUNC(opt_capsreaction
)
2001 struct valueData values
[] =
2003 {"Kick on disallowed caps.", 'k', 0},
2004 {"Kickban on disallowed caps.", 'b', 0},
2005 {"Short timed ban on disallowed caps.", 's', 0},
2006 {"Long timed ban on disallowed caps.", 'l', 0},
2007 {"Kill on disallowed caps.", 'd', 1}
2010 MULTIPLE_OPTION("CapsReaction ", "CapsReaction", ci_CapsReaction
);
2014 SPAMSERV_FUNC(opt_advscan
)
2016 BINARY_OPTION("AdvScan ", CHAN_ADV_SCAN
);
2020 SPAMSERV_FUNC(opt_capsscan
)
2022 BINARY_OPTION("CapsScan ", CHAN_CAPSSCAN
);
2026 SPAMSERV_FUNC(opt_spamscan
)
2028 BINARY_OPTION("SpamScan ", CHAN_SPAMSCAN
);
2032 SPAMSERV_FUNC(opt_badwordscan
)
2034 BINARY_OPTION("BadWordScan ", CHAN_BADWORDSCAN
);
2038 SPAMSERV_FUNC(opt_chanfloodscan
)
2040 BINARY_OPTION("ChanFloodScan ", CHAN_CHANFLOODSCAN
);
2044 SPAMSERV_FUNC(opt_joinflood
)
2046 BINARY_OPTION("JoinFloodScan ", CHAN_JOINFLOOD
);
2050 spamserv_add_trusted_account(const char *account
, struct string_list
*channel
, const char *issuer
, time_t issued
)
2052 struct trusted_account
*ta
;
2053 ta
= calloc(1, sizeof(*ta
));
2056 ta
->account
= strdup(account
);
2057 ta
->channel
= channel
? string_list_copy(channel
) : alloc_string_list(1);
2058 ta
->issuer
= strdup(issuer
);
2059 ta
->issued
= issued
;
2060 dict_insert(spamserv_trusted_accounts
, strdup(ta
->account
), ta
);
2065 free_trusted_account(void *data)
2067 struct trusted_account *ta = data;
2069 free_string_list(ta->channel);
2075 static SPAMSERV_FUNC(cmd_addtrust
)
2078 struct userData
*uData
;
2079 struct chanData
*cData
;
2080 struct chanInfo
*cInfo
;
2081 struct trusted_account
*ta
;
2082 struct string_list
*templist
;
2083 struct handle_info
*hi
;
2085 if (!(channel
= GetChannel(argv
[2]))) {
2086 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2090 cInfo
= get_chanInfo(channel
->name
);
2091 cData
= channel
->channel_info
;
2092 uData
= GetChannelUser(cData
, user
->handle_info
);
2094 if (!cInfo
|| !channel
->channel_info
) {
2095 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2099 if (CHECK_SUSPENDED(cInfo
)) {
2100 ss_reply("SSMSG_SUSPENDED", channel
->name
);
2104 if (!uData
|| (uData
->access
< UL_MANAGER
)) {
2105 ss_reply("SSMSG_NO_ACCESS");
2109 if (!(hi
= modcmd_get_handle_info(user
, argv
[1]))) {
2113 if ((ta
= dict_find(spamserv_trusted_accounts
, argv
[1], NULL
))) {
2114 if (ta
->channel
->used
&& (argc
> 1)) {
2115 for (i
=0; i
< ta
->channel
->used
; i
++) {
2116 if (!strcmp(ta
->channel
->list
[i
], argv
[2])) {
2117 ss_reply("SSMSG_ALREADY_TRUSTED", hi
->handle
);
2123 string_list_append(ta
->channel
, argv
[2]);
2124 ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2128 templist
= alloc_string_list(sizeof(argv
[2])+1);
2129 // templist = alloc_string_list(1);
2130 string_list_append(templist
, argv
[2]);
2132 spamserv_add_trusted_account(hi
->handle
, templist
, user
->handle_info
->handle
, now
);
2133 ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2137 static SPAMSERV_FUNC(cmd_oaddtrust
)
2139 unsigned int i
, global
= 0;
2140 struct chanInfo
*cInfo
;
2141 struct chanData
*cData
;
2142 struct trusted_account
*ta
;
2143 struct string_list
*templist
;
2144 struct handle_info
*hi
;
2146 if (!strcmp(argv
[2], "global"))
2149 if (!(channel
= GetChannel(argv
[2])) && (global
== 0)) {
2150 ss_reply("SSMSG_NOT_REGISTERED", channel
? channel
->name
: (global
? "global" : ""));
2155 cInfo
= get_chanInfo(channel
->name
);
2156 cData
= channel
->channel_info
;
2158 if (!cInfo
|| !channel
->channel_info
) {
2159 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2164 if (!(hi
= modcmd_get_handle_info(user
, argv
[1]))) {
2168 if ((ta
= dict_find(spamserv_trusted_accounts
, argv
[1], NULL
))) {
2169 if (ta
->channel
->used
&& (argc
> 1)) {
2170 for (i
=0; i
< ta
->channel
->used
; i
++) {
2171 if (!strcmp(ta
->channel
->list
[i
], argv
[2])) {
2172 ss_reply("SSMSG_ALREADY_TRUSTED", argv
[1]);
2178 string_list_append(ta
->channel
, argv
[2]);
2181 ss_reply("SSMSG_ADDED_TRUSTED", argv
[1]);
2183 ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", argv
[1], argv
[2]);
2188 templist
= alloc_string_list(sizeof(argv
[2])+1);
2189 // templist = alloc_string_list(1);
2190 string_list_append(templist
, argv
[2]);
2192 spamserv_add_trusted_account(hi
->handle
, templist
, user
->handle_info
->handle
, now
);
2195 ss_reply("SSMSG_ADDED_TRUSTED", hi
->handle
);
2197 ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2202 static SPAMSERV_FUNC(cmd_deltrust
)
2206 struct trusted_account
*ta
;
2207 struct userData
*uData
;
2208 struct chanData
*cData
;
2209 struct chanInfo
*cInfo
;
2210 struct handle_info
*hi
;
2212 if (!(channel
= GetChannel(argv
[2]))) {
2213 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2217 cInfo
= get_chanInfo(channel
->name
);
2218 cData
= channel
->channel_info
;
2219 uData
= GetChannelUser(cData
, user
->handle_info
);
2221 if (!cInfo
|| !channel
->channel_info
) {
2222 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2226 if (CHECK_SUSPENDED(cInfo
)) {
2227 ss_reply("SSMSG_SUSPENDED", channel
->name
);
2231 if (!uData
|| (uData
->access
< UL_MANAGER
)) {
2232 ss_reply("SSMSG_NO_ACCESS");
2236 if (!(hi
= modcmd_get_handle_info(user
, argv
[1]))) {
2240 ta
= dict_find(spamserv_trusted_accounts
, hi
->handle
, NULL
);
2243 ss_reply("SSMSG_NOT_TRUSTED", argv
[2]);
2248 if (ta
->channel
->used
) {
2249 for (i
=0; i
< ta
->channel
->used
; i
++) {
2250 if (!strcmp(ta
->channel
->list
[i
], argv
[2])) {
2251 string_list_delete(ta
->channel
, i
);
2258 ss_reply("SSMSG_REMOVED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2260 ss_reply("SSMSG_NOT_TRUSTED", hi
->handle
, argv
[2]);
2264 dict_remove(spamserv_trusted_accounts
, hi
->handle
);
2265 ss_reply("SSMSG_REMOVED_TRUSTED", hi
->handle
);
2271 static SPAMSERV_FUNC(cmd_odeltrust
)
2274 int rem
= 0, global
= 0;
2275 struct trusted_account
*ta
;
2276 struct chanInfo
*cInfo
;
2277 struct chanData
*cData
;
2278 struct handle_info
*hi
;
2280 if (!strcmp(argv
[2], "global"))
2283 if (!(channel
= GetChannel(argv
[2])) && (global
== 0)) {
2284 ss_reply("SSMSG_NOT_REGISTERED", channel
? channel
->name
: (global
? "global" : ""));
2289 cInfo
= get_chanInfo(channel
->name
);
2290 cData
= channel
->channel_info
;
2292 if (!cInfo
|| !channel
->channel_info
) {
2293 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2298 if (!(hi
= modcmd_get_handle_info(user
, argv
[1]))) {
2302 ta
= dict_find(spamserv_trusted_accounts
, hi
->handle
, NULL
);
2305 ss_reply("SSMSG_NOT_TRUSTED", argv
[2]);
2310 if (ta
->channel
->used
) {
2311 for (i
=0; i
< ta
->channel
->used
; i
++) {
2312 if (!strcmp(ta
->channel
->list
[i
], argv
[2])) {
2313 string_list_delete(ta
->channel
, i
);
2320 ss_reply("SSMSG_REMOVED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2322 ss_reply("SSMSG_NOT_TRUSTED", argv
[2]);
2326 dict_remove(spamserv_trusted_accounts
, hi
->handle
);
2327 ss_reply("SSMSG_REMOVED_TRUSTED", hi
->handle
);
2333 static SPAMSERV_FUNC(cmd_listtrust
) {
2335 struct trusted_account
*ta
;
2336 char issued
[INTERVALLEN
];
2341 if (!strcmp(argv
[1], "global")) {
2342 if (!IsHelping(user
)) {
2343 reply("SSMSG_MUST_BE_HELPING");
2348 channel
= GetChannel(argv
[1]);
2350 chan
= strdup(channel
->name
);
2352 ss_reply("SSMSG_NOT_REGISTERED", argv
[1]);
2357 reply("MSG_INVALID_CHANNEL");
2361 reply("SSMSG_TRUSTED_LIST");
2362 reply("SSMSG_TRUSTED_LIST_BAR");
2363 reply("SSMSG_TRUSTED_LIST_HEADER");
2364 reply("SSMSG_TRUSTED_LIST_BAR");
2365 for (it
= dict_first(spamserv_trusted_accounts
); it
; it
= iter_next(it
)) {
2368 if (ta
->channel
->used
) {
2369 for (i
=0; i
< ta
->channel
->used
; i
++) {
2371 if (!strcmp(ta
->channel
->list
[i
], chan
)) {
2373 intervalString(issued
, now
- ta
->issued
, user
->handle_info
);
2375 ss_reply("SSMSG_HOST_IS_TRUSTED", iter_key(it
),
2376 (ta
->issuer
? ta
->issuer
: "<unknown>"),
2377 (ta
->issued
? issued
: "some time"));
2379 } else if (!strcmp(ta
->channel
->list
[i
], "global") && (!strcmp(chan
, "global"))) {
2381 intervalString(issued
, now
- ta
->issued
, user
->handle_info
);
2383 ss_reply("SSMSG_HOST_IS_TRUSTED", iter_key(it
),
2384 (ta
->issuer
? ta
->issuer
: "<unknown>"),
2385 (ta
->issued
? issued
: 0));
2390 ss_reply("SSMSG_TRUSTED_LIST_END");
2395 to_lower(char *message
)
2397 unsigned int i
, diff
= 'a' - 'A';
2399 for(i
= 0; i
< strlen(message
); i
++)
2401 if((message
[i
] >= 'A') && (message
[i
] <= 'Z'))
2402 message
[i
] = message
[i
] + diff
;
2407 strip_mirc_codes(char *text
)
2409 // taken from xchat and modified
2410 int nc
= 0, i
= 0, col
= 0, len
= strlen(text
);
2411 static char new_str
[MAXLEN
];
2415 if((col
&& isdigit(*text
) && nc
< 2) ||
2416 (col
&& *text
== ',' && isdigit(*(text
+ 1)) && nc
< 3))
2455 is_in_exception_list(struct chanInfo
*cInfo
, char *message
)
2459 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
2460 if(strstr(message
, cInfo
->exceptions
->list
[i
]))
2467 is_in_badword_list(struct chanInfo
*cInfo
, char *message
)
2471 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
2472 if(strstr(message
, cInfo
->badwords
->list
[i
]))
2479 check_caps(struct chanInfo
*cInfo
, char *message
)
2483 if ( (c
= strlen(message
)) >= cInfo
->capsmin
) {
2485 char *s
= strdup(message
);
2492 if (i
>= cInfo
->capsmin
&& i
* 100 / c
>= cInfo
->capspercent
)
2500 check_badwords(struct chanInfo
*cInfo
, char *message
)
2502 if(spamserv_conf
.strip_mirc_codes
)
2503 message
= strip_mirc_codes(message
);
2505 /* This needs improving */
2506 if(is_in_exception_list(cInfo
, message
))
2509 if(is_in_badword_list(cInfo
, message
))
2516 check_advertising(struct chanInfo
*cInfo
, char *message
)
2520 if(spamserv_conf
.strip_mirc_codes
)
2521 message
= strip_mirc_codes(message
);
2523 if(is_in_exception_list(cInfo
, message
))
2526 while(message
[i
] != 0)
2528 if(message
[i
] == '#')
2530 char channelname
[CHANNELLEN
];
2533 if(!spamserv_conf
.adv_chan_must_exist
)
2536 /* only return 1, if the channel does exist */
2538 while((message
[i
] != 0) && (message
[i
] != ' '))
2540 channelname
[j
] = message
[i
];
2545 channelname
[j
] = '\0';
2547 if(GetChannel(channelname
))
2550 else if((message
[i
] == 'w') && (message
[i
+1] == 'w') && (message
[i
+2] == 'w') && (message
[i
+3] == '.'))
2552 else if((message
[i
] == 'h') && (message
[i
+1] == 't') && (message
[i
+2] == 't') && (message
[i
+3] == 'p') && (message
[i
+4] == ':'))
2554 else if((message
[i
] == 'f') && (message
[i
+1] == 't') && (message
[i
+2] == 'p') && ((message
[i
+3] == '.') || (message
[i
+3] == ':')))
2564 spamserv_punish(struct chanNode
*channel
, struct userNode
*user
, time_t expires
, char *reason
, int ban
)
2568 struct mod_chanmode change
;
2569 char *hostmask
= generate_hostmask(user
, GENMASK_STRICT_HOST
| GENMASK_ANY_IDENT
);
2571 sanitize_ircmask(hostmask
);
2574 add_channel_ban(channel
->channel_info
, hostmask
, spamserv
->nick
, now
, now
, now
+ expires
, reason
);
2576 mod_chanmode_init(&change
);
2578 change
.args
[0].mode
= MODE_BAN
;
2579 change
.args
[0].u
.hostmask
= hostmask
;
2580 mod_chanmode_announce(spamserv
, channel
, &change
);
2584 spamserv_debug(SSMSG_DEBUG_BAN
, user
->nick
, channel
->name
, reason
);
2587 spamserv_debug(SSMSG_DEBUG_KICK
, user
->nick
, channel
->name
, reason
);
2589 KickChannelUser(user
, channel
, spamserv
, reason
);
2593 spamserv_channel_message(struct chanNode
*channel
, struct userNode
*user
, char *text
)
2595 struct chanData
*cData
;
2596 struct chanInfo
*cInfo
;
2597 struct userInfo
*uInfo
;
2598 struct userData
*uData
;
2599 struct spamNode
*sNode
;
2600 struct floodNode
*fNode
;
2601 struct trusted_account
*ta
;
2602 unsigned int violation
= 0;
2603 char reason
[MAXLEN
];
2605 /* make sure: spamserv is not disabled; x3 is running; spamserv is in the chan; chan is regged, user does exist */
2606 if(!spamserv
|| quit_services
|| !GetUserMode(channel
, spamserv
) || IsOper(user
) || !(cInfo
= get_chanInfo(channel
->name
)) || !(uInfo
= get_userInfo(user
->nick
)))
2609 cData
= channel
->channel_info
;
2610 uData
= GetChannelUser(cData
, user
->handle_info
);
2612 if (user
->handle_info
) {
2613 ta
= dict_find(spamserv_trusted_accounts
, user
->handle_info
->handle
, NULL
);
2616 for (i
=0; i
< ta
->channel
->used
; i
++) {
2617 if (!strcmp(ta
->channel
->list
[i
], channel
->name
))
2620 if (!strcmp(ta
->channel
->list
[i
], "global"))
2627 if(uData
&& (uData
->access
>= cInfo
->exceptlevel
))
2630 if(CHECK_CAPSSCAN(cInfo
) && check_caps(cInfo
, text
))
2632 if(uData
&& (uData
->access
>= cInfo
->exceptcapslevel
))
2635 if(CHECK_CAPS_WARNED(uInfo
))
2637 switch(cInfo
->info
[ci_CapsReaction
])
2639 case 'k': uInfo
->flags
|= USER_KICK
; break;
2640 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2641 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2642 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2643 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2646 uInfo
->warnlevel
+= CAPS_WARNLEVEL
;
2651 uInfo
->flags
|= USER_CAPS_WARNED
;
2652 uInfo
->lastcaps
= now
;
2653 uInfo
->warnlevel
+= CAPS_WARNLEVEL
;
2655 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2656 if (spamserv_conf
.network_rules
)
2657 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_CAPS
, spamserv_conf
.network_rules
);
2659 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_CAPS
, spamserv_conf
.network_rules
);
2667 if(CHECK_SPAM(cInfo
))
2669 if(uData
&& (uData
->access
>= cInfo
->exceptspamlevel
))
2672 if(!(sNode
= uInfo
->spam
))
2674 spamserv_create_spamNode(channel
, uInfo
, text
);
2678 for(; sNode
; sNode
= sNode
->next
)
2679 if(sNode
->channel
== channel
)
2684 spamserv_create_spamNode(channel
, uInfo
, text
);
2688 unsigned long crc
= crc32(text
);
2690 if(crc
== sNode
->crc32
)
2692 unsigned int spamlimit
= 2;
2695 switch(cInfo
->info
[ci_SpamLimit
])
2697 case 'a': spamlimit
= 2; break;
2698 case 'b': spamlimit
= 3; break;
2699 case 'c': spamlimit
= 4; break;
2700 case 'd': spamlimit
= 5; break;
2701 case 'e': spamlimit
= 6; break;
2704 if(sNode
->count
== spamlimit
)
2706 uInfo
->warnlevel
+= SPAM_WARNLEVEL
;
2708 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2709 if (spamserv_conf
.network_rules
)
2710 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_SPAM
, spamserv_conf
.network_rules
);
2712 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_SPAM
, spamserv_conf
.network_rules
);
2715 else if(sNode
->count
> spamlimit
)
2717 switch(cInfo
->info
[ci_WarnReaction
])
2719 case 'k': uInfo
->flags
|= USER_KICK
; break;
2720 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2721 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2722 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2723 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2726 spamserv_delete_spamNode(uInfo
, sNode
);
2727 uInfo
->warnlevel
+= SPAM_WARNLEVEL
;
2740 if(CHECK_FLOOD(cInfo
))
2742 if(uData
&& (uData
->access
>= cInfo
->exceptfloodlevel
))
2745 if(!(fNode
= uInfo
->flood
))
2747 spamserv_create_floodNode(channel
, user
, &uInfo
->flood
);
2751 for(; fNode
; fNode
= fNode
->next
)
2752 if(fNode
->channel
== channel
)
2756 spamserv_create_floodNode(channel
, user
, &uInfo
->flood
);
2758 if(((now
- fNode
->time
) < FLOOD_EXPIRE
)) {
2761 if(fNode
->count
== FLOOD_MAX_LINES
- 1) {
2762 uInfo
->warnlevel
+= FLOOD_WARNLEVEL
;
2764 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2765 if (spamserv_conf
.network_rules
)
2766 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_FLOOD
, spamserv_conf
.network_rules
);
2768 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_FLOOD
, spamserv_conf
.network_rules
);
2772 else if(fNode
->count
> FLOOD_MAX_LINES
) {
2773 switch(cInfo
->info
[ci_WarnReaction
]) {
2774 case 'k': uInfo
->flags
|= USER_KICK
; break;
2775 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2776 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2777 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2778 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2781 spamserv_delete_floodNode(&uInfo
->flood
, fNode
);
2782 uInfo
->warnlevel
+= FLOOD_WARNLEVEL
;
2792 if(CHECK_BADWORDSCAN(cInfo
) && check_badwords(cInfo
, text
))
2794 if(uData
&& (uData
->access
>= cInfo
->exceptbadwordlevel
))
2797 if(CHECK_BAD_WARNED(uInfo
))
2799 switch(cInfo
->info
[ci_BadReaction
])
2801 case 'k': uInfo
->flags
|= USER_KICK
; break;
2802 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2803 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2804 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2805 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2808 uInfo
->warnlevel
+= BAD_WARNLEVEL
;
2813 uInfo
->flags
|= USER_BAD_WARNED
;
2814 uInfo
->lastbad
= now
;
2815 uInfo
->warnlevel
+= BAD_WARNLEVEL
;
2817 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2818 if (spamserv_conf
.network_rules
)
2819 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_BAD
, spamserv_conf
.network_rules
);
2821 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_BAD
, spamserv_conf
.network_rules
);
2826 if(CHECK_ADV(cInfo
) && check_advertising(cInfo
, text
))
2828 if(uData
&& (uData
->access
>= cInfo
->exceptspamlevel
))
2831 if(CHECK_ADV_WARNED(uInfo
))
2833 switch(cInfo
->info
[ci_AdvReaction
])
2835 case 'k': uInfo
->flags
|= USER_KICK
; break;
2836 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2837 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2838 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2839 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2842 uInfo
->warnlevel
+= ADV_WARNLEVEL
;
2847 uInfo
->flags
|= USER_ADV_WARNED
;
2848 uInfo
->lastadv
= now
;
2849 uInfo
->warnlevel
+= ADV_WARNLEVEL
;
2851 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2852 if (spamserv_conf
.network_rules
)
2853 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_ADV
, spamserv_conf
.network_rules
);
2855 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_ADV
, spamserv_conf
.network_rules
);
2860 if(!CHECK_WARNED(uInfo
) && !CHECK_KILL(uInfo
) && !CHECK_GLINE(uInfo
) && uInfo
->warnlevel
== MAX_WARNLEVEL
)
2862 uInfo
->flags
|= USER_WARNED
;
2863 if (spamserv_conf
.network_rules
)
2864 snprintf(reason
, sizeof(reason
), SSMSG_WARNING_RULES_2
, spamserv_conf
.network_rules
);
2866 snprintf(reason
, sizeof(reason
), SSMSG_WARNING_2
);
2867 irc_notice(spamserv
, user
->numeric
, reason
);
2868 irc_privmsg(spamserv
, user
->numeric
, reason
);
2870 else if(uInfo
->warnlevel
> MAX_WARNLEVEL
)
2872 if(CHECK_KILLED(uInfo
))
2873 uInfo
->flags
|= USER_GLINE
;
2875 uInfo
->flags
|= USER_KILL
;
2886 case 1: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_SPAM
, spamserv_conf
.network_rules
); break;
2887 case 2: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_FLOOD
, spamserv_conf
.network_rules
); break;
2888 case 3: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_ADV
, spamserv_conf
.network_rules
); break;
2889 case 4: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_BAD
, spamserv_conf
.network_rules
); break;
2890 case 5: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_CAPS
, spamserv_conf
.network_rules
); break;
2891 default: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES_2
: SSMSG_WARNING_2
, spamserv_conf
.network_rules
); break;
2894 if(CHECK_GLINE(uInfo
))
2896 int size
= strlen(user
->hostname
) + 3;
2897 char *mask
= alloca(size
);
2898 snprintf(mask
, size
, "*@%s", user
->hostname
);
2899 gline_add(spamserv
->nick
, mask
, spamserv_conf
.gline_duration
, reason
, now
, 1, 0);
2900 spamserv_debug(SSMSG_DEBUG_GLINE
, user
->nick
, user
->hostname
, channel
->name
);
2902 else if(CHECK_KILL(uInfo
))
2904 DelUser(user
, spamserv
, 1, reason
);
2905 spamserv_debug(SSMSG_DEBUG_KILL
, user
->nick
, channel
->name
);
2907 else if(CHECK_LONG_TBAN(uInfo
))
2909 spamserv_punish(channel
, user
, spamserv_conf
.long_ban_duration
, reason
, 1);
2911 else if(CHECK_SHORT_TBAN(uInfo
))
2913 spamserv_punish(channel
, user
, spamserv_conf
.short_ban_duration
, reason
, 1);
2915 else if(CHECK_KICKBAN(uInfo
))
2917 spamserv_punish(channel
, user
, 0, reason
, 1);
2919 else if(CHECK_KICK(uInfo
))
2921 spamserv_punish(channel
, user
, 0, reason
, 0);
2926 trusted_account_read(const char *account
, void *data
, UNUSED_ARG(void *extra
))
2928 struct record_data
*rd
= data
;
2929 const char *str
, *issuer
;
2930 struct string_list
*strlist
;
2933 if (rd
->type
== RECDB_OBJECT
) {
2934 dict_t obj
= GET_RECORD_OBJECT(rd
);
2935 /* new style structure */
2936 strlist
= database_get_data(obj
, KEY_CHANNELS
, RECDB_STRING_LIST
);
2937 issuer
= database_get_data(obj
, KEY_ISSUER
, RECDB_QSTRING
);
2938 str
= database_get_data(obj
, KEY_ISSUED
, RECDB_QSTRING
);
2939 issued
= str
? ParseInterval(str
) : 0;
2943 spamserv_add_trusted_account(account
, strlist
, issuer
, issued
);
2948 spamserv_saxdb_read(struct dict
*database
)
2951 struct record_data
*hir
;
2952 struct chanNode
*channel
;
2953 struct chanInfo
*cInfo
;
2954 struct string_list
*strlist
, *strlist2
;
2956 unsigned int exceptlevel
, exceptadvlevel
, exceptbadwordlevel
;
2957 unsigned int exceptfloodlevel
, exceptspamlevel
, exceptcapslevel
;
2958 unsigned int capsmin
, capspercent
;
2963 if ((object
= database_get_data(database
, KEY_TRUSTED_HOSTS
, RECDB_OBJECT
)))
2964 dict_foreach(object
, trusted_account_read
, spamserv_trusted_accounts
);
2966 for(it
= dict_first(database
); it
; it
= iter_next(it
))
2968 hir
= iter_data(it
);
2970 if(hir
->type
!= RECDB_OBJECT
)
2972 log_module(SS_LOG
, LOG_WARNING
, "Unexpected rectype %d for %s.", hir
->type
, iter_key(it
));
2976 channel
= GetChannel(iter_key(it
));
2977 if (!strcmp("trusted", iter_key(it
)))
2980 strlist
= database_get_data(hir
->d
.object
, KEY_EXCEPTIONS
, RECDB_STRING_LIST
);
2981 strlist2
= database_get_data(hir
->d
.object
, KEY_BADWORDS
, RECDB_STRING_LIST
);
2983 str
= database_get_data(hir
->d
.object
, KEY_FLAGS
, RECDB_QSTRING
);
2984 flags
= str
? atoi(str
) : 0;
2986 info
= database_get_data(hir
->d
.object
, KEY_INFO
, RECDB_QSTRING
);
2988 str
= database_get_data(hir
->d
.object
, KEY_EXPIRY
, RECDB_QSTRING
);
2989 expiry
= str
? strtoul(str
, NULL
, 0) : 0;
2991 str
= database_get_data(hir
->d
.object
, KEY_CAPSMIN
, RECDB_QSTRING
);
2992 capsmin
= str
? strtoul(str
, NULL
, 0) : 10;
2994 str
= database_get_data(hir
->d
.object
, KEY_CAPSPERCENT
, RECDB_QSTRING
);
2995 capspercent
= str
? strtoul(str
, NULL
, 0) : 25;
2997 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTLEVEL
, RECDB_QSTRING
);
2998 exceptlevel
= str
? strtoul(str
, NULL
, 0) : UL_MANAGER
;
3000 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTADVLEVEL
, RECDB_QSTRING
);
3001 exceptadvlevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
3003 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTBADWORDLEVEL
, RECDB_QSTRING
);
3004 exceptbadwordlevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
3006 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTCAPSLEVEL
, RECDB_QSTRING
);
3007 exceptcapslevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
3009 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTFLOODLEVEL
, RECDB_QSTRING
);
3010 exceptfloodlevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
3012 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTSPAMLEVEL
, RECDB_QSTRING
);
3013 exceptspamlevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
3017 if((cInfo
= spamserv_register_channel(channel
, strlist
, strlist2
, flags
, info
)))
3019 /* if the channel is suspended and expiry = 0 it means: channel will
3020 never expire ! it does NOT mean, the channel is not suspended */
3021 if(CHECK_SUSPENDED(cInfo
) && expiry
&& (expiry
< now
))
3023 cInfo
->flags
&= ~CHAN_SUSPENDED
;
3024 spamserv_join_channel(cInfo
->channel
);
3026 else if(!CHECK_SUSPENDED(cInfo
))
3027 spamserv_join_channel(cInfo
->channel
);
3029 cInfo
->suspend_expiry
= expiry
;
3031 cInfo
->capsmin
= capsmin
;
3032 cInfo
->capspercent
= capspercent
;
3033 cInfo
->exceptlevel
= exceptlevel
;
3034 cInfo
->exceptadvlevel
= exceptadvlevel
;
3035 cInfo
->exceptbadwordlevel
= exceptbadwordlevel
;
3036 cInfo
->exceptcapslevel
= exceptcapslevel
;
3037 cInfo
->exceptfloodlevel
= exceptfloodlevel
;
3038 cInfo
->exceptspamlevel
= exceptspamlevel
;
3042 log_module(SS_LOG
, LOG_ERROR
, "Couldn't register channel %s. Channel or info invalid.", iter_key(it
));
3049 spamserv_saxdb_write(struct saxdb_context
*ctx
)
3053 if (dict_size(spamserv_trusted_accounts
)) {
3054 saxdb_start_record(ctx
, KEY_TRUSTED_ACCOUNTS
, 1);
3055 for (it
= dict_first(spamserv_trusted_accounts
); it
; it
= iter_next(it
)) {
3056 struct trusted_account
*ta
= iter_data(it
);
3057 saxdb_start_record(ctx
, iter_key(it
), 0);
3058 if (ta
->channel
) saxdb_write_string_list(ctx
, KEY_CHANNELS
, ta
->channel
);
3059 if (ta
->issued
) saxdb_write_int(ctx
, KEY_ISSUED
, ta
->issued
);
3060 if (ta
->issuer
) saxdb_write_string(ctx
, KEY_ISSUER
, ta
->issuer
);
3061 saxdb_end_record(ctx
);
3063 saxdb_end_record(ctx
);
3066 for(it
= dict_first(registered_channels_dict
); it
; it
= iter_next(it
))
3068 struct chanInfo
*cInfo
= iter_data(it
);
3070 saxdb_start_record(ctx
, cInfo
->channel
->name
, 1);
3072 if(cInfo
->exceptions
->used
)
3073 saxdb_write_string_list(ctx
, KEY_EXCEPTIONS
, cInfo
->exceptions
);
3075 if(cInfo
->badwords
->used
)
3076 saxdb_write_string_list(ctx
, KEY_BADWORDS
, cInfo
->badwords
);
3079 saxdb_write_int(ctx
, KEY_FLAGS
, cInfo
->flags
);
3082 saxdb_write_int(ctx
, KEY_CAPSMIN
, cInfo
->capsmin
);
3084 if(cInfo
->capspercent
)
3085 saxdb_write_int(ctx
, KEY_CAPSPERCENT
, cInfo
->capspercent
);
3087 if(cInfo
->exceptlevel
)
3088 saxdb_write_int(ctx
, KEY_EXCEPTLEVEL
, cInfo
->exceptlevel
);
3090 if(cInfo
->exceptadvlevel
)
3091 saxdb_write_int(ctx
, KEY_EXCEPTADVLEVEL
, cInfo
->exceptadvlevel
);
3093 if(cInfo
->exceptbadwordlevel
)
3094 saxdb_write_int(ctx
, KEY_EXCEPTBADWORDLEVEL
, cInfo
->exceptbadwordlevel
);
3096 if(cInfo
->exceptcapslevel
)
3097 saxdb_write_int(ctx
, KEY_EXCEPTCAPSLEVEL
, cInfo
->exceptcapslevel
);
3099 if(cInfo
->exceptfloodlevel
)
3100 saxdb_write_int(ctx
, KEY_EXCEPTFLOODLEVEL
, cInfo
->exceptfloodlevel
);
3102 if(cInfo
->exceptspamlevel
)
3103 saxdb_write_int(ctx
, KEY_EXCEPTSPAMLEVEL
, cInfo
->exceptspamlevel
);
3105 saxdb_write_string(ctx
, KEY_INFO
, cInfo
->info
);
3107 if(cInfo
->suspend_expiry
)
3108 saxdb_write_int(ctx
, KEY_EXPIRY
, cInfo
->suspend_expiry
);
3110 saxdb_end_record(ctx
);
3116 spamserv_conf_read(void)
3121 if(!(conf_node
= conf_get_data(SPAMSERV_CONF_NAME
, RECDB_OBJECT
)))
3123 log_module(SS_LOG
, LOG_ERROR
, "config node `%s' is missing or has wrong type.", SPAMSERV_CONF_NAME
);
3127 str
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL
, RECDB_QSTRING
);
3131 spamserv_conf
.debug_channel
= AddChannel(str
, now
, "+tinms", NULL
, NULL
);
3133 if(spamserv_conf
.debug_channel
)
3134 spamserv_join_channel(spamserv_conf
.debug_channel
);
3138 spamserv_conf
.debug_channel
= NULL
;
3141 spamserv_conf
.global_exceptions
= database_get_data(conf_node
, KEY_GLOBAL_EXCEPTIONS
, RECDB_STRING_LIST
);
3143 spamserv_conf
.global_badwords
= database_get_data(conf_node
, KEY_GLOBAL_BADWORDS
, RECDB_STRING_LIST
);
3145 str
= database_get_data(conf_node
, KEY_NETWORK_RULES
, RECDB_QSTRING
);
3146 spamserv_conf
.network_rules
= str
? str
: NULL
;
3148 str
= database_get_data(conf_node
, KEY_TRIGGER
, RECDB_QSTRING
);
3149 spamserv_conf
.trigger
= str
? str
[0] : 0;
3151 str
= database_get_data(conf_node
, KEY_SHORT_BAN_DURATION
, RECDB_QSTRING
);
3152 spamserv_conf
.short_ban_duration
= str
? ParseInterval(str
) : ParseInterval("15m");
3154 str
= database_get_data(conf_node
, KEY_LONG_BAN_DURATION
, RECDB_QSTRING
);
3155 spamserv_conf
.long_ban_duration
= str
? ParseInterval(str
) : ParseInterval("1h");
3157 str
= database_get_data(conf_node
, KEY_GLINE_DURATION
, RECDB_QSTRING
);
3158 spamserv_conf
.gline_duration
= str
? ParseInterval(str
) : ParseInterval("1h");
3160 str
= database_get_data(conf_node
, KEY_EXCEPTION_MAX
, RECDB_QSTRING
);
3161 spamserv_conf
.exception_max
= str
? strtoul(str
, NULL
, 0) : 10;
3163 str
= database_get_data(conf_node
, KEY_EXCEPTION_MIN_LEN
, RECDB_QSTRING
);
3164 spamserv_conf
.exception_min_len
= str
? strtoul(str
, NULL
, 0) : 4;
3166 str
= database_get_data(conf_node
, KEY_EXCEPTION_MAX_LEN
, RECDB_QSTRING
);
3167 spamserv_conf
.exception_max_len
= str
? strtoul(str
, NULL
, 0) : 15;
3169 str
= database_get_data(conf_node
, KEY_BADWORD_MAX
, RECDB_QSTRING
);
3170 spamserv_conf
.badword_max
= str
? strtoul(str
, NULL
, 0) : 10;
3172 str
= database_get_data(conf_node
, KEY_BADWORD_MIN_LEN
, RECDB_QSTRING
);
3173 spamserv_conf
.badword_min_len
= str
? strtoul(str
, NULL
, 0) : 4;
3175 str
= database_get_data(conf_node
, KEY_BADWORD_MAX_LEN
, RECDB_QSTRING
);
3176 spamserv_conf
.badword_max_len
= str
? strtoul(str
, NULL
, 0) : 15;
3178 str
= database_get_data(conf_node
, KEY_ADV_CHAN_MUST_EXIST
, RECDB_QSTRING
);
3179 spamserv_conf
.adv_chan_must_exist
= str
? enabled_string(str
) : 1;
3181 str
= database_get_data(conf_node
, KEY_STRIP_MIRC_CODES
, RECDB_QSTRING
);
3182 spamserv_conf
.strip_mirc_codes
= str
? enabled_string(str
) : 0;
3184 str
= database_get_data(conf_node
, KEY_ALLOW_MOVE_MERGE
, RECDB_QSTRING
);
3185 spamserv_conf
.allow_move_merge
= str
? enabled_string(str
) : 0;
3189 spamserv_db_cleanup(void)
3193 while((it
= dict_first(registered_channels_dict
)))
3195 spamserv_unregister_channel(iter_data(it
));
3198 /* now handled automatically
3199 * while((it = dict_first(killed_users_dict)))
3201 free(iter_data(it));
3205 dict_delete(registered_channels_dict
);
3206 dict_delete(connected_users_dict
);
3207 dict_delete(killed_users_dict
);
3208 dict_delete(spamserv_trusted_accounts
);
3212 init_spamserv(const char *nick
)
3214 struct chanNode
*chan
;
3220 const char *modes
= conf_get_data("services/spamserv/modes", RECDB_QSTRING
);
3221 spamserv
= AddService(nick
, modes
? modes
: NULL
, "Anti Spam Services", NULL
);
3222 spamserv_service
= service_register(spamserv
);
3224 conf_register_reload(spamserv_conf_read
);
3226 SS_LOG
= log_register_type("SpamServ", "file:spamserv.log");
3228 /* auto-free the keys for these dicts,
3229 * and auto-free the keys AND data for killed_users_dict.
3230 * other data need free'd manually. */
3231 registered_channels_dict
= dict_new();
3232 dict_set_free_keys(registered_channels_dict
, free
);
3233 connected_users_dict
= dict_new();
3234 dict_set_free_keys(connected_users_dict
, free
);
3235 killed_users_dict
= dict_new();
3236 dict_set_free_keys(killed_users_dict
, free
);
3237 dict_set_free_data(killed_users_dict
, free
);
3238 spamserv_trusted_accounts
= dict_new();
3239 dict_set_free_keys(spamserv_trusted_accounts
, free
);
3240 dict_set_free_data(spamserv_trusted_accounts
, free
);
3242 saxdb_register("SpamServ", spamserv_saxdb_read
, spamserv_saxdb_write
);
3244 reg_new_user_func(spamserv_new_user_func
);
3245 reg_del_user_func(spamserv_del_user_func
);
3246 reg_nick_change_func(spamserv_nick_change_func
);
3247 reg_join_func(spamserv_user_join
);
3248 reg_part_func(spamserv_user_part
);
3250 timeq_add(now
+ FLOOD_TIMEQ_FREQ
, timeq_flood
, NULL
);
3251 timeq_add(now
+ JOINFLOOD_TIMEQ_FREQ
, timeq_joinflood
, NULL
);
3252 timeq_add(now
+ ADV_TIMEQ_FREQ
, timeq_adv
, NULL
);
3253 timeq_add(now
+ BAD_TIMEQ_FREQ
, timeq_bad
, NULL
);
3254 timeq_add(now
+ CAPS_TIMEQ_FREQ
, timeq_caps
, NULL
);
3255 timeq_add(now
+ WARNLEVEL_TIMEQ_FREQ
, timeq_warnlevel
, NULL
);
3256 timeq_add(now
+ KILL_TIMEQ_FREQ
, timeq_kill
, NULL
);
3258 spamserv_module
= module_register("SpamServ", SS_LOG
, "spamserv.help", NULL
);
3260 modcmd_register(spamserv_module
, "ADDTRUST", cmd_addtrust
, 3, MODCMD_REQUIRE_AUTHED
, "flags", "+acceptchan", NULL
);
3261 modcmd_register(spamserv_module
, "DELTRUST", cmd_deltrust
, 3, MODCMD_REQUIRE_AUTHED
, "flags", "+acceptchan", NULL
);
3262 modcmd_register(spamserv_module
, "OADDTRUST", cmd_oaddtrust
, 3, MODCMD_REQUIRE_AUTHED
, "flags", "+acceptchan,+helping", NULL
);
3263 modcmd_register(spamserv_module
, "ODELTRUST", cmd_odeltrust
, 3, MODCMD_REQUIRE_AUTHED
, "flags", "+acceptchan,+helping", NULL
);
3264 modcmd_register(spamserv_module
, "LISTTRUST", cmd_listtrust
, 2, MODCMD_REQUIRE_AUTHED
, NULL
);
3265 modcmd_register(spamserv_module
, "REGISTER", cmd_register
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, "flags", "+acceptchan,+helping", NULL
);
3266 modcmd_register(spamserv_module
, "UNREGISTER", cmd_unregister
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, "flags", "+loghostmask", NULL
);
3267 modcmd_register(spamserv_module
, "ADDEXCEPTION", cmd_addexception
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3268 modcmd_register(spamserv_module
, "DELEXCEPTION", cmd_delexception
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3269 modcmd_register(spamserv_module
, "ADDBADWORD", cmd_addbadword
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3270 modcmd_register(spamserv_module
, "DELBADWORD", cmd_delbadword
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3271 modcmd_register(spamserv_module
, "STATUS", cmd_status
, 1, 0, NULL
);
3272 modcmd_register(spamserv_module
, "SET", cmd_set
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3273 modcmd_register(spamserv_module
, "SET EXCEPTLEVEL", opt_exceptlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3274 modcmd_register(spamserv_module
, "SET EXCEPTADVLEVEL", opt_exceptadvlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3275 modcmd_register(spamserv_module
, "SET EXCEPTBADWORDLEVEL", opt_exceptbadwordlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3276 modcmd_register(spamserv_module
, "SET EXCEPTCAPSLEVEL", opt_exceptcapslevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3277 modcmd_register(spamserv_module
, "SET EXCEPTFLOODLEVEL", opt_exceptfloodlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3278 modcmd_register(spamserv_module
, "SET EXCEPTSPAMLEVEL", opt_exceptspamlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3279 modcmd_register(spamserv_module
, "SET SPAMLIMIT", opt_spamlimit
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3280 modcmd_register(spamserv_module
, "SET BADREACTION", opt_badreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3281 modcmd_register(spamserv_module
, "SET CAPSREACTION", opt_capsreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3282 modcmd_register(spamserv_module
, "SET ADVREACTION", opt_advreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3283 modcmd_register(spamserv_module
, "SET WARNREACTION", opt_warnreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3284 modcmd_register(spamserv_module
, "SET ADVSCAN", opt_advscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3285 modcmd_register(spamserv_module
, "SET CAPSSCAN", opt_capsscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3286 modcmd_register(spamserv_module
, "SET BADWORDSCAN", opt_badwordscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3287 modcmd_register(spamserv_module
, "SET SPAMSCAN", opt_spamscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3288 modcmd_register(spamserv_module
, "SET CHANFLOODSCAN", opt_chanfloodscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3289 modcmd_register(spamserv_module
, "SET JOINFLOODSCAN", opt_joinflood
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3290 modcmd_register(spamserv_module
, "SET CAPSMIN", opt_capsmin
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3291 modcmd_register(spamserv_module
, "SET CAPSPERCENT", opt_capspercent
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3293 spamserv_service
->trigger
= spamserv_conf
.trigger
;
3296 if (autojoin_channels
&& spamserv
) {
3297 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
3298 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
3299 AddChannelUser(spamserv
, chan
)->modes
|= MODE_CHANOP
;
3303 reg_exit_func(spamserv_db_cleanup
);
3304 message_register_table(msgtab
);