mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-11 03:25:54 +02:00
Use the libloc data for gathering and displaying the stored network flags, like "Anonymous Proxy" for the addresses. The notice of a flag only will be displayed, if a flag is set for the network which contains the given address. Currently this notice text is "hardcoded" in englisch language, because the entire other content of the page is in Englisch (responses from RIR's) and also the flag names like "Anonymous Proxy" are only availabe in English. IMHO there is no need to to translate the string "This address is marked as" into different languages, because of the reasons abouve. Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
153 lines
4.8 KiB
Perl
153 lines
4.8 KiB
Perl
#!/usr/bin/perl
|
|
###############################################################################
|
|
# #
|
|
# IPFire.org - A linux based firewall #
|
|
# Copyright (C) 2010 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 3 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/>. #
|
|
# #
|
|
###############################################################################
|
|
|
|
use CGI;
|
|
use IO::Socket;
|
|
use strict;
|
|
|
|
# enable only the following on debugging purpose
|
|
#use warnings;
|
|
#use CGI::Carp 'fatalsToBrowser';
|
|
|
|
require '/var/ipfire/general-functions.pl';
|
|
require "${General::swroot}/lang.pl";
|
|
require "${General::swroot}/header.pl";
|
|
require "${General::swroot}/location-functions.pl";
|
|
|
|
my %cgiparams=();
|
|
|
|
&Header::showhttpheaders();
|
|
|
|
&Header::openpage($Lang::tr{'ip info'}, 1, '');
|
|
&Header::openbigbox('100%', 'left');
|
|
my @lines=();
|
|
my $extraquery='';
|
|
|
|
# Hash which contains the whois servers from
|
|
# the responisible RIR of the continent.
|
|
my %whois_servers_by_continent = (
|
|
"AF" => "whois.afrinic.net",
|
|
"AS" => "whois.apnic.net",
|
|
"EU" => "whois.ripe.net",
|
|
"NA" => "whois.arin.net",
|
|
"SA" => "whois.lacnic.net"
|
|
);
|
|
|
|
# Default whois server if no continent could be determined.
|
|
my $whois_server = "whois.arin.net";
|
|
|
|
my $addr = CGI::param("ip") || "";
|
|
|
|
if (&General::validip($addr)) {
|
|
my $iaddr = inet_aton($addr);
|
|
my $hostname = gethostbyaddr($iaddr, AF_INET);
|
|
if (!$hostname) { $hostname = $Lang::tr{'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);
|
|
|
|
# Try to get the continent of the country code.
|
|
my $continent = &Location::get_continent_code($db_handle, $ccode);
|
|
|
|
# Check if a whois server for the continent is known.
|
|
if($whois_servers_by_continent{$continent}) {
|
|
# Use it.
|
|
$whois_server = $whois_servers_by_continent{$continent};
|
|
}
|
|
|
|
my $flag_icon = &Location::Functions::get_flag_icon($ccode);
|
|
|
|
my $sock = new IO::Socket::INET ( PeerAddr => $whois_server, PeerPort => 43, Proto => 'tcp');
|
|
if ($sock)
|
|
{
|
|
print $sock "$addr\n";
|
|
while (<$sock>) {
|
|
$extraquery = $1 if (/ReferralServer: whois:\/\/(\S+)\s+/);
|
|
push(@lines,$_);
|
|
}
|
|
close($sock);
|
|
if ($extraquery) {
|
|
undef (@lines);
|
|
$whois_server = $extraquery;
|
|
my $sock = new IO::Socket::INET ( PeerAddr => $whois_server, PeerPort => 43, Proto => 'tcp');
|
|
if ($sock)
|
|
{
|
|
print $sock "$addr\n";
|
|
while (<$sock>) {
|
|
push(@lines,$_);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
@lines = ( "$Lang::tr{'unable to contact'} $whois_server" );
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
@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_flag) {
|
|
# Get
|
|
my $network_flag_name = &Location::Functions::get_full_country_name($network_flag);
|
|
|
|
# Display notice.
|
|
print "<h3>This address is marked as $network_flag_name.</h3>\n";
|
|
print "<br>\n";
|
|
}
|
|
|
|
print "<pre>\n";
|
|
foreach my $line (@lines) {
|
|
print &Header::cleanhtml($line,"y");
|
|
}
|
|
print "</pre>\n";
|
|
&Header::closebox();
|
|
} else {
|
|
&Header::openbox('100%', 'left', $Lang::tr{'invalid ip'});
|
|
print <<EOF;
|
|
<p style="text-align: center;">
|
|
$Lang::tr{'invalid ip'}
|
|
</p>
|
|
EOF
|
|
&Header::closebox();
|
|
}
|
|
|
|
print <<END
|
|
<div align='center'>
|
|
<table width='80%'>
|
|
<tr>
|
|
<td align='center'><a href='$ENV{'HTTP_REFERER'}'><img src='/images/back.png' alt='$Lang::tr{'back'}' title='$Lang::tr{'back'}' /></a></td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
END
|
|
;
|
|
|
|
&Header::closebigbox();
|
|
|
|
&Header::closepage();
|