Browse Source

feat: load options from env

master
Dnomd343 2 years ago
parent
commit
87f89841ac
  1. 16
      kms.php

16
kms.php

@ -75,17 +75,21 @@ function get_param(string $field, string $default): string {
function load_params(): void { function load_params(): void {
global $argv; global $argv;
if (in_array('--debug', $argv)) { // enter debug mode if (strtolower(getenv('DEBUG')) === 'true' || in_array('--debug', $argv)) {
logging::$logLevel = logging::DEBUG; logging::$logLevel = logging::DEBUG; // enter debug mode
} }
global $ENABLE_HTTP; global $ENABLE_HTTP;
if (in_array('--disable-http', $argv)) { // disable http service if (strtolower(getenv('DISABLE_HTTP')) === 'true' || in_array('--disable-http', $argv)) {
logging::warning('Disable http service'); logging::warning('Disable http service');
$ENABLE_HTTP = false; $ENABLE_HTTP = false; // disable http service
} }
global $KMS_PORT; global $KMS_PORT;
if (getenv('KMS_PORT')) {
$KMS_PORT = intval(getenv('KMS_PORT'));
logging::debug('Get KMS_PORT from env -> ' . $KMS_PORT);
}
$KMS_PORT = intval(get_param('--kms-port', strval($KMS_PORT))); $KMS_PORT = intval(get_param('--kms-port', strval($KMS_PORT)));
if ($KMS_PORT < 1 || $KMS_PORT > 65535) { // 1 ~ 65535 if ($KMS_PORT < 1 || $KMS_PORT > 65535) { // 1 ~ 65535
logging::critical('Illegal KMS Port -> ' . $KMS_PORT); logging::critical('Illegal KMS Port -> ' . $KMS_PORT);
@ -98,6 +102,10 @@ function load_params(): void {
} }
global $HTTP_PORT; global $HTTP_PORT;
if (getenv('HTTP_PORT')) {
$HTTP_PORT = intval(getenv('HTTP_PORT'));
logging::debug('Get HTTP_PORT from env -> ' . $HTTP_PORT);
}
$HTTP_PORT = intval(get_param('--http-port', strval($HTTP_PORT))); $HTTP_PORT = intval(get_param('--http-port', strval($HTTP_PORT)));
if ($HTTP_PORT < 1 || $HTTP_PORT > 65535) { // 1 ~ 65535 if ($HTTP_PORT < 1 || $HTTP_PORT > 65535) { // 1 ~ 65535
logging::critical('Illegal HTTP Port -> ' . $HTTP_PORT); logging::critical('Illegal HTTP Port -> ' . $HTTP_PORT);

Loading…
Cancel
Save