diff --git a/upload/install/include/install_function.php b/upload/install/include/install_function.php index 448eb7ed9d08a3317d7f160292876259f2002647..5775d4f91d54075d01dbfebe85625a407de279cf 100644 --- a/upload/install/include/install_function.php +++ b/upload/install/include/install_function.php @@ -869,7 +869,7 @@ function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/'; $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80); - if(function_exists('curl_init') && $allowcurl) { + if(function_exists('curl_init') && function_exists('curl_exec') && $allowcurl) { $ch = curl_init(); $ip && curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: ".$host)); curl_setopt($ch, CURLOPT_URL, $scheme.'://'.($ip ? $ip : $host).':'.$port.$path); @@ -925,7 +925,7 @@ function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ } $fpflag = 0; - if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl' : $scheme).'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { + if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { $context = array( 'http' => array( 'method' => $post ? 'POST' : 'GET', diff --git a/upload/source/function/function_filesock.php b/upload/source/function/function_filesock.php index 7f0a8f5c2d0b9522368873f9e22504a8cb8639c8..634552936a68defd5f96158d01274c22e12aac40 100644 --- a/upload/source/function/function_filesock.php +++ b/upload/source/function/function_filesock.php @@ -183,7 +183,7 @@ function _dfsockopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FAL } $fpflag = 0; - if(!$fp = @fsocketopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout)) { + if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { $context = array( 'http' => array( 'method' => $post ? 'POST' : 'GET', @@ -193,7 +193,7 @@ function _dfsockopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FAL ), ); $context = stream_context_create($context); - $fp = @fopen($scheme.'://'.($ip ? $ip : $host).':'.$port.$path, 'b', false, $context); + $fp = @fopen($scheme.'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)).':'.$port.$path, 'b', false, $context); $fpflag = 1; } diff --git a/upload/uc_client/client.php b/upload/uc_client/client.php index f396693b2fa68d81bfefe32f25fdfaa503fa72be..034d06fd1f76d979497501b8b298607391aada6a 100644 --- a/upload/uc_client/client.php +++ b/upload/uc_client/client.php @@ -213,18 +213,119 @@ function uc_authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { } } -function uc_fopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) { +function uc_fopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { $__times__ = isset($_GET['__times__']) ? intval($_GET['__times__']) + 1 : 1; if($__times__ > 2) { return ''; } $url .= (strpos($url, '?') === FALSE ? '?' : '&')."__times__=$__times__"; - return uc_fopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block); -} + return uc_fopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block, $encodetype, $allowcurl); +} + +function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { + $return = ''; + $matches = parse_url($url); + $scheme = $matches['scheme']; + $host = $matches['host']; + $path = $matches['path'] ? $matches['path'].(isset($matches['query']) && $matches['query'] ? '?'.$matches['query'] : '') : '/'; + $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80); + + if(function_exists('curl_init') && function_exists('curl_exec') && $allowcurl) { + $ch = curl_init(); + $ip && curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: ".$host)); + curl_setopt($ch, CURLOPT_URL, $scheme.'://'.($ip ? $ip : $host).':'.$port.$path); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + if($post) { + curl_setopt($ch, CURLOPT_POST, 1); + if($encodetype == 'URLENCODE') { + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + } else { + parse_str($post, $postarray); + curl_setopt($ch, CURLOPT_POSTFIELDS, $postarray); + } + } + if($cookie) { + curl_setopt($ch, CURLOPT_COOKIE, $cookie); + } + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); + $data = curl_exec($ch); + $status = curl_getinfo($ch); + $errno = curl_errno($ch); + curl_close($ch); + if($errno || $status['http_code'] != 200) { + return; + } else { + return !$limit ? $data : substr($data, 0, $limit); + } + } + + if($post) { + $out = "POST $path HTTP/1.0\r\n"; + $header = "Accept: */*\r\n"; + $header .= "Accept-Language: zh-cn\r\n"; + $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; + $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n"; + $header .= "Host: $host\r\n"; + $header .= 'Content-Length: '.strlen($post)."\r\n"; + $header .= "Connection: Close\r\n"; + $header .= "Cache-Control: no-cache\r\n"; + $header .= "Cookie: $cookie\r\n\r\n"; + $out .= $header.$post; + } else { + $out = "GET $path HTTP/1.0\r\n"; + $header = "Accept: */*\r\n"; + $header .= "Accept-Language: zh-cn\r\n"; + $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n"; + $header .= "Host: $host\r\n"; + $header .= "Connection: Close\r\n"; + $header .= "Cookie: $cookie\r\n\r\n"; + $out .= $header; + } -function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) { - require_once libfile('function/filesock'); - return _dfsockopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block); + $fpflag = 0; + if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { + $context = array( + 'http' => array( + 'method' => $post ? 'POST' : 'GET', + 'header' => $header, + 'content' => $post, + 'timeout' => $timeout, + ), + ); + $context = stream_context_create($context); + $fp = @fopen($scheme.'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)).':'.$port.$path, 'b', false, $context); + $fpflag = 1; + } + + if(!$fp) { + return ''; + } else { + stream_set_blocking($fp, $block); + stream_set_timeout($fp, $timeout); + @fwrite($fp, $out); + $status = stream_get_meta_data($fp); + if(!$status['timed_out']) { + while (!feof($fp) && !$fpflag) { + if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) { + break; + } + } + + $stop = false; + while(!feof($fp) && !$stop) { + $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit)); + $return .= $data; + if($limit) { + $limit -= strlen($data); + $stop = $limit <= 0; + } + } + } + @fclose($fp); + return $return; + } } function uc_app_ls() { diff --git a/upload/uc_client/model/misc.php b/upload/uc_client/model/misc.php index e5ecd7c617382d95e5a2a0df77aecf04d7f858b4..cf8ed911034c668c575d5023019e56b623790ea7 100644 --- a/upload/uc_client/model/misc.php +++ b/upload/uc_client/model/misc.php @@ -52,16 +52,16 @@ class miscmodel { function test_api($url, $ip = '') { } - function dfopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE') { + function dfopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { $__times__ = isset($_GET['__times__']) ? intval($_GET['__times__']) + 1 : 1; if($__times__ > 2) { return ''; } $url .= (strpos($url, '?') === FALSE ? '?' : '&')."__times__=$__times__"; - return $this->dfopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block, $encodetype); + return $this->dfopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block, $encodetype, $allowcurl); } - function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE , $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE') { + function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE , $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { $return = ''; $matches = parse_url($url); $scheme = $matches['scheme']; @@ -69,6 +69,37 @@ class miscmodel { $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/'; $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80); + if(function_exists('curl_init') && function_exists('curl_exec') && $allowcurl) { + $ch = curl_init(); + $ip && curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: ".$host)); + curl_setopt($ch, CURLOPT_URL, $scheme.'://'.($ip ? $ip : $host).':'.$port.$path); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + if($post) { + curl_setopt($ch, CURLOPT_POST, 1); + if($encodetype == 'URLENCODE') { + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + } else { + parse_str($post, $postarray); + curl_setopt($ch, CURLOPT_POSTFIELDS, $postarray); + } + } + if($cookie) { + curl_setopt($ch, CURLOPT_COOKIE, $cookie); + } + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); + $data = curl_exec($ch); + $status = curl_getinfo($ch); + $errno = curl_errno($ch); + curl_close($ch); + if($errno || $status['http_code'] != 200) { + return; + } else { + return !$limit ? $data : substr($data, 0, $limit); + } + } + if($post) { $out = "POST $path HTTP/1.0\r\n"; $header = "Accept: */*\r\n"; @@ -94,7 +125,7 @@ class miscmodel { } $fpflag = 0; - if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl' : $scheme).'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { + if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { $context = array( 'http' => array( 'method' => $post ? 'POST' : 'GET', diff --git a/upload/uc_server/install/func.inc.php b/upload/uc_server/install/func.inc.php index 3825da2ffe5d5ed8a3f3b04ef1115e712149d215..5a99c4e28f82e8d38168adad9c33939d3afcaea8 100644 --- a/upload/uc_server/install/func.inc.php +++ b/upload/uc_server/install/func.inc.php @@ -741,7 +741,7 @@ function fsocketopen($hostname, $port = 80, &$errno, &$errstr, $timeout = 15) { return $fp; } -function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) { +function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { $return = ''; $matches = parse_url($url); $scheme = $matches['scheme']; @@ -749,6 +749,37 @@ function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ $path = $matches['path'] ? $matches['path'].(isset($matches['query']) && $matches['query'] ? '?'.$matches['query'] : '') : '/'; $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80); + if(function_exists('curl_init') && function_exists('curl_exec') && $allowcurl) { + $ch = curl_init(); + $ip && curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: ".$host)); + curl_setopt($ch, CURLOPT_URL, $scheme.'://'.($ip ? $ip : $host).':'.$port.$path); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + if($post) { + curl_setopt($ch, CURLOPT_POST, 1); + if($encodetype == 'URLENCODE') { + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + } else { + parse_str($post, $postarray); + curl_setopt($ch, CURLOPT_POSTFIELDS, $postarray); + } + } + if($cookie) { + curl_setopt($ch, CURLOPT_COOKIE, $cookie); + } + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); + $data = curl_exec($ch); + $status = curl_getinfo($ch); + $errno = curl_errno($ch); + curl_close($ch); + if($errno || $status['http_code'] != 200) { + return; + } else { + return !$limit ? $data : substr($data, 0, $limit); + } + } + if($post) { $out = "POST $path HTTP/1.0\r\n"; $header = "Accept: */*\r\n"; @@ -773,7 +804,7 @@ function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ } $fpflag = 0; - if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl' : $scheme).'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { + if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { $context = array( 'http' => array( 'method' => $post ? 'POST' : 'GET', diff --git a/upload/uc_server/model/misc.php b/upload/uc_server/model/misc.php index 49c9f7803637d364a03e02763c3b90240b4eade2..a0f0fd0d8810ecd43020c8ccb421ea13ea4f9a9f 100644 --- a/upload/uc_server/model/misc.php +++ b/upload/uc_server/model/misc.php @@ -50,16 +50,16 @@ class miscmodel { return preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $url); } - function dfopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE') { + function dfopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { $__times__ = isset($_GET['__times__']) ? intval($_GET['__times__']) + 1 : 1; if($__times__ > 2) { return ''; } $url .= (strpos($url, '?') === FALSE ? '?' : '&')."__times__=$__times__"; - return $this->dfopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block, $encodetype); + return $this->dfopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block, $encodetype, $allowcurl); } - function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE , $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE') { + function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE , $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) { $return = ''; $matches = parse_url($url); $scheme = $matches['scheme']; @@ -67,6 +67,37 @@ class miscmodel { $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/'; $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80); + if(function_exists('curl_init') && function_exists('curl_exec') && $allowcurl) { + $ch = curl_init(); + $ip && curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: ".$host)); + curl_setopt($ch, CURLOPT_URL, $scheme.'://'.($ip ? $ip : $host).':'.$port.$path); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + if($post) { + curl_setopt($ch, CURLOPT_POST, 1); + if($encodetype == 'URLENCODE') { + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + } else { + parse_str($post, $postarray); + curl_setopt($ch, CURLOPT_POSTFIELDS, $postarray); + } + } + if($cookie) { + curl_setopt($ch, CURLOPT_COOKIE, $cookie); + } + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); + $data = curl_exec($ch); + $status = curl_getinfo($ch); + $errno = curl_errno($ch); + curl_close($ch); + if($errno || $status['http_code'] != 200) { + return; + } else { + return !$limit ? $data : substr($data, 0, $limit); + } + } + if($post) { $out = "POST $path HTTP/1.0\r\n"; $header = "Accept: */*\r\n"; @@ -92,7 +123,7 @@ class miscmodel { } $fpflag = 0; - if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl' : $scheme).'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { + if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { $context = array( 'http' => array( 'method' => $post ? 'POST' : 'GET',