diff --git a/README.md b/README.md index f550ef5b..951e5e37 100644 --- a/README.md +++ b/README.md @@ -204,8 +204,7 @@ cow install-browser "group_speech_recognition": false, # 是否开启群组语音识别 "voice_reply_voice": false, # 是否使用语音回复语音 "use_linkai": false, # 是否使用 LinkAI 接口,默认关闭,设置为 true 后可对接 LinkAI 平台模型 - "web_host": "0.0.0.0", # Web 控制台监听地址,设为 "127.0.0.1" 表示仅本机可访问 - "web_password": "", # Web 控制台访问密码,留空则不启用密码保护(公网部署强烈建议设置) + "web_password": "", # Web 控制台访问密码,留空则不启用密码保护(监听 0.0.0.0 时务必设置) "agent": true, # 是否启用 Agent 模式,启用后拥有多轮工具决策、长期记忆、Skills 能力等 "agent_workspace": "~/cow", # Agent 的工作空间路径,用于存储 memory、skills、系统设定等 "agent_max_context_tokens": 50000, # Agent 模式下最大上下文 tokens,超出将自动智能压缩处理 @@ -716,14 +715,16 @@ Coding Plan 是各厂商推出的编程包月套餐,所有厂商均可通过 O ```json { "channel_type": "web", + "web_host": "0.0.0.0", + "web_password": "YOUR PASSWORD", "web_port": 9899 } ``` -- `web_host`: 默认为 `0.0.0.0`(所有网卡可访问),如只在本机使用可改为 `127.0.0.1` 仅监听本地 +- `web_host`: 监听地址,默认 `127.0.0.1`(仅本机),如需公网访问请改为 `0.0.0.0` 并设置密码 - `web_port`: 默认为 9899,可按需更改,需要服务器防火墙和安全组放行该端口 -- `web_password`: 访问密码,留空则不启用密码保护。部署在公网环境时建议设置 -- 如本地运行,启动后请访问 `http://localhost:9899/chat` ;如服务器运行,请访问 `http://ip:9899/chat` +- `web_password`: 访问密码,留空则不启用密码保护。部署在公网环境时请务必设置 +- 如本地运行,启动后请访问 `http://localhost:9899` ;如服务器运行,请访问 `http://YOUR_IP:9899` > 注:请将上述 url 中的 ip 或者 port 替换为实际的值 diff --git a/channel/web/web_channel.py b/channel/web/web_channel.py index f539fc29..51a09f88 100644 --- a/channel/web/web_channel.py +++ b/channel/web/web_channel.py @@ -696,10 +696,10 @@ class WebChannel(ChatChannel): return f.read() def startup(self): - host = conf().get("web_host", "0.0.0.0") + configured_host = conf().get("web_host", "") + host = configured_host or ("0.0.0.0" if _is_password_enabled() else "127.0.0.1") port = conf().get("web_port", 9899) - # Treat wildcard binds as public exposure for the security hint below. - is_public_bind = host in ("0.0.0.0", "", "::") + is_public_bind = host in ("0.0.0.0", "::") # 打印可用渠道类型提示 logger.info( @@ -716,9 +716,11 @@ class WebChannel(ChatChannel): logger.info("[WebChannel] ✅ Web控制台已运行") logger.info(f"[WebChannel] 🌐 本地访问: http://localhost:{port}") if is_public_bind: - logger.info(f"[WebChannel] 🌍 服务器访问: http://YOUR_IP:{port} (请将YOUR_IP替换为服务器IP)") + logger.info(f"[WebChannel] 🌍 服务器访问: http://YOUR_IP:{port} (将YOUR_IP替换为服务器IP)") if not _is_password_enabled(): - logger.info("[WebChannel] 提示:当前未设置 web_password,如需公网部署请配置访问密码") + logger.info("[WebChannel] ⚠️ 当前监听 0.0.0.0 且未设置 web_password,公网部署建议在 config.json 中配置访问密码") + else: + logger.info(f"[WebChannel] 🔒 当前仅监听 {host},仅本机可访问。如需公网访问,请将 web_host 改为 0.0.0.0 并配置 web_password 密码") try: import webbrowser diff --git a/config-template.json b/config-template.json index c3a03857..bf7e8b3c 100644 --- a/config-template.json +++ b/config-template.json @@ -31,6 +31,7 @@ "dingtalk_client_secret": "", "wecom_bot_id": "", "wecom_bot_secret": "", + "web_host": "", "web_password": "", "agent": true, "agent_max_context_tokens": 50000, diff --git a/config.py b/config.py index 5ea6c9c5..f281cecb 100644 --- a/config.py +++ b/config.py @@ -205,7 +205,7 @@ available_setting = { "Minimax_base_url": "", "deepseek_api_key": "", "deepseek_api_base": "https://api.deepseek.com/v1", - "web_host": "0.0.0.0", # Web console bind address; set to "127.0.0.1" to restrict access to localhost only + "web_host": "", # Web console bind address; empty means auto "web_port": 9899, "web_password": "", # Web console password; empty means no authentication required "web_session_expire_days": 30, # Auth session expiry in days diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 55d6a084..4d0ec94b 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -37,6 +37,8 @@ services: DINGTALK_CLIENT_SECRET: '' WECOM_BOT_ID: '' WECOM_BOT_SECRET: '' + # 如需通过宿主机访问 Web 控制台,改为 '0.0.0.0' 并设置 WEB_PASSWORD + WEB_HOST: '127.0.0.1' WEB_PASSWORD: '' AGENT: 'True' AGENT_MAX_CONTEXT_TOKENS: 50000 diff --git a/docs/channels/web.mdx b/docs/channels/web.mdx index 073becac..29d9ed97 100644 --- a/docs/channels/web.mdx +++ b/docs/channels/web.mdx @@ -20,18 +20,14 @@ Web 控制台是 CowAgent 的默认通道,启动后会自动运行,通过浏 | 参数 | 说明 | 默认值 | | --- | --- | --- | | `channel_type` | 设为 `web` | `web` | -| `web_host` | Web 服务监听地址,设为 `127.0.0.1` 表示仅本机可访问 | `0.0.0.0` | +| `web_host` | Web 服务监听地址,默认监听 `127.0.0.1`(仅本机),如需公网访问请改为 `0.0.0.0` 并设置密码 | `""` | | `web_port` | Web 服务监听端口 | `9899` | -| `web_password` | 访问密码,留空表示不启用密码保护 | `""` | +| `web_password` | 访问密码,留空表示不启用密码保护;监听 `0.0.0.0` 时建议设置 | `""` | | `web_session_expire_days` | 登录会话有效天数 | `30` | | `enable_thinking` | 是否启用深度思考模式 | `false` | 配置密码后,访问控制台时需先输入密码完成登录。登录状态默认保持 30 天,期间重启服务也无需重新登录。密码也支持在控制台的「配置」页面中在线修改。 - - 默认监听 `0.0.0.0`(所有网卡可访问),方便本机和局域网/服务器场景开箱即用。**部署到公网时务必设置 `web_password`**,或将 `web_host` 改为 `127.0.0.1` 仅允许本机访问。控制台启动时会自动检测并提示这一风险。 - - ## 访问地址 启动项目后访问: