X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fmod-watchdog.c;h=0edf09dfb5cec806111b9e91cf6809ab70f38d03;hb=HEAD;hp=c70ab70233be1094e17cadbd6224e93cbe5e13d9;hpb=ba891f830590ca957720345fd9dd66dfccc54c1f;p=srvx.git diff --git a/src/mod-watchdog.c b/src/mod-watchdog.c index c70ab70..0edf09d 100644 --- a/src/mod-watchdog.c +++ b/src/mod-watchdog.c @@ -43,11 +43,13 @@ #define KEY_BADWORD_MASK "mask" #define KEY_BADWORD_TRIGGERED "count" #define KEY_BADWORD_ACTION "action" +#define KEY_BADWOR_ALERT "alert" #define KEY_CHANNELS "channel" #define KEY_BADWORDID "badwordid" static const struct message_entry msgtab[] = { { "WDMSG_REGISTER_SUCCESS", "$b%s$b is now registered with %s." }, + { "WDMSG_UNREG_SUCCESS", "$b%s$b is now unregistered." }, { "WDMSG_NOT_REGISTERED", "$b%s$b is not registered with %s." }, { "WDMSG_ALREADY_ADDED", "$b%s$b is already added. (ID: %s)" }, { "WDMSG_BADWORD_ADDED", "added '$b%s$b' to the badword list with ID %s." }, @@ -59,6 +61,7 @@ static const struct message_entry msgtab[] = { { "WDMSG_BADWORD_SET", "Settings for BadWord entry $b%s$b" }, { "WDMSG_BADWORD_SET_MASK", "$bMASK$b: %s" }, { "WDMSG_BADWORD_SET_ACTION", "$bACTION$b: %s" }, + { "WDMSG_BADWORD_SET_ALERT", "$bALERT$b: %d" }, { NULL, NULL } }; @@ -67,6 +70,7 @@ struct badword { char *badword_mask; unsigned int triggered : 29; unsigned int action : 3; + unsigned int alert; }; struct watchdog_channel { @@ -80,12 +84,18 @@ struct watchdog_channel { #define BADACTION_KILL 2 #define BADACTION_GLINE 3 +#define WDMSG_BADWORD_ALERT "%s used badword '%s' in channel: %s." +#define WDMSG_REGISTER_SUCCESS "$b%s$b is now registered with %s by %s." +#define WDMSG_UNREG_SUCCESS "$b%s$b is now unregistered by %s." + static struct { const char *nick; const char *modes; const char *punishment_reason; unsigned long ban_duration; unsigned long gline_duration; + struct chanNode *alert_channel; + struct chanNode *oper_channel; } watchdog_conf; const char *watchdog_module_deps[] = { NULL }; @@ -98,8 +108,10 @@ static struct log_type *MS_LOG; static unsigned int last_badword_id = 0; static struct watchdog_channel *add_channel(const char *name); -static struct badword *add_badword(const char *badword_mask, unsigned int triggered, unsigned int action, const char *id); +static struct badword *add_badword(const char *badword_mask, unsigned int triggered, unsigned int action, unsigned int alert, const char *id); #define watchdog_notice(target, format...) send_message(target , watchdog , ## format) +#define watchdog_debug(format...) do { if(watchdog_conf.alert_channel) send_channel_message(watchdog_conf.alert_channel , watchdog , ## format); } while(0) +#define watchdog_oper_message(format...) do { if(watchdog_conf.oper_channel) send_channel_message(watchdog_conf.oper_channel , watchdog , ## format); } while(0) static MODCMD_FUNC(cmd_addbad) { @@ -113,7 +125,7 @@ static MODCMD_FUNC(cmd_addbad) } } - struct badword *new_badword = add_badword(mask, 0, BADACTION_KICK, NULL); + struct badword *new_badword = add_badword(mask, 0, BADACTION_KICK, 0, NULL); for (it = dict_first(shitlist); it; it = iter_next(it)) { struct badword *badword = iter_data(it); if(match_ircglob(badword->badword_mask, new_badword->badword_mask) && badword != new_badword) { @@ -175,6 +187,17 @@ static MODCMD_FUNC(cmd_setbad) } else { reply("WDMSG_BADWORD_SET_INVALID", setting); } + } + else if(!strcmp("ALERT",setting)) { + if (!strcmp("0",value)) { + badword->alert = 0; + reply("WDMSG_BADWORD_SET_DONE"); + } else if (!strcmp("1",value)) { + badword->alert = 1; + reply("WDMSG_BADWORD_SET_DONE"); + } else { + reply("WDMSG_BADWORD_SET_INVALID", setting); + } } else { reply("WDMSG_BADWORD_SETTING_INVALID", setting); } @@ -198,6 +221,7 @@ static MODCMD_FUNC(cmd_setbad) default: reply("WDMSG_BADWORD_SET_ACTION", "*undef*"); } + reply("WDMSG_BADWORD_SET_ALERT", badword->alert); } } else { reply("WDMSG_BADWORD_NOT_FOUND", argv[1]); @@ -226,7 +250,7 @@ static MODCMD_FUNC(cmd_listbad) count++; } tbl.length = count+1; - tbl.width = 4; + tbl.width = 5; tbl.flags = 0; tbl.flags = TABLE_NO_FREE; tbl.contents = malloc(tbl.length * sizeof(tbl.contents[0])); @@ -235,6 +259,7 @@ static MODCMD_FUNC(cmd_listbad) tbl.contents[0][1] = "Badword"; tbl.contents[0][2] = "Action"; tbl.contents[0][3] = "(Triggered)"; + tbl.contents[0][4] = "Alert"; if(!count) { table_send(cmd->parent->bot, user->nick, 0, NULL, tbl); @@ -271,6 +296,7 @@ static MODCMD_FUNC(cmd_listbad) tbl.contents[ii][2] = "*undef*"; } tbl.contents[ii][3] = strtab(bw->triggered); + tbl.contents[ii][4] = strtab(bw->alert); } table_send(cmd->parent->bot, user->nick, 0, NULL, tbl); for(ii = 1; ii < tbl.length; ++ii) @@ -332,6 +358,7 @@ static MODCMD_FUNC(cmd_register) add_channel(channel->name); reply("WDMSG_REGISTER_SUCCESS", channel->name, watchdog->nick); + watchdog_oper_message(WDMSG_REGISTER_SUCCESS, channel->name, watchdog->nick, user->handle_info->handle); return 1; } @@ -353,6 +380,7 @@ static MODCMD_FUNC(cmd_unregister) DelChannelUser(watchdog, channel, reason, 0); dict_remove(chanlist, channel->name); reply("CSMSG_UNREG_SUCCESS", channel->name); + watchdog_oper_message(WDMSG_UNREG_SUCCESS, channel->name, user->handle_info->handle); return 1; } else { reply("WDMSG_NOT_REGISTERED", channel->name, watchdog->nick); @@ -368,6 +396,10 @@ watchdog_detected_badword(struct userNode *user, struct chanNode *chan, struct b char *reason = watchdog_conf.punishment_reason; char mask[IRC_NTOP_MAX_SIZE+3] = { '*', '@', '\0' }; if(!IsOper(user)) { + if(badword->alert == 1) { + log_module(MS_LOG, LOG_WARNING, "%s used badword '%s' in channel: %s", user->nick, badword->badword_mask, chan->name); + watchdog_debug(WDMSG_BADWORD_ALERT, user->nick, badword->badword_mask, chan->name); + } switch(badword->action) { case BADACTION_BAN: hostmask = generate_hostmask(user, GENMASK_STRICT_HOST | GENMASK_ANY_IDENT); @@ -419,7 +451,7 @@ watchdog_channel_message(struct userNode *user, struct chanNode *chan, const cha } static struct badword* -add_badword(const char *badword_mask, unsigned int triggered, unsigned int action, const char *id) +add_badword(const char *badword_mask, unsigned int triggered, unsigned int action, unsigned int alert, const char *id) { struct badword *badword; @@ -435,6 +467,7 @@ add_badword(const char *badword_mask, unsigned int triggered, unsigned int actio badword->badword_mask = strdup(badword_mask); badword->triggered = triggered; badword->action = action; + badword->alert = alert; dict_insert(shitlist, badword->id, badword); return badword; } @@ -509,7 +542,26 @@ watchdog_conf_read(void) str = database_get_data(conf_node, "punishment_reason", RECDB_QSTRING); watchdog_conf.punishment_reason = (str ? str : "Your message contained a forbidden word."); + + str = database_get_data(conf_node, "alert_chan", RECDB_QSTRING); + if(str) + { + watchdog_conf.alert_channel = AddChannel(str, now, "+tinms", NULL); + } + else + { + watchdog_conf.alert_channel = NULL; + } + str = database_get_data(conf_node, "oper_channel", RECDB_QSTRING); + if(str) + { + watchdog_conf.oper_channel = AddChannel(str, now, "+tinms", NULL); + } + else + { + watchdog_conf.oper_channel = NULL; + } } static int @@ -517,7 +569,7 @@ watchdog_saxdb_read_shitlist(const char *name, void *data, UNUSED_ARG(void *extr { struct record_data *rd = data; char *badword; - char *triggered, *action; + char *triggered, *action, *alert; if (rd->type == RECDB_OBJECT) { dict_t obj = GET_RECORD_OBJECT(rd); @@ -525,8 +577,9 @@ watchdog_saxdb_read_shitlist(const char *name, void *data, UNUSED_ARG(void *extr badword = database_get_data(obj, KEY_BADWORD_MASK, RECDB_QSTRING); triggered = database_get_data(obj, KEY_BADWORD_TRIGGERED, RECDB_QSTRING); action = database_get_data(obj, KEY_BADWORD_ACTION, RECDB_QSTRING); + alert = database_get_data(obj, KEY_BADWOR_ALERT, RECDB_QSTRING); - add_badword(badword, strtoul(triggered, NULL, 0), strtoul(action, NULL, 0), name); + add_badword(badword, strtoul(triggered, NULL, 0), strtoul(action, NULL, 0), strtoul(alert, NULL, 0), name); } return 0; } @@ -579,6 +632,7 @@ watchdog_saxdb_write(struct saxdb_context *ctx) saxdb_write_string(ctx, KEY_BADWORD_MASK, badword->badword_mask); saxdb_write_int(ctx, KEY_BADWORD_TRIGGERED, badword->triggered); saxdb_write_int(ctx, KEY_BADWORD_ACTION, badword->action); + saxdb_write_int(ctx, KEY_BADWOR_ALERT, badword->alert); saxdb_end_record(ctx); }