--- jgreylist.orig 2007-02-03 11:01:55.000000000 -0200 +++ jgreylist 2007-02-05 09:42:20.000000000 -0200 @@ -271,6 +271,34 @@ } ############################################################################### +# +# Function for check the vpopmail relay table +# By Cláudio Borges +# Mon Feb 5 09:42:18 BRST 2007 +# +sub checkRelay($) +{ + use DBI; + my $ip = shift; + my $host = "localhost"; + my $port = "3306"; + my $database = "vpopmail"; + my $table = "relay"; + my $username = "vpopmail"; + my $password = "vp0ppw"; + my $connect = "DBI:mysql:database=$database;host=$host;port=$port"; + + my $sql = DBI->connect($connect, $username, $password); + my $query = "select ip_addr from $table where ip_addr = '$ip'"; + my $select = $sql->prepare($query); + $select->execute() or die $sql->errstr; + my $result = $select->fetchrow_hashref(); + my $ip_addr = $result->{ip_addr} if (defined($result)); + $select->finish; + $sql->disconnect(); + return 1 if (defined($ip_addr)); +} + ############################################################################### ############################################################################### # @@ -280,10 +308,16 @@ $ip = ( $ENV{"TCPREMOTEIP"} || die "TCPREMOTEIP not found\n" ) ; ip_check() ; +my $check_relay = &checkRelay($ip) ; -if ( exists $ENV{"JGREYLIST"} ) +if ( exists $ENV{"JGREYLIST"} || ( 1 == $check_relay) ) { - if ( $ENV{"JGREYLIST"} eq "" ) + if ( 1 == $check_relay ) + { + logline "$ip: OK whitelisted in relay table" ; + okay() ; + } + elsif ( $ENV{"JGREYLIST"} eq "" ) { logline "$ip: OK whitelisted" ; okay() ;