diff --git a/src/occtl-unix.c b/src/occtl-unix.c index 666602f6..719e8866 100644 --- a/src/occtl-unix.c +++ b/src/occtl-unix.c @@ -585,7 +585,8 @@ int handle_list_users_cmd(struct unix_ctx *ctx, const char *arg) return ret; } -int handle_list_banned_cmd(struct unix_ctx *ctx, const char *arg) +static +int handle_list_banned_cmd(struct unix_ctx *ctx, const char *arg, unsigned points) { int ret; struct cmd_reply_st raw; @@ -615,21 +616,34 @@ int handle_list_banned_cmd(struct unix_ctx *ctx, const char *arg) continue; /* add header */ - if (i == 0) { - fprintf(out, "%14s %14s %30s\n", - "IP", "score", "expires"); - } + if (points == 0) { + if (rep->info[i]->has_expires) { + t = rep->info[i]->expires; + tm = localtime(&t); + strftime(str_since, sizeof(str_since), DATE_TIME_FMT, tm); + } else { + if (points) + str_since[0] = 0; + else + continue; + } - if (rep->info[i]->has_expires) { - t = rep->info[i]->expires; - tm = localtime(&t); - strftime(str_since, sizeof(str_since), DATE_TIME_FMT, tm); + if (i == 0) { + fprintf(out, "%14s %14s %30s\n", + "IP", "score", "expires"); + } + + fprintf(out, "%14s %14u %30s\n", + rep->info[i]->ip, (unsigned)rep->info[i]->score, str_since); } else { - str_since[0] = 0; - } + if (i == 0) { + fprintf(out, "%14s %14s\n", + "IP", "score"); + } - fprintf(out, "%14s %14u %30s\n", - rep->info[i]->ip, (unsigned)rep->info[i]->score, str_since); + fprintf(out, "%14s %14u\n", + rep->info[i]->ip, (unsigned)rep->info[i]->score); + } } ret = 0; @@ -649,6 +663,16 @@ int handle_list_banned_cmd(struct unix_ctx *ctx, const char *arg) return ret; } +int handle_list_banned_ips_cmd(struct unix_ctx *ctx, const char *arg) +{ + return handle_list_banned_cmd(ctx, arg, 0); +} + +int handle_list_banned_points_cmd(struct unix_ctx *ctx, const char *arg) +{ + return handle_list_banned_cmd(ctx, arg, 1); +} + int print_list_entries(FILE* out, const char* name, char **val, unsigned vsize) { const char * tmp; diff --git a/src/occtl.c b/src/occtl.c index c8a2a7f8..4744e203 100644 --- a/src/occtl.c +++ b/src/occtl.c @@ -59,8 +59,10 @@ static const commands_st commands[] = { "Prints the status of the server", 1, 1), ENTRY("show users", NULL, handle_list_users_cmd, "Prints the connected users", 1, 1), - ENTRY("show banned", NULL, handle_list_banned_cmd, + ENTRY("show ip bans", NULL, handle_list_banned_ips_cmd, "Prints the banned IP addresses", 1, 1), + ENTRY("show ip points", NULL, handle_list_banned_points_cmd, + "Prints all the known IP addresses which have points", 1, 1), ENTRY("show user", "[NAME]", handle_show_user_cmd, "Prints information on the specified user", 1, 1), ENTRY("show id", "[ID]", handle_show_id_cmd, diff --git a/src/occtl.h b/src/occtl.h index dea62b50..4e339893 100644 --- a/src/occtl.h +++ b/src/occtl.h @@ -53,7 +53,8 @@ typedef int (*cmd_func) (CONN_TYPE * conn, const char *arg); int handle_status_cmd(CONN_TYPE * conn, const char *arg); int handle_list_users_cmd(CONN_TYPE * conn, const char *arg); -int handle_list_banned_cmd(CONN_TYPE * conn, const char *arg); +int handle_list_banned_ips_cmd(CONN_TYPE * conn, const char *arg); +int handle_list_banned_points_cmd(CONN_TYPE * conn, const char *arg); int handle_show_user_cmd(CONN_TYPE * conn, const char *arg); int handle_show_id_cmd(CONN_TYPE * conn, const char *arg); int handle_disconnect_user_cmd(CONN_TYPE * conn, const char *arg);