Browse Source

update: perf route process

master
dnomd343 2 years ago
parent
commit
682e681f58
  1. 4
      src/Basis.php
  2. 1
      src/KmsWeb.php
  3. 22
      src/Route.php

4
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']; return $isWinServer ? array_reverse($keysAsset['win-server']) : $keysAsset['win'];
} }
function getHost(): string { // TODO: get kms host function getHost(): string {
return 'kms.343.re'; return $_SERVER['HTTP_HOST'] ?? 'KMS_HOST'; // TODO: remove port content
} }
function officeInfo(): array { // office dir and kms key for different version function officeInfo(): array { // office dir and kms key for different version

1
src/KmsWeb.php

@ -16,7 +16,6 @@ function showKeysHtml(array $kmsKeys, string $header): void { // show kms keys i
echo '</div></body></html>'; echo '</div></body></html>';
} }
function showHelpHtml(string $host): void { // show help message in html function showHelpHtml(string $host): void { // show help message in html
echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">'; echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">'; echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">';

22
src/Route.php

@ -9,25 +9,17 @@ $url = $_SERVER['DOCUMENT_URI']; // request url
$isCli = ($_GET['cli'] == 'true'); // shell or web browser $isCli = ($_GET['cli'] == 'true'); // shell or web browser
$isGbk = false; // utf-8 or gbk $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 $isJson = false; // json output
if ($url == '/win/json') { if ($url == '/win/gbk' or $url == '/win-server/gbk') {
$url = '/win'; $url = ($url == '/win/gbk') ? '/win' : '/win-server'; // gbk mode
$isJson = true; $isGbk = true;
} }
if ($url == '/win-server/json') { if ($url == '/win/json' or $url == '/win-server/json') {
$url = '/win-server'; $url = ($url == '/win/json') ? '/win' : '/win-server'; // json mode
$isJson = true; $isJson = true;
} }
// start route process
if ($url == '/' or $url == '/help') { if ($url == '/' or $url == '/help') {
$isCli ? showHelpCli($kmsHost) : showHelpHtml($kmsHost); // show help message $isCli ? showHelpCli($kmsHost) : showHelpHtml($kmsHost); // show help message
} else if ($url == '/office') { } else if ($url == '/office') {
@ -49,6 +41,6 @@ if ($url == '/' or $url == '/help') {
echo "Illegal Request\n"; echo "Illegal Request\n";
} else { } else {
mimeJson(); mimeJson();
echo '{"status":"error","message":"Illegal Request"}'; echo '{"success":false,"message":"Illegal Request"}';
} }
} }

Loading…
Cancel
Save