summaryrefslogtreecommitdiffstats
path: root/rspamc.pl.in
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2011-02-15 15:50:25 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2011-02-15 15:50:25 +0300
commitb3928c8e33fe8fe7b5d496c6beeb8f66dcdfa104 (patch)
tree32c3f399c6f2627db6106257156d08024881854d /rspamc.pl.in
parent97182882b0d460ddd33450aaf82485b998b72115 (diff)
downloadrspamd-b3928c8e33fe8fe7b5d496c6beeb8f66dcdfa104.tar.gz
rspamd-b3928c8e33fe8fe7b5d496c6beeb8f66dcdfa104.zip
Remove some legacy from source tree.
Diffstat (limited to 'rspamc.pl.in')
-rwxr-xr-xrspamc.pl.in332
1 files changed, 0 insertions, 332 deletions
diff --git a/rspamc.pl.in b/rspamc.pl.in
deleted file mode 100755
index 9843bf384..000000000
--- a/rspamc.pl.in
+++ /dev/null
@@ -1,332 +0,0 @@
-#!/usr/bin/perl -w
-
-# Simple script that read message from STDIN and test it on rspamd server
-# using specified command.
-#
-# Usage: rspamc.pl [-c conf_file] [command] [-s statfile]
-#
-# By default rspamc.pl would read ./rspamd.conf and default command is SYMBOLS
-
-use Socket qw(:DEFAULT :crlf);
-use Term::Cap;
-use Mail::Rspamd::Client;
-use Mail::Rspamd::Config;
-use Data::Dumper;
-
-my %cfg = (
- 'conf_file' => '@CMAKE_INSTALL_PREFIX@/etc/rspamd.xml',
- 'command' => 'SYMBOLS',
- 'hosts' => ['localhost:11333', ],
- 'require_input' => 0,
- 'password' => '',
- 'control' => 0,
- 'statfile' => '',
- 'deliver_to'=> '',
- 'weight' => 1,
- 'imap_search' => 'ALL',
- 'ip' => '127.0.0.1',
-);
-
-my $terminal;
-my $is_tty = 1;
-
-$main::VERSION = '@RSPAMD_VERSION@';
-
-sub HELP_MESSAGE {
- print <<EOD;
-Usage: rspamc.pl [-h host] [-H hosts_list] [-P password] [-c conf_file] [-s statfile] [-d user\@domain] [command] [path]
--h host to connect (in format host:port) or unix socket path
--H path to file that contains list of hosts
--P define control password
--c config file to parse
--s statfile to use for learn commands
-
-Additional options:
--d define deliver-to header
--w define weight for fuzzy operations
--S define search string for IMAP operations
--i emulate that message was send from specified IP
--p pass message throught all filters
-
-Notes:
-imap format: imap:user:<username>:password:[<password>]:host:<hostname>:mbox:<mboxname>
-Password may be omitted and then it would be asked in terminal
-imaps requires IO::Socket::SSL
-
-Version: @RSPAMD_VERSION@
-EOD
- exit;
-};
-
-sub load_hosts_file {
- my $file = shift;
-
- open (HOSTS, "< $file") or die "cannot open file $file";
- $cfg{'hosts'} = [ ];
- while (<HOSTS>) {
- chomp;
- next if $_ =~ /^\s*#/;
- if ($_ =~ /^\s*(([^:]+):(\d+))\s*$/) {
- push (@{ $cfg{'hosts'} }, $1);
- }
- elsif ($_ =~ /^\s*([^:]+)\s*$/) {
- if ($cfg{'control'}) {
- push (@{ $cfg{'hosts'} }, "$1:11334");
- }
- else {
- push (@{ $cfg{'hosts'} }, "$1:11333");
- }
- }
- elsif ($_ =~ /^\s*(\/\S*)\s*$/) {
- push (@{ $cfg{'hosts'} }, "$1");
- }
- }
- close HOSTS;
-}
-
-# Load rspamd config params
-sub parse_config {
- my ($is_ctrl) = @_;
-
- my $parser = Mail::Rspamd::Config->new();
-
- $parser->load($cfg{'conf_file'});
-
- if (defined ($parser->{workers})) {
- foreach my $worker (@{ $parser->{workers} }) {
- if ($is_ctrl && $worker->{'type'} eq 'controller') {
- $cfg{'hosts'} = [ $worker->{'bind_socket'} ];
- $cfg{'password'} = $worker->{options}->{password};
- }
- elsif (!$is_ctrl && $worker->{'type'} eq 'normal') {
- $cfg{'hosts'} = [ $worker->{'bind_socket'} ];
- }
- }
- }
-}
-
-sub print_control_result {
- my ($host, $res) = @_;
-
- $terminal->Tputs( 'md', 1, *STDOUT ) if $is_tty;
- print "Results for host $host:\n\n";
- $terminal->Tputs( 'me', 1, *STDOUT ) if $is_tty;
- if ($res->{error_code} == 0) {
- print "$res->{error}\n";
- }
- else {
- print "Error occured: $res->{error_code}:\n$res->{error}\n";
- }
-}
-
-sub print_rspamc_result {
- my ($host, $res) = @_;
-
- $terminal->Tputs( 'md', 1, *STDOUT ) if $is_tty;
- print "Results for host $host:\n\n";
- $terminal->Tputs( 'me', 1, *STDOUT ) if $is_tty;
-
- if (defined($res->{error})) {
- print "Error occured: $res->{error}\n\n";
- }
- else {
- while (my ($metric, $result) = each (%{ $res })) {
- $terminal->Tputs( 'md', 1, *STDOUT ) if $is_tty;
- print "$metric: ";
- $terminal->Tputs( 'me', 1, *STDOUT ) if $is_tty;
- print "$result->{isspam}, [ $result->{score} / $result->{threshold} ]\n";
-
- $terminal->Tputs( 'md', 1, *STDOUT ) if $is_tty;
- print "Symbols: ";
- $terminal->Tputs( 'me', 1, *STDOUT ) if $is_tty;
- print join("; ", @{ $result->{symbols} }) . "\n";
-
- $terminal->Tputs( 'md', 1, *STDOUT ) if $is_tty;
- print "Action: ";
- $terminal->Tputs( 'me', 1, *STDOUT ) if $is_tty;
- print "$result->{action}\n";
-
- $terminal->Tputs( 'md', 1, *STDOUT ) if $is_tty;
- print "Urls: ";
- $terminal->Tputs( 'me', 1, *STDOUT ) if $is_tty;
- print join(", ", @{ $result->{urls} }) . "\n";
-
- foreach my $msg (@{ $result->{messages} }) {
- $terminal->Tputs( 'md', 1, *STDOUT ) if $is_tty;
- print "Message: ";
- $terminal->Tputs( 'me', 1, *STDOUT ) if $is_tty;
- print "$msg\n";
- }
- print "\n\n";
- }
- }
-}
-
-sub print_item_result {
- my ($file, $res) = @_;
- $terminal->Tputs( 'md', 1, *STDOUT ) if $is_tty;
- print "Results for item $file:\n\n";
- $terminal->Tputs( 'me', 1, *STDOUT ) if $is_tty;
-
- while (my ($host, $result) = each (%{ $res })) {
- if ($cfg{control}) {
- print_control_result ($host, $result);
- }
- else {
- print_rspamc_result ($host, $result);
- }
- }
-
-}
-############################# Main part ###########################################
-my %args;
-
-HELP_MESSAGE() unless scalar @ARGV >= 1;
-
-while (my $opt = shift @ARGV) {
- if ($opt eq '-c') {
- $args{c} = shift @ARGV;
- }
- elsif ($opt eq '-h') {
- $args{h} = shift @ARGV;
- }
- elsif ($opt eq '-P') {
- $args{P} = shift @ARGV;
- }
- elsif ($opt eq '-s') {
- $args{s} = shift @ARGV;
- }
- elsif ($opt eq '-w') {
- $args{w} = shift @ARGV;
- }
- elsif ($opt eq '-d') {
- $args{d} = shift @ARGV;
- }
- elsif ($opt eq '-S') {
- $args{S} = shift @ARGV;
- }
- elsif ($opt eq '-H') {
- $args{H} = shift @ARGV;
- }
- elsif ($opt eq '-i') {
- $args{i} = shift @ARGV;
- }
- elsif ($opt eq '-p') {
- $args{p} = 1;
- }
- elsif ($opt eq '-?' || $opt eq '--help') {
- HELP_MESSAGE();
- }
- elsif ($opt eq '--') {
- last;
- }
- else {
- unshift @ARGV,$opt;
- last;
- }
-}
-
-my $cmd = shift @ARGV;
-my @path = shift @ARGV;
-
-if (!defined ($cmd) || $cmd eq '') {
- $cmd = 'SYMBOLS';
-}
-
-if (defined ($args{c})) {
- if (-r $args{c}) {
- $cfg{'conf_file'} = $args{c};
- }
- else {
- die "config file $args{c} is not readable";
- }
-
-}
-
-if ($cmd =~ /(SYMBOLS|PROCESS|CHECK|URLS|EMAILS)/i) {
- $cfg{'command'} = $1;
- $cfg{'control'} = 0;
-}
-elsif ($cmd =~ /(STAT|LEARN|SHUTDOWN|RELOAD|UPTIME|COUNTERS|FUZZY_ADD|FUZZY_DEL|WEIGHTS)/i) {
- $cfg{'command'} = $1;
- $cfg{'control'} = 1;
- $cfg{'hosts'} = ['localhost:11334'];
-}
-else {
- die "unknown command $cmd";
-}
-
-if (-r $cfg{'conf_file'}) {
- # Try to parse config
- parse_config ($cfg{'control'});
-}
-
-if (defined ($args{S})) {
- $cfg{'imap_search'} = $args{S};
-}
-
-if (defined ($args{s})) {
- if ($args{s}) {
- $cfg{'statfile'} = $args{s};
- }
- else {
- main::HELP_MESSAGE();
- }
-}
-if (defined ($args{h})) {
- $cfg{'hosts'} = [ $args{h} ];
-}
-if (defined ($args{P})) {
- $cfg{'password'} = $args{P};
-}
-if (defined ($args{d})) {
- $cfg{'deliver_to'} = $args{d};
-}
-if (defined ($args{w})) {
- $cfg{'weight'} = $args{w};
-}
-if (defined ($args{i})) {
- $cfg{'ip'} = $args{i};
-}
-if (exists ($args{p})) {
- $cfg{'pass_all'} = 1;
-}
-
-if ($cmd =~ /SYMBOLS|SCAN|PROCESS|CHECK|REPORT_IFSPAM|REPORT|URLS|EMAILS|LEARN|FUZZY_ADD|FUZZY_DEL|WEIGHTS/i) {
- $cfg{'require_input'} = 1;
-}
-
-if (defined ($args{H})) {
- load_hosts_file ($args{H});
-}
-
-my $rspamd = Mail::Rspamd::Client->new(\%cfg);
-
-if (-t STDOUT) {
- $terminal = Tgetent Term::Cap { TERM => undef, OSPEED => 9600 };
-}
-else {
- $is_tty = 0;
-}
-
-if (!defined ($path[0]) || ! $cfg{'require_input'}) {
- my $input;
- if ($cfg{'require_input'}) {
- while (defined (my $line = <>)) {
- $input .= $line;
- }
- }
-
- my $res = $rspamd->do_all_cmd ($input);
- while (my ($host, $result) = each (%{ $res })) {
- if ($cfg{control}) {
- print_control_result ($host, $result);
- }
- else {
- print_rspamc_result ($host, $result);
- }
- }
-}
-else {
- $rspamd->process_path (\&print_item_result, @path);
-}