From 7eee60a7cf6dc70c03d000d12425be885896fc79 Mon Sep 17 00:00:00 2001 From: hmo Date: Sat, 18 Jul 2026 11:30:31 +0800 Subject: [PATCH] fix: _is_local_host helper for EJABBERD_HOST + local IP --- gateway/scripts/dashboard.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/gateway/scripts/dashboard.py b/gateway/scripts/dashboard.py index 35c803f..2da55d4 100644 --- a/gateway/scripts/dashboard.py +++ b/gateway/scripts/dashboard.py @@ -1017,7 +1017,7 @@ def api_expected(): elif check == "tcp": # 判断目标是否是本机 - is_local = host in ("127.0.0.1", "localhost", "::1", socket.gethostname()) + is_local = _is_local_host(host) if is_local: actual[name] = "running" if port_open(e["port"], host) else "stopped" else: @@ -1030,6 +1030,26 @@ def api_expected(): return jsonify({"expected": expected, "actual": actual}) +def _is_local_host(host): + """判断目标主机是否是本机(Dashboard 运行所在的机器)。""" + if host in ("127.0.0.1", "localhost", "::1"): + return True + # 246 是 Dashboard 的生产部署机器(同时运行 ejabberd) + if host == EJABBERD_HOST: + return True + try: + # 解析本机 hostname → IP,与 host 对比 + local_name = socket.gethostname() + if host == local_name: + return True + local_ip = socket.gethostbyname(local_name) + if host == local_ip: + return True + except: + pass + return False + + def port_open(port, host="127.0.0.1"): """Check if a port is listening on a specific host.""" try: