Improved filelist.php (#1586)

* Improved filelist.php

* Update filelist.tpl

* Update filelist.php

* Update filelist.php

* Update CHANGELOG.md

* Update filelist.php

* Updated

* Update filelist.php

* Update filelist.tpl

* Updated

* Update filelist.php

* Update filelist.php

* Update filelist.php

* Update filelist.php

* Updated

* Update filelist.tpl

* Update filelist.php

* Update install.php

* Update install.php

* Update install.php

* Update install.php

* Update install.php

* Update install.php

* Update install.php

* Updated

* Updated

* Updated

* Updated

* Update filelist.php

* Update filelist.tpl

* Updated

* Update main.php
This commit is contained in:
Roman Kelesidis 2024-08-11 14:29:37 +07:00 committed by GitHub
commit aca756ea67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 140 additions and 154 deletions

View file

@ -9,6 +9,7 @@
- [CLI] TorrentPier installer ☕️ [\#1576](https://github.com/torrentpier/torrentpier/pull/1576), [\#1582](https://github.com/torrentpier/torrentpier/pull/1582), [\#1585](https://github.com/torrentpier/torrentpier/pull/1585) ([belomaxorka](https://github.com/belomaxorka)) - [CLI] TorrentPier installer ☕️ [\#1576](https://github.com/torrentpier/torrentpier/pull/1576), [\#1582](https://github.com/torrentpier/torrentpier/pull/1582), [\#1585](https://github.com/torrentpier/torrentpier/pull/1585) ([belomaxorka](https://github.com/belomaxorka))
- Added some new HTML meta-tags [\#1562](https://github.com/torrentpier/torrentpier/pull/1562) ([belomaxorka](https://github.com/belomaxorka)) - Added some new HTML meta-tags [\#1562](https://github.com/torrentpier/torrentpier/pull/1562) ([belomaxorka](https://github.com/belomaxorka))
- Added showing releaser stats in profile [\#1568](https://github.com/torrentpier/torrentpier/pull/1568) ([belomaxorka](https://github.com/belomaxorka)) - Added showing releaser stats in profile [\#1568](https://github.com/torrentpier/torrentpier/pull/1568) ([belomaxorka](https://github.com/belomaxorka))
- Improved `filelist.php` [\#1586](https://github.com/torrentpier/torrentpier/pull/1586) ([belomaxorka](https://github.com/belomaxorka))
- Demo mode: Save user language in cookies [\#1584](https://github.com/torrentpier/torrentpier/pull/1584) ([belomaxorka](https://github.com/belomaxorka)) - Demo mode: Save user language in cookies [\#1584](https://github.com/torrentpier/torrentpier/pull/1584) ([belomaxorka](https://github.com/belomaxorka))
- Fixed `md5()` deprecated in PHP 8.4 [\#1561](https://github.com/torrentpier/torrentpier/pull/1561) ([belomaxorka](https://github.com/belomaxorka)) - Fixed `md5()` deprecated in PHP 8.4 [\#1561](https://github.com/torrentpier/torrentpier/pull/1561) ([belomaxorka](https://github.com/belomaxorka))
- Increased `USEREMAIL_MAX_LENGTH` [\#1566](https://github.com/torrentpier/torrentpier/pull/1566) ([belomaxorka](https://github.com/belomaxorka)) - Increased `USEREMAIL_MAX_LENGTH` [\#1566](https://github.com/torrentpier/torrentpier/pull/1566) ([belomaxorka](https://github.com/belomaxorka))

View file

@ -7,6 +7,8 @@
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License * @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
*/ */
define('BB_SCRIPT', 'filelist');
require __DIR__ . '/common.php'; require __DIR__ . '/common.php';
// Start session management // Start session management
@ -17,7 +19,6 @@ if ($bb_cfg['bt_disable_dht'] && IS_GUEST) {
} }
$topic_id = isset($_GET[POST_TOPIC_URL]) ? (int)$_GET[POST_TOPIC_URL] : 0; $topic_id = isset($_GET[POST_TOPIC_URL]) ? (int)$_GET[POST_TOPIC_URL] : 0;
if (!$topic_id) { if (!$topic_id) {
bb_simple_die($lang['INVALID_TOPIC_ID'], 404); bb_simple_die($lang['INVALID_TOPIC_ID'], 404);
} }
@ -28,9 +29,8 @@ $sql = 'SELECT t.attach_id, t.info_hash, t.info_hash_v2, t.size, ad.physical_fil
ON t.attach_id = ad.attach_id ON t.attach_id = ad.attach_id
WHERE t.topic_id = ' . $topic_id . ' WHERE t.topic_id = ' . $topic_id . '
LIMIT 1'; LIMIT 1';
$row = DB()->fetch_row($sql);
if (empty($row['physical_filename'])) { if (!$row = DB()->fetch_row($sql)) {
bb_simple_die($lang['INVALID_TOPIC_ID_DB'], 404); bb_simple_die($lang['INVALID_TOPIC_ID_DB'], 404);
} }
@ -44,13 +44,11 @@ $t_files_field = $meta_v2 ? 'getFileTree' : 'getFiles';
$t_hash_field = $meta_v2 ? 'piecesRoot' : 'sha1'; $t_hash_field = $meta_v2 ? 'piecesRoot' : 'sha1';
$file_path = get_attachments_dir() . '/' . $row['physical_filename']; $file_path = get_attachments_dir() . '/' . $row['physical_filename'];
if (!is_file($file_path)) { if (!is_file($file_path)) {
bb_simple_die($lang['TOR_NOT_FOUND'], 410); bb_simple_die($lang['TOR_NOT_FOUND'], 410);
} }
$file_contents = file_get_contents($file_path); $file_contents = file_get_contents($file_path);
if ($bb_cfg['flist_max_files']) { if ($bb_cfg['flist_max_files']) {
$filetree_pos = $meta_v2 ? strpos($file_contents, '9:file tree') : false; $filetree_pos = $meta_v2 ? strpos($file_contents, '9:file tree') : false;
$files_pos = $meta_v1 ? strpos($file_contents, '5:files', $filetree_pos) : false; $files_pos = $meta_v1 ? strpos($file_contents, '5:files', $filetree_pos) : false;
@ -77,149 +75,34 @@ if (IS_GUEST && $torrent->isPrivate()) {
} }
$files = $torrent->$t_version_field()->$t_files_field(); $files = $torrent->$t_version_field()->$t_files_field();
if ($meta_v1 && $meta_v2) { if ($meta_v1 && $meta_v2) {
$files = new \RecursiveIteratorIterator($files); // Flatten the list $files = new \RecursiveIteratorIterator($files); // Flatten the list
} }
$allFiles = ''; $files_count = 0;
foreach ($files as $file) { foreach ($files as $file) {
$allFiles .= '<tr><td>' . clean_tor_dirname(implode('/', $file->path)) . '</td><td>' . humn_size($file->length, 2) . '</td><td>' . $file->$t_hash_field . '</td></tr>'; $files_count++;
$row_class = ($files_count % 2) ? 'row1' : 'row2';
$template->assign_block_vars('filelist', [
'ROW_NUMBER' => $files_count,
'ROW_CLASS' => $row_class,
'FILE_PATH' => clean_tor_dirname(implode('/', $file->path)),
'FILE_LENGTH' => humn_size($file->length, 2),
'FILE_HASH' => $file->$t_hash_field ?? '-'
]);
} }
$data = [ $torrent_name = !empty($t_name = $torrent->getName()) ? htmlCHR(str_short($t_name, 200)) : $lang['UNKNOWN'];
'name' => !empty($t_name = $torrent->getName()) ? htmlCHR(substr($t_name, 0, 255)) : 'undefined', $torrent_size = humn_size($row['size'], 2);
'client' => !empty($creator = $torrent->getCreatedBy()) ? htmlCHR(substr($creator, 0, 20)) : 'unknown client',
'date' => (!empty($dt = $torrent->getCreationDate()) && is_numeric($creation_date = $dt->getTimestamp())) ? date('d-M-Y H:i (e)', $creation_date) : $lang['UNKNOWN'],
'size' => humn_size($row['size'], 2),
'file_count' => iterator_count($files),
'site_url' => FULL_URL,
'topic_url' => TOPIC_URL . $topic_id,
];
header('Cache-Control: public, max-age=3600'); $template->assign_vars([
'PAGE_TITLE' => "$torrent_name (" . $torrent_size . ")",
'FILES_COUNT' => sprintf($lang['BT_FLIST_FILE_PATH'], declension(iterator_count($files), 'files')),
'TORRENT_CREATION_DATE' => (!empty($dt = $torrent->getCreationDate()) && is_numeric($creation_date = $dt->getTimestamp())) ? date('d-M-Y H:i (e)', $creation_date) : $lang['UNKNOWN'],
'TORRENT_CLIENT' => !empty($creator = $torrent->getCreatedBy()) ? htmlCHR(str_short($creator, 20)) : $lang['UNKNOWN'],
echo <<<EOF 'BTMR_NOTICE' => sprintf($lang['BT_FLIST_BTMR_NOTICE'], 'https://github.com/kovalensky/tmrr'),
<!DOCTYPE html> 'U_TOPIC' => TOPIC_URL . $topic_id,
<html lang="en"> ]);
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=0.1, maximum-scale=1.0" />
<meta name="robots" content="index" />
<meta name="description" content="File listing for topic - $topic_id | {$data['name']} ({$data['size']})" />
<meta property="og:description" content="File listing for topic - $topic_id | {$data['name']} ({$data['size']})" />
<meta property="og:site_name" content="{$bb_cfg['sitename']}" />
<meta name="generator" content="TorrentPier" />
<meta name="version" content="{$bb_cfg['tp_version']}" />
<link rel="shortcut icon" href="favicon.png" type="image/x-icon" />
<link rel="search" type="application/opensearchdescription+xml" href="{$data['site_url']}opensearch_desc.xml" title="{$bb_cfg['sitename']} (Forum)" />
<link rel="search" type="application/opensearchdescription+xml" href="{$data['site_url']}opensearch_desc_bt.xml" title="{$bb_cfg['sitename']} (Tracker)" />
<title>{$data['name']} ({$data['size']}) | {$bb_cfg['sitename']}</title> print_page('filelist.tpl');
</head>
<body>
<style>
body {
background-color: #1f1f1f; color: #ffffff;
}
hr {
border: 0;
height: 0;
border-bottom: 1px solid #acacac;
}
table {
table-layout: auto;
border: none;
width: auto;
margin: 20px auto;
font-family: "Segoe UI", "Noto Sans", Helvetica, sans-serif;
background-color: #2c2c2c;
}
th, td {
padding: 10px;
text-align: left;
color: #acacac;
width: auto;
}
td {
border: 3px solid #353535;
}
th {
background-color: #1f1f1f;
width: auto;
}
p {
color: #b3b3b3;
}
a {
text-decoration: none;
color: #1d9100;
}
a:hover {
text-decoration: underline;
}
sup {
color: #aa8000;
}
.tooltip {
position: relative;
}
.tooltip .tooltiptext {
visibility: hidden;
position: absolute;
z-index: 1;
top: 0;
opacity: 0;
transition: opacity 0.7s;
width: 200px;
background-color: #111;
color: #acacac;
text-align: left;
border-radius: 5px;
padding: 5px;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 0.97;
}
</style>
<a href="{$data['site_url']}{$data['topic_url']}" style="font-family: monospace; color: #569904;">&larr; Back to the topic</a>
<center>
<h2 style="color: #b3b3b3; font-family: monospace;">Name: {$data['name']} | Date: {$data['date']} | Size: {$data['size']}</h2>
<p>
<p style="font-family: Calibri, sans-serif;">Created by: <i title="Torrent client's name">{$data['client']}</i></p>
</p>
<hr>
<table>
<tr>
<th>Path ({$data['file_count']} files)</th>
<th>Size</th>
<th class="tooltip" style="width: auto;">
BTMR hash
<sup>?
<span class="tooltiptext">
BitTorrent Merkle Root is a hash of a file embedded in torrents with BitTorrent v2 support, tracker users can extract, calculate them, also download deduplicated torrents using desktop tools such as
<a href="https://github.com/kovalensky/tmrr" target="_blank" referrerpolicy="origin">Torrent Merkle Root Reader.</a>
</span>
</sup>
</th>
</tr>
{$allFiles}
</table>
<p style="color: #b3b3b3; font-family: Calibri, sans-serif;">Generated by <a href="https://github.com/torrentpier/torrentpier" target="_blank" referrerpolicy="origin" title="Bull-powered BitTorrent tracker engine">TorrentPier</a></p>
</center>
</body>
</html>
EOF;

View file

@ -14,17 +14,10 @@ if (php_sapi_name() !== 'cli') {
die('Please run <code style="background:#222;color:#00e01f;padding:2px 6px;border-radius:3px;">php ' . basename(__FILE__) . '</code> in CLI mode'); die('Please run <code style="background:#222;color:#00e01f;padding:2px 6px;border-radius:3px;">php ' . basename(__FILE__) . '</code> in CLI mode');
} }
// Check if already installed
if (is_file(BB_ROOT . '.env')) {
out('- TorrentPier already installed', 'error');
exit;
}
/** /**
* System requirements * System requirements
*/ */
define('CHECK_REQUIREMENTS', [ define('CHECK_REQUIREMENTS', [
'status' => true,
'php_min_version' => '8.1.0', 'php_min_version' => '8.1.0',
'ext_list' => [ 'ext_list' => [
'json', 'json',
@ -105,6 +98,27 @@ function runProcess(string $cmd, string $input = null): void
proc_close($process); proc_close($process);
} }
/**
* Remove directory recursively
*
* @param string $dir
* @return void
*/
function rmdir_rec(string $dir): void
{
$it = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it,
RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $file) {
if ($file->isDir()) {
rmdir($file->getPathname());
} else {
unlink($file->getPathname());
}
}
rmdir($dir);
}
/** /**
* Setting permissions recursively * Setting permissions recursively
* *
@ -123,11 +137,11 @@ function chmod_r(string $dir, int $dirPermissions, int $filePermissions): void
$fullPath = realpath($dir . '/' . $file); $fullPath = realpath($dir . '/' . $file);
if (is_dir($fullPath)) { if (is_dir($fullPath)) {
out("- Directory: $fullPath"); // out("- Directory: $fullPath");
chmod($fullPath, $dirPermissions); chmod($fullPath, $dirPermissions);
chmod_r($fullPath, $dirPermissions, $filePermissions); chmod_r($fullPath, $dirPermissions, $filePermissions);
} elseif (is_file($fullPath)) { } elseif (is_file($fullPath)) {
out("- File: $fullPath"); // out("- File: $fullPath");
chmod($fullPath, $filePermissions); chmod($fullPath, $filePermissions);
} else { } else {
out("- Cannot find target path: $fullPath", 'error'); out("- Cannot find target path: $fullPath", 'error');
@ -160,8 +174,48 @@ foreach (CHECK_REQUIREMENTS['ext_list'] as $ext) {
} }
out("- All extensions are installed!\n", 'success'); out("- All extensions are installed!\n", 'success');
// Setting permissions // Check if already installed
out("- Setting permissions for folders...", 'info'); if (is_file(BB_ROOT . '.env')) {
out('- TorrentPier already installed', 'warning');
echo 'Are you sure want to re-install TorrentPier? [y/N]: ';
if (readline() === 'y') {
out("\n- Re-install process started...", 'info');
// environment
if (is_file(BB_ROOT . '.env')) {
if (unlink(BB_ROOT . '.env')) {
out('- Environment file successfully removed!');
} else {
out('- Cannot remove environment (.env) file. Delete it manually', 'error');
exit;
}
}
// composer.phar
if (is_file(BB_ROOT . 'composer.phar')) {
if (unlink(BB_ROOT . 'composer.phar')) {
out("- composer.phar file successfully removed!");
} else {
out('- Cannot remove composer.phar file. Delete it manually', 'error');
exit;
}
}
// composer dir
if (is_dir(BB_ROOT . 'vendor')) {
rmdir_rec(BB_ROOT . 'vendor');
if (!is_dir(BB_ROOT . 'vendor')) {
out("- Composer directory successfully removed!");
} else {
out('- Cannot remove Composer directory. Delete it manually', 'error');
exit;
}
}
out("- Re-install process completed!\n", 'success');
} else {
exit;
}
}
// Applying permissions
out("- Applying permissions for folders...", 'info');
chmod_r(BB_ROOT . 'data', 0755, 0644); chmod_r(BB_ROOT . 'data', 0755, 0644);
chmod_r(BB_ROOT . 'internal_data', 0755, 0644); chmod_r(BB_ROOT . 'internal_data', 0755, 0644);
chmod_r(BB_ROOT . 'sitemap', 0755, 0644); chmod_r(BB_ROOT . 'sitemap', 0755, 0644);
@ -194,7 +248,7 @@ if (!is_file(BB_ROOT . 'vendor/autoload.php')) {
if (is_file(BB_ROOT . 'composer.phar')) { if (is_file(BB_ROOT . 'composer.phar')) {
out('- Installing dependencies...', 'info'); out('- Installing dependencies...', 'info');
runProcess('php ' . BB_ROOT . 'composer.phar install --no-interaction --no-ansi'); runProcess('php ' . BB_ROOT . 'composer.phar install --no-interaction --no-ansi');
out("- Completed!\n", 'success'); out("- Completed! Composer dependencies are installed!\n", 'success');
} else { } else {
out('- composer.phar not found', 'error'); out('- composer.phar not found', 'error');
exit; exit;

View file

@ -1348,6 +1348,10 @@ $lang['BT_REG_FAIL_SAME_HASH'] = 'Another torrent with same info_hash already <a
$lang['BT_V1_ONLY_DISALLOWED'] = 'v1-only torrents have been disabled by the administrator at the moment, allowed: v2 and hybrids'; $lang['BT_V1_ONLY_DISALLOWED'] = 'v1-only torrents have been disabled by the administrator at the moment, allowed: v2 and hybrids';
$lang['BT_V2_ONLY_DISALLOWED'] = 'v2-only torrents have been disabled by the administrator at the moment, allowed: v1 and hybrids'; $lang['BT_V2_ONLY_DISALLOWED'] = 'v2-only torrents have been disabled by the administrator at the moment, allowed: v1 and hybrids';
$lang['BT_FLIST_LIMIT'] = 'Tracker settings do not allow to process lists with more than %d files. Current number is: %d'; $lang['BT_FLIST_LIMIT'] = 'Tracker settings do not allow to process lists with more than %d files. Current number is: %d';
$lang['BT_FLIST_BTMR_HASH'] = 'BTMR Hash';
$lang['BT_FLIST_BTMR_NOTICE'] = 'BitTorrent Merkle Root is a hash of a file embedded in torrents with BitTorrent v2 support, tracker users can extract, calculate them, also download deduplicated torrents using desktop tools such as <a href="%s" target="_blank" referrerpolicy="origin">Torrent Merkle Root Reader</a>';
$lang['BT_FLIST_CREATION_DATE'] = 'Creation date';
$lang['BT_FLIST_FILE_PATH'] = 'Path (%s)';
$lang['BT_UNREG_FROM_TRACKER'] = 'Remove from tracker'; $lang['BT_UNREG_FROM_TRACKER'] = 'Remove from tracker';
$lang['BT_UNREGISTERED'] = 'Torrent unregistered'; $lang['BT_UNREGISTERED'] = 'Torrent unregistered';
$lang['BT_UNREGISTERED_ALREADY'] = 'Torrent already unregistered'; $lang['BT_UNREGISTERED_ALREADY'] = 'Torrent already unregistered';
@ -1644,6 +1648,7 @@ $lang['SEND_PM_TXTB'] = '[PM]';
$lang['DECLENSION']['REPLIES'] = ['reply', 'replies']; $lang['DECLENSION']['REPLIES'] = ['reply', 'replies'];
$lang['DECLENSION']['TIMES'] = ['time', 'times']; $lang['DECLENSION']['TIMES'] = ['time', 'times'];
$lang['DECLENSION']['FILES'] = ['file', 'files'];
$lang['DELTA_TIME']['INTERVALS'] = [ $lang['DELTA_TIME']['INTERVALS'] = [
'seconds' => ['second', 'seconds'], 'seconds' => ['second', 'seconds'],
@ -1837,7 +1842,7 @@ $lang['DL_DL'] = 'DL';
$lang['DL_UL_SPEED'] = 'UL speed'; $lang['DL_UL_SPEED'] = 'UL speed';
$lang['DL_DL_SPEED'] = 'DL speed'; $lang['DL_DL_SPEED'] = 'DL speed';
$lang['DL_PORT'] = 'Port'; $lang['DL_PORT'] = 'Port';
$lang['DL_CLIENT'] = 'Client'; $lang['DL_CLIENT'] = 'BitTorrent client';
$lang['DL_FORMULA'] = 'Formula: Uploaded/TorrentSize'; $lang['DL_FORMULA'] = 'Formula: Uploaded/TorrentSize';
$lang['DL_ULR'] = 'ULR'; $lang['DL_ULR'] = 'ULR';
$lang['DL_STOPPED'] = 'stopped'; $lang['DL_STOPPED'] = 'stopped';

View file

@ -0,0 +1,43 @@
<h1 class="pagetitle">{PAGE_TITLE}</h1>
<ul>
<li>{L_BT_FLIST_CREATION_DATE}: <b>{TORRENT_CREATION_DATE}</b></li>
<li>{L_DL_CLIENT}: <b>{TORRENT_CLIENT}</b></li>
</ul>
<br>
<table class="forumline">
<thead>
<tr>
<th>#</th>
<th>{FILES_COUNT}</th>
<th>{L_SIZE}</th>
<th>{L_BT_FLIST_BTMR_HASH}</th>
</tr>
</thead>
<!-- BEGIN filelist -->
<tbody>
<tr class="{filelist.ROW_CLASS} tCenter">
<td>{filelist.ROW_NUMBER}</td>
<td>{filelist.FILE_PATH}</td>
<td>{filelist.FILE_LENGTH}</td>
<td>{filelist.FILE_HASH}</td>
</tr>
</tbody>
<!-- END filelist -->
<tfoot>
<tr>
<td class="catBottom warnColor1" colspan="4">{BTMR_NOTICE}</td>
</tr>
</tfoot>
</table>
<!--bottom_info-->
<div class="bottom_info">
<div class="spacer_8"></div>
<a href="{U_TOPIC}">{L_TOPIC_RETURN}</a>
<div id="timezone">
<p>{CURRENT_TIME}</p>
<p>{S_TIMEZONE}</p>
</div>
<div class="clear"></div>
</div><!--/bottom_info-->