From 76e3090b6c275e935eaef84f80579f5f75841c8a Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Wed, 10 Aug 2022 19:35:00 +0800 Subject: [PATCH] update: show office help message --- src/Basis.php | 21 +++++++++++++++------ src/{kmsCli.php => KmsCli.php} | 29 ++++++++++++++++++++++++++++- src/KmsWeb.php | 28 ++++++++++++++++++++++------ 3 files changed, 65 insertions(+), 13 deletions(-) rename src/{kmsCli.php => KmsCli.php} (54%) diff --git a/src/Basis.php b/src/Basis.php index 700853f..edf50c8 100644 --- a/src/Basis.php +++ b/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']; } -function officeCommand(string $version, string $key, string $host): string { - $command = 'if exist "%ProgramFiles%\Microsoft Office\\' . $version . '\ospp.vbs" '; - $command .= 'cd /d "%ProgramFiles%\Microsoft Office\\' . $version . "\"\n"; - $command .= 'if exist "%ProgramFiles(x86)%\Microsoft Office\\' . $version . '\ospp.vbs" '; - $command .= 'cd /d "%ProgramFiles(x86)%\Microsoft Office\\' . $version . "\"\n"; +function officeInfo(): array { // office dir and kms key for different version + return array( + '2010' => ['Office14', 'VYBBJ-TRJPB-QFQRF-QFT4D-H3GVB'], + '2013' => ['Office15', 'YC7DK-G2NP3-2QQC3-J6H88-GVGXT'], + '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 /sethst:$host\n"; $command .= "cscript ospp.vbs /act\n"; return $command . "cscript ospp.vbs /dstatus\n"; } -function osppCommand(string $host): array { +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.', '显示当前已安装的所有许可证信息'], diff --git a/src/kmsCli.php b/src/KmsCli.php similarity index 54% rename from src/kmsCli.php rename to src/KmsCli.php index 62737b9..db7a340 100644 --- a/src/kmsCli.php +++ b/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 } -function showHelpCli(string $host): void { +function showHelpCli(string $host): void { // show help message in shell $length = strlen($host); echo "\n" . genStr(floor(($length - 2) / 2)) . "Activation Command\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 " -> 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'); diff --git a/src/KmsWeb.php b/src/KmsWeb.php index 60e4bd9..12cfa5a 100644 --- a/src/KmsWeb.php +++ b/src/KmsWeb.php @@ -1,6 +1,6 @@ '; echo ''; echo ''; @@ -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 ''; echo ''; echo ''; @@ -29,8 +29,24 @@ function showHelpWeb(string $host) { echo 'KMS_KEY (Windows Server)

'; } -require_once 'Basis.php'; +function showOfficeHtml(string $host): void { // show office commands in html + echo ''; + echo ''; + echo '
'; + echo "Office KMS Server"; + foreach (officeInfo() as $version => $officeInfo) { + echo "

Office Professional Plus $version VL

\n"; + echo "
" . officeCommand($officeInfo[0], $officeInfo[1], $host) . "
\n"; + } + echo "

常用激活命令

\n"; + echo ""; + foreach (osppCommand($host) as $cmd => $desc) { + echo ""; + echo ""; + } + echo "
命令说明
cscript ospp.vbs $cmd$desc[1]

\n"; + echo "

以上命令仅用于激活VL版本的Office,如果当前为Retail版本,请先转化为批量授权版本。

\n"; + echo "
"; +} -//$keys = getKeys(); -//showKeysWeb($keys, 'Windows KMS Keys'); -showHelpWeb('kms.343.re'); +showOfficeHtml('kms.343.re');