diff --git a/web/static/i18n/en-US.json b/web/static/i18n/en-US.json index bf52aa7e..3ab8a6dc 100644 --- a/web/static/i18n/en-US.json +++ b/web/static/i18n/en-US.json @@ -789,6 +789,7 @@ "nav": { "basic": "Basic", "knowledge": "Knowledge base", + "c2": "C2", "robots": "Bots", "terminal": "Terminal", "security": "Security", @@ -800,6 +801,12 @@ "knowledge": { "title": "Knowledge base" }, + "c2": { + "title": "C2", + "sectionTitle": "Built-in C2", + "enableLabel": "Enable built-in C2 (listeners, sessions, payloads, MCP tools)", + "enableHint": "When off, listeners are not started and C2 MCP tools are not registered; the C2 sidebar is hidden—useful for local-only chat/knowledge deployments. Click Apply to save." + }, "robots": { "title": "Bot settings", "description": "Configure WeCom, DingTalk and Lark bots so you can chat with CyberStrikeAI on your phone without opening the web UI.", diff --git a/web/static/i18n/zh-CN.json b/web/static/i18n/zh-CN.json index f060c313..adcbce99 100644 --- a/web/static/i18n/zh-CN.json +++ b/web/static/i18n/zh-CN.json @@ -778,6 +778,7 @@ "nav": { "basic": "基本设置", "knowledge": "知识库", + "c2": "C2", "robots": "机器人设置", "terminal": "终端", "security": "安全设置", @@ -789,6 +790,12 @@ "knowledge": { "title": "知识库设置" }, + "c2": { + "title": "C2 设置", + "sectionTitle": "内置 C2", + "enableLabel": "启用内置 C2(监听器、会话、Payload、MCP 工具等)", + "enableHint": "关闭后不再启动监听器、不注册 C2 相关 MCP 工具,侧栏 C2 入口将隐藏;仅本机使用对话与知识库时可关闭以节省资源。修改后请点击「应用配置」。" + }, "robots": { "title": "机器人设置", "description": "配置企业微信、钉钉、飞书等机器人,在手机端直接与 CyberStrikeAI 对话,无需在服务器上打开网页。", diff --git a/web/static/js/router.js b/web/static/js/router.js index a53ee2a8..c5ae75d4 100644 --- a/web/static/js/router.js +++ b/web/static/js/router.js @@ -65,6 +65,9 @@ function initRouter() { // 切换页面 function switchPage(pageId) { + if (typeof window.syncC2NavOnceFromServer === 'function') { + void window.syncC2NavOnceFromServer(); + } // 隐藏所有页面 document.querySelectorAll('.page').forEach(page => { page.classList.remove('active'); diff --git a/web/static/js/settings.js b/web/static/js/settings.js index ebf30611..da45e95e 100644 --- a/web/static/js/settings.js +++ b/web/static/js/settings.js @@ -29,6 +29,42 @@ let toolsPagination = { totalPages: 0 }; +let c2NavSyncedOnce = false; + +/** 首次进入仪表盘等页面前拉一次配置,隐藏侧栏 C2(避免禁用后仍显示) */ +window.syncC2NavOnceFromServer = async function syncC2NavOnceFromServer() { + if (c2NavSyncedOnce || typeof apiFetch === 'undefined') { + return; + } + c2NavSyncedOnce = true; + try { + const r = await apiFetch('/api/config'); + if (r.ok) { + const cfg = await r.json(); + syncC2NavFromConfig(cfg); + } + } catch (_) { + /* ignore */ + } +}; + +// 根据 C2 是否启用显示主导航 C2 入口与仪表盘 C2 区块(与 /api/config 的 c2.enabled 一致) +function syncC2NavFromConfig(cfg) { + const on = cfg && cfg.c2 && cfg.c2.enabled !== false; + const nav = document.getElementById('nav-c2'); + if (nav) { + nav.style.display = on ? '' : 'none'; + } + const dash = document.getElementById('dashboard-section-c2'); + if (dash) { + if (!on) { + dash.hidden = true; + } else { + dash.removeAttribute('hidden'); + } + } +} + // 切换设置分类 function switchSettingsSection(section) { // 更新导航项状态 @@ -274,6 +310,12 @@ async function loadConfig(loadTools = true) { } } + const c2EnabledCb = document.getElementById('c2-enabled'); + if (c2EnabledCb) { + c2EnabledCb.checked = currentConfig.c2?.enabled !== false; + } + syncC2NavFromConfig(currentConfig); + // 填充机器人配置 const robots = currentConfig.robots || {}; const wecom = robots.wecom || {}; @@ -975,6 +1017,9 @@ async function applySettings() { const knowledgeEnabled = knowledgeEnabledCheckbox ? knowledgeEnabledCheckbox.checked : true; // 收集知识库配置 + const c2EnabledCheckbox = document.getElementById('c2-enabled'); + const c2Enabled = c2EnabledCheckbox ? c2EnabledCheckbox.checked : true; + const knowledgeConfig = { enabled: knowledgeEnabled, base_path: document.getElementById('knowledge-base-path')?.value.trim() || 'knowledge_base', @@ -1048,6 +1093,9 @@ async function applySettings() { }; })(), knowledge: knowledgeConfig, + c2: { + enabled: c2Enabled + }, robots: { wecom: { enabled: document.getElementById('robot-wecom-enabled')?.checked === true, @@ -1174,6 +1222,15 @@ async function applySettings() { ? window.t('settings.apply.applySuccess') : '配置已成功应用!'; alert(successMsg); + try { + const cfgResp = await apiFetch('/api/config'); + if (cfgResp.ok) { + const fresh = await cfgResp.json(); + syncC2NavFromConfig(fresh); + } + } catch (e) { + console.warn('refresh C2 nav after apply', e); + } try { if (typeof initChatAgentModeFromConfig === 'function') { await initChatAgentModeFromConfig(); diff --git a/web/templates/index.html b/web/templates/index.html index d40c6095..981ceded 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -1937,6 +1937,9 @@