From: Vsevolod Stakhov Date: Tue, 15 Mar 2011 13:32:58 +0000 (+0300) Subject: Add support of uptime command to rspamc. X-Git-Tag: 0.3.8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e7ec4dc4dcc484973957c69d15ca8f7aa41aa73e;p=rspamd.git Add support of uptime command to rspamc. Update manpages. Add script for generating manpages from pod. --- diff --git a/doc/makeman.sh b/doc/makeman.sh new file mode 100755 index 000000000..176f37b25 --- /dev/null +++ b/doc/makeman.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# Makes manual pages from pods + +POD2MAN="pod2man" +VERSION="unknown" +CMAKEFILE="../CMakeLists.txt" + +# Extract release version +if [ -f ${CMAKEFILE} ] ; then + _mjver=`fgrep 'SET(RSPAMD_VERSION_MAJOR' ${CMAKEFILE} | sed -e 's/^.*RSPAMD_VERSION_MAJOR \([0-9]\).*/\1/'` + _miver=`fgrep 'SET(RSPAMD_VERSION_MINOR' ${CMAKEFILE} | sed -e 's/^.*RSPAMD_VERSION_MINOR \([0-9]\).*/\1/'` + _pver=`fgrep 'SET(RSPAMD_VERSION_PATCH' ${CMAKEFILE} | sed -e 's/^.*RSPAMD_VERSION_PATCH \([0-9]\).*/\1/'` + VERSION="${_mjver}.${_miver}.${_pver}" +fi + +pod2man -c "Rspamd documentation" -n rspamd -s 8 -r "rspamd-${VERSION}" < rspamd.pod > rspamd.8 +pod2man -c "Rspamd documentation" -n rspamc -s 1 -r "rspamd-${VERSION}" < rspamc.pod > rspamc.1 diff --git a/doc/rspamc.1 b/doc/rspamc.1 index f4e5cf2ef..549899c91 100644 --- a/doc/rspamc.1 +++ b/doc/rspamc.1 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "rspamc 1" -.TH rspamc 1 "2011-02-25" "rspamd-0.3.7_1" "Rspamd documentation" +.TH rspamc 1 "2011-03-15" "rspamd-0.3.8" "Rspamd documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -134,9 +134,9 @@ rspamc \- a simple client for rspamd spam filtering system .SH "SYNOPSIS" .IX Header "SYNOPSIS" -rspamc [\fB\-h\fR \fIhost[:port]\fR] [\fB\-p\fR] +rspamc [\fB\-h\fR \fIhost[:port]\fR] [\fB\-p\fR] [\fB\-v\fR] [\fB\-i\fR \fIip\fR] [\fB\-s\fR \fIstatfile\fR] [\fB\-w\fR \fIweight\fR] -[\fB\-P\fR \fIpassword\fR] [\fB\-f\fR \fIflag\fR] [command] [file [file ...]] +[\fB\-P\fR \fIpassword\fR] [\fB\-f\fR \fIflag\fR] [\fB\-t\fR \fItimeout\fR] [command] [file [file ...]] .PP rspamc [\fB\-\-help\fR] .SH "DESCRIPTION" @@ -152,6 +152,9 @@ default port is \fI11333\fR for checking messages and \fI11334\fR for learning a .IP "\fB\-p\fR, \fB\-\-pass\-all\fR" 4 .IX Item "-p, --pass-all" Pass all filters when checking messages. Ignored in case of learning. +.IP "\fB\-v\fR, \fB\-\-verbose\fR" 4 +.IX Item "-v, --verbose" +Be more verbose while displaying results. For example show descriptions of symbols. .IP "\fB\-P\fR \fIpassword\fR, \fB\-\-password\fR \fIpassword\fR" 4 .IX Item "-P password, --password password" Specify controller's password. Mandatory option for learning. @@ -167,7 +170,10 @@ specific \s-1IP\s0 address. Weight of message for fuzzy operations. .IP "\fB\-f\fR \fIflag\fR, \fB\-\-flag\fR \fIflag\fR" 4 .IX Item "-f flag, --flag flag" -Weight of message for fuzzy operations. +Flag of list for fuzzy operations. +.IP "\fB\-t\fR \fItimeout\fR, \fB\-\-timeout\fR \fItimeout\fR" 4 +.IX Item "-t timeout, --timeout timeout" +Timeout in seconds for all operations. Default value is 5 seconds. .SH "RETURN VALUE" .IX Header "RETURN VALUE" On exit \fBrspamc\fR returns 0 if operation was successfull and error code otherwise. @@ -208,6 +214,12 @@ Get statistics: .Vb 1 \& rspamc stat .Ve +.PP +Get uptime: +.PP +.Vb 1 +\& rspamc uptime +.Ve .SH "AUTHOR" .IX Header "AUTHOR" Vsevolod Stakhov diff --git a/doc/rspamc.pod b/doc/rspamc.pod index 14de89b92..ebb452b4d 100644 --- a/doc/rspamc.pod +++ b/doc/rspamc.pod @@ -4,9 +4,9 @@ rspamc - a simple client for rspamd spam filtering system =head1 SYNOPSIS -rspamc [B<-h> I] [B<-p>] +rspamc [B<-h> I] [B<-p>] [B<-v>] [B<-i> I] [B<-s> I] [B<-w> I] -[B<-P> I] [B<-f> I] [command] [file [file ...]] +[B<-P> I] [B<-f> I] [B<-t> I] [command] [file [file ...]] rspamc [B<--help>] @@ -28,6 +28,10 @@ default port is I<11333> for checking messages and I<11334> for learning and sta Pass all filters when checking messages. Ignored in case of learning. +=item B<-v>, B<--verbose> + +Be more verbose while displaying results. For example show descriptions of symbols. + =item B<-P> I, B<--password> I Specify controller's password. Mandatory option for learning. @@ -47,8 +51,11 @@ Weight of message for fuzzy operations. =item B<-f> I, B<--flag> I -Weight of message for fuzzy operations. +Flag of list for fuzzy operations. +=item B<-t> I, B<--timeout> I + +Timeout in seconds for all operations. Default value is 5 seconds. =back @@ -82,6 +89,10 @@ Get statistics: rspamc stat +Get uptime: + + rspamc uptime + =head1 AUTHOR Vsevolod Stakhov @@ -93,4 +104,4 @@ Copyright 2011 by Vsevolod Stakhov . This program is free software; you may redistribute it and/or modify it under the terms of BSD license. -=cut \ No newline at end of file +=cut diff --git a/doc/rspamd.8 b/doc/rspamd.8 index 6e7e6e6f7..ea8e0b2b5 100644 --- a/doc/rspamd.8 +++ b/doc/rspamd.8 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "rspamd 8" -.TH rspamd 8 "2011-02-25" "rspamd-0.3.7_1" "Rspamd documentation" +.TH rspamd 8 "2011-03-15" "rspamd-0.3.8" "Rspamd documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l diff --git a/lib/librspamdclient.c b/lib/librspamdclient.c index c1143d0be..fa92df208 100644 --- a/lib/librspamdclient.c +++ b/lib/librspamdclient.c @@ -1535,6 +1535,27 @@ rspamd_get_stat (GError **err) return res; } +GString * +rspamd_get_uptime (GError **err) +{ + struct rspamd_connection *c; + GString *res; + static const gchar outcmd[] = "uptime\r\n"; + + g_assert (client != NULL); + + /* Connect to server */ + c = rspamd_connect_random_server (TRUE, err); + + if (c == NULL) { + return NULL; + } + + res = rspamd_send_controller_command (c, outcmd, strlen (outcmd), -1, err); + + return res; +} + /* * Free results */ diff --git a/lib/librspamdclient.h b/lib/librspamdclient.h index 1e7f70187..72b7311a7 100644 --- a/lib/librspamdclient.h +++ b/lib/librspamdclient.h @@ -102,6 +102,11 @@ gboolean rspamd_fuzzy_fd (int fd, const gchar *password, gint weight, gint flag, */ GString *rspamd_get_stat (GError **err); +/* + * Get uptime from server + */ +GString *rspamd_get_uptime (GError **err); + /* * Free results */ diff --git a/src/client/rspamc.c b/src/client/rspamc.c index f7ce4e9bc..155db86c6 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -61,7 +61,8 @@ enum rspamc_command { RSPAMC_COMMAND_LEARN, RSPAMC_COMMAND_FUZZY_ADD, RSPAMC_COMMAND_FUZZY_DEL, - RSPAMC_COMMAND_STAT + RSPAMC_COMMAND_STAT, + RSPAMC_COMMAND_UPTIME }; /* @@ -111,6 +112,9 @@ check_rspamc_command (const gchar *cmd) else if (g_ascii_strcasecmp (cmd, "STAT") == 0) { return RSPAMC_COMMAND_STAT; } + else if (g_ascii_strcasecmp (cmd, "UPTIME") == 0) { + return RSPAMC_COMMAND_UPTIME; + } return RSPAMC_COMMAND_UNKNOWN; } @@ -526,10 +530,40 @@ rspamd_do_stat () res = rspamd_get_stat (&err); if (res == NULL) { if (err != NULL) { - fprintf (stderr, "cannot learn message: %s\n", err->message); + fprintf (stderr, "cannot stat: %s\n", err->message); } else { - fprintf (stderr, "cannot learn message\n"); + fprintf (stderr, "cannot stat\n"); + } + exit (EXIT_FAILURE); + } + if (tty) { + printf ("\033[1m"); + } + PRINT_FUNC ("Results for host: %s\n\n", connect_str); + if (tty) { + printf ("\033[0m"); + } + res = g_string_append_c (res, '\0'); + printf ("%s\n", res->str); +} + +static void +rspamd_do_uptime () +{ + GError *err = NULL; + GString *res; + + /* Add server */ + add_rspamd_server (TRUE); + + res = rspamd_get_uptime (&err); + if (res == NULL) { + if (err != NULL) { + fprintf (stderr, "cannot uptime: %s\n", err->message); + } + else { + fprintf (stderr, "cannot uptime\n"); } exit (EXIT_FAILURE); } @@ -580,6 +614,9 @@ main (gint argc, gchar **argv, gchar **env) case RSPAMC_COMMAND_STAT: rspamd_do_stat (); break; + case RSPAMC_COMMAND_UPTIME: + rspamd_do_uptime (); + break; default: fprintf (stderr, "invalid arguments\n"); exit (EXIT_FAILURE);