From 7f4bde1dec03c61156a4aa2d590b12c3d2bd8565 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 29 Oct 2022 22:19:42 +0800 Subject: [PATCH 1/4] feat: add `/version` request --- kms.php | 2 ++ src/Route.php | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/kms.php b/kms.php index b7e9716..93de786 100755 --- a/kms.php +++ b/kms.php @@ -30,6 +30,7 @@ $VLMCSD = array( // vlmcsd process ); function load_nginx_config(int $kms_port, int $http_port): void { + global $VERSION; $nginx_config = "server { listen $http_port; listen [::]:$http_port ipv6only=on; @@ -51,6 +52,7 @@ function load_nginx_config(int $kms_port, int $http_port): void { } fastcgi_param KMS_PORT $kms_port; fastcgi_param KMS_CLI \$cli_mode; + fastcgi_param KMS_VER $VERSION; fastcgi_param SCRIPT_FILENAME /kms-server/src/Route.php; }\n}\n"; logging::debug("Nginx configure ->\n" . $nginx_config); diff --git a/src/Route.php b/src/Route.php index 374142a..4bb8cc3 100644 --- a/src/Route.php +++ b/src/Route.php @@ -19,6 +19,18 @@ if ($url == '/json') { // show keys in json format return; // skip following process } +if ($url == '/version') { // show version info + if ($isCli) { // cli mode + echo "\033[33mkms-server\033[0m => \033[36m" . getenv('KMS_VER') . "\033[0m\n"; + } else { + mimeJson(); + echo json_encode(array( + 'version' => getenv('KMS_VER') + )); + } + return; // skip following process +} + $isGbk = false; // utf-8 or gbk $isJson = false; // json output if ($url == '/win/gbk' or $url == '/win-server/gbk') { From ab31dc81c5f0943383e143fc09ddbdf503bdd20e Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 29 Oct 2022 22:22:30 +0800 Subject: [PATCH 2/4] fix: uninitialized nginx variable --- kms.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kms.php b/kms.php index 93de786..8d4968a 100755 --- a/kms.php +++ b/kms.php @@ -45,6 +45,7 @@ function load_nginx_config(int $kms_port, int $http_port): void { } location / { + set \$cli_mode false; include fastcgi_params; fastcgi_pass unix:/run/php-fpm.sock; if (\$http_user_agent ~* (curl|wget)) { From d7084e946ea75edf640576d7f931d643faecc509 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 29 Oct 2022 22:26:36 +0800 Subject: [PATCH 3/4] feat: `-v` and `--version` options --- kms.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kms.php b/kms.php index 8d4968a..279648b 100755 --- a/kms.php +++ b/kms.php @@ -172,6 +172,11 @@ pcntl_signal(SIGQUIT, function() { // receive SIGQUIT signal exit; }); +if (in_array('-v', $argv) || in_array('--version', $argv)) { + echo "\033[33mkms-server\033[0m => \033[36m$VERSION\033[0m\n"; // show version info + exit; +} + logging::info('Loading kms-server (' . $VERSION . ')'); load_params(); load_vlmcsd_command($KMS_PORT); From bfa279d24eed531555d6351e2fc78633be075149 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 29 Oct 2022 22:37:59 +0800 Subject: [PATCH 4/4] feat: `-h` and `--help` options --- kms.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/kms.php b/kms.php index 279648b..9d31135 100755 --- a/kms.php +++ b/kms.php @@ -29,6 +29,19 @@ $VLMCSD = array( // vlmcsd process 'pidFile' => '/run/vlmcsd.pid', ); +$HELP_MSG = " + kms-server ($VERSION) + + Project: https://github.com/dnomd343/kms-server.git + + --debug Enable debug mode + --kms-port Specify kms listen port + --http-port Specify http listen port + --disable-http Disable http service + --version Show version info + --help Show help message +\n"; + function load_nginx_config(int $kms_port, int $http_port): void { global $VERSION; $nginx_config = "server { @@ -177,6 +190,11 @@ if (in_array('-v', $argv) || in_array('--version', $argv)) { exit; } +if (in_array('-h', $argv) || in_array('--help', $argv)) { + echo $HELP_MSG; // show help message + exit; +} + logging::info('Loading kms-server (' . $VERSION . ')'); load_params(); load_vlmcsd_command($KMS_PORT);