Browse Source

feat: add server port in win active message

master
Dnomd343 2 years ago
parent
commit
a5db772bcb
  1. 2
      kms.php
  2. 3
      src/Basis.php
  3. 13
      src/KmsCli.php
  4. 11
      src/KmsWeb.php
  5. 6
      src/Route.php

2
kms.php

@ -3,7 +3,7 @@
# TODO: add PORT option # TODO: add PORT option
$version = 'v1.2.1'; $version = 'v1.2.2';
require_once './src/Daemon.php'; require_once './src/Daemon.php';
require_once './src/Logger.php'; require_once './src/Logger.php';

3
src/Basis.php

@ -60,7 +60,8 @@ function getHost(): string {
return 'KMS_HOST'; return 'KMS_HOST';
} }
$host = v6DelBracket($match[1][0]); // try to remove ipv6 bracket again $host = v6DelBracket($match[1][0]); // try to remove ipv6 bracket again
$host = ($host == '127.0.0.1' or $host == '::1') ? 'KMS_HOST' : $host; // ignore localhost forward // TODO: recover $host param
// $host = ($host == '127.0.0.1' or $host == '::1') ? 'KMS_HOST' : $host; // ignore localhost forward
return (isHost($host)) ? $host : 'KMS_HOST'; return (isHost($host)) ? $host : 'KMS_HOST';
} }

13
src/KmsCli.php

@ -19,13 +19,20 @@ function showKeysCli(array $kmsKeys, bool $isGbk = false): void { // show kms ke
echo $isGbk ? iconv('utf-8', 'gb2312', $ret) : $ret; // utf-8 or gbk echo $isGbk ? iconv('utf-8', 'gb2312', $ret) : $ret; // utf-8 or gbk
} }
function showHelpCli(string $host): void { // show help message in shell function showHelpCli(string $host, int $port): void { // show help message in shell
$length = strlen($host); $kmsServer = $host;
if (isIPv6($host)) { // host without ipv6 bracket
$kmsServer = '[' . $host . ']';
}
if ($port != 1688) {
$kmsServer = $kmsServer . ':' . $port; // add kms server port
}
$length = strlen($kmsServer);
echo "\n" . genStr(floor(($length - 2) / 2)) . "Activation Command\n"; echo "\n" . genStr(floor(($length - 2) / 2)) . "Activation Command\n";
echo "┏" . genStr($length + 14, '-') . "┓\n"; echo "┏" . genStr($length + 14, '-') . "┓\n";
echo "| slmgr /upk" . genStr($length + 3) . "|\n"; echo "| slmgr /upk" . genStr($length + 3) . "|\n";
echo "| slmgr /ipk KMS_KEY" . genStr($length - 5) . "|\n"; echo "| slmgr /ipk KMS_KEY" . genStr($length - 5) . "|\n";
echo "| slmgr /skms $host |\n"; echo "| slmgr /skms $kmsServer |\n";
echo "| slmgr /ato" . genStr($length + 3) . "|\n"; echo "| slmgr /ato" . genStr($length + 3) . "|\n";
echo "| slmgr /dlv" . genStr($length + 3) . "|\n"; echo "| slmgr /dlv" . genStr($length + 3) . "|\n";
echo "┗" . genStr($length + 14, '-') . "┛\n\n"; echo "┗" . genStr($length + 14, '-') . "┛\n\n";

11
src/KmsWeb.php

@ -16,13 +16,20 @@ function showKeysHtml(array $kmsKeys, string $header): void { // show kms keys i
echo '</div></body></html>'; echo '</div></body></html>';
} }
function showHelpHtml(string $host): void { // show help message in html function showHelpHtml(string $host, int $port): void { // show help message in html
$kmsServer = $host;
if (isIPv6($host)) { // host without ipv6 bracket
$kmsServer = '[' . $host . ']';
}
if ($port != 1688) {
$kmsServer = $kmsServer . ':' . $port; // add kms server port
}
echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">'; echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">'; echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
echo '<link rel="stylesheet" href="./assets/style.css" />'; echo '<link rel="stylesheet" href="./assets/style.css" />';
echo "<title>Windows Activation</title></head>\n"; echo "<title>Windows Activation</title></head>\n";
echo '<body><div><h2>Windows KMS Activation</h2><pre>'; echo '<body><div><h2>Windows KMS Activation</h2><pre>';
echo "<code> slmgr /upk\n slmgr /ipk KMS_KEY\n slmgr /skms $host\n slmgr /ato\n slmgr /dlv </code>"; echo "<code> slmgr /upk\n slmgr /ipk KMS_KEY\n slmgr /skms $kmsServer\n slmgr /ato\n slmgr /dlv </code>";
echo '</pre><p><a href="./office">KMS (Office)</a><br>'; echo '</pre><p><a href="./office">KMS (Office)</a><br>';
echo '<a href="./win">KMS_KEY (Windows)</a><br>'; echo '<a href="./win">KMS_KEY (Windows)</a><br>';
echo '<a href="./win-server">KMS_KEY (Windows Server)</a></p></div></body></html>'; echo '<a href="./win-server">KMS_KEY (Windows Server)</a></p></div></body></html>';

6
src/Route.php

@ -5,6 +5,10 @@ require_once 'Check.php';
require_once 'KmsCli.php'; require_once 'KmsCli.php';
require_once 'KmsWeb.php'; require_once 'KmsWeb.php';
// TODO: get kms port from env
//$kmsPort = 1688;
$kmsPort = 1689;
$kmsHost = getHost(); // kms server address $kmsHost = getHost(); // kms server address
$url = $_SERVER['DOCUMENT_URI']; // request url $url = $_SERVER['DOCUMENT_URI']; // request url
$isCli = ($_GET['cli'] == 'true'); // shell or web browser $isCli = ($_GET['cli'] == 'true'); // shell or web browser
@ -22,7 +26,7 @@ if ($url == '/win/json' or $url == '/win-server/json') {
// start route process // start route process
if ($url == '/' or $url == '/help') { if ($url == '/' or $url == '/help') {
$isCli ? showHelpCli($kmsHost) : showHelpHtml($kmsHost); // show help message $isCli ? showHelpCli($kmsHost, $kmsPort) : showHelpHtml($kmsHost, $kmsPort); // show help message
} else if ($url == '/office') { } else if ($url == '/office') {
$isCli ? showOfficeCli($kmsHost) : showOfficeHtml($kmsHost); // show office commands $isCli ? showOfficeCli($kmsHost) : showOfficeHtml($kmsHost); // show office commands
} else if ($url == '/win' or $url == '/win-server') { } else if ($url == '/win' or $url == '/win-server') {

Loading…
Cancel
Save