From 5844bb57b0548ef2211589bd045ff0eca55f2cf6 Mon Sep 17 00:00:00 2001 From: pk910 Date: Fri, 22 Jul 2011 02:41:52 +0200 Subject: [PATCH] added real message "scanner" to mod-watchdog.c --- src/mod-watchdog.c | 77 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/src/mod-watchdog.c b/src/mod-watchdog.c index 99527db..c114366 100644 --- a/src/mod-watchdog.c +++ b/src/mod-watchdog.c @@ -23,6 +23,9 @@ * "watchdog" { * "nick" "Watchdog"; * "modes" "+iok"; + "ban_duration" "2h"; //only if the channel is registered with chanserv + "gline_duration" "1h"; + "punishment_reason" "Your message contained a forbidden word."; * }; * }; * @@ -79,6 +82,9 @@ struct watchdog_channel { static struct { const char *nick; const char *modes; + const char *punishment_reason; + unsigned long ban_duration; + unsigned long gline_duration; } watchdog_conf; const char *watchdog_module_deps[] = { NULL }; @@ -331,9 +337,56 @@ static MODCMD_FUNC(cmd_unregister) } static void -watchdog_channel_message(struct userNode *user, struct chanNode *chan, const char *text, struct userNode *bot, unsigned int is_notice) +watchdog_detected_badword(struct userNode *user, struct chanNode *chan, struct badword *badword) { - //to be continued... + char *hostmask; + char *reason = watchdog_conf.punishment_reason; + switch(badword->action) { + case BADACTION_BAN: + hostmask = generate_hostmask(user, GENMASK_STRICT_HOST | GENMASK_ANY_IDENT); + sanitize_ircmask(hostmask); + if(chan->channel_info) { + //registered channel + add_channel_ban(chan->channel_info, hostmask, watchdog->nick, now, now, now + watchdog_conf.ban_duration, reason); + } + mod_chanmode_init(&change); + change.argc = 1; + change.args[0].mode = MODE_BAN; + change.args[0].u.hostmask = hostmask; + mod_chanmode_announce(watchdog, chan, &change); + free(hostmask); + + case BADACTION_KICK: + KickChannelUser(user, chan, watchdog, reason); + break; + case BADACTION_KILL: + DelUser(user, watchdog, 1, reason); + break; + case BADACTION_GLINE: + int size = strlen(user->hostname) + 3; + hostmask = alloca(size); + snprintf(hostmask, size, "*@%s", user->hostname); + gline_add(watchdog->nick, hostmask, watchdog_conf.gline_duration, reason, now, now, 0, 1); + break; + default: + //error? + } +} + +static void +watchdog_channel_message(struct userNode *user, struct chanNode *chan, const char *text, UNUSED_ARG(struct userNode *bot), UNUSED_ARG(unsigned int is_notice)) +{ + dict_iterator_t it; + + if(!watchdog) + return; + + for (it = dict_first(shitlist); it; it = iter_next(it)) { + struct badword *badword = iter_data(it); + if(match_ircglob(text, badword->badword_mask)) { + watchdog_detected_badword(user, chan, badword); + } + } } static struct badword* @@ -418,6 +471,16 @@ watchdog_conf_read(void) str = database_get_data(conf_node, "modes", RECDB_QSTRING); watchdog_conf.modes = (str ? str : NULL); + + str = database_get_data(conf_node, "ban_duration", RECDB_QSTRING); + watchdog_conf.ban_duration = str ? ParseInterval(str) : ParseInterval("2h"); + + str = database_get_data(conf_node, "gline_duration", RECDB_QSTRING); + watchdog_conf.gline_duration = str ? ParseInterval(str) : ParseInterval("1h"); + + str = database_get_data(conf_node, "punishment_reason", RECDB_QSTRING); + watchdog_conf.punishment_reason = (str ? str : "Your message contained a forbidden word."); + } static int @@ -569,5 +632,15 @@ watchdog_finalize(void) { str = database_get_data(conf_node, "modes", RECDB_QSTRING); if (str) watchdog_conf.modes = str; + + str = database_get_data(conf_node, "ban_duration", RECDB_QSTRING); + if (str) watchdog_conf.ban_duration = ParseInterval(str); + + str = database_get_data(conf_node, "gline_duration", RECDB_QSTRING); + if (str) watchdog_conf.gline_duration = ParseInterval(str); + + str = database_get_data(conf_node, "punishment_reason", RECDB_QSTRING); + if (str) watchdog_conf.punishment_reason = str; + return 1; } -- 2.20.1