diff --git a/README-EN.md b/README-EN.md index 7dc1964b..601a6c9f 100644 --- a/README-EN.md +++ b/README-EN.md @@ -40,7 +40,7 @@ Welcome to participate in internationalization work, click [here](https://github - Section H&R - TGBot ## System Requirements -- PHP: 8.2|8.3|8.4, must have extensions: bcmath, ctype, curl, fileinfo, json, mbstring, openssl, pdo_mysql, tokenizer, xml, mysqli, gd, redis, pcntl, sockets, posix, gmp, zend opcache +- PHP: 8.2|8.3|8.4, must have extensions: bcmath, ctype, curl, fileinfo, json, mbstring, openssl, pdo_mysql, tokenizer, xml, mysqli, gd, redis, pcntl, sockets, posix, gmp, zend opcache, zip, intl, pdo_sqlite, sqlite3 - Mysql: 5.7 latest version or above - Redis:2.6.12 or above - Others: supervisor, rsync diff --git a/README.md b/README.md index d75843cb..c43bbc47 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ - TGBot ## 系统要求 -- PHP: 8.2|8.3|8.4,必须扩展:bcmath, ctype, curl, fileinfo, json, mbstring, openssl, pdo_mysql, tokenizer, xml, mysqli, gd, redis, pcntl, sockets, posix, gmp, zend opcache +- PHP: 8.2|8.3|8.4,必须扩展:bcmath, ctype, curl, fileinfo, json, mbstring, openssl, pdo_mysql, tokenizer, xml, mysqli, gd, redis, pcntl, sockets, posix, gmp, zend opcache, zip, intl, pdo_sqlite, sqlite3 - Mysql: 5.7 最新版或以上版本 - Redis:2.6.12 或以上版本 - 其他:supervisor, rsync diff --git a/app/Auth/NexusWebUserProvider.php b/app/Auth/NexusWebUserProvider.php index 2805da2f..72306b84 100644 --- a/app/Auth/NexusWebUserProvider.php +++ b/app/Auth/NexusWebUserProvider.php @@ -61,15 +61,11 @@ class NexusWebUserProvider implements UserProvider */ public function retrieveByCredentials(array $credentials) { - list($tokenJson, $signature) = explode('.', base64_decode($credentials["c_secure_pass"])); - if (empty($tokenJson) || empty($signature)) { + $result = get_user_id_and_signature_from_cookie($credentials); + if (empty($result)) { return null; } - $tokenData = json_decode($tokenJson, true); - if (!isset($tokenData['user_id'])) { - return null; - } - return $this->retrieveById($tokenData['user_id']); + return $this->retrieveById($result['user_id']); } /** diff --git a/composer.json b/composer.json index e4cd56d7..5a973a0f 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,7 @@ "ext-xml": "*", "ext-zend-opcache": "*", "ext-zip": "*", + "ext-sqlite3": "*", "calebporzio/sushi": "^2.5", "elasticsearch/elasticsearch": "^7.16", "filament/filament": "^3.3", diff --git a/config/horizon.php b/config/horizon.php index 01d1d1e0..d1d8ba47 100644 --- a/config/horizon.php +++ b/config/horizon.php @@ -183,7 +183,7 @@ return [ 'defaults' => [ 'supervisor-1' => [ 'connection' => 'redis', - 'queue' => ['nexus_queue'], + 'queue' => ['default', 'nexus_queue'], 'balance' => 'auto', 'autoScalingStrategy' => 'time', 'maxProcesses' => 1, diff --git a/include/globalfunctions.php b/include/globalfunctions.php index 2f083edd..11ea5b97 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -1399,40 +1399,14 @@ function get_challenge_key(string $challenge): string { function get_user_from_cookie(array $cookie, $isArray = true): array|\App\Models\User|null { $log = "cookie: " . json_encode($cookie); - if (empty($cookie["c_secure_pass"])) { - do_log("$log, param not enough"); + $result = get_user_id_and_signature_from_cookie($cookie); + if (empty($result)) { return null; } - $base64Decoded = base64_decode($cookie["c_secure_pass"]); - if (empty($base64Decoded)) { - do_log("$log, invalid c_secure_pass"); - return null; - } - $log .= ", base64 decoded: " . $base64Decoded; - $tokenJsonAndSignature = explode(".", $base64Decoded); - if (count($tokenJsonAndSignature) != 2) { - do_log("$log, invalid c_secure_pass base64_decoded"); - return null; - } - $tokenJson = $tokenJsonAndSignature[0]; - $signature = $tokenJsonAndSignature[1]; -// list($tokenJson, $signature) = explode('.', base64_decode($_COOKIE["c_secure_pass"])); - if (empty($tokenJson) || empty($signature)) { - do_log("$log, no tokenJson or signature"); - return null; - } - $tokenData = json_decode($tokenJson, true); - if (!isset($tokenData['user_id'])) { - do_log("$log, no user_id"); - return null; - } - if (!isset($tokenData['expires']) || $tokenData['expires'] < time()) { - do_log("$log, signature expired"); - return null; - } - $id = $tokenData['user_id']; + $id = $result['user_id']; + $tokenJson = $result['token_json']; + $signature = $result['signature']; $log .= ", uid = $id"; - if ($isArray) { $res = sql_query("SELECT * FROM users WHERE users.id = ".sqlesc($id)." AND users.enabled='yes' AND users.status = 'confirmed' LIMIT 1"); $row = mysql_fetch_array($res); @@ -1464,6 +1438,46 @@ function get_user_from_cookie(array $cookie, $isArray = true): array|\App\Models return $row; } +function get_user_id_and_signature_from_cookie(array $cookie): array|null +{ + $log = "cookie: " . json_encode($cookie); + if (empty($cookie["c_secure_pass"])) { + do_log("$log, param not enough"); + return null; + } + $base64Decoded = base64_decode($cookie["c_secure_pass"]); + if (empty($base64Decoded)) { + do_log("$log, invalid c_secure_pass"); + return null; + } + $log .= ", base64 decoded: " . $base64Decoded; + $tokenJsonAndSignature = explode(".", $base64Decoded); + if (count($tokenJsonAndSignature) != 2) { + do_log("$log, invalid c_secure_pass base64_decoded"); + return null; + } + $tokenJson = $tokenJsonAndSignature[0]; + $signature = $tokenJsonAndSignature[1]; + if (empty($tokenJson) || empty($signature)) { + do_log("$log, no tokenJson or signature"); + return null; + } + $tokenData = json_decode($tokenJson, true); + if (!isset($tokenData['user_id'])) { + do_log("$log, no user_id"); + return null; + } + if (!isset($tokenData['expires']) || $tokenData['expires'] < time()) { + do_log("$log, signature expired"); + return null; + } + return [ + "user_id" => $tokenData['user_id'], + 'token_json' => $tokenJson, + 'signature' => $signature, + ]; +} + function render_password_hash_js(string $formId, string $passwordOriginalClass, string $passwordHashedName, bool $passwordRequired, string $passwordConfirmClass = "password_confirmation", string $usernameName = "username"): void { $tipTooShort = nexus_trans('signup.password_too_short'); $tipTooLong = nexus_trans('signup.password_too_long'); diff --git a/nexus/Install/Install.php b/nexus/Install/Install.php index 4c398900..4935c2f2 100644 --- a/nexus/Install/Install.php +++ b/nexus/Install/Install.php @@ -34,7 +34,8 @@ class Install protected array $requiredExtensions = [ 'ctype', 'curl', 'fileinfo', 'json', 'mbstring', 'openssl', 'pdo_mysql', 'tokenizer', 'xml', - 'mysqli', 'bcmath', 'redis', 'gd', 'gmp', 'Zend OPcache', 'pcntl', 'posix', 'sockets', 'zip', 'intl' + 'mysqli', 'bcmath', 'redis', 'gd', 'gmp', 'Zend OPcache', 'pcntl', 'posix', 'sockets', 'zip', 'intl', + 'sqlite3', 'pdo_sqlite' ]; protected array $optionalExtensions = [ // ['name' => 'swoole', 'desc' => "If use swoole for Octane, make sure 'current' shows 1"],