Add support for network ranges in whitelist plugin (#298)
This commit is contained in:
parent
2e4ea13639
commit
3d40ea7280
@ -138,16 +138,23 @@ sub check_host {
|
|||||||
# From tcpserver
|
# From tcpserver
|
||||||
if (exists $ENV{WHITELISTCLIENT}) {
|
if (exists $ENV{WHITELISTCLIENT}) {
|
||||||
$self->qp->connection->notes('whitelistclient', 1);
|
$self->qp->connection->notes('whitelistclient', 1);
|
||||||
$self->log(2, "pass, is whitelisted client");
|
$self->log(2, "pass, $ip is whitelisted client");
|
||||||
$self->adjust_karma(5);
|
$self->adjust_karma(5);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $config_arg = $self->{_per_recipient} ? {rcpt => $rcpt, %MERGE} : {};
|
my $config_arg = $self->{_per_recipient} ? {rcpt => $rcpt, %MERGE} : {};
|
||||||
for my $h ($self->qp->config('whitelisthosts', $config_arg)) {
|
for my $h ($self->qp->config('whitelisthosts', $config_arg)) {
|
||||||
|
my $ipNet = NetAddr::IP->new($ip);
|
||||||
|
my $hNet = NetAddr::IP->new($h);
|
||||||
if ($h eq $ip or $ip =~ /^\Q$h\E/) {
|
if ($h eq $ip or $ip =~ /^\Q$h\E/) {
|
||||||
$self->qp->connection->notes('whitelisthost', 1);
|
$self->qp->connection->notes('whitelisthost', 1);
|
||||||
$self->log(2, "pass, is a whitelisted host");
|
$self->log(2, "pass, $ip is a whitelisted host");
|
||||||
|
$self->adjust_karma(5);
|
||||||
|
return OK;
|
||||||
|
} elsif ( $ipNet->within($hNet) ) {
|
||||||
|
$self->qp->connection->notes('whitelisthost', 1);
|
||||||
|
$self->log(2, "pass, $ip is in a whitelisted block");
|
||||||
$self->adjust_karma(5);
|
$self->adjust_karma(5);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user