diff options
author | Marc Alexander <admin@m-a-styles.de> | 2016-02-03 14:06:10 +0100 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2016-02-03 14:06:10 +0100 |
commit | c83db45f55858c78648a6650aec39a9fc627a50b (patch) | |
tree | 86b575f69ecca5bccea6b50bf12a71fa73955f8b | |
parent | [ticket/14448] Update composer.json and lock file for guzzlehttp (diff) | |
download | phpbb-c83db45f55858c78648a6650aec39a9fc627a50b.tar.gz phpbb-c83db45f55858c78648a6650aec39a9fc627a50b.tar.bz2 phpbb-c83db45f55858c78648a6650aec39a9fc627a50b.zip |
[ticket/14448] Use GuzzleHttp and try to verify certs
PHPBB3-14448
-rw-r--r-- | phpBB/phpbb/files/types/remote.php | 48 | ||||
-rw-r--r-- | tests/files/types_remote_test.php | 2 |
2 files changed, 37 insertions, 13 deletions
diff --git a/phpBB/phpbb/files/types/remote.php b/phpBB/phpbb/files/types/remote.php index 92e0e3b9bc..f4a4fa70d1 100644 --- a/phpBB/phpbb/files/types/remote.php +++ b/phpBB/phpbb/files/types/remote.php @@ -93,29 +93,53 @@ class remote extends base $url['path'] = implode('', $url['path']); $upload_ary['name'] = utf8_basename($url['path']) . (($ext) ? '.' . $ext : ''); - $filesize = 0; $remote_max_filesize = $this->get_max_file_size(); - $client = new \Guzzle\Http\Client([ + $guzzle_options = [ 'timeout' => $this->upload->upload_timeout, 'connect_timeout' => $this->upload->upload_timeout, - ]); + ]; + $client = new \GuzzleHttp\Client($guzzle_options); - try { - $response = $client->get($upload_url)->send(); - } catch (\Guzzle\Http\Exception\ClientErrorResponseException $responseException) { + try + { + $response = $client->get($upload_url, $guzzle_options); + } + catch (\GuzzleHttp\Exception\ClientException $clientException) + { return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'URL_NOT_FOUND'); - } catch (\Guzzle\Http\Exception\CurlException $curlException) { - //curl exceptions are when the DNS fails etc - return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED')); - } catch (\Guzzle\Http\Exception\RequestException $requestException) { - return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'REMOTE_UPLOAD_TIMEOUT'); + } + catch (\GuzzleHttp\Exception\RequestException $requestException) + { + if (strpos($requestException->getMessage(), 'cURL error 28') !== false || preg_match('/408|504/', $requestException->getCode())) + { + return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'REMOTE_UPLOAD_TIMEOUT'); + } + else + { + if (strpos($requestException->getMessage(), 'cURL error 60') !== false) + { + // Work around non existent CA file + try + { + $response = $client->get($upload_url, array_merge($guzzle_options, ['verify' => false])); + } + catch (\GuzzleHttp\Exception\RequestException $requestException) + { + return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED')); + } + } + else + { + return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED')); + } + } } catch (\Exception $e) { return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED')); } - $content_length = $response->getContentLength(); + $content_length = $response->getBody()->getSize(); if ($remote_max_filesize && $content_length > $remote_max_filesize) { $max_filesize = get_formatted_filesize($remote_max_filesize, false); diff --git a/tests/files/types_remote_test.php b/tests/files/types_remote_test.php index caed5c9e05..96103ad046 100644 --- a/tests/files/types_remote_test.php +++ b/tests/files/types_remote_test.php @@ -118,7 +118,7 @@ class phpbb_files_types_remote_test extends phpbb_test_case $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_allowed_extensions(array('png')); $type_remote->set_upload($upload); - $upload->upload_timeout = -5; + $upload->upload_timeout = 0.001; $file = $type_remote->upload('http://google.com/?.png'); |