mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-20 13:24:01 -07:00
Fix issues related to file list display and torrent registration (#1028)
Bencoding libraries properties changed in the new version
This commit is contained in:
parent
5005474b1a
commit
5d872e3555
4 changed files with 24 additions and 19 deletions
|
@ -132,7 +132,7 @@ $peer_hash = hash('xxh128', $passkey . $info_hash_hex . $port);
|
||||||
// Events
|
// Events
|
||||||
$stopped = ($event === 'stopped');
|
$stopped = ($event === 'stopped');
|
||||||
|
|
||||||
// Get the real port to help NAT users
|
// Get the real port to help some NAT users
|
||||||
$port = $_SERVER['REMOTE_PORT'];
|
$port = $_SERVER['REMOTE_PORT'];
|
||||||
|
|
||||||
// Set seeder & complete
|
// Set seeder & complete
|
||||||
|
|
|
@ -32,14 +32,12 @@ if (!file_exists($filename) || !$file_contents = file_get_contents($filename)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents)) {
|
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY)) {
|
||||||
return $lang['TORFILE_INVALID'];
|
return $lang['TORFILE_INVALID'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$torrent = new TorrentPier\Legacy\TorrentFileList($tor);
|
$torrent = new TorrentPier\Legacy\TorrentFileList($tor);
|
||||||
if (($tor['info']['meta version'] ?? null) == 2) {
|
|
||||||
$tor_filelist = $torrent->fileTreeList($tor['info']['file tree'], $tor['info']['name'] ?? ''); // v2
|
$tor_filelist = $torrent->get_filelist();
|
||||||
} else {
|
|
||||||
$tor_filelist = $torrent->get_filelist(); // v1
|
|
||||||
}
|
|
||||||
$this->response['html'] = $tor_filelist;
|
$this->response['html'] = $tor_filelist;
|
||||||
|
|
|
@ -316,7 +316,7 @@ class Torrent
|
||||||
if (!is_file($filename) || !file_exists($filename)) {
|
if (!is_file($filename) || !file_exists($filename)) {
|
||||||
self::torrent_error_exit($lang['ERROR_NO_ATTACHMENT']);
|
self::torrent_error_exit($lang['ERROR_NO_ATTACHMENT']);
|
||||||
}
|
}
|
||||||
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents)) {
|
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY)) {
|
||||||
self::torrent_error_exit($lang['TORFILE_INVALID']);
|
self::torrent_error_exit($lang['TORFILE_INVALID']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,26 +348,27 @@ class Torrent
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if torrent contains info_hash v2 or v1
|
// Check if torrent contains info_hash v2 or v1
|
||||||
$bt_v1 = $bt_v2 = false;
|
if (($info['meta version'] ?? null) == 2 ) {
|
||||||
if (($info['meta version'] ?? null) == 2 && is_array($info['file tree'] ?? null)) {
|
if (is_array($info['file tree'] ?? null)) {
|
||||||
$bt_v2 = true;
|
$bt_v2 = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (isset($info['pieces'])) {
|
if (isset($info['pieces'])) {
|
||||||
$bt_v1 = true;
|
$bt_v1 = true;
|
||||||
}
|
}
|
||||||
if ($bb_cfg['tracker']['disabled_v2_torrents'] && $bt_v2 && !$bt_v1) {
|
if ($bb_cfg['tracker']['disabled_v2_torrents'] && isset($bt_v2) && !isset($bt_v1)) {
|
||||||
self::torrent_error_exit('v2-only torrents were disabled, allowed: v1 and hybrids');
|
self::torrent_error_exit('v2-only torrents were disabled, allowed: v1 and hybrids');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getting info_hash v1
|
// Getting info_hash v1
|
||||||
if ($bt_v1) {
|
if (isset($bt_v1)) {
|
||||||
$info_hash = pack('H*', hash('sha1', \Arokettu\Bencode\Bencode::encode($info)));
|
$info_hash = pack('H*', hash('sha1', \Arokettu\Bencode\Bencode::encode($info)));
|
||||||
$info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
|
$info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
|
||||||
$info_hash_where = "WHERE info_hash = '$info_hash_sql'";
|
$info_hash_where = "WHERE info_hash = '$info_hash_sql'";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getting info_hash v2
|
// Getting info_hash v2
|
||||||
if ($bt_v2) {
|
if (isset($bt_v2)) {
|
||||||
$v2_hash = hash('sha256', \Arokettu\Bencode\Bencode::encode($info));
|
$v2_hash = hash('sha256', \Arokettu\Bencode\Bencode::encode($info));
|
||||||
$info_hash_v2 = pack('H*', $v2_hash);
|
$info_hash_v2 = pack('H*', $v2_hash);
|
||||||
$info_hash_v2_sql = rtrim(DB()->escape($info_hash_v2), ' ');
|
$info_hash_v2_sql = rtrim(DB()->escape($info_hash_v2), ' ');
|
||||||
|
@ -386,17 +387,18 @@ class Torrent
|
||||||
}
|
}
|
||||||
|
|
||||||
$totallen = 0;
|
$totallen = 0;
|
||||||
|
|
||||||
if (isset($info['length'])) {
|
if (isset($info['length'])) {
|
||||||
$totallen = (float)$info['length'];
|
$totallen = (float)$info['length'];
|
||||||
} elseif ($bt_v1 && isset($info['files']) && \is_array($info['files'])) {
|
} elseif (isset($bt_v1) && isset($info['files']) && \is_array($info['files'])) {
|
||||||
foreach ($info['files'] as $fn => $f) {
|
foreach ($info['files'] as $fn => $f) {
|
||||||
// Exclude padding files
|
// Exclude padding files
|
||||||
if (($f['attr'] ?? null) !== 'p') {
|
if (($f['attr'] ?? null) !== 'p') {
|
||||||
$totallen += (float)$f['length'];
|
$totallen += (float)$f['length'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif ($bt_v2) {
|
} elseif (isset($bt_v2)) {
|
||||||
$fileTreeSize = function ($array, string $name = '') use (&$fileTreeSize) {
|
$fileTreeSize = function (array $array, string $name = '') use (&$fileTreeSize) {
|
||||||
$size = 0;
|
$size = 0;
|
||||||
|
|
||||||
foreach ($array as $key => $value) {
|
foreach ($array as $key => $value) {
|
||||||
|
@ -543,7 +545,7 @@ class Torrent
|
||||||
$ann_url = $bb_cfg['bt_announce_url'];
|
$ann_url = $bb_cfg['bt_announce_url'];
|
||||||
|
|
||||||
$file_contents = file_get_contents($filename);
|
$file_contents = file_get_contents($filename);
|
||||||
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents)) {
|
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY)) {
|
||||||
bb_die($lang['TORFILE_INVALID']);
|
bb_die($lang['TORFILE_INVALID']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,11 @@ class TorrentFileList
|
||||||
public function get_filelist()
|
public function get_filelist()
|
||||||
{
|
{
|
||||||
global $html;
|
global $html;
|
||||||
|
if (($this->tor_decoded['info']['meta version'] ?? null) == 2) {
|
||||||
|
if (is_array($this->tor_decoded['info']['file tree'] ?? null)) {
|
||||||
|
return $this->fileTreeList($this->tor_decoded['info']['file tree']); //v2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->build_filelist_array();
|
$this->build_filelist_array();
|
||||||
|
|
||||||
|
@ -132,7 +137,7 @@ class TorrentFileList
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function fileTreeList($array, string $name = ''): string
|
public function fileTreeList(array $array, string $name = ''): string
|
||||||
{
|
{
|
||||||
$folders = [];
|
$folders = [];
|
||||||
$rootFiles = [];
|
$rootFiles = [];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue