Browse Source

* add 'jail regex stats' & 'jail regex add' commands

master
Alex 'AdUser' Z 8 years ago
parent
commit
53935abd77
  1. 2
      src/cmsg.h
  2. 16
      src/commands.c
  3. 14
      src/daemon.c

2
src/cmsg.h

@ -21,6 +21,8 @@ enum f2b_cmsg_type {
CMD_JAIL_IP_STATUS, CMD_JAIL_IP_STATUS,
CMD_JAIL_IP_BAN, CMD_JAIL_IP_BAN,
CMD_JAIL_IP_RELEASE, CMD_JAIL_IP_RELEASE,
CMD_JAIL_REGEX_STATS,
CMD_JAIL_REGEX_ADD,
CMD_MAX_NUMBER, CMD_MAX_NUMBER,
}; };

16
src/commands.c

@ -65,6 +65,14 @@ struct f2b_cmd_t {
.tokens = { "jail", "<jailname>", "release", "<ip>", NULL }, .tokens = { "jail", "<jailname>", "release", "<ip>", NULL },
.help = "Forcefully release some ip in given jail", .help = "Forcefully release some ip in given jail",
}, },
[CMD_JAIL_REGEX_STATS] = {
.tokens = { "jail", "<jailname>", "regex", "stats", NULL },
.help = "Show matches stats for jail regexps",
},
[CMD_JAIL_REGEX_ADD] = {
.tokens = { "jail", "<jailname>", "regex", "add", "<regex>", NULL },
.help = "Add new regexp to jail",
},
}; };
void void
@ -158,6 +166,14 @@ f2b_cmd_parse(const char *src, char *buf, size_t buflen) {
strlcat(buf, "\n", buflen); strlcat(buf, "\n", buflen);
return CMD_JAIL_IP_RELEASE; return CMD_JAIL_IP_RELEASE;
} }
if (tokenc == 4 && strcmp(tokens[2], "regex") == 0 && strcmp(tokens[3], "stats") == 0) {
return CMD_JAIL_REGEX_STATS;
}
if (tokenc == 5 && strcmp(tokens[2], "regex") == 0 && strcmp(tokens[3], "add") == 0) {
strlcat(buf, tokens[4], buflen);
strlcat(buf, "\n", buflen);
return CMD_JAIL_REGEX_ADD;
}
} }
return CMD_NONE; return CMD_NONE;

14
src/daemon.c

@ -99,7 +99,7 @@ f2b_cmsg_process(const f2b_cmsg_t *msg, char *res, size_t ressize) {
memset(args, 0x0, sizeof(args)); memset(args, 0x0, sizeof(args));
f2b_cmsg_extract_args(msg, args); f2b_cmsg_extract_args(msg, args);
if (msg->type >= CMD_JAIL_STATUS && msg->type <= CMD_JAIL_IP_RELEASE) { if (msg->type >= CMD_JAIL_STATUS && msg->type <= CMD_MAX_NUMBER) {
if (args[0] == NULL) { if (args[0] == NULL) {
strlcpy(res, "can't find jail: no args\n", ressize); strlcpy(res, "can't find jail: no args\n", ressize);
return; return;
@ -150,6 +150,18 @@ f2b_cmsg_process(const f2b_cmsg_t *msg, char *res, size_t ressize) {
} else if (msg->type == CMD_JAIL_IP_RELEASE) { } else if (msg->type == CMD_JAIL_IP_RELEASE) {
f2b_jail_unban(jail, addr); f2b_jail_unban(jail, addr);
strlcpy(res, "ok", ressize); strlcpy(res, "ok", ressize);
} else if (msg->type == CMD_JAIL_REGEX_STATS) {
f2b_filter_stats(jail->filter, res, ressize);
} else if (msg->type == CMD_JAIL_REGEX_ADD) {
if (args[1] == NULL) {
strlcpy(res, "can't find regex: no args", ressize);
return;
}
if (f2b_filter_append(jail->filter, args[1])) {
strlcpy(res, "ok", ressize);
} else {
strlcpy(res, f2b_filter_error(jail->filter), ressize);
}
} else { } else {
strlcpy(res, "error: unsupported command type", ressize); strlcpy(res, "error: unsupported command type", ressize);
} }

Loading…
Cancel
Save