Fix magnet link passkey creation for new users

Signed-off-by: Yuriy Pikhtarev <iglix@me.com>
This commit is contained in:
Yuriy Pikhtarev 2018-06-24 18:03:46 +03:00
commit 1cbc084f2e
No known key found for this signature in database
GPG key ID: 3A9B5A757B48ECC6
5 changed files with 26 additions and 8 deletions

View file

@ -143,7 +143,7 @@ if ($tor_reged && $tor_info) {
// Magnet link // Magnet link
$passkey = DB()->fetch_row("SELECT auth_key FROM " . BB_BT_USERS . " WHERE user_id = " . (int)$bt_user_id . " LIMIT 1"); $passkey = DB()->fetch_row("SELECT auth_key FROM " . BB_BT_USERS . " WHERE user_id = " . (int)$bt_user_id . " LIMIT 1");
$tor_magnet = create_magnet($tor_info['info_hash'], $passkey['auth_key'], $userdata['session_logged_in']); $tor_magnet = create_magnet($tor_info['info_hash'], $passkey['auth_key']);
// ratio limits // ratio limits
$min_ratio_dl = $bb_cfg['bt_min_ratio_allow_dl_tor']; $min_ratio_dl = $bb_cfg['bt_min_ratio_allow_dl_tor'];

View file

@ -1912,11 +1912,30 @@ function pad_with_space($str)
return $str ? " $str " : $str; return $str ? " $str " : $str;
} }
function create_magnet($infohash, $auth_key, $logged_in) /**
* Create magnet link
*
* @param string $infohash
* @param string|bool $auth_key
*
* @return string
*/
function create_magnet($infohash, $auth_key)
{ {
global $bb_cfg, $_GET, $images; global $bb_cfg, $images, $lang, $userdata;
if (IS_GUEST && $bb_cfg['bt_tor_browse_only_reg']) {
$passkey = '';
} elseif (empty($auth_key)) {
if (!$passkey = \TorrentPier\Legacy\Torrent::generate_passkey($userdata['user_id'], true)) {
bb_die($lang['PASSKEY_ERR_EMPTY']);
}
} else {
$passkey = $auth_key;
}
$passkey_url = $passkey ? "?{$bb_cfg['passkey_key']}=$auth_key" : '';
$passkey_url = ((!$logged_in || isset($_GET['no_passkey'])) && $bb_cfg['bt_tor_browse_only_reg']) ? '' : "?{$bb_cfg['passkey_key']}=$auth_key";
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'] . $passkey_url) . '"><img src="' . $images['icon_magnet'] . '" width="12" height="12" border="0" /></a>';
} }

View file

@ -599,13 +599,12 @@ class Torrent
// Insert new row // Insert new row
DB()->query("INSERT IGNORE INTO " . BB_BT_USERS . " (user_id, auth_key) VALUES ($user_id, '$passkey_val')"); DB()->query("INSERT IGNORE INTO " . BB_BT_USERS . " (user_id, auth_key) VALUES ($user_id, '$passkey_val')");
if (DB()->affected_rows() == 1) { if (DB()->affected_rows() == 1) {
return $passkey_val; return $passkey_val;
} }
// Update // Update
DB()->query("UPDATE IGNORE " . BB_BT_USERS . " SET auth_key = '$passkey_val' WHERE user_id = $user_id"); DB()->query("UPDATE IGNORE " . BB_BT_USERS . " SET auth_key = '$passkey_val' WHERE user_id = $user_id");
if (DB()->affected_rows() == 1) { if (DB()->affected_rows() == 1) {
// Ocelot // Ocelot
if ($bb_cfg['ocelot']['enabled']) { if ($bb_cfg['ocelot']['enabled']) {

View file

@ -698,7 +698,7 @@ if ($allowed_forums) {
$s_last = $tor['seeder_last_seen']; $s_last = $tor['seeder_last_seen'];
$att_id = $tor['attach_id']; $att_id = $tor['attach_id'];
$size = $tor['size']; $size = $tor['size'];
$tor_magnet = create_magnet($tor['info_hash'], $passkey['auth_key'], $userdata['session_logged_in']); $tor_magnet = create_magnet($tor['info_hash'], $passkey['auth_key']);
$compl = $tor['complete_count']; $compl = $tor['complete_count'];
$dl_sp = ($dl) ? humn_size($dl, 0, 'KB') . '/s' : '0 KB/s'; $dl_sp = ($dl) ? humn_size($dl, 0, 'KB') . '/s' : '0 KB/s';
$ul_sp = ($ul) ? humn_size($ul, 0, 'KB') . '/s' : '0 KB/s'; $ul_sp = ($ul) ? humn_size($ul, 0, 'KB') . '/s' : '0 KB/s';

View file

@ -470,7 +470,7 @@ foreach ($topic_rowset as $topic) {
)); ));
if (isset($topic['tor_size'])) { if (isset($topic['tor_size'])) {
$tor_magnet = create_magnet($topic['info_hash'], $topic['auth_key'], $userdata['session_logged_in']); $tor_magnet = create_magnet($topic['info_hash'], $topic['auth_key']);
$template->assign_block_vars('t.tor', array( $template->assign_block_vars('t.tor', array(
'SEEDERS' => (int)$topic['seeders'], 'SEEDERS' => (int)$topic['seeders'],