fix: _is_local_host helper for EJABBERD_HOST + local IP
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user