From 2e5b157ede844f6588e0a8de96e2b10de9f08f44 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Wed, 1 Jan 2025 00:21:06 +0700 Subject: [PATCH] =?UTF-8?q?Drop=20Ocelot=20announcer=20support=20?= =?UTF-8?q?=F0=9F=AB=A1=20(#1727)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Drop Ocelot announcer support * Update tr_complete_count.php * Delete ocelot.sql * Update Torrent.php * Update Torrent.php * Update Torrent.php * Update Torrent.php * Update CHANGELOG.md * Update tr_make_snapshot.php * Update tr_make_snapshot.php * Update tr_make_snapshot.php * Update tr_make_snapshot.php --- CHANGELOG.md | 1 + install/sql/ocelot.sql | 57 --------- library/config.php | 10 -- .../includes/cron/jobs/tr_complete_count.php | 43 ------- .../includes/cron/jobs/tr_make_snapshot.php | 63 +++------- src/Legacy/Torrent.php | 115 ++---------------- 6 files changed, 28 insertions(+), 261 deletions(-) delete mode 100644 install/sql/ocelot.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dc1d3c7d..277bf45bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Release 2.4.5 🍧️ ([belomaxorka](https://github.com/belomaxorka)) - Added `TorrentPier instance hash` generation [\#1726](https://github.com/torrentpier/torrentpier/pull/1726) ([belomaxorka](https://github.com/belomaxorka)) - Added `m4a` extension support in M3U playback [\#1724](https://github.com/torrentpier/torrentpier/pull/1724) ([belomaxorka](https://github.com/belomaxorka)) +- Drop Ocelot announcer support 🫡 [\#1727](https://github.com/torrentpier/torrentpier/pull/1727) ([belomaxorka](https://github.com/belomaxorka)) - Show torrent's announcers list in `filelist.php` page [\#1708](https://github.com/torrentpier/torrentpier/pull/1708) ([belomaxorka](https://github.com/belomaxorka)) - [PHP 8.4] Fixed some deprecations [\#1718](https://github.com/torrentpier/torrentpier/pull/1718) ([belomaxorka](https://github.com/belomaxorka)) - [Configurable] Show magnet-links for guests [\#1712](https://github.com/torrentpier/torrentpier/pull/1712) ([belomaxorka](https://github.com/belomaxorka)) diff --git a/install/sql/ocelot.sql b/install/sql/ocelot.sql deleted file mode 100644 index 0502dc3d0..000000000 --- a/install/sql/ocelot.sql +++ /dev/null @@ -1,57 +0,0 @@ -SET SQL_MODE = ""; - --- ---------------------------- --- Table structure for `bb_bt_tracker` --- ---------------------------- -DROP TABLE IF EXISTS `bb_bt_tracker`; -CREATE TABLE IF NOT EXISTS `bb_bt_tracker` -( - `peer_hash` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', - `topic_id` mediumint(8) unsigned NOT NULL DEFAULT '0', - `peer_id` varchar(20) NOT NULL, - `user_id` mediumint(9) NOT NULL DEFAULT '0', - `ip` varchar(42) NOT NULL DEFAULT '0', - `ipv6` varchar(32) DEFAULT NULL, - `port` smallint(5) unsigned NOT NULL DEFAULT '0', - `client` varchar(51) NOT NULL DEFAULT 'Unknown', - `seeder` tinyint(1) NOT NULL DEFAULT '0', - `releaser` tinyint(1) NOT NULL DEFAULT '0', - `tor_type` tinyint(1) NOT NULL DEFAULT '0', - `uploaded` bigint(20) unsigned NOT NULL DEFAULT '0', - `downloaded` bigint(20) unsigned NOT NULL DEFAULT '0', - `remain` bigint(20) unsigned NOT NULL DEFAULT '0', - `speed_up` mediumint(8) unsigned NOT NULL DEFAULT '0', - `speed_down` mediumint(8) unsigned NOT NULL DEFAULT '0', - `up_add` bigint(20) unsigned NOT NULL DEFAULT '0', - `down_add` bigint(20) unsigned NOT NULL DEFAULT '0', - `update_time` int(11) NOT NULL DEFAULT '0', - `complete_percent` bigint(20) NOT NULL DEFAULT '0', - PRIMARY KEY (`peer_hash`), - KEY `topic_id` (`topic_id`), - KEY `user_id` (`user_id`) -) ENGINE = MyISAM - DEFAULT CHARSET = utf8; - --- ---------------------------- --- Records of bb_bt_tracker --- ---------------------------- - --- ---------------------------- --- Table structure for `bb_bt_tracker_snap` --- ---------------------------- -DROP TABLE IF EXISTS `bb_bt_tracker_snap`; -CREATE TABLE IF NOT EXISTS `bb_bt_tracker_snap` -( - `topic_id` mediumint(8) unsigned NOT NULL DEFAULT '0', - `seeders` mediumint(8) unsigned NOT NULL DEFAULT '0', - `leechers` mediumint(8) unsigned NOT NULL DEFAULT '0', - `speed_up` int(10) unsigned NOT NULL DEFAULT '0', - `speed_down` int(10) unsigned NOT NULL DEFAULT '0', - `complete` int(11) NOT NULL DEFAULT '0', - PRIMARY KEY (`topic_id`) -) ENGINE = MyISAM - DEFAULT CHARSET = utf8; - --- ---------------------------- --- Records of bb_bt_tracker_snap --- ---------------------------- diff --git a/library/config.php b/library/config.php index 6ba66bd5c..7c887c51d 100644 --- a/library/config.php +++ b/library/config.php @@ -127,16 +127,6 @@ $bb_cfg['torr_server'] = [ 'disable_for_guest' => true ]; -// Ocelot -$bb_cfg['ocelot'] = [ - 'enabled' => false, - 'host' => $domain_name, - 'port' => 34000, - 'url' => "http://$domain_name:34000/", // with '/' - 'secret' => 'some_10_chars', // 10 chars - 'stats' => 'some_10_chars', // 10 chars -]; - // FAQ url help link $bb_cfg['how_to_download_url_help'] = 'viewtopic.php?t=1'; // How to download? $bb_cfg['what_is_torrent_url_help'] = 'viewtopic.php?t=2'; // What is a torrent? diff --git a/library/includes/cron/jobs/tr_complete_count.php b/library/includes/cron/jobs/tr_complete_count.php index 706b8c98e..ad1867bf7 100644 --- a/library/includes/cron/jobs/tr_complete_count.php +++ b/library/includes/cron/jobs/tr_complete_count.php @@ -11,8 +11,6 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -global $bb_cfg; - // Update TORRENT "completed" counters DB()->query(" UPDATE @@ -23,44 +21,3 @@ DB()->query(" WHERE tor.topic_id = snap.topic_id "); - -/* -if ($bb_cfg['ocelot']['enabled']) { - // Update TORRENT "completed" counters - DB()->query(" - UPDATE - " . BB_BT_TORRENTS . " tor, - " . BB_BT_TRACKER_SNAP . " snap - SET - tor.complete_count = snap.complete - WHERE - tor.topic_id = snap.topic_id - "); -} else { - // Get complete counts - DB()->query(" - CREATE TEMPORARY TABLE tmp_complete_count - SELECT - topic_id, COUNT(*) AS compl_cnt - FROM " . BB_BT_TORSTAT . " - WHERE completed = 0 - GROUP BY topic_id - "); - - // Update USER "completed" counters - DB()->query("UPDATE " . BB_BT_TORSTAT . " SET completed = 1"); - - // Update TORRENT "completed" counters - DB()->query(" - UPDATE - " . BB_BT_TORRENTS . " tor, - tmp_complete_count tmp - SET - tor.complete_count = tor.complete_count + tmp.compl_cnt - WHERE - tor.topic_id = tmp.topic_id - "); - - // Drop tmp table - DB()->query("DROP TEMPORARY TABLE tmp_complete_count"); -}*/ diff --git a/library/includes/cron/jobs/tr_make_snapshot.php b/library/includes/cron/jobs/tr_make_snapshot.php index edf08cbca..6c3a4c74e 100644 --- a/library/includes/cron/jobs/tr_make_snapshot.php +++ b/library/includes/cron/jobs/tr_make_snapshot.php @@ -18,13 +18,11 @@ DB()->expect_slow_query(600); // // Make tracker snapshot // -if (!$bb_cfg['ocelot']['enabled']) { - define('NEW_BB_BT_TRACKER_SNAP', 'new_tracker_snap'); - define('OLD_BB_BT_TRACKER_SNAP', 'old_tracker_snap'); +define('NEW_BB_BT_TRACKER_SNAP', 'new_tracker_snap'); +define('OLD_BB_BT_TRACKER_SNAP', 'old_tracker_snap'); - DB()->query("DROP TABLE IF EXISTS " . NEW_BB_BT_TRACKER_SNAP . ", " . OLD_BB_BT_TRACKER_SNAP); - DB()->query("CREATE TABLE " . NEW_BB_BT_TRACKER_SNAP . " LIKE " . BB_BT_TRACKER_SNAP); -} +DB()->query("DROP TABLE IF EXISTS " . NEW_BB_BT_TRACKER_SNAP . ", " . OLD_BB_BT_TRACKER_SNAP); +DB()->query("CREATE TABLE " . NEW_BB_BT_TRACKER_SNAP . " LIKE " . BB_BT_TRACKER_SNAP); $per_cycle = 50000; $row = DB()->fetch_row("SELECT MIN(topic_id) AS start_id, MAX(topic_id) AS finish_id FROM " . BB_BT_TRACKER); @@ -37,44 +35,25 @@ while (true) { $val = []; - if (!$bb_cfg['ocelot']['enabled']) { - $sql = " - SELECT - topic_id, SUM(seeder) AS seeders, (COUNT(*) - SUM(seeder)) AS leechers, - SUM(speed_up) AS speed_up, SUM(speed_down) AS speed_down, SUM(complete) AS completed - FROM " . BB_BT_TRACKER . " - WHERE topic_id BETWEEN $start_id AND $end_id - GROUP BY topic_id - "; - } else { - $sql = " - SELECT - topic_id, SUM(speed_up) AS speed_up, SUM(speed_down) AS speed_down - FROM " . BB_BT_TRACKER . " - WHERE topic_id BETWEEN $start_id AND $end_id - GROUP BY topic_id - "; - } + $sql = " + SELECT + topic_id, SUM(seeder) AS seeders, (COUNT(*) - SUM(seeder)) AS leechers, + SUM(speed_up) AS speed_up, SUM(speed_down) AS speed_down, SUM(complete) AS completed + FROM " . BB_BT_TRACKER . " + WHERE topic_id BETWEEN $start_id AND $end_id + GROUP BY topic_id + "; foreach (DB()->fetch_rowset($sql) as $row) { $val[] = implode(',', $row); } if ($val) { - if (!$bb_cfg['ocelot']['enabled']) { - DB()->query(" - REPLACE INTO " . NEW_BB_BT_TRACKER_SNAP . " + DB()->query(" + REPLACE INTO " . NEW_BB_BT_TRACKER_SNAP . " (topic_id, seeders, leechers, speed_up, speed_down, completed) - VALUES(" . implode('),(', $val) . ") - "); - } else { - DB()->query(" - INSERT INTO " . BB_BT_TRACKER_SNAP . " - (topic_id, speed_up, speed_down) - VALUES(" . implode('),(', $val) . ") - ON DUPLICATE KEY UPDATE speed_up = VALUES(speed_up), speed_down = VALUES(speed_down) - "); - } + VALUES(" . implode('),(', $val) . ") + "); } if ($end_id > $finish_id) { @@ -84,15 +63,13 @@ while (true) { $start_id += $per_cycle; } -if (!$bb_cfg['ocelot']['enabled']) { - DB()->query(" - RENAME TABLE +DB()->query(" + RENAME TABLE " . BB_BT_TRACKER_SNAP . " TO " . OLD_BB_BT_TRACKER_SNAP . ", " . NEW_BB_BT_TRACKER_SNAP . " TO " . BB_BT_TRACKER_SNAP . " - "); +"); - DB()->query("DROP TABLE IF EXISTS " . NEW_BB_BT_TRACKER_SNAP . ", " . OLD_BB_BT_TRACKER_SNAP); -} +DB()->query("DROP TABLE IF EXISTS " . NEW_BB_BT_TRACKER_SNAP . ", " . OLD_BB_BT_TRACKER_SNAP); // // Make dl-list snapshot diff --git a/src/Legacy/Torrent.php b/src/Legacy/Torrent.php index be0fe9116..e82cad195 100644 --- a/src/Legacy/Torrent.php +++ b/src/Legacy/Torrent.php @@ -160,14 +160,6 @@ class Torrent 'topic_title' => $topic_title, ]); - // Ocelot - if ($bb_cfg['ocelot']['enabled']) { - if ($row = DB()->fetch_row("SELECT info_hash FROM " . BB_BT_TORRENTS . " WHERE attach_id = $attach_id LIMIT 1")) { - $info_hash = $row['info_hash']; - } - self::ocelot_update_tracker('delete_torrent', ['info_hash' => rawurlencode($info_hash), 'id' => $topic_id]); - } - // Delete torrent $sql = "DELETE FROM " . BB_BT_TORRENTS . " WHERE attach_id = $attach_id"; @@ -257,7 +249,7 @@ class Torrent */ public static function change_tor_type($attach_id, $tor_status_gold) { - global $topic_id, $lang, $bb_cfg; + global $topic_id, $lang; if (!$torrent = self::get_torrent_info($attach_id)) { bb_die($lang['TOR_NOT_FOUND']); @@ -269,17 +261,8 @@ class Torrent $topic_id = $torrent['topic_id']; $tor_status_gold = (int)$tor_status_gold; - $info_hash = null; DB()->query("UPDATE " . BB_BT_TORRENTS . " SET tor_type = $tor_status_gold WHERE topic_id = $topic_id"); - - // Ocelot - if ($bb_cfg['ocelot']['enabled']) { - if ($row = DB()->fetch_row("SELECT info_hash FROM " . BB_BT_TORRENTS . " WHERE topic_id = $topic_id LIMIT 1")) { - $info_hash = $row['info_hash']; - } - self::ocelot_update_tracker('update_torrent', ['info_hash' => rawurlencode($info_hash), 'freetorrent' => $tor_status_gold]); - } } /** @@ -412,11 +395,6 @@ class Torrent } } - // Ocelot - if ($bb_cfg['ocelot']['enabled']) { - self::ocelot_update_tracker('add_torrent', ['info_hash' => rawurlencode($info_hash ?? hex2bin(substr($v2_hash, 0, 40))), 'id' => $topic_id, 'freetorrent' => 0]); - } - if ($row = DB()->fetch_row("SELECT topic_id FROM " . BB_BT_TORRENTS . " $info_hash_where LIMIT 1")) { $msg = sprintf($lang['BT_REG_FAIL_SAME_HASH'], TOPIC_URL . $row['topic_id']); bb_die($msg); @@ -562,10 +540,6 @@ class Torrent if ($bt_userdata = get_bt_userdata($user_id)) { $passkey_val = $bt_userdata['auth_key']; - - if ($bb_cfg['ocelot']['enabled']) { - self::ocelot_update_tracker('add_user', ['id' => $user_id, 'passkey' => $passkey_val]); - } } // Ratio limits @@ -596,7 +570,7 @@ class Torrent } // Get tracker announcer - $announce_url = $bb_cfg['ocelot']['enabled'] ? $bb_cfg['ocelot']['url'] . "$passkey_val/announce" : $bb_cfg['bt_announce_url'] . "?$passkey_key=$passkey_val"; + $announce_url = $bb_cfg['bt_announce_url'] . "?$passkey_key=$passkey_val"; // Replace original announce url with tracker default if ($bb_cfg['bt_replace_ann_url'] || !isset($tor['announce'])) { @@ -695,7 +669,7 @@ class Torrent */ public static function generate_passkey($user_id, bool $force_generate = false) { - global $bb_cfg, $lang; + global $lang; $user_id = (int)$user_id; @@ -719,19 +693,13 @@ class Torrent if (!$old_passkey) { // Create first passkey DB()->query("INSERT IGNORE INTO " . BB_BT_USERS . " (user_id, auth_key) VALUES ($user_id, '$passkey_val')"); - if (DB()->affected_rows() == 1) { - return $passkey_val; - } } else { // Update exists passkey DB()->query("UPDATE IGNORE " . BB_BT_USERS . " SET auth_key = '$passkey_val' WHERE user_id = $user_id LIMIT 1"); - if (DB()->affected_rows() == 1) { - // Ocelot - if ($bb_cfg['ocelot']['enabled']) { - self::ocelot_update_tracker('change_passkey', ['oldpasskey' => $old_passkey, 'newpasskey' => $passkey_val]); - } - return $passkey_val; - } + } + + if (DB()->affected_rows() == 1) { + return $passkey_val; } return false; @@ -797,75 +765,6 @@ class Torrent bb_die($msg . $message); } - /** - * Update torrent on Ocelot tracker - * - * @param string $action - * @param array $updates - * - * @return bool - */ - private static function ocelot_update_tracker($action, $updates) - { - global $bb_cfg; - - $get = $bb_cfg['ocelot']['secret'] . "/update?action=$action"; - - foreach ($updates as $key => $value) { - $get .= "&$key=$value"; - } - - $max_attempts = 3; - $err = false; - - return !(self::ocelot_send_request($get, $max_attempts, $err) === false); - } - - /** - * Send request to the Ocelot traker - * - * @param string $get - * @param int $max_attempts - * @param bool $err - * - * @return bool|int - */ - private static function ocelot_send_request($get, $max_attempts = 1, &$err = false) - { - global $bb_cfg; - - $header = "GET /$get HTTP/1.1\r\nConnection: Close\r\n\r\n"; - $attempts = $success = $response = 0; - - while (!$success && $attempts++ < $max_attempts) { - // Send request - $file = fsockopen($bb_cfg['ocelot']['host'], $bb_cfg['ocelot']['port'], $error_num, $error_string); - if ($file) { - if (fwrite($file, $header) === false) { - $err = "Failed to fwrite()"; - continue; - } - } else { - $err = "Failed to fsockopen() - $error_num - $error_string"; - continue; - } - - // Check for response - while (!feof($file)) { - $response .= fread($file, 1024); - } - - $data_end = strrpos($response, "\n"); - $status = substr($response, $data_end + 1); - - if ($status == "success") { - $success = true; - } - } - - return $success; - } - /** * Returns the user passkey, false otherwise *