]> jfr.im git - irc/quakenet/newserv.git/blame - rbl/rbl_commands.c
A4STATS: remove E style escapes and switch to createtable for indices
[irc/quakenet/newserv.git] / rbl / rbl_commands.c
CommitLineData
67af3857
GB
1#include <stdio.h>
2#include <string.h>
3#include "../core/hooks.h"
4#include "../control/control.h"
5#include "../irc/irc.h"
6#include "../lib/irc_string.h"
7#include "../lib/version.h"
8#include "rbl.h"
9
10MODULE_VERSION("");
11
12static int rbl_cmdlookuprbl(void *source, int cargc, char **cargv) {
13 nick *sender = source;
14 rbl_instance *rbl;
15 struct irc_in_addr ip;
16
17 if (cargc < 1)
18 return CMD_USAGE;
19
20 if (!ipmask_parse(cargv[0], &ip, NULL)) {
21 controlreply(sender, "Invalid IP address.");
22 return CMD_ERROR;
23 }
24
25 for (rbl = rbl_instances; rbl; rbl = rbl->next) {
26 char reason[255];
27 if (RBL_LOOKUP(rbl, &ip, reason, sizeof(reason)) <= 0)
28 continue;
29
30 controlreply(sender, "RBL: %s (%s)", rbl->name->content, reason);
31 }
32
33 controlreply(sender, "Done.");
34
35 return CMD_OK;
36}
37
38static int rbl_cmdlistrbl(void *source, int cargc, char **cargv) {
39 nick *sender = source;
40 rbl_instance *rbl;
41
42 for (rbl = rbl_instances; rbl; rbl = rbl->next)
43 controlreply(sender, "%s", rbl->name->content);
44
45 controlreply(sender, "End of list.");
46
47 return CMD_OK;
48}
49
50void _init(void) {
51 registercontrolhelpcmd("lookuprbl", NO_OPER, 1, &rbl_cmdlookuprbl, "Usage: lookuprbl <IP>\nLooks up whether RBL records exist for the specified IP address.");
52 registercontrolhelpcmd("listrbl", NO_OPER, 0, &rbl_cmdlistrbl, "Usage: listrbl\nLists RBLs.");
53}
54
55void _fini(void) {
56 deregistercontrolcmd("lookuprbl", &rbl_cmdlookuprbl);
57 deregistercontrolcmd("listrbl", &rbl_cmdlistrbl);
58}