]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - html/cgi-bin/ipinfo.cgi
Merge branch 'core110'
[ipfire-2.x.git] / html / cgi-bin / ipinfo.cgi
index bc214f09525d8bb38d0f11d0cc6c573a87f53065..16541f12621c9fd0ce25fc2015de453aac4d0f58 100644 (file)
@@ -2,7 +2,7 @@
 ###############################################################################
 #                                                                             #
 # IPFire.org - A linux based firewall                                         #
-# Copyright (C) 2007  Michael Tremer & Christian Schmidt                      #
+# 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        #
@@ -19,6 +19,7 @@
 #                                                                             #
 ###############################################################################
 
+use CGI;
 use IO::Socket;
 use strict;
 
@@ -34,20 +35,14 @@ my %cgiparams=();
 
 &Header::showhttpheaders();
 
-&Header::getcgihash(\%cgiparams);
-
-$ENV{'QUERY_STRING'} =~s/&//g;
-my @addrs = split(/ip=/,$ENV{'QUERY_STRING'});
-
-my %whois_servers = ("RIPE"=>"whois.ripe.net","APNIC"=>"whois.apnic.net","LACNIC"=>"whois.lacnic.net");
-
 &Header::openpage($Lang::tr{'ip info'}, 1, '');
-
 &Header::openbigbox('100%', 'left');
 my @lines=();
 my $extraquery='';
-foreach my $addr (@addrs) {
-next if $addr eq "";
+
+my $addr = CGI::param("ip") || "";
+
+if (&General::validip($addr)) {
        $extraquery='';
        @lines=();
        my $whoisname = "whois.arin.net";
@@ -58,15 +53,15 @@ next if $addr eq "";
        my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp');
        if ($sock)
        {
-               print $sock "$addr\n";
+               print $sock "$addr\n";
                while (<$sock>) {
-                       $extraquery = $1 if (/NetType:    Allocated to (\S+)\s+/);
+                       $extraquery = $1 if (/ReferralServer: whois:\/\/(\S+)\s+/);
                        push(@lines,$_);
                }
                close($sock);
                if ($extraquery) {
                        undef (@lines);
-                       $whoisname = $whois_servers{$extraquery};
+                       $whoisname = $extraquery;
                        my $sock = new IO::Socket::INET ( PeerAddr => $whoisname, PeerPort => 43, Proto => 'tcp');
                        if ($sock)
                        {
@@ -93,13 +88,21 @@ next if $addr eq "";
        }
        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'}'>$Lang::tr{'back'}</a></td>
+       <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>