1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-21 00:02:18 +02:00

[ticket/14448] Use GuzzleHttp and try to verify certs

PHPBB3-14448
This commit is contained in:
Marc Alexander 2016-02-03 14:06:10 +01:00
parent 5ee559d524
commit c83db45f55
2 changed files with 37 additions and 13 deletions

View File

@ -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);

View File

@ -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');