diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index fccba9fd..276dfbb3 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -50,7 +50,7 @@ class Test extends Command */ public function handle() { - + } } diff --git a/app/Repositories/ToolRepository.php b/app/Repositories/ToolRepository.php index 7588bc79..93250910 100644 --- a/app/Repositories/ToolRepository.php +++ b/app/Repositories/ToolRepository.php @@ -9,8 +9,6 @@ use Illuminate\Support\Str; class ToolRepository extends BaseRepository { - private static $encrypter; - public function backupWeb(): array { $webRoot = base_path(); @@ -146,17 +144,8 @@ class ToolRepository extends BaseRepository return $backupResult; } - public function getEncrypter(): Encrypter + public function getEncrypter(string $key): Encrypter { - if (!is_null(self::$encrypter)) { - return self::$encrypter; - } - $key = nexus_env('APP_KEY'); - $prefix = 'base64:'; - if (Str::startsWith($key,$prefix)) { - $key = substr($key, strlen($prefix)); - $key = base64_decode($key); - } - return self::$encrypter = new Encrypter($key, 'AES-256-CBC'); + return new Encrypter($key, 'AES-256-CBC'); } } diff --git a/app/Repositories/TorrentRepository.php b/app/Repositories/TorrentRepository.php index 5209298a..bc01cc44 100644 --- a/app/Repositories/TorrentRepository.php +++ b/app/Repositories/TorrentRepository.php @@ -254,15 +254,20 @@ class TorrentRepository extends BaseRepository return "$speed/s"; } - public function encryptDownHash($id, $uid): string + public function encryptDownHash($id, $user): string { + if (!is_array($user) || empty($user['passkey']) || empty($user['id'])) { + $user = User::query()->findOrFail(intval($user), ['id', 'passkey'])->toArray(); + } + //down hash is relative to user passkey + $key = md5($user['passkey'] . date('Ymd') . $user['id']); $toolRep = new ToolRepository(); $payload = [ 'id' => $id, - 'uid' => $uid, + 'uid' => $user['id'], 'date' => date('Ymd'), ]; - return $toolRep->getEncrypter()->encrypt($payload); + return $toolRep->getEncrypter($key)->encrypt($payload); } public function decryptDownHash($downHash) diff --git a/lang/chs/lang_details.php b/lang/chs/lang_details.php index 2849d8e1..12d1fc4e 100644 --- a/lang/chs/lang_details.php +++ b/lang/chs/lang_details.php @@ -220,7 +220,7 @@ $lang_details = array 'text_and_more' => "……(这里只显示最新记录。共", 'text_users_in_total' => "个用户表示了感谢)", 'torrent_dl_url' => "种子链接", - 'torrent_dl_url_notice' => "可在BT客户端使用,请保护好Passkey,谨防泄露。", + 'torrent_dl_url_notice' => "可在BT客户端使用,当天有效。", 'torrent_dl_url_text' => "右键查看。", 'span_description_have_given' =>'你已经赠送魔力值', 'text_no_magic_added' => "暂无魔力值奖励", diff --git a/lang/cht/lang_details.php b/lang/cht/lang_details.php index b8152a2d..3bdc7da8 100644 --- a/lang/cht/lang_details.php +++ b/lang/cht/lang_details.php @@ -219,7 +219,7 @@ $lang_details = array 'text_and_more' => "……(這裏只顯示最新記錄。共", 'text_users_in_total' => "個用戶表示了感謝)", 'torrent_dl_url' => "種子連結", - 'torrent_dl_url_notice' => "可在BT用戶端使用,請保護好Passkey,謹防洩露。", + 'torrent_dl_url_notice' => "可在BT用戶端使用,當天有效。", 'torrent_dl_url_text' => "右鍵查看。", 'span_description_have_given' =>'你已經贈送魔力值', 'text_no_magic_added' => "暫無魔力值獎勵", diff --git a/lang/en/lang_details.php b/lang/en/lang_details.php index 7fd4c486..dc88ae7e 100644 --- a/lang/en/lang_details.php +++ b/lang/en/lang_details.php @@ -219,7 +219,7 @@ $lang_details = array 'text_and_more' => " and more (thanks from ", 'text_users_in_total' => " users in total)", 'torrent_dl_url' => "Torrent URL", - 'torrent_dl_url_notice' => "You can copy it to your BT Client. Take care since it contains your passkey.", + 'torrent_dl_url_notice' => "You can copy it to your BT Client. Only valid in today.", 'torrent_dl_url_text' => "Right click to view.", 'span_description_have_given' =>'You have given the magic of the value', 'text_no_magic_added' => "No magic value of the award", diff --git a/public/details.php b/public/details.php index 6c492b37..d3a6ff5f 100644 --- a/public/details.php +++ b/public/details.php @@ -38,6 +38,7 @@ if (!$row) { ) { permissiondenied(); } else { + $torrentRep = new \App\Repositories\TorrentRepository(); $torrentUpdate = []; if (!empty($_GET["hit"])) { $torrentUpdate[] = 'views = views + 1'; @@ -127,7 +128,7 @@ if (!$row) { else $download = ""; tr($lang_details['row_action'], $download. ($owned == 1 ? "<$editlink>\"edit\" ".$lang_details['text_edit_torrent'] . " | " : ""). (get_user_class() >= $askreseed_class && $row['seeders'] == 0 ? "\"reseed\" ".$lang_details['text_ask_for_reseed'] ." | " : "") . "\"report\" ".$lang_details['text_report_torrent']."", 1); - tr($lang_details['torrent_dl_url'],sprintf('%s',$lang_details['torrent_dl_url_notice'],getSchemeAndHttpHost(),$id,$CURUSER['passkey'], $lang_details['torrent_dl_url_text']),1); + tr($lang_details['torrent_dl_url'],sprintf('%s',$lang_details['torrent_dl_url_notice'], getSchemeAndHttpHost(), $torrentRep->encryptDownHash($row['id'], $CURUSER), $lang_details['torrent_dl_url_text']),1); // ---------------- start subtitle block -------------------// $r = sql_query("SELECT subs.*, language.flagpic, language.lang_name FROM subs LEFT JOIN language ON subs.lang_id=language.id WHERE torrent_id = " . sqlesc($row["id"]). " ORDER BY subs.lang_id ASC") or sqlerr(__FILE__, __LINE__); diff --git a/public/download.php b/public/download.php index 396ac5f6..a8517371 100644 --- a/public/download.php +++ b/public/download.php @@ -1,15 +1,25 @@ decryptDownHash($_REQUEST['downhash']); + } catch (\Exception $exception) { + do_log("downhash: " . $_REQUEST['downhash'] . " invalid: " . $exception->getMessage()); + die("invalid downhash, decrypt fail"); + } + if ($params['date'] != date('Ymd')) { + die("invalid downhash, expires"); + } + $id = $params['id']; + $uid = $params['uid']; + + $res = sql_query("SELECT * FROM users WHERE id=". sqlesc($uid)." LIMIT 1"); $user = mysql_fetch_array($res); if (!$user) - die("invalid passkey"); + die("invalid downhash, payload invalid"); elseif ($user['enabled'] == 'no' || $user['parked'] == 'yes') die("account disabed or parked"); $oldip = $user['ip']; @@ -18,6 +28,9 @@ if ($passkey){ } else { + $id = (int)$_GET["id"]; + if (!$id) + httperr(); loggedinorreturn(); parked(); $letdown = intval($_GET['letdown'] ?? 0);