From mboxrd@z Thu Jan 1 00:00:00 1970 From: IT Superhack To: development@lists.ipfire.org Subject: [PATCH] Add GeoIP information to ipinfo.cgi Date: Fri, 01 Jan 2016 17:41:32 +0100 Message-ID: <5686AC3C.8040805@web.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0287432606220741501==" List-Id: --===============0287432606220741501== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 --- 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 @@ ############################################################################= ### =20 use IO::Socket; +use Geo::IP::PurePerl; use strict; =20 # enable only the following on debugging purpose @@ -27,10 +28,13 @@ use strict; #use CGI::Carp 'fatalsToBrowser'; =20 require '/var/ipfire/general-functions.pl'; +require "${General::swroot}/geoip-functions.pl"; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; =20 my %cgiparams=3D(); +my $s; +my @key; =20 &Header::showhttpheaders(); =20 @@ -52,6 +56,14 @@ next if $addr eq ""; my $iaddr =3D inet_aton($addr); my $hostname =3D gethostbyaddr($iaddr, AF_INET); if (!$hostname) { $hostname =3D $Lang::tr{'lookup failed'}; } +=09 + # geoip lookup + my $geoaddr =3D Geo::IP::PurePerl->new(); + my $ccode =3D $geoaddr->country_code_by_name($addr); + my $fcode =3D lc($ccode); + # Get flag icon for of the country. + my $flag_icon =3D &GeoIP::get_flag_icon($ccode); +=09 =20 my $sock =3D new IO::Socket::INET ( PeerAddr =3D> $whoisname, PeerPort =3D>= 43, Proto =3D> 'tcp'); if ($sock) @@ -84,7 +96,9 @@ next if $addr eq ""; @lines =3D ( "$Lang::tr{'unable to contact'} $whoisname" ); } =20 - &Header::openbox('100%', 'left', $addr . ' (' . $hostname . ') : '.$whoisna= me); + # include geoip information here + &Header::openbox('100%', 'left', $addr . ' 3D\''=20 (' . $hostname . ') : '.$whoisn= ame); print "
\n";
 	foreach my $line (@lines) {
 		print &Header::cleanhtml($line,"y");


--===============0287432606220741501==
Content-Type: application/pgp-signature
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="signature.asc"
MIME-Version: 1.0

LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0KCmlRRWNCQUVCQ2dBR0JRSldocXhEQUFvSkVP
eUxhMUM1RWF6cjF1RUlBS3BmQ3E3WWFCTUxUMCtaK2NiUW1Xak8KNGdPa2JXMWd0RzFvL1lPeGM2
OWo0bkhURnAvS3U1YllnYnhCSUVRREhsdEtacU9NbHZXSTVUSTI1eTRjQk9TSQppaDAyNlhzTnZC
WUdkUC8yb3o1NUg3OG9CTUVTb1hMd0tjUmJMZUs0Y0pnQzZlVVpLMm9JR3NOa211YWFmNnl3CjJs
RGlmemtxRkhJMUFxbTVtNVFLcnBYempaaUdtYUVVUHRiTGtCVmNaRmVDU2VxRjJYRGpRWDJzRElQ
b3BaSmEKUk1leVdXRjhYZFFWa2VpMkVBcElMUms1YkhiQ1piaDROaTFhbHBTbHFLaDFTVjNXYytN
WmJxOVRYT2YrbXVNagp0d1lkM0hmMmkxbVdtR3N2VXNDVmdmbmNYMWdReUxMdGZ3UDNRS1JWZlhH
UHRhdHFlRUd3Nzk2L3VsNkxJQWc9Cj0rRkhFCi0tLS0tRU5EIFBHUCBTSUdOQVRVUkUtLS0tLQo=

--===============0287432606220741501==--