Minor improvements (#1480)

* Some enhancements for updates checker

* Updated

* Update updater.php

* Update init_bb.php

* Update CHANGELOG.md

* Update globals.css

* Updated

* Update functions.php

* Update init_bb.php

* Updated

* Updated

* Updated

* Update update_geolite_db.php

* Update update_geolite_db.php

* Update update_geolite_db.php

* Updated

* Update .gitignore

* Update init_bb.php

* Updated

* Update CHANGELOG.md
This commit is contained in:
Roman Kelesidis 2024-05-11 00:44:35 +07:00 committed by GitHub
commit 9ada2c63b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 48 additions and 38 deletions

View file

@ -19,9 +19,9 @@
- Demo mode: Allow registering torrents by default [\#1440](https://github.com/torrentpier/torrentpier/pull/1440) ([belomaxorka](https://github.com/belomaxorka)) - Demo mode: Allow registering torrents by default [\#1440](https://github.com/torrentpier/torrentpier/pull/1440) ([belomaxorka](https://github.com/belomaxorka))
- Temp: Removed showing forum description in `viewforum.php` [\#1465](https://github.com/torrentpier/torrentpier/pull/1465) ([belomaxorka](https://github.com/belomaxorka)) - Temp: Removed showing forum description in `viewforum.php` [\#1465](https://github.com/torrentpier/torrentpier/pull/1465) ([belomaxorka](https://github.com/belomaxorka))
- Code refactoring [\#1441](https://github.com/torrentpier/torrentpier/pull/1441) ([belomaxorka](https://github.com/belomaxorka)) - Code refactoring [\#1441](https://github.com/torrentpier/torrentpier/pull/1441) ([belomaxorka](https://github.com/belomaxorka))
- Minor improvements [\#1435](https://github.com/torrentpier/torrentpier/pull/1435), [\#1443](https://github.com/torrentpier/torrentpier/pull/1443), [\#1446](https://github.com/torrentpier/torrentpier/pull/1446), [\#1450](https://github.com/torrentpier/torrentpier/pull/1450), [\#1452](https://github.com/torrentpier/torrentpier/pull/1452), [\#1458](https://github.com/torrentpier/torrentpier/pull/1458), [\#1461](https://github.com/torrentpier/torrentpier/pull/1461), [\#1462](https://github.com/torrentpier/torrentpier/pull/1462), [\#1467](https://github.com/torrentpier/torrentpier/pull/1467), [\#1469](https://github.com/torrentpier/torrentpier/pull/1469), [\#1472](https://github.com/torrentpier/torrentpier/pull/1472), [\#1477](https://github.com/torrentpier/torrentpier/pull/1477) ([belomaxorka](https://github.com/belomaxorka)) - Minor improvements [\#1435](https://github.com/torrentpier/torrentpier/pull/1435), [\#1443](https://github.com/torrentpier/torrentpier/pull/1443), [\#1446](https://github.com/torrentpier/torrentpier/pull/1446), [\#1450](https://github.com/torrentpier/torrentpier/pull/1450), [\#1452](https://github.com/torrentpier/torrentpier/pull/1452), [\#1458](https://github.com/torrentpier/torrentpier/pull/1458), [\#1461](https://github.com/torrentpier/torrentpier/pull/1461), [\#1462](https://github.com/torrentpier/torrentpier/pull/1462), [\#1467](https://github.com/torrentpier/torrentpier/pull/1467), [\#1469](https://github.com/torrentpier/torrentpier/pull/1469), [\#1472](https://github.com/torrentpier/torrentpier/pull/1472), [\#1477](https://github.com/torrentpier/torrentpier/pull/1477), [\#1480](https://github.com/torrentpier/torrentpier/pull/1480) ([belomaxorka](https://github.com/belomaxorka))
- Updated deps [\#1454](https://github.com/torrentpier/torrentpier/pull/1454), [\#1455](https://github.com/torrentpier/torrentpier/pull/1455), [\#1459](https://github.com/torrentpier/torrentpier/pull/1459), [\#1460](https://github.com/torrentpier/torrentpier/pull/1460) ([belomaxorka](https://github.com/belomaxorka)) - Updated deps [\#1454](https://github.com/torrentpier/torrentpier/pull/1454), [\#1455](https://github.com/torrentpier/torrentpier/pull/1455), [\#1459](https://github.com/torrentpier/torrentpier/pull/1459), [\#1460](https://github.com/torrentpier/torrentpier/pull/1460) ([belomaxorka](https://github.com/belomaxorka))
- New Crowdin updates [\#1444](https://github.com/torrentpier/torrentpier/pull/1444), [\#1447](https://github.com/torrentpier/torrentpier/pull/1447), [\#1453](https://github.com/torrentpier/torrentpier/pull/1453), [\#1468](https://github.com/torrentpier/torrentpier/pull/1468), [\#1473](https://github.com/torrentpier/torrentpier/pull/1473), [\#1476](https://github.com/torrentpier/torrentpier/pull/1476) ([Exileum](https://github.com/Exileum)) - New Crowdin updates [\#1444](https://github.com/torrentpier/torrentpier/pull/1444), [\#1447](https://github.com/torrentpier/torrentpier/pull/1447), [\#1453](https://github.com/torrentpier/torrentpier/pull/1453), [\#1468](https://github.com/torrentpier/torrentpier/pull/1468), [\#1473](https://github.com/torrentpier/torrentpier/pull/1473), [\#1476](https://github.com/torrentpier/torrentpier/pull/1476), [\#1479](https://github.com/torrentpier/torrentpier/pull/1479) ([Exileum](https://github.com/Exileum))
## [v2.4.2](https://github.com/torrentpier/torrentpier/tree/v2.4.2) (2024-03-30) ## [v2.4.2](https://github.com/torrentpier/torrentpier/tree/v2.4.2) (2024-03-30)
[Full Changelog](https://github.com/torrentpier/torrentpier/compare/v2.4.1...v2.4.2) [Full Changelog](https://github.com/torrentpier/torrentpier/compare/v2.4.1...v2.4.2)

View file

@ -448,7 +448,7 @@ if ($tor_reged && $tor_info) {
'ROW_BGR' => $row_bgr, 'ROW_BGR' => $row_bgr,
'NAME' => ($peer['update_time']) ? $name : "<s>$name</s>", 'NAME' => ($peer['update_time']) ? $name : "<s>$name</s>",
'PEER_ID' => isset($peer['peer_id']) ? get_user_torrent_client($peer['peer_id']) : $lang['UNKNOWN'], 'PEER_ID' => isset($peer['peer_id']) ? get_user_torrent_client($peer['peer_id']) : $lang['UNKNOWN'],
'COUNTRY' => render_flag(countryByIP($ip, $port), false), 'COUNTRY' => render_flag(getCountryByIP($ip, $port), false),
'COMPL_PRC' => $compl_perc, 'COMPL_PRC' => $compl_perc,
'UP_TOTAL' => ($max_up_id[$x] == $pid) ? "<b>$up_tot</b>" : $up_tot, 'UP_TOTAL' => ($max_up_id[$x] == $pid) ? "<b>$up_tot</b>" : $up_tot,
'DOWN_TOTAL' => ($max_down_id[$x] == $pid) ? "<b>$down_tot</b>" : $down_tot, 'DOWN_TOTAL' => ($max_down_id[$x] == $pid) ? "<b>$down_tot</b>" : $down_tot,

View file

@ -45,7 +45,7 @@ foreach ($cron_jobs as $job) {
if (is_file($job_script)) { if (is_file($job_script)) {
$cron_start_time = utime(); $cron_start_time = utime();
$cron_runtime_log = ''; $cron_runtime_log = [];
$cron_write_log = (CRON_LOG_ENABLED && (CRON_FORCE_LOG || $job['log_enabled'] >= 1)); $cron_write_log = (CRON_LOG_ENABLED && (CRON_FORCE_LOG || $job['log_enabled'] >= 1));
$cron_sql_log_file = CRON_LOG_DIR . '/SQL-' . basename($job['cron_script']); $cron_sql_log_file = CRON_LOG_DIR . '/SQL-' . basename($job['cron_script']);
@ -83,9 +83,10 @@ foreach ($cron_jobs as $job) {
$msg .= LOG_LF . '------=-------=----------=------=-------=----------'; $msg .= LOG_LF . '------=-------=----------=------=-------=----------';
bb_log($msg . LOG_LF, CRON_LOG_DIR . '/' . CRON_LOG_FILE); bb_log($msg . LOG_LF, CRON_LOG_DIR . '/' . CRON_LOG_FILE);
if ($cron_runtime_log) { if (is_countable($cron_runtime_log)) {
$runtime_log_file = ($job['log_file']) ?: $job['cron_script']; $runtime_log_file = ($job['log_file']) ?: $job['cron_script'];
bb_log($cron_runtime_log . LOG_LF, CRON_LOG_DIR . '/' . basename($runtime_log_file)); $cron_runtime_log[] = '';
bb_log($cron_runtime_log, CRON_LOG_DIR . '/' . basename($runtime_log_file));
} }
} }

View file

@ -16,6 +16,6 @@ global $cron_runtime_log;
foreach ($bb_cfg['cache']['engines'] as $cache_name => $cache_val) { foreach ($bb_cfg['cache']['engines'] as $cache_name => $cache_val) {
if (method_exists(CACHE($cache_name), 'gc')) { if (method_exists(CACHE($cache_name), 'gc')) {
$changes = CACHE($cache_name)->gc(); $changes = CACHE($cache_name)->gc();
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- " . str_pad("$cache_name ", 25, '-', STR_PAD_RIGHT) . " del: $changes\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- " . str_pad("$cache_name ", 25, '-', STR_PAD_RIGHT) . " del: $changes";
} }
} }

View file

@ -37,7 +37,7 @@ foreach (file($dump_path) as $line) {
$temp_line .= $line; $temp_line .= $line;
if (str_ends_with(trim($line), ';')) { if (str_ends_with(trim($line), ';')) {
if (!DB()->query($temp_line)) { if (!DB()->query($temp_line)) {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Error performing query: " . $temp_line . " | " . DB()->sql_error()['message'] . "\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Error performing query: " . $temp_line . " | " . DB()->sql_error()['message'];
} }
$temp_line = ''; $temp_line = '';
} }

View file

@ -20,17 +20,17 @@ $old_file_path = INT_DATA_DIR . '/GeoLite2-City.mmdb.old';
$repo_link = 'https://api.github.com/repos/P3TERX/GeoLite.mmdb/releases/latest'; $repo_link = 'https://api.github.com/repos/P3TERX/GeoLite.mmdb/releases/latest';
if (is_file($old_file_path) && unlink($old_file_path)) { if (is_file($old_file_path) && unlink($old_file_path)) {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Old GeoLite file successfully removed (First step)\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Old GeoLite file successfully removed (First step)";
} }
if (is_file($save_path)) { if (is_file($save_path)) {
if (rename($save_path, $old_file_path)) { if (rename($save_path, $old_file_path)) {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Successfully created old GeoLite file\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Successfully created old GeoLite file";
} else { } else {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot create old GeoLite file\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Cannot create old GeoLite file";
} }
} else { } else {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot find GeoLite file (It's okay)\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Cannot find GeoLite file (It's okay)";
} }
$context = stream_context_create(['http' => ['header' => 'User-Agent: ' . APP_NAME]]); $context = stream_context_create(['http' => ['header' => 'User-Agent: ' . APP_NAME]]);
@ -39,43 +39,44 @@ $repo_content = file_get_contents($repo_link, context: $context);
$json_response = false; $json_response = false;
if ($repo_content !== false) { if ($repo_content !== false) {
$json_response = json_decode(utf8_encode($repo_content), true); $json_response = json_decode(utf8_encode($repo_content), true);
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Successfully connected to: " . $repo_link . "\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Successfully connected to: " . $repo_link;
} else { } else {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot access to: " . $repo_link . "\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Cannot access to: " . $repo_link;
} }
if (is_array($json_response) && !empty($json_response)) { if (is_array($json_response) && !empty($json_response)) {
$download_link = $json_response['assets'][1]['browser_download_url']; $download_link = $json_response['assets'][1]['browser_download_url'];
$file_date = $json_response['name'] ?? ''; $file_date = $json_response['name'] ?? '';
if (!empty($download_link)) { if (!empty($download_link)) {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Link to download is valid: " . $download_link . "\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Link to download is valid: " . $download_link;
$get_file = file_get_contents($download_link); $get_file = file_get_contents($download_link);
$get_file_md5 = md5_file($download_link);
if ($get_file !== false) { if ($get_file !== false) {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- GeoLite file obtained\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- GeoLite file obtained. MD5: $get_file_md5";
file_put_contents($save_path, $get_file); // Save new GeoLite file! file_put_contents($save_path, $get_file); // Save new GeoLite file!
if (is_file($save_path)) { if (is_file($save_path) && ($get_file_md5 === md5_file($save_path))) {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- GeoLite file successfully saved ($file_date)\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- GeoLite file successfully saved ($file_date). MD5 hashes are identical";
if (is_file($old_file_path) && unlink($old_file_path)) { if (is_file($old_file_path) && unlink($old_file_path)) {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Old GeoLite file successfully removed (Second step)\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Old GeoLite file successfully removed (Second step)";
} }
} else { } else {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Reverting all changes...\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Reverting all changes...";
if (is_file($old_file_path)) { if (is_file($old_file_path)) {
if (rename($old_file_path, $save_path)) { if (rename($old_file_path, $save_path)) {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Successfully reverted\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Successfully reverted";
} else { } else {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot revert changes, because cannot rename old file\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Cannot revert changes, because cannot rename old file";
} }
} else { } else {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot revert changes, old file not found\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Cannot revert changes, old file not found";
} }
} }
} else { } else {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- GeoLite file not obtained\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- GeoLite file not obtained";
} }
} else { } else {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Cannot find link to download\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Cannot find link to download";
} }
} else { } else {
$cron_runtime_log .= date('Y-m-d H:i:s') . " -- Invalid response from server: " . $json_response . "\n"; $cron_runtime_log[] = date('Y-m-d H:i:s') . " -- Invalid response from server: " . $json_response;
} }

View file

@ -25,7 +25,7 @@ if ($updater_content !== false) {
if (is_array($json_response) && !empty($json_response)) { if (is_array($json_response) && !empty($json_response)) {
$get_version = $json_response['tag_name']; $get_version = $json_response['tag_name'];
$version_code_actual = (int)trim(str_replace(['.', 'v', ','], '', $get_version)); $version_code_actual = (int)trim(str_replace(['.', 'v'], '', $get_version));
$has_update = VERSION_CODE < $version_code_actual; $has_update = VERSION_CODE < $version_code_actual;
// Save current version & latest available // Save current version & latest available

View file

@ -2148,22 +2148,21 @@ function getBanInfo(int $userId = null): ?array
*/ */
function readUpdaterFile(): array|bool function readUpdaterFile(): array|bool
{ {
$str = []; if (!is_file(UPDATER_FILE)) {
return false;
}
$str = [];
if ($updaterFile = fopen(UPDATER_FILE, 'r')) { if ($updaterFile = fopen(UPDATER_FILE, 'r')) {
while (!feof($updaterFile)) { while (!feof($updaterFile)) {
$str[] = trim(fgets($updaterFile)); $str[] = trim(fgets($updaterFile));
} }
} }
if (!empty($str)) { return [
return [ 'previous_version' => is_numeric($str[0]) ? (int)$str[0] : 0,
'previous_version' => (int)$str[0], 'latest_version' => is_numeric($str[1]) ? (int)$str[1] : 0
'latest_version' => (int)$str[1], ];
];
}
return false;
} }
/** /**
@ -2173,7 +2172,7 @@ function readUpdaterFile(): array|bool
* @param int $port * @param int $port
* @return mixed|string|null * @return mixed|string|null
*/ */
function countryByIP(string $ipAddress, int $port = 1111): mixed function getCountryByIP(string $ipAddress, int $port = 1111): mixed
{ {
global $lang; global $lang;

View file

@ -28,7 +28,7 @@ define('USER_IP', $user_ip);
define('IN_DEMO_MODE', env('APP_DEMO_MODE', false)); define('IN_DEMO_MODE', env('APP_DEMO_MODE', false));
// Version code // Version code
define('VERSION_CODE', (int)trim(str_replace(['.', 'v', ','], '', $bb_cfg['tp_version']))); define('VERSION_CODE', (int)trim(str_replace(['.', 'v'], '', $bb_cfg['tp_version'])));
/** /**
* @param $contents * @param $contents
@ -403,6 +403,10 @@ $userdata =& $user->data;
/** /**
* Check for updates * Check for updates
*/ */
$updaterFile = readUpdaterFile();
if ($updaterFile && ($updaterFile['previous_version'] < VERSION_CODE)) {
define('IN_UPDATER', true);
}
/** /**
* Cron * Cron

View file

@ -597,6 +597,11 @@ input.long {
padding-right: 20px; padding-right: 20px;
} }
.buttons input {
padding-left: 7px;
padding-right: 7px;
}
.buttons input:hover { .buttons input:hover {
border: 1px solid #DEDEDE; border: 1px solid #DEDEDE;
background: #FFF; background: #FFF;