diff --git a/src/cmsg.h b/src/cmsg.h index 457c2b5..f51cbb2 100644 --- a/src/cmsg.h +++ b/src/cmsg.h @@ -21,6 +21,8 @@ enum f2b_cmsg_type { CMD_JAIL_IP_STATUS, CMD_JAIL_IP_BAN, CMD_JAIL_IP_RELEASE, + CMD_JAIL_REGEX_STATS, + CMD_JAIL_REGEX_ADD, CMD_MAX_NUMBER, }; diff --git a/src/commands.c b/src/commands.c index e9140e7..1d262a0 100644 --- a/src/commands.c +++ b/src/commands.c @@ -65,6 +65,14 @@ struct f2b_cmd_t { .tokens = { "jail", "", "release", "", NULL }, .help = "Forcefully release some ip in given jail", }, + [CMD_JAIL_REGEX_STATS] = { + .tokens = { "jail", "", "regex", "stats", NULL }, + .help = "Show matches stats for jail regexps", + }, + [CMD_JAIL_REGEX_ADD] = { + .tokens = { "jail", "", "regex", "add", "", NULL }, + .help = "Add new regexp to jail", + }, }; void @@ -158,6 +166,14 @@ f2b_cmd_parse(const char *src, char *buf, size_t buflen) { strlcat(buf, "\n", buflen); 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; diff --git a/src/daemon.c b/src/daemon.c index 6c451b6..5b702ad 100644 --- a/src/daemon.c +++ b/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)); 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) { strlcpy(res, "can't find jail: no args\n", ressize); 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) { f2b_jail_unban(jail, addr); 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 { strlcpy(res, "error: unsupported command type", ressize); }