c70ab70233be1094e17cadbd6224e93cbe5e13d9
[srvx.git] / src / mod-watchdog.c
1 /* mod-watchdog.c - Watchdog module for srvx
2  * Copyright 2003-2004 Martijn Smit and srvx Development Team
3  *
4  * This file is part of srvx.
5  *
6  * srvx is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with srvx; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
19  */
20
21 /* Adds new section to srvx.conf:
22  * "modules" {
23  *     "watchdog" {
24  *         "nick" "Watchdog";
25  *         "modes" "+iok";
26            "ban_duration" "2h"; //only if the channel is registered with chanserv
27            "gline_duration" "1h";
28            "punishment_reason" "Your message contained a forbidden word.";
29  *     };
30  *  };
31  *
32  */
33
34 #include "chanserv.h"
35 #include "opserv.h"
36 #include "conf.h"
37 #include "modcmd.h"
38 #include "saxdb.h"
39 #include "timeq.h"
40 #include "gline.h"
41
42 #define KEY_BADWORDS "badwords"
43 #define KEY_BADWORD_MASK "mask"
44 #define KEY_BADWORD_TRIGGERED "count"
45 #define KEY_BADWORD_ACTION "action"
46 #define KEY_CHANNELS "channel"
47 #define KEY_BADWORDID "badwordid"
48
49 static const struct message_entry msgtab[] = {
50     { "WDMSG_REGISTER_SUCCESS", "$b%s$b is now registered with %s." },
51     { "WDMSG_NOT_REGISTERED", "$b%s$b is not registered with %s." },
52     { "WDMSG_ALREADY_ADDED", "$b%s$b is already added. (ID: %s)" },
53     { "WDMSG_BADWORD_ADDED", "added '$b%s$b' to the badword list with ID %s." },
54     { "WDMSG_BADWORD_NOT_FOUND", "badword with ID %s does not exist." },
55     { "WDMSG_BADWORD_REMOVED", "badword ID $b%s$b has been removed (mask: '%s')" },
56     { "WDMSG_BADWORD_SET_DONE", "Done." },
57     { "WDMSG_BADWORD_SET_INVALID", "Invalid Option for setting %s" },
58     { "OSMSG_BADWORD_SETTING_INVALID", "unknown setting $b%s$b." },
59     { "WDMSG_BADWORD_SET", "Settings for BadWord entry $b%s$b" },
60     { "WDMSG_BADWORD_SET_MASK",   "$bMASK$b:   %s" },
61     { "WDMSG_BADWORD_SET_ACTION", "$bACTION$b: %s" },
62     { NULL, NULL }
63 };
64
65 struct badword {
66     char *id;
67     char *badword_mask;
68     unsigned int triggered : 29;
69     unsigned int action : 3;
70 };
71
72 struct watchdog_channel {
73     struct chanNode *channel;
74     //struct shitList *shitlist;
75 };
76
77 /* badword.action fields */
78 #define BADACTION_KICK   0
79 #define BADACTION_BAN    1
80 #define BADACTION_KILL   2
81 #define BADACTION_GLINE  3
82
83 static struct {
84     const char *nick;
85     const char *modes;
86     const char *punishment_reason;
87     unsigned long ban_duration;
88     unsigned long gline_duration;
89 } watchdog_conf;
90
91 const char *watchdog_module_deps[] = { NULL };
92 struct userNode *watchdog;
93 static struct module *watchdog_module;
94 static struct service *watchdog_service;
95 static dict_t shitlist;
96 static dict_t chanlist;
97 static struct log_type *MS_LOG;
98 static unsigned int last_badword_id = 0;
99
100 static struct watchdog_channel *add_channel(const char *name);
101 static struct badword *add_badword(const char *badword_mask, unsigned int triggered, unsigned int action, const char *id);
102 #define watchdog_notice(target, format...) send_message(target , watchdog , ## format)
103
104 static MODCMD_FUNC(cmd_addbad)
105 {
106     dict_iterator_t it;
107     char *mask = unsplit_string(argv + 1, argc - 1, NULL);
108     for (it = dict_first(shitlist); it; it = iter_next(it)) {
109         struct badword *badword = iter_data(it);
110         if(match_ircglob(mask,badword->badword_mask)) {
111             reply("WDMSG_ALREADY_ADDED", mask, badword->id);
112             return 1;
113         }
114     }
115
116     struct badword *new_badword = add_badword(mask, 0, BADACTION_KICK, NULL);
117     for (it = dict_first(shitlist); it; it = iter_next(it)) {
118         struct badword *badword = iter_data(it);
119         if(match_ircglob(badword->badword_mask, new_badword->badword_mask) && badword != new_badword) {
120             dict_remove(shitlist, badword->id);
121         }
122     }
123
124     reply("WDMSG_BADWORD_ADDED", new_badword->badword_mask, new_badword->id);
125     return 1;
126 }
127
128 static MODCMD_FUNC(cmd_delbad)
129 {
130     unsigned int n;
131
132     for (n=1; n<argc; n++) {
133         struct badword *badword = dict_find(shitlist, argv[n], NULL);
134         if (!badword) {
135             reply("WDMSG_BADWORD_NOT_FOUND", argv[n]);
136             continue;
137         }
138         reply("WDMSG_BADWORD_REMOVED", argv[n], badword->badword_mask);
139         dict_remove(shitlist, argv[n]);
140     }
141     return 1;
142 }
143
144 static MODCMD_FUNC(cmd_setbad)
145 {
146     struct badword *badword;
147     if ((badword = dict_find(shitlist, argv[1], NULL))) {
148         if (argc > 3) {
149             unsigned int ii;
150             char *setting = argv[2];
151             char *value = argv[3];
152             for( ii = 0; setting[ ii ]; ii++)
153                 setting[ ii ] = toupper( setting[ ii ] );
154             for( ii = 0; value[ ii ]; ii++)
155                 value[ ii ] = toupper( value[ ii ] );
156             if(!strcmp("MASK",setting)) {
157                   free(badword->badword_mask);
158                   badword->badword_mask = strdup(argv[3]);
159                   badword->triggered = 0;
160                   reply("WDMSG_BADWORD_SET_DONE");
161             }
162             else if(!strcmp("ACTION",setting)) {
163                  if (!strcmp("1",value) || !strcmp("KICK",value)) {
164                     badword->action = BADACTION_KICK;
165                     reply("WDMSG_BADWORD_SET_DONE");
166                  } else if (!strcmp("2",value) || !strcmp("BAN",value)) {
167                     badword->action = BADACTION_BAN;
168                     reply("WDMSG_BADWORD_SET_DONE");
169                  } else if (!strcmp("3",value) || !strcmp("KILL",value)) {
170                     badword->action = BADACTION_KILL;
171                     reply("WDMSG_BADWORD_SET_DONE");
172                  } else if (!strcmp("4",value) || !strcmp("GLINE",value)) {
173                     badword->action = BADACTION_GLINE;
174                     reply("WDMSG_BADWORD_SET_DONE");
175                  } else {
176                     reply("WDMSG_BADWORD_SET_INVALID", setting);
177                  }
178             } else {
179                  reply("WDMSG_BADWORD_SETTING_INVALID", setting);
180             }
181             
182         } else {
183             reply("WDMSG_BADWORD_SET", badword->id);
184             reply("WDMSG_BADWORD_SET_MASK", badword->badword_mask);
185             switch(badword->action) {
186                 case BADACTION_KICK:
187                   reply("WDMSG_BADWORD_SET_ACTION", "KICK");
188                   break;
189                 case BADACTION_BAN:
190                   reply("WDMSG_BADWORD_SET_ACTION", "BAN");
191                   break;
192                 case BADACTION_KILL:
193                   reply("WDMSG_BADWORD_SET_ACTION", "KILL");
194                   break;
195                 case BADACTION_GLINE:
196                   reply("WDMSG_BADWORD_SET_ACTION", "GLINE");
197                   break;
198                 default:
199                   reply("WDMSG_BADWORD_SET_ACTION", "*undef*");
200             }
201         }
202     } else {
203         reply("WDMSG_BADWORD_NOT_FOUND", argv[1]);
204         return 0;
205     }
206     return 1;
207 }
208
209 int
210 badwords_sort(const void *pa, const void *pb)
211 {
212         struct badword *a = *(struct badword**)pa;
213         struct badword *b = *(struct badword**)pb;
214
215         return strtoul(a->id, NULL, 0) - strtoul(b->id, NULL, 0);
216 }
217
218 static MODCMD_FUNC(cmd_listbad)
219 {
220     struct helpfile_table tbl;
221     unsigned int count = 0, ii = 0;
222     struct badword **badwords;
223     
224     dict_iterator_t it;
225     for (it = dict_first(shitlist); it; it = iter_next(it)) {
226         count++;
227     }
228     tbl.length = count+1;
229     tbl.width = 4;
230     tbl.flags = 0;
231     tbl.flags = TABLE_NO_FREE;
232     tbl.contents = malloc(tbl.length * sizeof(tbl.contents[0]));
233     tbl.contents[0] = malloc(tbl.width * sizeof(tbl.contents[0][0]));
234     tbl.contents[0][0] = "#";
235     tbl.contents[0][1] = "Badword";
236     tbl.contents[0][2] = "Action";
237     tbl.contents[0][3] = "(Triggered)";
238     if(!count)
239     {
240         table_send(cmd->parent->bot, user->nick, 0, NULL, tbl);
241         reply("MSG_NONE");
242         free(tbl.contents[0]);
243         free(tbl.contents);
244         return 0;
245     }
246     badwords = alloca(count * sizeof(badwords[0]));
247     for (it = dict_first(shitlist); it; it = iter_next(it)) {
248         struct badword *bw = iter_data(it);
249         badwords[ii++] = bw;
250     }
251     qsort(badwords, count, sizeof(badwords[0]), badwords_sort);
252     for (ii = 1; ii <= count; ii++) {
253         struct badword *bw = badwords[ii-1];
254         tbl.contents[ii] = malloc(tbl.width * sizeof(tbl.contents[0][0]));
255         tbl.contents[ii][0] = strdup(bw->id);
256         tbl.contents[ii][1] = strdup(bw->badword_mask);
257         switch(bw->action) {
258             case BADACTION_KICK:
259               tbl.contents[ii][2] = "KICK";
260               break;
261             case BADACTION_BAN:
262               tbl.contents[ii][2] = "BAN";
263               break;
264             case BADACTION_KILL:
265               tbl.contents[ii][2] = "KILL";
266               break;
267             case BADACTION_GLINE:
268               tbl.contents[ii][2] = "GLINE";
269               break;
270             default:
271               tbl.contents[ii][2] = "*undef*";
272         }
273         tbl.contents[ii][3] = strtab(bw->triggered);
274     }
275     table_send(cmd->parent->bot, user->nick, 0, NULL, tbl);
276     for(ii = 1; ii < tbl.length; ++ii)
277     {
278         free(tbl.contents[ii]);
279     }
280     free(tbl.contents[0]);
281     free(tbl.contents);
282     return 1;
283 }
284
285 static MODCMD_FUNC(cmd_register)
286 {
287     dict_iterator_t it;
288     struct modeNode *mn;
289
290     if(channel)
291     {
292
293         if(channel->bad_channel)
294         {
295             reply("CSMSG_ILLEGAL_CHANNEL", channel->name);
296             return 0;
297         }
298
299         if(!IsHelping(user)
300            && (!(mn = GetUserMode(channel, user)) || !(mn->modes & MODE_CHANOP)))
301         {
302             reply("CSMSG_MUST_BE_OPPED", channel->name);
303             return 0;
304         }
305
306     }
307     else
308     {
309
310         if((argc < 2) || !IsChannelName(argv[1]))
311         {
312             reply("MSG_NOT_CHANNEL_NAME");
313             return 0;
314         }
315
316         if(opserv_bad_channel(argv[1]))
317         {
318             reply("CSMSG_ILLEGAL_CHANNEL", argv[1]);
319             return 0;
320         }
321
322         channel = AddChannel(argv[1], now, NULL, NULL);
323     }
324
325     for (it = dict_first(chanlist); it; it = iter_next(it)) {
326         struct watchdog_channel *chan = iter_data(it);
327         if(chan->channel == channel) {
328             reply("CSMSG_ALREADY_REGGED", channel->name);
329             return 0;
330         }
331     }
332
333     add_channel(channel->name);
334     reply("WDMSG_REGISTER_SUCCESS", channel->name, watchdog->nick);
335     return 1;
336 }
337
338 static MODCMD_FUNC(cmd_unregister)
339 {
340     struct watchdog_channel *chan = NULL;
341     dict_iterator_t it;
342     
343     for (it = dict_first(chanlist); it; it = iter_next(it)) {
344         chan = iter_data(it);
345         if(chan->channel == channel)
346             break;
347     }
348     
349     if(chan && chan->channel == channel) {
350         //found, unregister it!
351         char reason[MAXLEN];
352         sprintf(reason, "Unregistered by %s.", user->handle_info->handle);
353         DelChannelUser(watchdog, channel, reason, 0);
354         dict_remove(chanlist, channel->name);
355         reply("CSMSG_UNREG_SUCCESS", channel->name);
356         return 1;
357     } else {
358         reply("WDMSG_NOT_REGISTERED", channel->name, watchdog->nick);
359         return 0;
360     }
361
362 }
363
364 static void
365 watchdog_detected_badword(struct userNode *user, struct chanNode *chan, struct badword *badword) 
366 {
367     char *hostmask;
368     char *reason = watchdog_conf.punishment_reason;
369     char mask[IRC_NTOP_MAX_SIZE+3] = { '*', '@', '\0' };
370     if(!IsOper(user)) {
371                 switch(badword->action) {
372                         case BADACTION_BAN:
373                                 hostmask = generate_hostmask(user, GENMASK_STRICT_HOST | GENMASK_ANY_IDENT);
374                                 sanitize_ircmask(hostmask);
375                                 if(chan->channel_info) {
376                                         //registered channel
377                                         add_channel_ban(chan->channel_info, hostmask, watchdog->nick, now, now, now + watchdog_conf.ban_duration, reason);
378                                 }
379                                 struct mod_chanmode change;
380                                 mod_chanmode_init(&change);
381                                 change.argc = 1;
382                                 change.args[0].mode = MODE_BAN;
383                                 change.args[0].u.hostmask = hostmask;
384                                 mod_chanmode_announce(watchdog, chan, &change);
385                                 free(hostmask);
386
387                         case BADACTION_KICK:
388                                 if(GetUserMode(chan, user))
389                                         KickChannelUser(user, chan, watchdog, reason);
390                                 break;
391                         case BADACTION_KILL:
392                                 DelUser(user, watchdog, 1, reason);
393                                 break;
394                         case BADACTION_GLINE:
395                                 irc_ntop(mask + 2, sizeof(mask) - 2, &user->ip);
396                                 gline_add(watchdog->nick, mask, watchdog_conf.gline_duration, reason, now, now, 0, 1);
397                                 break;
398                         default:
399                                 //error?
400                                 break;
401                         }
402     }
403 }
404
405 static void
406 watchdog_channel_message(struct userNode *user, struct chanNode *chan, const char *text, UNUSED_ARG(struct userNode *bot), UNUSED_ARG(unsigned int is_notice))
407 {
408     dict_iterator_t it;
409
410     if(!watchdog || !dict_find(chanlist, chan->name, NULL))
411         return;
412
413     for (it = dict_first(shitlist); it; it = iter_next(it)) {
414         struct badword *badword = iter_data(it);
415         if(match_ircglob(text, badword->badword_mask)) {
416             watchdog_detected_badword(user, chan, badword);
417         }
418     }
419 }
420
421 static struct badword*
422 add_badword(const char *badword_mask, unsigned int triggered, unsigned int action, const char *id)
423 {
424     struct badword *badword;
425
426     badword = calloc(1, sizeof(*badword));
427     if (!badword)
428         return NULL;
429
430     if(!id) {
431         last_badword_id++;
432         badword->id = strtab(last_badword_id);
433     } else
434         badword->id = strdup(id);
435     badword->badword_mask = strdup(badword_mask);
436     badword->triggered = triggered;
437     badword->action = action;
438     dict_insert(shitlist, badword->id, badword);
439     return badword;
440 }
441
442 static void
443 free_shitlist_entry(void *data)
444 {
445     struct badword *badword = data;
446     free(badword->id);
447     free(badword->badword_mask);
448     free(badword);
449 }
450
451 static struct watchdog_channel*
452 add_channel(const char *name)
453 {
454     struct watchdog_channel *wc;
455     struct mod_chanmode *change;
456
457     if(!watchdog) //module disabled
458         return NULL;
459
460     wc = calloc(1, sizeof(*wc));
461     if (!wc)
462         return NULL;
463
464     wc->channel = AddChannel(name, now, NULL, NULL);
465     change = mod_chanmode_alloc(1);
466     change->argc = 1;
467     change->args[0].mode = MODE_CHANOP;
468     change->args[0].u.member = AddChannelUser(watchdog, wc->channel);
469     mod_chanmode_announce(watchdog, wc->channel, change);
470         mod_chanmode_free(change);
471     dict_insert(chanlist, wc->channel->name, wc);
472     return wc;
473 }
474
475 static void
476 free_chanlist_entry(void *data)
477 {
478     struct watchdog_channel *wc = data;
479     
480     free(wc);
481 }
482
483 static void
484 watchdog_conf_read(void)
485 {
486     dict_t conf_node;
487     const char *str;
488
489     str = "modules/watchdog";
490     if (!(conf_node = conf_get_data(str, RECDB_OBJECT))) {
491         log_module(MS_LOG, LOG_ERROR, "config node `%s' is missing or has wrong type.", str);
492         return;
493     }
494
495     str = database_get_data(conf_node, "nick", RECDB_QSTRING);
496     if(watchdog_conf.nick && strcmp(watchdog_conf.nick, str)) {
497         //nick changed
498     }
499     watchdog_conf.nick = str;
500     
501     str = database_get_data(conf_node, "modes", RECDB_QSTRING);
502     watchdog_conf.modes = (str ? str : NULL);
503     
504     str = database_get_data(conf_node, "ban_duration", RECDB_QSTRING);
505         watchdog_conf.ban_duration = str ? ParseInterval(str) : ParseInterval("2h");
506     
507     str = database_get_data(conf_node, "gline_duration", RECDB_QSTRING);
508         watchdog_conf.gline_duration = str ? ParseInterval(str) : ParseInterval("1h");
509     
510     str = database_get_data(conf_node, "punishment_reason", RECDB_QSTRING);
511         watchdog_conf.punishment_reason = (str ? str : "Your message contained a forbidden word.");
512     
513 }
514
515 static int
516 watchdog_saxdb_read_shitlist(const char *name, void *data, UNUSED_ARG(void *extra))
517 {
518     struct record_data *rd = data;
519     char *badword;
520     char *triggered, *action;
521
522      if (rd->type == RECDB_OBJECT) {
523         dict_t obj = GET_RECORD_OBJECT(rd);
524         /* new style structure */
525         badword = database_get_data(obj, KEY_BADWORD_MASK, RECDB_QSTRING);
526         triggered = database_get_data(obj, KEY_BADWORD_TRIGGERED, RECDB_QSTRING);
527         action = database_get_data(obj, KEY_BADWORD_ACTION, RECDB_QSTRING);
528
529         add_badword(badword, strtoul(triggered, NULL, 0), strtoul(action, NULL, 0), name);
530     }
531     return 0;
532 }
533
534 static int
535 watchdog_saxdb_read_chanlist(const char *name, void *data, UNUSED_ARG(void *extra))
536 {
537     struct record_data *rd = data;
538
539      if (rd->type == RECDB_OBJECT) {
540         //dict_t obj = GET_RECORD_OBJECT(rd);
541         /* nothing in here, yet */
542
543         add_channel(name);
544     }
545     return 0;
546 }
547
548 static int
549 watchdog_saxdb_read(struct dict *db)
550 {
551     struct dict *object;
552     char *str;
553     str = database_get_data(db, KEY_BADWORDID, RECDB_QSTRING);
554     last_badword_id = str ? strtoul(str, NULL, 0) : 0;
555
556     if ((object = database_get_data(db, KEY_BADWORDS, RECDB_OBJECT)))
557         dict_foreach(object, watchdog_saxdb_read_shitlist, NULL);
558
559     if ((object = database_get_data(db, KEY_CHANNELS, RECDB_OBJECT)))
560         dict_foreach(object, watchdog_saxdb_read_chanlist, NULL);
561
562     return 1;
563 }
564
565 static int
566 watchdog_saxdb_write(struct saxdb_context *ctx)
567 {
568     dict_iterator_t it;
569
570     saxdb_write_int(ctx, KEY_BADWORDID, last_badword_id);
571
572     if (dict_size(shitlist)) {
573         saxdb_start_record(ctx, KEY_BADWORDS, 1);
574         for (it = dict_first(shitlist); it; it = iter_next(it)) {
575             struct badword *badword = iter_data(it);
576             if(badword && badword->badword_mask) {
577                 saxdb_start_record(ctx, iter_key(it), 0);
578                 
579                 saxdb_write_string(ctx, KEY_BADWORD_MASK, badword->badword_mask);
580                 saxdb_write_int(ctx, KEY_BADWORD_TRIGGERED, badword->triggered);
581                 saxdb_write_int(ctx, KEY_BADWORD_ACTION, badword->action);
582                 
583                 saxdb_end_record(ctx);
584             }
585         }
586         saxdb_end_record(ctx);
587     }
588
589     if (dict_size(chanlist)) {
590         saxdb_start_record(ctx, KEY_CHANNELS, 1);
591         for (it = dict_first(chanlist); it; it = iter_next(it)) {
592             struct watchdog_channel *wc = iter_data(it);
593             if(wc && wc->channel && wc->channel->name) {
594                 saxdb_start_record(ctx, wc->channel->name, 0);
595                 //anything else?
596                 saxdb_end_record(ctx);
597             }
598         }
599         saxdb_end_record(ctx);
600     }
601     
602     return 0;
603 }
604
605 static void
606 watchdog_cleanup(void)
607 {
608     dict_delete(shitlist);
609     dict_delete(chanlist);
610 }
611
612 int
613 watchdog_init(void)
614 {
615     MS_LOG = log_register_type("Watchdog", "file:watchdog.log");
616     
617     /* set up shitlist dict */
618     dict_delete(shitlist);
619     shitlist = dict_new();
620     dict_set_free_data(shitlist, free_shitlist_entry);
621     /* set up chanlist dict */
622     dict_delete(chanlist);
623     chanlist = dict_new();
624     dict_set_free_data(chanlist, free_chanlist_entry);
625
626     const char *nick, *modes;
627     if((nick = conf_get_data("modules/watchdog/nick", RECDB_QSTRING))) {
628         modes = conf_get_data("modules/watchdog/modes", RECDB_QSTRING);
629         watchdog = AddLocalUser(nick, nick, NULL, "Watchdog Service", modes);
630         watchdog_service = service_register(watchdog);
631         watchdog_service->trigger = ',';
632         reg_allchanmsg_func(watchdog, watchdog_channel_message);
633     }
634
635     conf_register_reload(watchdog_conf_read);
636     reg_exit_func(watchdog_cleanup);
637     saxdb_register("Watchdog", watchdog_saxdb_read, watchdog_saxdb_write);
638
639     watchdog_module = module_register("Watchdog", MS_LOG, "mod-watchdog.help", NULL);
640     modcmd_register(watchdog_module, "addbad", cmd_addbad, 2, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
641     modcmd_register(watchdog_module, "delbad", cmd_delbad, 2, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
642     modcmd_register(watchdog_module, "setbad", cmd_setbad, 2, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
643     modcmd_register(watchdog_module, "listbad", cmd_listbad, 1, MODCMD_REQUIRE_AUTHED, "flags", "+oper", NULL);
644     modcmd_register(watchdog_module, "register", cmd_register, 1, MODCMD_REQUIRE_AUTHED, "flags", "+acceptchan,+helping", NULL);
645     modcmd_register(watchdog_module, "unregister", cmd_unregister, 1, MODCMD_REQUIRE_AUTHED | MODCMD_REQUIRE_CHANNEL, "flags", "+helping", NULL);
646     message_register_table(msgtab);
647
648     return 1;
649 }
650
651 int
652 watchdog_finalize(void) {
653     dict_t conf_node;
654     const char *str;
655
656     str = "modules/watchdog";
657     if (!(conf_node = conf_get_data(str, RECDB_OBJECT))) {
658         log_module(MS_LOG, LOG_ERROR, "config node `%s' is missing or has wrong type.", str);
659         return 0;
660     }
661
662     str = database_get_data(conf_node, "nick", RECDB_QSTRING);
663     if (str) watchdog_conf.nick = str;
664     
665     str = database_get_data(conf_node, "modes", RECDB_QSTRING);
666     if (str) watchdog_conf.modes = str;
667     
668     str = database_get_data(conf_node, "ban_duration", RECDB_QSTRING);
669         if (str) watchdog_conf.ban_duration = ParseInterval(str);
670     
671     str = database_get_data(conf_node, "gline_duration", RECDB_QSTRING);
672         if (str) watchdog_conf.gline_duration = ParseInterval(str);
673     
674     str = database_get_data(conf_node, "punishment_reason", RECDB_QSTRING);
675         if (str) watchdog_conf.punishment_reason = str;
676     
677     return 1;
678 }