summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2014-10-22 19:11:32 +0400
committerDmitry Kozlov <xeb@mail.ru>2014-10-22 19:11:39 +0400
commita3f7e7d1e26bcf1ddb4d86d06f8a3a976374eade (patch)
treeae0616177a6c4dfac89b2f4f34894b31b05ab61d
parentbaae559b6234f30fdb93697ae74833b678c94b5b (diff)
downloadaccel-ppp-a3f7e7d1e26bcf1ddb4d86d06f8a3a976374eade.tar.gz
accel-ppp-a3f7e7d1e26bcf1ddb4d86d06f8a3a976374eade.zip
cli: introduced verbose option
If verbose=0 then cli won't produce any logging if verbose=1 then log only connections if verbose=2 then log also executed commands
-rw-r--r--accel-pppd/accel-ppp.conf1
-rw-r--r--accel-pppd/accel-ppp.conf.55
-rw-r--r--accel-pppd/cli/tcp.c35
-rw-r--r--accel-pppd/cli/telnet.c39
4 files changed, 63 insertions, 17 deletions
diff --git a/accel-pppd/accel-ppp.conf b/accel-pppd/accel-ppp.conf
index 49d1fa9..93dca1f 100644
--- a/accel-pppd/accel-ppp.conf
+++ b/accel-pppd/accel-ppp.conf
@@ -219,6 +219,7 @@ down-limiter=tbf
verbose=1
[cli]
+verbose=1
telnet=127.0.0.1:2000
tcp=127.0.0.1:2001
#password=123
diff --git a/accel-pppd/accel-ppp.conf.5 b/accel-pppd/accel-ppp.conf.5
index 06a1d3f..1f53f32 100644
--- a/accel-pppd/accel-ppp.conf.5
+++ b/accel-pppd/accel-ppp.conf.5
@@ -886,6 +886,11 @@ Due to accel-ppp operates with rates in kilobit basis if you send rates in diffe
.br
Configuration of the command line interface.
.TP
+.BI "verbose=" n
+If \fIn\fR = 1 then cli module will log IP address of each connection.
+.br
+If \fIn\fR = 2 then cli module will also log passed commands.
+.TP
.BI "tcp=" host:port
Defines on which IP address and port the TCP module will listen for incoming
connections. When \fIhost\fR is empty, the TCP module listens on all local
diff --git a/accel-pppd/cli/tcp.c b/accel-pppd/cli/tcp.c
index 4ec4950..9f60cbf 100644
--- a/accel-pppd/cli/tcp.c
+++ b/accel-pppd/cli/tcp.c
@@ -11,6 +11,7 @@
#include <sys/socket.h>
#include "triton.h"
+#include "events.h"
#include "log.h"
#include "list.h"
#include "memdebug.h"
@@ -19,11 +20,11 @@
#define RECV_BUF_SIZE 1024
-struct tcp_client_t
-{
+struct tcp_client_t {
struct cli_client_t cli_client;
struct list_head entry;
struct triton_md_handler_t hnd;
+ struct sockaddr_in addr;
struct list_head xmit_queue;
struct buffer_t *xmit_buf;
uint8_t *cmdline;
@@ -33,13 +34,14 @@ struct tcp_client_t
int disconnect:1;
};
-struct buffer_t
-{
+struct buffer_t {
struct list_head entry;
int size;
uint8_t buf[0];
};
+static int conf_verbose;
+
static struct triton_context_t serv_ctx;
static struct triton_md_handler_t serv_hnd;
static LIST_HEAD(clients);
@@ -171,8 +173,12 @@ static int cln_read(struct triton_md_handler_t *h)
if (strcmp((char *)cln->cmdline, conf_cli_passwd))
goto drop;
cln->auth = 1;
- } else
+ } else {
+ if (conf_verbose == 2)
+ log_info2("cli: %s: %s\n", inet_ntoa(cln->addr.sin_addr), cln->cmdline);
+
cli_process_cmd(&cln->cli_client);
+ }
if (cln->disconnect)
goto drop;
@@ -241,7 +247,8 @@ static int serv_read(struct triton_md_handler_t *h)
continue;
}
- log_info2("cli: tcp: new connection from %s\n", inet_ntoa(addr.sin_addr));
+ if (conf_verbose)
+ log_info2("cli: tcp: new connection from %s\n", inet_ntoa(addr.sin_addr));
if (fcntl(sock, F_SETFL, O_NONBLOCK)) {
log_error("cli: tcp: failed to set nonblocking mode: %s, closing connection...\n", strerror(errno));
@@ -251,6 +258,7 @@ static int serv_read(struct triton_md_handler_t *h)
conn = _malloc(sizeof(*conn));
memset(conn, 0, sizeof(*conn));
+ conn->addr = addr;
conn->hnd.fd = sock;
conn->hnd.read = cln_read;
conn->hnd.write = cln_write;
@@ -345,6 +353,17 @@ static void start_server(const char *host, int port)
triton_context_wakeup(&serv_ctx);
}
+static void load_config(void)
+{
+ const char *opt;
+
+ opt = conf_get_opt("cli", "verbose");
+ if (opt)
+ conf_verbose = atoi(opt);
+ else
+ conf_verbose = 1;
+}
+
static void init(void)
{
const char *opt;
@@ -364,11 +383,15 @@ static void init(void)
port = atoi(d + 1);
if (port <= 0)
goto err_fmt;
+
+ load_config();
temp_buf = malloc(RECV_BUF_SIZE);
start_server(host, port);
+ triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
+
return;
err_fmt:
log_emerg("cli: tcp: invalid format\n");
diff --git a/accel-pppd/cli/telnet.c b/accel-pppd/cli/telnet.c
index fb211ea..cece88e 100644
--- a/accel-pppd/cli/telnet.c
+++ b/accel-pppd/cli/telnet.c
@@ -15,6 +15,7 @@
#include <sys/types.h>
#include "triton.h"
+#include "events.h"
#include "log.h"
#include "ppp.h"
#include "list.h"
@@ -32,11 +33,11 @@
#define ESC_UP "[A"
#define ESC_DOWN "[B"
-struct telnet_client_t
-{
+struct telnet_client_t {
struct cli_client_t cli_client;
struct list_head entry;
struct triton_md_handler_t hnd;
+ struct sockaddr_in addr;
struct list_head xmit_queue;
struct buffer_t *xmit_buf;
int xmit_pos;
@@ -53,8 +54,7 @@ struct telnet_client_t
int disconnect:1;
};
-struct buffer_t
-{
+struct buffer_t {
struct list_head entry;
int size;
struct buffer_t *p_buf;
@@ -70,6 +70,8 @@ static uint8_t *temp_buf;
static int conf_history_len = 100;
static const char *conf_history_file = "/var/lib/accel-ppp/history";
+static int conf_verbose;
+
static LIST_HEAD(history);
static int history_len;
static pthread_mutex_t history_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -303,6 +305,9 @@ static int telnet_input_char(struct telnet_client_t *cln, uint8_t c)
list_add(&b->entry, cln->history.next);
cln->history_pos = cln->history.next;
+ if (conf_verbose == 2)
+ log_info2("cli: %s: %s\n", inet_ntoa(cln->addr.sin_addr), cln->cmdline);
+
if (cli_process_cmd(&cln->cli_client))
return -1;
}
@@ -551,18 +556,15 @@ static int serv_read(struct triton_md_handler_t *h)
continue;
}
- log_info2("cli: telnet: new connection from %s\n", inet_ntoa(addr.sin_addr));
-
- if (fcntl(sock, F_SETFL, O_NONBLOCK)) {
- log_error("cli: telnet: failed to set nonblocking mode: %s, closing connection...\n", strerror(errno));
- close(sock);
- continue;
- }
+ if (conf_verbose)
+ log_info2("cli: telnet: new connection from %s\n", inet_ntoa(addr.sin_addr));
+ fcntl(sock, F_SETFL, O_NONBLOCK);
fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC);
conn = _malloc(sizeof(*conn));
memset(conn, 0, sizeof(*conn));
+ conn->addr = addr;
conn->hnd.fd = sock;
conn->hnd.read = cln_read;
conn->hnd.write = cln_write;
@@ -725,6 +727,17 @@ static void load_history_file(void)
fclose(f);
}
+static void load_config(void)
+{
+ const char *opt;
+
+ opt = conf_get_opt("cli", "verbose");
+ if (opt)
+ conf_verbose = atoi(opt);
+ else
+ conf_verbose = 1;
+}
+
static void init(void)
{
const char *opt;
@@ -749,6 +762,8 @@ static void init(void)
if (opt)
conf_history_file = _strdup(opt);
+ load_config();
+
recv_buf = malloc(RECV_BUF_SIZE);
temp_buf = malloc(RECV_BUF_SIZE);
@@ -758,6 +773,8 @@ static void init(void)
atexit(save_history_file);
+ triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
+
return;
err_fmt:
log_emerg("cli: telnet: invalid format\n");