Browse Source

update: show office help message

master
dnomd343 2 years ago
parent
commit
76e3090b6c
  1. 21
      src/Basis.php
  2. 29
      src/KmsCli.php
  3. 28
      src/KmsWeb.php

21
src/Basis.php

@ -13,18 +13,27 @@ function getKeys(bool $isWinServer = false): array { // get kms keys asset
return $isWinServer ? array_reverse($keysAsset['win-server']) : $keysAsset['win']; return $isWinServer ? array_reverse($keysAsset['win-server']) : $keysAsset['win'];
} }
function officeCommand(string $version, string $key, string $host): string { function officeInfo(): array { // office dir and kms key for different version
$command = 'if exist "%ProgramFiles%\Microsoft Office\\' . $version . '\ospp.vbs" '; return array(
$command .= 'cd /d "%ProgramFiles%\Microsoft Office\\' . $version . "\"\n"; '2010' => ['Office14', 'VYBBJ-TRJPB-QFQRF-QFT4D-H3GVB'],
$command .= 'if exist "%ProgramFiles(x86)%\Microsoft Office\\' . $version . '\ospp.vbs" '; '2013' => ['Office15', 'YC7DK-G2NP3-2QQC3-J6H88-GVGXT'],
$command .= 'cd /d "%ProgramFiles(x86)%\Microsoft Office\\' . $version . "\"\n"; '2016' => ['Office16', 'XQNVK-8JYDB-WJ9W3-YJ8YR-WFG99'],
'2019' => ['Office16', 'NMMKJ-6RK4F-KMJVX-8D9MJ-6MWKP'],
);
}
function officeCommand(string $dir, string $key, string $host): 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 /inpkey:$key\n";
$command .= "cscript ospp.vbs /sethst:$host\n"; $command .= "cscript ospp.vbs /sethst:$host\n";
$command .= "cscript ospp.vbs /act\n"; $command .= "cscript ospp.vbs /act\n";
return $command . "cscript ospp.vbs /dstatus\n"; return $command . "cscript ospp.vbs /dstatus\n";
} }
function osppCommand(string $host): array { function osppCommand(string $host): array { // load office ospp command
return array( return array(
'/dstatus' => ['Displays license information for installed product keys.', '显示当前已安装产品密钥的许可证信息'], '/dstatus' => ['Displays license information for installed product keys.', '显示当前已安装产品密钥的许可证信息'],
'/dstatusall' => ['Displays license information for all installed licenses.', '显示当前已安装的所有许可证信息'], '/dstatusall' => ['Displays license information for all installed licenses.', '显示当前已安装的所有许可证信息'],

29
src/kmsCli.php → src/KmsCli.php

@ -19,7 +19,7 @@ function showKeysCli(array $kmsKeys, bool $isGbk = false): void { // show kms ke
echo $isGbk ? iconv('utf-8', 'gb2312', $ret) : $ret; // utf-8 or gbk echo $isGbk ? iconv('utf-8', 'gb2312', $ret) : $ret; // utf-8 or gbk
} }
function showHelpCli(string $host): void { function showHelpCli(string $host): void { // show help message in shell
$length = strlen($host); $length = strlen($host);
echo "\n" . genStr(floor(($length - 2) / 2)) . "Activation Command\n"; echo "\n" . genStr(floor(($length - 2) / 2)) . "Activation Command\n";
echo "┏" . genStr($length + 14, '-') . "┓\n"; echo "┏" . genStr($length + 14, '-') . "┓\n";
@ -35,3 +35,30 @@ function showHelpCli(string $host): void {
echo "KMS_KEY(GBK) -> http://$host/win/gbk\n"; echo "KMS_KEY(GBK) -> http://$host/win/gbk\n";
echo " -> http://$host/win-server/gbk\n\n"; echo " -> http://$host/win-server/gbk\n\n";
} }
function showOfficeCli(string $host): void { // show office commands in shell
$lenLeft = $lenRight = 0;
$ospp = osppCommand($host);
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 genStr(120, '-') . "\n";
}
foreach ($ospp as $cmd => $desc) {
$lenLeft = ($lenLeft < strlen($cmd)) ? strlen($cmd) : $lenLeft;
$lenRight = ($lenRight < strlen($desc[0])) ? strlen($desc[0]) : $lenRight;
}
$header = 'Common activation commands';
echo "\n" . genStr(floor(($lenLeft + $lenRight - strlen($header) + 24) / 2)) . $header;
echo "\n┏" . genStr($lenLeft + $lenRight + 22, '-') . "┓\n";
foreach ($ospp as $cmd => $desc) {
echo "| cscript ospp.vbs $cmd" . genStr($lenLeft - strlen($cmd)) . ' | ';
echo $desc[0] . genStr($lenRight - strlen($desc[0])) . " |\n";
}
echo '┗' . genStr($lenLeft + $lenRight + 22, '-') . "┛\n\n";
echo "These commands are only applicable to the VL version of Office.\n";
echo "If it is a Retail version, please convert it to Volume first.\n\n";
}
showOfficeCli('kms.343.re');

28
src/KmsWeb.php

@ -1,6 +1,6 @@
<?php <?php
function showKeysWeb(array $kmsKeys, string $header): void { // show kms keys in html function showKeysHtml(array $kmsKeys, string $header): void { // show kms keys in html
echo '<!DOCTYPE html><html><head><meta charset="utf-8">'; echo '<!DOCTYPE html><html><head><meta charset="utf-8">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">'; echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
echo '<link rel="stylesheet" href="./assets/style.css" /></head>'; echo '<link rel="stylesheet" href="./assets/style.css" /></head>';
@ -17,7 +17,7 @@ function showKeysWeb(array $kmsKeys, string $header): void { // show kms keys in
} }
function showHelpWeb(string $host) { function showHelpHtml(string $host): void { // show help message in html
echo '<!DOCTYPE html><html><head><meta charset="utf-8">'; echo '<!DOCTYPE html><html><head><meta charset="utf-8">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">'; echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
echo '<link rel="stylesheet" href="./assets/style.css" /></head>'; echo '<link rel="stylesheet" href="./assets/style.css" /></head>';
@ -29,8 +29,24 @@ function showHelpWeb(string $host) {
echo '<a href="http://' . $host . '/win-server">KMS_KEY (Windows Server)</a></p></div></body></html>'; echo '<a href="http://' . $host . '/win-server">KMS_KEY (Windows Server)</a></p></div></body></html>';
} }
require_once 'Basis.php'; function showOfficeHtml(string $host): void { // show office commands 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><body><div>';
echo "<title>Office KMS Server</title>";
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 "<h2>常用激活命令</h2>\n";
echo "<table><thead><tr><th>命令</th><th>说明</th></tr></thead><tbody>";
foreach (osppCommand($host) as $cmd => $desc) {
echo "<tr><td>cscript ospp.vbs $cmd</td>";
echo "<td>$desc[1]</td></tr>";
}
echo "</tbody></table><br>\n";
echo "<p>以上命令仅用于激活VL版本的Office,如果当前为Retail版本,请先转化为批量授权版本。</p>\n";
echo "</div></body></html>";
}
//$keys = getKeys(); showOfficeHtml('kms.343.re');
//showKeysWeb($keys, 'Windows KMS Keys');
showHelpWeb('kms.343.re');

Loading…
Cancel
Save