mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
[ticket/9871] Restore get_remote_file
PHPBB3-9871
This commit is contained in:
parent
6a8f110b5a
commit
8748032866
3 changed files with 73 additions and 139 deletions
|
@ -2925,6 +2925,72 @@ function get_database_size()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Retrieve contents from remotely stored file
|
||||||
|
*/
|
||||||
|
function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port = 80, $timeout = 6)
|
||||||
|
{
|
||||||
|
global $user;
|
||||||
|
|
||||||
|
if ($fsock = @fsockopen($host, $port, $errno, $errstr, $timeout))
|
||||||
|
{
|
||||||
|
@fputs($fsock, "GET $directory/$filename HTTP/1.0\r\n");
|
||||||
|
@fputs($fsock, "HOST: $host\r\n");
|
||||||
|
@fputs($fsock, "Connection: close\r\n\r\n");
|
||||||
|
|
||||||
|
$timer_stop = time() + $timeout;
|
||||||
|
stream_set_timeout($fsock, $timeout);
|
||||||
|
|
||||||
|
$file_info = '';
|
||||||
|
$get_info = false;
|
||||||
|
|
||||||
|
while (!@feof($fsock))
|
||||||
|
{
|
||||||
|
if ($get_info)
|
||||||
|
{
|
||||||
|
$file_info .= @fread($fsock, 1024);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$line = @fgets($fsock, 1024);
|
||||||
|
if ($line == "\r\n")
|
||||||
|
{
|
||||||
|
$get_info = true;
|
||||||
|
}
|
||||||
|
else if (stripos($line, '404 not found') !== false)
|
||||||
|
{
|
||||||
|
$errstr = $user->lang['FILE_NOT_FOUND'] . ': ' . $filename;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$stream_meta_data = stream_get_meta_data($fsock);
|
||||||
|
|
||||||
|
if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop)
|
||||||
|
{
|
||||||
|
$errstr = $user->lang['FSOCK_TIMEOUT'];
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@fclose($fsock);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ($errstr)
|
||||||
|
{
|
||||||
|
$errstr = utf8_convert_message($errstr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$errstr = $user->lang['FSOCK_DISABLED'];
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $file_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
* Tidy Warnings
|
* Tidy Warnings
|
||||||
* Remove all warnings which have now expired from the database
|
* Remove all warnings which have now expired from the database
|
||||||
* The duration of a warning can be defined by the administrator
|
* The duration of a warning can be defined by the administrator
|
||||||
|
|
|
@ -48,71 +48,3 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $
|
||||||
|
|
||||||
return phpbb_get_avatar($row, $alt, $ignore_config);
|
return phpbb_get_avatar($row, $alt, $ignore_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve contents from remotely stored file
|
|
||||||
*
|
|
||||||
* @deprecated 3.1.0-a4 (To be removed: 3.3.0)
|
|
||||||
*/
|
|
||||||
function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port = 80, $timeout = 6)
|
|
||||||
{
|
|
||||||
global $user;
|
|
||||||
|
|
||||||
if ($fsock = @fsockopen($host, $port, $errno, $errstr, $timeout))
|
|
||||||
{
|
|
||||||
@fputs($fsock, "GET $directory/$filename HTTP/1.0\r\n");
|
|
||||||
@fputs($fsock, "HOST: $host\r\n");
|
|
||||||
@fputs($fsock, "Connection: close\r\n\r\n");
|
|
||||||
|
|
||||||
$timer_stop = time() + $timeout;
|
|
||||||
stream_set_timeout($fsock, $timeout);
|
|
||||||
|
|
||||||
$file_info = '';
|
|
||||||
$get_info = false;
|
|
||||||
|
|
||||||
while (!@feof($fsock))
|
|
||||||
{
|
|
||||||
if ($get_info)
|
|
||||||
{
|
|
||||||
$file_info .= @fread($fsock, 1024);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$line = @fgets($fsock, 1024);
|
|
||||||
if ($line == "\r\n")
|
|
||||||
{
|
|
||||||
$get_info = true;
|
|
||||||
}
|
|
||||||
else if (stripos($line, '404 not found') !== false)
|
|
||||||
{
|
|
||||||
$errstr = $user->lang['FILE_NOT_FOUND'] . ': ' . $filename;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$stream_meta_data = stream_get_meta_data($fsock);
|
|
||||||
|
|
||||||
if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop)
|
|
||||||
{
|
|
||||||
$errstr = $user->lang['FSOCK_TIMEOUT'];
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@fclose($fsock);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($errstr)
|
|
||||||
{
|
|
||||||
$errstr = utf8_convert_message($errstr);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$errstr = $user->lang['FSOCK_DISABLED'];
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $file_info;
|
|
||||||
}
|
|
||||||
|
|
|
@ -151,7 +151,13 @@ class version_helper
|
||||||
|
|
||||||
if ($info === false || $force_update)
|
if ($info === false || $force_update)
|
||||||
{
|
{
|
||||||
$info = $this->get_remote_file('version.phpbb.com', '/phpbb', 'versions.json');
|
$errstr = $errno = '';
|
||||||
|
$info = get_remote_file('version.phpbb.com', '/phpbb', 'versions.json', $errstr, $errno);
|
||||||
|
|
||||||
|
if (!empty($errstr))
|
||||||
|
{
|
||||||
|
throw new \RuntimeException($errstr);
|
||||||
|
}
|
||||||
|
|
||||||
$info = json_decode($info, true);
|
$info = json_decode($info, true);
|
||||||
|
|
||||||
|
@ -176,74 +182,4 @@ class version_helper
|
||||||
|
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get remote file
|
|
||||||
*
|
|
||||||
* @param string $host Host, e.g. version.phpbb.com
|
|
||||||
* @param string $directory Directory, e.g. /phpbb
|
|
||||||
* @param string $filename Filename, e.g. versions.json
|
|
||||||
* @param int $port Port
|
|
||||||
* @param int $timeout Timeout (seconds)
|
|
||||||
* @return string Remote file contents
|
|
||||||
* @throws \RuntimeException
|
|
||||||
*/
|
|
||||||
public function get_remote_file($host, $directory, $filename, $port = 80, $timeout = 6)
|
|
||||||
{
|
|
||||||
$errstr = $errno = false;
|
|
||||||
|
|
||||||
if ($fsock = @fsockopen($host, $port, $errno, $errstr, $timeout))
|
|
||||||
{
|
|
||||||
@fputs($fsock, "GET $directory/$filename HTTP/1.0\r\n");
|
|
||||||
@fputs($fsock, "HOST: $host\r\n");
|
|
||||||
@fputs($fsock, "Connection: close\r\n\r\n");
|
|
||||||
|
|
||||||
$timer_stop = time() + $timeout;
|
|
||||||
stream_set_timeout($fsock, $timeout);
|
|
||||||
|
|
||||||
$file_info = '';
|
|
||||||
$get_info = false;
|
|
||||||
|
|
||||||
while (!@feof($fsock))
|
|
||||||
{
|
|
||||||
if ($get_info)
|
|
||||||
{
|
|
||||||
$file_info .= @fread($fsock, 1024);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$line = @fgets($fsock, 1024);
|
|
||||||
if ($line == "\r\n")
|
|
||||||
{
|
|
||||||
$get_info = true;
|
|
||||||
}
|
|
||||||
else if (stripos($line, '404 not found') !== false)
|
|
||||||
{
|
|
||||||
throw new \RuntimeException($this->user->lang('FILE_NOT_FOUND') . ': ' . $filename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$stream_meta_data = stream_get_meta_data($fsock);
|
|
||||||
|
|
||||||
if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop)
|
|
||||||
{
|
|
||||||
throw new \RuntimeException($this->user->lang('FSOCK_TIMEOUT'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@fclose($fsock);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($errstr)
|
|
||||||
{
|
|
||||||
throw new \RuntimeException(utf8_convert_message($errstr));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new \RuntimeException($this->user->lang('FSOCK_DISABLED'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $file_info;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue