From 32b1246a4b086ea25066634a5eb1296be552b890 Mon Sep 17 00:00:00 2001 From: Giacomo Sanchietti Date: Wed, 28 Feb 2024 09:43:40 +0100 Subject: [PATCH] fix_port_range --- imageroot/actions/configure-module/20configure | 3 ++- imageroot/actions/create-module/20initialize | 12 +++++++----- imageroot/actions/create-module/40firewall | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/imageroot/actions/configure-module/20configure b/imageroot/actions/configure-module/20configure index a926f72..0ab84ea 100755 --- a/imageroot/actions/configure-module/20configure +++ b/imageroot/actions/configure-module/20configure @@ -14,7 +14,8 @@ import hashlib request = json.load(sys.stdin) -ports = os.environ["TCP_PORTS"].split(',') +(start,end) = os.environ["TCP_PORTS_RANGE"].split('-') +ports = [*range(int(start), int(end))] # Configure Traefik to route requests to the nethsec-controller service response = agent.tasks.run( diff --git a/imageroot/actions/create-module/20initialize b/imageroot/actions/create-module/20initialize index 1265628..0a7a50f 100755 --- a/imageroot/actions/create-module/20initialize +++ b/imageroot/actions/create-module/20initialize @@ -8,11 +8,13 @@ exec 1>&2 # Send any output to stderr, to not alter the action response protocol set -e -ovpn_udp_port=$(echo $TCP_PORTS | cut -d',' -f1) -api_port=$(echo $TCP_PORTS | cut -d',' -f2) -ui_port=$(echo $TCP_PORTS | cut -d',' -f3) -proxy_port=$(echo $TCP_PORTS | cut -d',' -f4) -promtail_port=$(echo $TCP_PORTS | cut -d',' -f5) +start=$(echo $TCP_PORTS_RANGE | cut -d'-' -f1) + +ovpn_udp_port=$start +api_port=$(($start+1)) +ui_port=$(($start+2)) +proxy_port=$(($start+3)) +promtail_port=$(($start+4)) # port 6 and 7 are reserved for loki # port 8 is reserved for prometheus # port 9 is reserved for grafana diff --git a/imageroot/actions/create-module/40firewall b/imageroot/actions/create-module/40firewall index 743ed8e..4277596 100755 --- a/imageroot/actions/create-module/40firewall +++ b/imageroot/actions/create-module/40firewall @@ -8,5 +8,5 @@ import os import agent -ovpn_port = os.environ['TCP_PORTS'].split(',')[0] +ovpn_port = os.environ['TCP_PORTS_RANGE'].split('-')[0] agent.assert_exp(agent.add_public_service(os.environ['MODULE_ID'], [f"{ovpn_port}/udp"]))