mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-19 21:03:54 -07:00
More performance optimized/random string generation, removed passkey length limit from the announcer (#1013)
This commit is contained in:
parent
c69712a463
commit
725773254f
7 changed files with 20 additions and 17 deletions
|
@ -30,7 +30,7 @@ if (isset($_GET['?info_hash']) && !isset($_GET['info_hash'])) {
|
||||||
if (strpos($_SERVER['REQUEST_URI'], 'scrape') !== false) {
|
if (strpos($_SERVER['REQUEST_URI'], 'scrape') !== false) {
|
||||||
msg_die('Please disable SCRAPE!');
|
msg_die('Please disable SCRAPE!');
|
||||||
}
|
}
|
||||||
if (!isset($_GET[$passkey_key]) || !is_string($_GET[$passkey_key]) || strlen($_GET[$passkey_key]) !== BT_AUTH_KEY_LENGTH) {
|
if (!isset($_GET[$passkey_key]) || !is_string($_GET[$passkey_key])) {
|
||||||
msg_die('Please LOG IN and RE-DOWNLOAD this torrent (passkey not found)');
|
msg_die('Please LOG IN and RE-DOWNLOAD this torrent (passkey not found)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,9 +93,6 @@ if (!isset($downloaded) || $downloaded < 0) {
|
||||||
if (!isset($left) || $left < 0) {
|
if (!isset($left) || $left < 0) {
|
||||||
msg_die('Invalid left value: ' . $left);
|
msg_die('Invalid left value: ' . $left);
|
||||||
}
|
}
|
||||||
if (!verify_id($passkey, BT_AUTH_KEY_LENGTH)) {
|
|
||||||
msg_die('Invalid passkey: ' . $passkey);
|
|
||||||
}
|
|
||||||
|
|
||||||
// IP
|
// IP
|
||||||
$ip = $_SERVER['REMOTE_ADDR'];
|
$ip = $_SERVER['REMOTE_ADDR'];
|
||||||
|
|
11
common.php
11
common.php
|
@ -102,7 +102,7 @@ define('BB_BT_TRACKER', 'bb_bt_tracker');
|
||||||
define('BB_BT_TRACKER_SNAP', 'bb_bt_tracker_snap');
|
define('BB_BT_TRACKER_SNAP', 'bb_bt_tracker_snap');
|
||||||
define('BB_BT_USERS', 'bb_bt_users');
|
define('BB_BT_USERS', 'bb_bt_users');
|
||||||
|
|
||||||
define('BT_AUTH_KEY_LENGTH', 10);
|
define('BT_AUTH_KEY_LENGTH', 20);
|
||||||
|
|
||||||
define('DL_STATUS_RELEASER', -1);
|
define('DL_STATUS_RELEASER', -1);
|
||||||
define('DL_STATUS_DOWN', 0);
|
define('DL_STATUS_DOWN', 0);
|
||||||
|
@ -297,9 +297,14 @@ function str_compact($str)
|
||||||
*/
|
*/
|
||||||
function make_rand_str($length = 10): string
|
function make_rand_str($length = 10): string
|
||||||
{
|
{
|
||||||
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
$pool = str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||||
|
|
||||||
return substr(str_shuffle(str_repeat($pool, (int)$length)), 0, $length);
|
$randomString = '';
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
$randomString .= $pool[random_int(0, 61)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $randomString;
|
||||||
}
|
}
|
||||||
|
|
||||||
function array_deep(&$var, $fn, $one_dimensional = false, $array_only = false)
|
function array_deep(&$var, $fn, $one_dimensional = false, $array_only = false)
|
||||||
|
|
|
@ -1188,10 +1188,10 @@ function get_user_torrent_client(string $peer_id): mixed
|
||||||
'-CT' => 'CTorrent', '-DE' => 'Deluge', '-FD' => 'Free Download Manager', 'FD6' => 'Free Download Manager',
|
'-CT' => 'CTorrent', '-DE' => 'Deluge', '-FD' => 'Free Download Manager', 'FD6' => 'Free Download Manager',
|
||||||
'-FG' => 'FlashGet', '-FL' => 'Folx', '-HL' => 'Halite', '-KG' => 'KGet',
|
'-FG' => 'FlashGet', '-FL' => 'Folx', '-HL' => 'Halite', '-KG' => 'KGet',
|
||||||
'-KT' => 'KTorrent', '-LT' => 'libTorrent', '-Lr' => 'LibreTorrent', '-MG' => 'MediaGet',
|
'-KT' => 'KTorrent', '-LT' => 'libTorrent', '-Lr' => 'LibreTorrent', '-MG' => 'MediaGet',
|
||||||
'-TR' => 'Transmission', '-tT' => 'tTorrent', '-UM' => "uTorrent Mac", '-UT' => "uTorrent",
|
'-TR' => 'Transmission', '-tT' => 'tTorrent', '-UM' => "uTorrent Mac", '-UT' => 'uTorrent',
|
||||||
'-UW' => "uTorrent Web", '-WW' => 'WebTorrent', '-WD' => 'WebTorrent', '-XL' => 'Xunlei',
|
'-UW' => 'uTorrent Web', '-WW' => 'WebTorrent', '-WD' => 'WebTorrent', '-XL' => 'Xunlei',
|
||||||
'-PI' => 'PicoTorrent', '-qB' => 'qBittorrent', 'M' => 'BitTorrent', 'MG' => 'MediaGet',
|
'-PI' => 'PicoTorrent', '-qB' => 'qBittorrent', 'M' => 'BitTorrent', 'MG' => 'MediaGet',
|
||||||
'OP' => 'Opera', 'TIX' => 'Tixati', 'aria2-' => 'Aria2', 'A2' => 'Aria2',
|
'-MG' => 'MediaGet', 'OP' => 'Opera', 'TIX' => 'Tixati', 'aria2-' => 'Aria2', 'A2' => 'Aria2',
|
||||||
/**
|
/**
|
||||||
* ================================ Other ================================
|
* ================================ Other ================================
|
||||||
* '-BB' => 'BitBuddy', '-AR' => 'Arctic', '-AT' => 'Artemis', '-AV' => 'Avicora',
|
* '-BB' => 'BitBuddy', '-AR' => 'Arctic', '-AT' => 'Artemis', '-AV' => 'Avicora',
|
||||||
|
@ -1233,9 +1233,10 @@ function get_user_torrent_client(string $peer_id): mixed
|
||||||
|
|
||||||
if (!empty($bestMatch)) {
|
if (!empty($bestMatch)) {
|
||||||
return '<img width="auto" height="auto" style="display:inline!important;vertical-align:middle" src="/styles/images/clients/' . $bestMatch . '.png" alt="' . $bestMatch . '" title="' . $peer_id . '">';
|
return '<img width="auto" height="auto" style="display:inline!important;vertical-align:middle" src="/styles/images/clients/' . $bestMatch . '.png" alt="' . $bestMatch . '" title="' . $peer_id . '">';
|
||||||
} else {
|
|
||||||
return $peer_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $peer_id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function birthday_age($date)
|
function birthday_age($date)
|
||||||
|
|
|
@ -262,7 +262,7 @@ define('SHOW_PEERS_NAMES', 2);
|
||||||
define('SHOW_PEERS_FULL', 3);
|
define('SHOW_PEERS_FULL', 3);
|
||||||
|
|
||||||
define('SEARCH_ID_LENGTH', 12);
|
define('SEARCH_ID_LENGTH', 12);
|
||||||
define('ACTKEY_LENGHT', 32);
|
define('ACTKEY_LENGTH', 32);
|
||||||
define('SID_LENGTH', 20);
|
define('SID_LENGTH', 20);
|
||||||
define('LOGIN_KEY_LENGTH', 32);
|
define('LOGIN_KEY_LENGTH', 32);
|
||||||
define('USERNAME_MIN_LENGTH', 3);
|
define('USERNAME_MIN_LENGTH', 3);
|
||||||
|
|
|
@ -534,7 +534,7 @@ if ($submit && !$errors) {
|
||||||
*/
|
*/
|
||||||
if ($mode == 'register') {
|
if ($mode == 'register') {
|
||||||
if ($bb_cfg['reg_email_activation']) {
|
if ($bb_cfg['reg_email_activation']) {
|
||||||
$user_actkey = make_rand_str(ACTKEY_LENGHT);
|
$user_actkey = make_rand_str(ACTKEY_LENGTH);
|
||||||
$db_data['user_active'] = 0;
|
$db_data['user_active'] = 0;
|
||||||
$db_data['user_actkey'] = $user_actkey;
|
$db_data['user_actkey'] = $user_actkey;
|
||||||
} else {
|
} else {
|
||||||
|
@ -597,7 +597,7 @@ if ($submit && !$errors) {
|
||||||
// если что-то было изменено
|
// если что-то было изменено
|
||||||
if ($db_data) {
|
if ($db_data) {
|
||||||
if (!$pr_data['user_active']) {
|
if (!$pr_data['user_active']) {
|
||||||
$user_actkey = make_rand_str(ACTKEY_LENGHT);
|
$user_actkey = make_rand_str(ACTKEY_LENGTH);
|
||||||
$pr_data['user_actkey'] = $user_actkey;
|
$pr_data['user_actkey'] = $user_actkey;
|
||||||
$db_data['user_actkey'] = $user_actkey;
|
$db_data['user_actkey'] = $user_actkey;
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ if (isset($_POST['submit'])) {
|
||||||
$username = $row['username'];
|
$username = $row['username'];
|
||||||
$user_id = $row['user_id'];
|
$user_id = $row['user_id'];
|
||||||
|
|
||||||
$user_actkey = make_rand_str(ACTKEY_LENGHT);
|
$user_actkey = make_rand_str(ACTKEY_LENGTH);
|
||||||
$user_password = make_rand_str(PASSWORD_MIN_LENGTH);
|
$user_password = make_rand_str(PASSWORD_MIN_LENGTH);
|
||||||
|
|
||||||
$sql = "UPDATE " . BB_USERS . "
|
$sql = "UPDATE " . BB_USERS . "
|
||||||
|
|
|
@ -63,6 +63,6 @@ class IPHelper extends Ip
|
||||||
|
|
||||||
public static function long2ip_extended(string $ip): string
|
public static function long2ip_extended(string $ip): string
|
||||||
{
|
{
|
||||||
return self::long2ip($ip, $ip > 4294967295);
|
return self::long2ip($ip, $ip > 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue