diff --git a/bt/announce.php b/bt/announce.php index 93f60fd66..bd60278f8 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -26,14 +26,11 @@ if (isset($_GET['?info_hash']) && !isset($_GET['info_hash'])) { $_GET['info_hash'] = $_GET['?info_hash']; } -$is_bt_v2 = null; -$is_hybrid = $hybrid_v1_hash = $hybrid_v2_hash = $hybrid_tor_update = false; - // Initial request verification if (strpos($_SERVER['REQUEST_URI'], 'scrape') !== false) { msg_die('Please disable SCRAPE!'); } -if (!isset($_GET[$passkey_key]) || !is_string($_GET[$passkey_key]) || strlen($_GET[$passkey_key]) != BT_AUTH_KEY_LENGTH) { +if (!isset($_GET[$passkey_key]) || !is_string($_GET[$passkey_key]) || strlen($_GET[$passkey_key]) !== BT_AUTH_KEY_LENGTH) { msg_die('Please LOG IN and RE-DOWNLOAD this torrent (passkey not found)'); } @@ -60,7 +57,7 @@ $passkey = $$passkey_key ?? null; if (!isset($peer_id)) { msg_die('peer_id was not provided'); } -if (strlen($peer_id) != 20) { +if (strlen($peer_id) !== 20) { msg_die('Invalid peer_id: ' . bin2hex($peer_id)); } @@ -73,9 +70,9 @@ if (!isset($info_hash)) { $info_hash_hex = bin2hex($info_hash); // Check info_hash version -if (strlen($info_hash) == 32) { +if (strlen($info_hash) === 32) { $is_bt_v2 = true; -} elseif (strlen($info_hash) == 20) { +} elseif (strlen($info_hash) === 20) { $is_bt_v2 = false; } else { msg_die('Invalid info_hash: ' . $info_hash_hex); @@ -125,8 +122,7 @@ if (!\TorrentPier\Helpers\IPHelper::isValid($ip)) { $ip_sql = \TorrentPier\Helpers\IPHelper::ip2long($ip); // Peer unique id -$peer_hash = md5(rtrim($info_hash, ' ') . $passkey . $ip . $port); - +$peer_hash = hash('xxh128', rtrim($info_hash, ' ') . $passkey . $ip . $port); // Events $stopped = ($event === 'stopped'); @@ -300,7 +296,7 @@ if ($bb_cfg['tracker']['freeleech'] && $down_add) { // Insert / update peer info $peer_info_updated = false; $update_time = ($stopped) ? 0 : TIMENOW; -if (($is_hybrid && $hybrid_tor_update) || !$is_hybrid) { // Update statistics only for one topic +if (isset($is_hybrid, $hybrid_tor_update) || !isset($is_hybrid)) { // Update statistics only for one topic if ($lp_info) { $sql = "UPDATE " . BB_BT_TRACKER . " SET update_time = $update_time"; @@ -408,11 +404,11 @@ if (!$output) { 'complete' => (int)$seeders, 'incomplete' => (int)$leechers, 'downloaded' => (int)$client_completed, - 'warning message' => 'Statistics were updated', 'peers' => $peers, ]; $peers_list_cached = CACHE('tr_cache')->set(PEERS_LIST_PREFIX . $topic_id, $output, PEERS_LIST_EXPIRE); + $output['warning message'] = 'Statistics were updated'; } // Return data to client diff --git a/index.php b/index.php index eb10bf754..2f1fc1f24 100644 --- a/index.php +++ b/index.php @@ -131,7 +131,7 @@ $replace_in_parent = [ 'last_topic_id' ]; -$cache_name = 'index_sql_' . md5($sql); +$cache_name = 'index_sql_' . hash('xxh128', $sql); if (!$cat_forums = CACHE('bb_cache')->get($cache_name)) { $cat_forums = []; foreach (DB()->fetch_rowset($sql) as $row) { diff --git a/src/Legacy/Template.php b/src/Legacy/Template.php index 399b10ae5..ca028202e 100644 --- a/src/Legacy/Template.php +++ b/src/Legacy/Template.php @@ -684,7 +684,7 @@ class Template continue; } $line = '<' . '?php '; - $filehash = md5($params_str . $this->include_count . TIMENOW); + $filehash = hash('xxh128', $params_str . $this->include_count . TIMENOW); $line .= ' $this->set_filename(\'xs_include_' . $filehash . '\', \'' . $params_str . '\', true); '; $line .= ' $this->pparse(\'xs_include_' . $filehash . '\'); '; $line .= ' ?' . '>'; diff --git a/src/Legacy/Torrent.php b/src/Legacy/Torrent.php index 91dfa8a89..5a90f6f63 100644 --- a/src/Legacy/Torrent.php +++ b/src/Legacy/Torrent.php @@ -362,7 +362,7 @@ class Torrent // Getting info_hash v1 if ($bt_v1) { - $info_hash = pack('H*', sha1(\SandFox\Bencode\Bencode::encode($info))); + $info_hash = pack('H*', hash('sha1', \SandFox\Bencode\Bencode::encode($info))); $info_hash_sql = rtrim(DB()->escape($info_hash), ' '); $info_hash_where = "WHERE info_hash = '$info_hash_sql'"; }