diff --git a/bt/announce.php b/bt/announce.php index 4a6c48415..29a2f4001 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -82,7 +82,7 @@ if (!isset($info_hash)) { $info_hash_hex = bin2hex($info_hash); // Store peer id -$peer_id_sql = rtrim(DB()->escape(preg_replace('/[^a-zA-Z0-9\-\_]/', '', $peer_id)), ' '); +$peer_id_sql = preg_replace('/[^a-zA-Z0-9\-\_]/', '', $peer_id); // Check info_hash length if (strlen($info_hash) !== 20) { @@ -108,17 +108,15 @@ if (!isset($left) || $left < 0) { // IP $ip = $_SERVER['REMOTE_ADDR']; +// 'ip' query handling if (!$bb_cfg['ignore_reported_ip'] && isset($_GET['ip']) && $ip !== $_GET['ip']) { - if (!$bb_cfg['verify_reported_ip']) { - $ip = $_GET['ip']; - } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) { - foreach ($matches[0] as $x_ip) { - if ($x_ip === $_GET['ip']) { - if (!$bb_cfg['allow_internal_ip'] && preg_match("#(127\.([0-9]{1,3}\.){2}[0-9]{1,3}|10\.([0-9]{1,3}\.){2}[0-9]{1,3}|172\.[123][0-9]\.[0-9]{1,3}\.[0-9]{1,3}|192\.168\.[0-9]{1,3}\.[0-9]{1,3})#", $x_ip)) { - break; - } - $ip = $x_ip; - break; + if (!$bb_cfg['verify_reported_ip'] && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $x_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + + if ($x_ip === $_GET['ip']) { + $filteredIp = filter_var($x_ip, FILTER_VALIDATE_IP); + if ($filteredIp !== false && ($bb_cfg['allow_internal_ip'] || !filter_var($filteredIp, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE))) { + $ip = $filteredIp; } } } @@ -216,7 +214,12 @@ if ($lp_info) { // Check hybrid status if (!empty($row['info_hash']) && !empty($row['info_hash_v2'])) { - if ($info_hash !== $row['info_hash']) { // Change this to substr($row['info_hash_v2'], 0, 20) in the future for updating statistics, in case of v2 torrents being prioritized. + $stat_protocol = match($bb_cfg['tracker']['hybrid_stat_protocol']) { + 1 => $row['info_hash'], + 2 => substr($row['info_hash_v2'], 0, 20), + default => $row['info_hash'] + }; + if ($info_hash !== $stat_protocol) { $hybrid_unrecord = true; // This allows us to announce only for one info-hash } } @@ -450,7 +453,6 @@ if (!$output) { $output = [ 'interval' => (int)$announce_interval, - 'min interval' => (int)$announce_interval, 'complete' => (int)$seeders, 'incomplete' => (int)$leechers, 'downloaded' => (int)$client_completed, diff --git a/common.php b/common.php index 3ba700bd2..a60d45e00 100644 --- a/common.php +++ b/common.php @@ -44,7 +44,7 @@ date_default_timezone_set('UTC'); // Set remote address $allowedCDNs = ['HTTP_X_FORWARDED_FOR', 'HTTP_FASTLY_CLIENT_IP', 'HTTP_CF_CONNECTING_IP']; foreach ($allowedCDNs as $allowedCDN) { - if (isset($_SERVER[$allowedCDN]) && filter_var($_SERVER[$allowedCDN], FILTER_VALIDATE_IP)) { + if (isset($_SERVER[$allowedCDN]) && filter_var($_SERVER[$allowedCDN], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { $_SERVER['REMOTE_ADDR'] = $_SERVER[$allowedCDN]; } } diff --git a/composer.json b/composer.json index aa8c85a5d..2e678e70c 100644 --- a/composer.json +++ b/composer.json @@ -47,6 +47,7 @@ "ext-xml": "*", "ext-xmlwriter": "*", "arokettu/bencode": "^4.1.0", + "arokettu/torrent-file": "^5.2.1", "bugsnag/bugsnag": "^v3.29.1", "claviska/simpleimage": "^4.0", "egulias/email-validator": "^4.0.1", diff --git a/filelist.php b/filelist.php index 90697d7e6..9ae8bff4c 100644 --- a/filelist.php +++ b/filelist.php @@ -35,9 +35,10 @@ if (empty($row) || empty($row['physical_filename'])) { bb_simple_die($lang['INVALID_TOPIC_ID_DB'], 404); } -if (empty($row['info_hash_v2'])) { - bb_simple_die($lang['BT_V2_FLIST_ONLY'], 410); -} +// Method fields +$t_version_field = !empty($row['info_hash_v2']) ? 'v2' : 'v1'; +$t_files_field = ($t_version_field === 'v2') ? 'getFileTree' : 'getFiles'; +$t_hash_field = ($t_version_field === 'v2') ? 'piecesRoot' : 'sha1'; $file_path = get_attachments_dir() . '/' . $row['physical_filename']; @@ -48,32 +49,44 @@ if (!is_file($file_path)) { $file_contents = file_get_contents($file_path); if ($bb_cfg['flist_max_files']) { - $filetree_pos = strpos($file_contents, '9:file tree'); + $filetree_pos = !empty($row['info_hash_v2']) ? strpos($file_contents, '9:file tree') : false; $files_pos = !empty($row['info_hash']) ? strpos($file_contents, '5:files', $filetree_pos) : false; - $file_count = substr_count($file_contents, '6:length', $filetree_pos, ($files_pos ? ($files_pos - $filetree_pos) : null)); + + if ($filetree_pos) { + $file_count = substr_count($file_contents, '6:length', $filetree_pos, ($files_pos ? ($files_pos - $filetree_pos) : null)); + } + else { + $file_count = substr_count($file_contents, '6:length', $files_pos); + } if ($file_count > $bb_cfg['flist_max_files']) { - bb_simple_die(sprintf($lang['BT_V2_FLIST_LIMIT'], $bb_cfg['flist_max_files'], $file_count), 410); + bb_simple_die(sprintf($lang['BT_FLIST_LIMIT'], $bb_cfg['flist_max_files'], $file_count), 410); } } try { - $torrent = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY); + $torrent = \Arokettu\Torrent\TorrentFile::loadFromString($file_contents); } catch (\Exception $e) { bb_simple_die(htmlCHR("{$lang['TORFILE_INVALID']}: {$e->getMessage()}"), 410); } -if (isset($torrent['info']['private']) && IS_GUEST) { +if ($torrent->isPrivate() && IS_GUEST) { bb_simple_die($lang['BT_PRIVATE_TORRENT'], 403); } -$files = (new TorrentPier\Legacy\TorrentFileList($torrent))->fileTreeTable($torrent['info']['file tree']); +$files = $torrent->$t_version_field()->$t_files_field(); + +$allFiles = ''; +foreach ($files as $file) { + $allFiles .= '
Path ({$files['count']} files) | +Path ({$data['file_count']} files) | Size | BTMR hash @@ -186,15 +199,12 @@ sup { |
---|
Generated by TorrentPier