diff --git a/backend/kms-check.php b/backend/kms-check.php new file mode 100644 index 0000000..cbcad30 --- /dev/null +++ b/backend/kms-check.php @@ -0,0 +1,69 @@ + 'error', + 'message' => 'host param not exist' + )); + } + if (isset($config['port'])) { + $port = $config['port']; + } else { + $port = 1688; + } + if (isset($config['version'])) { + $version = $config['version']; + } else { + $version = 6; + } + + $cmd = 'vlmcs '; + if (isDomain($host) || isIPv4($host)) { + $cmd .= $host; + } else if (isIPv6($host)) { + $cmd .= '[' . $host . ']'; + } else { + return array( + 'status' => 'error', + 'message' => 'illegal host' + ); + } + if ($port > 65535 || $port < 0) { + return array( + 'status' => 'error', + 'message' => 'illegal port' + ); + } else { + $cmd .= ':' . $port; + } + if ($version != 4 && $version != 5 && $version != 6) { + return array( + 'status' => 'error', + 'message' => 'illegal version' + ); + } else { + $cmd .= ' -' . $version; + } + + $raw = shell_exec($cmd); + preg_match('/successful/', $raw, $match); + header('Content-Type: application/json; charset=utf-8'); + if (!count($match)) { + return array( + 'status' => 'error', + 'message' => 'connect fail' + ); + } else { + return array( + 'status' => 'ok', + 'message' => 'success' + ); + } +} + +?> diff --git a/backend/route.php b/backend/route.php index 19a54c2..5a545e3 100644 --- a/backend/route.php +++ b/backend/route.php @@ -4,6 +4,7 @@ include 'kms-cli.php'; include 'kms-web.php'; include 'kms-help.php'; include 'kms-office.php'; +include 'kms-check.php'; function isDomain($domain) { preg_match('/^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/', $domain, $match); @@ -14,6 +15,10 @@ function isIPv4($ip) { return filter_var($ip, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4); } +function isIPv6($ip) { + return filter_var($ip, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6); +} + $kmsHost = "{KMS_HOST}"; $webSite = $kmsHost; if (isset($_SERVER['HTTP_HOST'])) { // 获取服务URL @@ -110,6 +115,12 @@ if ($url == '/win-server/json') { exit; } +if ($url == '/check') { + header('Content-Type: application/json; charset=utf-8'); + echo json_encode(checkKms($_GET)); + exit; +} + if ($_GET['cli'] == 'true') { // 无效请求 echo 'Illegal Request' . PHP_EOL; } else { @@ -117,4 +128,4 @@ if ($_GET['cli'] == 'true') { // 无效请求 echo '{"status":"error","message":"Illegal Request"}'; } -?> \ No newline at end of file +?>