diff --git a/web/cli.php b/web/cli.php new file mode 100644 index 0000000..3749386 --- /dev/null +++ b/web/cli.php @@ -0,0 +1,103 @@ + `| xxx |` + $titleLen = stringLen($title); + $bodyOffset = $titleOffset = 0; + if ($titleLen > $bodyLen) { // title longer than body + $bodyOffset = floor(($titleLen - $bodyLen) / 2); // body move right + } else { + $titleOffset = floor(($bodyLen - $titleLen) / 2); // title move right + } + + printf("%s%s\n", stringGen($titleOffset), $title); // show list title + printf("%s┏-%s-┓\n", stringGen($bodyOffset), stringGen($contentLen, '-')); + foreach ($content as $row) { // show list body + printf("%s| %s%s |\n", + stringGen($bodyOffset), $row, stringGen($contentLen - stringLen($row)) + ); + } + printf("%s┗-%s-┛\n", stringGen($bodyOffset), stringGen($contentLen, '-')); +} + +/// Print table with two columns under command line. +/// +/// Example +/// ┏---------------┓ +/// | xxx | xxxxxx | +/// | xxxx | xxxxxx | +/// | xx | xxxxxx | +/// ┗---------------┛ +function showCliTable(string $title, array $content): void { + $length = 0; + foreach ($content as $row => $_) { // found the longest item + $length = ($length < stringLen($row)) ? stringLen($row) : $length; + } + $cache = array(); + foreach ($content as $row_1 => $row_2) { + $cache[] = $row_1 . stringGen($length - stringLen($row_1)) . ' | ' . $row_2; + } + showCliList($title, $cache); // render as list +} + +class CliOutput { + /// Print help message under command line. + public function showHelp(string $host, string $port): void { + if (isIPv6($host)) { + $host = "[$host]"; // add ipv6 bracket + } + $kmsServer = $host; + $urlPrefix = "http://$host"; + if ($port != 1688) { // not default port + $kmsServer = "$kmsServer:$port"; // add service port + } + + echo PHP_EOL; + showCliList('Windows Activation', [ + 'slmgr /upk', + 'slmgr /ipk KMS_KEY', + "slmgr /skms $kmsServer", + 'slmgr /ato', + 'slmgr /dlv', + ]); + echo "\nKMS_KEY\n"; + echo " -> $urlPrefix/win\n"; + echo " -> $urlPrefix/win-server\n"; + echo "\nOffice\n"; + echo " -> $urlPrefix/office\n\n"; + } + + /// Print GVLKs under command line. + public function showGvlks(bool $isWinServer): void { + echo PHP_EOL; + foreach (loadGvlks($isWinServer) as $version => $content) { + showCliTable($version, $content); + echo PHP_EOL; + } + } + +} + +$cli = new CliOutput(); +//$cli->showHelp('kms.343.re', 1688); +//$cli->showHelp('kms.343.re', 1689); +//$cli->showHelp('1.1.1.1', 1689); +//$cli->showHelp('fc00::', 1689); + +$cli->showGvlks(false); +$cli->showGvlks(true); diff --git a/web/utils.php b/web/utils.php index fe2b777..dcadf75 100644 --- a/web/utils.php +++ b/web/utils.php @@ -1,5 +1,13 @@ $col_2) { // found the longest length - $leftLen = ($leftLen < stringLen($col_1)) ? stringLen($col_1) : $leftLen; - $rightLen = ($rightLen < stringLen($col_2)) ? stringLen($col_2) : $rightLen; - } - $titleOffset = floor(($leftLen + $rightLen + 7 - stringLen($title)) / 2); - - echo stringGen($titleOffset) . $title . PHP_EOL; // show table title - echo '┏' . stringGen($leftLen + $rightLen + 5, '-') . '┓' . PHP_EOL; - foreach ($content as $col_1 => $col_2) { // show table body - echo '| ' . $col_1 . stringGen($leftLen - stringLen($col_1)) . ' | '; - echo $col_2 . stringGen($rightLen - stringLen($col_2)) . ' |' . PHP_EOL; - } - echo '┗' . stringGen($leftLen + $rightLen + 5, '-') . '┛' . PHP_EOL; -} - -echo PHP_EOL; -foreach (loadGvlks(false) as $version => $content) { - showCliTable($version, $content); - echo PHP_EOL; -}