diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-12-18 15:15:32 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-12-18 15:15:32 +0000 |
commit | 1ac9eba59e1247d2ee5de9cac7ef662ac4cc0f1c (patch) | |
tree | 25e8dbd6f2285c90115aacf67aaa7b81b9e8f294 /src/client/rspamc.c | |
parent | 5733cc904c84da231ec87da3d4e41b939b9a2a79 (diff) | |
download | rspamd-1ac9eba59e1247d2ee5de9cac7ef662ac4cc0f1c.tar.gz rspamd-1ac9eba59e1247d2ee5de9cac7ef662ac4cc0f1c.zip |
Add commands help for rspamc.
Diffstat (limited to 'src/client/rspamc.c')
-rw-r--r-- | src/client/rspamc.c | 120 |
1 files changed, 119 insertions, 1 deletions
diff --git a/src/client/rspamc.c b/src/client/rspamc.c index 9279682e4..3ed9f1dd4 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -46,6 +46,7 @@ static gint timeout = 5; static gboolean pass_all; static gboolean tty = FALSE; static gboolean verbose = FALSE; +static gboolean print_commands = FALSE; static struct rspamd_client *client = NULL; static GOptionEntry entries[] = @@ -64,6 +65,7 @@ static GOptionEntry entries[] = { "rcpt", 'r', 0, G_OPTION_ARG_STRING, &rcpt, "Emulate that message is for specified user", NULL }, { "timeout", 't', 0, G_OPTION_ARG_INT, &timeout, "Timeout for waiting for a reply", NULL }, { "bind", 'b', 0, G_OPTION_ARG_STRING, &local_addr, "Bind to specified ip address", NULL }, + { "commands", 0, 0, G_OPTION_ARG_NONE, &print_commands, "List available commands", NULL }, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; @@ -82,6 +84,92 @@ enum rspamc_command { RSPAMC_COMMAND_ADD_ACTION }; +struct { + enum rspamc_command cmd; + const char *name; + const char *description; + gboolean is_controller; + gboolean is_privileged; +} rspamc_command_help[] = { + { + .cmd = RSPAMC_COMMAND_SYMBOLS, + .name = "symbols", + .description = "scan message and show symbols (default command)", + .is_controller = FALSE, + .is_privileged = FALSE + }, + { + .cmd = RSPAMC_COMMAND_LEARN_SPAM, + .name = "learn_spam", + .description = "learn message as spam", + .is_controller = TRUE, + .is_privileged = TRUE + }, + { + .cmd = RSPAMC_COMMAND_LEARN_HAM, + .name = "learn_ham", + .description = "learn message as ham", + .is_controller = TRUE, + .is_privileged = TRUE + }, + { + .cmd = RSPAMC_COMMAND_FUZZY_ADD, + .name = "fuzzy_add", + .description = "add message to fuzzy storage (check -f and -w options for this command)", + .is_controller = TRUE, + .is_privileged = TRUE + }, + { + .cmd = RSPAMC_COMMAND_FUZZY_DEL, + .name = "fuzzy_del", + .description = "delete message from fuzzy storage (check -f option for this command)", + .is_controller = TRUE, + .is_privileged = TRUE + }, + { + .cmd = RSPAMC_COMMAND_STAT, + .name = "stat", + .description = "show rspamd statistics", + .is_controller = TRUE, + .is_privileged = FALSE + }, + { + .cmd = RSPAMC_COMMAND_STAT_RESET, + .name = "stat_reset", + .description = "show and reset rspamd statistics (useful for graphs)", + .is_controller = TRUE, + .is_privileged = TRUE + }, + { + .cmd = RSPAMC_COMMAND_COUNTERS, + .name = "counters", + .description = "display rspamd symbols statistics", + .is_controller = TRUE, + .is_privileged = FALSE + }, + { + .cmd = RSPAMC_COMMAND_UPTIME, + .name = "uptime", + .description = "show rspamd uptime", + .is_controller = TRUE, + .is_privileged = FALSE + }, + { + .cmd = RSPAMC_COMMAND_ADD_SYMBOL, + .name = "add_symbol", + .description = "add or modify symbol settings in rspamd", + .is_controller = TRUE, + .is_privileged = TRUE + }, + { + .cmd = RSPAMC_COMMAND_ADD_ACTION, + .name = "add_action", + .description = "add or modify action settings", + .is_controller = TRUE, + .is_privileged = TRUE + } +}; + /* * Parse command line */ @@ -151,6 +239,30 @@ check_rspamc_command (const gchar *cmd) return RSPAMC_COMMAND_UNKNOWN; } +static void +print_commands_list (void) +{ + guint i; + + PRINT_FUNC ("Rspamc commands summary:\n"); + for (i = 0; i < G_N_ELEMENTS (rspamc_command_help); i ++) { + if (tty) { + PRINT_FUNC (" \033[1m%10s\033[0m (%7s%1s)\t%s\n", rspamc_command_help[i].name, + rspamc_command_help[i].is_controller ? "control" : "normal", + rspamc_command_help[i].is_privileged ? "*" : "", + rspamc_command_help[i].description); + } + else { + PRINT_FUNC (" %10s (%7s%1s)\t%s\n", rspamc_command_help[i].name, + rspamc_command_help[i].is_controller ? "control" : "normal", + rspamc_command_help[i].is_privileged ? "*" : "", + rspamc_command_help[i].description); + } + } + PRINT_FUNC ("\n* is for privileged commands that may need password (see -P option)\n"); + PRINT_FUNC ("control commands use port 11334 while normal use 11333 by default (see -h option)\n"); +} + /* * Parse connect_str and add server to librspamdclient */ @@ -798,6 +910,13 @@ main (gint argc, gchar **argv, gchar **env) read_cmd_line (&argc, &argv); + tty = isatty (STDOUT_FILENO); + + if (print_commands) { + print_commands_list (); + exit (EXIT_SUCCESS); + } + if (local_addr) { if (inet_aton (local_addr, &ina) != 0) { client = rspamd_client_init_binded (&ina); @@ -812,7 +931,6 @@ main (gint argc, gchar **argv, gchar **env) } rspamd_set_timeout (client, 1000, timeout * 1000); - tty = isatty (STDOUT_FILENO); /* Now read other args from argc and argv */ if (argc == 1) { /* No args, just read stdin */ |