From patchwork Tue Nov 3 14:29:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Peter_M=C3=BCller?= X-Patchwork-Id: 3631 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4CQXGk4kCdz3why for ; Tue, 3 Nov 2020 14:29:18 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4CQXGk2kfjzTf; Tue, 3 Nov 2020 14:29:18 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4CQXGk2BBGz2yXQ; Tue, 3 Nov 2020 14:29:18 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4CQXGj30Hnz2xjX for ; Tue, 3 Nov 2020 14:29:17 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4CQXGg6M79zTf for ; Tue, 3 Nov 2020 14:29:15 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1604413756; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bdWt6NMwnWS36guVpH9g/11O2uwx4BEuc05NAGVzPlQ=; b=sDLuocXKLQPe81YbQycDwlQfpeqwlHApBsBvcRkSClulGlhFO0UuBr+w78/Pu2WEc2EnRM m1Ac0MslOnm0c0DQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1604413756; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bdWt6NMwnWS36guVpH9g/11O2uwx4BEuc05NAGVzPlQ=; b=UZkVNiu+EQ/gncl7UNJg00B2bHyoz1x7byHdMHLhUdiqZdjSMp+uRmxJ6PtZoyPvue9imz XaxoRoJCmtr3Y8qhGBROL5V23kurpIfYn38e7u5+S3X6h32fb/rzXJgzEWkbgCZxwZYzjh g/nWnA8TZYt+WWfppNBO++L/uGNdTI7yAkCD3qAOn+MFa5rBRK+4fx/gcK/UB1EYMUtewa w340jaXmg/+60P33yJIuhCrmcaieAxXrjN1e2QjynpuR+5PA1Q06zGqqG9+D9PudO9V0bX JVsKO55Ync7/BFkS5ek1ZnSm7ENuiC7aSD0w3+JZ/nmx2tjO9evhUx2Q5uZswg== Subject: [PATCH 2/4] ipinfo.cgi: display AS information as well To: development@lists.ipfire.org References: <8cce16a8-5a92-acbb-28e7-68df2a95d887@ipfire.org> From: =?utf-8?q?Peter_M=C3=BCller?= Message-ID: Date: Tue, 3 Nov 2020 15:29:14 +0100 MIME-Version: 1.0 In-Reply-To: <8cce16a8-5a92-acbb-28e7-68df2a95d887@ipfire.org> Content-Language: en-US X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Signed-off-by: Peter Müller --- html/cgi-bin/ipinfo.cgi | 143 +++++++++++++++++++++++++--------------- 1 file changed, 91 insertions(+), 52 deletions(-) diff --git a/html/cgi-bin/ipinfo.cgi b/html/cgi-bin/ipinfo.cgi index d8cb6c6b7..1b56e08f9 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/".$mainsettings{'THEME'}."/include/colors.txt", \%color); + my %cgiparams=(); &Header::showhttpheaders(); -&Header::openpage($Lang::tr{'ip info'}, 1, ''); -&Header::openbigbox('100%', 'left'); my @lines=(); my $extraquery=''; @@ -57,18 +61,38 @@ 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... + # Enumerate location information for IP address... my $db_handle = &Location::Functions::init(); my $ccode = &Location::Functions::lookup_country_code($db_handle, $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); + # Enumerate Autonomous System details for IP address... + my $asn = &Location::Functions::lookup_asn($db_handle, $addr); + my $as_name; + if ($asn) { + $as_name = &Location::Functions::get_as_name($db_handle, $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}) { # Use it. @@ -77,6 +101,63 @@ 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,53 +189,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_flags) { - # Get amount of flags for this network. - my $flags_amount = @network_flags; - my $processed_flags; - - # The message string which will be displayed. - my $message_string = "This address is marked as"; - - # 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); - - # Add the flag name to the message string. - $message_string = "$message_string" . " $network_flag_name"; - - # Check if multiple flags are set for this network. - if ($flags_amount gt "1") { - # Check if the the current flag is the next-to-last one. - if ($processed_flags eq $flags_amount - 1) { - $message_string = "$message_string" . " and "; - - # Check if the current flag it the last one. - } elsif ($processed_flags eq $flags_amount) { - # The message is finished add a dot for ending the sentence. - $message_string = "$message_string" . "."; - - # Otherwise add a simple comma to the message string. - } else { - $message_string = "$message_string" . ", "; - } - } else { - # Nothing special to do, simple add a dot to finish the sentence. - $message_string = "$message_string" . "."; - } - } - - # Display the generated notice. - print "

$message_string

\n"; - print "
\n"; - } + &Header::openbox('100%', 'left', $Lang::tr{'whois results from'} . " " . $whois_server); print "
\n";
 	foreach my $line (@lines) {
@@ -163,6 +198,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 <