From e7eae5a0d1f361676e5fde241dcf32b27ab2360a Mon Sep 17 00:00:00 2001 From: dw-0 Date: Sun, 13 Oct 2024 11:21:18 +0200 Subject: [PATCH] fix: correctly handle IPs in nginx config files when parsing ports (#568) * chore: add jupyter files to .gitignore Signed-off-by: Dominik Willner * fix: correctly handle IPs in nginx config files when parsing ports Signed-off-by: Dominik Willner --------- Signed-off-by: Dominik Willner --- .gitignore | 4 ++++ kiauh/components/webui_client/client_utils.py | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index bff7f5f..b3e84e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,10 @@ .idea .vscode .pytest_cache +.jupyter +*.ipynb +*.ipynb_checkpoints +*.tmp __pycache__ .kiauh-env *.code-workspace diff --git a/kiauh/components/webui_client/client_utils.py b/kiauh/components/webui_client/client_utils.py index ca9727f..1c17aac 100644 --- a/kiauh/components/webui_client/client_utils.py +++ b/kiauh/components/webui_client/client_utils.py @@ -353,10 +353,16 @@ def read_ports_from_nginx_configs() -> List[int]: lines = cfg.readlines() for line in lines: - 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]) + line = re.sub( + r"default_server|http://|https://|[;\[\]]", + "", + line.strip(), + ) + if line.startswith("listen"): + if ":" not in line: + port_list.append(line.split()[-1]) + else: + port_list.append(line.split(":")[-1]) ports_to_ints_list = [int(port) for port in port_list] return sorted(ports_to_ints_list, key=lambda x: int(x))