Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions astrbot/core/config/astrbot_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ def __init__(
)
# 检查配置完整性,并插入
has_new = self.check_config_integrity(default_config, conf)

if isinstance(dashboard_conf, dict):
host_val = dashboard_conf.get("host")
if isinstance(host_val, str) and host_val:
dashboard_conf["host"] = [host_val]
has_new = True
Comment thread
2278535805 marked this conversation as resolved.

reset_dashboard_password = self._consume_reset_dashboard_password_flag()
if reset_dashboard_password and "dashboard" in conf:
self._reset_generated_dashboard_password(conf)
Expand Down
2 changes: 1 addition & 1 deletion astrbot/core/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
"password_storage_upgraded": False,
"password_change_required": False,
"jwt_secret": "",
"host": "0.0.0.0",
"host": ["0.0.0.0", "::"],
"port": 6185,
"disable_access_log": True,
"trust_proxy_headers": False,
Expand Down
6 changes: 6 additions & 0 deletions astrbot/core/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ def get_local_ip_addresses():
for addr in addrs:
if addr.family == socket.AF_INET: # 使用 socket.AF_INET 代替 psutil.AF_INET
network_ips.append(addr.address)
elif addr.family == socket.AF_INET6:
address = addr.address
scope_idx = address.find("%")
if scope_idx != -1:
address = address[:scope_idx]
network_ips.append(address)

return network_ips

Expand Down
30 changes: 24 additions & 6 deletions astrbot/dashboard/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,15 @@ def run(self):
or os.environ.get("ASTRBOT_DASHBOARD_PORT")
or dashboard_config.get("port", 6185)
)
host = (
host_raw = (
os.environ.get("DASHBOARD_HOST")
or os.environ.get("ASTRBOT_DASHBOARD_HOST")
or dashboard_config.get("host", "0.0.0.0")
)
if isinstance(host_raw, list):
hosts = host_raw
else:
hosts = [h.strip() for h in str(host_raw).split(",")]
enable = dashboard_config.get("enable", True)
ssl_config = dashboard_config.get("ssl", {})
if not isinstance(ssl_config, dict):
Expand All @@ -578,17 +582,26 @@ def run(self):
logger.info("WebUI disabled.")
return None

logger.info("Starting WebUI at %s://%s:%s", scheme, host, port)
if host == "0.0.0.0":
logger.info("Starting WebUI at %s://%s:%s", scheme, hosts, port)
Comment thread
2278535805 marked this conversation as resolved.
Outdated
all_interfaces = {"0.0.0.0", "::"}
local_hosts = {"localhost", "127.0.0.1", "::1"}
if all_interfaces & set(hosts):
logger.info(
"WebUI listens on all interfaces. Check security. Set dashboard.host in data/cmd_config.json to change it.",
)

if host not in ["localhost", "127.0.0.1"]:
if not set(hosts).issubset(local_hosts):
try:
ip_addr = get_local_ip_addresses()
except Exception as _:
pass

bound_v6 = all(":" in h for h in hosts)
bound_v4 = all(":" not in h for h in hosts)
if bound_v6 and not bound_v4:
ip_addr = [ip for ip in ip_addr if ":" in ip]
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated
elif bound_v4 and not bound_v6:
ip_addr = [ip for ip in ip_addr if ":" not in ip]
Comment thread
2278535805 marked this conversation as resolved.
Outdated
if isinstance(port, str):
port = int(port)

Expand All @@ -614,7 +627,10 @@ def run(self):
parts = [f"\n ✨✨✨\n AstrBot v{VERSION} {webui_status}\n\n"]
parts.append(f" ➜ Local: {scheme}://localhost:{port}\n")
for ip in ip_addr:
parts.append(f" ➜ Network: {scheme}://{ip}:{port}\n")
if ":" in ip:
parts.append(f" ➜ Network: {scheme}://[{ip}]:{port}\n")
else:
parts.append(f" ➜ Network: {scheme}://{ip}:{port}\n")
parts.append(self._build_dashboard_credentials_display())
display = "".join(parts)

Expand All @@ -627,7 +643,9 @@ def run(self):

# 配置 Hypercorn
config = HyperConfig()
config.bind = [f"{host}:{port}"]
config.bind = [
f"[{h}]:{port}" if ":" in h else f"{h}:{port}" for h in hosts
]
if bool(self.config.get("dashboard", {}).get("trust_proxy_headers", False)):
config.logger_class = _ProxyAwareHypercornLogger
if ssl_enable:
Expand Down
8 changes: 7 additions & 1 deletion astrbot/dashboard/services/auth_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,13 @@ def can_skip_default_password_auth(self) -> bool:
or os.environ.get("ASTRBOT_DASHBOARD_HOST")
or self.config["dashboard"].get("host", "")
)
return str(host).strip().lower() in LOCAL_DASHBOARD_HOSTS
if isinstance(host, list):
hosts = host
else:
hosts = [h.strip() for h in str(host).split(",")]
return all(
str(h).strip().lower() in LOCAL_DASHBOARD_HOSTS for h in hosts
)

@staticmethod
def env_flag_enabled(name: str) -> bool:
Expand Down