Browse Source

feat: kms server

master
Dnomd343 3 years ago
commit
363a81bb99
  1. BIN
      fonts/RobotoMono-Regular.woff
  2. BIN
      fonts/lato-black.woff
  3. BIN
      fonts/lato-normal.woff
  4. 43
      kms-cli.php
  5. 40
      kms-help.php
  6. BIN
      kms-keys.db
  7. 43
      kms-keys.php
  8. 34
      kms-web.php
  9. 38
      route.php
  10. 108
      style.css

BIN
fonts/RobotoMono-Regular.woff

Binary file not shown.

BIN
fonts/lato-black.woff

Binary file not shown.

BIN
fonts/lato-normal.woff

Binary file not shown.

43
kms-cli.php

@ -0,0 +1,43 @@
<?php
// 请求方式:showWinKeys() | showWinServerKeys()
require_once 'kms-keys.php';
function showVersion($title, $content) {
$length = 0;
foreach ($content as $row) { // 获取最长的字符串长度
$strLength = strlen(iconv('utf-8', 'gb2312', $row['name']));
if ($length < $strLength) {
$length = $strLength;
}
}
$strLength = strlen(iconv('utf-8', 'gb2312', $title)); // 获取标题长度
echo str_pad('', floor(($length - $strLength + 36) / 2), ' ') . $title . PHP_EOL; // 居中输出标题
echo '┏' . str_pad('', $length + 34, '-') . '┓' . PHP_EOL;
foreach ($content as $row) { // 显示表格主体
$strLength = strlen(iconv('utf-8', 'gb2312', $row['name']));
echo '| ' . $row['name'] . str_pad('', $length - $strLength, ' ') . ' | ';
echo $row['key'] . ' |' . PHP_EOL;
}
echo '┗' . str_pad('', $length + 34, '-') . '┛' . PHP_EOL;
}
function showKmsKeys($kmsKeys) { // 命令行显示KMS密钥
foreach ($kmsKeys as $versionName => $versionContent) {
echo PHP_EOL;
showVersion($versionName, $versionContent); // 逐个显示表格
}
}
function showWinKeys() { // 显示Windows的KMS密钥
$kmsKeys = getKmsKeys('win');
showKmsKeys($kmsKeys);
}
function showWinServerKeys() { // 显示Windows Server的KMS密钥
$kmsKeys = array_reverse(getKmsKeys('win-server'));
showKmsKeys($kmsKeys);
}
?>

40
kms-help.php

@ -0,0 +1,40 @@
<?php
function showHelp() {
global $webSite;
$length = strlen($webSite);
echo PHP_EOL;
echo str_pad('', floor(($length - 2) / 2), ' ') . 'Activation Command' . PHP_EOL;
echo '┏' . str_pad('', $length + 14, '-') . '┓' . PHP_EOL;
echo '| slmgr /upk' . str_pad('', $length + 3, ' ') . '|' . PHP_EOL;
echo '| slmgr /ipk {KMS_KEY}' . str_pad('', $length - 7, ' ') . '|' . PHP_EOL;
echo '| slmgr /skms ' . $webSite . ' |' . PHP_EOL;
echo '| slmgr /ato' . str_pad('', $length + 3, ' ') . '|' . PHP_EOL;
echo '| slmgr /dlv' . str_pad('', $length + 3, ' ') . '|' . PHP_EOL;
echo '┗' . str_pad('', $length + 14, '-') . '┛' . PHP_EOL;
echo PHP_EOL;
echo 'KMS_KEY -> http://' . $webSite . '/win' . PHP_EOL;
echo ' -> http://' . $webSite . '/win-server' . PHP_EOL;
echo PHP_EOL;
}
function webHelp() {
global $webSite;
echo '<!DOCTYPE html><html><head><meta charset="utf-8">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0"><title>';
echo 'Windows Activation';
echo '</title><link rel="stylesheet" href="./style.css" /></head>';
echo '<body><div><h2>Windows KMS Activation</h2><pre>';
echo '<code> slmgr /upk' . PHP_EOL;
echo ' slmgr /ipk {KMS_KEY}' . PHP_EOL;
echo ' slmgr /skms ' . $webSite . PHP_EOL;
echo ' slmgr /ato' . PHP_EOL;
echo ' slmgr /dlv</code>';
echo '</pre><p><a href="';
echo 'http://' . $webSite . '/win';
echo '">KMS_KEY (Windows)</a><br><a href="';
echo 'http://' . $webSite . '/win-server';
echo '">KMS_KEY (Windows Server)</a></p></div></body></html>';
}
?>

BIN
kms-keys.db

Binary file not shown.

43
kms-keys.php

