From 682e681f584238ccf532d615749a85f127cac526 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Wed, 10 Aug 2022 21:04:20 +0800 Subject: [PATCH] update: perf route process --- src/Basis.php | 6 +++--- src/KmsWeb.php | 1 - src/Route.php | 22 +++++++--------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/Basis.php b/src/Basis.php index 9cace28..13461c4 100644 --- a/src/Basis.php +++ b/src/Basis.php @@ -17,8 +17,8 @@ function getKeys(bool $isWinServer = false): array { // get kms keys asset return $isWinServer ? array_reverse($keysAsset['win-server']) : $keysAsset['win']; } -function getHost(): string { // TODO: get kms host - return 'kms.343.re'; +function getHost(): string { + return $_SERVER['HTTP_HOST'] ?? 'KMS_HOST'; // TODO: remove port content } function officeInfo(): array { // office dir and kms key for different version @@ -51,4 +51,4 @@ function osppCommand(string $host): array { // load office ospp command '/remhst' => ['Removes KMS host name and sets port to default.', '删除 KMS 主机名'], '/act' => ['Activates installed Office product keys.', '激活 Office'], ); -} \ No newline at end of file +} diff --git a/src/KmsWeb.php b/src/KmsWeb.php index 5744cd1..0dfdffe 100644 --- a/src/KmsWeb.php +++ b/src/KmsWeb.php @@ -16,7 +16,6 @@ function showKeysHtml(array $kmsKeys, string $header): void { // show kms keys i echo ''; } - function showHelpHtml(string $host): void { // show help message in html echo ''; echo ''; diff --git a/src/Route.php b/src/Route.php index 1c2adbc..6738798 100644 --- a/src/Route.php +++ b/src/Route.php @@ -9,25 +9,17 @@ $url = $_SERVER['DOCUMENT_URI']; // request url $isCli = ($_GET['cli'] == 'true'); // shell or web browser $isGbk = false; // utf-8 or gbk -if ($url == '/win/gbk') { - $url = '/win'; - $isGbk = true; -} -if ($url == '/win-server/gbk') { - $url = '/win-server'; - $isGbk = true; -} - $isJson = false; // json output -if ($url == '/win/json') { - $url = '/win'; - $isJson = true; +if ($url == '/win/gbk' or $url == '/win-server/gbk') { + $url = ($url == '/win/gbk') ? '/win' : '/win-server'; // gbk mode + $isGbk = true; } -if ($url == '/win-server/json') { - $url = '/win-server'; +if ($url == '/win/json' or $url == '/win-server/json') { + $url = ($url == '/win/json') ? '/win' : '/win-server'; // json mode $isJson = true; } +// start route process if ($url == '/' or $url == '/help') { $isCli ? showHelpCli($kmsHost) : showHelpHtml($kmsHost); // show help message } else if ($url == '/office') { @@ -49,6 +41,6 @@ if ($url == '/' or $url == '/help') { echo "Illegal Request\n"; } else { mimeJson(); - echo '{"status":"error","message":"Illegal Request"}'; + echo '{"success":false,"message":"Illegal Request"}'; } }