diff --git a/backend/kms-check.php b/backend/kms-check.php index cbcad30..0d171ac 100644 --- a/backend/kms-check.php +++ b/backend/kms-check.php @@ -1,39 +1,38 @@ 'error', 'message' => 'host param not exist' - )); + ); } if (isset($config['port'])) { $port = $config['port']; } else { - $port = 1688; + $port = 1688; // 默认KMS端口 } - if (isset($config['version'])) { - $version = $config['version']; + if (isset($config['site']) && $config['site'] !== '') { + $site = $config['site']; } else { - $version = 6; + $site = null; // site参数可选 } $cmd = 'vlmcs '; if (isDomain($host) || isIPv4($host)) { $cmd .= $host; } else if (isIPv6($host)) { - $cmd .= '[' . $host . ']'; + $cmd .= '[' . $host . ']'; // IPv6地址需用中括号包围 } else { - return array( + return array( // host内容不是 IPv4/IPv6/Domain 'status' => 'error', 'message' => 'illegal host' ); } - if ($port > 65535 || $port < 0) { + if ($port > 65535 || $port < 0) { // 端口不存在 return array( 'status' => 'error', 'message' => 'illegal port' @@ -41,24 +40,22 @@ function checkKms($config) { // 检测KMS服务器是否可用 } else { $cmd .= ':' . $port; } - if ($version != 4 && $version != 5 && $version != 6) { - return array( - 'status' => 'error', - 'message' => 'illegal version' - ); - } else { - $cmd .= ' -' . $version; + if ($site !== null) { + $cmd .= ' -w ' . $site; // 加入site参数 } - - $raw = shell_exec($cmd); - preg_match('/successful/', $raw, $match); + $fileName = md5(rand()) . '.txt'; // 生成随机文件名 + $cmd .= ' -G ' . $tempPath . $fileName; + shell_exec($cmd); // 执行vlmcs测试 + $raw = shell_exec('ls ' . $tempPath); + preg_match('/' . $fileName . '/', $raw, $match); // 判断随机文件是否存在 header('Content-Type: application/json; charset=utf-8'); - if (!count($match)) { + if (!count($match)) { // 随机文件不存在 -> KMS连接错误 return array( 'status' => 'error', 'message' => 'connect fail' ); - } else { + } else { // 随机文件存在 -> KMS测试成功 + shell_exec('rm -f ' . $tempPath . $fileName); // 删除随机文件 return array( 'status' => 'ok', 'message' => 'success' diff --git a/conf/docker/vlmcsd.sh b/conf/docker/vlmcsd.sh index 665ba68..afde0cd 100644 --- a/conf/docker/vlmcsd.sh +++ b/conf/docker/vlmcsd.sh @@ -3,6 +3,7 @@ git clone --branch master --single-branch https://github.com/Wind4/vlmcsd.git /t cd /tmp/vlmcsd-build make mkdir /tmp/vlmcsd +cp /tmp/vlmcsd-build/bin/vlmcs /tmp/vlmcsd/ cp /tmp/vlmcsd-build/bin/vlmcsd /tmp/vlmcsd/ cp /tmp/vlmcsd-build/etc/vlmcsd.kmd /tmp/vlmcsd/ -rm -rf /tmp/vlmcsd-build +rm -rf /tmp/vlmcsd-build \ No newline at end of file