Browse Source

* commands.[ch] : rename commands: regex stats -> filter stats, regex add -> filter reload

master
Alex 'AdUser' Z 8 years ago
parent
commit
aa37f6852a
  1. 31
      src/commands.c
  2. 4
      src/commands.h

31
src/commands.c

@ -79,15 +79,15 @@ struct f2b_cmd_t {
.tokens = { "jail", "<jailname>", "release", "<ip>", NULL },
.help = "Forcefully release some ip in given jail",
},
[CMD_JAIL_REGEX_STATS] = {
[CMD_JAIL_FILTER_STATS] = {
.argc = 1, .tokenc = 4,
.tokens = { "jail", "<jailname>", "regex", "stats", NULL },
.tokens = { "jail", "<jailname>", "filter", "stats", NULL },
.help = "Show matches stats for jail regexps",
},
[CMD_JAIL_REGEX_ADD] = {
.argc = 2, .tokenc = 5,
.tokens = { "jail", "<jailname>", "regex", "add", "<regex>", NULL },
.help = "Add new regexp to jail",
[CMD_JAIL_FILTER_RELOAD] = {
.argc = 2, .tokenc = 4,
.tokens = { "jail", "<jailname>", "filter", "reload", NULL },
.help = "Reload regexps for given jail",
},
};
@ -183,22 +183,11 @@ 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 == 4 && strcmp(tokens[2], "filter") == 0 && strcmp(tokens[3], "stats") == 0) {
return CMD_JAIL_FILTER_STATS;
}
if (tokenc >= 5 && strcmp(tokens[2], "regex") == 0 && strcmp(tokens[3], "add") == 0) {
/* TODO: rewrite, this version is very error-prone */
char *regex = strstr(src, "add");
regex += strlen("add");
while (isblank(*regex))
regex++;
if (*regex == '\0') {
/* empty regex */
return CMD_NONE;
}
strlcat(buf, regex, buflen);
strlcat(buf, "\n", buflen);
return CMD_JAIL_REGEX_ADD;
if (tokenc == 4 && strcmp(tokens[2], "filter") == 0 && strcmp(tokens[3], "reload") == 0) {
return CMD_JAIL_FILTER_RELOAD;
}
}

4
src/commands.h

@ -25,8 +25,8 @@ enum f2b_cmd_type {
CMD_JAIL_IP_SHOW,
CMD_JAIL_IP_BAN,
CMD_JAIL_IP_RELEASE,
CMD_JAIL_REGEX_STATS,
CMD_JAIL_REGEX_ADD,
CMD_JAIL_FILTER_STATS,
CMD_JAIL_FILTER_RELOAD,
CMD_MAX_NUMBER,
};

Loading…
Cancel
Save