Browse Source

+ 'log events' csocket command

master
Alex 'AdUser' Z 4 years ago
parent
commit
1bae05c92d
  1. 8
      src/commands.c
  2. 1
      src/commands.h
  3. 15
      src/csocket.c
  4. 1
      src/csocket.h

8
src/commands.c

@ -50,6 +50,11 @@ struct cmd_desc {
.argc = 1, .tokenc = 3,
.tokens = { "log", "level", "<level>", NULL },
.help = "Change maximum level of logged messages",
}, {
.type = CMD_LOG_EVENTS,
.argc = 1, .tokenc = 3,
.tokens = { "log", "events", "<bool>", NULL },
.help = "Enable/disable sending events to connected client",
}, {
.type = CMD_JAIL_STATUS,
.argc = 1, .tokenc = 3,
@ -224,6 +229,9 @@ f2b_cmd_parse(f2b_cmd_t *cmd, const char *src) {
if (cmd->argc == 3 && strcmp(cmd->args[1], "level") == 0) {
cmd->type = CMD_LOG_LEVEL; return true;
}
if (cmd->argc == 3 && strcmp(cmd->args[1], "events") == 0) {
cmd->type = CMD_LOG_EVENTS; return true;
}
}
cmd->type = CMD_UNKNOWN;
f2b_buf_free(&cmd->data);

1
src/commands.h

@ -26,6 +26,7 @@ enum f2b_command_type {
/* logging */
CMD_LOG_ROTATE, /**< reopen logfile. (only for `logdest = file`) */
CMD_LOG_LEVEL, /**< change maximum level of logged messages */
CMD_LOG_EVENTS, /**< enable/disable sending events to connected client */
/* jail commands */
CMD_JAIL_STATUS, /**< show status of given jail */
CMD_JAIL_SET, /**< set parameter of given jail */

15
src/csocket.c

@ -131,6 +131,19 @@ f2b_conn_check_auth(f2b_conn_t *conn, f2b_cmd_t *cmd) {
return false;
}
void
f2b_conn_events(f2b_conn_t *conn, f2b_cmd_t *cmd) {
if (strcmp(cmd->args[2], "on") == 0 ||
strcmp(cmd->args[2], "yes") == 0 ||
strcmp(cmd->args[2], "true") == 0) {
conn->flags |= CSOCKET_CONN_EVENTS;
f2b_buf_append(&conn->send, "+events on\n", 0);
} else {
conn->flags &= ~CSOCKET_CONN_EVENTS;
f2b_buf_append(&conn->send, "+events off\n", 0);
}
}
int
f2b_conn_process(f2b_conn_t *conn, bool in, void (*cb)(const f2b_cmd_t *cmd, f2b_buf_t *res)) {
f2b_cmd_t *cmd = NULL;
@ -171,6 +184,8 @@ f2b_conn_process(f2b_conn_t *conn, bool in, void (*cb)(const f2b_cmd_t *cmd, f2b
if ((cmd = f2b_cmd_create(line)) != NULL) {
if (cmd->type == CMD_AUTH) {
f2b_conn_check_auth(conn, cmd);
} else if (cmd->type == CMD_LOG_EVENTS) {
f2b_conn_events(conn, cmd);
} else if (conn->flags & CSOCKET_CONN_AUTH_OK) {
cb(cmd, &conn->send); /* handle command */
} else {

1
src/csocket.h

@ -15,6 +15,7 @@
#define CSOCKET_CONN_TYPE_UNIX 0x01
#define CSOCKET_CONN_TYPE_INET 0x02
#define CSOCKET_CONN_AUTH_OK 0x04
#define CSOCKET_CONN_EVENTS 0x08
/**
* @file

Loading…
Cancel
Save