Browse Source

fix: kms host without port by url

master v1.0
Dnomd343 3 years ago
parent
commit
f633435621
  1. 24
      README.md
  2. 8
      backend/kms-office.php
  3. 27
      backend/route.php

24
README.md

@ -290,6 +290,7 @@ php7.3-fpm.pid php7.3-fpm.sock
```
对应Nginx配置如下
```
# RH系
fastcgi_pass 127.0.0.1:9000;
@ -303,9 +304,16 @@ fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
shell> nginx -s reload
```
测试服务是否正常工作
```
shell> curl 127.0.0.1:1689/win
···不同版本Windows的KMS密钥···
```
**4. 配置vlmcsd服务**
在vlmcsd的[Github页面](https://github.com/Wind4/vlmcsd/releases)获取最新release包
在vlmcsd的[Github页面](https://github.com/Wind4/vlmcsd/releases)获取最新release包
```
# 下载最新release并解压
@ -361,7 +369,19 @@ Active: active (running) ···
···
```
## 容器构建
## 开发相关
### JSON接口
`kms-server` 预留了以下JSON接口,用于输出内置的KMS密钥。
+ `/win/json`:输出各版本Windows的KMS密钥;
+ `/win-server/json`:输出各版本Windows Server的KMS密钥;
+ `/json`:输出各版本Windows和Windows Server的KMS密钥;
### 容器构建
**本地构建**

8
backend/kms-office.php

@ -17,7 +17,7 @@ if exist "%ProgramFiles(x86)%\Microsoft Office\Office16\ospp.vbs" cd /d "%Progra
cscript ospp.vbs /inpkey:NMMKJ-6RK4F-KMJVX-8D9MJ-6MWKP';
function loadOsppInfo() { // 初始化ospp信息
global $webSite;
global $kmsHost;
global $osppOption, $osppDescription, $osppDescriptionCn;
$osppOption[] = '/dstatus';
@ -36,7 +36,7 @@ function loadOsppInfo() { // 初始化ospp信息
$osppDescription[] = 'Installs a product key with a user-provided product key.';
$osppDescriptionCn[] = '安装产品密钥';
$osppOption[] = '/sethst:' . $webSite;
$osppOption[] = '/sethst:' . $kmsHost;
$osppDescription[] = 'Sets a KMS host name with a user-provided host name.';
$osppDescriptionCn[] = '设置 KMS 主机名';
@ -50,8 +50,8 @@ function loadOsppInfo() { // 初始化ospp信息
}
function loadOfficeCmd() { // 初始化Office激活命令
global $webSite, $office;
$activeCmd = 'cscript ospp.vbs /sethst:' . $webSite . PHP_EOL . 'cscript ospp.vbs /act';
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;

27
backend/route.php

@ -5,11 +5,30 @@ include 'kms-web.php';
include 'kms-help.php';
include 'kms-office.php';
$webSite = "{KMS_HOST}";
if (isset($_SERVER['HTTP_HOST'])) { // 获取服务域名
preg_match('#^127.0.0.1#', $_SERVER['HTTP_HOST'], $match); // 排除127.0.0.1下的host
if (count($match) == 0) {
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);
}
$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];
}
}
}
}

Loading…
Cancel
Save