From 211159ed063ad3b4a5e979bcb5e62bed6c156396 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Tue, 10 Aug 2021 21:13:35 +0800 Subject: [PATCH] feat: ntp check on server --- cmdRoute.php | 5 ++ models/kmsCheck.php | 8 +-- models/ntpCheck.php | 119 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 models/ntpCheck.php diff --git a/cmdRoute.php b/cmdRoute.php index a180a8e..6003c28 100644 --- a/cmdRoute.php +++ b/cmdRoute.php @@ -4,11 +4,13 @@ require_once 'models/tgDC.php'; require_once 'models/ipInfo.php'; require_once 'models/cfopPic.php'; require_once 'models/kmsCheck.php'; +require_once 'models/ntpCheck.php'; $cmds = array( // 命令列表 'ip', 'dc', 'kms', + 'ntp', 'cfop' ); @@ -23,6 +25,9 @@ function route($cmd, $rawParam) { // 命令请求路由 case 'kms': kmsCheck($rawParam); break; + case 'ntp': + ntpCheck($rawParam); + break; case 'cfop': cfopPic($rawParam); break; diff --git a/models/kmsCheck.php b/models/kmsCheck.php index 6bfce73..b1bff52 100644 --- a/models/kmsCheck.php +++ b/models/kmsCheck.php @@ -6,7 +6,7 @@ class kmsCheck { private function isHost($host) { // 判断host是否合法 preg_match('/^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/', $host, $match); if (count($match) !== 0) { // 域名 - return true; + if (!is_numeric(substr($host, -1))) { return true; } // 域名最后一位不为数字 } if (filter_var($host, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4)) { // IPv4地址 return true; @@ -120,7 +120,7 @@ class kmsCheck { } function kmsCheck($rawParam) { // KMS测试入口 - global $chatId, $messageId; + global $chatId; if ($rawParam == '' || $rawParam === 'help') { // 显示使用说明 sendMessage($chatId, array( 'parse_mode' => 'Markdown', @@ -148,11 +148,11 @@ function kmsCheck($rawParam) { // KMS测试入口 sendPayload(array( 'method' => 'editMessageText', 'chat_id' => $chatId, - 'message_id' => $messageId, + 'message_id' => $message['result']['message_id'], ) + (new kmsCheck)->checkKms($check['host'], $check['port'])); // 发起查询并返回结果 } -function kmsCheckCallback($rawParam) { +function kmsCheckCallback($rawParam) { // KMS测试回调入口 global $chatId, $messageId; $selectMsg = array( 'text' => 'Which one did you need?', diff --git a/models/ntpCheck.php b/models/ntpCheck.php new file mode 100644 index 0000000..7f8af08 --- /dev/null +++ b/models/ntpCheck.php @@ -0,0 +1,119 @@ +curlPost('https://servertest.online/ntp', array( + 'a' => $host, + 'c' => 'Query+both' + )); + preg_match('/<\/form>[\s\S]+