added alert for badwords
authorNurPech <nurpech@nurpech.de>
Sun, 19 May 2013 23:45:35 +0000 (01:45 +0200)
committerNurPech <nurpech@nurpech.de>
Sun, 19 May 2013 23:45:35 +0000 (01:45 +0200)
src/mod-watchdog.c

index c70ab70233be1094e17cadbd6224e93cbe5e13d9..ba8bc5988f2ae9584550dc74ee7a8c0c33f90040 100644 (file)
@@ -43,6 +43,7 @@
 #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"
 
@@ -59,6 +60,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_ALERT", "%s used badword '%s' in channel: %s" },
     { NULL, NULL }
 };
 
@@ -67,6 +69,7 @@ struct badword {
     char *badword_mask;
     unsigned int triggered : 29;
     unsigned int action : 3;
+    unsigned int alert;
 };
 
 struct watchdog_channel {
@@ -175,6 +178,15 @@ static MODCMD_FUNC(cmd_setbad)
                  } else {
                     reply("WDMSG_BADWORD_SET_INVALID", setting);
                  }
+            }
+            else if(!strcmp("ALERT",setting)) {
+                if (!strcmp("0",value)) {
+                       badword->alert = 0;
+                } else if (!strcmp("1",value)) {
+                       badword->alert = 1;
+                } else {
+                       reply("WDMSG_BADWORD_SET_INVALID", setting);
+                }
             } else {
                  reply("WDMSG_BADWORD_SETTING_INVALID", setting);
             }
@@ -226,7 +238,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 +247,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 +284,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)
@@ -368,6 +382,9 @@ 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, "WDMSG_BADWORD_ALERT", user->nick, badword->badword_mask, channel->name);
+       }
                switch(badword->action) {
                        case BADACTION_BAN:
                                hostmask = generate_hostmask(user, GENMASK_STRICT_HOST | GENMASK_ANY_IDENT);
@@ -419,7 +436,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 +452,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;
 }
@@ -525,8 +543,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 +598,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);
             }