Added TorrentPier files integrity check 📦 (#1491)

* Added file integrity check 📦

* Update CHANGELOG.md

* Update CHANGELOG.md

* Updated

* Update Common.php

* Updated

* Update board_maintenance.php

* Update index.tpl

* Updated

* Updated

* Update build_check_updates.php

* Update build_check_updates.php

* Update build_check_updates.php

* Update build_check_updates.php

* Update build_check_updates.php

* Update index.php

* Updated

* Update build_check_updates.php

* Update build_files_integrity.php

* Update build_files_integrity.php

* Update build_files_integrity.php

* Create checksums.md5

* Update build_files_integrity.php

* Update build_files_integrity.php

* Updated

* Update checksums.md5

* Update defines.php

* Update build_files_integrity.php

* Updated

* Update main.php

* Update main.php

* Update main.php

* Update index.tpl

* Update index.tpl

* Update index.php

* Update build_check_updates.php

* Update build_check_updates.php

* Update checksums.md5

* Update build_files_integrity.php

* Update checksums.md5
This commit is contained in:
Roman Kelesidis 2024-06-08 00:32:10 +07:00 committed by GitHub
commit 437c2e5d8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 2614 additions and 4 deletions

View file

@ -6,6 +6,7 @@
**Merged pull requests:**
- Release 2.4.3 🐎 ([belomaxorka](https://github.com/belomaxorka))
- Added TorrentPier files integrity check 📦 [\#1491](https://github.com/torrentpier/torrentpier/pull/1491) ([belomaxorka](https://github.com/belomaxorka))
- Added updates checker ⚙️ [\#1451](https://github.com/torrentpier/torrentpier/pull/1451), [\#1475](https://github.com/torrentpier/torrentpier/pull/1475) ([belomaxorka](https://github.com/belomaxorka))
- Added preview for country flags while editing [\#1448](https://github.com/torrentpier/torrentpier/pull/1448) ([belomaxorka](https://github.com/belomaxorka))
- Added support for APCu caching method [\#1442](https://github.com/torrentpier/torrentpier/pull/1442) ([belomaxorka](https://github.com/belomaxorka))

View file

@ -15,6 +15,12 @@ if (!$stats = $datastore->get('stats')) {
$stats = $datastore->get('stats');
}
// Files integrity check
if (!$files_integrity_data = $datastore->get('files_integrity')) {
$datastore->update('files_integrity');
$files_integrity_data = $datastore->get('files_integrity');
}
// Check for updates
if (!$update_data = $datastore->get('check_updates')) {
$datastore->update('check_updates');
@ -82,8 +88,18 @@ if (isset($_GET['pane']) && $_GET['pane'] == 'left') {
'ADMIN_LOCK_CRON' => is_file(BB_DISABLED),
]);
// Files integrity check results
if (!empty($files_integrity_data)) {
$template->assign_block_vars('integrity_check', [
'INTEGRITY_SUCCESS' => (bool)$files_integrity_data['success'],
'INTEGRITY_WRONG_FILES_LIST' => implode("\n</li>\n<li>\n", $files_integrity_data['wrong_files']),
'INTEGRITY_LAST_CHECK_TIME' => sprintf($lang['INTEGRITY_LAST_CHECK'], bb_date($files_integrity_data['timestamp'])),
'INTEGRITY_CHECKED_FILES' => sprintf($lang['INTEGRITY_CHECKED'], $files_integrity_data['total_num'], ($files_integrity_data['total_num'] - $files_integrity_data['wrong_files_num'])),
]);
}
// Check for updates
if (!empty($update_data)) {
if (isset($update_data['available_update'])) {
$template->assign_block_vars('updater', [
'UPDATE_AVAILABLE' => $update_data['available_update'],
'NEW_VERSION_NUMBER' => $update_data['latest_version'],

2509
internal_data/checksums.md5 Normal file

File diff suppressed because it is too large Load diff

View file

@ -33,6 +33,7 @@ define('APP_NAME', 'TorrentPier');
define('UPDATER_URL', 'https://api.github.com/repos/torrentpier/torrentpier/releases/latest');
define('UPDATER_FILE', INT_DATA_DIR . '/updater.ver');
define('API_IP_URL', 'https://freeipapi.com/api/json/');
define('CHECKSUMS_FILE', INT_DATA_DIR . '/checksums.md5');
define('CHECK_REQUIREMENTS', [
'status' => true,
'php_min_version' => '8.1.0',

View file

@ -61,3 +61,6 @@ if (IN_DEMO_MODE) {
// Check for updates
$datastore->update('check_updates');
// Integrity check
$datastore->update('files_integrity');

View file

@ -15,7 +15,7 @@ global $bb_cfg;
$data = [];
$context = stream_context_create(['http' => ['header' => 'User-Agent: ' . APP_NAME]]);
$context = stream_context_create(['http' => ['header' => 'User-Agent: ' . APP_NAME, 'timeout' => 10, 'ignore_errors' => true]]);
$updater_content = file_get_contents(UPDATER_URL, context: $context);
$json_response = false;
@ -23,7 +23,7 @@ if ($updater_content !== false) {
$json_response = json_decode(utf8_encode($updater_content), true);
}
if (is_array($json_response) && !empty($json_response)) {
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));
@ -52,4 +52,5 @@ if (is_array($json_response) && !empty($json_response)) {
}
}
$data[] = ['latest_check_timestamp' => TIMENOW];
$this->store('check_updates', $data);

View file

@ -0,0 +1,54 @@
<?php
/**
* TorrentPier Bull-powered BitTorrent tracker engine
*
* @copyright Copyright (c) 2005-2024 TorrentPier (https://torrentpier.com)
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
*/
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
}
global $bb_cfg;
$data = [];
$filesList = [];
$checksumFile = new SplFileObject(CHECKSUMS_FILE, 'r');
$checksumFile->setFlags(SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE);
$lines = [];
foreach ($checksumFile as $line) {
$parts = explode(' ', $line);
if (!isset($parts[1])) {
// Skip end line
break;
}
if (basename($parts[1]) === basename(CHECKSUMS_FILE)) {
// Skip checksums.md5
continue;
}
$filesList[] = [
'path' => trim($parts[1]),
'hash' => trim($parts[0])
];
}
$wrongFilesList = [];
foreach ($filesList as $file) {
if (strtolower(md5_file(BB_ROOT . '/' . $file['path'])) !== strtolower($file['hash'])) {
$wrongFilesList[] = $file['path'];
}
}
$data = [
'success' => empty($wrongFilesList),
'wrong_files' => $wrongFilesList,
'wrong_files_num' => count($wrongFilesList),
'total_num' => count($filesList),
'timestamp' => TIMENOW,
];
$this->store('files_integrity', $data);

View file

@ -2283,6 +2283,12 @@ $lang['DISALLOWED_ALREADY'] = 'The name you entered could not be disallowed. It
$lang['CLICK_RETURN_DISALLOWADMIN'] = 'Click %sHere%s to return to Disallow Username Administration';
// Integrity check
$lang['INTEGRITY_CHECK_SUCCESS'] = 'TorrentPier files integrity check was successful!';
$lang['INTEGRITY_CHECK_FAIL'] = 'Some TorrentPier files not pass integrity check!';
$lang['INTEGRITY_CHECKED'] = 'Total checked: %s file(s), of which pass integrity check: %s file(s).';
$lang['INTEGRITY_LAST_CHECK'] = 'Last check: %s.';
// Version Check
$lang['VERSION_INFORMATION'] = 'Version Information';
$lang['UPDATE_AVAILABLE'] = 'Update available';

View file

@ -42,6 +42,7 @@ class Common
public array $known_items = [
'cat_forums' => 'build_cat_forums.php',
'check_updates' => 'build_check_updates.php',
'files_integrity' => 'build_files_integrity.php',
'jumpbox' => 'build_cat_forums.php',
'viewtopic_forum_select' => 'build_cat_forums.php',
'latest_news' => 'build_cat_forums.php',

View file

@ -84,7 +84,25 @@
}
</script>
<br/>
<!-- BEGIN integrity_check -->
<!-- IF integrity_check.INTEGRITY_SUCCESS -->
<div class="alert alert-success" style="width: 95%;">
<h4 class="alert-heading">{L_INTEGRITY_CHECK_SUCCESS}</h4>
<h6>{integrity_check.INTEGRITY_CHECKED_FILES} {integrity_check.INTEGRITY_LAST_CHECK_TIME}</h6>
</div>
<!-- ELSE -->
<div class="alert alert-danger" style="width: 95%;">
<h4 class="alert-heading">{L_INTEGRITY_CHECK_FAIL}</h4>
<h6>{integrity_check.INTEGRITY_CHECKED_FILES} {integrity_check.INTEGRITY_LAST_CHECK_TIME}</h6>
<hr>
<!-- IF integrity_check.INTEGRITY_WRONG_FILES_LIST -->
<ul style="max-height: 120px; overflow-x: auto;">
<li>{integrity_check.INTEGRITY_WRONG_FILES_LIST}</li>
</ul>
<!-- ENDIF -->
</div>
<!-- ENDIF -->
<!-- END integrity_check -->
<!-- IF ADMIN_LOCK_CRON -->
<div class="alert alert-danger" style="width: 95%;">

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before After
Before After