阶段 01(基线冻结与环境核验) - 新增 docs/decision-baseline.md:DEC-001~408 决策登记、TBD 处置、 GAP-01~18 文档同步清单、NEED-01~10 阻塞项闭环 - DEC-005 定稿:NapCat 维持 latest-stable,升级强制全量回归(选项 B) - DEC-006 定稿:开发期接受 MinIO 明文 HTTP + root 凭据,正式环境 TLS 与受限子账号列为部署前置条件 - 新增 .env.example(仅占位值)、.gitignore(排除 env-local.md 与 local/) - 实测环境:JDK 21 / MySQL 8.0.46(lower_case_table_names=1 导致库名 强制小写,影响首版初始化命名)/ MinIO 建桶读写全通 阶段 02(NapCat 4.18.41 协议实测,正向 WebSocket) - 三证据矩阵(API retcode + 事件段 + history 回读段)覆盖 27 项能力 - 关键结论:retcode=0 不等于送达(poke/location/私聊 at 静默丢段); file 段成功但零事件回推;forward 容器无效须用并列 node 段且 content 必须为段数组;get_forward_msg 读回为能力缺口; record 受上游解码能力限制;music 降级为 text;URL 形式媒体可用 但 rkey 具时效;撤回只能用 delete_msg 且 history 不回显撤回状态; 通知类事件无 real_seq,去重键需分类设计 - 安全发现:get_ai_record 名义查询实际会真实发送语音,已标 severity high - 上游自检 API 不可信(can_send_record 返回 yes=true 与实测矛盾) 能力基线与回归门禁(DEC-005 落地) - 新增 docs/capability-baseline.json:27 项能力机器可读基线 + 8 条跨能力硬约束 GC-001~008,状态不得留空 - 新增 tools/probe/capability-check.mjs:离线结构校验 PASS(0 错误 0 警告,探针覆盖 22/27);漂移比对 17 项自动一致、0 漂移、 1 缺测、4 人工确认 → PASS;门禁有效性已做红/绿验证 - 新增/修复探测脚本 20 个,均默认 dry-run、写操作需 --yes、 凭据仅从环境变量读取 未验证项保持未验证:反向 WS / HTTP 回调 / HTTP API 三条入站链路受阻于 网络拓扑;重复投递、乱序、断线重连补推及需 QQ 端人工操作的通知类事件 未采集,去重键与「结果未知」状态机不得定稿。
71 lines
2.7 KiB
JavaScript
71 lines
2.7 KiB
JavaScript
// NapCat WebUI 网络配置管理(默认只读;写操作需显式 --apply)
|
||
// 密码只从环境变量 NAPCAT_WEBUI_PASSWORD 读取,脚本内不留任何凭据或哈希。
|
||
//
|
||
// 用法:
|
||
// NAPCAT_WEBUI_PASSWORD=xxx node tools/probe/napcat-webui.mjs list
|
||
// NAPCAT_WEBUI_PASSWORD=xxx node tools/probe/napcat-webui.mjs version
|
||
// NAPCAT_WEBUI_PASSWORD=xxx node tools/probe/napcat-webui.mjs scheme
|
||
// NAPCAT_WEBUI_PASSWORD=xxx node tools/probe/napcat-webui.mjs apply <jsonFile> # 需 --apply
|
||
const BASE = (process.env.NAPCAT_WEBUI_URL || 'http://192.168.5.32:6099').replace(/\/$/, '');
|
||
const PASSWORD = process.env.NAPCAT_WEBUI_PASSWORD;
|
||
|
||
if (!PASSWORD) {
|
||
console.error('缺少环境变量 NAPCAT_WEBUI_PASSWORD。凭据不得硬编码在脚本或仓库中。');
|
||
process.exit(1);
|
||
}
|
||
|
||
// NapCat WebUI 登录方式:hash = SHA256(password + ".napcat"),实测确认
|
||
const hash = await sha256Hex(`${PASSWORD}.napcat`);
|
||
|
||
async function sha256Hex(s) {
|
||
const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(s));
|
||
return [...new Uint8Array(buf)].map(b => b.toString(16).padStart(2, '0')).join('');
|
||
}
|
||
|
||
async function api(path, { method = 'GET', body, cred } = {}) {
|
||
const headers = { 'Content-Type': 'application/json' };
|
||
if (cred) headers.Authorization = `Bearer ${cred}`;
|
||
const res = await fetch(`${BASE}/api${path}`, {
|
||
method, headers, body: body ? JSON.stringify(body) : undefined,
|
||
});
|
||
const text = await res.text();
|
||
let json; try { json = JSON.parse(text); } catch { json = { __raw: text.slice(0, 400) }; }
|
||
return { http: res.status, ...json };
|
||
}
|
||
|
||
const login = await api('/auth/login', { method: 'POST', body: { hash } });
|
||
if (login.code !== 0) {
|
||
console.error(`WebUI 登录失败: code=${login.code} message=${login.message}`);
|
||
process.exit(1);
|
||
}
|
||
const CRED = login.data?.Credential;
|
||
console.error(`WebUI 登录成功(credential 长度 ${CRED?.length})`);
|
||
|
||
const cmd = process.argv[2];
|
||
|
||
switch (cmd) {
|
||
case 'version': {
|
||
const r = await api('/webui/version', { cred: CRED });
|
||
console.log(JSON.stringify(r, null, 2));
|
||
break;
|
||
}
|
||
case 'scheme': {
|
||
const r = await api('/webui/scheme', { cred: CRED });
|
||
console.log(JSON.stringify(r, null, 2));
|
||
break;
|
||
}
|
||
case 'list': {
|
||
const r = await api('/network/list', { method: 'POST', cred: CRED, body: {} });
|
||
console.log(JSON.stringify(r, null, 2));
|
||
break;
|
||
}
|
||
case 'apply': {
|
||
console.error('apply 未启用:修改 NapCat 网络配置属于对外部运行实例的写操作,');
|
||
console.error('需先人工确认新增项与影响范围,再显式实现。');
|
||
process.exit(1);
|
||
}
|
||
default:
|
||
console.error('用法: list | version | scheme | apply');
|
||
process.exit(1);
|
||
}
|