From 3372f4f043e6d9ae1c0f1553ff75c8d604f8aead Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Thu, 15 Aug 2024 10:36:00 +0200 Subject: [PATCH] Try to detect ssh and telnet port Signed-off-by: Martin Zeithaml --- bin/start.sh | 33 +++++++++++++++++++++++++++++ defaults/serverConfig/defaults.yaml | 4 ++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/bin/start.sh b/bin/start.sh index 6c24f83..3ae2299 100755 --- a/bin/start.sh +++ b/bin/start.sh @@ -80,6 +80,39 @@ if [ "$ZWE_zowe_verifyCertificates" = "DISABLED" ]; then export NODE_TLS_REJECT_UNAUTHORIZED=0 fi +# Check ssh and telnet port +if [ -z "${ZWED_SSH_PORT}" ]; then + if [ -e "/etc/ssh/sshd_config" ]; then + ssh_port=$(cat "/etc/ssh/sshd_config" | grep '^Port.*' | awk -F\ '{print $2}') + # Empty or non-numeric? Set default + if [ -z "${ssh_port}" ] || [ -z $(echo "${ssh_port}" | grep -E '^[0-9]{1,5}$') ]; then + export ZWED_SSH_PORT=22 + else + # Out of range? Set default + if [ "${ssh_port}" -lt 1 ] || [ "${ssh_port}" -gt 65535 ]; then + export ZWED_SSH_PORT=22 + else + export ZWED_SSH_PORT="${ssh_port}" + fi + fi + fi +fi + +if [ -z "${ZWED_TN3270_PORT}" ]; then + if [ -e "/etc/services" ]; then + telnet_port=$(cat "/etc/services" | grep '^telnet' | awk -F\ '{print $2}' | awk -F/ '{print $1}') + if [ -z "${telnet_port}" ] || [ -z $(echo "${telnet_port}" | grep -E '^[0-9]{1,5}$') ]; then + export ZWED_TN3270_PORT=23 + else + if [ "${telnet_port}" -lt 1 ] || [ "${telnet_port}" -gt 65535 ]; then + export ZWED_TN3270_PORT=23 + else + export ZWED_TN3270_PORT="${telnet_port}" + fi + fi + fi +fi + # set production mode if applicable export NODE_ENV=${NODE_ENV:-production} diff --git a/defaults/serverConfig/defaults.yaml b/defaults/serverConfig/defaults.yaml index 6c11475..9f57bb3 100644 --- a/defaults/serverConfig/defaults.yaml +++ b/defaults/serverConfig/defaults.yaml @@ -2,8 +2,8 @@ zowe: workspaceDirectory: ${{ process.env.HOME + '/.zowe/workspace' }} externalDomains: ${{ function a() { if (process.env.ZWE_zowe_externalDomains) { return process.env.ZWE_zowe_externalDomains.split(','); } else { return [ os.hostname() ] } }; a() }} environments: - ZWED_SSH_PORT: 22 - ZWED_TN3270_PORT: 23 + ZWED_SSH_PORT: "${{ process.env.ZWED_SSH_PORT ? process.env.ZWED_SSH_PORT : 22 }}" + ZWED_TN3270_PORT: "${{ process.env.ZWED_TN3270_PORT ? process.env.ZWED_TN3270_PORT : 23 }}" ZWED_TN3270_SECURITY: telnet ZWED_SSH_HOST: ${{ zowe.externalDomains[0] }} ZWED_TN3270_HOST: ${{ zowe.externalDomains[0] }}