diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-10 19:54:20 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-10 19:54:20 +0300 |
commit | e7017a518bbec3f2de37275ac6195ea55cb6b19e (patch) | |
tree | 084f1c81a1d0606e575abd2156e5c4314615652c /utils/redirector.pl.in | |
parent | 9cfc5813c0a07ddce2bd0c611a9de84f67a4a910 (diff) | |
download | rspamd-e7017a518bbec3f2de37275ac6195ea55cb6b19e.tar.gz rspamd-e7017a518bbec3f2de37275ac6195ea55cb6b19e.zip |
* Fix redirector connection procedure
* Add more strict login
* Add new header Queue-ID to protocol
* Log message id or queue id
* Add config file for redirector
* Add ability to set regexp and domains list to check with redirector
Diffstat (limited to 'utils/redirector.pl.in')
-rwxr-xr-x | utils/redirector.pl.in | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/utils/redirector.pl.in b/utils/redirector.pl.in index c406b48a3..f1a7f3196 100755 --- a/utils/redirector.pl.in +++ b/utils/redirector.pl.in @@ -42,10 +42,13 @@ my %cfg = ( logfile => '/var/log/rspamd-redirector.log', do_log => 0, debug => 0, + check_regexp => 'http://[^/]+/', + check_domains => [ 'narod.ru', 'test.ru' ], digest_bits => 256, cache_expire => 3600, user => '@RSPAMD_USER@', group => '@RSPAMD_GROUP@', + cfg_file => '@CMAKE_INSTALL_PREFIX@/etc/rspamd-redirector.conf', ); our $do_reopen_log = 0; @@ -59,8 +62,8 @@ Proc::Daemon::Init if !$cfg{debug}; if ($> == 0) { my $uid = getpwnam($cfg{user}) or die "user $cfg{user} unknown"; my $gid = getgrnam($cfg{group}) or die "group $cfg{group} unknown"; - $< = $uid; - $) = $gid; + $< = $> = $uid; + $) = $( = $gid; } die "Cannot write to pidfile $cfg{pidfile}" if ! open(PID, "> $cfg{pidfile}"); @@ -88,6 +91,7 @@ my $memd = new Cache::Memcached::Fast({ $SIG{USR1} = sub { $do_reopen_log = 1; }; $SIG{INT} = sub { $poe_kernel->stop(); }; $SIG{QUIT} = sub { $poe_kernel->stop(); }; +$SIG{PIPE} = 'IGNORE'; write_log ("", "Starting URL resolver"); @@ -104,6 +108,17 @@ POE::Component::Client::HTTP->spawn( ), ); +sub read_file { + my ($file) = @_; + + open(IN, $file) or die "Can't open $file: $!"; + local $/; + my $content = <IN>; + close IN; + + return $content; +} + sub reopen_log { if ($cfg{do_log}) { close (LOG); @@ -403,6 +418,30 @@ sub process_input { return; } + my $domain; + if ($request->uri =~ /^http:\/\/([^\/]+)\//) { + my @parts = split(/\./, $1); + my $c1 = pop @parts; + my $c2 = pop @parts; + $domain = "$c2.$c1"; + } + + if ((defined($cfg{check_regexp}) && $request->uri !~ $cfg{check_regexp}) || + (defined($cfg{check_domains}) && ($_ = grep(/$domain/, $cfg{check_domains})) == 0)) { + write_log ($heap->{remote_ip}, "Uri is not checked: " . $request->uri); + my $new_response = HTTP::Response->new(200); + $new_response->header("Uri", $request->uri); + $new_response->header("Connection", "close"); + $new_response->header("Proxy-Connection", "close"); + + # Avoid sending the response if the client has gone away. + $heap->{client}->put($new_response) if defined $heap->{client}; + $kernel->yield("shutdown"); + + # Shut down the client's connection when the response is sent. + return; + } + # Check cache first my $redirect = memcached_check_url($request->uri); if ($redirect) { @@ -426,6 +465,12 @@ sub process_input { $kernel->post( "cl", "request", "got_response", $new_request, [0, ""]); } +# Try to eval config file +if (-f $cfg{cfg_file}) { + my $config = read_file ($cfg{cfg_file}); + eval $config; +} + POE::Component::Server::TCP->new ( Alias => "", Port => $cfg{port}, |