diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-09-03 18:36:50 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-09-03 18:36:50 +0400 |
commit | 328516883b740207d86f8a0b618eb62a2170aa97 (patch) | |
tree | 1c6d7e905cd18701597773d43de47b7ceaf72487 /rspamc.pl.in | |
parent | b196e64d98a4d88b54c9a4dfaf2d9dc0b9d98ed6 (diff) | |
download | rspamd-328516883b740207d86f8a0b618eb62a2170aa97.tar.gz rspamd-328516883b740207d86f8a0b618eb62a2170aa97.zip |
* Fix Mail::Rspamd::Config for new rspamd features
* Use Mail::Rspamd::Config in rspamc client
Diffstat (limited to 'rspamc.pl.in')
-rwxr-xr-x | rspamc.pl.in | 52 |
1 files changed, 14 insertions, 38 deletions
diff --git a/rspamc.pl.in b/rspamc.pl.in index f994eced7..a261f66c9 100755 --- a/rspamc.pl.in +++ b/rspamc.pl.in @@ -10,6 +10,7 @@ use Socket qw(:DEFAULT :crlf); use Term::Cap; use Mail::Rspamd::Client; +use Mail::Rspamd::Config; use Data::Dumper; my %cfg = ( @@ -101,47 +102,22 @@ sub load_hosts_file { # Load rspamd config params sub parse_config { my ($is_ctrl) = @_; - - if (! open CONF, "< $cfg{'conf_file'}") { - print STDERR "Config file $cfg{'conf_file'} cannot be opened\n"; - return; - } - my $ctrl = 0, $skip = 0; - while (<CONF>) { - if ($_ =~ /^.*type.*=.*controller.*$/i) { - $ctrl = 1; - } - if ($ctrl && $_ =~ /}/) { - $ctrl = 0; - } - if ($_ =~ /^.*type.*=.*(?:lmtp|delivery|fuzzy).*$/i) { - $skip = 1; - } - if ($skip && $_ =~ /}/) { - $skip = 0; - } - if (!$skip && ((!$is_ctrl && !$ctrl) || ($ctrl && $is_ctrl)) - && $_ =~ /^\s*bind_socket\s*=\s*((([^:]+):(\d+))|(\/\S*))/i) { - if ($3 && $4) { - if ($3 eq '*') { - $cfg{'hosts'} = [ "127.0.0.1:$4" ]; - } - else { - $cfg{'hosts'} = [ "$3:$4" ]; - } - } - else { - $cfg{'hosts'} = [ "$5" ]; - } - } - if ($ctrl && $is_ctrl && $_ =~ /^\s*password\s*=\s*"(\S+)"/) { - $cfg{'password'} = $1; - } - } + my $parser = Mail::Rspamd::Config->new(); - close CONF; + $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 { |