diff --git a/library/ajax/passkey.php b/library/ajax/passkey.php index cfb7f78f4..4974720f4 100644 --- a/library/ajax/passkey.php +++ b/library/ajax/passkey.php @@ -18,10 +18,8 @@ $mode = (string)$this->request['mode']; if ($req_uid == $userdata['user_id'] || IS_ADMIN) { switch ($mode) { - case 'create': - $first_creation = !\TorrentPier\Legacy\Torrent::getPasskey($req_uid); - - if (empty($this->request['confirmed']) && !$first_creation) { + case 'generate': + if (empty($this->request['confirmed'])) { $this->prompt_for_confirm($lang['BT_GEN_PASSKEY_NEW']); } @@ -31,20 +29,8 @@ if ($req_uid == $userdata['user_id'] || IS_ADMIN) { \TorrentPier\Legacy\Torrent::tracker_rm_user($req_uid); - $this->response['first_creation'] = $first_creation; $this->response['passkey'] = $passkey; break; - case 'remove': - if (empty($this->request['confirmed'])) { - $this->prompt_for_confirm($lang['QUESTION']); - } - - if (!$delete = \TorrentPier\Legacy\Torrent::deletePasskey($req_uid)) { - $this->ajax_die('Could not remove passkey'); - } - - $this->response['passkey_removed'] = $delete; - break; default: $this->ajax_die('Invalid mode'); } diff --git a/library/attach_mod/displaying_torrent.php b/library/attach_mod/displaying_torrent.php index 9ca1548dd..671e1fe5d 100644 --- a/library/attach_mod/displaying_torrent.php +++ b/library/attach_mod/displaying_torrent.php @@ -13,21 +13,6 @@ if (!defined('BB_ROOT')) { global $bb_cfg, $t_data, $poster_id, $is_auth, $dl_link_css, $dl_status_css, $lang, $images; -$bt_user_id = $userdata['user_id']; -$bt_topic_id = $t_data['topic_id']; - -$user_passkey = \TorrentPier\Legacy\Torrent::getPasskey($bt_user_id); - -if (!$user_passkey) { - $template->assign_block_vars('postrow.attach.tor_reged', array()); - $template->assign_vars(array( - 'TOR_BLOCKED' => true, - 'TOR_BLOCKED_MSG' => $lang['PASSKEY_ALERT_INFO'], - )); - - return; -} - $change_peers_bgr_over = true; $bgr_class_1 = 'row1'; $bgr_class_2 = 'row2'; @@ -73,6 +58,8 @@ if ($bb_cfg['bt_allow_spmode_change']) { } } +$bt_topic_id = $t_data['topic_id']; +$bt_user_id = $userdata['user_id']; $attach_id = $attachments['_' . $post_id][$i]['attach_id']; $tracker_status = $attachments['_' . $post_id][$i]['tracker_status']; $download_count = $attachments['_' . $post_id][$i]['download_count']; @@ -155,6 +142,7 @@ if ($tor_reged && $tor_info) { $tor_type = $tor_info['tor_type']; // Magnet link + $user_passkey = \TorrentPier\Legacy\Torrent::getPasskey($bt_user_id); $tor_magnet = create_magnet($tor_info['info_hash'], $tor_info['info_hash_v2'], $user_passkey); // ratio limits @@ -181,7 +169,7 @@ if ($tor_reged && $tor_info) { $user_status = $bt_userdata['user_status'] ?? null; - if (($min_ratio_dl || $min_ratio_warn) && $user_status != DL_STATUS_COMPLETE && $bt_user_id != $poster_id && $tor_type != TOR_TYPE_GOLD) { + if (($min_ratio_dl || $min_ratio_warn) && $user_status != DL_STATUS_COMPLETE && ($bt_user_id != ($poster_id || GUEST_UID)) && $tor_type != TOR_TYPE_GOLD) { if (($user_ratio = get_bt_ratio($bt_userdata)) !== null) { $dl_allowed = ($user_ratio > $min_ratio_dl); } diff --git a/library/config.php b/library/config.php index 2be18c1c4..b7cdd5b51 100644 --- a/library/config.php +++ b/library/config.php @@ -372,7 +372,6 @@ $bb_cfg['last_visit_update_intrv'] = 3600; // sec $bb_cfg['invalid_logins'] = 5; // Количество неверных попыток ввода пароля, перед выводом проверки капчей $bb_cfg['new_user_reg_disabled'] = false; // Запретить регистрацию новых учетных записей $bb_cfg['unique_ip'] = false; // Запретить регистрацию нескольких учетных записей с одного ip -$bb_cfg['auto_gen_passkey'] = true; // Генерировать passkey автоматически при регистрации $bb_cfg['new_user_reg_restricted'] = false; // Ограничить регистрацию новых пользователей по времени по указанному ниже интервалу $bb_cfg['new_user_reg_interval'] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]; // Допустимые часы регистрации $bb_cfg['reg_email_activation'] = true; // Требовать активацию учетной записи по email diff --git a/library/includes/functions.php b/library/includes/functions.php index 451c7cb56..fec7ce425 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -799,10 +799,6 @@ function generate_user_info($row, bool $group_mod = false): array function get_bt_userdata($user_id) { - if (!\TorrentPier\Legacy\Torrent::getPasskey($user_id)) { - return false; - } - if (!$btu = CACHE('bb_cache')->get('btu_' . $user_id)) { $btu = DB()->fetch_row(" SELECT bt.*, SUM(tr.speed_up) AS speed_up, SUM(tr.speed_down) AS speed_down @@ -1761,11 +1757,11 @@ function decode_text_match($txt) * * @param string $infohash * @param string $infohash_v2 - * @param string|bool $auth_key + * @param string $auth_key * * @return string */ -function create_magnet(string $infohash, string $infohash_v2, $auth_key): string +function create_magnet(string $infohash, string $infohash_v2, string $auth_key): string { global $bb_cfg, $images; @@ -1774,11 +1770,6 @@ function create_magnet(string $infohash, string $infohash_v2, $auth_key): string return false; } - // Hasn't passkey - if (!$auth_key) { - return false; - } - return ''; } diff --git a/library/includes/page_header.php b/library/includes/page_header.php index 33b3bbada..555292c6b 100644 --- a/library/includes/page_header.php +++ b/library/includes/page_header.php @@ -122,7 +122,6 @@ $template->assign_vars(array( 'USER_OPTIONS_JS' => (IS_GUEST) ? '{}' : json_encode($user->opt_js, JSON_THROW_ON_ERROR), 'USE_TABLESORTER' => !empty($page_cfg['use_tablesorter']), - 'NEED_GEN_PASSKEY' => (!IS_GUEST && !\TorrentPier\Legacy\Torrent::getPasskey($userdata['user_id'])), 'SITENAME' => $bb_cfg['sitename'], 'U_INDEX' => BB_ROOT . "index.php", diff --git a/library/includes/torrent_show_dl_list.php b/library/includes/torrent_show_dl_list.php index 52422c608..1370ef1aa 100644 --- a/library/includes/torrent_show_dl_list.php +++ b/library/includes/torrent_show_dl_list.php @@ -25,7 +25,7 @@ $count_mode = ($bb_cfg['bt_dl_list_only_count'] && !(@$_GET['dl'] === 'names')); $dl_topic = ($t_data['topic_dl_type'] == TOPIC_DL_TYPE_DL && !($bb_cfg['bt_dl_list_only_1st_page'] && $start)); $show_dl_list = ($dl_topic && ($bb_cfg['bt_show_dl_list'] || ($bb_cfg['allow_dl_list_names_mode'] && @$_GET['dl'] === 'names'))); -$show_dl_buttons = ($dl_topic && $bb_cfg['bt_show_dl_list_buttons']); +$show_dl_buttons = (!IS_GUEST && $dl_topic && $bb_cfg['bt_show_dl_list_buttons']); // link to clear DL-List $template->assign_vars(array('S_DL_DELETE' => false)); diff --git a/library/includes/ucp/register.php b/library/includes/ucp/register.php index c6f3b061b..ff6d383db 100644 --- a/library/includes/ucp/register.php +++ b/library/includes/ucp/register.php @@ -550,13 +550,6 @@ if ($submit && !$errors) { DB()->query("INSERT INTO " . BB_USERS . $sql_args); $new_user_id = DB()->sql_nextid(); - // Auto generate passkey - if ($bb_cfg['auto_gen_passkey']) { - if (!\TorrentPier\Legacy\Torrent::generate_passkey($new_user_id, true)) { - bb_die('Could not generate passkey'); - } - } - if (IS_ADMIN) { set_pr_die_append_msg($new_user_id); $message = $lang['ACCOUNT_ADDED']; diff --git a/library/language/source/main.php b/library/language/source/main.php index eabc58adc..1f406fa9c 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -1069,8 +1069,6 @@ $lang['BT_GEN_PASSKEY'] = 'create a new'; $lang['BT_PASSKEY_VIEW'] = 'show'; $lang['BT_GEN_PASSKEY_NEW'] = "Attention! After changing the new passkey, you will need to re-download all the active torrents! \n Are you sure you want to create a new passkey?"; $lang['BT_NO_SEARCHABLE_FORUMS'] = 'No searchable forums found'; -$lang['PASSKEY_ALERT_TITLE'] = 'Creating a passkey'; -$lang['PASSKEY_ALERT_INFO'] = 'To use the tracker functionality, you need to create a passkey.'; $lang['SEEDS'] = 'Seed'; $lang['LEECHS'] = 'Leech'; diff --git a/src/Legacy/Common/User.php b/src/Legacy/Common/User.php index 62b9add93..16ededb71 100644 --- a/src/Legacy/Common/User.php +++ b/src/Legacy/Common/User.php @@ -250,6 +250,13 @@ class User } } + // Generate passkey + if (!\TorrentPier\Legacy\Torrent::getPasskey($this->data['user_id'])) { + if (!\TorrentPier\Legacy\Torrent::generate_passkey($this->data['user_id'], true)) { + bb_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 aeb956854..c082b7a67 100644 --- a/src/Legacy/Torrent.php +++ b/src/Legacy/Torrent.php @@ -769,15 +769,4 @@ class Torrent return false; } - - /** - * Removes user passkey, false otherwise - * - * @param int|string $user_id - * @return bool - */ - public static function deletePasskey($user_id): bool - { - return (bool)DB()->query("DELETE FROM " . BB_BT_USERS . " WHERE user_id = " . (int)$user_id); - } } diff --git a/styles/templates/default/page_header.tpl b/styles/templates/default/page_header.tpl index 56e1053a8..b008263b1 100644 --- a/styles/templates/default/page_header.tpl +++ b/styles/templates/default/page_header.tpl @@ -470,22 +470,6 @@ $(document).ready(function() {
- - - -
-

{L_PASSKEY_ALERT_TITLE}

-
- {L_PASSKEY_ALERT_INFO} - {L_BT_GEN_PASSKEY} -
-
diff --git a/styles/templates/default/usercp_viewprofile.tpl b/styles/templates/default/usercp_viewprofile.tpl index 9a0596422..38acc9144 100644 --- a/styles/templates/default/usercp_viewprofile.tpl +++ b/styles/templates/default/usercp_viewprofile.tpl @@ -166,14 +166,10 @@ ajax.callback.index_data = function(data) { - + @@ -401,7 +397,7 @@ ajax.callback.index_data = function(data) { [ {L_BT_PASSKEY}: {L_BT_PASSKEY_VIEW} ] diff --git a/viewforum.php b/viewforum.php index f4d7a8898..29878c354 100644 --- a/viewforum.php +++ b/viewforum.php @@ -470,7 +470,7 @@ foreach ($topic_rowset as $topic) { )); if (isset($topic['tor_size'])) { - $tor_magnet = create_magnet($topic['info_hash'], $topic['info_hash_v2'], ($topic['auth_key'] ?? false)); + $tor_magnet = create_magnet($topic['info_hash'], $topic['info_hash_v2'], $topic['auth_key']); $template->assign_block_vars('t.tor', array( 'SEEDERS' => (int)$topic['seeders'],