diff --git a/bt/announce.php b/bt/announce.php index 2a2a42fb0..c40e72bf4 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -65,6 +65,15 @@ if (strlen($peer_id) !== 20) { msg_die('Invalid peer_id: ' . $peer_id); } +// Check for client ban +if ($bb_cfg['client_ban']['enabled']) { + foreach (array_keys($bb_cfg['client_ban']['clients']) as $client) { + if (str_starts_with($peer_id, $client)) { + msg_die($bb_cfg['client_ban']['clients'][$client]); + } + } +} + // Verify info_hash if (!isset($info_hash)) { msg_die('info_hash was not provided'); @@ -102,8 +111,7 @@ $ip = $_SERVER['REMOTE_ADDR']; 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)) { + } 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)) { @@ -243,8 +251,7 @@ if ($lp_info) { if ($row = DB()->fetch_row($sql)) { if ($seeder && $bb_cfg['tracker']['limit_seed_count'] && $row['active_torrents'] >= $bb_cfg['tracker']['limit_seed_count']) { msg_die('Only ' . $bb_cfg['tracker']['limit_seed_count'] . ' torrent(s) allowed for seeding'); - } - elseif (!$seeder && $bb_cfg['tracker']['limit_leech_count'] && $row['active_torrents'] >= $bb_cfg['tracker']['limit_leech_count']) { + } elseif (!$seeder && $bb_cfg['tracker']['limit_leech_count'] && $row['active_torrents'] >= $bb_cfg['tracker']['limit_leech_count']) { msg_die('Only ' . $bb_cfg['tracker']['limit_leech_count'] . ' torrent(s) allowed for leeching' . $rating_msg); } } @@ -267,8 +274,7 @@ if ($lp_info) { if ($row = DB()->fetch_row($sql)) { if ($seeder && $bb_cfg['tracker']['limit_seed_ips'] && $row['ips'] >= $bb_cfg['tracker']['limit_seed_ips']) { msg_die('You can seed only from ' . $bb_cfg['tracker']['limit_seed_ips'] . " IP's"); - } - elseif (!$seeder && $bb_cfg['tracker']['limit_leech_ips'] && $row['ips'] >= $bb_cfg['tracker']['limit_leech_ips']) { + } elseif (!$seeder && $bb_cfg['tracker']['limit_leech_ips'] && $row['ips'] >= $bb_cfg['tracker']['limit_leech_ips']) { msg_die('You can leech only from ' . $bb_cfg['tracker']['limit_leech_ips'] . " IP's"); } } @@ -352,7 +358,7 @@ if ((!$lp_info || !$peer_info_updated) && !$stopped && empty($hybrid_unrecord)) // Exit if stopped if ($stopped) { - silent_exit('Cache will be reset within 30 seconds'); + dummy_exit(); } // Store peer info in cache @@ -462,7 +468,6 @@ if (!$output) { } $output['external ip'] = inet_pton($ip); -$output['warning message'] = 'Statistics were updated'; // Return data to client echo \Arokettu\Bencode\Bencode::encode($output); diff --git a/bt/includes/init_tr.php b/bt/includes/init_tr.php index 08331237a..02a964b88 100644 --- a/bt/includes/init_tr.php +++ b/bt/includes/init_tr.php @@ -69,7 +69,6 @@ function dummy_exit($interval = 1800, $cache_dict = []) $output['complete'] = $cache_dict['complete']; $output['incomplete'] = $cache_dict['incomplete']; $output['downloaded'] = $cache_dict['downloaded']; - $output['warning message'] = 'Next statistics update in: ' . (floor($interval / 60) % 60) . ' minutes'; } if (isset($cache_dict['peers'])) { diff --git a/library/config.php b/library/config.php index 2f1eca8ad..4ef5af87e 100644 --- a/library/config.php +++ b/library/config.php @@ -101,6 +101,16 @@ $bb_cfg['passkey_key'] = 'uk'; // Passkey key name in GET request $bb_cfg['ignore_reported_ip'] = false; // Ignore IP reported by client $bb_cfg['verify_reported_ip'] = true; // Verify IP reported by client against $_SERVER['HTTP_X_FORWARDED_FOR'] $bb_cfg['allow_internal_ip'] = false; // Allow internal IP (10.xx.. etc.) +$bb_cfg['client_ban'] = [ + 'enabled' => false, + // Clients to be blocked, for example, peer id '-UT' will block all uTorrent clients, '-UT2' will block builds starting with 2 (default: false) + // The second argument is being shown in the torrent client as a failure message + // Handy client list: https://github.com/transmission/transmission/blob/f85c3b6f8db95d5363f6ec38eee603f146c6adb6/libtransmission/clients.cc#L504 + 'clients' => [ + '-UT' => "uTorrent — NOT ad-free and open-source", + '-MG' => 'Mostly leeching client' + ] +]; // Ocelot $bb_cfg['ocelot'] = [ @@ -670,7 +680,8 @@ $bb_cfg['tracker'] = [ 'search_by_tor_status' => true, 'freeleech' => false, // freeleech mode (If enabled, then disable "gold_silver_enabled") 'gold_silver_enabled' => true, // golden / silver days mode (If enabled, then disable "freeleech") - 'disabled_v2_torrents' => false // allow registration of v2-only torrents + 'disabled_v1_torrents' => false, // disallow registration of v1-only torrents, for future implementations where client will use v2 only and there won't be need for v1, relieving tracker + 'disabled_v2_torrents' => false // disallow registration of v2-only torrents ]; // Ratio settings diff --git a/library/language/source/main.php b/library/language/source/main.php index 30c122a55..c5c5694c8 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -1072,6 +1072,7 @@ $lang['BT_ADDED'] = 'Added'; $lang['BT_REG_ON_TRACKER'] = 'Register on tracker'; $lang['BT_REG_FAIL'] = 'Could not register torrent on tracker'; $lang['BT_REG_FAIL_SAME_HASH'] = 'Another torrent with same info_hash already registered'; +$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_FILE_LIST_ONLY'] = 'Currently, only torrents with BitTorrent version 2 support are enabled for separate file listing'; $lang['BT_UNREG_FROM_TRACKER'] = 'Remove from tracker'; diff --git a/src/Legacy/Torrent.php b/src/Legacy/Torrent.php index 3ff44d61f..6b3bb5499 100644 --- a/src/Legacy/Torrent.php +++ b/src/Legacy/Torrent.php @@ -349,15 +349,21 @@ class Torrent } // Check if torrent contains info_hash v2 or v1 - if (($info['meta version'] ?? null) == 2) { - if (is_array($info['file tree'] ?? null)) { + if (isset($info['meta version'], $info['file tree'])) { + if ($info['meta version'] === 2 && is_array($info['file tree'])) { $bt_v2 = true; } } + if (isset($info['pieces'])) { $bt_v1 = true; } - if ($bb_cfg['tracker']['disabled_v2_torrents'] && isset($bt_v2) && !isset($bt_v1)) { + + if ($bb_cfg['tracker']['disabled_v1_torrents'] && isset($bt_v1) && !isset($bt_v2)) { + self::torrent_error_exit($lang['BT_V1_ONLY_DISALLOWED']); + } + + if ($bb_cfg['tracker']['disabled_v2_torrents'] && !isset($bt_v1) && isset($bt_v2)) { self::torrent_error_exit($lang['BT_V2_ONLY_DISALLOWED']); }