added mod-watchdog (without any functions, yet)
authorpk910 <philipp@zoelle1.de>
Wed, 20 Jul 2011 20:23:00 +0000 (22:23 +0200)
committerpk910 <philipp@zoelle1.de>
Wed, 20 Jul 2011 20:58:15 +0000 (22:58 +0200)
src/Makefile.am
src/mod-watchdog.c [new file with mode: 0644]
src/mod-watchdog.help [new file with mode: 0644]

index 33d71ad34ebeae883c2725dfdd8a665b2c8c33e4..cdf6ae818dce7a44319a9f3aca288ab297251157 100644 (file)
@@ -13,6 +13,7 @@ noinst_DATA = \
        mail.help \
     spamserv.help \
        mod-helpserv.help \
+    mod-watchdog.help \
        mod-memoserv.help \
        mod-qserver.help \
        mod-snoop.help \
@@ -54,6 +55,7 @@ EXTRA_srvx_SOURCES = \
        proto-p10.c \
        mod-blacklist.c \
        mod-helpserv.c \
+    mod-watchdog.c \
        mod-memoserv.c \
        mod-qserver.c \
        mod-snoop.c \
diff --git a/src/mod-watchdog.c b/src/mod-watchdog.c
new file mode 100644 (file)
index 0000000..11d59c5
--- /dev/null
@@ -0,0 +1,246 @@
+/* mod-watchdog.c - Watchdog module for srvx
+ * Copyright 2003-2004 Martijn Smit and srvx Development Team
+ *
+ * This file is part of srvx.
+ *
+ * srvx is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with srvx; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
+ */
+
+/* Adds new section to srvx.conf:
+ * "modules" {
+ *     "watchdog" {
+ *         "nick" "Watchdog";
+ *         "modes" "+iok"
+ *     };
+ *  };
+ *
+ */
+
+#include "chanserv.h"
+#include "conf.h"
+#include "modcmd.h"
+#include "saxdb.h"
+#include "timeq.h"
+
+#define KEY_SENT "sent"
+
+static const struct message_entry msgtab[] = {
+    { "WDMSG_NULL", "null." },
+    { NULL, NULL }
+};
+
+struct badword {
+    char *badword_mask;
+    unsigned int triggered : 29;
+    unsigned int action : 3;
+};
+
+DECLARE_LIST(shitList, struct badword*);
+DEFINE_LIST(shitList, struct badword*)
+
+/* badword.action fields */
+#define BADACTION_KICK   1
+#define BADACTION_KILL   2
+#define BADACTION_GLINE  3
+
+static struct {
+    char *nick;
+    char *modes;
+} watchdog_conf;
+
+struct userNode *watchdog;
+static struct module *watchdog_module;
+static struct service *watchdog_service;
+static struct shitList *shitlist;
+
+
+static MODCMD_FUNC(cmd_addbad)
+{
+    //to be continued...
+    return 1;
+}
+
+static MODCMD_FUNC(cmd_delbad)
+{
+    //to be continued...
+    return 1;
+}
+
+static MODCMD_FUNC(cmd_editbad)
+{
+    //to be continued...
+    return 1;
+}
+
+static MODCMD_FUNC(cmd_listbad)
+{
+    //to be continued...
+    return 1;
+}
+
+static void
+watchdog_channel_message(struct userNode *user, struct chanNode *chan, const char *text, struct userNode *bot, unsigned int is_notice)
+{
+    //to be continued...
+}
+
+static struct badword*
+add_badword(char *badword, unsigned int triggered, unsigned int action)
+{
+    struct badword *badword;
+
+    badword = calloc(1, sizeof(*badword));
+    if (!badword)
+        return NULL;
+
+    badword->badword_mask = strdup(badword);
+    badword->triggered = triggered;
+    badword->action = action;
+    shitlist_append(&shitlist, badword);
+    return badword;
+}
+
+static void
+delete_badword(struct badword *badword)
+{
+    shitlist_remove(&shitlist, badword);
+    free(badword->badword_mask);
+    free(badword);
+}
+
+static void
+watchdog_conf_read(void)
+{
+    dict_t conf_node;
+    const char *str;
+
+    str = "modules/watchdog";
+    if (!(conf_node = conf_get_data(str, RECDB_OBJECT))) {
+        log_module(MS_LOG, LOG_ERROR, "config node `%s' is missing or has wrong type.", str);
+        return;
+    }
+
+    str = database_get_data(conf_node, "nick", RECDB_QSTRING);
+    if(watchdog_conf.nick && strcmp(watchdog_conf.nick, str)) {
+        //nick changed
+    }
+    watchdog_conf.nick = str;
+    
+    str = database_get_data(conf_node, "modes", RECDB_QSTRING);
+    watchdog_conf.modes = str;
+}
+
+static int
+watchdog_saxdb_read_shitlist(const char *name, void *data, UNUSED_ARG(void *extra))
+{
+    struct record_data *rd = data;
+    char *badword;
+    char *triggered, *action;
+
+     if (rd->type == RECDB_OBJECT) {
+        dict_t obj = GET_RECORD_OBJECT(rd);
+        /* new style structure */
+        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);
+
+        add_badword(badword, strtoul(triggered, NULL, 0), strtoul(action, NULL, 0));
+        return 1;
+    } else
+        return 0;
+}
+
+static int
+watchdog_saxdb_read(struct dict *db)
+{
+    struct dict *object;
+    if ((object = database_get_data(conf_db, KEY_BADWORDS, RECDB_OBJECT)))
+        dict_foreach(object, watchdog_saxdb_read_shitlist, NULL);
+}
+
+static int
+watchdog_saxdb_write(struct saxdb_context *ctx)
+{
+    struct badword *badword;
+    char str[17];
+    unsigned int id = 0, ii;
+
+    saxdb_start_record(ctx, KEY_BADWORDS, 1);
+    for (ii = 0; ii < ma->recvd.used; ++ii) {
+        badword = ma->recvd.list[ii];
+        snprintf(str, sizeof(str), "%x", id++);
+        saxdb_start_record(ctx, str, 0);
+        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_end_record(ctx);
+    }
+    saxdb_end_record(ctx);
+
+    return 0;
+}
+
+static void
+watchdog_cleanup(void)
+{
+    while (shitlist.used)
+        delete_badword(shitlist.list[0]);
+    shitlist_clean(&shitlist);
+}
+
+int
+watchdog_init(void)
+{
+    MS_LOG = log_register_type("Watchdog", "file:watchdog.log");
+    conf_register_reload(watchdog_conf_read);
+    reg_exit_func(watchdog_cleanup);
+    saxdb_register("Watchdog", watchdog_saxdb_read, watchdog_saxdb_write);
+
+    const char *nick, *modes;
+    if(nick = conf_get_data("services/spamserv/nick", RECDB_QSTRING)) {
+        modes = conf_get_data("services/spamserv/modes", RECDB_QSTRING);
+        spamserv = AddLocalUser(nick, nick, NULL, "Watchdog Service", modes);
+        spamserv_service = service_register(spamserv);
+        reg_allchanmsg_func(spamserv, watchdog_channel_message);
+    }
+
+    watchdog_module = module_register("Watchdog", MS_LOG, "mod-watchdog.help", NULL);
+    modcmd_register(watchdog_module, "addbad", cmd_addbad, 1, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
+    modcmd_register(watchdog_module, "delbad", cmd_delbad, 1, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
+    modcmd_register(watchdog_module, "editbad", cmd_editbad, 1, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
+    modcmd_register(watchdog_module, "listbad", cmd_listbad, 1, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
+    message_register_table(msgtab);
+
+    return 1;
+}
+
+int
+watchdog_finalize(void) {
+    dict_t conf_node;
+    const char *str;
+
+    str = "modules/watchdog";
+    if (!(conf_node = conf_get_data(str, RECDB_OBJECT))) {
+        log_module(MS_LOG, LOG_ERROR, "config node `%s' is missing or has wrong type.", str);
+        return 0;
+    }
+
+    str = database_get_data(conf_node, "nick", RECDB_QSTRING);
+    if (str) watchdog_conf.nick = str;
+    
+    str = database_get_data(conf_node, "modes", RECDB_QSTRING);
+    if (str) watchdog_conf.modes = str;
+    return 1;
+}
diff --git a/src/mod-watchdog.help b/src/mod-watchdog.help
new file mode 100644 (file)
index 0000000..0519ecb
--- /dev/null
@@ -0,0 +1 @@
\ No newline at end of file