Browse Source

feat: show kms keys by tgbot

master
Dnomd343 3 years ago
parent
commit
aa250a9d67
  1. 3
      cmdRoute.php
  2. 113
      models/kmsCheck.php

3
cmdRoute.php

@ -34,6 +34,9 @@ function routeCallback($cmd, $rawParam) { // 回调请求路由
case 'ip': case 'ip':
ipInfoCallback($rawParam); ipInfoCallback($rawParam);
break; break;
case 'kms':
kmsCheckCallback($rawParam);
break;
case 'cfop': case 'cfop':
cfopPicCallback($rawParam); cfopPicCallback($rawParam);
break; break;

113
models/kmsCheck.php

@ -1,7 +1,7 @@
<?php <?php
class kmsCheck { class kmsCheck {
private $api = 'https://kms.343.re/check?'; private $api = 'https://kms.343.re';
private function isHost($host) { // 判断host是否合法 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); 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);
@ -56,9 +56,49 @@ class kmsCheck {
); );
} }
private function simpStr($str) { // 简化版本名称
preg_match_all('/[0-9a-zA-Z]/', $str, $match);
return implode('', $match[0]);
}
public function getKmsVersions($type) {
$kmsKeys = json_decode(file_get_contents($this->api . '/' . $type . '/json'), true);
foreach ($kmsKeys as $version => $kmsKey) {
$buttons[] = array([ // 生成按钮列表
'text' => $version,
'callback_data' => '/kms ' . $this->simpStr($version)
]);
}
$buttons[] = array([
'text' => '<< Go back <<',
'callback_data' => '/kms keys'
]);
return array(
'text' => 'Which version did you need?',
'reply_markup' => json_encode(array( // 显示列表按钮
'inline_keyboard' => $buttons
))
);
}
public function getKmsKeys($targetVersion) { // 显示指定版本的KMS密钥列表
$kmsKeys = json_decode(file_get_contents($this->api . '/json'), true);
foreach ($kmsKeys as $version => $kmsKey) { // 比对压缩以后的名称
if ($this->simpStr($version) === $targetVersion) { break; } // 匹配成功
}
$msg = '*' . $version . ' KMS Keys*' . PHP_EOL . PHP_EOL;
foreach ($kmsKey as $row) {
$msg .= $row['name'] . ':`' . $row['key'] . '`' . PHP_EOL . PHP_EOL;
}
return array(
'parse_mode' => 'Markdown',
'text' => $msg
);
}
public function checkKms($host, $port) { public function checkKms($host, $port) {
$server = $host . ':' . $port; $server = $host . ':' . $port;
$url = $this->api . 'host=' . $host . '&port=' . $port; $url = $this->api . '/check?host=' . $host . '&port=' . $port;
$content = json_decode(file_get_contents($url), true); // 请求上游接口 $content = json_decode(file_get_contents($url), true); // 请求上游接口
switch ($content['status']) { switch ($content['status']) {
case 'ok': case 'ok':
@ -80,11 +120,17 @@ class kmsCheck {
} }
function kmsCheck($rawParam) { // KMS测试入口 function kmsCheck($rawParam) { // KMS测试入口
global $chatId; global $chatId, $messageId;
if ($rawParam == '' || $rawParam === 'help') { // 显示使用说明 if ($rawParam == '' || $rawParam === 'help') { // 显示使用说明
sendMessage($chatId, array( sendMessage($chatId, array(
'parse_mode' => 'Markdown', 'parse_mode' => 'Markdown',
'text' => '*Usage:* `/kms IP/Domain[:port]`' 'text' => '*Usage:* `/kms IP/Domain[:port]`',
'reply_markup' => json_encode(array( // 获取KMS密钥按钮
'inline_keyboard' => array([[
'text' => 'Get KMS Keys',
'callback_data' => '/kms keys'
]])
))
)); ));
return; return;
} }
@ -102,8 +148,65 @@ function kmsCheck($rawParam) { // KMS测试入口
sendPayload(array( sendPayload(array(
'method' => 'editMessageText', 'method' => 'editMessageText',
'chat_id' => $chatId, 'chat_id' => $chatId,
'message_id' => $message['result']['message_id'] 'message_id' => $messageId,
) + (new kmsCheck)->checkKms($check['host'], $check['port'])); // 发起查询并返回结果 ) + (new kmsCheck)->checkKms($check['host'], $check['port'])); // 发起查询并返回结果
} }
function kmsCheckCallback($rawParam) {
global $chatId, $messageId;
$selectMsg = array(
'text' => 'Which one did you need?',
'reply_markup' => json_encode(array(
'inline_keyboard' => array(
array([
'text' => 'Windows',
'callback_data' => '/kms win'
]),
array([
'text' => 'Windows Server',
'callback_data' => '/kms win-server'
]),
array([
'text' => 'Activation Command',
'callback_data' => '/kms cmd'
])
)
))
);
$actiCmd = '```' . PHP_EOL . 'slmgr /upk' . PHP_EOL . 'slmgr /ipk {KMS_KEY}' . PHP_EOL;
$actiCmd .= 'slmgr /skms {KMS_HOST}' . PHP_EOL . 'slmgr /ato' . PHP_EOL . 'slmgr /dlv';
$actiCmd .= PHP_EOL . '```';
switch ($rawParam) {
case 'keys':
sendPayload(array(
'method' => 'editMessageText',
'chat_id' => $chatId,
'message_id' => $messageId,
) + $selectMsg);
return;
case 'cmd':
sendPayload(array(
'method' => 'editMessageText',
'chat_id' => $chatId,
'message_id' => $messageId,
'parse_mode' => 'Markdown',
'text' => $actiCmd
));
return;
case 'win':
case 'win-server':
sendPayload(array(
'method' => 'editMessageText',
'chat_id' => $chatId,
'message_id' => $messageId,
) + (new kmsCheck)->getKmsVersions($rawParam));
return;
}
sendPayload(array(
'method' => 'editMessageText',
'chat_id' => $chatId,
'message_id' => $messageId
) + (new kmsCheck)->getKmsKeys($rawParam));
}
?> ?>

Loading…
Cancel
Save