Index: branches/unlabeled/unlabeled-1.63.4/core/kernel/utility/debugger.php =================================================================== diff -u -r7007 -r7008 --- branches/unlabeled/unlabeled-1.63.4/core/kernel/utility/debugger.php (.../debugger.php) (revision 7007) +++ branches/unlabeled/unlabeled-1.63.4/core/kernel/utility/debugger.php (.../debugger.php) (revision 7008) @@ -80,8 +80,16 @@ } // check IP before enabling debug mode + $ip_match = false; $ip_addresses = isset($dbg_options['DBG_IP']) ? explode(';', $dbg_options['DBG_IP']) : Array (); - if (!in_array($_SERVER['REMOTE_ADDR'], $ip_addresses)) { + foreach ($ip_addresses as $ip_address) { + if ($this->netMatch($ip_address, $_SERVER['REMOTE_ADDR'])) { + $ip_match = true; + break; + } + } + + if (!$ip_match) { define('DEBUG_MODE', 0); return ; } @@ -168,6 +176,43 @@ return $paArray1; } + function netMatch($network, $ip) { + + $network = trim($network); + $ip = trim($ip); + + if ($network == $ip) { + // comparing 2 ip addresses directly + return true; + } + + $d = strpos($network, '-'); + if ($d === false) { + // sigle subnet specified + $ip_arr = explode('/', $network); + + if (!preg_match("@\d*\.\d*\.\d*\.\d*@", $ip_arr[0], $matches)) { + $ip_arr[0] .= '.0'; // Alternate form 194.1.4/24 + } + + $network_long = ip2long($ip_arr[0]); + $x = ip2long($ip_arr[1]); + + $mask = long2ip($x) == $ip_arr[1] ? $x : (0xffffffff << (32 - $ip_arr[1])); + $ip_long = ip2long($ip); + + return ($ip_long & $mask) == ($network_long & $mask); + } + else { + // ip address range specified + $from = ip2long(trim(substr($network, 0, $d))); + $to = ip2long(trim(substr($network, $d + 1))); + + $ip = ip2long($ip); + return ($ip >= $from && $ip <= $to); + } + } + function InitReport() { if (!class_exists('kApplication')) return false;