From 38048d381dc59d89b40ecd32b4da96e171f52cf8 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Wed, 10 Aug 2022 18:57:15 +0800 Subject: [PATCH] feat: add office commands --- src/Basis.php | 23 +++++++++++++++++++++++ src/KmsWeb.php | 10 +++++----- src/kmsCli.php | 16 ++++++++-------- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/Basis.php b/src/Basis.php index 389e71b..700853f 100644 --- a/src/Basis.php +++ b/src/Basis.php @@ -12,3 +12,26 @@ function getKeys(bool $isWinServer = false): array { // get kms keys asset $keysAsset = json_decode(file_get_contents('../assets/kms-keys.json'), true); 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"; + $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 { + 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'], + ); +} \ No newline at end of file diff --git a/src/KmsWeb.php b/src/KmsWeb.php index 5cbc72c..60e4bd9 100644 --- a/src/KmsWeb.php +++ b/src/KmsWeb.php @@ -17,16 +17,16 @@ function showKeysWeb(array $kmsKeys, string $header): void { // show kms keys in } -function showHelpWeb(string $site) { +function showHelpWeb(string $host) { echo ''; echo ''; echo ''; echo 'Windows Activation'; echo '

Windows KMS Activation

';
-    echo ' slmgr /upk\n slmgr /ipk KMS_KEY\n slmgr /skms ' . $site . '\n slmgr /ato\n slmgr /dlv ';
-    echo '

KMS (Office)
'; - echo 'KMS_KEY (Windows)
'; - echo 'KMS_KEY (Windows Server)

'; + echo ' slmgr /upk\n slmgr /ipk KMS_KEY\n slmgr /skms ' . $host . '\n slmgr /ato\n slmgr /dlv '; + echo '

KMS (Office)
'; + echo 'KMS_KEY (Windows)
'; + echo 'KMS_KEY (Windows Server)

'; } require_once 'Basis.php'; diff --git a/src/kmsCli.php b/src/kmsCli.php index 4b4b64a..62737b9 100644 --- a/src/kmsCli.php +++ b/src/kmsCli.php @@ -19,19 +19,19 @@ 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 $site): void { - $length = strlen($site); +function showHelpCli(string $host): void { + $length = strlen($host); echo "\n" . genStr(floor(($length - 2) / 2)) . "Activation Command\n"; echo "┏" . genStr($length + 14, '-') . "┓\n"; echo "| slmgr /upk" . genStr($length + 3) . "|\n"; echo "| slmgr /ipk KMS_KEY" . genStr($length - 5) . "|\n"; - echo "| slmgr /skms $site |\n"; + echo "| slmgr /skms $host |\n"; echo "| slmgr /ato" . genStr($length + 3) . "|\n"; echo "| slmgr /dlv" . genStr($length + 3) . "|\n"; echo "┗" . genStr($length + 14, '-') . "┛\n\n"; - echo "Office -> http://$site/office\n\n"; - echo "KMS_KEY -> http://$site/win\n"; - echo " -> http://$site/win-server\n\n"; - echo "KMS_KEY(GBK) -> http://$site/win/gbk\n"; - echo " -> http://$site/win-server/gbk\n\n"; + echo "Office -> http://$host/office\n\n"; + echo "KMS_KEY -> http://$host/win\n"; + echo " -> http://$host/win-server\n\n"; + echo "KMS_KEY(GBK) -> http://$host/win/gbk\n"; + echo " -> http://$host/win-server/gbk\n\n"; }