From 57d0d59b5379600f63cf7d5f774e3ec000e39473 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Wed, 2 Jul 2025 10:16:54 +0300 Subject: [PATCH] feat(updater): Added exceptions logging (#2026) * feat(updater): Added exceptions logging * refactor(updater): Use `sha256` hash if available --- admin/index.php | 2 +- composer.lock | 80 +++++++++---------- .../datastore/build_check_updates.php | 21 +++-- library/includes/functions.php | 4 +- src/Updater.php | 71 +++++++++++++--- styles/templates/admin/index.tpl | 2 +- 6 files changed, 120 insertions(+), 60 deletions(-) diff --git a/admin/index.php b/admin/index.php index ea3d0a2aa..1b42b53fa 100644 --- a/admin/index.php +++ b/admin/index.php @@ -90,7 +90,7 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') { 'NEW_VERSION_SIZE' => $update_data['latest_version_size'], 'NEW_VERSION_DL_LINK' => $update_data['latest_version_dl_link'], 'NEW_VERSION_LINK' => $update_data['latest_version_link'], - 'NEW_VERSION_MD5' => $update_data['latest_version_checksum'] + 'NEW_VERSION_HASH' => $update_data['latest_version_checksum'] ]); } diff --git a/composer.lock b/composer.lock index a3fa490ba..9bf9af62c 100644 --- a/composer.lock +++ b/composer.lock @@ -286,16 +286,16 @@ }, { "name": "arokettu/torrent-file", - "version": "5.3.1", + "version": "5.3.2", "source": { "type": "git", "url": "https://github.com/arokettu/torrent-file.git", - "reference": "650ed7109bcd01dd6c4f47d129f120eb1f82ca07" + "reference": "0fba9ed15b8f60beb33a590a36db9b97d28ce171" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/arokettu/torrent-file/zipball/650ed7109bcd01dd6c4f47d129f120eb1f82ca07", - "reference": "650ed7109bcd01dd6c4f47d129f120eb1f82ca07", + "url": "https://api.github.com/repos/arokettu/torrent-file/zipball/0fba9ed15b8f60beb33a590a36db9b97d28ce171", + "reference": "0fba9ed15b8f60beb33a590a36db9b97d28ce171", "shasum": "" }, "require": { @@ -313,9 +313,9 @@ "league/event": "^3.0", "phpunit/phpunit": "^10.5.3", "psy/psysh": "*", - "sandfox.dev/code-standard": "^1.2024.07.05", + "sandfox.dev/code-standard": "^1.2025.05.07", "squizlabs/php_codesniffer": "*", - "vimeo/psalm": "^5.2" + "vimeo/psalm": "^5.2 | ^6" }, "suggest": { "ext-openssl": "for signature logic" @@ -351,7 +351,7 @@ "issues": "https://gitlab.com/sandfox/torrent-file/-/issues", "source": "https://gitlab.com/sandfox/torrent-file" }, - "time": "2024-07-28T21:43:34+00:00" + "time": "2025-06-28T21:41:10+00:00" }, { "name": "arokettu/unsigned", @@ -995,16 +995,16 @@ }, { "name": "google/recaptcha", - "version": "1.3.0", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/google/recaptcha.git", - "reference": "d59a801e98a4e9174814a6d71bbc268dff1202df" + "reference": "56522c261d2e8c58ba416c90f81a4cd9f2ed89b9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/google/recaptcha/zipball/d59a801e98a4e9174814a6d71bbc268dff1202df", - "reference": "d59a801e98a4e9174814a6d71bbc268dff1202df", + "url": "https://api.github.com/repos/google/recaptcha/zipball/56522c261d2e8c58ba416c90f81a4cd9f2ed89b9", + "reference": "56522c261d2e8c58ba416c90f81a4cd9f2ed89b9", "shasum": "" }, "require": { @@ -1043,7 +1043,7 @@ "issues": "https://github.com/google/recaptcha/issues", "source": "https://github.com/google/recaptcha" }, - "time": "2023-02-18T17:41:46+00:00" + "time": "2025-06-26T22:21:57+00:00" }, { "name": "graham-campbell/result-type", @@ -1620,16 +1620,16 @@ }, { "name": "league/flysystem", - "version": "3.29.1", + "version": "3.30.0", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "edc1bb7c86fab0776c3287dbd19b5fa278347319" + "reference": "2203e3151755d874bb2943649dae1eb8533ac93e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/edc1bb7c86fab0776c3287dbd19b5fa278347319", - "reference": "edc1bb7c86fab0776c3287dbd19b5fa278347319", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/2203e3151755d874bb2943649dae1eb8533ac93e", + "reference": "2203e3151755d874bb2943649dae1eb8533ac93e", "shasum": "" }, "require": { @@ -1653,13 +1653,13 @@ "composer/semver": "^3.0", "ext-fileinfo": "*", "ext-ftp": "*", - "ext-mongodb": "^1.3", + "ext-mongodb": "^1.3|^2", "ext-zip": "*", "friendsofphp/php-cs-fixer": "^3.5", "google/cloud-storage": "^1.23", "guzzlehttp/psr7": "^2.6", "microsoft/azure-storage-blob": "^1.1", - "mongodb/mongodb": "^1.2", + "mongodb/mongodb": "^1.2|^2", "phpseclib/phpseclib": "^3.0.36", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^9.5.11|^10.0", @@ -1697,22 +1697,22 @@ ], "support": { "issues": "https://github.com/thephpleague/flysystem/issues", - "source": "https://github.com/thephpleague/flysystem/tree/3.29.1" + "source": "https://github.com/thephpleague/flysystem/tree/3.30.0" }, - "time": "2024-10-08T08:58:34+00:00" + "time": "2025-06-25T13:29:59+00:00" }, { "name": "league/flysystem-local", - "version": "3.29.0", + "version": "3.30.0", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem-local.git", - "reference": "e0e8d52ce4b2ed154148453d321e97c8e931bd27" + "reference": "6691915f77c7fb69adfb87dcd550052dc184ee10" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem-local/zipball/e0e8d52ce4b2ed154148453d321e97c8e931bd27", - "reference": "e0e8d52ce4b2ed154148453d321e97c8e931bd27", + "url": "https://api.github.com/repos/thephpleague/flysystem-local/zipball/6691915f77c7fb69adfb87dcd550052dc184ee10", + "reference": "6691915f77c7fb69adfb87dcd550052dc184ee10", "shasum": "" }, "require": { @@ -1746,9 +1746,9 @@ "local" ], "support": { - "source": "https://github.com/thephpleague/flysystem-local/tree/3.29.0" + "source": "https://github.com/thephpleague/flysystem-local/tree/3.30.0" }, - "time": "2024-08-09T21:24:39+00:00" + "time": "2025-05-21T10:34:19+00:00" }, { "name": "league/mime-type-detection", @@ -3146,16 +3146,16 @@ }, { "name": "symfony/mailer", - "version": "v6.4.21", + "version": "v6.4.23", "source": { "type": "git", "url": "https://github.com/symfony/mailer.git", - "reference": "ada2809ccd4ec27aba9fc344e3efdaec624c6438" + "reference": "a480322ddf8e54de262c9bca31fdcbe26b553de5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/mailer/zipball/ada2809ccd4ec27aba9fc344e3efdaec624c6438", - "reference": "ada2809ccd4ec27aba9fc344e3efdaec624c6438", + "url": "https://api.github.com/repos/symfony/mailer/zipball/a480322ddf8e54de262c9bca31fdcbe26b553de5", + "reference": "a480322ddf8e54de262c9bca31fdcbe26b553de5", "shasum": "" }, "require": { @@ -3206,7 +3206,7 @@ "description": "Helps sending emails", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/mailer/tree/v6.4.21" + "source": "https://github.com/symfony/mailer/tree/v6.4.23" }, "funding": [ { @@ -3222,7 +3222,7 @@ "type": "tidelift" } ], - "time": "2025-04-26T23:47:35+00:00" + "time": "2025-06-26T21:24:02+00:00" }, { "name": "symfony/mime", @@ -3651,16 +3651,16 @@ "packages-dev": [ { "name": "symfony/var-dumper", - "version": "v6.4.21", + "version": "v6.4.23", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "22560f80c0c5cd58cc0bcaf73455ffd81eb380d5" + "reference": "d55b1834cdbfcc31bc2cd7e095ba5ed9a88f6600" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/22560f80c0c5cd58cc0bcaf73455ffd81eb380d5", - "reference": "22560f80c0c5cd58cc0bcaf73455ffd81eb380d5", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/d55b1834cdbfcc31bc2cd7e095ba5ed9a88f6600", + "reference": "d55b1834cdbfcc31bc2cd7e095ba5ed9a88f6600", "shasum": "" }, "require": { @@ -3716,7 +3716,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v6.4.21" + "source": "https://github.com/symfony/var-dumper/tree/v6.4.23" }, "funding": [ { @@ -3732,7 +3732,7 @@ "type": "tidelift" } ], - "time": "2025-04-09T07:34:50+00:00" + "time": "2025-06-27T15:05:27+00:00" } ], "aliases": [], @@ -3746,6 +3746,6 @@ "platform": { "php": ">=8.1" }, - "platform-dev": [], - "plugin-api-version": "2.3.0" + "platform-dev": {}, + "plugin-api-version": "2.6.0" } diff --git a/library/includes/datastore/build_check_updates.php b/library/includes/datastore/build_check_updates.php index a990d4364..aae8ededd 100644 --- a/library/includes/datastore/build_check_updates.php +++ b/library/includes/datastore/build_check_updates.php @@ -18,9 +18,16 @@ if (!$bb_cfg['tp_updater_settings']['enabled']) { } $data = []; +$data[] = ['latest_check_timestamp' => TIMENOW]; -$updaterDownloader = new \TorrentPier\Updater(); -$updaterDownloader = $updaterDownloader->getLastVersion($bb_cfg['tp_updater_settings']['allow_pre_releases']); +try { + $updaterDownloader = new \TorrentPier\Updater(); + $updaterDownloader = $updaterDownloader->getLastVersion($bb_cfg['tp_updater_settings']['allow_pre_releases']); +} catch (Exception $exception) { + bb_log('[Updater] Exception: ' . $exception->getMessage() . LOG_LF); + $this->store('check_updates', $data); + return; +} $getVersion = \TorrentPier\Helpers\VersionHelper::removerPrefix($updaterDownloader['tag_name']); $currentVersion = \TorrentPier\Helpers\VersionHelper::removerPrefix($bb_cfg['tp_version']); @@ -28,6 +35,7 @@ $currentVersion = \TorrentPier\Helpers\VersionHelper::removerPrefix($bb_cfg['tp_ // Has update! if (\z4kn4fein\SemVer\Version::greaterThan($getVersion, $currentVersion)) { $latestBuildFileLink = $updaterDownloader['assets'][0]['browser_download_url']; + $SHAFileHash = $updaterDownloader['assets'][0]['digest'] ?? ''; // Check updater file $updaterFile = readUpdaterFile(); @@ -41,10 +49,12 @@ if (\z4kn4fein\SemVer\Version::greaterThan($getVersion, $currentVersion)) { ]), UPDATER_FILE, replace_content: true); } - // Get MD5 checksum + // Get MD5 / sha256 checksum $buildFileChecksum = ''; - if (isset($latestBuildFileLink)) { - $buildFileChecksum = strtoupper(md5_file($latestBuildFileLink)); + if (!empty($SHAFileHash)) { + $buildFileChecksum = $SHAFileHash; + } else { + $buildFileChecksum = 'MD5: ' . strtoupper(md5_file($latestBuildFileLink)); } // Build data array @@ -58,5 +68,4 @@ if (\z4kn4fein\SemVer\Version::greaterThan($getVersion, $currentVersion)) { ]; } -$data[] = ['latest_check_timestamp' => TIMENOW]; $this->store('check_updates', $data); diff --git a/library/includes/functions.php b/library/includes/functions.php index dde48be28..c222ecc39 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -2229,10 +2229,10 @@ function infoByIP(string $ipAddress, int $port = 0): array ]; } } else { - bb_log("[FreeIPAPI] Failed to get IP info for: $ipAddress"); + bb_log("[FreeIPAPI] Failed to get IP info for: $ipAddress" . LOG_LF); } } catch (Exception $e) { - bb_log("[FreeIPAPI] " . $e->getMessage()); + bb_log("[FreeIPAPI] " . $e->getMessage() . LOG_LF); } if (empty($data)) { diff --git a/src/Updater.php b/src/Updater.php index 5ccba7843..2f90d2f1b 100644 --- a/src/Updater.php +++ b/src/Updater.php @@ -38,6 +38,13 @@ class Updater */ public string $savePath; + /** + * LTS version pattern (v2.4.*) + * + * @var string + */ + private const LTS_VERSION_PATTERN = '/^v2\.4\.\d+$/'; + /** * Stream context * @@ -130,23 +137,67 @@ class Updater } /** - * Returns information of latest TorrentPier version available + * Returns information of latest TorrentPier LTS version (v2.4.*) available + * + * @param bool $allowPreReleases + * @return array + * @throws Exception + */ + public function getLastVersion(bool $allowPreReleases = true): array + { + // Filter releases to get only LTS versions (v2.4.*) + $ltsVersions = array_filter($this->jsonResponse, function ($release) { + return preg_match(self::LTS_VERSION_PATTERN, $release['tag_name']); + }); + + if (empty($ltsVersions)) { + throw new Exception('No LTS versions (v2.4.*) found'); + } + + // Sort LTS versions by version number (descending) + usort($ltsVersions, function ($a, $b) { + return version_compare($b['tag_name'], $a['tag_name']); + }); + + if (!$allowPreReleases) { + foreach ($ltsVersions as $release) { + if (isset($release['prerelease']) && $release['prerelease']) { + continue; + } + return $release; + } + + // If no stable LTS versions found + throw new Exception('No stable LTS versions (v2.4.*) found'); + } + + return $ltsVersions[0]; + } + + /** + * Get all available LTS versions (v2.4.*) * * @param bool $allowPreReleases * @return array */ - public function getLastVersion(bool $allowPreReleases = true): array + public function getAllLTSVersions(bool $allowPreReleases = true): array { - if (!$allowPreReleases) { - foreach ($this->jsonResponse as $index) { - if (isset($index['prerelease']) && $index['prerelease']) { - continue; - } + // Filter releases to get only LTS versions (v2.4.*) + $ltsVersions = array_filter($this->jsonResponse, function ($release) use ($allowPreReleases) { + $isLTSVersion = preg_match(self::LTS_VERSION_PATTERN, $release['tag_name']); - return $index; + if (!$allowPreReleases && isset($release['prerelease']) && $release['prerelease']) { + return false; } - } - return $this->jsonResponse[0]; + return $isLTSVersion; + }); + + // Sort LTS versions by version number (descending) + usort($ltsVersions, function ($a, $b) { + return version_compare($b['tag_name'], $a['tag_name']); + }); + + return array_values($ltsVersions); } } diff --git a/styles/templates/admin/index.tpl b/styles/templates/admin/index.tpl index 3c8f30941..4ee45c3b4 100644 --- a/styles/templates/admin/index.tpl +++ b/styles/templates/admin/index.tpl @@ -160,7 +160,7 @@ {L_UPDATE_AVAILABLE}: - {updater.NEW_VERSION_NUMBER} ({L_SIZE}: {updater.NEW_VERSION_SIZE}) · {L_DOWNLOAD} · {L_CHANGELOG} · MD5: {updater.NEW_VERSION_MD5} + {updater.NEW_VERSION_NUMBER} ({L_SIZE}: {updater.NEW_VERSION_SIZE}) · {L_DOWNLOAD} · {L_CHANGELOG} · {updater.NEW_VERSION_HASH}