Browse Source

feat: kms keys in html page

master
dnomd343 2 years ago
parent
commit
e9a5038b84
  1. 14
      src/Basis.php
  2. 17
      src/KeysCli.php
  3. 22
      src/KeysWeb.php

14
src/Basis.php

@ -0,0 +1,14 @@
<?php
function genStr(int $length, string $fillStr = ' '): string { // generate a string of specified length
return str_pad('', $length, $fillStr);
}
function lenUtf8(string $str): int { // get string length (Chinese -> 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'];
}

17
src/Cli.php → src/KeysCli.php

@ -1,16 +1,8 @@
<?php
function genStr(int $length, string $fillStr = ' '): string { // generate a string of specified length
return str_pad('', $length, $fillStr);
}
function lenUtf8(string $str): int { // get string length (Chinese -> 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']));

22
src/KeysWeb.php

@ -0,0 +1,22 @@
<?php
function showKeysWeb(array $kmsKeys, string $header): void { // show kms keys in html
echo '<!DOCTYPE html><html><head><meta charset="utf-8">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
echo '<link rel="stylesheet" href="./assets/style.css" /></head>';
echo "<title>$header</title><body><div>";
foreach ($kmsKeys as $title => $keys) {
echo "<h2>$title</h2>";
echo '<table><thead><tr><th>操作系统</th><th>KMS密钥</th></tr></thead><tbody>';
foreach ($keys as $caption => $key) {
echo "<tr><td>$caption</td><td>$key</td></tr>";
}
echo '</tbody></table>';
}
echo '</div></body></html>';
}
require_once 'Basis.php';
$keys = getKeys();
showKeysWeb($keys, 'Windows KMS Keys');
Loading…
Cancel
Save