Browse Source

* add 'jail $jail source stats' csocket command

master
Alex 'AdUser' Z 4 years ago
parent
commit
504b14c549
  1. 8
      src/commands.c
  2. 3
      src/commands.h
  3. 3
      src/daemon.c
  4. 8
      src/source.c
  5. 5
      src/source.h

8
src/commands.c

@ -70,6 +70,11 @@ struct cmd_desc {
.argc = 2, .tokenc = 5, .argc = 2, .tokenc = 5,
.tokens = { "jail", "<jailname>", "ip", "release", "<ip>", NULL }, .tokens = { "jail", "<jailname>", "ip", "release", "<ip>", NULL },
.help = "Forcefully release some ip in given jail", .help = "Forcefully release some ip in given jail",
}, {
.type = CMD_JAIL_SOURCE_STATS,
.argc = 1, .tokenc = 4,
.tokens = { "jail", "<jailname>", "source", "stats", NULL },
.help = "Show source stats for jail",
}, { }, {
.type = CMD_JAIL_FILTER_STATS, .type = CMD_JAIL_FILTER_STATS,
.argc = 1, .tokenc = 4, .argc = 1, .tokenc = 4,
@ -191,6 +196,9 @@ f2b_cmd_parse(f2b_cmd_t *cmd, const char *src) {
if (cmd->argc == 5 && strcmp(cmd->args[2], "ip") == 0 && strcmp(cmd->args[3], "release") == 0) { if (cmd->argc == 5 && strcmp(cmd->args[2], "ip") == 0 && strcmp(cmd->args[3], "release") == 0) {
cmd->type = CMD_JAIL_IP_RELEASE; return true; cmd->type = CMD_JAIL_IP_RELEASE; return true;
} }
if (cmd->argc == 4 && strcmp(cmd->args[2], "source") == 0 && strcmp(cmd->args[3], "stats") == 0) {
cmd->type = CMD_JAIL_SOURCE_STATS; return true;
}
if (cmd->argc == 4 && strcmp(cmd->args[2], "filter") == 0 && strcmp(cmd->args[3], "stats") == 0) { if (cmd->argc == 4 && strcmp(cmd->args[2], "filter") == 0 && strcmp(cmd->args[3], "stats") == 0) {
cmd->type = CMD_JAIL_FILTER_STATS; return true; cmd->type = CMD_JAIL_FILTER_STATS; return true;
} }

3
src/commands.h

@ -31,7 +31,8 @@ enum f2b_command_type {
CMD_JAIL_IP_STATUS, /**< show status of given ip */ CMD_JAIL_IP_STATUS, /**< show status of given ip */
CMD_JAIL_IP_BAN, /**< force ban given ip */ CMD_JAIL_IP_BAN, /**< force ban given ip */
CMD_JAIL_IP_RELEASE, /**< force unban given ip */ CMD_JAIL_IP_RELEASE, /**< force unban given ip */
CMD_JAIL_FILTER_STATS, /**< show stats of fileter matches */ CMD_JAIL_SOURCE_STATS, /**< show stats of source */
CMD_JAIL_FILTER_STATS, /**< show stats of filter matches */
CMD_JAIL_FILTER_RELOAD, /**< reload filter patterns from file */ CMD_JAIL_FILTER_RELOAD, /**< reload filter patterns from file */
CMD_MAX_NUMBER, /**< placeholder */ CMD_MAX_NUMBER, /**< placeholder */
}; };

3
src/daemon.c

@ -137,6 +137,9 @@ f2b_csocket_cmd_process(const f2b_cmd_t *cmd, f2b_buf_t *res) {
} else if (cmd->type == CMD_JAIL_IP_RELEASE) { } else if (cmd->type == CMD_JAIL_IP_RELEASE) {
f2b_jail_cmd_ip_xxx(buf, sizeof(buf), jail, -1, cmd->args[4]); f2b_jail_cmd_ip_xxx(buf, sizeof(buf), jail, -1, cmd->args[4]);
f2b_buf_append(res, buf, 0); f2b_buf_append(res, buf, 0);
} else if (cmd->type == CMD_JAIL_SOURCE_STATS) {
f2b_source_cmd_stats(buf, sizeof(buf), jail->source);
f2b_buf_append(res, buf, 0);
} else if (cmd->type == CMD_JAIL_FILTER_STATS) { } else if (cmd->type == CMD_JAIL_FILTER_STATS) {
f2b_filter_cmd_stats(buf, sizeof(buf), jail->filter); f2b_filter_cmd_stats(buf, sizeof(buf), jail->filter);
f2b_buf_append(res, buf, 0); f2b_buf_append(res, buf, 0);

8
src/source.c

@ -109,3 +109,11 @@ f2b_source_ ## CMD(f2b_source_t *source) { \
SOURCE_CMD_ARG0(start, bool) SOURCE_CMD_ARG0(start, bool)
SOURCE_CMD_ARG0(stop, bool) SOURCE_CMD_ARG0(stop, bool)
SOURCE_CMD_ARG0(ready, bool) SOURCE_CMD_ARG0(ready, bool)
void
f2b_source_cmd_stats(char *buf, size_t bufsize, f2b_source_t *source) {
assert(source != NULL);
assert(buf != NULL);
source->stats(source->cfg, buf, bufsize);
}

5
src/source.h

@ -76,4 +76,9 @@ bool f2b_source_next (f2b_source_t *s, char *buf, size_t bufsize, bool reset);
*/ */
bool f2b_source_stop (f2b_source_t *s); bool f2b_source_stop (f2b_source_t *s);
/* handlers for csocket commands processing */
/** handler of 'jail $JAIL source stats' cmd */
void f2b_source_cmd_stats (char *buf, size_t bufsize, f2b_source_t *f);
#endif /* F2B_SOURCE_H_ */ #endif /* F2B_SOURCE_H_ */

Loading…
Cancel
Save