fix(btpanel): bootstrap 写入 panel/config/api.json

宝塔读取 config/api.json 而非 data/api.json,错误路径导致白名单与 token 不生效。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
r
2026-06-21 10:01:40 +08:00
parent b768da3ab8
commit e5929694c3
2 changed files with 27 additions and 1 deletions
@@ -0,0 +1,26 @@
# 2026-06-21 宝塔 bootstrap 写入正确 api.json 路径
## 摘要
SSH bootstrap 将 API 配置写入 `/www/server/panel/data/api.json`,而宝塔面板实际读取 `/www/server/panel/config/api.json`,导致白名单与 token 未生效,所有代理 API 返回「IP校验失败」。
## 动机
生产验收:8 台已 configured 服务器全部代理失败;子机 exec 显示 `config/api.json` 白名单仍为旧 IP `172.96.253.26`,与 `data/api.json` 不一致。
## 涉及文件
- `server/infrastructure/btpanel/ssh_bootstrap.py``API_PATH` 改为 `panel/config/api.json`
- `tests/test_btpanel_ssh_bootstrap.py``exit_code=0` 回归用例(上一轮)
## 迁移 / 重启
- 需部署 API 后,对已 configured 服务器**重新执行 bootstrap**(手动或批量)以合并白名单与 token 到正确文件。
- 无需 DB 迁移。
## 验证
```bash
.venv/bin/pytest tests/test_btpanel_ssh_bootstrap.py -q
# 生产:POST /api/btpanel/servers/{id}/bootstrap 后 GET .../system/total 应返回真实指标而非 IP 错误
```
@@ -19,7 +19,7 @@ import json, os, secrets, sys, subprocess
PANEL_ROOT = "/www/server/panel"
DATA_DIR = os.path.join(PANEL_ROOT, "data")
API_PATH = os.path.join(DATA_DIR, "api.json")
API_PATH = os.path.join(PANEL_ROOT, "config", "api.json")
def read_text(path, default=""):
try: