From a59939b3f36a2d76bce46ba323c6e1344e4f7f4d Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 8 Aug 2021 02:16:24 +0800 Subject: [PATCH] fix: kms check error in php safe mode --- backend/kms-check.php | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/backend/kms-check.php b/backend/kms-check.php index 0d171ac..718cbb1 100644 --- a/backend/kms-check.php +++ b/backend/kms-check.php @@ -43,23 +43,19 @@ function checkKms($config) { // 检测KMS服务器是否可用 if ($site !== null) { $cmd .= ' -w ' . $site; // 加入site参数 } - $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)) { // 随机文件不存在 -> KMS连接错误 - return array( - 'status' => 'error', - 'message' => 'connect fail' - ); - } else { // 随机文件存在 -> KMS测试成功 - shell_exec('rm -f ' . $tempPath . $fileName); // 删除随机文件 + $cmd .= ' -G temp'; + $raw = shell_exec($cmd); // 执行vlmcs测试 + preg_match_all('/Sending activation request \(KMS V6\)/', $raw, $match); + if (count($match[0]) == 6) { // KMS服务器连接成功 return array( 'status' => 'ok', 'message' => 'success' ); + } else { // KMS服务器连接异常 + return array( + 'status' => 'error', + 'message' => 'connect fail' + ); } }