From 7fd91e6cef7df4c166f1fd5858581fe4cae07fc1 Mon Sep 17 00:00:00 2001 From: dw-0 Date: Sat, 24 Feb 2024 15:46:02 +0100 Subject: [PATCH] refactor(KIAUH): allow reading ipv6 configured ports with possible default_server suffixes Signed-off-by: Dominik Willner --- kiauh/utils/filesystem_utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kiauh/utils/filesystem_utils.py b/kiauh/utils/filesystem_utils.py index 52603d6..14ad26f 100644 --- a/kiauh/utils/filesystem_utils.py +++ b/kiauh/utils/filesystem_utils.py @@ -7,7 +7,7 @@ # # # This file may be distributed under the terms of the GNU GPLv3 license # # ======================================================================= # - +import re import shutil import subprocess from pathlib import Path @@ -152,8 +152,9 @@ def read_ports_from_nginx_configs() -> List[str]: lines = cfg.readlines() for line in lines: - line = line.strip().replace(";", "") - if line.startswith("listen"): + line = line.replace("default_server", "") + line = re.sub(r"[;:\[\]]", "", line.strip()) + if line.startswith("listen") and line.split()[-1] not in port_list: port_list.append(line.split()[-1]) return sorted(port_list, key=lambda x: int(x))