From: Tim Düsterhus Date: Thu, 17 May 2012 13:59:11 +0000 (+0200) Subject: Fixing RemoteFile and Proxy Usage X-Git-Tag: 2.0.0_Beta_1~1101^2~7^2~4 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0bc0d3397f2fae042246ae07214c782d1e9a302d;p=GitHub%2FWoltLab%2FWCF.git Fixing RemoteFile and Proxy Usage - RemoteFile no longer accepts an array of options, fsockopen does not support them - Rewrite FileUtil::downloadFileFromHTTP to support proxy --- diff --git a/wcfsetup/install/files/lib/system/io/RemoteFile.class.php b/wcfsetup/install/files/lib/system/io/RemoteFile.class.php index 2c141b3b35..286c50b243 100644 --- a/wcfsetup/install/files/lib/system/io/RemoteFile.class.php +++ b/wcfsetup/install/files/lib/system/io/RemoteFile.class.php @@ -45,16 +45,11 @@ class RemoteFile extends File { * @param integer $timeout * @param array $options */ - public function __construct($host, $port, $timeout = 30, $options = array()) { + public function __construct($host, $port, $timeout = 3) { $this->host = $host; $this->port = $port; - if (count($options)) { - $context = stream_context_create($options); - $this->resource = fsockopen($host, $port, $this->errorNumber, $this->errorDesc, $timeout, $context); - } - else { - $this->resource = fsockopen($host, $port, $this->errorNumber, $this->errorDesc, $timeout); - } + + $this->resource = fsockopen($host, $port, $this->errorNumber, $this->errorDesc, $timeout); if ($this->resource === false) { throw new SystemException('Can not connect to ' . $host); } diff --git a/wcfsetup/install/files/lib/util/FileUtil.class.php b/wcfsetup/install/files/lib/util/FileUtil.class.php index 6df24f453e..f9c7128b16 100644 --- a/wcfsetup/install/files/lib/util/FileUtil.class.php +++ b/wcfsetup/install/files/lib/util/FileUtil.class.php @@ -399,20 +399,11 @@ final class FileUtil { $newFileName = self::getTemporaryFilename($prefix.'_'); $localFile = new File($newFileName); // the file to write. - // parse options - if (PROXY_SERVER_HTTP) { - $options['http']['proxy'] = PROXY_SERVER_HTTP; - $options['http']['request_fulluri'] = true; - } - $timeout = 30; - if (isset($options['timeout'])) { - $timeout = $options['timeout']; - unset($options['timeout']); + if (!isset($options['timeout'])) { + $options['timeout'] = 30; } - $method = (!empty($postParameters) ? 'POST' : 'GET'); - if (isset($options['method'])) { - $method = $options['method']; - unset($options['method']); + if (!isset($options['method'])) { + $options['method'] = (!empty($postParameters) ? 'POST' : 'GET'); } // parse URL @@ -420,6 +411,14 @@ final class FileUtil { $port = ($parsedUrl['scheme'] == 'https' ? 443 : 80); $host = $parsedUrl['host']; $path = (isset($parsedUrl['path']) ? $parsedUrl['path'] : '/'); + // proxy is set + if (PROXY_SERVER_HTTP) { + $parsedProxy = parse_url(PROXY_SERVER_HTTP); + $host = $parsedProxy['host']; + $port = ($parsedProxy['scheme'] == 'https' ? 443 : 80); + $path = $httpUrl; + $parsedUrl['query'] = ''; + } // build parameter-string $parameterString = ''; @@ -437,7 +436,7 @@ final class FileUtil { // connect try { - $remoteFile = new RemoteFile(($parsedUrl['scheme'] == 'https' ? 'ssl://' : '').$host, $port, $timeout, $options); + $remoteFile = new RemoteFile(($port === 443 ? 'ssl://' : '').$host, $port, $options['timeout']); } catch (SystemException $e) { $localFile->close(); @@ -446,7 +445,7 @@ final class FileUtil { } // build and send the http request. - $request = $method." ".$path.(!empty($parsedUrl['query']) ? '?'.$parsedUrl['query'] : '')." HTTP/1.0\r\n"; + $request = $options['method']." ".$path.(!empty($parsedUrl['query']) ? '?'.$parsedUrl['query'] : '')." HTTP/1.0\r\n"; $request .= "User-Agent: HTTP.PHP (FileUtil.class.php; WoltLab Community Framework/".WCF_VERSION."; ".WCF::getLanguage()->languageCode.")\r\n"; $request .= "Accept: */*\r\n"; $request .= "Accept-Language: ".WCF::getLanguage()->languageCode."\r\n";