Add GeoIP information to ipinfo.cgi
mbox

Message ID 5686AC3C.8040805@web.de
State New
Headers show

Message

IT Superhack Jan. 2, 2016, 3:41 a.m. UTC
Add the GeoIP information to the general ip information
(address, reverse dns name) on the ipinfo.cgi.

The ip address is given to Geo::IP::PurePerl first, then
the country code and the flag icon path are queried.

Fixes a feature request filed under bug #10946

Signed-off-by: Timmothy Wilson <itsuperhack@web.de>
---

Comments

IT Superhack Jan. 19, 2016, 3:56 a.m. UTC | #1
Hello development-list,

I was just wondering if something is wrong
with the patch (code error/bad style?) because there
was no answer within ~ two weeks.

Best regards,
Timmothy Wilson

IT Superhack:
> Add the GeoIP information to the general ip information
> (address, reverse dns name) on the ipinfo.cgi.
> 
> The ip address is given to Geo::IP::PurePerl first, then
> the country code and the flag icon path are queried.
> 
> Fixes a feature request filed under bug #10946
> 
> Signed-off-by: Timmothy Wilson <itsuperhack@web.de>
> ---
> diff --git a/html/cgi-bin/ipinfo.cgi b/html/cgi-bin/ipinfo.cgi
> index 71098a2..cebce23 100644
> --- a/html/cgi-bin/ipinfo.cgi
> +++ b/html/cgi-bin/ipinfo.cgi
> @@ -20,6 +20,7 @@
>  ###############################################################################
>  
>  use IO::Socket;
> +use Geo::IP::PurePerl;
>  use strict;
>  
>  # enable only the following on debugging purpose
> @@ -27,10 +28,13 @@ use strict;
>  #use CGI::Carp 'fatalsToBrowser';
>  
>  require '/var/ipfire/general-functions.pl';
> +require "${General::swroot}/geoip-functions.pl";
>  require "${General::swroot}/lang.pl";
>  require "${General::swroot}/header.pl";
>  
>  my %cgiparams=();
> +my $s;
> +my @key;
>  
>  &Header::showhttpheaders();
>  
> @@ -52,6 +56,14 @@ next if $addr eq "";
>  	my $iaddr = inet_aton($addr);
>  	my $hostname = gethostbyaddr($iaddr, AF_INET);
>  	if (!$hostname) { $hostname = $Lang::tr{'lookup failed'}; }
> +	
> +	# geoip lookup
> +	my $geoaddr = Geo::IP::PurePerl->new();
> +	my $ccode = $geoaddr->country_code_by_name($addr);
> +	my $fcode = lc($ccode);
> +	# Get flag icon for of the country.
> +	my $flag_icon = &GeoIP::get_flag_icon($ccode);
> +	
>  
>  	my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp');
>  	if ($sock)
> @@ -84,7 +96,9 @@ next if $addr eq "";
>  		@lines = ( "$Lang::tr{'unable to contact'} $whoisname" );
>  	}
>  
> -	&Header::openbox('100%', 'left', $addr . ' (' . $hostname . ') : '.$whoisname);
> +	# include geoip information here
> +	&Header::openbox('100%', 'left', $addr . ' <a href=\'/cgi-bin/country.cgi#' . $fcode . '\'><img src=\'' . $flag_icon . '\' border=\'0\' align=\'absmiddle\' alt=\'' 
> +.$ccode .'\' title=\'' . $ccode . '\'></a> (' . $hostname . ') : '.$whoisname);
>  	print "<pre>\n";
>  	foreach my $line (@lines) {
>  		print &Header::cleanhtml($line,"y");
>
Michael Tremer Jan. 19, 2016, 11:05 a.m. UTC | #2
Hi,

no I guess this is kind of alright. I just would have expected a bit
more feedback from the others here. Seems to be a bit of a lonely show
at the moment.

I have stated that at an other occasion recently that I do not think
that the information from a whois query and the geoip database is that
much related, but if it helps people that is okay for me.

However this seems to be an issue:

  The rules are pretty simple: If you comply and agree with the IPFire 
  Project Contributor Agreement, then you just add a line saying

    Signed-off-by: Random Developer <random@developer.example.org>

  using your real name. No pseudonyms or anonymous contributions.

From: http://wiki.ipfire.org/devel/git/tags

Best,
-Michael

On Mon, 2016-01-18 at 17:56 +0100, IT Superhack wrote:
> Hello development-list,
> 
> I was just wondering if something is wrong
> with the patch (code error/bad style?) because there
> was no answer within ~ two weeks.
> 
> Best regards,
> Timmothy Wilson
> 
> IT Superhack:
> > Add the GeoIP information to the general ip information
> > (address, reverse dns name) on the ipinfo.cgi.
> > 
> > The ip address is given to Geo::IP::PurePerl first, then
> > the country code and the flag icon path are queried.
> > 
> > Fixes a feature request filed under bug #10946
> > 
> > Signed-off-by: Timmothy Wilson <itsuperhack@web.de>
> > ---
> > diff --git a/html/cgi-bin/ipinfo.cgi b/html/cgi-bin/ipinfo.cgi
> > index 71098a2..cebce23 100644
> > --- a/html/cgi-bin/ipinfo.cgi
> > +++ b/html/cgi-bin/ipinfo.cgi
> > @@ -20,6 +20,7 @@
> >  ##################################################################
> > #############
> >  
> >  use IO::Socket;
> > +use Geo::IP::PurePerl;
> >  use strict;
> >  
> >  # enable only the following on debugging purpose
> > @@ -27,10 +28,13 @@ use strict;
> >  #use CGI::Carp 'fatalsToBrowser';
> >  
> >  require '/var/ipfire/general-functions.pl';
> > +require "${General::swroot}/geoip-functions.pl";
> >  require "${General::swroot}/lang.pl";
> >  require "${General::swroot}/header.pl";
> >  
> >  my %cgiparams=();
> > +my $s;
> > +my @key;
> >  
> >  &Header::showhttpheaders();
> >  
> > @@ -52,6 +56,14 @@ next if $addr eq "";
> >  	my $iaddr = inet_aton($addr);
> >  	my $hostname = gethostbyaddr($iaddr, AF_INET);
> >  	if (!$hostname) { $hostname = $Lang::tr{'lookup failed'};
> > }
> > +	
> > +	# geoip lookup
> > +	my $geoaddr = Geo::IP::PurePerl->new();
> > +	my $ccode = $geoaddr->country_code_by_name($addr);
> > +	my $fcode = lc($ccode);
> > +	# Get flag icon for of the country.
> > +	my $flag_icon = &GeoIP::get_flag_icon($ccode);
> > +	
> >  
> >  	my $sock = new IO::Socket::INET ( PeerAddr => $whoisname,
> > PeerPort => 43, Proto => 'tcp');
> >  	if ($sock)
> > @@ -84,7 +96,9 @@ next if $addr eq "";
> >  		@lines = ( "$Lang::tr{'unable to contact'}
> > $whoisname" );
> >  	}
> >  
> > -	&Header::openbox('100%', 'left', $addr . ' (' . $hostname
> > . ') : '.$whoisname);
> > +	# include geoip information here
> > +	&Header::openbox('100%', 'left', $addr . ' <a href=\'/cgi
> > -bin/country.cgi#' . $fcode . '\'><img src=\'' . $flag_icon . '\'
> > border=\'0\' align=\'absmiddle\' alt=\'' 
> > +.$ccode .'\' title=\'' . $ccode . '\'></a> (' . $hostname . ') :
> > '.$whoisname);
> >  	print "<pre>\n";
> >  	foreach my $line (@lines) {
> >  		print &Header::cleanhtml($line,"y");
> > 
> 
>