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;
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
= NULL
;
576 kNode
= dict_find(killed_users_dict
, irc_ntoa(&user
->ip
), 0);
580 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for uInfo; nick: %s", user
->nick
);
585 spamserv_debug(SSMSG_DEBUG_RECONNECT
, user
->nick
);
590 uInfo
->joinflood
= NULL
;
591 uInfo
->flags
= kNode
? USER_KILLED
: 0;
592 uInfo
->warnlevel
= kNode
? kNode
->warnlevel
: 0;
597 dict_insert(connected_users_dict
, strdup(user
->nick
), uInfo
);
602 dict_remove(killed_users_dict
, irc_ntoa(&user
->ip
));
607 spamserv_delete_user(struct userInfo
*uInfo
)
614 spamserv_delete_spamNode(uInfo
, uInfo
->spam
);
618 spamserv_delete_floodNode(&uInfo
->flood
, uInfo
->flood
);
621 while(uInfo
->joinflood
)
622 spamserv_delete_floodNode(&uInfo
->joinflood
, uInfo
->joinflood
);
624 dict_remove(connected_users_dict
, uInfo
->user
->nick
);
629 spamserv_new_user_func(struct userNode
*user
)
632 spamserv_create_user(user
);
638 spamserv_del_user_func(struct userNode
*user
, struct userNode
*killer
, UNUSED_ARG(const char *why
))
640 struct userInfo
*uInfo
= get_userInfo(user
->nick
);
641 struct killNode
*kNode
;
643 if(killer
== spamserv
)
645 kNode
= malloc(sizeof(struct killNode
));
649 log_module(SS_LOG
, LOG_ERROR
, "Couldn't allocate memory for killNode - nickname %s", user
->nick
);
650 spamserv_delete_user(uInfo
);
654 if(uInfo
->warnlevel
> KILL_WARNLEVEL
)
655 kNode
->warnlevel
= uInfo
->warnlevel
- KILL_WARNLEVEL
;
657 kNode
->warnlevel
= 0;
661 dict_insert(killed_users_dict
, strdup(irc_ntoa(&user
->ip
)), kNode
);
664 spamserv_delete_user(uInfo
);
668 spamserv_nick_change_func(struct userNode
*user
, const char *old_nick
)
670 struct userInfo
*uInfo
= get_userInfo(old_nick
);
673 dict_remove(connected_users_dict
, old_nick
);
674 dict_insert(connected_users_dict
, strdup(user
->nick
), uInfo
);
679 spamserv_user_join(struct modeNode
*mNode
)
681 struct chanNode
*channel
= mNode
->channel
;
682 struct userNode
*user
= mNode
->user
;
683 struct chanInfo
*cInfo
;
684 struct userInfo
*uInfo
;
685 struct floodNode
*jfNode
;
687 if(user
->uplink
->burst
|| !(cInfo
= get_chanInfo(channel
->name
)) || !CHECK_JOINFLOOD(cInfo
) || !(uInfo
= get_userInfo(user
->nick
)))
690 if(!(jfNode
= uInfo
->joinflood
))
692 spamserv_create_floodNode(channel
, user
, &uInfo
->joinflood
);
696 for(; jfNode
; jfNode
= jfNode
->next
)
697 if(jfNode
->channel
== channel
)
702 spamserv_create_floodNode(channel
, user
, &uInfo
->joinflood
);
709 if(jfNode
->count
> JOINFLOOD_MAX
)
713 spamserv_delete_floodNode(&uInfo
->joinflood
, jfNode
);
714 snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_JOINFLOOD
, spamserv_conf
.network_rules
);
715 spamserv_punish(channel
, user
, JOINFLOOD_B_DURATION
, reason
, 1);
724 spamserv_user_part(struct modeNode
*mn
, UNUSED_ARG(const char *reason
))
726 struct userNode
*user
= mn
->user
;
727 struct chanNode
*channel
= mn
->channel
;
728 struct userInfo
*uInfo
;
729 struct spamNode
*sNode
;
730 struct floodNode
*fNode
;
732 if(user
->dead
|| !get_chanInfo(channel
->name
) || !(uInfo
= get_userInfo(user
->nick
)))
735 if((sNode
= uInfo
->spam
))
737 for(; sNode
; sNode
= sNode
->next
)
738 if(sNode
->channel
== channel
)
742 spamserv_delete_spamNode(uInfo
, sNode
);
745 if((fNode
= uInfo
->flood
))
747 for(; fNode
; fNode
= fNode
->next
)
748 if(fNode
->channel
== channel
)
752 spamserv_delete_floodNode(&uInfo
->flood
, fNode
);
756 /***********************************************/
758 /***********************************************/
766 for(i
= 0; i
< 256; i
++)
770 for(j
= 8; j
> 0; j
--)
774 crc
= (crc
>> 1) ^ 0xEDB88320L
;
787 crc32(const char *text
)
789 register unsigned long crc
= 0xFFFFFFFF;
790 unsigned int c
, i
= 0;
792 while((c
= (unsigned int)text
[i
++]) != 0)
793 crc
= ((crc
>> 8) & 0x00FFFFFF) ^ crc_table
[(crc
^c
) & 0xFF];
795 return (crc
^0xFFFFFFFF);
799 timeq_flood(UNUSED_ARG(void *data
))
802 struct userInfo
*uInfo
;
803 struct floodNode
*fNode
;
805 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
807 uInfo
= iter_data(it
);
812 if(!(fNode
= uInfo
->flood
))
815 for(; fNode
; fNode
= fNode
->next
)
817 if(now
- fNode
->time
> FLOOD_EXPIRE
)
819 if(!(--fNode
->count
))
820 spamserv_delete_floodNode(&uInfo
->flood
, fNode
);
825 timeq_add(now
+ FLOOD_TIMEQ_FREQ
, timeq_flood
, NULL
);
829 timeq_joinflood(UNUSED_ARG(void *data
))
832 struct userInfo
*uInfo
;
833 struct floodNode
*fNode
, *nextnode
;
835 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
837 uInfo
= iter_data(it
);
839 if(!(fNode
= uInfo
->joinflood
))
842 for(; fNode
; fNode
= nextnode
)
844 nextnode
= fNode
->next
;
845 if(now
- fNode
->time
> JOINFLOOD_EXPIRE
)
847 if(!(--fNode
->count
))
848 spamserv_delete_floodNode(&uInfo
->joinflood
, fNode
);
853 timeq_add(now
+ JOINFLOOD_TIMEQ_FREQ
, timeq_joinflood
, NULL
);
857 timeq_bad(UNUSED_ARG(void *data
))
860 struct userInfo
*uInfo
;
862 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
864 uInfo
= iter_data(it
);
866 if(uInfo
->lastbad
&& uInfo
->lastbad
- now
> BAD_EXPIRE
)
869 uInfo
->flags
&= ~USER_BAD_WARNED
;
873 timeq_add(now
+ BAD_TIMEQ_FREQ
, timeq_bad
, NULL
);
877 timeq_caps(UNUSED_ARG(void *data
))
880 struct userInfo
*uInfo
;
882 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
884 uInfo
= iter_data(it
);
886 if(uInfo
->lastcaps
&& uInfo
->lastcaps
- now
> CAPS_EXPIRE
)
889 uInfo
->flags
&= ~USER_CAPS_WARNED
;
893 timeq_add(now
+ CAPS_TIMEQ_FREQ
, timeq_caps
, NULL
);
897 timeq_adv(UNUSED_ARG(void *data
))
900 struct userInfo
*uInfo
;
902 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
904 uInfo
= iter_data(it
);
906 if(uInfo
->lastadv
&& uInfo
->lastadv
- now
> ADV_EXPIRE
)
909 uInfo
->flags
&= ~USER_ADV_WARNED
;
913 timeq_add(now
+ ADV_TIMEQ_FREQ
, timeq_adv
, NULL
);
917 timeq_warnlevel(UNUSED_ARG(void *data
))
920 struct userInfo
*uInfo
;
922 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
924 uInfo
= iter_data(it
);
926 if(uInfo
->warnlevel
> 0)
930 timeq_add(now
+ WARNLEVEL_TIMEQ_FREQ
, timeq_warnlevel
, NULL
);
934 timeq_kill(UNUSED_ARG(void *data
))
937 struct killNode
*kNode
;
940 for(it
= dict_first(killed_users_dict
); it
; it
= iter_next(it
))
942 kNode
= iter_data(it
);
944 if(now
- kNode
->time
> KILL_EXPIRE
) {
945 dict_remove(killed_users_dict
, iter_key(it
));
946 /* have to restart the loop because next is
947 * now invalid. FIXME: how could we do this better? */
948 break; /* out of for() loop */
951 /* no more killed_users to delete, so stop while loop */
952 break; /* out of while() loop */
955 timeq_add(now
+ KILL_TIMEQ_FREQ
, timeq_kill
, NULL
);
959 binary_option(char *name
, unsigned long mask
, struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[])
961 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
966 if(enabled_string(argv
[1]))
968 cInfo
->flags
|= mask
;
971 else if(disabled_string(argv
[1]))
973 cInfo
->flags
&= ~mask
;
978 spamserv_notice(user
, "SSMSG_INVALID_BINARY", argv
[1]);
984 value
= (cInfo
->flags
& mask
) ? 1 : 0;
987 spamserv_notice(user
, "SSMSG_STRING_VALUE", name
, value
? "Enabled." : "Disabled.");
999 multiple_option(char *name
, char *description
, enum channelinfo info
, struct valueData
*values
, int count
, struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[])
1001 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1006 index
= atoi(argv
[1]);
1008 if(index
< 0 || index
>= count
)
1010 spamserv_notice(user
, "SSMSG_INVALID_NUM_SET", index
, description
);
1012 for(index
= 0; index
< count
; index
++)
1013 spamserv_notice(user
, "SSMSG_NUMERIC_VALUE", name
, index
, values
[index
].description
);
1018 if(values
[index
].oper_only
&& !IsOper(user
))
1020 spamserv_notice(user
, "SSMSG_MUST_BE_OPER");
1024 cInfo
->info
[info
] = values
[index
].value
;
1028 for(index
= 0; index
< count
&& cInfo
->info
[info
] != values
[index
].value
; index
++);
1031 spamserv_notice(user
, "SSMSG_NUMERIC_VALUE", name
, index
, values
[index
].description
);
1036 show_exceptions(struct userNode
*user
, struct chanInfo
*cInfo
)
1038 struct helpfile_table table
;
1041 if(!cInfo
->exceptions
->used
)
1043 spamserv_notice(user
, "SSMSG_NO_EXCEPTIONS");
1047 spamserv_notice(user
, "SSMSG_EXCEPTION_LIST");
1051 table
.flags
= TABLE_REPEAT_ROWS
| TABLE_NO_FREE
| TABLE_NO_HEADERS
;
1052 table
.contents
= alloca(cInfo
->exceptions
->used
* sizeof(*table
.contents
));
1054 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1056 table
.contents
[table
.length
] = alloca(table
.width
* sizeof(**table
.contents
));
1057 table
.contents
[table
.length
][0] = cInfo
->exceptions
->list
[i
];
1061 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
1067 show_badwords(struct userNode
*user
, struct chanInfo
*cInfo
)
1069 struct helpfile_table table
;
1072 if(!cInfo
->badwords
->used
)
1074 spamserv_notice(user
, "SSMSG_NO_BADWORDS");
1078 spamserv_notice(user
, "SSMSG_BADWORD_LIST");
1082 table
.flags
= TABLE_REPEAT_ROWS
| TABLE_NO_FREE
| TABLE_NO_HEADERS
;
1083 table
.contents
= alloca(cInfo
->badwords
->used
* sizeof(*table
.contents
));
1085 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1087 table
.contents
[table
.length
] = alloca(table
.width
* sizeof(**table
.contents
));
1088 table
.contents
[table
.length
][0] = cInfo
->badwords
->list
[i
];
1092 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
1098 show_memory_usage(struct userNode
*user
)
1101 struct helpfile_table table
;
1102 struct chanInfo
*cInfo
;
1103 struct userInfo
*uInfo
;
1104 struct spamNode
*sNode
;
1105 struct floodNode
*fNode
;
1106 double channel_size
= 0, user_size
, size
;
1107 unsigned int spamcount
= 0, floodcount
= 0, i
, j
;
1110 for(it
= dict_first(registered_channels_dict
); it
; it
= iter_next(it
))
1112 cInfo
= iter_data(it
);
1114 if(!cInfo
->exceptions
->used
)
1117 if(!cInfo
->badwords
->used
)
1120 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1121 channel_size
+= strlen(cInfo
->exceptions
->list
[i
]) * sizeof(char);
1123 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1124 channel_size
+= strlen(cInfo
->badwords
->list
[i
]) * sizeof(char);
1127 for(it
= dict_first(connected_users_dict
); it
; it
= iter_next(it
))
1129 uInfo
= iter_data(it
);
1131 for(sNode
= uInfo
->spam
; sNode
; sNode
= sNode
->next
, spamcount
++);
1132 for(fNode
= uInfo
->flood
; fNode
; fNode
= fNode
->next
, floodcount
++);
1133 for(fNode
= uInfo
->joinflood
; fNode
; fNode
= fNode
->next
, floodcount
++);
1136 channel_size
+= dict_size(registered_channels_dict
) * sizeof(struct chanInfo
);
1138 user_size
= dict_size(connected_users_dict
) * sizeof(struct userInfo
) +
1139 dict_size(killed_users_dict
) * sizeof(struct killNode
) +
1140 spamcount
* sizeof(struct spamNode
) +
1141 floodcount
* sizeof(struct floodNode
);
1143 size
= channel_size
+ user_size
;
1145 ss_reply("SSMSG_STATUS_MEMORY");
1149 table
.flags
= TABLE_NO_FREE
| TABLE_NO_HEADERS
| TABLE_PAD_LEFT
;
1150 table
.contents
= calloc(table
.length
, sizeof(char**));
1153 table
.contents
[0] = calloc(table
.width
, sizeof(char*));
1154 snprintf(buffer
, sizeof(buffer
), "Channel Memory Usage:");
1155 table
.contents
[0][0] = strdup(buffer
);
1156 snprintf(buffer
, sizeof(buffer
), " %g Byte; ", channel_size
);
1157 table
.contents
[0][1] = strdup(buffer
);
1158 snprintf(buffer
, sizeof(buffer
), "%g KiloByte; ", channel_size
/ 1024);
1159 table
.contents
[0][2] = strdup(buffer
);
1160 snprintf(buffer
, sizeof(buffer
), "%g MegaByte", channel_size
/ 1024 / 1024);
1161 table
.contents
[0][3] = strdup(buffer
);
1164 table
.contents
[1] = calloc(table
.width
, sizeof(char*));
1165 snprintf(buffer
, sizeof(buffer
), "User Memory Usage :");
1166 table
.contents
[1][0] = strdup(buffer
);
1167 snprintf(buffer
, sizeof(buffer
), " %g Byte; ", user_size
);
1168 table
.contents
[1][1] = strdup(buffer
);
1169 snprintf(buffer
, sizeof(buffer
), "%g KiloByte; ", user_size
/ 1024);
1170 table
.contents
[1][2] = strdup(buffer
);
1171 snprintf(buffer
, sizeof(buffer
), "%g MegaByte", user_size
/ 1024 / 1024);
1172 table
.contents
[1][3] = strdup(buffer
);
1174 // total memory usage
1175 table
.contents
[2] = calloc(table
.width
, sizeof(char*));
1176 snprintf(buffer
, sizeof(buffer
), "Total Memory Usage :");
1177 table
.contents
[2][0] = strdup(buffer
);
1178 snprintf(buffer
, sizeof(buffer
), " %g Byte; ", size
);
1179 table
.contents
[2][1] = strdup(buffer
);
1180 snprintf(buffer
, sizeof(buffer
), "%g KiloByte; ", size
/ 1024);
1181 table
.contents
[2][2] = strdup(buffer
);
1182 snprintf(buffer
, sizeof(buffer
), "%g MegaByte", size
/ 1024 / 1024);
1183 table
.contents
[2][3] = strdup(buffer
);
1185 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
1187 for(i
= 0; i
< table
.length
; i
++)
1189 for(j
= 0; j
< table
.width
; j
++)
1190 free((char*)table
.contents
[i
][j
]);
1192 free(table
.contents
[i
]);
1195 free(table
.contents
);
1199 show_registered_channels(struct userNode
*user
)
1201 struct helpfile_table table
;
1204 spamserv_notice(user
, "SSMSG_STATUS_CHANNEL_LIST");
1206 if(!dict_size(registered_channels_dict
))
1208 spamserv_notice(user
, "SSMSG_STATUS_NO_CHANNEL");
1214 table
.flags
= TABLE_REPEAT_ROWS
| TABLE_NO_FREE
| TABLE_NO_HEADERS
;
1215 table
.contents
= alloca(dict_size(registered_channels_dict
) * sizeof(*table
.contents
));
1217 for(it
= dict_first(registered_channels_dict
); it
; it
= iter_next(it
))
1219 struct chanInfo
*cInfo
= iter_data(it
);
1221 table
.contents
[table
.length
] = alloca(table
.width
* sizeof(**table
.contents
));
1222 table
.contents
[table
.length
][0] = cInfo
->channel
->name
;
1226 table_send(spamserv
, user
->nick
, 0, NULL
, table
);
1229 /***********************************************/
1231 /***********************************************/
1234 SPAMSERV_FUNC(cmd_register
)
1236 struct chanInfo
*cInfo
;
1238 if(!channel
|| !channel
->channel_info
)
1240 ss_reply("SSMSG_NOT_REGISTERED_CS", channel
->name
);
1244 if(get_chanInfo(channel
->name
))
1246 ss_reply("SSMSG_ALREADY_REGISTERED", channel
->name
);
1250 if(IsSuspended(channel
->channel_info
))
1252 ss_reply("SSMSG_SUSPENDED_CS", channel
->name
, "register");
1256 if(channel
== spamserv_conf
.debug_channel
)
1258 ss_reply("SSMSG_DEBUG_CHAN");
1262 if(!(cInfo
= spamserv_register_channel(channel
, spamserv_conf
.global_exceptions
, spamserv_conf
.global_badwords
, CHAN_FLAGS_DEFAULT
, CHAN_INFO_DEFAULT
)))
1264 ss_reply("SSMSG_NO_REGISTER", channel
->name
);
1268 spamserv_join_channel(cInfo
->channel
);
1270 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, "SSMSG_REGISTERED_BY",
1271 channel
->name
, user
->handle_info
->handle
);
1272 ss_reply("SSMSG_REG_SUCCESS", channel
->name
);
1278 SPAMSERV_FUNC(cmd_unregister
)
1280 struct chanInfo
*cInfo
;
1281 struct chanData
*cData
;
1282 struct userData
*uData
;
1283 char reason
[MAXLEN
];
1285 if(!channel
|| !(cData
= channel
->channel_info
) || !(cInfo
= get_chanInfo(channel
->name
)))
1287 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1291 if(!(uData
= GetChannelUser(cData
, user
->handle_info
)) || (uData
->access
< UL_OWNER
))
1293 ss_reply("SSMSG_NO_ACCESS");
1297 if(!IsHelping(user
))
1299 if(IsSuspended(cData
))
1301 ss_reply("SSMSG_SUSPENDED_CS", channel
->name
, "unregister");
1305 if(argc
< 2 || strcasecmp(argv
[1], "CONFIRM"))
1307 ss_reply("SSMSG_CONFIRM_UNREG");
1312 if(!CHECK_SUSPENDED(cInfo
))
1314 snprintf(reason
, sizeof(reason
), "%s unregistered by %s.", spamserv
->nick
, user
->handle_info
->handle
);
1315 spamserv_part_channel(channel
, reason
);
1318 spamserv_unregister_channel(cInfo
);
1320 global_message_args(MESSAGE_RECIPIENT_OPERS
| MESSAGE_RECIPIENT_HELPERS
, "SSMSG_UNREGISTERED_BY",
1321 channel
->name
, user
->handle_info
->handle
);
1322 ss_reply("SSMSG_UNREG_SUCCESS", channel
->name
);
1328 SPAMSERV_FUNC(cmd_status
)
1330 ss_reply("SSMSG_STATUS");
1331 ss_reply("SSMSG_STATUS_USERS", dict_size(connected_users_dict
));
1332 ss_reply("SSMSG_STATUS_CHANNELS", dict_size(registered_channels_dict
));
1334 if(IsOper(user
) && argc
> 1)
1336 if(!irccasecmp(argv
[1], "memory"))
1337 show_memory_usage(user
);
1338 else if(!irccasecmp(argv
[1], "channels"))
1339 show_registered_channels(user
);
1346 SPAMSERV_FUNC(cmd_addexception
)
1348 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1349 struct userData
*uData
;
1352 if(!cInfo
|| !channel
->channel_info
)
1354 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1358 if(CHECK_SUSPENDED(cInfo
))
1360 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1364 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1366 ss_reply("SSMSG_NO_ACCESS");
1371 return show_exceptions(user
, cInfo
);
1373 if(cInfo
->exceptions
->used
== spamserv_conf
.exception_max
&& !IsOper(user
))
1375 ss_reply("SSMSG_EXCEPTION_MAX", spamserv_conf
.exception_max
);
1379 if(strlen(argv
[1]) < spamserv_conf
.exception_min_len
)
1381 ss_reply("SSMSG_EXCEPTION_TOO_SHORT", spamserv_conf
.exception_min_len
);
1384 else if(strlen(argv
[1]) > spamserv_conf
.exception_max_len
)
1386 ss_reply("SSMSG_EXCEPTION_TOO_LONG", spamserv_conf
.exception_max_len
);
1390 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1392 if(!irccasecmp(argv
[1], cInfo
->exceptions
->list
[i
]))
1394 ss_reply("SSMSG_EXCEPTION_IN_LIST", argv
[1]);
1399 string_list_append(cInfo
->exceptions
, strdup(argv
[1]));
1400 ss_reply("SSMSG_EXCEPTION_ADDED", argv
[1]);
1406 SPAMSERV_FUNC(cmd_delexception
)
1408 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1409 struct userData
*uData
;
1413 if(!cInfo
|| !channel
->channel_info
)
1415 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1419 if(CHECK_SUSPENDED(cInfo
))
1421 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1425 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1427 ss_reply("SSMSG_NO_ACCESS");
1432 return show_exceptions(user
, cInfo
);
1434 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
1436 if(!irccasecmp(argv
[1], cInfo
->exceptions
->list
[i
]))
1445 ss_reply("SSMSG_NO_SUCH_EXCEPTION", argv
[1]);
1449 string_list_delete(cInfo
->exceptions
, i
);
1450 ss_reply("SSMSG_EXCEPTION_DELETED", argv
[1]);
1456 SPAMSERV_FUNC(cmd_addbadword
)
1458 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1459 struct userData
*uData
;
1462 if(!cInfo
|| !channel
->channel_info
)
1464 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1468 if(CHECK_SUSPENDED(cInfo
))
1470 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1474 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1476 ss_reply("SSMSG_NO_ACCESS");
1481 return show_badwords(user
, cInfo
);
1483 if(cInfo
->badwords
->used
== spamserv_conf
.badword_max
&& !IsOper(user
))
1485 ss_reply("SSMSG_BADWORD_MAX", spamserv_conf
.badword_max
);
1489 if(strlen(argv
[1]) < spamserv_conf
.badword_min_len
)
1491 ss_reply("SSMSG_BADWORD_TOO_SHORT", spamserv_conf
.badword_min_len
);
1494 else if(strlen(argv
[1]) > spamserv_conf
.badword_max_len
)
1496 ss_reply("SSMSG_BADWORD_TOO_LONG", spamserv_conf
.badword_max_len
);
1500 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1502 if(!irccasecmp(argv
[1], cInfo
->badwords
->list
[i
]))
1504 ss_reply("SSMSG_BADWORD_IN_LIST", argv
[1]);
1509 string_list_append(cInfo
->badwords
, strdup(argv
[1]));
1510 ss_reply("SSMSG_BADWORD_ADDED", argv
[1]);
1516 SPAMSERV_FUNC(cmd_delbadword
)
1518 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1519 struct userData
*uData
;
1523 if(!cInfo
|| !channel
->channel_info
)
1525 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1529 if(CHECK_SUSPENDED(cInfo
))
1531 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1535 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1537 ss_reply("SSMSG_NO_ACCESS");
1542 return show_badwords(user
, cInfo
);
1544 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
1546 if(!irccasecmp(argv
[1], cInfo
->badwords
->list
[i
]))
1555 ss_reply("SSMSG_NO_SUCH_BADWORD", argv
[1]);
1559 string_list_delete(cInfo
->badwords
, i
);
1560 ss_reply("SSMSG_BADWORD_DELETED", argv
[1]);
1566 SPAMSERV_FUNC(cmd_set
)
1568 struct chanInfo
*cInfo
= get_chanInfo(channel
->name
);
1569 struct userData
*uData
;
1570 struct svccmd
*subcmd
;
1571 char cmd_name
[MAXLEN
];
1576 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
1580 if(CHECK_SUSPENDED(cInfo
))
1582 ss_reply("SSMSG_SUSPENDED", channel
->name
);
1586 if(!(uData
= GetChannelUser(channel
->channel_info
, user
->handle_info
)) || (uData
->access
< 400))
1588 ss_reply("SSMSG_NO_ACCESS");
1594 ss_reply("SSMSG_CHANNEL_OPTIONS");
1596 for(i
= 0; i
< SET_SUBCMDS_SIZE
; i
++)
1598 sprintf(cmd_name
, "%s %s", cmd
->name
, set_subcommands
[i
]);
1600 if((subcmd
= dict_find(cmd
->parent
->commands
, cmd_name
, NULL
)))
1601 subcmd
->command
->func(user
, channel
, 1, argv
+ 1, subcmd
);
1607 sprintf(cmd_name
, "%s %s", cmd
->name
, argv
[1]);
1608 subcmd
= dict_find(cmd
->parent
->commands
, cmd_name
, NULL
);
1612 reply("SSMSG_INVALID_OPTION", argv
[1], argv
[0]);
1616 return subcmd
->command
->func(user
, channel
, argc
- 1, argv
+ 1, subcmd
);
1619 int ss_check_user_level(struct chanNode
*channel
, struct userNode
*user
, unsigned int minimum
, int allow_override
, int exempt_owner
)
1621 struct userData
*uData
;
1622 struct chanData
*cData
= channel
->channel_info
;
1625 uData
= _GetChannelUser(cData
, user
->handle_info
, allow_override
, 0);
1628 if(minimum
<= uData
->access
)
1630 if((minimum
> UL_OWNER
) && (uData
->access
== UL_OWNER
) && exempt_owner
)
1637 channel_except_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1639 struct chanData
*cData
= channel
->channel_info
;
1640 struct chanInfo
*cInfo
;
1641 struct userData
*uData
;
1642 unsigned short value
;
1644 cInfo
= get_chanInfo(channel
->name
);
1648 if(!ss_check_user_level(channel
, user
, cInfo
->exceptlevel
, 1, 1))
1650 reply("SSMSG_CANNOT_SET");
1653 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1654 if(!value
&& strcmp(argv
[1], "0"))
1656 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1659 uData
= GetChannelUser(cData
, user
->handle_info
);
1660 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1662 reply("SSMSG_BAD_SETLEVEL");
1665 cInfo
->exceptlevel
= value
;
1667 reply("SSMSG_SET_EXCEPTLEVEL", cInfo
->exceptlevel
);
1672 channel_except_adv_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1674 struct chanData
*cData
= channel
->channel_info
;
1675 struct chanInfo
*cInfo
;
1676 struct userData
*uData
;
1677 unsigned short value
;
1679 cInfo
= get_chanInfo(channel
->name
);
1683 if(!ss_check_user_level(channel
, user
, cInfo
->exceptadvlevel
, 1, 1))
1685 reply("SSMSG_CANNOT_SET");
1688 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1689 if(!value
&& strcmp(argv
[1], "0"))
1691 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1694 uData
= GetChannelUser(cData
, user
->handle_info
);
1695 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1697 reply("SSMSG_BAD_SETLEVEL");
1700 cInfo
->exceptadvlevel
= value
;
1702 reply("SSMSG_SET_EXCEPTADVLEVEL", cInfo
->exceptadvlevel
);
1707 channel_except_badword_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1709 struct chanData
*cData
= channel
->channel_info
;
1710 struct chanInfo
*cInfo
;
1711 struct userData
*uData
;
1712 unsigned short value
;
1714 cInfo
= get_chanInfo(channel
->name
);
1718 if(!ss_check_user_level(channel
, user
, cInfo
->exceptbadwordlevel
, 1, 1))
1720 reply("SSMSG_CANNOT_SET");
1723 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1724 if(!value
&& strcmp(argv
[1], "0"))
1726 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1729 uData
= GetChannelUser(cData
, user
->handle_info
);
1730 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1732 reply("SSMSG_BAD_SETLEVEL");
1735 cInfo
->exceptbadwordlevel
= value
;
1737 reply("SSMSG_SET_EXCEPTBADWORDLEVEL", cInfo
->exceptbadwordlevel
);
1742 channel_except_caps_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1744 struct chanData
*cData
= channel
->channel_info
;
1745 struct chanInfo
*cInfo
;
1746 struct userData
*uData
;
1747 unsigned short value
;
1749 cInfo
= get_chanInfo(channel
->name
);
1753 if(!ss_check_user_level(channel
, user
, cInfo
->exceptcapslevel
, 1, 1))
1755 reply("SSMSG_CANNOT_SET");
1758 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1759 if(!value
&& strcmp(argv
[1], "0"))
1761 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1764 uData
= GetChannelUser(cData
, user
->handle_info
);
1765 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1767 reply("SSMSG_BAD_SETLEVEL");
1770 cInfo
->exceptcapslevel
= value
;
1772 reply("SSMSG_SET_EXCEPTCAPSLEVEL", cInfo
->exceptcapslevel
);
1777 channel_except_flood_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1779 struct chanData
*cData
= channel
->channel_info
;
1780 struct chanInfo
*cInfo
;
1781 struct userData
*uData
;
1782 unsigned short value
;
1784 cInfo
= get_chanInfo(channel
->name
);
1788 if(!ss_check_user_level(channel
, user
, cInfo
->exceptfloodlevel
, 1, 1))
1790 reply("SSMSG_CANNOT_SET");
1793 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1794 if(!value
&& strcmp(argv
[1], "0"))
1796 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1799 uData
= GetChannelUser(cData
, user
->handle_info
);
1800 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1802 reply("SSMSG_BAD_SETLEVEL");
1805 cInfo
->exceptfloodlevel
= value
;
1807 reply("SSMSG_SET_EXCEPTFLOODLEVEL", cInfo
->exceptfloodlevel
);
1812 channel_except_spam_level(struct userNode
*user
, struct chanNode
*channel
, int argc
, char *argv
[], struct svccmd
*cmd
)
1814 struct chanData
*cData
= channel
->channel_info
;
1815 struct chanInfo
*cInfo
;
1816 struct userData
*uData
;
1817 unsigned short value
;
1819 cInfo
= get_chanInfo(channel
->name
);
1823 if(!ss_check_user_level(channel
, user
, cInfo
->exceptspamlevel
, 1, 1))
1825 reply("SSMSG_CANNOT_SET");
1828 value
= user_level_from_name(argv
[1], UL_OWNER
+1);
1829 if(!value
&& strcmp(argv
[1], "0"))
1831 reply("SSMSG_INVALID_ACCESS", argv
[1]);
1834 uData
= GetChannelUser(cData
, user
->handle_info
);
1835 if(!uData
|| ((uData
->access
< UL_OWNER
) && (value
> uData
->access
)))
1837 reply("SSMSG_BAD_SETLEVEL");
1840 cInfo
->exceptspamlevel
= value
;
1842 reply("SSMSG_SET_EXCEPTSPAMLEVEL", cInfo
->exceptspamlevel
);
1847 SPAMSERV_FUNC(opt_capsmin
)
1849 struct chanInfo
*cInfo
;
1851 cInfo
= get_chanInfo(channel
->name
);
1855 char *mask
= strdup(argv
[1]);
1856 unsigned int old
= cInfo
->capsmin
;
1858 if (isdigit(*mask
) && strspn(mask
, "1234567890,-") == strlen(mask
)) {
1859 cInfo
->capsmin
= mask
? strtoul(mask
, NULL
, 0) : 10;
1861 if (cInfo
->capsmin
< 0) {
1862 cInfo
->capsmin
= old
;
1863 reply("SSMSG_BAD_SETLEVEL");
1867 reply("SSMSG_BAD_SETLEVEL");
1871 reply("SSMSG_SET_CAPSMIN", cInfo
->capsmin
);
1876 SPAMSERV_FUNC(opt_capspercent
)
1878 struct chanInfo
*cInfo
;
1880 cInfo
= get_chanInfo(channel
->name
);
1884 char *mask
= strdup(argv
[1]);
1885 unsigned int old
= cInfo
->capspercent
;
1887 if (isdigit(*mask
) && strspn(mask
, "1234567890,-") == strlen(mask
)) {
1888 cInfo
->capspercent
= mask
? strtoul(mask
, NULL
, 0) : 10;
1890 if ((cInfo
->capspercent
< 0) || (cInfo
->capspercent
> 100)) {
1891 cInfo
->capspercent
= old
;
1892 reply("SSMSG_BAD_SETLEVEL");
1896 reply("SSMSG_BAD_SETLEVEL");
1900 reply("SSMSG_SET_CAPSPERCENT", cInfo
->capspercent
);
1905 SPAMSERV_FUNC(opt_exceptlevel
)
1907 return channel_except_level(SSFUNC_ARGS
);
1911 SPAMSERV_FUNC(opt_exceptadvlevel
)
1913 return channel_except_adv_level(SSFUNC_ARGS
);
1917 SPAMSERV_FUNC(opt_exceptbadwordlevel
)
1919 return channel_except_badword_level(SSFUNC_ARGS
);
1923 SPAMSERV_FUNC(opt_exceptcapslevel
)
1925 return channel_except_caps_level(SSFUNC_ARGS
);
1929 SPAMSERV_FUNC(opt_exceptfloodlevel
)
1931 return channel_except_flood_level(SSFUNC_ARGS
);
1935 SPAMSERV_FUNC(opt_exceptspamlevel
)
1937 return channel_except_spam_level(SSFUNC_ARGS
);
1941 SPAMSERV_FUNC(opt_spamlimit
)
1943 struct valueData values
[] =
1945 {"Users may send the same message $b2$b times.", 'a', 0},
1946 {"Users may send the same message $b3$b times.", 'b', 0},
1947 {"Users may send the same message $b4$b times.", 'c', 0},
1948 {"Users may send the same message $b5$b times.", 'd', 0},
1949 {"Users may send the same message $b6$b times.", 'e', 0}
1952 MULTIPLE_OPTION("SpamLimit ", "SpamLimit", ci_SpamLimit
);
1956 SPAMSERV_FUNC(opt_advreaction
)
1958 struct valueData values
[] =
1960 {"Kick on disallowed advertising.", 'k', 0},
1961 {"Kickban on disallowed advertising.", 'b', 0},
1962 {"Short timed ban on disallowed advertising.", 's', 0},
1963 {"Long timed ban on disallowed advertising.", 'l', 0},
1964 {"Kill on disallowed advertising.", 'd', 1}
1967 MULTIPLE_OPTION("AdvReaction ", "AdvReaction", ci_AdvReaction
);
1971 SPAMSERV_FUNC(opt_warnreaction
)
1973 struct valueData values
[] =
1975 {"Kick after warning.", 'k', 0},
1976 {"Kickban after warning.", 'b', 0},
1977 {"Short timed ban after warning.", 's', 0},
1978 {"Long timed ban after warning.", 'l', 0},
1979 {"Kill after warning.", 'd', 1}
1982 MULTIPLE_OPTION("WarnReaction ", "WarnReaction", ci_WarnReaction
);
1986 SPAMSERV_FUNC(opt_badreaction
)
1988 struct valueData values
[] =
1990 {"Kick on disallowed badwords.", 'k', 0},
1991 {"Kickban on disallowed badwords.", 'b', 0},
1992 {"Short timed ban on disallowed badwords.", 's', 0},
1993 {"Long timed ban on disallowed badwords.", 'l', 0},
1994 {"Kill on disallowed badwords.", 'd', 1}
1997 MULTIPLE_OPTION("BadReaction ", "BadReaction", ci_BadReaction
);
2001 SPAMSERV_FUNC(opt_capsreaction
)
2003 struct valueData values
[] =
2005 {"Kick on disallowed caps.", 'k', 0},
2006 {"Kickban on disallowed caps.", 'b', 0},
2007 {"Short timed ban on disallowed caps.", 's', 0},
2008 {"Long timed ban on disallowed caps.", 'l', 0},
2009 {"Kill on disallowed caps.", 'd', 1}
2012 MULTIPLE_OPTION("CapsReaction ", "CapsReaction", ci_CapsReaction
);
2016 SPAMSERV_FUNC(opt_advscan
)
2018 BINARY_OPTION("AdvScan ", CHAN_ADV_SCAN
);
2022 SPAMSERV_FUNC(opt_capsscan
)
2024 BINARY_OPTION("CapsScan ", CHAN_CAPSSCAN
);
2028 SPAMSERV_FUNC(opt_spamscan
)
2030 BINARY_OPTION("SpamScan ", CHAN_SPAMSCAN
);
2034 SPAMSERV_FUNC(opt_badwordscan
)
2036 BINARY_OPTION("BadWordScan ", CHAN_BADWORDSCAN
);
2040 SPAMSERV_FUNC(opt_chanfloodscan
)
2042 BINARY_OPTION("ChanFloodScan ", CHAN_CHANFLOODSCAN
);
2046 SPAMSERV_FUNC(opt_joinflood
)
2048 BINARY_OPTION("JoinFloodScan ", CHAN_JOINFLOOD
);
2052 spamserv_add_trusted_account(const char *account
, struct string_list
*channel
, const char *issuer
, time_t issued
)
2054 struct trusted_account
*ta
;
2055 ta
= calloc(1, sizeof(*ta
));
2058 ta
->account
= strdup(account
);
2059 ta
->channel
= channel
? string_list_copy(channel
) : alloc_string_list(1);
2060 ta
->issuer
= strdup(issuer
);
2061 ta
->issued
= issued
;
2062 dict_insert(spamserv_trusted_accounts
, strdup(ta
->account
), ta
);
2067 free_trusted_account(void *data)
2069 struct trusted_account *ta = data;
2071 free_string_list(ta->channel);
2077 static SPAMSERV_FUNC(cmd_addtrust
)
2080 struct userData
*uData
;
2081 struct chanData
*cData
;
2082 struct chanInfo
*cInfo
;
2083 struct trusted_account
*ta
;
2084 struct string_list
*templist
;
2085 struct handle_info
*hi
;
2087 if (!(channel
= GetChannel(argv
[2]))) {
2088 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2092 cInfo
= get_chanInfo(channel
->name
);
2093 cData
= channel
->channel_info
;
2094 uData
= GetChannelUser(cData
, user
->handle_info
);
2096 if (!cInfo
|| !channel
->channel_info
) {
2097 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2101 if (CHECK_SUSPENDED(cInfo
)) {
2102 ss_reply("SSMSG_SUSPENDED", channel
->name
);
2106 if (!uData
|| (uData
->access
< UL_MANAGER
)) {
2107 ss_reply("SSMSG_NO_ACCESS");
2111 if (!(hi
= modcmd_get_handle_info(user
, argv
[1]))) {
2115 if ((ta
= dict_find(spamserv_trusted_accounts
, argv
[1], NULL
))) {
2116 if (ta
->channel
->used
&& (argc
> 1)) {
2117 for (i
=0; i
< ta
->channel
->used
; i
++) {
2118 if (!strcmp(ta
->channel
->list
[i
], argv
[2])) {
2119 ss_reply("SSMSG_ALREADY_TRUSTED", hi
->handle
);
2125 string_list_append(ta
->channel
, argv
[2]);
2126 ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2130 templist
= alloc_string_list(sizeof(argv
[2])+1);
2131 // templist = alloc_string_list(1);
2132 string_list_append(templist
, argv
[2]);
2134 spamserv_add_trusted_account(hi
->handle
, templist
, user
->handle_info
->handle
, now
);
2135 ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2139 static SPAMSERV_FUNC(cmd_oaddtrust
)
2141 unsigned int i
, global
= 0;
2142 struct chanInfo
*cInfo
;
2143 struct chanData
*cData
;
2144 struct trusted_account
*ta
;
2145 struct string_list
*templist
;
2146 struct handle_info
*hi
;
2148 if (!strcmp(argv
[2], "global"))
2151 if (!(channel
= GetChannel(argv
[2])) && (global
== 0)) {
2152 ss_reply("SSMSG_NOT_REGISTERED", channel
? channel
->name
: (global
? "global" : ""));
2157 cInfo
= get_chanInfo(channel
->name
);
2158 cData
= channel
->channel_info
;
2160 if (!cInfo
|| !channel
->channel_info
) {
2161 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2166 if (!(hi
= modcmd_get_handle_info(user
, argv
[1]))) {
2170 if ((ta
= dict_find(spamserv_trusted_accounts
, argv
[1], NULL
))) {
2171 if (ta
->channel
->used
&& (argc
> 1)) {
2172 for (i
=0; i
< ta
->channel
->used
; i
++) {
2173 if (!strcmp(ta
->channel
->list
[i
], argv
[2])) {
2174 ss_reply("SSMSG_ALREADY_TRUSTED", argv
[1]);
2180 string_list_append(ta
->channel
, argv
[2]);
2183 ss_reply("SSMSG_ADDED_TRUSTED", argv
[1]);
2185 ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", argv
[1], argv
[2]);
2190 templist
= alloc_string_list(sizeof(argv
[2])+1);
2191 // templist = alloc_string_list(1);
2192 string_list_append(templist
, argv
[2]);
2194 spamserv_add_trusted_account(hi
->handle
, templist
, user
->handle_info
->handle
, now
);
2197 ss_reply("SSMSG_ADDED_TRUSTED", hi
->handle
);
2199 ss_reply("SSMSG_ADDED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2204 static SPAMSERV_FUNC(cmd_deltrust
)
2208 struct trusted_account
*ta
;
2209 struct userData
*uData
;
2210 struct chanData
*cData
;
2211 struct chanInfo
*cInfo
;
2212 struct handle_info
*hi
;
2214 if (!(channel
= GetChannel(argv
[2]))) {
2215 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2219 cInfo
= get_chanInfo(channel
->name
);
2220 cData
= channel
->channel_info
;
2221 uData
= GetChannelUser(cData
, user
->handle_info
);
2223 if (!cInfo
|| !channel
->channel_info
) {
2224 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2228 if (CHECK_SUSPENDED(cInfo
)) {
2229 ss_reply("SSMSG_SUSPENDED", channel
->name
);
2233 if (!uData
|| (uData
->access
< UL_MANAGER
)) {
2234 ss_reply("SSMSG_NO_ACCESS");
2238 if (!(hi
= modcmd_get_handle_info(user
, argv
[1]))) {
2242 ta
= dict_find(spamserv_trusted_accounts
, hi
->handle
, NULL
);
2245 ss_reply("SSMSG_NOT_TRUSTED", argv
[2]);
2250 if (ta
->channel
->used
) {
2251 for (i
=0; i
< ta
->channel
->used
; i
++) {
2252 if (!strcmp(ta
->channel
->list
[i
], argv
[2])) {
2253 string_list_delete(ta
->channel
, i
);
2260 ss_reply("SSMSG_REMOVED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2262 ss_reply("SSMSG_NOT_TRUSTED", hi
->handle
, argv
[2]);
2266 dict_remove(spamserv_trusted_accounts
, hi
->handle
);
2267 ss_reply("SSMSG_REMOVED_TRUSTED", hi
->handle
);
2273 static SPAMSERV_FUNC(cmd_odeltrust
)
2276 int rem
= 0, global
= 0;
2277 struct trusted_account
*ta
;
2278 struct chanInfo
*cInfo
;
2279 struct chanData
*cData
;
2280 struct handle_info
*hi
;
2282 if (!strcmp(argv
[2], "global"))
2285 if (!(channel
= GetChannel(argv
[2])) && (global
== 0)) {
2286 ss_reply("SSMSG_NOT_REGISTERED", channel
? channel
->name
: (global
? "global" : ""));
2291 cInfo
= get_chanInfo(channel
->name
);
2292 cData
= channel
->channel_info
;
2294 if (!cInfo
|| !channel
->channel_info
) {
2295 ss_reply("SSMSG_NOT_REGISTERED", channel
->name
);
2300 if (!(hi
= modcmd_get_handle_info(user
, argv
[1]))) {
2304 ta
= dict_find(spamserv_trusted_accounts
, hi
->handle
, NULL
);
2307 ss_reply("SSMSG_NOT_TRUSTED", argv
[2]);
2312 if (ta
->channel
->used
) {
2313 for (i
=0; i
< ta
->channel
->used
; i
++) {
2314 if (!strcmp(ta
->channel
->list
[i
], argv
[2])) {
2315 string_list_delete(ta
->channel
, i
);
2322 ss_reply("SSMSG_REMOVED_TRUSTED_CHANNEL", hi
->handle
, argv
[2]);
2324 ss_reply("SSMSG_NOT_TRUSTED", argv
[2]);
2328 dict_remove(spamserv_trusted_accounts
, hi
->handle
);
2329 ss_reply("SSMSG_REMOVED_TRUSTED", hi
->handle
);
2335 static SPAMSERV_FUNC(cmd_listtrust
) {
2337 struct trusted_account
*ta
;
2338 char issued
[INTERVALLEN
];
2343 if (!strcmp(argv
[1], "global")) {
2344 if (!IsHelping(user
)) {
2345 reply("SSMSG_MUST_BE_HELPING");
2350 channel
= GetChannel(argv
[1]);
2352 chan
= strdup(channel
->name
);
2354 ss_reply("SSMSG_NOT_REGISTERED", argv
[1]);
2359 reply("MSG_INVALID_CHANNEL");
2363 reply("SSMSG_TRUSTED_LIST");
2364 reply("SSMSG_TRUSTED_LIST_BAR");
2365 reply("SSMSG_TRUSTED_LIST_HEADER");
2366 reply("SSMSG_TRUSTED_LIST_BAR");
2367 for (it
= dict_first(spamserv_trusted_accounts
); it
; it
= iter_next(it
)) {
2370 if (ta
->channel
->used
) {
2371 for (i
=0; i
< ta
->channel
->used
; i
++) {
2373 if (!strcmp(ta
->channel
->list
[i
], chan
)) {
2375 intervalString(issued
, now
- ta
->issued
, user
->handle_info
);
2377 ss_reply("SSMSG_HOST_IS_TRUSTED", iter_key(it
),
2378 (ta
->issuer
? ta
->issuer
: "<unknown>"),
2379 (ta
->issued
? issued
: "some time"));
2381 } else if (!strcmp(ta
->channel
->list
[i
], "global") && (!strcmp(chan
, "global"))) {
2383 intervalString(issued
, now
- ta
->issued
, user
->handle_info
);
2385 ss_reply("SSMSG_HOST_IS_TRUSTED", iter_key(it
),
2386 (ta
->issuer
? ta
->issuer
: "<unknown>"),
2387 (ta
->issued
? issued
: 0));
2392 ss_reply("SSMSG_TRUSTED_LIST_END");
2397 to_lower(char *message
)
2399 unsigned int i
, diff
= 'a' - 'A';
2401 for(i
= 0; i
< strlen(message
); i
++)
2403 if((message
[i
] >= 'A') && (message
[i
] <= 'Z'))
2404 message
[i
] = message
[i
] + diff
;
2409 strip_mirc_codes(char *text
)
2411 // taken from xchat and modified
2412 int nc
= 0, i
= 0, col
= 0, len
= strlen(text
);
2413 static char new_str
[MAXLEN
];
2417 if((col
&& isdigit(*text
) && nc
< 2) ||
2418 (col
&& *text
== ',' && isdigit(*(text
+ 1)) && nc
< 3))
2457 is_in_exception_list(struct chanInfo
*cInfo
, char *message
)
2461 for(i
= 0; i
< cInfo
->exceptions
->used
; i
++)
2462 if(strstr(message
, cInfo
->exceptions
->list
[i
]))
2469 is_in_badword_list(struct chanInfo
*cInfo
, char *message
)
2473 for(i
= 0; i
< cInfo
->badwords
->used
; i
++)
2474 if(strstr(message
, cInfo
->badwords
->list
[i
]))
2481 check_caps(struct chanInfo
*cInfo
, char *message
)
2485 if ( (c
= strlen(message
)) >= cInfo
->capsmin
) {
2487 char *s
= strdup(message
);
2494 if (i
>= cInfo
->capsmin
&& i
* 100 / c
>= cInfo
->capspercent
)
2502 check_badwords(struct chanInfo
*cInfo
, char *message
)
2504 if(spamserv_conf
.strip_mirc_codes
)
2505 message
= strip_mirc_codes(message
);
2507 /* This needs improving */
2508 if(is_in_exception_list(cInfo
, message
))
2511 if(is_in_badword_list(cInfo
, message
))
2518 check_advertising(struct chanInfo
*cInfo
, char *message
)
2522 if(spamserv_conf
.strip_mirc_codes
)
2523 message
= strip_mirc_codes(message
);
2525 if(is_in_exception_list(cInfo
, message
))
2528 while(message
[i
] != 0)
2530 if(message
[i
] == '#')
2532 char channelname
[CHANNELLEN
];
2535 if(!spamserv_conf
.adv_chan_must_exist
)
2538 /* only return 1, if the channel does exist */
2540 while((message
[i
] != 0) && (message
[i
] != ' '))
2542 channelname
[j
] = message
[i
];
2547 channelname
[j
] = '\0';
2549 if(GetChannel(channelname
))
2552 else if((message
[i
] == 'w') && (message
[i
+1] == 'w') && (message
[i
+2] == 'w') && (message
[i
+3] == '.'))
2554 else if((message
[i
] == 'h') && (message
[i
+1] == 't') && (message
[i
+2] == 't') && (message
[i
+3] == 'p') && (message
[i
+4] == ':'))
2556 else if((message
[i
] == 'f') && (message
[i
+1] == 't') && (message
[i
+2] == 'p') && ((message
[i
+3] == '.') || (message
[i
+3] == ':')))
2566 spamserv_punish(struct chanNode
*channel
, struct userNode
*user
, time_t expires
, char *reason
, int ban
)
2570 struct mod_chanmode change
;
2571 char *hostmask
= generate_hostmask(user
, GENMASK_STRICT_HOST
| GENMASK_ANY_IDENT
);
2573 sanitize_ircmask(hostmask
);
2576 add_channel_ban(channel
->channel_info
, hostmask
, spamserv
->nick
, now
, now
, now
+ expires
, reason
);
2578 mod_chanmode_init(&change
);
2580 change
.args
[0].mode
= MODE_BAN
;
2581 change
.args
[0].u
.hostmask
= hostmask
;
2582 mod_chanmode_announce(spamserv
, channel
, &change
);
2586 spamserv_debug(SSMSG_DEBUG_BAN
, user
->nick
, channel
->name
, reason
);
2589 spamserv_debug(SSMSG_DEBUG_KICK
, user
->nick
, channel
->name
, reason
);
2591 KickChannelUser(user
, channel
, spamserv
, reason
);
2595 spamserv_channel_message(struct chanNode
*channel
, struct userNode
*user
, char *text
)
2597 struct chanData
*cData
;
2598 struct chanInfo
*cInfo
;
2599 struct userInfo
*uInfo
;
2600 struct userData
*uData
;
2601 struct spamNode
*sNode
;
2602 struct floodNode
*fNode
;
2603 struct trusted_account
*ta
;
2604 unsigned int violation
= 0;
2605 char reason
[MAXLEN
];
2607 /* make sure: spamserv is not disabled; x3 is running; spamserv is in the chan; chan is regged, user does exist */
2608 if(!spamserv
|| quit_services
|| !GetUserMode(channel
, spamserv
) || IsOper(user
) || !(cInfo
= get_chanInfo(channel
->name
)) || !(uInfo
= get_userInfo(user
->nick
)))
2611 cData
= channel
->channel_info
;
2612 uData
= GetChannelUser(cData
, user
->handle_info
);
2614 if (user
->handle_info
) {
2615 ta
= dict_find(spamserv_trusted_accounts
, user
->handle_info
->handle
, NULL
);
2618 for (i
=0; i
< ta
->channel
->used
; i
++) {
2619 if (!strcmp(ta
->channel
->list
[i
], channel
->name
))
2622 if (!strcmp(ta
->channel
->list
[i
], "global"))
2629 if(uData
&& (uData
->access
>= cInfo
->exceptlevel
))
2632 if(CHECK_CAPSSCAN(cInfo
) && check_caps(cInfo
, text
))
2634 if(uData
&& (uData
->access
>= cInfo
->exceptcapslevel
))
2637 if(CHECK_CAPS_WARNED(uInfo
))
2639 switch(cInfo
->info
[ci_CapsReaction
])
2641 case 'k': uInfo
->flags
|= USER_KICK
; break;
2642 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2643 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2644 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2645 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2648 uInfo
->warnlevel
+= CAPS_WARNLEVEL
;
2653 uInfo
->flags
|= USER_CAPS_WARNED
;
2654 uInfo
->lastcaps
= now
;
2655 uInfo
->warnlevel
+= CAPS_WARNLEVEL
;
2657 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2658 if (spamserv_conf
.network_rules
)
2659 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_CAPS
, spamserv_conf
.network_rules
);
2661 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_CAPS
, spamserv_conf
.network_rules
);
2669 if(CHECK_SPAM(cInfo
))
2671 if(uData
&& (uData
->access
>= cInfo
->exceptspamlevel
))
2674 if(!(sNode
= uInfo
->spam
))
2676 spamserv_create_spamNode(channel
, uInfo
, text
);
2680 for(; sNode
; sNode
= sNode
->next
)
2681 if(sNode
->channel
== channel
)
2686 spamserv_create_spamNode(channel
, uInfo
, text
);
2690 unsigned long crc
= crc32(text
);
2692 if(crc
== sNode
->crc32
)
2694 unsigned int spamlimit
= 2;
2697 switch(cInfo
->info
[ci_SpamLimit
])
2699 case 'a': spamlimit
= 2; break;
2700 case 'b': spamlimit
= 3; break;
2701 case 'c': spamlimit
= 4; break;
2702 case 'd': spamlimit
= 5; break;
2703 case 'e': spamlimit
= 6; break;
2706 if(sNode
->count
== spamlimit
)
2708 uInfo
->warnlevel
+= SPAM_WARNLEVEL
;
2710 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2711 if (spamserv_conf
.network_rules
)
2712 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_SPAM
, spamserv_conf
.network_rules
);
2714 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_SPAM
, spamserv_conf
.network_rules
);
2717 else if(sNode
->count
> spamlimit
)
2719 switch(cInfo
->info
[ci_WarnReaction
])
2721 case 'k': uInfo
->flags
|= USER_KICK
; break;
2722 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2723 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2724 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2725 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2728 spamserv_delete_spamNode(uInfo
, sNode
);
2729 uInfo
->warnlevel
+= SPAM_WARNLEVEL
;
2742 if(CHECK_FLOOD(cInfo
))
2744 if(uData
&& (uData
->access
>= cInfo
->exceptfloodlevel
))
2747 if(!(fNode
= uInfo
->flood
))
2749 spamserv_create_floodNode(channel
, user
, &uInfo
->flood
);
2753 for(; fNode
; fNode
= fNode
->next
)
2754 if(fNode
->channel
== channel
)
2758 spamserv_create_floodNode(channel
, user
, &uInfo
->flood
);
2760 if(((now
- fNode
->time
) < FLOOD_EXPIRE
)) {
2763 if(fNode
->count
== FLOOD_MAX_LINES
- 1) {
2764 uInfo
->warnlevel
+= FLOOD_WARNLEVEL
;
2766 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2767 if (spamserv_conf
.network_rules
)
2768 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_FLOOD
, spamserv_conf
.network_rules
);
2770 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_FLOOD
, spamserv_conf
.network_rules
);
2774 else if(fNode
->count
> FLOOD_MAX_LINES
) {
2775 switch(cInfo
->info
[ci_WarnReaction
]) {
2776 case 'k': uInfo
->flags
|= USER_KICK
; break;
2777 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2778 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2779 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2780 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2783 spamserv_delete_floodNode(&uInfo
->flood
, fNode
);
2784 uInfo
->warnlevel
+= FLOOD_WARNLEVEL
;
2794 if(CHECK_BADWORDSCAN(cInfo
) && check_badwords(cInfo
, text
))
2796 if(uData
&& (uData
->access
>= cInfo
->exceptbadwordlevel
))
2799 if(CHECK_BAD_WARNED(uInfo
))
2801 switch(cInfo
->info
[ci_BadReaction
])
2803 case 'k': uInfo
->flags
|= USER_KICK
; break;
2804 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2805 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2806 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2807 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2810 uInfo
->warnlevel
+= BAD_WARNLEVEL
;
2815 uInfo
->flags
|= USER_BAD_WARNED
;
2816 uInfo
->lastbad
= now
;
2817 uInfo
->warnlevel
+= BAD_WARNLEVEL
;
2819 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2820 if (spamserv_conf
.network_rules
)
2821 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_BAD
, spamserv_conf
.network_rules
);
2823 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_BAD
, spamserv_conf
.network_rules
);
2828 if(CHECK_ADV(cInfo
) && check_advertising(cInfo
, text
))
2830 if(uData
&& (uData
->access
>= cInfo
->exceptspamlevel
))
2833 if(CHECK_ADV_WARNED(uInfo
))
2835 switch(cInfo
->info
[ci_AdvReaction
])
2837 case 'k': uInfo
->flags
|= USER_KICK
; break;
2838 case 'b': uInfo
->flags
|= USER_KICKBAN
; break;
2839 case 's': uInfo
->flags
|= USER_SHORT_TBAN
; break;
2840 case 'l': uInfo
->flags
|= USER_LONG_TBAN
; break;
2841 case 'd': uInfo
->flags
|= CHECK_KILLED(uInfo
) ? USER_GLINE
: USER_KILL
; break;
2844 uInfo
->warnlevel
+= ADV_WARNLEVEL
;
2849 uInfo
->flags
|= USER_ADV_WARNED
;
2850 uInfo
->lastadv
= now
;
2851 uInfo
->warnlevel
+= ADV_WARNLEVEL
;
2853 if(uInfo
->warnlevel
< MAX_WARNLEVEL
) {
2854 if (spamserv_conf
.network_rules
)
2855 spamserv_notice(user
, "SSMSG_WARNING_RULES_T", SSMSG_ADV
, spamserv_conf
.network_rules
);
2857 spamserv_notice(user
, "SSMSG_WARNING_T", SSMSG_ADV
, spamserv_conf
.network_rules
);
2862 if(!CHECK_WARNED(uInfo
) && !CHECK_KILL(uInfo
) && !CHECK_GLINE(uInfo
) && uInfo
->warnlevel
== MAX_WARNLEVEL
)
2864 uInfo
->flags
|= USER_WARNED
;
2865 if (spamserv_conf
.network_rules
)
2866 snprintf(reason
, sizeof(reason
), SSMSG_WARNING_RULES_2
, spamserv_conf
.network_rules
);
2868 snprintf(reason
, sizeof(reason
), SSMSG_WARNING_2
);
2869 irc_notice(spamserv
, user
->numeric
, reason
);
2870 irc_privmsg(spamserv
, user
->numeric
, reason
);
2872 else if(uInfo
->warnlevel
> MAX_WARNLEVEL
)
2874 if(CHECK_KILLED(uInfo
))
2875 uInfo
->flags
|= USER_GLINE
;
2877 uInfo
->flags
|= USER_KILL
;
2888 case 1: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_SPAM
, spamserv_conf
.network_rules
); break;
2889 case 2: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_FLOOD
, spamserv_conf
.network_rules
); break;
2890 case 3: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_ADV
, spamserv_conf
.network_rules
); break;
2891 case 4: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_BAD
, spamserv_conf
.network_rules
); break;
2892 case 5: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES
: SSMSG_WARNING
, SSMSG_CAPS
, spamserv_conf
.network_rules
); break;
2893 default: snprintf(reason
, sizeof(reason
), spamserv_conf
.network_rules
? SSMSG_WARNING_RULES_2
: SSMSG_WARNING_2
, spamserv_conf
.network_rules
); break;
2896 if(CHECK_GLINE(uInfo
))
2898 int size
= strlen(user
->hostname
) + 3;
2899 char *mask
= alloca(size
);
2900 snprintf(mask
, size
, "*@%s", user
->hostname
);
2901 gline_add(spamserv
->nick
, mask
, spamserv_conf
.gline_duration
, reason
, now
, 1, 0);
2902 spamserv_debug(SSMSG_DEBUG_GLINE
, user
->nick
, user
->hostname
, channel
->name
);
2904 else if(CHECK_KILL(uInfo
))
2906 DelUser(user
, spamserv
, 1, reason
);
2907 spamserv_debug(SSMSG_DEBUG_KILL
, user
->nick
, channel
->name
);
2909 else if(CHECK_LONG_TBAN(uInfo
))
2911 spamserv_punish(channel
, user
, spamserv_conf
.long_ban_duration
, reason
, 1);
2913 else if(CHECK_SHORT_TBAN(uInfo
))
2915 spamserv_punish(channel
, user
, spamserv_conf
.short_ban_duration
, reason
, 1);
2917 else if(CHECK_KICKBAN(uInfo
))
2919 spamserv_punish(channel
, user
, 0, reason
, 1);
2921 else if(CHECK_KICK(uInfo
))
2923 spamserv_punish(channel
, user
, 0, reason
, 0);
2928 trusted_account_read(const char *account
, void *data
, UNUSED_ARG(void *extra
))
2930 struct record_data
*rd
= data
;
2931 const char *str
, *issuer
;
2932 struct string_list
*strlist
;
2935 if (rd
->type
== RECDB_OBJECT
) {
2936 dict_t obj
= GET_RECORD_OBJECT(rd
);
2937 /* new style structure */
2938 strlist
= database_get_data(obj
, KEY_CHANNELS
, RECDB_STRING_LIST
);
2939 issuer
= database_get_data(obj
, KEY_ISSUER
, RECDB_QSTRING
);
2940 str
= database_get_data(obj
, KEY_ISSUED
, RECDB_QSTRING
);
2941 issued
= str
? ParseInterval(str
) : 0;
2945 spamserv_add_trusted_account(account
, strlist
, issuer
, issued
);
2950 spamserv_saxdb_read(struct dict
*database
)
2953 struct record_data
*hir
;
2954 struct chanNode
*channel
;
2955 struct chanInfo
*cInfo
;
2956 struct string_list
*strlist
, *strlist2
;
2958 unsigned int exceptlevel
, exceptadvlevel
, exceptbadwordlevel
;
2959 unsigned int exceptfloodlevel
, exceptspamlevel
, exceptcapslevel
;
2960 unsigned int capsmin
, capspercent
;
2965 if ((object
= database_get_data(database
, KEY_TRUSTED_HOSTS
, RECDB_OBJECT
)))
2966 dict_foreach(object
, trusted_account_read
, spamserv_trusted_accounts
);
2968 for(it
= dict_first(database
); it
; it
= iter_next(it
))
2970 hir
= iter_data(it
);
2972 if(hir
->type
!= RECDB_OBJECT
)
2974 log_module(SS_LOG
, LOG_WARNING
, "Unexpected rectype %d for %s.", hir
->type
, iter_key(it
));
2978 channel
= GetChannel(iter_key(it
));
2979 if (!strcmp("trusted", iter_key(it
)))
2982 strlist
= database_get_data(hir
->d
.object
, KEY_EXCEPTIONS
, RECDB_STRING_LIST
);
2983 strlist2
= database_get_data(hir
->d
.object
, KEY_BADWORDS
, RECDB_STRING_LIST
);
2985 str
= database_get_data(hir
->d
.object
, KEY_FLAGS
, RECDB_QSTRING
);
2986 flags
= str
? atoi(str
) : 0;
2988 info
= database_get_data(hir
->d
.object
, KEY_INFO
, RECDB_QSTRING
);
2990 str
= database_get_data(hir
->d
.object
, KEY_EXPIRY
, RECDB_QSTRING
);
2991 expiry
= str
? strtoul(str
, NULL
, 0) : 0;
2993 str
= database_get_data(hir
->d
.object
, KEY_CAPSMIN
, RECDB_QSTRING
);
2994 capsmin
= str
? strtoul(str
, NULL
, 0) : 10;
2996 str
= database_get_data(hir
->d
.object
, KEY_CAPSPERCENT
, RECDB_QSTRING
);
2997 capspercent
= str
? strtoul(str
, NULL
, 0) : 25;
2999 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTLEVEL
, RECDB_QSTRING
);
3000 exceptlevel
= str
? strtoul(str
, NULL
, 0) : UL_MANAGER
;
3002 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTADVLEVEL
, RECDB_QSTRING
);
3003 exceptadvlevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
3005 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTBADWORDLEVEL
, RECDB_QSTRING
);
3006 exceptbadwordlevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
3008 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTCAPSLEVEL
, RECDB_QSTRING
);
3009 exceptcapslevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
3011 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTFLOODLEVEL
, RECDB_QSTRING
);
3012 exceptfloodlevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
3014 str
= database_get_data(hir
->d
.object
, KEY_EXCEPTSPAMLEVEL
, RECDB_QSTRING
);
3015 exceptspamlevel
= str
? strtoul(str
, NULL
, 0) : UL_OP
;
3019 if((cInfo
= spamserv_register_channel(channel
, strlist
, strlist2
, flags
, info
)))
3021 /* if the channel is suspended and expiry = 0 it means: channel will
3022 never expire ! it does NOT mean, the channel is not suspended */
3023 if(CHECK_SUSPENDED(cInfo
) && expiry
&& (expiry
< now
))
3025 cInfo
->flags
&= ~CHAN_SUSPENDED
;
3026 spamserv_join_channel(cInfo
->channel
);
3028 else if(!CHECK_SUSPENDED(cInfo
))
3029 spamserv_join_channel(cInfo
->channel
);
3031 cInfo
->suspend_expiry
= expiry
;
3033 cInfo
->capsmin
= capsmin
;
3034 cInfo
->capspercent
= capspercent
;
3035 cInfo
->exceptlevel
= exceptlevel
;
3036 cInfo
->exceptadvlevel
= exceptadvlevel
;
3037 cInfo
->exceptbadwordlevel
= exceptbadwordlevel
;
3038 cInfo
->exceptcapslevel
= exceptcapslevel
;
3039 cInfo
->exceptfloodlevel
= exceptfloodlevel
;
3040 cInfo
->exceptspamlevel
= exceptspamlevel
;
3044 log_module(SS_LOG
, LOG_ERROR
, "Couldn't register channel %s. Channel or info invalid.", iter_key(it
));
3051 spamserv_saxdb_write(struct saxdb_context
*ctx
)
3055 if (dict_size(spamserv_trusted_accounts
)) {
3056 saxdb_start_record(ctx
, KEY_TRUSTED_ACCOUNTS
, 1);
3057 for (it
= dict_first(spamserv_trusted_accounts
); it
; it
= iter_next(it
)) {
3058 struct trusted_account
*ta
= iter_data(it
);
3059 saxdb_start_record(ctx
, iter_key(it
), 0);
3060 if (ta
->channel
) saxdb_write_string_list(ctx
, KEY_CHANNELS
, ta
->channel
);
3061 if (ta
->issued
) saxdb_write_int(ctx
, KEY_ISSUED
, ta
->issued
);
3062 if (ta
->issuer
) saxdb_write_string(ctx
, KEY_ISSUER
, ta
->issuer
);
3063 saxdb_end_record(ctx
);
3065 saxdb_end_record(ctx
);
3068 for(it
= dict_first(registered_channels_dict
); it
; it
= iter_next(it
))
3070 struct chanInfo
*cInfo
= iter_data(it
);
3072 saxdb_start_record(ctx
, cInfo
->channel
->name
, 1);
3074 if(cInfo
->exceptions
->used
)
3075 saxdb_write_string_list(ctx
, KEY_EXCEPTIONS
, cInfo
->exceptions
);
3077 if(cInfo
->badwords
->used
)
3078 saxdb_write_string_list(ctx
, KEY_BADWORDS
, cInfo
->badwords
);
3081 saxdb_write_int(ctx
, KEY_FLAGS
, cInfo
->flags
);
3084 saxdb_write_int(ctx
, KEY_CAPSMIN
, cInfo
->capsmin
);
3086 if(cInfo
->capspercent
)
3087 saxdb_write_int(ctx
, KEY_CAPSPERCENT
, cInfo
->capspercent
);
3089 if(cInfo
->exceptlevel
)
3090 saxdb_write_int(ctx
, KEY_EXCEPTLEVEL
, cInfo
->exceptlevel
);
3092 if(cInfo
->exceptadvlevel
)
3093 saxdb_write_int(ctx
, KEY_EXCEPTADVLEVEL
, cInfo
->exceptadvlevel
);
3095 if(cInfo
->exceptbadwordlevel
)
3096 saxdb_write_int(ctx
, KEY_EXCEPTBADWORDLEVEL
, cInfo
->exceptbadwordlevel
);
3098 if(cInfo
->exceptcapslevel
)
3099 saxdb_write_int(ctx
, KEY_EXCEPTCAPSLEVEL
, cInfo
->exceptcapslevel
);
3101 if(cInfo
->exceptfloodlevel
)
3102 saxdb_write_int(ctx
, KEY_EXCEPTFLOODLEVEL
, cInfo
->exceptfloodlevel
);
3104 if(cInfo
->exceptspamlevel
)
3105 saxdb_write_int(ctx
, KEY_EXCEPTSPAMLEVEL
, cInfo
->exceptspamlevel
);
3107 saxdb_write_string(ctx
, KEY_INFO
, cInfo
->info
);
3109 if(cInfo
->suspend_expiry
)
3110 saxdb_write_int(ctx
, KEY_EXPIRY
, cInfo
->suspend_expiry
);
3112 saxdb_end_record(ctx
);
3118 spamserv_conf_read(void)
3123 if(!(conf_node
= conf_get_data(SPAMSERV_CONF_NAME
, RECDB_OBJECT
)))
3125 log_module(SS_LOG
, LOG_ERROR
, "config node `%s' is missing or has wrong type.", SPAMSERV_CONF_NAME
);
3129 str
= database_get_data(conf_node
, KEY_DEBUG_CHANNEL
, RECDB_QSTRING
);
3133 spamserv_conf
.debug_channel
= AddChannel(str
, now
, "+tinms", NULL
, NULL
);
3135 if(spamserv_conf
.debug_channel
)
3136 spamserv_join_channel(spamserv_conf
.debug_channel
);
3140 spamserv_conf
.debug_channel
= NULL
;
3143 spamserv_conf
.global_exceptions
= database_get_data(conf_node
, KEY_GLOBAL_EXCEPTIONS
, RECDB_STRING_LIST
);
3145 spamserv_conf
.global_badwords
= database_get_data(conf_node
, KEY_GLOBAL_BADWORDS
, RECDB_STRING_LIST
);
3147 str
= database_get_data(conf_node
, KEY_NETWORK_RULES
, RECDB_QSTRING
);
3148 spamserv_conf
.network_rules
= str
? str
: NULL
;
3150 str
= database_get_data(conf_node
, KEY_TRIGGER
, RECDB_QSTRING
);
3151 spamserv_conf
.trigger
= str
? str
[0] : 0;
3153 str
= database_get_data(conf_node
, KEY_SHORT_BAN_DURATION
, RECDB_QSTRING
);
3154 spamserv_conf
.short_ban_duration
= str
? ParseInterval(str
) : ParseInterval("15m");
3156 str
= database_get_data(conf_node
, KEY_LONG_BAN_DURATION
, RECDB_QSTRING
);
3157 spamserv_conf
.long_ban_duration
= str
? ParseInterval(str
) : ParseInterval("1h");
3159 str
= database_get_data(conf_node
, KEY_GLINE_DURATION
, RECDB_QSTRING
);
3160 spamserv_conf
.gline_duration
= str
? ParseInterval(str
) : ParseInterval("1h");
3162 str
= database_get_data(conf_node
, KEY_EXCEPTION_MAX
, RECDB_QSTRING
);
3163 spamserv_conf
.exception_max
= str
? strtoul(str
, NULL
, 0) : 10;
3165 str
= database_get_data(conf_node
, KEY_EXCEPTION_MIN_LEN
, RECDB_QSTRING
);
3166 spamserv_conf
.exception_min_len
= str
? strtoul(str
, NULL
, 0) : 4;
3168 str
= database_get_data(conf_node
, KEY_EXCEPTION_MAX_LEN
, RECDB_QSTRING
);
3169 spamserv_conf
.exception_max_len
= str
? strtoul(str
, NULL
, 0) : 15;
3171 str
= database_get_data(conf_node
, KEY_BADWORD_MAX
, RECDB_QSTRING
);
3172 spamserv_conf
.badword_max
= str
? strtoul(str
, NULL
, 0) : 10;
3174 str
= database_get_data(conf_node
, KEY_BADWORD_MIN_LEN
, RECDB_QSTRING
);
3175 spamserv_conf
.badword_min_len
= str
? strtoul(str
, NULL
, 0) : 4;
3177 str
= database_get_data(conf_node
, KEY_BADWORD_MAX_LEN
, RECDB_QSTRING
);
3178 spamserv_conf
.badword_max_len
= str
? strtoul(str
, NULL
, 0) : 15;
3180 str
= database_get_data(conf_node
, KEY_ADV_CHAN_MUST_EXIST
, RECDB_QSTRING
);
3181 spamserv_conf
.adv_chan_must_exist
= str
? enabled_string(str
) : 1;
3183 str
= database_get_data(conf_node
, KEY_STRIP_MIRC_CODES
, RECDB_QSTRING
);
3184 spamserv_conf
.strip_mirc_codes
= str
? enabled_string(str
) : 0;
3186 str
= database_get_data(conf_node
, KEY_ALLOW_MOVE_MERGE
, RECDB_QSTRING
);
3187 spamserv_conf
.allow_move_merge
= str
? enabled_string(str
) : 0;
3191 spamserv_db_cleanup(void)
3195 while((it
= dict_first(registered_channels_dict
)))
3197 spamserv_unregister_channel(iter_data(it
));
3200 /* now handled automatically
3201 * while((it = dict_first(killed_users_dict)))
3203 free(iter_data(it));
3207 dict_delete(registered_channels_dict
);
3208 dict_delete(connected_users_dict
);
3209 dict_delete(killed_users_dict
);
3210 dict_delete(spamserv_trusted_accounts
);
3214 init_spamserv(const char *nick
)
3216 struct chanNode
*chan
;
3222 const char *modes
= conf_get_data("services/spamserv/modes", RECDB_QSTRING
);
3223 spamserv
= AddService(nick
, modes
? modes
: NULL
, "Anti Spam Services", NULL
);
3224 spamserv_service
= service_register(spamserv
);
3226 conf_register_reload(spamserv_conf_read
);
3228 SS_LOG
= log_register_type("SpamServ", "file:spamserv.log");
3230 /* auto-free the keys for these dicts,
3231 * and auto-free the keys AND data for killed_users_dict.
3232 * other data need free'd manually. */
3233 registered_channels_dict
= dict_new();
3234 dict_set_free_keys(registered_channels_dict
, free
);
3235 connected_users_dict
= dict_new();
3236 dict_set_free_keys(connected_users_dict
, free
);
3237 killed_users_dict
= dict_new();
3238 dict_set_free_keys(killed_users_dict
, free
);
3239 dict_set_free_data(killed_users_dict
, free
);
3240 spamserv_trusted_accounts
= dict_new();
3241 dict_set_free_keys(spamserv_trusted_accounts
, free
);
3242 dict_set_free_data(spamserv_trusted_accounts
, free
);
3244 saxdb_register("SpamServ", spamserv_saxdb_read
, spamserv_saxdb_write
);
3246 reg_new_user_func(spamserv_new_user_func
);
3247 reg_del_user_func(spamserv_del_user_func
);
3248 reg_nick_change_func(spamserv_nick_change_func
);
3249 reg_join_func(spamserv_user_join
);
3250 reg_part_func(spamserv_user_part
);
3252 timeq_add(now
+ FLOOD_TIMEQ_FREQ
, timeq_flood
, NULL
);
3253 timeq_add(now
+ JOINFLOOD_TIMEQ_FREQ
, timeq_joinflood
, NULL
);
3254 timeq_add(now
+ ADV_TIMEQ_FREQ
, timeq_adv
, NULL
);
3255 timeq_add(now
+ BAD_TIMEQ_FREQ
, timeq_bad
, NULL
);
3256 timeq_add(now
+ CAPS_TIMEQ_FREQ
, timeq_caps
, NULL
);
3257 timeq_add(now
+ WARNLEVEL_TIMEQ_FREQ
, timeq_warnlevel
, NULL
);
3258 timeq_add(now
+ KILL_TIMEQ_FREQ
, timeq_kill
, NULL
);
3260 spamserv_module
= module_register("SpamServ", SS_LOG
, "spamserv.help", NULL
);
3262 modcmd_register(spamserv_module
, "ADDTRUST", cmd_addtrust
, 3, MODCMD_REQUIRE_AUTHED
, "flags", "+acceptchan", NULL
);
3263 modcmd_register(spamserv_module
, "DELTRUST", cmd_deltrust
, 3, MODCMD_REQUIRE_AUTHED
, "flags", "+acceptchan", NULL
);
3264 modcmd_register(spamserv_module
, "OADDTRUST", cmd_oaddtrust
, 3, MODCMD_REQUIRE_AUTHED
, "flags", "+acceptchan,+helping", NULL
);
3265 modcmd_register(spamserv_module
, "ODELTRUST", cmd_odeltrust
, 3, MODCMD_REQUIRE_AUTHED
, "flags", "+acceptchan,+helping", NULL
);
3266 modcmd_register(spamserv_module
, "LISTTRUST", cmd_listtrust
, 2, MODCMD_REQUIRE_AUTHED
, NULL
);
3267 modcmd_register(spamserv_module
, "REGISTER", cmd_register
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, "flags", "+acceptchan,+helping", NULL
);
3268 modcmd_register(spamserv_module
, "UNREGISTER", cmd_unregister
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, "flags", "+loghostmask", NULL
);
3269 modcmd_register(spamserv_module
, "ADDEXCEPTION", cmd_addexception
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3270 modcmd_register(spamserv_module
, "DELEXCEPTION", cmd_delexception
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3271 modcmd_register(spamserv_module
, "ADDBADWORD", cmd_addbadword
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3272 modcmd_register(spamserv_module
, "DELBADWORD", cmd_delbadword
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3273 modcmd_register(spamserv_module
, "STATUS", cmd_status
, 1, 0, NULL
);
3274 modcmd_register(spamserv_module
, "SET", cmd_set
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3275 modcmd_register(spamserv_module
, "SET EXCEPTLEVEL", opt_exceptlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3276 modcmd_register(spamserv_module
, "SET EXCEPTADVLEVEL", opt_exceptadvlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3277 modcmd_register(spamserv_module
, "SET EXCEPTBADWORDLEVEL", opt_exceptbadwordlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3278 modcmd_register(spamserv_module
, "SET EXCEPTCAPSLEVEL", opt_exceptcapslevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3279 modcmd_register(spamserv_module
, "SET EXCEPTFLOODLEVEL", opt_exceptfloodlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3280 modcmd_register(spamserv_module
, "SET EXCEPTSPAMLEVEL", opt_exceptspamlevel
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3281 modcmd_register(spamserv_module
, "SET SPAMLIMIT", opt_spamlimit
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3282 modcmd_register(spamserv_module
, "SET BADREACTION", opt_badreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3283 modcmd_register(spamserv_module
, "SET CAPSREACTION", opt_capsreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3284 modcmd_register(spamserv_module
, "SET ADVREACTION", opt_advreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3285 modcmd_register(spamserv_module
, "SET WARNREACTION", opt_warnreaction
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3286 modcmd_register(spamserv_module
, "SET ADVSCAN", opt_advscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3287 modcmd_register(spamserv_module
, "SET CAPSSCAN", opt_capsscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3288 modcmd_register(spamserv_module
, "SET BADWORDSCAN", opt_badwordscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3289 modcmd_register(spamserv_module
, "SET SPAMSCAN", opt_spamscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3290 modcmd_register(spamserv_module
, "SET CHANFLOODSCAN", opt_chanfloodscan
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3291 modcmd_register(spamserv_module
, "SET JOINFLOODSCAN", opt_joinflood
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3292 modcmd_register(spamserv_module
, "SET CAPSMIN", opt_capsmin
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3293 modcmd_register(spamserv_module
, "SET CAPSPERCENT", opt_capspercent
, 1, MODCMD_REQUIRE_AUTHED
|MODCMD_REQUIRE_CHANNEL
, NULL
);
3295 spamserv_service
->trigger
= spamserv_conf
.trigger
;
3298 if (autojoin_channels
&& spamserv
) {
3299 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
3300 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
3301 AddChannelUser(spamserv
, chan
)->modes
|= MODE_CHANOP
;
3305 reg_exit_func(spamserv_db_cleanup
);
3306 message_register_table(msgtab
);