mirror of https://github.com/dnomd343/kms-server
dnomd343
2 years ago
3 changed files with 53 additions and 7 deletions
@ -1,15 +1,46 @@ |
|||||
<?php |
<?php |
||||
|
|
||||
|
require_once 'Basis.php'; |
||||
require_once 'Process.php'; |
require_once 'Process.php'; |
||||
|
|
||||
function kmsCheck(string $host, int $port = 1688): bool { |
function vlmcsCheck(string $host, int $port = 1688): bool { |
||||
# TODO: ipv6 host add bracket |
$host = str_contains($host, ':') ? "[$host]" : $host; // ipv6 add bracket |
||||
$vlmcs = new Process(['vlmcs', $host . ':' . $port], $capture = true); |
$vlmcs = new Process(['vlmcs', $host . ':' . $port], true); |
||||
while($vlmcs->isAlive()); // wait vlmcs exit |
while($vlmcs->isAlive()); // wait vlmcs exit |
||||
preg_match_all('/Sending activation request \(KMS V6\)/', $vlmcs->getStdout(), $match); |
preg_match_all('/Sending activation request \(KMS V6\)/', $vlmcs->getStdout(), $match); |
||||
return count($match[0]) != 0; |
return count($match[0]) != 0; |
||||
} |
} |
||||
|
|
||||
$host = 'kms.343.re'; |
function kmsCheck(): array { |
||||
echo "check $host -> "; |
if (!isset($_GET['host'])) { // missing host param |
||||
echo (kmsCheck($host) ? 'yes' : 'no') . PHP_EOL; |
return array( |
||||
|
'success' => false, |
||||
|
'message' => 'missing host param' |
||||
|
); |
||||
|
} |
||||
|
$host = $_GET['host']; |
||||
|
if (!isIPv4($host) and !isIPv6($host) and !isDomain($host)) { // invalid host |
||||
|
return array( |
||||
|
'success' => false, |
||||
|
'message' => 'invalid host' |
||||
|
); |
||||
|
} |
||||
|
$port = $_GET['port'] ?? 1688; |
||||
|
if ($port > 65535 or $port < 0) { // invalid port |
||||
|
return array( |
||||
|
'success' => false, |
||||
|
'message' => 'invalid port' |
||||
|
); |
||||
|
} |
||||
|
if (vlmcsCheck($host, $port)) { // KMS server available |
||||
|
return array( |
||||
|
'success' => true, |
||||
|
'message' => 'kms server available' |
||||
|
); |
||||
|
} else { // KMS server couldn't reach |
||||
|
return array( |
||||
|
'success' => false, |
||||
|
'message' => 'kms server connect failed' |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
Loading…
Reference in new issue