feat(shell): 插件密码加密、失败熔断与客户端自动更新(v1.11.3)

- 插件配置中 format=password 字段改为 AES-256-GCM 密文落盘(本机密钥,历史明文自动迁移)
- 同一插件连续失败 3 次自动禁用(仅统计进程启动后失败),升级自动解除
- 检测到新版本后台下载,空闲窗口提前提示并自动重启升级,设置页可配安全窗口
This commit is contained in:
2026-11-26 09:28:18 +08:00
parent 32e28d3aec
commit 9db8c74b7f
22 changed files with 792 additions and 38 deletions
+26 -5
View File
@@ -21,6 +21,8 @@ const runHistory = require("./run-history");
const lastFields = require("./last-fields");
const notes = require("./notes");
const pluginConfigs = require("./plugin-configs");
const localCrypto = require("./local-crypto");
const pluginHealth = require("./plugin-health");
const scheduler = require("./scheduler");
const tasks = require("./tasks");
const flows = require("./flows");
@@ -308,6 +310,8 @@ function settingsSnapshot() {
settings_file: shellSettings.filePath(),
autostart: autostartEnabled(),
close_behavior: s.close_behavior,
auto_shell_update: s.auto_shell_update,
auto_update_safe_min: s.auto_update_safe_min,
run_timeout_sec: config.runTimeoutFor(null),
run_timeout_override: s.run_timeout_sec,
run_timeout_default: config.RUN_TIMEOUT,
@@ -647,6 +651,16 @@ async function route(req, res, url) {
return sendJson(res, 200, { ok: true, rollback: done });
}
// ---------- 插件失败熔断:手动恢复(升级插件也会自动清零) ----------
const healthResetMatch = p.match(/^\/api\/plugins\/([^/]+)\/health\/reset$/);
if (healthResetMatch && method === "POST") {
session.requireLogin(cookies);
const pluginId = decodeURIComponent(healthResetMatch[1]);
checkUiAllowed(pluginId);
pluginHealth.reset(pluginId);
return sendJson(res, 200, { ok: true, health: pluginHealth.status(pluginId) });
}
// ---------- 壳子更新 ----------
if (p === "/api/shell/update-status" && method === "GET") {
session.requireLogin(cookies);
@@ -729,7 +743,7 @@ async function route(req, res, url) {
session.requireLogin(cookies);
const body = await readJsonBody(req);
const patch = {};
for (const k of ["close_behavior", "run_timeout_sec", "run_max_mem_mb", "log_max_mb", "log_keep"]) {
for (const k of ["close_behavior", "auto_shell_update", "auto_update_safe_min", "run_timeout_sec", "run_max_mem_mb", "log_max_mb", "log_keep"]) {
if (Object.prototype.hasOwnProperty.call(body, k)) patch[k] = body[k];
}
let next;
@@ -1116,8 +1130,11 @@ async function route(req, res, url) {
const body = await readJsonBody(req);
if (!body.plugin_id) throw Object.assign(new Error("缺少 plugin_id"), { status: 400 });
checkUiAllowed(body.plugin_id);
const plugin = registry.find(body.plugin_id);
const cfg = pluginConfigs.saveConfig(account, body.plugin_id, body.name, body.fields, plugin.fields);
// 密码字段名由 registry 解析(兼容"目录名≠manifest.id"的历史差异),加密落盘
const cfg = pluginConfigs.saveConfig(
account, body.plugin_id, body.name, body.fields,
registry.passwordKeysOf(body.plugin_id)
);
if (!cfg) throw Object.assign(new Error("配置名称不能为空"), { status: 400 });
return sendJson(res, 200, { ok: true, config: cfg });
}
@@ -1183,7 +1200,8 @@ function readPluginConfig(pluginId) {
if (!fs.existsSync(p)) return {};
try {
const data = JSON.parse(fs.readFileSync(p, "utf-8"));
return data && typeof data === "object" && !Array.isArray(data) ? data : {};
// 密码字段解密后再给插件 UI / 执行链;旧明文数据原样透传
return data && typeof data === "object" && !Array.isArray(data) ? localCrypto.decryptFields(data) : {};
} catch (e) {
return {};
}
@@ -1192,9 +1210,12 @@ function readPluginConfig(pluginId) {
function savePluginConfig(pluginId, data) {
const p = path.join(config.PLUGIN_CONFIG_DIR, `${pluginId}.json`);
try {
// format=password 字段加密落盘;取不到插件元数据时按原样保存(不阻断)
const keys = registry.passwordKeysOf(pluginId);
const stored = localCrypto.encryptFields(data, keys);
fs.mkdirSync(config.PLUGIN_CONFIG_DIR, { recursive: true });
const tmp = p + ".tmp";
fs.writeFileSync(tmp, JSON.stringify(data, null, 2), "utf-8");
fs.writeFileSync(tmp, JSON.stringify(stored, null, 2), "utf-8");
fs.renameSync(tmp, p); // 原子替换
} catch (e) {
logger.warning(`插件 ${pluginId} 配置保存失败:${e.message}`);