From 8103c5a132ea651e8de89296f22b7ec2bfcc16a4 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Mon, 7 May 2012 03:36:00 -0400 Subject: [PATCH] added country name to GeoIP plugin and removed redundant words from log entries --- plugins/ident/geoip | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/plugins/ident/geoip b/plugins/ident/geoip index 6ee2836..bfe8e30 100644 --- a/plugins/ident/geoip +++ b/plugins/ident/geoip @@ -7,9 +7,11 @@ do a lookup on incoming connections and record the country of origin. Thats all it does. -It logs the country to the connection notes 'geoip_country'. Another -plugin can use that value to do things to the connection, like reject, -or greylist. +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 @@ -19,12 +21,18 @@ sub hook_connect { my ($self) = @_; my $geoip = Geo::IP->new(GEOIP_STANDARD); - my $country = - $geoip->country_code_by_addr( $self->qp->connection->remote_ip ) - or return (DECLINED); + my $remote_ip = $self->qp->connection->remote_ip; - $self->qp->connection->notes('geoip_country', $country); - $self->log(LOGNOTICE, "GeoIP Country: $country"); + 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; }