Browse Source

feat: json interface

master
Dnomd343 3 years ago
parent
commit
fc8693fed4
  1. 41
      backend/route.php

41
backend/route.php

@ -4,7 +4,7 @@ include 'kms-cli.php';
include 'kms-web.php'; include 'kms-web.php';
include 'kms-help.php'; include 'kms-help.php';
if (isset($_SERVER['HTTP_HOST'])) { if (isset($_SERVER['HTTP_HOST'])) { // 获取服务域名
$webSite = $_SERVER['HTTP_HOST']; $webSite = $_SERVER['HTTP_HOST'];
} else { } else {
$webSite = "{HOST}"; $webSite = "{HOST}";
@ -12,19 +12,23 @@ if (isset($_SERVER['HTTP_HOST'])) {
$url = $_SERVER['DOCUMENT_URI']; $url = $_SERVER['DOCUMENT_URI'];
$gbk = false; $gbk = false;
if ($url == '/') {
if ($url == '/' || $url == '/help') { // 操作提示
if ($_GET['cli'] == 'true') { if ($_GET['cli'] == 'true') {
showHelp(); showHelp();
} else { } else {
webHelp(); webHelp();
} }
exit;
} }
if ($url == '/win') {
if ($url == '/win') { // KMS密钥获取
if ($_GET['cli'] == 'true') { if ($_GET['cli'] == 'true') {
showWinKeys(); showWinKeys();
} else { } else {
webWinKeys(); webWinKeys();
} }
exit;
} }
if ($url == '/win-server') { if ($url == '/win-server') {
if ($_GET['cli'] == 'true') { if ($_GET['cli'] == 'true') {
@ -32,9 +36,10 @@ if ($url == '/win-server') {
} else { } else {
webWinServerKeys(); webWinServerKeys();
} }
exit;
} }
if ($url == '/win/gbk') { if ($url == '/win/gbk') { // KMS密钥获取(GBK兼容)
if ($_GET['cli'] == 'true') { if ($_GET['cli'] == 'true') {
$gbk = true; $gbk = true;
showWinKeys(); showWinKeys();
@ -42,6 +47,7 @@ if ($url == '/win/gbk') {
header('HTTP/1.1 302 Moved Temporarily'); header('HTTP/1.1 302 Moved Temporarily');
header('Location: /win'); header('Location: /win');
} }
exit;
} }
if ($url == '/win-server/gbk') { if ($url == '/win-server/gbk') {
if ($_GET['cli'] == 'true') { if ($_GET['cli'] == 'true') {
@ -51,6 +57,33 @@ if ($url == '/win-server/gbk') {
header('HTTP/1.1 302 Moved Temporarily'); header('HTTP/1.1 302 Moved Temporarily');
header('Location: /win-server'); header('Location: /win-server');
} }
exit;
}
if ($url == '/json') { // JSON格式获取KMS密钥
header('Content-Type: application/json; charset=utf-8');
$kmsKeys = getKmsKeys('win') + getKmsKeys('win-server');
echo json_encode($kmsKeys);
exit;
}
if ($url == '/win/json') {
header('Content-Type: application/json; charset=utf-8');
$kmsKeys = getKmsKeys('win');
echo json_encode($kmsKeys);
exit;
}
if ($url == '/win-server/json') {
header('Content-Type: application/json; charset=utf-8');
$kmsKeys = getKmsKeys('win-server');
echo json_encode($kmsKeys);
exit;
}
if ($_GET['cli'] == 'true') { // 无效请求
echo 'Illegal Request' . PHP_EOL;
} else {
header('Content-Type: application/json; charset=utf-8');
echo '{"status":"error","message":"Illegal Request"}';
} }
?> ?>
Loading…
Cancel
Save