@ -0,0 +1,43 @@
<?php
// 数据来源:kms-keys.db
// 请求方式:getKmsKeys($type)
// 返回格式:
// {
// "version_1": [
// {
// "name": 版本名称
// "key": KMS密钥
// },
// ···
// ],
// "version_2": [
// ···
// ],
// ···
// }
class kmsDB extends SQLite3 {
function __construct() {
$this->open('kms-keys.db'); // KMS密钥数据库
}
}
function getVersionName($type, $version_id) { // 获取对应版本的名称
$db = new kmsDB;
$res = $db->query('SELECT * FROM `' . $type . '_version` WHERE version_id=' . $version_id . ';');
return $res->fetchArray(SQLITE3_ASSOC)['version_name'];
}
function getKmsKeys($type) { // 获取所有版本的KMS密钥
$db = new kmsDB;
$res = $db->query('SELECT * FROM `' . $type . '`;');
while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
$index = $row['version'];
unset($row['version']);
$data[getVersionName($type, $index)][] = $row;
}
return $data;
}
?>

34
kms-web.php

@ -0,0 +1,34 @@
<?php
// 请求方式:webWinKeys() | webWinServerKeys()
require_once 'kms-keys.php';
function webKmsKeys($kmsKeys, $title) { // 网页显示KMS密钥
echo '<!DOCTYPE html><html><head><meta charset="utf-8">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0"><title>';
echo $title;
echo '</title><link rel="stylesheet" href="./style.css" /></head><body><div>';
foreach ($kmsKeys as $versionName => $versionContent) {
echo '<h2>' . $versionName . '</h2>';
echo '<table><thead><tr><th>操作系统</th><th>KMS密钥</th></tr></thead><tbody>';
foreach ($versionContent as $row) {
echo '<tr><td>' . $row['name'] . '</td>';
echo '<td>' . $row['key'] . '</td></tr>';
}
echo '</tbody></table>';
}
echo '</div></body></html>';
}
function webWinKeys() { // 网页显示Windows的KMS密钥
$kmsKeys = getKmsKeys('win');
webKmsKeys($kmsKeys, 'Windows KMS Keys');
}
function webWinServerKeys() { // 网页显示Windows Server的KMS密钥
$kmsKeys = array_reverse(getKmsKeys('win-server'));
webKmsKeys($kmsKeys, 'Windows Server KMS Keys');
}
?>

38
route.php

@ -0,0 +1,38 @@
<?php
include 'kms-cli.php';
include 'kms-web.php';
include 'kms-help.php';
if (isset($_SERVER['HTTP_HOST'])) {
$webSite = $_SERVER['HTTP_HOST'];
} else {
$webSite = "{HOST}";
}
$url = $_SERVER['DOCUMENT_URI'];
if ($url == '/') {
if ($_GET['cli'] == 'true') {
showHelp();
} else {
webHelp();
}
}
if ($url == '/win') {
if ($_GET['cli'] == 'true') {
showWinKeys();
} else {
webWinKeys();
}
}
if ($url == '/win-server') {
if ($_GET['cli'] == 'true') {
showWinServerKeys();
} else {
webWinServerKeys();
}
}
?>

108
style.css

@ -0,0 +1,108 @@
@font-face {
font-family: Lato;
font-style: normal;
font-weight: 400;
src: url(./fonts/lato-normal.woff) format("woff")
}
@font-face {
font-family: Lato;
font-style: normal;
font-weight: 600;
src: url(./fonts/lato-black.woff) format("woff")
}
@font-face {
font-family: Roboto Mono;
font-style: normal;
font-weight: 400;
src: url(./fonts/RobotoMono-Regular.woff) format("woff");
}
body,
html {
margin: 0;
padding: 0;
color: rgba(0, 0, 0, .75);
font-size: 16px;
font-family: Lato, sans-serif;
font-variant-ligatures: common-ligatures;
line-height: 1.67;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale
}
div {
margin-bottom: 180px;
margin-left: auto;
margin-right: auto;
padding-left: 30px;
padding-right: 30px;
max-width: 750px
}
h2 {
margin: 1.8em 0;
line-height: 1.33
}
h2:after {
content: "";
display: block;
position: relative;
top: .33em;
border-bottom: 1px solid hsla(0, 0%, 50%, .33)
}
a {
color: #0c93e4;
text-decoration: underline;
text-decoration-skip: ink;
background-color: transparent;
-webkit-text-decoration-skip: objects;
}
a:focus,
a:hover {
text-decoration: none
}
code,
pre {
font-family: Roboto Mono, monospace;
font-size: .85em
}
pre * {
font-size: inherit
}
pre>code {
background-color: rgba(0, 0, 0, .05);
display: block;
padding: .5em;
-webkit-text-size-adjust: none;
overflow-x: auto;
white-space: pre
}
table {
background-color: transparent;
border-collapse: collapse;
border-spacing: 0
}
td,
th {
border-right: 1px solid #dcdcdc;
padding: 8px 12px
}
td {
border-top: 1px solid #dcdcdc
}
td:last-child,
th:last-child {
border-right: 0
}
Loading…
Cancel
Save