From 028dc2c8b6e13c15ed21d386454e511c7de61852 Mon Sep 17 00:00:00 2001 From: r Date: Sun, 21 Jun 2026 10:10:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(btpanel):=20API=20base=5Furl=20=E4=B8=8D?= =?UTF-8?q?=E5=90=AB=E5=AE=89=E5=85=A8=E5=85=A5=E5=8F=A3=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 宝塔 API 走 :port/system,安全入口仅用于浏览器登录;修复代理 404。 Co-authored-by: Cursor --- docs/changelog/2026-06-21-btpanel-api-json-path-fix.md | 3 ++- server/application/services/btpanel_service.py | 4 +--- server/infrastructure/btpanel/ssh_bootstrap.py | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/changelog/2026-06-21-btpanel-api-json-path-fix.md b/docs/changelog/2026-06-21-btpanel-api-json-path-fix.md index 8780618f..08540e97 100644 --- a/docs/changelog/2026-06-21-btpanel-api-json-path-fix.md +++ b/docs/changelog/2026-06-21-btpanel-api-json-path-fix.md @@ -10,7 +10,8 @@ SSH bootstrap 将 API 配置写入 `/www/server/panel/data/api.json`,而宝塔 ## 涉及文件 -- `server/infrastructure/btpanel/ssh_bootstrap.py` — `API_PATH` 改为 `panel/config/api.json` +- `server/infrastructure/btpanel/client.py` — 签名 `md5(time+token)` +- `server/infrastructure/btpanel/ssh_bootstrap.py` — `base_url` 不含安全入口路径 - `tests/test_btpanel_ssh_bootstrap.py` — `exit_code=0` 回归用例(上一轮) ## 迁移 / 重启 diff --git a/server/application/services/btpanel_service.py b/server/application/services/btpanel_service.py index 2ed1016d..27a6df4d 100644 --- a/server/application/services/btpanel_service.py +++ b/server/application/services/btpanel_service.py @@ -12,7 +12,6 @@ from server.domain.models import AuditLog, Server from server.infrastructure.btpanel.client import BtPanelApiError, BtPanelClient from server.infrastructure.btpanel.credentials import ( BtPanelCredentials, - get_bt_panel_base_url, merge_bt_panel_extra, public_bt_panel_status, read_bt_panel_credentials, @@ -406,8 +405,7 @@ class BtPanelService: if not url: method = "ssh" - panel_base = (creds.base_url if creds else None) or get_bt_panel_base_url(server) - url = await ssh_temp_login_url(server, base_url=panel_base) + url = await ssh_temp_login_url(server, base_url=None) await self.audit.create(AuditLog( admin_username=admin_username, diff --git a/server/infrastructure/btpanel/ssh_bootstrap.py b/server/infrastructure/btpanel/ssh_bootstrap.py index 9ec203ab..6afcee71 100644 --- a/server/infrastructure/btpanel/ssh_bootstrap.py +++ b/server/infrastructure/btpanel/ssh_bootstrap.py @@ -51,8 +51,7 @@ def main(): scheme = "https" if ssl else "http" host = panel_host or "127.0.0.1" base = f"{scheme}://{host}:{port}" - if admin_path and admin_path != "/": - base += "/" + admin_path.strip("/") + # API 根路径不含安全入口;浏览器登录 URL 由 ssh_login 单独探测 admin_path api = {} if os.path.isfile(API_PATH): try: