diff -Nur smeserver-geoip-1.2.old/root/usr/share/qpsmtpd/plugins/check_badcountries smeserver-geoip-1.2/root/usr/share/qpsmtpd/plugins/check_badcountries --- smeserver-geoip-1.2.old/root/usr/share/qpsmtpd/plugins/check_badcountries 2019-10-18 18:06:57.720000000 -0400 +++ smeserver-geoip-1.2/root/usr/share/qpsmtpd/plugins/check_badcountries 2019-10-18 18:11:03.629000000 -0400 @@ -96,6 +96,8 @@ =head1 CHANGES +2019-10 - JP Pialasse - reintroduce block country functionality with geoip v1 + 2019-01 - John Crisp - modify to work correctly with mailstats 2019-01 - JP Pialasse - make it compatible with old v1 + improve log level @@ -306,7 +308,8 @@ sub geoip_lookup { my $self = shift; - return DECLINED if $self->is_localhost($self->qp->connection->remote_ip); + my $ip = $self->qp->connection->remote_ip; + return DECLINED if $self->is_localhost($ip); # reopen the DB if Geo::IP failed due to DB update $self->open_geoip_db(); @@ -343,6 +346,30 @@ } $self->log(LOGINFO, join(", ", @msg_parts)); + if ( $self->qp->config("badcountries") ) { + my @badcountries = $self->qp->config("badcountries"); + + my $country = $self->qp->connection->notes('geoip_country'); + # Returns DECLINED if there are no countries found above + return DECLINED unless $country; + + $self->log(LOGNOTICE, "GeoIP Country: $country"); + + for (@badcountries) { + my ($pattern, $response) = split /\s+/, $_, 2; + #my $whitelisthost = $connection->notes('whitelisthost'); + my $whitelisthost = $self->qp->connection->notes('whitelisthost'); + if ($whitelisthost) { + $self->log(LOGNOTICE, "Country $country Pattern $pattern Whitehost $whitelisthost RemoteIP $ip"); + $self->log(LOGNOTICE, "Geoip whitelisthost found $whitelisthost"); + return OK; + } + else { + return (DENY, "Country is on Blocked List") if ($country eq $pattern); + } + } + } + return DECLINED; }