diff --git a/CHANGELOG.md b/CHANGELOG.md index b433df278..274c544b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ - Invites: Permanent invites feature [\#1670](https://github.com/torrentpier/torrentpier/pull/1670) ([belomaxorka](https://github.com/belomaxorka)) - Demo mode: Save user language in cookies [\#1584](https://github.com/torrentpier/torrentpier/pull/1584) ([belomaxorka](https://github.com/belomaxorka)) - BBCode: Fixed relative links working [\#1613](https://github.com/torrentpier/torrentpier/pull/1613) ([belomaxorka](https://github.com/belomaxorka)) -- Fixed broken torrent stats displaying [\#1672](https://github.com/torrentpier/torrentpier/pull/1672) ([belomaxorka](https://github.com/belomaxorka)) +- Fixed broken torrent stats displaying [\#1672](https://github.com/torrentpier/torrentpier/pull/1672), [\#1673](https://github.com/torrentpier/torrentpier/pull/1673) ([belomaxorka](https://github.com/belomaxorka)) - Fixed incorrect page width on mobile devices [\#1653](https://github.com/torrentpier/torrentpier/pull/1653) ([belomaxorka](https://github.com/belomaxorka)) - Fixed template caching issue [\#1622](https://github.com/torrentpier/torrentpier/pull/1622) ([belomaxorka](https://github.com/belomaxorka)) - Fixed `md5()` deprecated in PHP 8.4 [\#1561](https://github.com/torrentpier/torrentpier/pull/1561) ([belomaxorka](https://github.com/belomaxorka)) diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index 641cc131d..88cdfdfc1 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -434,6 +434,10 @@ CREATE TABLE IF NOT EXISTS `bb_bt_users` -- ---------------------------- -- Records of bb_bt_users -- ---------------------------- +INSERT INTO `bb_bt_users` (user_id, auth_key) +VALUES ('-1', SUBSTRING(MD5(RAND()), 1, 20)), + ('-746', SUBSTRING(MD5(RAND()), 1, 20)), + ('2', SUBSTRING(MD5(RAND()), 1, 20)); -- ---------------------------- -- Table structure for `bb_bt_user_settings` diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index 6ee61734d..b8cd9cd15 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -268,6 +268,7 @@ define('BB_WORDS', 'bb_words'); define('BB_THX', 'bb_thx'); define('TORRENT_EXT', 'torrent'); +define('TORRENT_MIMETYPE', 'application/x-bittorrent'); define('TOPIC_DL_TYPE_NORMAL', 0); define('TOPIC_DL_TYPE_DL', 1); diff --git a/library/includes/ucp/register.php b/library/includes/ucp/register.php index 372df7dff..7c306af84 100644 --- a/library/includes/ucp/register.php +++ b/library/includes/ucp/register.php @@ -605,6 +605,16 @@ if ($submit && !$errors) { DB()->query("INSERT INTO " . BB_USERS . $sql_args); $new_user_id = DB()->sql_nextid(); + // Generate passkey + for ($i = 0, $max_try = 3; $i <= $max_try; $i++) { + if (\TorrentPier\Legacy\Torrent::generate_passkey($new_user_id, true)) { + break; + } + if ($i == $max_try) { + bb_simple_die('Could not generate passkey'); + } + } + if (IS_ADMIN) { set_pr_die_append_msg($new_user_id); $message = $lang['ACCOUNT_ADDED']; diff --git a/src/Legacy/Attach.php b/src/Legacy/Attach.php index 6ac6bea2b..ffd46e160 100644 --- a/src/Legacy/Attach.php +++ b/src/Legacy/Attach.php @@ -569,7 +569,7 @@ class Attach } } else { if (empty($this->attachment_mimetype_list[$i]) && $this->attachment_extension_list[$i] === TORRENT_EXT) { - $this->attachment_mimetype_list[$i] = 'application/x-bittorrent'; + $this->attachment_mimetype_list[$i] = TORRENT_MIMETYPE; } // insert attachment into db diff --git a/src/Legacy/Common/User.php b/src/Legacy/Common/User.php index 33efa5cb2..678a7f905 100644 --- a/src/Legacy/Common/User.php +++ b/src/Legacy/Common/User.php @@ -10,7 +10,6 @@ namespace TorrentPier\Legacy\Common; use TorrentPier\Legacy\DateDelta; -use TorrentPier\Legacy\Torrent; use TorrentPier\Sessions; use Exception; @@ -253,13 +252,6 @@ class User $user_id = (int)$this->data['user_id']; $mod_admin_session = ((int)$this->data['user_level'] === ADMIN || (int)$this->data['user_level'] === MOD); - // Generate passkey - if (!Torrent::getPasskey($this->data['user_id'])) { - if (!Torrent::generate_passkey($this->data['user_id'], true)) { - bb_simple_die('Could not generate passkey'); - } - } - // Create new session for ($i = 0, $max_try = 5; $i <= $max_try; $i++) { $session_id = make_rand_str(SID_LENGTH); diff --git a/src/Legacy/Torrent.php b/src/Legacy/Torrent.php index 8a832a2be..6d0b5cf49 100644 --- a/src/Legacy/Torrent.php +++ b/src/Legacy/Torrent.php @@ -671,7 +671,7 @@ class Torrent bb_die("
$out"); } - header("Content-Type: application/x-bittorrent; name=\"$dl_fname\""); + header("Content-Type: " . TORRENT_MIMETYPE . "; name=\"$dl_fname\""); header("Content-Disposition: attachment; filename=\"$dl_fname\""); exit($output); @@ -866,10 +866,6 @@ class Torrent */ public static function getPasskey(int|string $user_id): bool|string { - if ($passkey = DB()->fetch_row("SELECT auth_key FROM " . BB_BT_USERS . " WHERE user_id = " . (int)$user_id . " LIMIT 1")) { - return $passkey['auth_key']; - } - - return false; + return get_bt_userdata($user_id)['auth_key']; } } diff --git a/src/TorrServerAPI.php b/src/TorrServerAPI.php index bc5ccf008..884a0e653 100644 --- a/src/TorrServerAPI.php +++ b/src/TorrServerAPI.php @@ -76,7 +76,7 @@ class TorrServerAPI global $bb_cfg; // Check mimetype - if ($mimetype !== 'application/x-bittorrent') { + if ($mimetype !== TORRENT_MIMETYPE) { return false; } diff --git a/styles/templates/default/page_header.tpl b/styles/templates/default/page_header.tpl index ffeae1f90..6cd69b151 100644 --- a/styles/templates/default/page_header.tpl +++ b/styles/templates/default/page_header.tpl @@ -391,7 +391,7 @@ function go_to_page ()