From 2c8d5d28e972693af13de11bb9be5a2023eb2a8a Mon Sep 17 00:00:00 2001 From: Marc Harnos Date: Fri, 7 Jan 2022 23:13:38 +0100 Subject: [PATCH 1/3] simplify host fallback logic move decision logic for freeBSD HOST environment var into temp var --- server/server.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/server/server.js b/server/server.js index 868bbd5ef..48a4c084c 100644 --- a/server/server.js +++ b/server/server.js @@ -63,12 +63,9 @@ console.info("Version: " + checkVersion.version); // If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available and the unspecified IPv4 address (0.0.0.0) otherwise. // Dual-stack support for (::) -let hostname = process.env.UPTIME_KUMA_HOST || args.host; - // Also read HOST if not FreeBSD, as HOST is a system environment variable in FreeBSD -if (!hostname && !FBSD) { - hostname = process.env.HOST; -} +let hostEnv = FBSD ? null : process.env.HOST; +let hostname = process.env.UPTIME_KUMA_HOST || args.host || hostEnv; if (hostname) { console.log("Custom hostname: " + hostname); From 0053a29d103d803c22a278a861e417933241fb97 Mon Sep 17 00:00:00 2001 From: Marc Harnos Date: Fri, 7 Jan 2022 23:16:26 +0100 Subject: [PATCH 2/3] add validation to port value parsing only port configurations that are valid (not isNaN) after parseInt are considered to be used in port variable --- server/server.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/server.js b/server/server.js index 48a4c084c..6b822a3de 100644 --- a/server/server.js +++ b/server/server.js @@ -71,7 +71,9 @@ if (hostname) { console.log("Custom hostname: " + hostname); } -const port = parseInt(process.env.UPTIME_KUMA_PORT || process.env.PORT || args.port || 3001); +const port = [process.env.UPTIME_KUMA_PORT, process.env.PORT, args.port, 3001] + .map(portValue => parseInt(portValue)) + .find(portValue => !isNaN(portValue)); // SSL const sslKey = process.env.UPTIME_KUMA_SSL_KEY || process.env.SSL_KEY || args["ssl-key"] || undefined; From 0bbe157099996db930294893207bad3f71ea3fae Mon Sep 17 00:00:00 2001 From: Marc Harnos Date: Sat, 8 Jan 2022 14:36:33 +0100 Subject: [PATCH 3/3] change parsing priority for all passed arguments update all passed args in server.js to prioritize command line, then use env.UPTIME_KUMA_ environment variables, then use the generic environment variable versions env.HOST, env.PORT, env.SSL_KEY, env.SSL_CERT and fall back to default values where applicable --- server/server.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/server.js b/server/server.js index 6b822a3de..d3f2b20a5 100644 --- a/server/server.js +++ b/server/server.js @@ -65,20 +65,20 @@ console.info("Version: " + checkVersion.version); // Dual-stack support for (::) // Also read HOST if not FreeBSD, as HOST is a system environment variable in FreeBSD let hostEnv = FBSD ? null : process.env.HOST; -let hostname = process.env.UPTIME_KUMA_HOST || args.host || hostEnv; +let hostname = args.host || process.env.UPTIME_KUMA_HOST || hostEnv; if (hostname) { console.log("Custom hostname: " + hostname); } -const port = [process.env.UPTIME_KUMA_PORT, process.env.PORT, args.port, 3001] +const port = [args.port, process.env.UPTIME_KUMA_PORT, process.env.PORT, 3001] .map(portValue => parseInt(portValue)) .find(portValue => !isNaN(portValue)); // SSL -const sslKey = process.env.UPTIME_KUMA_SSL_KEY || process.env.SSL_KEY || args["ssl-key"] || undefined; -const sslCert = process.env.UPTIME_KUMA_SSL_CERT || process.env.SSL_CERT || args["ssl-cert"] || undefined; -const disableFrameSameOrigin = !!process.env.UPTIME_KUMA_DISABLE_FRAME_SAMEORIGIN || args["disable-frame-sameorigin"] || false; +const sslKey = args["ssl-key"] || process.env.UPTIME_KUMA_SSL_KEY || process.env.SSL_KEY || undefined; +const sslCert = args["ssl-cert"] || process.env.UPTIME_KUMA_SSL_CERT || process.env.SSL_CERT || undefined; +const disableFrameSameOrigin = args["disable-frame-sameorigin"] || !!process.env.UPTIME_KUMA_DISABLE_FRAME_SAMEORIGIN || false; // 2FA / notp verification defaults const twofa_verification_opts = {