2012-04-29 01:35:59 -07:00
|
|
|
#!perl -w
|
2004-08-29 07:47:25 +00:00
|
|
|
|
2012-04-07 20:11:16 -04:00
|
|
|
=head1 SYNOPSIS
|
2004-08-29 07:47:25 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2012-05-07 03:36:00 -04:00
|
|
|
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.
|
2004-08-29 07:47:25 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
use Geo::IP;
|
|
|
|
|
2005-07-07 04:17:39 +00:00
|
|
|
sub hook_connect {
|
2012-04-22 17:00:53 -04:00
|
|
|
my ($self) = @_;
|
2004-08-29 07:47:25 +00:00
|
|
|
|
2012-04-22 17:00:53 -04:00
|
|
|
my $geoip = Geo::IP->new(GEOIP_STANDARD);
|
2012-05-07 03:36:00 -04:00
|
|
|
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);
|
2004-08-29 07:47:25 +00:00
|
|
|
|
2012-05-07 03:36:00 -04:00
|
|
|
my $message = $c_code;
|
|
|
|
$message .= ", $c_name" if $c_name;
|
|
|
|
$self->log(LOGINFO, $message);
|
2004-08-29 07:47:25 +00:00
|
|
|
|
2012-04-22 17:00:53 -04:00
|
|
|
return DECLINED;
|
2004-08-29 07:47:25 +00:00
|
|
|
}
|