8103c5a132
and removed redundant words from log entries
39 lines
1012 B
Perl
39 lines
1012 B
Perl
#!perl -w
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
This plugin uses MaxMind's GeoIP service and the Geo::IP perl module to
|
|
do a lookup on incoming connections and record the country of origin.
|
|
|
|
Thats all it does.
|
|
|
|
It logs the 2 char country code to note 'geoip_country'.
|
|
It logs the country name to the connection note 'geoip_country_name'.
|
|
|
|
Other plugins can use that info to do things to the connection, like
|
|
reject or greylist.
|
|
|
|
=cut
|
|
|
|
use Geo::IP;
|
|
|
|
sub hook_connect {
|
|
my ($self) = @_;
|
|
|
|
my $geoip = Geo::IP->new(GEOIP_STANDARD);
|
|
my $remote_ip = $self->qp->connection->remote_ip;
|
|
|
|
my $c_code = $geoip->country_code_by_addr( $remote_ip )
|
|
or return DECLINED; # if this fails, so too will name
|
|
my $c_name = $geoip->country_name_by_addr( $remote_ip );
|
|
|
|
$self->qp->connection->notes('geoip_country_name', $c_name);
|
|
$self->qp->connection->notes('geoip_country', $c_code);
|
|
|
|
my $message = $c_code;
|
|
$message .= ", $c_name" if $c_name;
|
|
$self->log(LOGINFO, $message);
|
|
|
|
return DECLINED;
|
|
}
|