Browse Source

feat: request route

master
dnomd343 2 years ago
parent
commit
e17a6b7962
  1. 8
      src/Basis.php
  2. 53
      src/Route.php

8
src/Basis.php

@ -1,5 +1,9 @@
<?php
function mimeJson(): void { // return json mime type
header('Content-Type: application/json; charset=utf-8');
}
function genStr(int $length, string $fillStr = ' '): string { // generate a string of specified length
return str_pad('', $length, $fillStr);
}
@ -13,6 +17,10 @@ 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 officeInfo(): array { // office dir and kms key for different version
return array(
'2010' => ['Office14', 'VYBBJ-TRJPB-QFQRF-QFT4D-H3GVB'],

53
src/Route.php

@ -1,3 +1,54 @@
<?php
echo 'ok' . PHP_EOL;
require_once 'Basis.php';
require_once 'KmsCli.php';
require_once 'KmsWeb.php';
$kmsHost = getHost(); // kms server address
$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-server/json') {
$url = '/win-server';
$isJson = true;
}
if ($url == '/' or $url == '/help') {
$isCli ? showHelpCli($kmsHost) : showHelpHtml($kmsHost); // show help message
} else if ($url == '/office') {
$isCli ? showOfficeCli($kmsHost) : showOfficeHtml($kmsHost); // show office commands
} else if ($url == '/win' or $url == '/win-server') {
$kmsKeys = getKeys(($url != '/win'));
$caption = 'Windows ' . (($url == '/win') ? '' : 'Server ') . 'KMS Keys';
if ($isJson) {
mimeJson();
echo json_encode($kmsKeys); // json format of kms keys
} else {
$isCli ? showKeysCli($kmsKeys, $isGbk) : showKeysHtml($kmsKeys, $caption); // kms keys of windows
}
} else if ($url == '/check') {
mimeJson();
echo "WIP..."; // TODO: kms check
} else { // unknown request
if ($isCli) {
echo "Illegal Request\n";
} else {
mimeJson();
echo '{"status":"error","message":"Illegal Request"}';
}
}

Loading…
Cancel
Save