The second version of this patch only unifies the licence banner, but leaves GPLv2 untouched. In addition, functions have been changed to use a script-wide location database handle, as introduced in commit b62d7e0cc71cc1ff23d66dd8baf0f5f3c5c7a29b.
Signed-off-by: Peter Müller peter.mueller@ipfire.org --- config/cfgroot/location-functions.pl | 68 +++++++++++++++++++--------- 1 file changed, 46 insertions(+), 22 deletions(-)
diff --git a/config/cfgroot/location-functions.pl b/config/cfgroot/location-functions.pl index fdf2c6efe..b7465c5ef 100644 --- a/config/cfgroot/location-functions.pl +++ b/config/cfgroot/location-functions.pl @@ -1,25 +1,23 @@ #!/usr/bin/perl -w -############################################################################ -# # -# This file is part of the IPFire Firewall. # -# # -# IPFire is free software; you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation; either version 2 of the License, or # -# (at your option) any later version. # -# # -# IPFire is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with IPFire; if not, write to the Free Software # -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# # -# Copyright (C) 2015 - 2020 IPFire Team info@ipfire.org. # -# # -############################################################################ +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007-2020 IPFire Team info@ipfire.org # +# # +# 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 # +# the Free Software Foundation, either version 2 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see http://www.gnu.org/licenses/. # +# # +###############################################################################
package Location::Functions;
@@ -86,7 +84,7 @@ sub verify ($) { }
# -## Function to the the country code of a given address. +## Function to get the country code of a given address. # sub lookup_country_code($$) { my ($address) = @_; @@ -236,6 +234,32 @@ sub address_has_flags($) { return @flags; }
+# +## Function to get the Autonomous System Number of a given address. +# +sub lookup_asn($) { + my ($address) = @_; + + # Lookup the given address. + my $asn = &Location::lookup_asn($db_handle, $address); + + # Return the number of the Autonomous System + return $asn; +} + +# +## Function to get the name of an Autonomous System. +# +sub get_as_name($) { + my ($asn) = @_; + + # Fetch the name of this AS... + my $as_name = &Location::get_as_name($db_handle, $asn); + + # Return the name of the Autonomous System + return $as_name; +} + # Custom END declaration which will be executed when perl # ends, to release the database handle to libloc. END {
Signed-off-by: Peter Müller peter.mueller@ipfire.org --- html/cgi-bin/ipinfo.cgi | 142 +++++++++++++++++++++++++--------------- 1 file changed, 90 insertions(+), 52 deletions(-)
diff --git a/html/cgi-bin/ipinfo.cgi b/html/cgi-bin/ipinfo.cgi index ecc7c436c..1b7ceeadc 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 info@ipfire.org # +# Copyright (C) 2007-2020 IPFire Team info@ipfire.org # # # # 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,17 +61,37 @@ 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 $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::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}) { # Use it. @@ -76,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; + <center> + <table class="tbl" width='100%'> + <tr> + <td bgcolor='$color{'color22'}'><strong>$Lang::tr{'country'}</strong></td> + <td bgcolor='$color{'color22'}'>$cname <a href='country.cgi#$ccode'><img src="$flag_icon" border="0" alt="$cname" title="$cname" /></td> + </tr> + <tr> + <td bgcolor='$color{'color20'}'><strong>$Lang::tr{'ptr'}</strong></td> + <td bgcolor='$color{'color20'}'>$hostname</td> + </tr> + <tr> + <td bgcolor='$color{'color22'}'><strong>$Lang::tr{'autonomous system'}</strong></td> + <td bgcolor='$color{'color22'}'>$asn $as_name</td> + </tr> +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; + <tr> + <td $col><strong>$network_flag_name</strong></td> + <td $col>$Lang::tr{'yes'}</td> + </tr> +END + } + } + + print " </table>\n"; + print " </center>\n"; + + &Header::closebox(); + my $sock = new IO::Socket::INET ( PeerAddr => $whois_server, PeerPort => 43, Proto => 'tcp'); if ($sock) { @@ -107,53 +187,7 @@ if (&General::validip($addr)) { @lines = ( "$Lang::tr{'unable to contact'} $whois_server" ); }
- &Header::openbox('100%', 'left', $addr . " <a href='country.cgi#$ccode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode' title='$ccode' /></a> (" . $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 "<h3>$message_string</h3>\n"; - print "<br>\n"; - } + &Header::openbox('100%', 'left', $Lang::tr{'whois results from'} . " " . $whois_server);
print "<pre>\n"; foreach my $line (@lines) { @@ -162,6 +196,10 @@ if (&General::validip($addr)) { print "</pre>\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 <<EOF; <p style="text-align: center;">
Signed-off-by: Peter Müller peter.mueller@ipfire.org --- html/cgi-bin/dns.cgi | 2 +- html/cgi-bin/remote.cgi | 4 ++-- langs/de/cgi-bin/de.pl | 9 +++++++-- langs/en/cgi-bin/en.pl | 9 +++++++-- langs/es/cgi-bin/es.pl | 2 +- langs/fr/cgi-bin/fr.pl | 2 +- langs/it/cgi-bin/it.pl | 2 +- langs/nl/cgi-bin/nl.pl | 2 +- langs/pl/cgi-bin/pl.pl | 2 +- langs/ru/cgi-bin/ru.pl | 2 +- langs/tr/cgi-bin/tr.pl | 2 +- 11 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/html/cgi-bin/dns.cgi b/html/cgi-bin/dns.cgi index 5c3ca875d..337166ccf 100755 --- a/html/cgi-bin/dns.cgi +++ b/html/cgi-bin/dns.cgi @@ -625,7 +625,7 @@ END $rdns = gethostbyaddr($iaddr, AF_INET); }
- if (!$rdns) { $rdns = $Lang::tr{'lookup failed'}; } + if (!$rdns) { $rdns = $Lang::tr{'ptr lookup failed'}; }
# Mark ISP name servers as disabled if ($id <= 2 && $enabled eq "disabled") { diff --git a/html/cgi-bin/remote.cgi b/html/cgi-bin/remote.cgi index a27e10de9..31e4f4085 100644 --- a/html/cgi-bin/remote.cgi +++ b/html/cgi-bin/remote.cgi @@ -2,7 +2,7 @@ ############################################################################### # # # IPFire.org - A linux based firewall # -# Copyright (C) 2007-2019 IPFire Team info@ipfire.org # +# Copyright (C) 2007-2020 IPFire Team info@ipfire.org # # # # 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 # @@ -293,7 +293,7 @@ sub printactivelogins() # get rDNS... my $iaddr = inet_aton($remoteip); my $rdns = gethostbyaddr($iaddr, AF_INET); - if (!$rdns) { $rdns = $Lang::tr{'lookup failed'}; }; + if (!$rdns) { $rdns = $Lang::tr{'ptr lookup failed'}; };
my $table_colour = ($id++ % 2) ? $color{'color22'} : $color{'color20'};
diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl index 4a2a9e2e0..0c4ad8c8f 100644 --- a/langs/de/cgi-bin/de.pl +++ b/langs/de/cgi-bin/de.pl @@ -444,12 +444,14 @@ 'are you sure' => 'Sind Sie sicher?', 'arp table entries' => 'Einträge der ARP-Tabelle', 'artist' => 'Künstler', +'asn lookup failed' => 'AS-Auflösung gescheitert', 'atm device' => 'Device:', 'atm settings' => 'ATM-Einstellungen', 'attemps' => 'Versuche', 'attention' => 'ACHTUNG', 'august' => 'August', 'authentication' => 'Authentifizierung:', +'autonomous system' => 'Autonomes System', 'automatic' => 'Automatisch', 'available updates' => 'Verfügbare Updates:', 'average' => 'Durchschnitt', @@ -1503,7 +1505,9 @@ 'ip alias added' => 'Externer IP-Alias hinzugefügt', 'ip alias changed' => 'Externer IP-Alias geändert', 'ip alias removed' => 'Externer IP-Alias entfernt', -'ip info' => 'IP-Information', +'ip basic info' => 'Grundlegende IP-Informationen', +'ip info' => 'IP-Informationen', +'ip info for' => 'IP-Informationen für', 'ipfire has now rebooted' => 'IPFire wird neu gestartet.', 'ipfire has now shutdown' => 'IPFire wird heruntergefahren.', 'ipfire side' => 'IPFire Seite:', @@ -1595,7 +1599,6 @@ 'logging server' => 'Protokollierungsserver', 'loginlogout' => 'Login/Logout', 'logs' => 'Protokolldateien', -'lookup failed' => 'Reverse Lookup gescheitert', 'loosedirectorychecking' => 'Loose directorychecking', 'low' => 'Niedrig', 'ls_dhcpd' => 'DHCP-Server:', @@ -2068,6 +2071,7 @@ 'proxy reports weekly' => 'Wöchentliche Berichte', 'psk' => 'PSK', 'ptr' => 'PTR', +'ptr lookup failed' => 'Reverse Lookup gescheitert', 'pulse' => 'Puls', 'pulse dial' => 'Pulswahl:', 'qos add subclass' => 'Unterklasse hinzufügen', @@ -2863,6 +2867,7 @@ 'week-graph' => 'Woche', 'weekly firewallhits' => 'wöchentliche Firewalltreffer', 'weeks' => 'Wochen', +'whois results from' => 'WHOIS-Ergebnisse von', 'wildcards' => 'Wildcards', 'wins server' => 'WINS-Server', 'wins support' => 'WINS-Support', diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index 1151da08d..94512cae6 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -443,12 +443,14 @@ 'are you sure' => 'Are you sure?', 'arp table entries' => 'ARP Table Entries', 'artist' => 'Artist', +'asn lookup failed' => 'AS lookup failed', 'atm device' => 'Device:', 'atm settings' => 'ATM settings', 'attemps' => 'Attempts', 'attention' => 'ATTENTION', 'august' => 'August', 'authentication' => 'Authentication:', +'autonomous system' => 'Autonomous System', 'automatic' => 'Automatic', 'available updates' => 'Available updates:', 'average' => 'Average', @@ -1531,7 +1533,9 @@ 'ip alias added' => 'External IP alias added', 'ip alias changed' => 'External IP alias changed', 'ip alias removed' => 'External IP alias removed', -'ip info' => 'IP Information', +'ip basic info' => 'Basic IP information', +'ip info' => 'IP information', +'ip info' => 'IP information for', 'ipfire has now rebooted' => 'IPFire is rebooting now.', 'ipfire has now shutdown' => 'IPFire is shutting down now.', 'ipfire side' => 'IPFire side:', @@ -1623,7 +1627,6 @@ 'logging server' => 'Logging Server', 'loginlogout' => 'Login/Logout', 'logs' => 'logs', -'lookup failed' => 'Reverse lookup failed', 'loosedirectorychecking' => 'Loosedirectorychecking', 'low' => 'Low', 'ls_dhcpd' => 'DHCP Server:', @@ -2099,6 +2102,7 @@ 'proxy reports weekly' => 'Weekly reports', 'psk' => 'PSK', 'ptr' => 'PTR', +'ptr lookup failed' => 'Reverse lookup failed', 'pulse' => 'Pulse', 'pulse dial' => 'Pulse dial:', 'qos add subclass' => 'Add subclass', @@ -2907,6 +2911,7 @@ 'week-graph' => 'Week', 'weekly firewallhits' => 'weekly firewallhits', 'weeks' => 'Weeks', +'whois results from' => 'WHOIS results from', 'wildcards' => 'Wildcards', 'winbind daemon' => 'Winbind Daemon', 'wins server' => 'Wins Server', diff --git a/langs/es/cgi-bin/es.pl b/langs/es/cgi-bin/es.pl index ae155d26b..0e9b13787 100644 --- a/langs/es/cgi-bin/es.pl +++ b/langs/es/cgi-bin/es.pl @@ -1096,7 +1096,7 @@ 'logging server' => 'Servidor de conexión', 'loginlogout' => 'Login/Logout', 'logs' => 'registros', -'lookup failed' => 'Falló la búsqueda reversiva', +'ptr lookup failed' => 'Falló la búsqueda reversiva', 'loosedirectorychecking' => 'Chequeo de loosedirectory', 'low' => 'Bajo', 'ls_dhcpd' => 'Servidor DHCP:', diff --git a/langs/fr/cgi-bin/fr.pl b/langs/fr/cgi-bin/fr.pl index b5232db8c..cfb158963 100644 --- a/langs/fr/cgi-bin/fr.pl +++ b/langs/fr/cgi-bin/fr.pl @@ -1627,7 +1627,7 @@ 'logging server' => 'Serveur de connexion', 'loginlogout' => 'Connexion/Quitter', 'logs' => 'Journaux', -'lookup failed' => 'La recherche inversée a échouée', +'ptr lookup failed' => 'La recherche inversée a échouée', 'loosedirectorychecking' => 'Echec de la vérification du répertoire', 'low' => 'Bas', 'ls_dhcpd' => 'Serveur DHCP :', diff --git a/langs/it/cgi-bin/it.pl b/langs/it/cgi-bin/it.pl index ada8887ac..be796a5e5 100644 --- a/langs/it/cgi-bin/it.pl +++ b/langs/it/cgi-bin/it.pl @@ -1409,7 +1409,7 @@ 'logging server' => 'Logging Server', 'loginlogout' => 'Login/Logout', 'logs' => 'Gestione Log', -'lookup failed' => 'Reverse lookup failed', +'ptr lookup failed' => 'Reverse lookup failed', 'loosedirectorychecking' => 'Loosedirectorychecking', 'low' => 'Basso', 'ls_dhcpd' => 'DHCP Server:', diff --git a/langs/nl/cgi-bin/nl.pl b/langs/nl/cgi-bin/nl.pl index bbd5a3f3d..ca6aa4af5 100644 --- a/langs/nl/cgi-bin/nl.pl +++ b/langs/nl/cgi-bin/nl.pl @@ -1389,7 +1389,7 @@ 'logging server' => 'Loggingserver', 'loginlogout' => 'Login/Logout', 'logs' => 'logs', -'lookup failed' => 'Reverse lookup mislukt', +'ptr lookup failed' => 'Reverse lookup mislukt', 'loosedirectorychecking' => 'Loosedirectorychecking', 'low' => 'Laag', 'ls_dhcpd' => 'DHCP Server:', diff --git a/langs/pl/cgi-bin/pl.pl b/langs/pl/cgi-bin/pl.pl index e85173021..682f1985f 100644 --- a/langs/pl/cgi-bin/pl.pl +++ b/langs/pl/cgi-bin/pl.pl @@ -1095,7 +1095,7 @@ 'logging server' => 'Serwer logowania', 'loginlogout' => 'Zalogowanie/wylogowanie', 'logs' => 'logi', -'lookup failed' => 'Reverse lookup failed', +'ptr lookup failed' => 'Reverse lookup failed', 'loosedirectorychecking' => 'Loosedirectorychecking', 'low' => 'Niski', 'ls_dhcpd' => 'Serwer DHCP:', diff --git a/langs/ru/cgi-bin/ru.pl b/langs/ru/cgi-bin/ru.pl index 371394474..b27a00447 100644 --- a/langs/ru/cgi-bin/ru.pl +++ b/langs/ru/cgi-bin/ru.pl @@ -1088,7 +1088,7 @@ 'logging server' => 'Сервер Логов', 'loginlogout' => 'Login/Logout', 'logs' => 'Логи', -'lookup failed' => 'Reverse lookup failed', +'ptr lookup failed' => 'Reverse lookup failed', 'loosedirectorychecking' => 'Loosedirectorychecking', 'low' => 'Low', 'ls_dhcpd' => 'DHCP сервер:', diff --git a/langs/tr/cgi-bin/tr.pl b/langs/tr/cgi-bin/tr.pl index da868a312..cff74ac95 100644 --- a/langs/tr/cgi-bin/tr.pl +++ b/langs/tr/cgi-bin/tr.pl @@ -1539,7 +1539,7 @@ 'logging server' => 'Günlük Sunucusu', 'loginlogout' => 'Giriş/Çıkış', 'logs' => 'Günlükler', -'lookup failed' => 'Ters arama başarısız', +'ptr lookup failed' => 'Ters arama başarısız', 'loosedirectorychecking' => 'Serbest Dizin Denetimi', 'low' => 'Düşük', 'ls_dhcpd' => 'DHCP Sunucusu:',