Passkey rework 🔫 (#839)

* WIP: Passkey rework 🔫

* Update tracker.php

* Update Torrent.php

* Update Torrent.php

* Update displaying_torrent.php

* Update viewforum.php

* Update Torrent.php

* Update functions.php

* Update functions.php

* Updated

* Update config.php

* Update functions.php

* Update usercp_viewprofile.tpl

* Update usercp_viewprofile.tpl

* Updated

* Updated

* Update usercp_viewprofile.tpl

* Update usercp_viewprofile.tpl

* Update displaying_torrent.php
This commit is contained in:
Roman Kelesidis 2023-07-23 23:55:57 +07:00 committed by GitHub
commit 9ba9ca2b61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 88 additions and 52 deletions

View file

@ -795,6 +795,10 @@ 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
@ -805,14 +809,6 @@ function get_bt_userdata($user_id)
LIMIT 1
");
if (empty($btu)) {
if (!\TorrentPier\Legacy\Torrent::generate_passkey($user_id, true)) {
bb_simple_die('Could not generate passkey');
}
$btu = get_bt_userdata($user_id);
}
CACHE('bb_cache')->set('btu_' . $user_id, $btu, 300);
}
@ -831,7 +827,9 @@ function show_bt_userdata($user_id)
{
global $lang, $template;
$btu = get_bt_userdata($user_id);
if (!$btu = get_bt_userdata($user_id)) {
return;
}
$template->assign_vars(array(
'SHOW_BT_USERDATA' => true,
@ -1764,22 +1762,19 @@ function decode_text_match($txt)
*/
function create_magnet($infohash, $auth_key): string
{
global $bb_cfg, $images, $lang, $userdata;
global $bb_cfg, $images;
// Only for registered users
if (IS_GUEST && $bb_cfg['bt_tor_browse_only_reg']) {
$passkey = false;
} elseif (empty($auth_key)) {
if (!$passkey = \TorrentPier\Legacy\Torrent::generate_passkey($userdata['user_id'], true)) {
bb_die($lang['PASSKEY_ERR_EMPTY']);
}
$auth_key = $passkey;
} else {
$passkey = $auth_key;
return false;
}
$passkey_url = $passkey ? "?{$bb_cfg['passkey_key']}=$auth_key" : '';
// Hasn't passkey
if (!$auth_key) {
return false;
}
return '<a href="magnet:?xt=urn:btih:' . bin2hex($infohash) . '&tr=' . urlencode($bb_cfg['bt_announce_url'] . $passkey_url) . '"><img src="' . $images['icon_magnet'] . '" width="12" height="12" border="0" /></a>';
return '<a href="magnet:?xt=urn:btih:' . bin2hex($infohash) . '&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>';
}
function set_die_append_msg($forum_id = null, $topic_id = null, $group_id = null)