mirror of https://github.com/dnomd343/kms-server
dnomd343
2 years ago
8 changed files with 0 additions and 483 deletions
@ -1,60 +0,0 @@ |
|||
<?php |
|||
|
|||
function checkKms($config) { // 检测KMS服务器是否可用 |
|||
if (isset($config['host'])) { |
|||
$host = $config['host']; |
|||
} else { // host参数必选 |
|||
return array( |
|||
'status' => 'error', |
|||
'message' => 'host param not exist' |
|||
); |
|||
} |
|||
if (isset($config['port'])) { |
|||
$port = $config['port']; |
|||
} else { |
|||
$port = 1688; // 默认KMS端口 |
|||
} |
|||
if (isset($config['site']) && $config['site'] !== '') { |
|||
$site = $config['site']; |
|||
} else { |
|||
$site = null; // site参数可选 |
|||
} |
|||
$cmd = 'vlmcs '; // 生成vlmcs测试命令 |
|||
if (isDomain($host) || isIPv4($host)) { |
|||
$cmd .= $host; |
|||
} else if (isIPv6($host)) { |
|||
$cmd .= '[' . $host . ']'; // IPv6地址需用中括号包围 |
|||
} else { |
|||
return array( // host内容不是 IPv4/IPv6/Domain |
|||
'status' => 'error', |
|||
'message' => 'illegal host' |
|||
); |
|||
} |
|||
if ($port > 65535 || $port < 0) { // 端口不存在 |
|||
return array( |
|||
'status' => 'error', |
|||
'message' => 'illegal port' |
|||
); |
|||
} else { |
|||
$cmd .= ':' . $port; // 命令中加入端口信息 |
|||
} |
|||
if ($site !== null) { |
|||
$cmd .= ' -w ' . $site; // 加入site参数 |
|||
} |
|||
$cmd .= ' -G temp'; |
|||
$raw = shell_exec($cmd); // 执行vlmcs测试 |
|||
preg_match_all('/Sending activation request \(KMS V6\)/', $raw, $match); |
|||
if (count($match[0]) == 6) { // KMS服务器连接成功 |
|||
return array( |
|||
'status' => 'ok', |
|||
'message' => 'success' |
|||
); |
|||
} else { // KMS服务器连接异常 |
|||
return array( |
|||
'status' => 'error', |
|||
'message' => 'connect fail' |
|||
); |
|||
} |
|||
} |
|||
|
|||
?> |
@ -1,52 +0,0 @@ |
|||
<?php |
|||
|
|||
// 请求方式:showWinKeys() | showWinServerKeys() |
|||
|
|||
require_once 'kms-keys.php'; |
|||
|
|||
function show($str) { // GBK兼容 |
|||
global $gbk; |
|||
if ($gbk) { |
|||
return iconv('utf-8', 'gb2312', $str); |
|||
} else { |
|||
return $str; |
|||
} |
|||
} |
|||
|
|||
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), ' ') . show($title) . PHP_EOL; // 居中输出标题 |
|||
echo '┏' . str_pad('', $length + 34, '-') . '┓' . PHP_EOL; |
|||
foreach ($content as $row) { // 显示表格主体 |
|||
$strLength = strlen(iconv('utf-8', 'gb2312', $row['name'])); |
|||
echo '| ' . show($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); |
|||
} |
|||
|
|||
?> |
@ -1,47 +0,0 @@ |
|||
<?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 'Office -> http://' . $webSite . '/office' . PHP_EOL; |
|||
echo PHP_EOL; |
|||
echo 'KMS_KEY -> http://' . $webSite . '/win' . PHP_EOL; |
|||
echo ' -> http://' . $webSite . '/win-server' . PHP_EOL; |
|||
echo PHP_EOL; |
|||
echo 'KMS_KEY(GBK) -> http://' . $webSite . '/win/gbk' . PHP_EOL; |
|||
echo ' -> http://' . $webSite . '/win-server/gbk' . 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="./assets/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 . '/office'; |
|||
echo '">KMS (Office)</a><br><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>'; |
|||
} |
|||
|
|||
?> |
Binary file not shown.
@ -1,43 +0,0 @@ |
|||
<?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; |
|||
} |
|||
|
|||
?> |
@ -1,116 +0,0 @@ |
|||
<?php |
|||
|
|||
$office['2010'] = 'if exist "%ProgramFiles%\Microsoft Office\Office14\ospp.vbs" cd /d "%ProgramFiles%\Microsoft Office\Office14" |
|||
if exist "%ProgramFiles(x86)%\Microsoft Office\Office14\ospp.vbs" cd /d "%ProgramFiles(x86)%\Microsoft Office\Office14" |
|||
cscript ospp.vbs /inpkey:VYBBJ-TRJPB-QFQRF-QFT4D-H3GVB'; |
|||
|
|||
$office['2013'] = 'if exist "%ProgramFiles%\Microsoft Office\Office15\ospp.vbs" cd /d "%ProgramFiles%\Microsoft Office\Office15" |
|||
if exist "%ProgramFiles(x86)%\Microsoft Office\Office15\ospp.vbs" cd /d "%ProgramFiles(x86)%\Microsoft Office\Office15" |
|||
cscript ospp.vbs /inpkey:YC7DK-G2NP3-2QQC3-J6H88-GVGXT'; |
|||
|
|||
$office['2016'] = 'if exist "%ProgramFiles%\Microsoft Office\Office16\ospp.vbs" cd /d "%ProgramFiles%\Microsoft Office\Office16" |
|||
if exist "%ProgramFiles(x86)%\Microsoft Office\Office16\ospp.vbs" cd /d "%ProgramFiles(x86)%\Microsoft Office\Office16" |
|||
cscript ospp.vbs /inpkey:XQNVK-8JYDB-WJ9W3-YJ8YR-WFG99'; |
|||
|
|||
$office['2019'] = 'if exist "%ProgramFiles%\Microsoft Office\Office16\ospp.vbs" cd /d "%ProgramFiles%\Microsoft Office\Office16" |
|||
if exist "%ProgramFiles(x86)%\Microsoft Office\Office16\ospp.vbs" cd /d "%ProgramFiles(x86)%\Microsoft Office\Office16" |
|||
cscript ospp.vbs /inpkey:NMMKJ-6RK4F-KMJVX-8D9MJ-6MWKP'; |
|||
|
|||
function loadOsppInfo() { // 初始化ospp信息 |
|||
global $kmsHost; |
|||
global $osppOption, $osppDescription, $osppDescriptionCn; |
|||
|
|||
$osppOption[] = '/dstatus'; |
|||
$osppDescription[] = 'Displays license information for installed product keys.'; |
|||
$osppDescriptionCn[] = '显示当前已安装产品密钥的许可证信息'; |
|||
|
|||
$osppOption[] = '/dstatusall'; |
|||
$osppDescription[] = 'Displays license information for all installed licenses.'; |
|||
$osppDescriptionCn[] = '显示当前已安装的所有许可证信息'; |
|||
|
|||
$osppOption[] = '/unpkey:XXXXX'; |
|||
$osppDescription[] = 'Uninstalls an product key with the last five digits of it.'; |
|||
$osppDescriptionCn[] = '卸载已安装的产品密钥(最后5位)'; |
|||
|
|||
$osppOption[] = '/inpkey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX'; |
|||
$osppDescription[] = 'Installs a product key with a user-provided product key.'; |
|||
$osppDescriptionCn[] = '安装产品密钥'; |
|||
|
|||
$osppOption[] = '/sethst:' . $kmsHost; |
|||
$osppDescription[] = 'Sets a KMS host name with a user-provided host name.'; |
|||
$osppDescriptionCn[] = '设置 KMS 主机名'; |
|||
|
|||
$osppOption[] = '/remhst'; |
|||
$osppDescription[] = 'Removes KMS host name and sets port to default.'; |
|||
$osppDescriptionCn[] = '删除 KMS 主机名'; |
|||
|
|||
$osppOption[] = '/act'; |
|||
$osppDescription[] = 'Activates installed Office product keys.'; |
|||
$osppDescriptionCn[] = '激活 Office'; |
|||
} |
|||
|
|||
function loadOfficeCmd() { // 初始化Office激活命令 |
|||
global $kmsHost, $office; |
|||
$activeCmd = 'cscript ospp.vbs /sethst:' . $kmsHost . PHP_EOL . 'cscript ospp.vbs /act'; |
|||
$activeCmd .= PHP_EOL . 'cscript ospp.vbs /dstatus' . PHP_EOL; |
|||
foreach ($office as $index => $officeKmsCmd) { |
|||
$office[$index] .= PHP_EOL . $activeCmd; |
|||
} |
|||
} |
|||
|
|||
function showOfficeHelp() { // 命令行输出Office激活帮助 |
|||
loadOsppInfo(); |
|||
loadOfficeCmd(); |
|||
global $office, $osppOption, $osppDescription, $osppDescriptionCn; |
|||
echo PHP_EOL; |
|||
foreach ($office as $index => $officeKmsCmd) { |
|||
echo str_pad('', 34, ' ') . 'Office Professional Plus ' . $index . ' VL Activation Command' . PHP_EOL; |
|||
echo str_pad('', 120, '-') . PHP_EOL; |
|||
echo $officeKmsCmd; |
|||
echo str_pad('', 120, '-') . PHP_EOL . PHP_EOL; |
|||
} |
|||
$length = 0; |
|||
$length_first = 0; |
|||
foreach ($osppOption as $index => $option) { // 获取最长的字符串长度 |
|||
$strLength = strlen($option) + strlen($osppDescription[$index]); |
|||
if ($length < $strLength) { |
|||
$length = $strLength; |
|||
$length_first = strlen($option); |
|||
} |
|||
} |
|||
$title = 'Common activation commands'; |
|||
echo str_pad('', floor(($length - strlen($title) + 26) / 2), ' ') . $title . PHP_EOL; |
|||
echo '┏' . str_pad('', $length + 24, '-') . '┓' . PHP_EOL; |
|||
foreach ($osppOption as $index => $option) { |
|||
echo '| cscript ospp.vbs ' . str_pad($osppOption[$index], $length_first, ' ') . ' | '; |
|||
echo str_pad($osppDescription[$index], $length - $length_first + 2, ' ') . ' |' . PHP_EOL; |
|||
} |
|||
echo '┗' . str_pad('', $length + 24, '-') . '┛' . PHP_EOL . PHP_EOL; |
|||
echo 'These commands are only applicable to the VL version of Office.' . PHP_EOL; |
|||
echo 'If it is a Retail version, please convert it to Volume first.' . PHP_EOL . PHP_EOL; |
|||
} |
|||
|
|||
function webOfficeHelp() { // 网页输出Office激活帮助 |
|||
loadOsppInfo(); |
|||
loadOfficeCmd(); |
|||
global $office, $osppOption, $osppDescription, $osppDescriptionCn; |
|||
echo '<!DOCTYPE html><html><head><meta charset="utf-8">'; |
|||
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0"><title>'; |
|||
echo 'Office KMS Server'; |
|||
echo '</title><link rel="stylesheet" href="./assets/style.css" /></head><body><div>'; |
|||
foreach ($office as $officeVersion => $officeKmsCmd) { |
|||
echo '<h2>Office Professional Plus ' . $officeVersion . ' VL</h2>' . PHP_EOL; |
|||
echo '<pre><code>' . $officeKmsCmd . '</code></pre>' . PHP_EOL; |
|||
} |
|||
echo '<h2>常用激活命令</h2>' . PHP_EOL; |
|||
echo '<table><thead><tr><th>命令</th><th>说明</th></tr></thead><tbody>'; |
|||
foreach ($osppOption as $index => $option) { |
|||
echo '<tr><td>cscript ospp.vbs ' . $option . '</td>'; |
|||
echo '<td>' . $osppDescriptionCn[$index] . '</td></tr>'; |
|||
} |
|||
echo '</tbody></table><br>' . PHP_EOL; |
|||
echo '<p>以上命令仅用于激活VL版本的Office,如果当前为Retail版本,请先转化为批量授权版本。</p>' . PHP_EOL; |
|||
echo '</div></body></html>'; |
|||
} |
|||
|
|||
?> |
@ -1,34 +0,0 @@ |
|||
<?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="./assets/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'); |
|||
} |
|||
|
|||
?> |
@ -1,131 +0,0 @@ |
|||
<?php |
|||
|
|||
include 'kms-cli.php'; |
|||
include 'kms-web.php'; |
|||
include 'kms-help.php'; |
|||
include 'kms-office.php'; |
|||
include 'kms-check.php'; |
|||
|
|||
function isDomain($domain) { |
|||
preg_match('/^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/', $domain, $match); |
|||
return (count($match) != 0); |
|||
} |
|||
|
|||
function isIPv4($ip) { |
|||
return filter_var($ip, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4); |
|||
} |
|||
|
|||
function isIPv6($ip) { |
|||
return filter_var($ip, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6); |
|||
} |
|||
|
|||
$kmsHost = "{KMS_HOST}"; |
|||
$webSite = $kmsHost; |
|||
if (isset($_SERVER['HTTP_HOST'])) { // 获取服务URL |
|||
$webSite = $_SERVER['HTTP_HOST']; |
|||
} |
|||
if (isDomain($webSite) || isIPv4($webSite)) { // URL为域名或者IPv4地址 |
|||
$kmsHost = $webSite; |
|||
} else { |
|||
preg_match('/^[a-zA-Z0-9.-]*/', $webSite, $match); |
|||
if (count($match) != 0) { |
|||
if (isDomain($match[0]) || isIPv4($match[0])) { // 去除端口后为域名或者IPv4地址 |
|||
if ($match[0] != '127.0.0.1') { // 排除本地IP |
|||
$kmsHost = $match[0]; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
$url = $_SERVER['DOCUMENT_URI']; |
|||
$gbk = false; |
|||
|
|||
if ($url == '/' || $url == '/help') { // 操作提示 |
|||
if ($_GET['cli'] == 'true') { |
|||
showHelp(); |
|||
} else { |
|||
webHelp(); |
|||
} |
|||
exit; |
|||
} |
|||
|
|||
if ($url == '/office') { // office激活帮助 |
|||
if ($_GET['cli'] == 'true') { |
|||
showOfficeHelp(); |
|||
} else { |
|||
webOfficeHelp(); |
|||
} |
|||
exit; |
|||
} |
|||
|
|||
if ($url == '/win') { // KMS密钥获取 |
|||
if ($_GET['cli'] == 'true') { |
|||
showWinKeys(); |
|||
} else { |
|||
webWinKeys(); |
|||
} |
|||
exit; |
|||
} |
|||
if ($url == '/win-server') { |
|||
if ($_GET['cli'] == 'true') { |
|||
showWinServerKeys(); |
|||
} else { |
|||
webWinServerKeys(); |
|||
} |
|||
exit; |
|||
} |
|||
|
|||
if ($url == '/win/gbk') { // KMS密钥获取(GBK兼容) |
|||
if ($_GET['cli'] == 'true') { |
|||
$gbk = true; |
|||
showWinKeys(); |
|||
} else { |
|||
header('HTTP/1.1 302 Moved Temporarily'); |
|||
header('Location: /win'); |
|||
} |
|||
exit; |
|||
} |
|||
if ($url == '/win-server/gbk') { |
|||
if ($_GET['cli'] == 'true') { |
|||
$gbk = true; |
|||
showWinServerKeys(); |
|||
} else { |
|||
header('HTTP/1.1 302 Moved Temporarily'); |
|||
header('Location: /win-server'); |
|||
} |
|||
exit; |
|||
} |
|||
|
|||
if ($url == '/json') { // JSON格式获取KMS密钥 |
|||
header('Content-Type: application/json; charset=utf-8'); |
|||
$kmsKeys = getKmsKeys('win') + getKmsKeys('win-server'); |
|||
echo json_encode($kmsKeys); |
|||
exit; |
|||
} |
|||
if ($url == '/win/json') { |
|||
header('Content-Type: application/json; charset=utf-8'); |
|||
$kmsKeys = getKmsKeys('win'); |
|||
echo json_encode($kmsKeys); |
|||
exit; |
|||
} |
|||
if ($url == '/win-server/json') { |
|||
header('Content-Type: application/json; charset=utf-8'); |
|||
$kmsKeys = getKmsKeys('win-server'); |
|||
echo json_encode($kmsKeys); |
|||
exit; |
|||
} |
|||
|
|||
if ($url == '/check') { |
|||
header('Content-Type: application/json; charset=utf-8'); |
|||
echo json_encode(checkKms($_GET)); |
|||
exit; |
|||
} |
|||
|
|||
if ($_GET['cli'] == 'true') { // 无效请求 |
|||
echo 'Illegal Request' . PHP_EOL; |
|||
} else { |
|||
header('Content-Type: application/json; charset=utf-8'); |
|||
echo '{"status":"error","message":"Illegal Request"}'; |
|||
} |
|||
|
|||
?> |
Loading…
Reference in new issue