Beispiel #1
0
 public function process($ip, &$stats = array(), &$options = array(), &$post = array())
 {
     if (defined('AF_INET6') && strpos($ip, '.') === false) {
         try {
             if (!inet_pton($ip)) {
                 return 'invalid ip: ' . $ip;
             }
         } catch (Exception $e) {
             return 'invalid ip: ' . $ip;
         }
     }
     $ips = be_module::ip2numstr($ip);
     if ($ips >= '224000000000' && $ips <= '239255255255') {
         return 'IPv4 Multicast Address Space Registry';
     }
     // Reserved for future use >=240.0.0.0
     if ($ips >= '240000000000' && $ips <= '255255255255') {
         return 'Reserved for future use';
     }
     return false;
 }
 public function ipListMatch($ip)
 {
     // does a match agains a list of ip addresses
     $ipt = be_module::ip2numstr($ip);
     foreach ($this->searchlist as $c) {
         if (!is_array($c)) {
             // this might be a cidr
             if (substr_count($c, '.') == 3) {
                 if (strpos($c, '/') !== false) {
                     // cidr
                     $c = be_module::cidr2ip($c);
                 } else {
                     // single ip
                     $c = array($c, $c);
                 }
             }
             if (!is_array($c)) {
                 $this->searchname = $c;
             }
         }
         if (is_array($c)) {
             list($ips, $ipe) = $c;
             if (strpos($ips, '.') === false && strpos($ips, ':') === false) {
                 // new numstr format
                 if ($ipt < $ips) {
                     return false;
                 }
                 if ($ipt >= $ips && $ipt <= $ipe) {
                     return $this->searchname . ': ' . $ip;
                 }
             } else {
                 if (strpos($ips, ':') !== false) {
                     // IPV6
                     if ($ip >= $ips && $ip <= $ipe) {
                         return $this->searchname . ': ' . $ip;
                     }
                 } else {
                     $ips = be_module::ip2numstr($ips);
                     $ipe = be_module::ip2numstr($ipe);
                     if ($ipt >= $ips && $ipt <= $ipe) {
                         if (is_array($ip)) {
                             echo "array in ip: " . print_r($ip, true) . "<br>";
                             $ip = $ip[0];
                         }
                         return $this->searchname . ': ' . $ip;
                     }
                 }
             }
         }
     }
     return false;
 }
Beispiel #3
0
 public function process($ip, &$stats = array(), &$options = array(), &$post = array())
 {
     if (empty($ip)) {
         return 'invalid ip: ' . $ip;
     }
     if (strpos($ip, ':') === false && strpos($ip, '.') === false) {
         return 'invalid ip: ' . $ip;
     }
     if (defined('AF_INET6') && strpos($ip, ':') !== false) {
         try {
             if (!@inet_pton($ip)) {
                 return 'invalid ip: ' . $ip;
             }
         } catch (Exception $e) {
             return 'invalid ip: ' . $ip;
         }
     }
     // check ip4 for local private ip addresses
     if ($ip == '127.0.0.1') {
         return 'Accessing site through localhost';
     }
     $priv = array(array('100000000000', '100255255255'), array('172016000000', '172031255255'), array('192168000000', '192168255255'));
     $ip2 = be_module::ip2numstr($ip);
     foreach ($priv as $ips) {
         if ($ip2 >= $ips[0] && $ip2 <= $ips[1]) {
             return 'local IP address:' . $ip;
         }
         if ($ip2 < $ips[1]) {
             break;
         }
         // sorted so we can bail
     }
     //use the experimental check fake ip routine
     // doesn't work on older PHPs or some servers without IP6 support enables.
     /*
     try {
     	if ($this->_is_fake_ip($ip)) {
     		return "Fake IP (experimental) $ip";
     	}
     } catch (Exception $e) {
     	return $e;
     }
     */
     // check fb ipv6
     $lip = "127.0.0.1";
     if (substr($ip, 0, 2) == 'FB' || substr($ip, 0, 2) == 'fb') {
         'local IP address:' . $ip;
     }
     // see if server and browser are running on same server.
     if (array_key_exists('SERVER_ADDR', $_SERVER)) {
         $lip = $_SERVER["SERVER_ADDR"];
         if ($ip == $lip) {
             return 'ip same as server:' . $ip;
         }
     } else {
         if (array_key_exists('LOCAL_ADDR', $_SERVER)) {
             // IIS 7?
             $lip = $_SERVER["LOCAL_ADDR"];
             if ($ip == $lip) {
                 return 'ip same as server:' . $ip;
             }
         } else {
             // IIs 6 no server address use a gethost by name? Hope we never get here
             try {
                 $lip = @gethostbyname($_SERVER['SERVER_NAME']);
                 if ($ip == $lip) {
                     return 'ip same as server:' . $ip;
                 }
             } catch (Exception $e) {
                 // can't make this work - ignore
             }
         }
     }
     // we can do this with ip4 addresses - check if same /24 subnet
     $j = strrpos($ip, '.');
     if ($j === false) {
         return false;
     }
     $k = strrpos($lip, '.');
     if ($k === false) {
         return false;
     }
     if (substr($ip, 0, $j) == substr($lip, 0, $k)) {
         return 'ip same /24 subnet as server' . $ip;
     }
     return false;
 }