]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/ipinfo.cgi
Merge remote-tracking branch 'ms/dns-forwarding' into next
[ipfire-2.x.git] / html / cgi-bin / ipinfo.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 IPFire Team <info@ipfire.org> #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 use CGI;
23 use IO::Socket;
24 use strict;
25
26 # enable only the following on debugging purpose
27 #use warnings;
28 #use CGI::Carp 'fatalsToBrowser';
29
30 require '/var/ipfire/general-functions.pl';
31 require "${General::swroot}/lang.pl";
32 require "${General::swroot}/header.pl";
33 require "${General::swroot}/geoip-functions.pl";
34
35 my %cgiparams=();
36
37 &Header::showhttpheaders();
38
39 &Header::openpage($Lang::tr{'ip info'}, 1, '');
40 &Header::openbigbox('100%', 'left');
41 my @lines=();
42 my $extraquery='';
43
44 my $addr = CGI::param("ip") || "";
45
46 if (&General::validip($addr)) {
47 $extraquery='';
48 @lines=();
49 my $whoisname = "whois.arin.net";
50 my $iaddr = inet_aton($addr);
51 my $hostname = gethostbyaddr($iaddr, AF_INET);
52 if (!$hostname) { $hostname = $Lang::tr{'lookup failed'}; }
53
54 # enumerate GeoIP information for IP address...
55 my $ccode = &GeoIP::lookup($addr);
56 my $flag_icon = &GeoIP::get_flag_icon($ccode);
57
58 my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp');
59 if ($sock)
60 {
61 print $sock "n $addr\n";
62 while (<$sock>) {
63 $extraquery = $1 if (/ReferralServer: whois:\/\/(\S+)\s+/);
64 push(@lines,$_);
65 }
66 close($sock);
67 if ($extraquery) {
68 undef (@lines);
69 $whoisname = $extraquery;
70 my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp');
71 if ($sock)
72 {
73 print $sock "$addr\n";
74 while (<$sock>) {
75 push(@lines,$_);
76 }
77 }
78 else
79 {
80 @lines = ( "$Lang::tr{'unable to contact'} $whoisname" );
81 }
82 }
83 }
84 else
85 {
86 @lines = ( "$Lang::tr{'unable to contact'} $whoisname" );
87 }
88
89 &Header::openbox('100%', 'left', $addr . " <a href='country.cgi#$ccode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode' title='$ccode' /></a> (" . $hostname . ') : '.$whoisname);
90 print "<pre>\n";
91 foreach my $line (@lines) {
92 print &Header::cleanhtml($line,"y");
93 }
94 print "</pre>\n";
95 &Header::closebox();
96 } else {
97 &Header::openbox('100%', 'left', $Lang::tr{'invalid ip'});
98 print <<EOF;
99 <p style="text-align: center;">
100 $Lang::tr{'invalid ip'}
101 </p>
102 EOF
103 &Header::closebox();
104 }
105
106 print <<END
107 <div align='center'>
108 <table width='80%'>
109 <tr>
110 <td align='center'><a href='$ENV{'HTTP_REFERER'}'><img src='/images/back.png' alt='$Lang::tr{'back'}' title='$Lang::tr{'back'}' /></a></td>
111 </tr>
112 </table>
113 </div>
114 END
115 ;
116
117 &Header::closebigbox();
118
119 &Header::closepage();