feat(updater): Added exceptions logging (#2026)

* feat(updater): Added exceptions logging

* refactor(updater): Use `sha256` hash if available
This commit is contained in:
Roman Kelesidis 2025-07-02 10:16:54 +03:00 committed by GitHub
parent 76b191ff41
commit 57d0d59b53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 120 additions and 60 deletions

View file

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

80
composer.lock generated
View file

@ -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"
}

View file

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

View file

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

View file

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

View file

@ -160,7 +160,7 @@
<!-- IF updater.UPDATE_AVAILABLE -->
<tr>
<td class="row1" nowrap="nowrap" width="25%"><b>{L_UPDATE_AVAILABLE}:</b></td>
<td class="row2"><b>{updater.NEW_VERSION_NUMBER}</b><!-- IF updater.NEW_VERSION_SIZE -->&nbsp;({L_SIZE}:&nbsp;{updater.NEW_VERSION_SIZE})<!-- ENDIF -->&nbsp;&middot;&nbsp;<a target="_blank" href="{updater.NEW_VERSION_DL_LINK}">{L_DOWNLOAD}</a>&nbsp;&middot;&nbsp;<a target="_blank" href="{updater.NEW_VERSION_LINK}">{L_CHANGELOG}</a><!-- IF updater.NEW_VERSION_MD5 -->&nbsp;&middot;&nbsp;<span class="copyElement" data-clipboard-text="{updater.NEW_VERSION_MD5}" title="{L_COPY_TO_CLIPBOARD}">MD5:&nbsp;{updater.NEW_VERSION_MD5}</span><!-- ENDIF --></td>
<td class="row2"><b>{updater.NEW_VERSION_NUMBER}</b><!-- IF updater.NEW_VERSION_SIZE -->&nbsp;({L_SIZE}:&nbsp;{updater.NEW_VERSION_SIZE})<!-- ENDIF -->&nbsp;&middot;&nbsp;<a target="_blank" href="{updater.NEW_VERSION_DL_LINK}">{L_DOWNLOAD}</a>&nbsp;&middot;&nbsp;<a target="_blank" href="{updater.NEW_VERSION_LINK}">{L_CHANGELOG}</a><!-- IF updater.NEW_VERSION_HASH -->&nbsp;&middot;&nbsp;<span class="copyElement" data-clipboard-text="{updater.NEW_VERSION_HASH}" title="{L_COPY_TO_CLIPBOARD}">{updater.NEW_VERSION_HASH}</span><!-- ENDIF --></td>
</tr>
<!-- ENDIF -->
<!-- END updater -->