Index: trunk/core/kernel/utility/debugger.php =================================================================== diff -u -N -r6703 -r7391 --- trunk/core/kernel/utility/debugger.php (.../debugger.php) (revision 6703) +++ trunk/core/kernel/utility/debugger.php (.../debugger.php) (revision 7391) @@ -73,8 +73,28 @@ function Debugger() { - global $start; + global $start, $dbg_options; + // check if user haven't defined DEBUG_MODE contant directly + if (defined('DEBUG_MODE') && DEBUG_MODE) { + die('error: contant DEBUG_MODE defined directly, please use $dbg_options array instead'); + } + // check IP before enabling debug mode + $ip_match = false; + $ip_addresses = isset($dbg_options['DBG_IP']) ? explode(';', $dbg_options['DBG_IP']) : Array (); + 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 ; + } + + // debug is allowed for user, continue initialization $this->InitDebugger(); $this->profileStart('kernel4_startup', 'Startup and Initialization of kernel4', $start); $this->profileStart('script_runtime', 'Script runtime', $start); @@ -92,8 +112,10 @@ */ function InitDebugger() { - unset($_REQUEST['debug_host'], $_REQUEST['debug_fastfile']); // this var messed up whole detection stuff :( + global $dbg_options; + unset($_REQUEST['debug_host'], $_REQUEST['debug_fastfile'], $dbg_options['DBG_IP']); // this var messed up whole detection stuff :( + // Detect fact, that this session beeing debugged by Zend Studio foreach ($_REQUEST as $rq_name => $rq_value) { if (substr($rq_name, 0, 6) == 'debug_') { @@ -122,6 +144,9 @@ $dbg_constMap['DBG_EDITOR'] = 'c:\Program Files\Zend\ZendStudio-5.2.0\bin\ZDE.exe %F'; } + // user defined options override debugger defaults + $dbg_constMap = $this->array_merge_recursive2($dbg_constMap, $dbg_options); + foreach ($dbg_constMap as $dbg_constName => $dbg_constValue) { $this->safeDefine($dbg_constName, $dbg_constValue); } @@ -138,6 +163,56 @@ } } + function array_merge_recursive2($paArray1, $paArray2) + { + if (!is_array($paArray1) or !is_array($paArray2)) { + return $paArray2; + } + + foreach ($paArray2 AS $sKey2 => $sValue2) { + $paArray1[$sKey2] = isset($paArray1[$sKey2]) ? array_merge_recursive2($paArray1[$sKey2], $sValue2) : $sValue2; + } + + 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; @@ -313,7 +388,8 @@ if (is_null($array)) { return 'NULL'; - }elseif (!is_array($array)) { + } + elseif (!is_array($array)) { if ($cut_min_length != -1 && strlen($array) > $cut_min_length) { $array = substr($array, 0, $cut_first).' ...'; }