Minor improvements (#868)

* Minor improvements

* Update viewforum.php

* Updated
This commit is contained in:
Roman Kelesidis 2023-08-27 20:05:27 +07:00 committed by GitHub
commit 9b43d144a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 20 additions and 90 deletions

View file

@ -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');
}

View file

@ -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);
}

View file

@ -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

View file

@ -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 '<a href="magnet:?xt=urn:btih:' . bin2hex($infohash) . (!empty($infohash_v2) ? '&xt=urn:btmh:1220' . bin2hex($infohash_v2) : '') . '&tr=' . urlencode($bb_cfg['bt_announce_url'] . "?{$bb_cfg['passkey_key']}=$auth_key") . '"><img src="' . $images['icon_magnet'] . '" width="12" height="12" border="0" /></a>';
}

View file

@ -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",

View file

@ -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));

View file

@ -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'];

View file

@ -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';

View file

@ -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);

View file

@ -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);
}
}

View file

@ -470,22 +470,6 @@ $(document).ready(function() {
<!--main_content-->
<td id="main_content">
<div id="main_content_wrap">
<!-- IF NEED_GEN_PASSKEY -->
<script type="text/javascript">
ajax.callback.passkey = function (data) {
if (data.first_creation) {
window.location.reload();
}
};
</script>
<div class="alert alert-info" style="width: 95%;">
<h4 class="alert-heading">{L_PASSKEY_ALERT_TITLE}</h4>
<hr>
{L_PASSKEY_ALERT_INFO}
<a href="#" onclick="ajax.exec({ action: 'passkey', mode: 'create', user_id: {SESSION_USER_ID} }); return false;">{L_BT_GEN_PASSKEY}</a>
</div>
<!-- ENDIF -->
<div id="latest_news">
<table cellspacing="0" cellpadding="0" width="100%">
<tr>

View file

@ -166,14 +166,10 @@ ajax.callback.index_data = function(data) {
</script>
<!-- ENDIF -->
<!-- IF SHOW_PASSKEY && not NEED_GEN_PASSKEY -->
<!-- IF SHOW_PASSKEY -->
<script type="text/javascript">
ajax.callback.passkey = function (data) {
if (data.first_creation || data.passkey_removed) {
window.location.reload();
} else if (data.passkey) {
$('#passkey').text(data.passkey);
}
$('#passkey').text(data.passkey);
};
</script>
<!-- ENDIF / SHOW_PASSKEY -->
@ -401,7 +397,7 @@ ajax.callback.index_data = function(data) {
<!-- IF SHOW_PASSKEY -->
[ {L_BT_PASSKEY}: <span id="passkey-btn"><a class="med" href="#" onclick="$('#passkey-gen').show(); $('#passkey-btn').hide(); return false;">{L_BT_PASSKEY_VIEW}</a></span>
<span id="passkey-gen" class="med" style="display: none;">
<!-- IF AUTH_KEY --><b id="passkey" class="med bold">{AUTH_KEY}</b>&nbsp;|&nbsp;<a href="#" onclick="ajax.exec({ action: 'passkey', mode: 'remove', user_id : {PROFILE_USER_ID} }); return false;">{L_REMOVE}</a>&nbsp;&middot;&nbsp;<!-- ENDIF --><a href="#" onclick="ajax.exec({ action: 'passkey', mode: 'create', user_id : {PROFILE_USER_ID} }); return false;">{L_BT_GEN_PASSKEY}</a>
<b id="passkey" class="med bold">{AUTH_KEY}</b>&nbsp;|&nbsp;<a href="#" onclick="ajax.exec({ action: 'passkey', mode: 'generate', user_id : {PROFILE_USER_ID} }); return false;">{L_BT_GEN_PASSKEY}</a>
</span> ]
<!-- ENDIF -->
</td>

View file

@ -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'],