Index: trunk/core/kernel/globals.php =================================================================== diff -u -N -r7887 -r8402 --- trunk/core/kernel/globals.php (.../globals.php) (revision 7887) +++ trunk/core/kernel/globals.php (.../globals.php) (revision 8402) @@ -113,7 +113,7 @@ { if(!defined($const_name)) define($const_name,$const_value); } - + if( !function_exists('parse_portal_ini') ) { function parse_portal_ini($file, $parse_section = false) @@ -335,6 +335,9 @@ curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); } + elseif ($request_type == 'GET' && isset($post) && strlen($post) > 0) { + curl_setopt($ch, CURLOPT_URL, preg_match('/\?/', $url) ? $url.'&'.$post : $url.'?'.$post); + } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @@ -488,4 +491,62 @@ } return $string; } + + /** + * Checks, that user IP address is within allowed range + * + * @param string $ip_list semi-column (by default) separated ip address list + * @param string $separator ip address separator (default ";") + * + * @return bool + */ + function ipMatch($ip_list, $separator = ';') + { + $ip_match = false; + $ip_addresses = $ip_list ? explode($separator, $ip_list) : Array (); + foreach ($ip_addresses as $ip_address) { + if (netMatch($ip_address, $_SERVER['REMOTE_ADDR'])) { + $ip_match = true; + break; + } + } + + return $ip_match; + } + + 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); + } + } ?> \ No newline at end of file