Browse Source

feat: add port field in office active message

master
Dnomd343 2 years ago
parent
commit
7cfa99501e
  1. 28
      src/Basis.php
  2. 9
      src/KmsCli.php
  3. 9
      src/KmsWeb.php
  4. 2
      src/Route.php

28
src/Basis.php

@ -74,25 +74,33 @@ function officeInfo(): array { // office dir and kms key for different version
);
}
function officeCommand(string $dir, string $key, string $host): string { // load office active command
function officeCommand(string $dir, string $key, string $host, int $port): string { // load office active command
$command = 'if exist "%ProgramFiles%\Microsoft Office\\' . $dir . '\ospp.vbs" ';
$command .= 'cd /d "%ProgramFiles%\Microsoft Office\\' . $dir . "\"\n";
$command .= 'if exist "%ProgramFiles(x86)%\Microsoft Office\\' . $dir . '\ospp.vbs" ';
$command .= 'cd /d "%ProgramFiles(x86)%\Microsoft Office\\' . $dir . "\"\n";
$command .= "cscript ospp.vbs /inpkey:$key\n";
$command .= "cscript ospp.vbs /sethst:$host\n";
if ($port != 1688) {
$command .= "cscript ospp.vbs /setprt:$port\n";
}
$command .= "cscript ospp.vbs /act\n";
return $command . "cscript ospp.vbs /dstatus\n";
}
function osppCommand(string $host): array { // load office ospp command
return array(
'/dstatus' => ['Displays license information for installed product keys.', '显示当前已安装产品密钥的许可证信息'],
'/dstatusall' => ['Displays license information for all installed licenses.', '显示当前已安装的所有许可证信息'],
'/unpkey:XXXXX' => ['Uninstalls an product key with the last five digits of it.', '卸载已安装的产品密钥(最后5位)'],
'/inpkey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX' => ['Installs a product key with a user-provided product key.', '安装产品密钥'],
"/sethst:$host" => ['Sets a KMS host name with a user-provided host name.', '设置 KMS 主机名'],
'/remhst' => ['Removes KMS host name and sets port to default.', '删除 KMS 主机名'],
'/act' => ['Activates installed Office product keys.', '激活 Office'],
function osppCommand(string $host, int $port): array { // load office ospp command
$osppCmd = array(
'/dstatus' => ['Display license information for installed product keys.', '显示当前已安装产品密钥的许可证信息'],
'/dstatusall' => ['Display license information for installed licenses.', '显示当前已安装的所有许可证信息'],
'/unpkey:XXXXX' => ['Uninstall a product key with the last five digits of it.', '卸载已安装的产品密钥(最后5位)'],
'/inpkey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX' => ['Install a product key with user-provided product key.', '安装产品密钥'],
"/sethst:$host" => ['Set a KMS host name with user-provided host name.', '设置 KMS 主机名'],
"/setprt:$port" => ['Set a KMS port with user-provided port number.', '设置 KMS 主机端口'],
'/remhst' => ['Remove KMS host name and sets port to default.', '删除 KMS 主机名'],
'/act' => ['Activate installedOffice product keys.', '激活 Office'],
);
if ($port == 1688) {
unset($osppCmd["/setprt:$port"]); // remove setprt option with default port
}
return $osppCmd;
}

9
src/KmsCli.php

@ -43,13 +43,16 @@ function showHelpCli(string $host, int $port): void { // show help message in sh
echo " -> http://$host/win-server/gbk\n\n";
}
function showOfficeCli(string $host): void { // show office commands in shell
function showOfficeCli(string $host, int $port): void { // show office commands in shell
if (isIPv6($host)) { // host without ipv6 bracket
$host = '[' . $host . ']';
}
$lenLeft = $lenRight = 0;
$ospp = osppCommand($host);
$ospp = osppCommand($host, $port);
foreach (officeInfo() as $version => $officeInfo) {
echo "\n" . genStr(34) . "Office Professional Plus $version VL Activation Command\n";
echo genStr(120, '-') . "\n";
echo officeCommand($officeInfo[0], $officeInfo[1], $host);
echo officeCommand($officeInfo[0], $officeInfo[1], $host, $port);
echo genStr(120, '-') . "\n";
}
foreach ($ospp as $cmd => $desc) {

9
src/KmsWeb.php

@ -35,18 +35,21 @@ function showHelpHtml(string $host, int $port): void { // show help message in h
echo '<a href="./win-server">KMS_KEY (Windows Server)</a></p></div></body></html>';
}
function showOfficeHtml(string $host): void { // show office commands in html
function showOfficeHtml(string $host, int $port): void { // show office commands in html
if (isIPv6($host)) { // host without ipv6 bracket
$host = '[' . $host . ']';
}
echo '<!DOCTYPE html><html lang="zh-CN"><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" />';
echo "<title>Office KMS Server</title></head>\n<body><div>";
foreach (officeInfo() as $version => $officeInfo) {
echo "<h2>Office Professional Plus $version VL</h2>\n";
echo "<pre><code>" . officeCommand($officeInfo[0], $officeInfo[1], $host) . "</code></pre>\n";
echo "<pre><code>" . officeCommand($officeInfo[0], $officeInfo[1], $host, $port) . "</code></pre>\n";
}
echo "<h2>常用激活命令</h2>\n";
echo "<table><thead><tr><th>命令</th><th>说明</th></tr></thead><tbody>";
foreach (osppCommand($host) as $cmd => $desc) {
foreach (osppCommand($host, $port) as $cmd => $desc) {
echo "<tr><td>cscript ospp.vbs $cmd</td>";
echo "<td>$desc[1]</td></tr>";
}

2
src/Route.php

@ -28,7 +28,7 @@ if ($url == '/win/json' or $url == '/win-server/json') {
if ($url == '/' or $url == '/help') {
$isCli ? showHelpCli($kmsHost, $kmsPort) : showHelpHtml($kmsHost, $kmsPort); // show help message
} else if ($url == '/office') {
$isCli ? showOfficeCli($kmsHost) : showOfficeHtml($kmsHost); // show office commands
$isCli ? showOfficeCli($kmsHost, $kmsPort) : showOfficeHtml($kmsHost, $kmsPort); // show office commands
} else if ($url == '/win' or $url == '/win-server') {
$kmsKeys = getKeys(($url != '/win'));
$caption = 'Windows ' . (($url == '/win') ? '' : 'Server ') . 'KMS Keys';

Loading…
Cancel
Save