diff --git a/CHANGELOG.md b/CHANGELOG.md index e80da16f7..209267f27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) - 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)) +- 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)) - 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)) diff --git a/filelist.php b/filelist.php index cdf8a1fc7..3b4412928 100644 --- a/filelist.php +++ b/filelist.php @@ -7,6 +7,8 @@ * @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License */ +define('BB_SCRIPT', 'filelist'); + require __DIR__ . '/common.php'; // 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; - if (!$topic_id) { 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 WHERE t.topic_id = ' . $topic_id . ' 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); } @@ -44,13 +44,11 @@ $t_files_field = $meta_v2 ? 'getFileTree' : 'getFiles'; $t_hash_field = $meta_v2 ? 'piecesRoot' : 'sha1'; $file_path = get_attachments_dir() . '/' . $row['physical_filename']; - if (!is_file($file_path)) { bb_simple_die($lang['TOR_NOT_FOUND'], 410); } $file_contents = file_get_contents($file_path); - if ($bb_cfg['flist_max_files']) { $filetree_pos = $meta_v2 ? strpos($file_contents, '9:file tree') : 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(); - if ($meta_v1 && $meta_v2) { $files = new \RecursiveIteratorIterator($files); // Flatten the list } -$allFiles = ''; +$files_count = 0; foreach ($files as $file) { - $allFiles .= '
-
Created by: {$data['client']}
- -Path ({$data['file_count']} files) | -Size | -- BTMR hash - ? - - 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 - Torrent Merkle Root Reader. - - - | -
---|
Generated by TorrentPier
-php ' . basename(__FILE__) . '
in CLI mode');
}
-// Check if already installed
-if (is_file(BB_ROOT . '.env')) {
- out('- TorrentPier already installed', 'error');
- exit;
-}
-
/**
* System requirements
*/
define('CHECK_REQUIREMENTS', [
- 'status' => true,
'php_min_version' => '8.1.0',
'ext_list' => [
'json',
@@ -105,6 +98,27 @@ function runProcess(string $cmd, string $input = null): void
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
*
@@ -123,11 +137,11 @@ function chmod_r(string $dir, int $dirPermissions, int $filePermissions): void
$fullPath = realpath($dir . '/' . $file);
if (is_dir($fullPath)) {
- out("- Directory: $fullPath");
+ // out("- Directory: $fullPath");
chmod($fullPath, $dirPermissions);
chmod_r($fullPath, $dirPermissions, $filePermissions);
} elseif (is_file($fullPath)) {
- out("- File: $fullPath");
+ // out("- File: $fullPath");
chmod($fullPath, $filePermissions);
} else {
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');
-// Setting permissions
-out("- Setting permissions for folders...", 'info');
+// Check if already installed
+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 . 'internal_data', 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')) {
out('- Installing dependencies...', 'info');
runProcess('php ' . BB_ROOT . 'composer.phar install --no-interaction --no-ansi');
- out("- Completed!\n", 'success');
+ out("- Completed! Composer dependencies are installed!\n", 'success');
} else {
out('- composer.phar not found', 'error');
exit;
diff --git a/library/language/source/main.php b/library/language/source/main.php
index 1fc121473..81733a4ce 100644
--- a/library/language/source/main.php
+++ b/library/language/source/main.php
@@ -1348,6 +1348,10 @@ $lang['BT_REG_FAIL_SAME_HASH'] = 'Another torrent with same info_hash already Torrent Merkle Root Reader';
+$lang['BT_FLIST_CREATION_DATE'] = 'Creation date';
+$lang['BT_FLIST_FILE_PATH'] = 'Path (%s)';
$lang['BT_UNREG_FROM_TRACKER'] = 'Remove from tracker';
$lang['BT_UNREGISTERED'] = 'Torrent unregistered';
$lang['BT_UNREGISTERED_ALREADY'] = 'Torrent already unregistered';
@@ -1644,6 +1648,7 @@ $lang['SEND_PM_TXTB'] = '[PM]';
$lang['DECLENSION']['REPLIES'] = ['reply', 'replies'];
$lang['DECLENSION']['TIMES'] = ['time', 'times'];
+$lang['DECLENSION']['FILES'] = ['file', 'files'];
$lang['DELTA_TIME']['INTERVALS'] = [
'seconds' => ['second', 'seconds'],
@@ -1837,7 +1842,7 @@ $lang['DL_DL'] = 'DL';
$lang['DL_UL_SPEED'] = 'UL speed';
$lang['DL_DL_SPEED'] = 'DL speed';
$lang['DL_PORT'] = 'Port';
-$lang['DL_CLIENT'] = 'Client';
+$lang['DL_CLIENT'] = 'BitTorrent client';
$lang['DL_FORMULA'] = 'Formula: Uploaded/TorrentSize';
$lang['DL_ULR'] = 'ULR';
$lang['DL_STOPPED'] = 'stopped';
diff --git a/styles/templates/default/filelist.tpl b/styles/templates/default/filelist.tpl
new file mode 100644
index 000000000..25f9a9cc1
--- /dev/null
+++ b/styles/templates/default/filelist.tpl
@@ -0,0 +1,43 @@
+# | +{FILES_COUNT} | +{L_SIZE} | +{L_BT_FLIST_BTMR_HASH} | +
---|---|---|---|
{filelist.ROW_NUMBER} | +{filelist.FILE_PATH} | +{filelist.FILE_LENGTH} | +{filelist.FILE_HASH} | +
{BTMR_NOTICE} | +
{CURRENT_TIME}
+{S_TIMEZONE}
+