From 1bae05c92d7dc8fc6a8a446e8fa8e4c8782f99eb Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Mon, 29 Mar 2021 16:55:05 +1000 Subject: [PATCH] + 'log events' csocket command --- src/commands.c | 8 ++++++++ src/commands.h | 1 + src/csocket.c | 15 +++++++++++++++ src/csocket.h | 1 + 4 files changed, 25 insertions(+) diff --git a/src/commands.c b/src/commands.c index 07c64b3..33c76be 100644 --- a/src/commands.c +++ b/src/commands.c @@ -50,6 +50,11 @@ struct cmd_desc { .argc = 1, .tokenc = 3, .tokens = { "log", "level", "", NULL }, .help = "Change maximum level of logged messages", + }, { + .type = CMD_LOG_EVENTS, + .argc = 1, .tokenc = 3, + .tokens = { "log", "events", "", 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); diff --git a/src/commands.h b/src/commands.h index 932a457..ad41c9e 100644 --- a/src/commands.h +++ b/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 */ diff --git a/src/csocket.c b/src/csocket.c index cd728fd..ea78748 100644 --- a/src/csocket.c +++ b/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 { diff --git a/src/csocket.h b/src/csocket.h index fdfb021..ba79f40 100644 --- a/src/csocket.h +++ b/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