X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=html%2Fcgi-bin%2Fipinfo.cgi;h=fd490b08e50e343f1b8d4534516c4c70b9558258;hb=43ecaceb4da5b868f62ae6ff9daf30927fc335e8;hp=cce6097ffd8e8f9e9ea5c6dbb5f589215597f0f4;hpb=e5b1e648f68401dc8e9a144b85ad0dcae2f74c0b;p=people%2Fpmueller%2Fipfire-2.x.git diff --git a/html/cgi-bin/ipinfo.cgi b/html/cgi-bin/ipinfo.cgi index cce6097ffd..fd490b08e5 100644 --- a/html/cgi-bin/ipinfo.cgi +++ b/html/cgi-bin/ipinfo.cgi @@ -2,7 +2,7 @@ ############################################################################### # # # IPFire.org - A linux based firewall # -# Copyright (C) 2010 IPFire Team # +# Copyright (C) 2007-2020 IPFire Team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -32,12 +32,16 @@ require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; require "${General::swroot}/location-functions.pl"; +# Load colours for current theme... +my %color = (); +my %mainsettings = (); +&General::readhash("${General::swroot}/main/settings", \%mainsettings); +&General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); + my %cgiparams=(); &Header::showhttpheaders(); -&Header::openpage($Lang::tr{'ip info'}, 1, ''); -&Header::openbigbox('100%', 'left'); my @lines=(); my $extraquery=''; @@ -57,17 +61,36 @@ my $whois_server = "whois.arin.net"; my $addr = CGI::param("ip") || ""; if (&General::validip($addr)) { + # Write HTML page header... + &Header::openpage($Lang::tr{'ip info for'} . ' ' . $addr, 1, ''); + &Header::openbigbox('100%', 'left'); + my $iaddr = inet_aton($addr); my $hostname = gethostbyaddr($iaddr, AF_INET); - if (!$hostname) { $hostname = $Lang::tr{'lookup failed'}; } + if (!$hostname) { $hostname = $Lang::tr{'ptr lookup failed'}; } - # enumerate location information for IP address... - my $db_handle = &Location::Functions::init(); - my $ccode = &Location::Functions::lookup_country_code($db_handle, $addr); - my $network_flag = &Location::Functions::address_has_flag($addr); + # Enumerate location information for IP address... + my $ccode = &Location::Functions::lookup_country_code($addr); + my $cname = &Location::Functions::get_full_country_name($ccode); + my @network_flags = &Location::Functions::address_has_flags($addr); # Try to get the continent of the country code. - my $continent = &Location::get_continent_code($db_handle, $ccode); + my $continent = &Location::Functions::get_continent_code($ccode); + + # Enumerate Autonomous System details for IP address... + my $asn = &Location::Functions::lookup_asn($addr); + my $as_name; + if ($asn) { + $as_name = &Location::Functions::get_as_name($asn); + + # In case we have found an AS name, make output more readable... + if ($as_name) { + $as_name = "- " . $as_name; + } + $asn = "AS" . $asn; + } else { + $asn = $Lang::tr{'asn lookup failed'}; + } # Check if a whois server for the continent is known. if($whois_servers_by_continent{$continent}) { @@ -77,6 +100,62 @@ if (&General::validip($addr)) { my $flag_icon = &Location::Functions::get_flag_icon($ccode); + &Header::openbox('100%', 'left', $Lang::tr{'ip basic info'}); + + print < + + + + + + + + + + + + + +END + + # Check if the address has a flag. + if (@network_flags) { + # Get amount of flags for this network. + my $flags_amount = @network_flags; + my $processed_flags; + + # Loop through the array of network_flags. + foreach my $network_flag (@network_flags) { + # Increment value of processed flags. + $processed_flags++; + + # Get the network flag name. + my $network_flag_name = &Location::Functions::get_full_country_name($network_flag); + + # Colorize columns. + my $col; + if ($processed_flags % 2) { + $col = "bgcolor='$color{'color20'}'"; } + else { + $col = "bgcolor='$color{'color22'}'"; + } + + # Write table row... + print < + + + +END + } + } + + print "
$Lang::tr{'country'}$cname $cname
$Lang::tr{'ptr'}$hostname
$Lang::tr{'autonomous system'}$asn $as_name
$network_flag_name$Lang::tr{'yes'}
\n"; + print " \n"; + + &Header::closebox(); + my $sock = new IO::Socket::INET ( PeerAddr => $whois_server, PeerPort => 43, Proto => 'tcp'); if ($sock) { @@ -108,17 +187,7 @@ if (&General::validip($addr)) { @lines = ( "$Lang::tr{'unable to contact'} $whois_server" ); } - &Header::openbox('100%', 'left', $addr . " $ccode (" . $hostname . ') : '.$whois_server); - - # Check if the address has a flag. - if ($network_flag) { - # Get - my $network_flag_name = &Location::Functions::get_full_country_name($network_flag); - - # Display notice. - print "

This address is marked as $network_flag_name.

\n"; - print "
\n"; - } + &Header::openbox('100%', 'left', $Lang::tr{'whois results from'} . " " . $whois_server); print "
\n";
 	foreach my $line (@lines) {
@@ -127,6 +196,10 @@ if (&General::validip($addr)) {
 	print "
\n"; &Header::closebox(); } else { + # Open HTML page header in case of invalid IP addresses + &Header::openpage($Lang::tr{'ip info'}, 1, ''); + &Header::openbigbox('100%', 'left'); + &Header::openbox('100%', 'left', $Lang::tr{'invalid ip'}); print <