From 6c8589775b8df2b6fbeffbe594d9279ae90e85ba Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 19 Feb 2014 16:11:40 -0600 Subject: [ticket/9871] Update version check file to use json format PHPBB3-9871 --- phpBB/phpbb/version_helper.php | 249 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 phpBB/phpbb/version_helper.php (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php new file mode 100644 index 0000000000..df577c5dff --- /dev/null +++ b/phpBB/phpbb/version_helper.php @@ -0,0 +1,249 @@ +cache = $cache; + $this->config = $config; + $this->user = $user; + } + + /** + * Wrapper for version_compare() that allows using uppercase A and B + * for alpha and beta releases. + * + * See http://www.php.net/manual/en/function.version-compare.php + * + * @param string $version1 First version number + * @param string $version2 Second version number + * @param string $operator Comparison operator (optional) + * + * @return mixed Boolean (true, false) if comparison operator is specified. + * Integer (-1, 0, 1) otherwise. + */ + public function compare($version1, $version2, $operator = null) + { + $version1 = strtolower($version1); + $version2 = strtolower($version2); + + if (is_null($operator)) + { + return version_compare($version1, $version2); + } + else + { + return version_compare($version1, $version2, $operator); + } + } + + /** + * Check whether or not a version is "stable" + * + * Stable means only numbers OR a pl release + * + * @param string $version + * @return bool Bool true or false + */ + public function is_stable($version) + { + $matches = false; + preg_match('/^[\d\.]+/', $version, $matches); + + if (empty($matches[0])) + { + return false; + } + + return $this->compare($version, $matches[0], '>='); + } + + /** + * Gets the latest version for the current branch the user is on + * + * @param bool $force_update Ignores cached data. Defaults to false. + * @return string + * @throws \RuntimeException + */ + public function get_latest_on_current_branch($force_update = false) + { + $versions = $this->get_versions_matching_stability($force_update); + + $self = $this; + $current_version = $this->config['version']; + + // Filter out any versions less than to the current version + $versions = array_filter($versions, function($data) use ($self, $current_version) { + return $self->compare($data['current'], $current_version, '>='); + }); + + // Get the lowest version from the previous list. + return array_reduce($versions, function($value, $data) use ($self) { + if ($value === null || $self->compare($data['current'], $value, '<')) + { + return $data['current']; + } + + return $value; + }); + } + + /** + * Obtains the latest version information + * + * @param bool $force_update Ignores cached data. Defaults to false. + * @return string + * @throws \RuntimeException + */ + public function get_suggested_updates($force_update = false) + { + $versions = $this->get_versions_matching_stability($force_update); + + $self = $this; + $current_version = $this->config['version']; + + // Filter out any versions less than or equal to the current version + return array_filter($versions, function($data) use ($self, $current_version) { + return $self->compare($data['current'], $current_version, '>'); + }); + } + + /** + * Obtains the latest version information matching the stability of the current install + * + * @param bool $force_update Ignores cached data. Defaults to false. + * @return string Version info + * @throws \RuntimeException + */ + public function get_versions_matching_stability($force_update = false) + { + $info = $this->get_versions($force_update); + + return ($this->is_stable($this->config['version']) && !defined('PHPBB_QA')) ? $info['stable'] : $info['unstable']; + } + + /** + * Obtains the latest version information + * + * @param bool $force_update Ignores cached data. Defaults to false. + * @return string Version info, includes stable and unstable data + * @throws \RuntimeException + */ + public function get_versions($force_update = false) + { + $info = $this->cache->get('versioncheck'); + + if ($info === false || $force_update) + { + $info = $this->get_remote_file('version.phpbb.com', '/phpbb', 'versions.json'); + + $info = json_decode($info, true); + + if (empty($info['stable']) || empty($info['unstable'])) + { + $this->user->add_lang('acp/common'); + + throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL')); + } + + // Replace & with & on announcement links + foreach ($info as $stability => $branches) + { + foreach ($branches as $branch => $branch_data) + { + $info[$stability][$branch]['announcement'] = str_replace('&', '&', $branch_data['announcement']); + } + } + + $this->cache->put('versioncheck', $info, 86400); // 24 hours + } + + 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; + } +} -- cgit v1.2.1 From 8748032866293129b881f9b7f3f0173c1e3a646b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 5 Mar 2014 19:07:39 -0600 Subject: [ticket/9871] Restore get_remote_file PHPBB3-9871 --- phpBB/phpbb/version_helper.php | 78 ++++-------------------------------------- 1 file changed, 7 insertions(+), 71 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index df577c5dff..f9db731415 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -151,7 +151,13 @@ class version_helper 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); @@ -176,74 +182,4 @@ class version_helper 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; - } } -- cgit v1.2.1 From 43074a1b6938f3efb2b9282a25cf7beb3b1e14a6 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 5 Mar 2014 19:09:47 -0600 Subject: [ticket/9871] Restore phpbb_version_compare PHPBB3-9871 --- phpBB/phpbb/version_helper.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index f9db731415..54c56a1b7f 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -40,17 +40,7 @@ class version_helper */ public function compare($version1, $version2, $operator = null) { - $version1 = strtolower($version1); - $version2 = strtolower($version2); - - if (is_null($operator)) - { - return version_compare($version1, $version2); - } - else - { - return version_compare($version1, $version2, $operator); - } + return phpbb_version_compare($version1, $version2, $operator); } /** -- cgit v1.2.1 From 98542547e2b0416f0f11bc1d75e5d999ae0d9f2b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 5 Mar 2014 19:18:54 -0600 Subject: [ticket/9871] Typehint and comment on var types PHPBB3-9871 --- phpBB/phpbb/version_helper.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 54c56a1b7f..6f2fd0c732 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -14,11 +14,16 @@ namespace phpbb; */ class version_helper { + /** @var \phpbb\cache\service */ protected $cache; + + /** @var \phpbb\config\config */ protected $config; + + /** @var \phpbb\user */ protected $user; - public function __construct($cache, $config, $user) + public function __construct(\phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\user $user) { $this->cache = $cache; $this->config = $config; -- cgit v1.2.1 From 00d86a4af1adc4d34955d0432ef514d8c25942c9 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 10 Mar 2014 21:26:46 -0500 Subject: [ticket/9871] Allow setting the host/file to load for the version class PHPBB3-9871 --- phpBB/phpbb/version_helper.php | 47 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 6f2fd0c732..d7bc09182e 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -14,6 +14,21 @@ namespace phpbb; */ class version_helper { + /** + * @var string Host + */ + protected $host = 'version.phpbb.com'; + + /** + * @var string Path to file + */ + protected $path = '/phpbb'; + + /** + * @var string File name + */ + protected $file = 'versions.json'; + /** @var \phpbb\cache\service */ protected $cache; @@ -23,6 +38,13 @@ class version_helper /** @var \phpbb\user */ protected $user; + /** + * Constructor + * + * @param \phpbb\cache\service $cache + * @param \phpbb\config\config $config + * @param \phpbb\user $user + */ public function __construct(\phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\user $user) { $this->cache = $cache; @@ -30,6 +52,23 @@ class version_helper $this->user = $user; } + /** + * Set location to the file + * + * @param string $host Host (e.g. version.phpbb.com) + * @param string $path Path to file (e.g. /phpbb) + * @param string $file File name (Default: versions.json) + * @return version_helper + */ + public function set_file_location($host, $path, $file = 'versions.json') + { + $this->host = $host; + $this->path = $path; + $this->file = $file; + + return $this; + } + /** * Wrapper for version_compare() that allows using uppercase A and B * for alpha and beta releases. @@ -142,12 +181,14 @@ class version_helper */ public function get_versions($force_update = false) { - $info = $this->cache->get('versioncheck'); + $cache_file = 'versioncheck_' . $this->host . $this->path . $this->file; + + $info = $this->cache->get($cache_file); if ($info === false || $force_update) { $errstr = $errno = ''; - $info = get_remote_file('version.phpbb.com', '/phpbb', 'versions.json', $errstr, $errno); + $info = get_remote_file($this->host, $this->path, $this->file, $errstr, $errno); if (!empty($errstr)) { @@ -172,7 +213,7 @@ class version_helper } } - $this->cache->put('versioncheck', $info, 86400); // 24 hours + $this->cache->put($cache_file, $info, 86400); // 24 hours } return $info; -- cgit v1.2.1 From feed1441add9582d987c7480b92cc38946eedf15 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 11 Mar 2014 19:15:50 -0500 Subject: [ticket/9871] Option to force the stability when checking for updates PHPBB3-9871 --- phpBB/phpbb/version_helper.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index d7bc09182e..b8f305111f 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -29,6 +29,12 @@ class version_helper */ protected $file = 'versions.json'; + /** + * @var null|string Null to not force stability, 'unstable' or 'stable' to + * force the corresponding stability + */ + protected $force_stability; + /** @var \phpbb\cache\service */ protected $cache; @@ -50,6 +56,11 @@ class version_helper $this->cache = $cache; $this->config = $config; $this->user = $user; + + if (defined('PHPBB_QA')) + { + $this->force_stability = 'unstable'; + } } /** @@ -69,6 +80,20 @@ class version_helper return $this; } + /** + * Over-ride the stability to force check to include unstable versions + * + * @param null|string Null to not force stability, 'unstable' or 'stable' to + * force the corresponding stability + * @return version_helper + */ + public function force_stability($stability) + { + $this->force_stability = $stability; + + return $this; + } + /** * Wrapper for version_compare() that allows using uppercase A and B * for alpha and beta releases. @@ -169,7 +194,12 @@ class version_helper { $info = $this->get_versions($force_update); - return ($this->is_stable($this->config['version']) && !defined('PHPBB_QA')) ? $info['stable'] : $info['unstable']; + if ($this->force_stability !== null) + { + return ($this->force_stability === 'unstable') ? $info['unstable'] : $info['stable']; + } + + return ($this->is_stable($this->config['version'])) ? $info['stable'] : $info['unstable']; } /** -- cgit v1.2.1 From 60d2c1f4006894f2bb4fa310372734d02565e9ca Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Mar 2014 07:07:26 -0500 Subject: [ticket/9871] Can set current version to use instead of the phpBB version PHPBB3-9871 --- phpBB/phpbb/version_helper.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index b8f305111f..e2fdf6ce63 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -29,6 +29,11 @@ class version_helper */ protected $file = 'versions.json'; + /** + * @var string Current version installed + */ + protected $current_version; + /** * @var null|string Null to not force stability, 'unstable' or 'stable' to * force the corresponding stability @@ -61,6 +66,8 @@ class version_helper { $this->force_stability = 'unstable'; } + + $this->current_version = $this->config['version']; } /** @@ -80,6 +87,19 @@ class version_helper return $this; } + /** + * Set current version + * + * @param string $version The current version + * @return version_helper + */ + public function set_current_version($version) + { + $this->current_version = $version; + + return $this; + } + /** * Over-ride the stability to force check to include unstable versions * @@ -145,7 +165,7 @@ class version_helper $versions = $this->get_versions_matching_stability($force_update); $self = $this; - $current_version = $this->config['version']; + $current_version = $this->current_version; // Filter out any versions less than to the current version $versions = array_filter($versions, function($data) use ($self, $current_version) { @@ -175,7 +195,7 @@ class version_helper $versions = $this->get_versions_matching_stability($force_update); $self = $this; - $current_version = $this->config['version']; + $current_version = $this->current_version; // Filter out any versions less than or equal to the current version return array_filter($versions, function($data) use ($self, $current_version) { @@ -199,7 +219,7 @@ class version_helper return ($this->force_stability === 'unstable') ? $info['unstable'] : $info['stable']; } - return ($this->is_stable($this->config['version'])) ? $info['stable'] : $info['unstable']; + return ($this->is_stable($this->current_version)) ? $info['stable'] : $info['unstable']; } /** -- cgit v1.2.1 From 36d5fff1c6cbacbda4b4c623d8b9d909f214167a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 12 May 2014 23:47:05 +0200 Subject: [ticket/12536] Get Versions Should Not Require Both Stable and Unstable https://tracker.phpbb.com/browse/PHPBB3-12536 PHPBB3-12536 --- phpBB/phpbb/version_helper.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index e2fdf6ce63..7d59b5cd3a 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -216,10 +216,19 @@ class version_helper if ($this->force_stability !== null) { - return ($this->force_stability === 'unstable') ? $info['unstable'] : $info['stable']; + $stability = ($this->force_stability === 'unstable') ? 'unstable' : 'stable'; + } + else + { + $stability = $this->is_stable($this->current_version) ? 'stable' : 'unstable'; + } + + if (!isset($info[$stability])) + { + throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL')); } - return ($this->is_stable($this->current_version)) ? $info['stable'] : $info['unstable']; + return $info[$stability]; } /** @@ -247,7 +256,7 @@ class version_helper $info = json_decode($info, true); - if (empty($info['stable']) || empty($info['unstable'])) + if (empty($info['stable']) && empty($info['unstable'])) { $this->user->add_lang('acp/common'); -- cgit v1.2.1 From 3dddf1f4bf84d7a97ee47623a868483079ed643e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 13 May 2014 12:48:08 +0200 Subject: [ticket/12536] Return empty array if stability unavailable PHPBB3-12536 --- phpBB/phpbb/version_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 7d59b5cd3a..4c779c1a5a 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -225,7 +225,7 @@ class version_helper if (!isset($info[$stability])) { - throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL')); + return array(); } return $info[$stability]; -- cgit v1.2.1 From 8b6df0e2f8a0601b43a1c1186f09bf058dadb47b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 13 May 2014 12:59:10 +0200 Subject: [ticket/12536] Update doc block PHPBB3-12536 --- phpBB/phpbb/version_helper.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 4c779c1a5a..8e1c593094 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -208,7 +208,6 @@ class version_helper * * @param bool $force_update Ignores cached data. Defaults to false. * @return string Version info - * @throws \RuntimeException */ public function get_versions_matching_stability($force_update = false) { -- cgit v1.2.1 From e1d9f1c67c9be90ac2f7f6a86ed02f0c22622afa Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 15 May 2014 01:14:44 +0200 Subject: [ticket/12536] Use stable values when unstable are unavailable PHPBB3-12536 --- phpBB/phpbb/version_helper.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 8e1c593094..4718088ab6 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -215,19 +215,10 @@ class version_helper if ($this->force_stability !== null) { - $stability = ($this->force_stability === 'unstable') ? 'unstable' : 'stable'; - } - else - { - $stability = $this->is_stable($this->current_version) ? 'stable' : 'unstable'; - } - - if (!isset($info[$stability])) - { - return array(); + return ($this->force_stability === 'unstable') ? $info['unstable'] : $info['stable']; } - return $info[$stability]; + return ($this->is_stable($this->current_version)) ? $info['stable'] : $info['unstable']; } /** @@ -271,6 +262,9 @@ class version_helper } } + $info['stable'] = (empty($info['stable'])) ? array() : $info['stable']; + $info['unstable'] = (empty($info['unstable'])) ? $info['stable'] : $info['unstable']; + $this->cache->put($cache_file, $info, 86400); // 24 hours } -- cgit v1.2.1 From 8a227b981adae1ec49ad0996f32fe3e5fff33e8a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 26 May 2014 23:46:59 +0200 Subject: [ticket/12536] Restore missing @throws PHPBB3-12536 --- phpBB/phpbb/version_helper.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 4718088ab6..76bd477e18 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -208,6 +208,7 @@ class version_helper * * @param bool $force_update Ignores cached data. Defaults to false. * @return string Version info + * @throws \RuntimeException */ public function get_versions_matching_stability($force_update = false) { -- cgit v1.2.1 From a759704b39fc1c1353f865a633759b1369589b67 Mon Sep 17 00:00:00 2001 From: Yuriy Rusko Date: Tue, 27 May 2014 20:18:06 +0200 Subject: [ticket/12594] Remove @package tags and update file headers PHPBB3-12594 --- phpBB/phpbb/version_helper.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index e2fdf6ce63..47e9bbe0f3 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ -- cgit v1.2.1 From 521fe2b8e29fdb61ab0c02ec40f20b652d66623a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 12 May 2014 12:30:27 +0200 Subject: [ticket/11366] Force the use of the cache on the list page PHPBB3-11366 --- phpBB/phpbb/version_helper.php | 72 +++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 32 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 5991744e76..968a57428f 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -158,15 +158,16 @@ class version_helper } /** - * Gets the latest version for the current branch the user is on - * - * @param bool $force_update Ignores cached data. Defaults to false. - * @return string - * @throws \RuntimeException - */ - public function get_latest_on_current_branch($force_update = false) + * Gets the latest version for the current branch the user is on + * + * @param bool $force_update Ignores cached data. Defaults to false. + * @param bool $force_cache Force the use of the cache. Override $force_update. + * @return string + * @throws \RuntimeException + */ + public function get_latest_on_current_branch($force_update = false, $force_cache = false) { - $versions = $this->get_versions_matching_stability($force_update); + $versions = $this->get_versions_matching_stability($force_update, $force_cache); $self = $this; $current_version = $this->current_version; @@ -188,15 +189,16 @@ class version_helper } /** - * Obtains the latest version information - * - * @param bool $force_update Ignores cached data. Defaults to false. - * @return string - * @throws \RuntimeException - */ - public function get_suggested_updates($force_update = false) + * Obtains the latest version information + * + * @param bool $force_update Ignores cached data. Defaults to false. + * @param bool $force_cache Force the use of the cache. Override $force_update. + * @return string + * @throws \RuntimeException + */ + public function get_suggested_updates($force_update = false, $force_cache = false) { - $versions = $this->get_versions_matching_stability($force_update); + $versions = $this->get_versions_matching_stability($force_update, $force_cache); $self = $this; $current_version = $this->current_version; @@ -208,15 +210,16 @@ class version_helper } /** - * Obtains the latest version information matching the stability of the current install - * - * @param bool $force_update Ignores cached data. Defaults to false. - * @return string Version info - * @throws \RuntimeException - */ - public function get_versions_matching_stability($force_update = false) + * Obtains the latest version information matching the stability of the current install + * + * @param bool $force_update Ignores cached data. Defaults to false. + * @param bool $force_cache Force the use of the cache. Override $force_update. + * @return string Version info + * @throws \RuntimeException + */ + public function get_versions_matching_stability($force_update = false, $force_cache = false) { - $info = $this->get_versions($force_update); + $info = $this->get_versions($force_update, $force_cache); if ($this->force_stability !== null) { @@ -227,19 +230,24 @@ class version_helper } /** - * Obtains the latest version information - * - * @param bool $force_update Ignores cached data. Defaults to false. - * @return string Version info, includes stable and unstable data - * @throws \RuntimeException - */ - public function get_versions($force_update = false) + * Obtains the latest version information + * + * @param bool $force_update Ignores cached data. Defaults to false. + * @param bool $force_cache Force the use of the cache. Override $force_update. + * @return string Version info, includes stable and unstable data + * @throws \RuntimeException + */ + public function get_versions($force_update = false, $force_cache = false) { $cache_file = 'versioncheck_' . $this->host . $this->path . $this->file; $info = $this->cache->get($cache_file); - if ($info === false || $force_update) + if ($info === false && $force_cache) + { + throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL')); + } + else if ($info === false || $force_update) { $errstr = $errno = ''; $info = get_remote_file($this->host, $this->path, $this->file, $errstr, $errno); -- cgit v1.2.1 From 6380aea647c2d611a4c3aaf5d0fe4046782340dd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 Oct 2014 00:34:51 +0100 Subject: [ticket/13232] Fix more issues with TTL and global cache file PHPBB3-13232 --- phpBB/phpbb/version_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 968a57428f..96386f6d04 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -239,7 +239,7 @@ class version_helper */ public function get_versions($force_update = false, $force_cache = false) { - $cache_file = 'versioncheck_' . $this->host . $this->path . $this->file; + $cache_file = '_versioncheck_' . $this->host . $this->path . $this->file; $info = $this->cache->get($cache_file); -- cgit v1.2.1 From 3fba5e317adefce4814e49ee6a3c6b80f79bafe9 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sun, 9 Nov 2014 01:21:40 +0100 Subject: [ticket/13243] Validate announcement entry for existence in version_helper PHPBB3-13243 --- phpBB/phpbb/version_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 96386f6d04..c3c3602944 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -271,7 +271,7 @@ class version_helper { foreach ($branches as $branch => $branch_data) { - $info[$stability][$branch]['announcement'] = str_replace('&', '&', $branch_data['announcement']); + $info[$stability][$branch]['announcement'] = (!empty($branch_data['announcement'])) ? str_replace('&', '&', $branch_data['announcement']) : ''; } } -- cgit v1.2.1 From 2793f9c078272b178250ed4e0812219b9c5c1676 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 21 Nov 2014 18:07:36 +0100 Subject: [ticket/13358] Add file_downloader to version_helper PHPBB3-13358 --- phpBB/phpbb/version_helper.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index c3c3602944..3b455ec5ba 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -50,6 +50,9 @@ class version_helper /** @var \phpbb\config\config */ protected $config; + /** @var \phpbb\file_downloader */ + protected $file_downloader; + /** @var \phpbb\user */ protected $user; @@ -58,12 +61,14 @@ class version_helper * * @param \phpbb\cache\service $cache * @param \phpbb\config\config $config + * @param \phpbb\file_downloader $file_downloader * @param \phpbb\user $user */ - public function __construct(\phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\user $user) + public function __construct(\phpbb\cache\service $cache, \phpbb\config\config $config, file_downloader $file_downloader, \phpbb\user $user) { $this->cache = $cache; $this->config = $config; + $this->file_downloader = $file_downloader; $this->user = $user; if (defined('PHPBB_QA')) @@ -250,7 +255,9 @@ class version_helper else if ($info === false || $force_update) { $errstr = $errno = ''; - $info = get_remote_file($this->host, $this->path, $this->file, $errstr, $errno); + $this->file_downloader->set_error_number($errno) + ->set_error_string($errstr); + $info = $this->file_downloader->get($this->host, $this->path, $this->file); if (!empty($errstr)) { -- cgit v1.2.1 From 352648f173e7b132544bf3eaa494184bec6d5aa2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 21 Nov 2014 21:34:02 +0100 Subject: [ticket/13358] Fix tests and use exceptions instead of user object PHPBB3-13358 --- phpBB/phpbb/version_helper.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 3b455ec5ba..d7f1f02678 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -257,7 +257,13 @@ class version_helper $errstr = $errno = ''; $this->file_downloader->set_error_number($errno) ->set_error_string($errstr); - $info = $this->file_downloader->get($this->host, $this->path, $this->file); + try { + $info = $this->file_downloader->get($this->host, $this->path, $this->file); + } + catch (\RuntimeException $exception) + { + throw new \RuntimeException(call_user_func_array(array($this->user, 'lang'), $exception->getMessage())); + } if (!empty($errstr)) { -- cgit v1.2.1 From da1888a7fad3be8a42b326e24bd676c92a7e4c51 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 16 Nov 2014 11:09:53 +0100 Subject: [ticket/security-171] Use type cast helper for json data SECURITY-171 --- phpBB/phpbb/version_helper.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index c3c3602944..3c5f3efcf2 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -259,6 +259,13 @@ class version_helper $info = json_decode($info, true); + // Sanitize any data we retrieve from a server + $json_sanitizer = function(&$value, $key) { + $type_cast_helper = new \phpbb\request\type_cast_helper(); + $type_cast_helper->set_var($value, $value, gettype($value), true); + }; + array_walk_recursive($info, $json_sanitizer); + if (empty($info['stable']) && empty($info['unstable'])) { $this->user->add_lang('acp/common'); @@ -266,15 +273,6 @@ class version_helper throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL')); } - // Replace & with & on announcement links - foreach ($info as $stability => $branches) - { - foreach ($branches as $branch => $branch_data) - { - $info[$stability][$branch]['announcement'] = (!empty($branch_data['announcement'])) ? str_replace('&', '&', $branch_data['announcement']) : ''; - } - } - $info['stable'] = (empty($info['stable'])) ? array() : $info['stable']; $info['unstable'] = (empty($info['unstable'])) ? $info['stable'] : $info['unstable']; -- cgit v1.2.1 From 4ee05b1c17fa1be0c911c9d37e106f19b23ebac2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 17 Nov 2014 00:33:51 +0100 Subject: [ticket/security-171] Add tests for retrieved remote data in version_helper SECURITY-171 --- phpBB/phpbb/version_helper.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 3c5f3efcf2..bcc67712e4 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -260,11 +260,14 @@ class version_helper $info = json_decode($info, true); // Sanitize any data we retrieve from a server - $json_sanitizer = function(&$value, $key) { - $type_cast_helper = new \phpbb\request\type_cast_helper(); - $type_cast_helper->set_var($value, $value, gettype($value), true); - }; - array_walk_recursive($info, $json_sanitizer); + if (!empty($info)) + { + $json_sanitizer = function (&$value, $key) { + $type_cast_helper = new \phpbb\request\type_cast_helper(); + $type_cast_helper->set_var($value, $value, gettype($value), true); + }; + array_walk_recursive($info, $json_sanitizer); + } if (empty($info['stable']) && empty($info['unstable'])) { -- cgit v1.2.1 From 171837eefe2f8e17597629b108e2aa30c0f4055f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 21 Nov 2014 23:16:22 +0100 Subject: [ticket/13358] Do not pass variables by reference PHPBB3-13358 --- phpBB/phpbb/version_helper.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index d7f1f02678..38050d8ad7 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -254,9 +254,6 @@ class version_helper } else if ($info === false || $force_update) { - $errstr = $errno = ''; - $this->file_downloader->set_error_number($errno) - ->set_error_string($errstr); try { $info = $this->file_downloader->get($this->host, $this->path, $this->file); } @@ -264,10 +261,11 @@ class version_helper { throw new \RuntimeException(call_user_func_array(array($this->user, 'lang'), $exception->getMessage())); } + $error_string = $this->file_downloader->get_error_string(); - if (!empty($errstr)) + if (!empty($error_string)) { - throw new \RuntimeException($errstr); + throw new \RuntimeException($error_string); } $info = json_decode($info, true); -- cgit v1.2.1 From f3ae5e4cb2cf1f3db1d2b8e2a34e234845712efe Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 22 Nov 2014 15:23:26 +0100 Subject: [ticket/13358] Correctly create version_helper in acp_extensions The full namespace for the file_downloader is now also being used in version_helper. PHPBB3-13358 --- phpBB/phpbb/version_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 38050d8ad7..e34bd0ba60 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -64,7 +64,7 @@ class version_helper * @param \phpbb\file_downloader $file_downloader * @param \phpbb\user $user */ - public function __construct(\phpbb\cache\service $cache, \phpbb\config\config $config, file_downloader $file_downloader, \phpbb\user $user) + public function __construct(\phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\file_downloader $file_downloader, \phpbb\user $user) { $this->cache = $cache; $this->config = $config; -- cgit v1.2.1 From 893e4b3067d6ac4c5afe1a20fbb48b462e55c226 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Thu, 27 Nov 2014 00:55:01 +0100 Subject: [ticket/13393] Call user->lang function directly PHPBB3-13393 --- phpBB/phpbb/version_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 7387ad296e..dc62f06fb2 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -259,7 +259,7 @@ class version_helper } catch (\RuntimeException $exception) { - throw new \RuntimeException(call_user_func_array(array($this->user, 'lang'), $exception->getMessage())); + throw new \RuntimeException($this->user->lang($exception->getMessage())); } $error_string = $this->file_downloader->get_error_string(); -- cgit v1.2.1 From 69450c715244e41a26e63470bd292778ed25438a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 30 Jan 2015 18:02:04 +0100 Subject: [ticket/13556] Fix exception translation with filedownloader PHPBB3-13556 --- phpBB/phpbb/version_helper.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index dc62f06fb2..e4f68f5aab 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -257,9 +257,10 @@ class version_helper try { $info = $this->file_downloader->get($this->host, $this->path, $this->file); } - catch (\RuntimeException $exception) + catch (\phpbb\exception\runtime_exception $exception) { - throw new \RuntimeException($this->user->lang($exception->getMessage())); + $prepare_parameters = array_merge(array($exception->getMessage()), $exception->get_parameters()); + throw new \RuntimeException(call_user_func_array(array($this->user, 'lang'), $prepare_parameters)); } $error_string = $this->file_downloader->get_error_string(); -- cgit v1.2.1 From 30279347acf62e6e39eea7bf56b46e48e2170ddc Mon Sep 17 00:00:00 2001 From: Kilian Date: Fri, 25 Sep 2015 21:06:13 +0200 Subject: [ticket/12618] Allow extension author to use SSL for version-check For version-check a new parameter 'ssl' is introduced. If set to true, it will use 443 as port for the file_downloader. In file_downloader, the host parameter of fsockopen is appended with 'ssl://' in case the port is 443 in order to use SSL. PHPBB3-12618 --- phpBB/phpbb/version_helper.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index e4f68f5aab..a1e66ba8fe 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -33,6 +33,11 @@ class version_helper */ protected $file = 'versions.json'; + /** + * @var bool Use SSL or not + */ + protected $use_ssl = false; + /** * @var string Current version installed */ @@ -85,13 +90,15 @@ class version_helper * @param string $host Host (e.g. version.phpbb.com) * @param string $path Path to file (e.g. /phpbb) * @param string $file File name (Default: versions.json) + * @param bool $use_ssl Use SSL or not (Default: false) * @return version_helper */ - public function set_file_location($host, $path, $file = 'versions.json') + public function set_file_location($host, $path, $file = 'versions.json', $use_ssl = false) { $this->host = $host; $this->path = $path; $this->file = $file; + $this->use_ssl = $use_ssl; return $this; } @@ -244,7 +251,7 @@ class version_helper */ public function get_versions($force_update = false, $force_cache = false) { - $cache_file = '_versioncheck_' . $this->host . $this->path . $this->file; + $cache_file = '_versioncheck_' . $this->host . $this->path . $this->file . $this->use_ssl; $info = $this->cache->get($cache_file); @@ -255,7 +262,7 @@ class version_helper else if ($info === false || $force_update) { try { - $info = $this->file_downloader->get($this->host, $this->path, $this->file); + $info = $this->file_downloader->get($this->host, $this->path, $this->file, $this->use_ssl ? 443 : 80); } catch (\phpbb\exception\runtime_exception $exception) { -- cgit v1.2.1 From 658820654f5789a786a5537c1b43991744b83d2c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 26 Dec 2016 22:01:51 +0100 Subject: [ticket/security-203] Fully validate version check data in version helper This will also take care of SECURITY-204 as it's the same underlying issue. Admins still need to ensure they don't visit malicious sites for URLs provided by extensions. SECURITY-203 --- phpBB/phpbb/version_helper.php | 107 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index a1e66ba8fe..dc95f6d001 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -61,6 +61,23 @@ class version_helper /** @var \phpbb\user */ protected $user; + protected $version_schema = array( + 'stable' => array( + 'current' => 'version', + 'download' => 'url', + 'announcement' => 'url', + 'eol' => 'url', + 'security' => 'bool', + ), + 'unstable' => array( + 'current' => 'version', + 'download' => 'url', + 'announcement' => 'url', + 'eol' => 'url', + 'security' => 'bool', + ), + ); + /** * Constructor * @@ -298,9 +315,99 @@ class version_helper $info['stable'] = (empty($info['stable'])) ? array() : $info['stable']; $info['unstable'] = (empty($info['unstable'])) ? $info['stable'] : $info['unstable']; + $this->validate_versions($info); + $this->cache->put($cache_file, $info, 86400); // 24 hours } return $info; } + + /** + * Validate versions info input + * + * @param array $versions_info Decoded json data array. Will be modified + * and cleaned by this method + */ + public function validate_versions(&$versions_info) + { + $array_diff = array_diff_key($versions_info, array($this->version_schema)); + + // Remove excessive data + if (count($array_diff) > 0) + { + $old_versions_info = $versions_info; + $versions_info = array( + 'stable' => !empty($old_versions_info['stable']) ? $old_versions_info['stable'] : array(), + 'unstable' => !empty($old_versions_info['unstable']) ? $old_versions_info['unstable'] : array(), + ); + unset($old_versions_info); + } + + foreach ($versions_info as $stability_type => &$versions_data) + { + foreach ($versions_data as $branch => &$version_data) + { + if (!preg_match('/^[0-9]+\.[0-9]+$/', $branch)) + { + unset($versions_data[$branch]); + continue; + } + + $stability_diff = array_diff_key($version_data, $this->version_schema[$stability_type]); + + if (count($stability_diff) > 0) + { + $old_version_data = $version_data; + $version_data = array(); + foreach ($this->version_schema[$stability_type] as $key => $value) + { + if (isset($old_version_data[$key]) || $old_version_data[$key] === null) + { + $version_data[$key] = $old_version_data[$key]; + } + } + unset($old_version_data); + } + + foreach ($version_data as $key => &$value) + { + if (!isset($this->version_schema[$stability_type][$key])) + { + unset($version_data[$key]); + throw new \RuntimeException($this->user->lang('VERSIONCHECK_INVALID_ENTRY')); + } + + switch ($this->version_schema[$stability_type][$key]) + { + case 'bool': + $value = (bool) $value; + break; + + case 'url': + if (!empty($value) && !preg_match('#^' . get_preg_expression('url') . '$#iu', $value) && + !preg_match('#^' . get_preg_expression('www_url') . '$#iu', $value)) + { + $value = ''; + throw new \RuntimeException($this->user->lang('VERSIONCHECK_INVALID_URL')); + } + break; + + case 'version': + $value = $value ?: ''; + if (!preg_match(get_preg_expression('semantic_version'), $value)) + { + $value = ''; + throw new \RuntimeException($this->user->lang('VERSIONCHECK_INVALID_VERSION')); + } + break; + + default: + // Shouldn't be possible to trigger this + throw new \RuntimeException($this->user->lang('VERSIONCHECK_INVALID_ENTRY')); + } + } + } + } + } } -- cgit v1.2.1 From ad251e4590744b0927019ae935c92c7101aa7678 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2016 18:11:31 +0100 Subject: [ticket/security-203] Do not add null values to versions info Also stopped using reference for validate_versions() method argument. SECURTIY-203 --- phpBB/phpbb/version_helper.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index dc95f6d001..e2d90af04a 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -315,7 +315,7 @@ class version_helper $info['stable'] = (empty($info['stable'])) ? array() : $info['stable']; $info['unstable'] = (empty($info['unstable'])) ? $info['stable'] : $info['unstable']; - $this->validate_versions($info); + $info = $this->validate_versions($info); $this->cache->put($cache_file, $info, 86400); // 24 hours } @@ -328,8 +328,10 @@ class version_helper * * @param array $versions_info Decoded json data array. Will be modified * and cleaned by this method + * + * @return array Versions info array */ - public function validate_versions(&$versions_info) + public function validate_versions($versions_info) { $array_diff = array_diff_key($versions_info, array($this->version_schema)); @@ -362,7 +364,7 @@ class version_helper $version_data = array(); foreach ($this->version_schema[$stability_type] as $key => $value) { - if (isset($old_version_data[$key]) || $old_version_data[$key] === null) + if (isset($old_version_data[$key])) { $version_data[$key] = $old_version_data[$key]; } @@ -388,16 +390,13 @@ class version_helper if (!empty($value) && !preg_match('#^' . get_preg_expression('url') . '$#iu', $value) && !preg_match('#^' . get_preg_expression('www_url') . '$#iu', $value)) { - $value = ''; throw new \RuntimeException($this->user->lang('VERSIONCHECK_INVALID_URL')); } break; case 'version': - $value = $value ?: ''; - if (!preg_match(get_preg_expression('semantic_version'), $value)) + if (!empty($value) && !preg_match(get_preg_expression('semantic_version'), $value)) { - $value = ''; throw new \RuntimeException($this->user->lang('VERSIONCHECK_INVALID_VERSION')); } break; @@ -409,5 +408,7 @@ class version_helper } } } + + return $versions_info; } } -- cgit v1.2.1 From 90a77ba9d3e97718e9da7d1ee95ece4e756d26b7 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 27 Dec 2016 18:18:20 +0100 Subject: [ticket/security-203] Allow more characters for branch names SECURITY-203 --- phpBB/phpbb/version_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index e2d90af04a..70a009ed3d 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -243,7 +243,7 @@ class version_helper * * @param bool $force_update Ignores cached data. Defaults to false. * @param bool $force_cache Force the use of the cache. Override $force_update. - * @return string Version info + * @return array Version info * @throws \RuntimeException */ public function get_versions_matching_stability($force_update = false, $force_cache = false) @@ -350,7 +350,7 @@ class version_helper { foreach ($versions_data as $branch => &$version_data) { - if (!preg_match('/^[0-9]+\.[0-9]+$/', $branch)) + if (!preg_match('/^[0-9a-z\-\.]+$/i', $branch)) { unset($versions_data[$branch]); continue; -- cgit v1.2.1 From 0572d6e33ad8f19f9f70d872421ee6ab268d6ae8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 22 Jan 2017 16:09:51 +0100 Subject: [ticket/14968] Add method for retrieving updates on current branch PHPBB3-14968 --- phpBB/phpbb/version_helper.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index a1e66ba8fe..b5f493de9d 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -200,6 +200,45 @@ class version_helper }); } + /** + * Gets the latest version for the current branch the user is on + * + * @param bool $force_update Ignores cached data. Defaults to false. + * @param bool $force_cache Force the use of the cache. Override $force_update. + * @return string + * @throws \RuntimeException + */ + public function get_update_on_branch($force_update = false, $force_cache = false) + { + $versions = $this->get_versions_matching_stability($force_update, $force_cache); + + $self = $this; + $current_version = $this->current_version; + + // Filter out any versions less than to the current version + $versions = array_filter($versions, function($data) use ($self, $current_version) { + return $self->compare($data['current'], $current_version, '>='); + }); + + // Get the lowest version from the previous list. + return array_reduce($versions, function($value, $data) use ($self, $current_version) { + if ($value === null && $self->compare($data['current'], $current_version, '>=')) + { + + if (!$data['eol'] && (!$data['security'] || $self->compare($data['security'], $data['current'], '<='))) + { + return ($self->compare($data['current'], $current_version, '>')) ? $data : array(); + } + else + { + return null; + } + } + + return $value; + }); + } + /** * Obtains the latest version information * -- cgit v1.2.1 From 20a4d095de449e4f72272e77da4e009033f2c1de Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 22 Jan 2017 16:56:14 +0100 Subject: [ticket/14968] Update docblock and ensure method returns array PHPBB3-14968 --- phpBB/phpbb/version_helper.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index b5f493de9d..135d390584 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -201,11 +201,14 @@ class version_helper } /** - * Gets the latest version for the current branch the user is on + * Gets the latest update for the current branch the user is on + * Will suggest versions from newer branches when EoL has been reached + * and/or version from newer branch is needed for having all known security + * issues fixed. * * @param bool $force_update Ignores cached data. Defaults to false. * @param bool $force_cache Force the use of the cache. Override $force_update. - * @return string + * @return array Version info or empty array if there are no updates * @throws \RuntimeException */ public function get_update_on_branch($force_update = false, $force_cache = false) @@ -221,10 +224,9 @@ class version_helper }); // Get the lowest version from the previous list. - return array_reduce($versions, function($value, $data) use ($self, $current_version) { + $update_info = array_reduce($versions, function($value, $data) use ($self, $current_version) { if ($value === null && $self->compare($data['current'], $current_version, '>=')) { - if (!$data['eol'] && (!$data['security'] || $self->compare($data['security'], $data['current'], '<='))) { return ($self->compare($data['current'], $current_version, '>')) ? $data : array(); @@ -237,6 +239,8 @@ class version_helper return $value; }); + + return $update_info === null ? array() : $update_info; } /** -- cgit v1.2.1 From 45c3cb52e43ba662209310e761644789b541b786 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 22 Mar 2017 12:14:05 -0700 Subject: [ticket/15143] Fix display of version update in ACP PHPBB3-15143 --- phpBB/phpbb/version_helper.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 135d390584..b00f4f1d5f 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -184,7 +184,7 @@ class version_helper $self = $this; $current_version = $this->current_version; - // Filter out any versions less than to the current version + // Filter out any versions less than the current version $versions = array_filter($versions, function($data) use ($self, $current_version) { return $self->compare($data['current'], $current_version, '>='); }); @@ -218,7 +218,7 @@ class version_helper $self = $this; $current_version = $this->current_version; - // Filter out any versions less than to the current version + // Filter out any versions less than the current version $versions = array_filter($versions, function($data) use ($self, $current_version) { return $self->compare($data['current'], $current_version, '>='); }); @@ -248,7 +248,7 @@ class version_helper * * @param bool $force_update Ignores cached data. Defaults to false. * @param bool $force_cache Force the use of the cache. Override $force_update. - * @return string + * @return array * @throws \RuntimeException */ public function get_suggested_updates($force_update = false, $force_cache = false) @@ -269,7 +269,7 @@ class version_helper * * @param bool $force_update Ignores cached data. Defaults to false. * @param bool $force_cache Force the use of the cache. Override $force_update. - * @return string Version info + * @return array Version info * @throws \RuntimeException */ public function get_versions_matching_stability($force_update = false, $force_cache = false) @@ -289,7 +289,7 @@ class version_helper * * @param bool $force_update Ignores cached data. Defaults to false. * @param bool $force_cache Force the use of the cache. Override $force_update. - * @return string Version info, includes stable and unstable data + * @return array Version info, includes stable and unstable data * @throws \RuntimeException */ public function get_versions($force_update = false, $force_cache = false) -- cgit v1.2.1 From 91ab27ecc9973d8f929d3e1ec06886fa9e57b979 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Fri, 24 Mar 2017 09:37:14 -0700 Subject: [ticket/15142] Check extension updates on current branch PHPBB3-15142 --- phpBB/phpbb/version_helper.php | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 135d390584..c613885909 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -243,6 +243,62 @@ class version_helper return $update_info === null ? array() : $update_info; } + /** + * Gets the latest extension update for the current phpBB branch the user is on + * Will suggest versions from newer branches when EoL has been reached + * and/or version from newer branch is needed for having all known security + * issues fixed. + * + * @param bool $force_update Ignores cached data. Defaults to false. + * @param bool $force_cache Force the use of the cache. Override $force_update. + * @return array Version info or empty array if there are no updates + * @throws \RuntimeException + */ + public function get_ext_update_on_branch($force_update = false, $force_cache = false) + { + $versions = $this->get_versions_matching_stability($force_update, $force_cache); + + $self = $this; + $current_version = $this->current_version; + + // Get current phpBB branch from version, e.g.: 3.2 + preg_match('/^(\d+\.\d+).*$/', $this->config['version'], $matches); + $current_branch = $matches[1]; + + // Filter out any versions less than the current version + $versions = array_filter($versions, function($data) use ($self, $current_version) { + return $self->compare($data['current'], $current_version, '>='); + }); + + // Filter out any phpbb branches less than the current version + $branches = array_filter(array_keys($versions), function($branch) use ($self, $current_branch) { + return $self->compare($branch, $current_branch, '>='); + }); + $versions = array_intersect_key($versions, array_flip($branches)); + + // CDB reverse sorts extension versions, so we need to resort them + ksort($versions); + + // Get the lowest version from the previous list. + $update_info = array_reduce($versions, function($value, $data) use ($self, $current_version) { + if ($value === null && $self->compare($data['current'], $current_version, '>=')) + { + if (!$data['eol'] && (!$data['security'] || $self->compare($data['security'], $data['current'], '<='))) + { + return $self->compare($data['current'], $current_version, '>') ? $data : array(); + } + else + { + return null; + } + } + + return $value; + }); + + return $update_info === null ? array() : $update_info; + } + /** * Obtains the latest version information * -- cgit v1.2.1 From afddb81acfa291ba8043d6af974f97abe8ec5243 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Fri, 24 Mar 2017 11:45:11 -0700 Subject: [ticket/15142] Handle versions for unmatched branches PHPBB3-15142 --- phpBB/phpbb/version_helper.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index c613885909..614c93d781 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -274,12 +274,20 @@ class version_helper $branches = array_filter(array_keys($versions), function($branch) use ($self, $current_branch) { return $self->compare($branch, $current_branch, '>='); }); - $versions = array_intersect_key($versions, array_flip($branches)); - - // CDB reverse sorts extension versions, so we need to resort them - ksort($versions); + $versions = !empty($branches) ? array_intersect_key($versions, array_flip($branches)) : $versions; + if (!empty($branches)) + { + $versions = array_intersect_key($versions, array_flip($branches)); + } + else + { + // If branches are empty, it means the current phpBB branch is newer than any branch the + // extension was validated against. Reverse sort the versions array so we get the newest + // validated release available. + krsort($versions); + } - // Get the lowest version from the previous list. + // Get the first available version from the previous list. $update_info = array_reduce($versions, function($value, $data) use ($self, $current_version) { if ($value === null && $self->compare($data['current'], $current_version, '>=')) { -- cgit v1.2.1 From 450402ea429e654aab01ae934772ddf90d2e6a38 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 3 Apr 2017 11:34:40 -0700 Subject: [ticket/15142] Remove duplicate code PHPBB3-15142 --- phpBB/phpbb/version_helper.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/phpbb/version_helper.php') diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php index 614c93d781..34e471493e 100644 --- a/phpBB/phpbb/version_helper.php +++ b/phpBB/phpbb/version_helper.php @@ -274,7 +274,6 @@ class version_helper $branches = array_filter(array_keys($versions), function($branch) use ($self, $current_branch) { return $self->compare($branch, $current_branch, '>='); }); - $versions = !empty($branches) ? array_intersect_key($versions, array_flip($branches)) : $versions; if (!empty($branches)) { $versions = array_intersect_key($versions, array_flip($branches)); -- cgit v1.2.1