diff --git a/src/Basis.php b/src/Basis.php index 09e018c..dfc4721 100644 --- a/src/Basis.php +++ b/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; } diff --git a/src/KmsCli.php b/src/KmsCli.php index 8e079b5..b79ff69 100644 --- a/src/KmsCli.php +++ b/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) { diff --git a/src/KmsWeb.php b/src/KmsWeb.php index 698fb5b..77fdc89 100644 --- a/src/KmsWeb.php +++ b/src/KmsWeb.php @@ -35,18 +35,21 @@ function showHelpHtml(string $host, int $port): void { // show help message in h echo 'KMS_KEY (Windows Server)

'; } -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 ''; echo ''; echo ''; echo "Office KMS Server\n
"; foreach (officeInfo() as $version => $officeInfo) { echo "

Office Professional Plus $version VL

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

常用激活命令

\n"; echo ""; - foreach (osppCommand($host) as $cmd => $desc) { + foreach (osppCommand($host, $port) as $cmd => $desc) { echo ""; echo ""; } diff --git a/src/Route.php b/src/Route.php index ce0472b..5e65420 100644 --- a/src/Route.php +++ b/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';
命令说明
cscript ospp.vbs $cmd$desc[1]