mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-20 21:33:54 -07:00
WIP: Added restoring corrupt TorrentPier files 🪛 (#1493)
* Added restoring corrupt files 🪛
* Update index.tpl
* Updated
* Updated
* Update build_files_integrity.php
* Update build_files_integrity.php
* Update build_files_integrity.php
* Updated
* Updater
* Update Updater.php
* Updated
* Update Updater.php
* Update build_check_updates.php
* Updated
* Updated
* Updated
* Update build_files_integrity.php
* Update build_files_integrity.php
* Updated
* Update checksums.md5
* Update build_files_integrity.php
* Updated
* Updated
* Update Updater.php
* Update CHANGELOG.md
* Updated
* Update index.tpl
* Update functions.php
* Update Updater.php
This commit is contained in:
parent
e36a5ee07a
commit
2cbf9ed743
12 changed files with 259 additions and 102 deletions
|
@ -15,41 +15,34 @@ global $bb_cfg;
|
|||
|
||||
$data = [];
|
||||
|
||||
$context = stream_context_create(['http' => ['header' => 'User-Agent: ' . APP_NAME, 'timeout' => 10, 'ignore_errors' => true]]);
|
||||
$updater_content = file_get_contents(UPDATER_URL, context: $context);
|
||||
$updaterDownloader = new \TorrentPier\Updater();
|
||||
$updaterDownloader = $updaterDownloader->getLastVersion();
|
||||
|
||||
$json_response = false;
|
||||
if ($updater_content !== false) {
|
||||
$json_response = json_decode(utf8_encode($updater_content), true);
|
||||
}
|
||||
$get_version = $updaterDownloader['tag_name'];
|
||||
$version_code_actual = (int)trim(str_replace(['.', 'v'], '', $get_version));
|
||||
|
||||
if ((is_array($json_response) && !empty($json_response)) && !isset($json_response['message'])) {
|
||||
$get_version = $json_response['tag_name'];
|
||||
$version_code_actual = (int)trim(str_replace(['.', 'v'], '', $get_version));
|
||||
// Has update!
|
||||
if (VERSION_CODE < $version_code_actual) {
|
||||
$latest_release_file = $updaterDownloader['assets'][0]['browser_download_url'];
|
||||
|
||||
// Has update!
|
||||
if (VERSION_CODE < $version_code_actual) {
|
||||
$latest_release_file = $json_response['assets'][0]['browser_download_url'];
|
||||
// Save current version & latest available
|
||||
file_write(json_encode(['previous_version' => VERSION_CODE, 'latest_version' => $version_code_actual]), UPDATER_FILE, replace_content: true);
|
||||
|
||||
// Save current version & latest available
|
||||
file_write(VERSION_CODE . "\n" . $version_code_actual, UPDATER_FILE, replace_content: true);
|
||||
|
||||
// Get MD5 checksum
|
||||
$md5_file_checksum = '';
|
||||
if (isset($latest_release_file)) {
|
||||
$md5_file_checksum = strtoupper(md5_file($latest_release_file));
|
||||
}
|
||||
|
||||
// Build data array
|
||||
$data = [
|
||||
'available_update' => true,
|
||||
'latest_version' => $get_version,
|
||||
'latest_version_size' => isset($json_response['assets'][0]['size']) ? humn_size($json_response['assets'][0]['size']) : false,
|
||||
'latest_version_dl_link' => $latest_release_file ?? $json_response['html_url'],
|
||||
'latest_version_checksum' => $md5_file_checksum,
|
||||
'latest_version_link' => $json_response['html_url']
|
||||
];
|
||||
// Get MD5 checksum
|
||||
$md5_file_checksum = '';
|
||||
if (isset($latest_release_file)) {
|
||||
$md5_file_checksum = strtoupper(md5_file($latest_release_file));
|
||||
}
|
||||
|
||||
// Build data array
|
||||
$data = [
|
||||
'available_update' => true,
|
||||
'latest_version' => $get_version,
|
||||
'latest_version_size' => isset($updaterDownloader['assets'][0]['size']) ? humn_size($updaterDownloader['assets'][0]['size']) : false,
|
||||
'latest_version_dl_link' => $latest_release_file ?? $updaterDownloader['html_url'],
|
||||
'latest_version_checksum' => $md5_file_checksum,
|
||||
'latest_version_link' => $updaterDownloader['html_url']
|
||||
];
|
||||
}
|
||||
|
||||
$data[] = ['latest_check_timestamp' => TIMENOW];
|
||||
|
|
|
@ -13,12 +13,14 @@ if (!defined('BB_ROOT')) {
|
|||
|
||||
global $bb_cfg;
|
||||
|
||||
$data = [];
|
||||
$filesList = [];
|
||||
if (!$bb_cfg['integrity_check']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$checksumFile = new SplFileObject(CHECKSUMS_FILE, 'r');
|
||||
$checksumFile->setFlags(SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE);
|
||||
|
||||
$filesList = [];
|
||||
$lines = [];
|
||||
foreach ($checksumFile as $line) {
|
||||
$parts = explode(' ', $line);
|
||||
|
@ -36,13 +38,41 @@ foreach ($checksumFile as $line) {
|
|||
];
|
||||
}
|
||||
|
||||
$dynamicFiles = [
|
||||
BB_ENABLED
|
||||
];
|
||||
|
||||
$wrongFilesList = [];
|
||||
foreach ($filesList as $file) {
|
||||
if (strtolower(md5_file(BB_ROOT . '/' . $file['path'])) !== strtolower($file['hash'])) {
|
||||
if (!empty($dynamicFiles) && in_array(hide_bb_path($file['path']), $dynamicFiles)) {
|
||||
// Exclude dynamic files
|
||||
continue;
|
||||
}
|
||||
if (!file_exists(BB_ROOT . '/' . $file['path']) || strtolower(md5_file(BB_ROOT . '/' . $file['path'])) !== strtolower($file['hash'])) {
|
||||
$wrongFilesList[] = $file['path'];
|
||||
}
|
||||
}
|
||||
|
||||
// Restore corrupt files
|
||||
if (is_file(RESTORE_CORRUPT_CONFIRM_FILE)) {
|
||||
$buildDownloader = new \TorrentPier\Updater();
|
||||
if ($buildDownloader->download(INT_DATA_DIR . '/', $bb_cfg['tp_version'])) {
|
||||
// Unzip downloaded build file
|
||||
$zipArchive = new ZipArchive;
|
||||
$extractDownloadedFile = $zipArchive->open($buildDownloader->savePath);
|
||||
if ($extractDownloadedFile === true) {
|
||||
if ($zipArchive->extractTo(BB_ROOT, $wrongFilesList)) {
|
||||
$wrongFilesList = [];
|
||||
}
|
||||
$zipArchive->close();
|
||||
}
|
||||
}
|
||||
|
||||
// Delete restore confirm file & build file
|
||||
unlink($buildDownloader->savePath);
|
||||
unlink(RESTORE_CORRUPT_CONFIRM_FILE);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'success' => empty($wrongFilesList),
|
||||
'wrong_files' => $wrongFilesList,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue