From e9a5038b84add128e64c141ecd9960f2c75066e0 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Wed, 10 Aug 2022 18:10:13 +0800 Subject: [PATCH] feat: kms keys in html page --- src/Basis.php | 14 ++++++++++++++ src/{Cli.php => KeysCli.php} | 17 ++--------------- src/KeysWeb.php | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 src/Basis.php rename src/{Cli.php => KeysCli.php} (52%) create mode 100644 src/KeysWeb.php diff --git a/src/Basis.php b/src/Basis.php new file mode 100644 index 0000000..389e71b --- /dev/null +++ b/src/Basis.php @@ -0,0 +1,14 @@ + 2) + return strlen(iconv('utf-8', 'gb2312', $str)); +} + +function getKeys(bool $isWinServer = false): array { // get kms keys asset + $keysAsset = json_decode(file_get_contents('../assets/kms-keys.json'), true); + return $isWinServer ? array_reverse($keysAsset['win-server']) : $keysAsset['win']; +} diff --git a/src/Cli.php b/src/KeysCli.php similarity index 52% rename from src/Cli.php rename to src/KeysCli.php index 4f8ec01..2c77390 100644 --- a/src/Cli.php +++ b/src/KeysCli.php @@ -1,16 +1,8 @@ 2) -// preg_match_all('/./us', $str, $match); -// return count($match[0]); - return strlen(iconv('utf-8', 'gb2312', $str)); -} +require_once 'Basis.php'; -function showKeys(array $kmsKeys, bool $isGbk = false): void { // show kms keys in shell +function showKeysCli(array $kmsKeys, bool $isGbk = false): void { // show kms keys in shell $ret = PHP_EOL; foreach ($kmsKeys as $title => $keys) { $length = 0; @@ -26,8 +18,3 @@ function showKeys(array $kmsKeys, bool $isGbk = false): void { // show kms keys } echo $isGbk ? iconv('utf-8', 'gb2312', $ret) : $ret; // utf-8 or gbk } - -$keyAsset = json_decode(file_get_contents('../assets/kms-keys.json'), true); -showKeys($keyAsset['win']); -echo '========================================================================================' . PHP_EOL; -showKeys(array_reverse($keyAsset['win-server'])); diff --git a/src/KeysWeb.php b/src/KeysWeb.php new file mode 100644 index 0000000..5da6a7d --- /dev/null +++ b/src/KeysWeb.php @@ -0,0 +1,22 @@ +'; + echo ''; + echo ''; + echo "$header
"; + foreach ($kmsKeys as $title => $keys) { + echo "

$title

"; + echo ''; + foreach ($keys as $caption => $key) { + echo ""; + } + echo '
操作系统KMS密钥
$caption$key
'; + } + echo '
'; +} + +require_once 'Basis.php'; + +$keys = getKeys(); +showKeysWeb($keys, 'Windows KMS Keys');