mirror of
https://github.com/CyberSecurityUP/NeuroSploit.git
synced 2026-12-06 02:53:57 +01:00
fix(web): dashboard stats in pentests view, toolbox JSON parse, PR review modal
- Move dashboardStats into pentests view (was global, polluting all pages) - Make stats cards reflect actual run data from file storage - Fix toolbox JSON parsing: separate stdout/stderr in runCli, handle array JSON in toolsCall (was only matching object patterns) - Add New PR Review modal with repo/PR input form - Target table click now switches to pentests view - Dashboard cards: severity-colored layout with CSS - Strip redundant Storage card from stats Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
00b2458e14
commit
76ce3101cc
4 files changed
+102
-28
No files matched your search
+71
-13
@@ -172,7 +172,7 @@ function switchView(viewName) {
|
||||
const runHist = $('#sbRunHistory');
|
||||
if (runHist) runHist.style.display = ['live','detail'].includes(viewName) ? '' : 'none';
|
||||
if (viewName === 'wizard') loadProjectOptions();
|
||||
if (viewName === 'pentests') loadPentests();
|
||||
if (viewName === 'pentests') { loadPentests(); loadDashboardStats(); }
|
||||
if (viewName === 'issues') loadIssues();
|
||||
if (viewName === 'repos') loadRepos();
|
||||
if (viewName === 'projects') loadProjects();
|
||||
@@ -1459,9 +1459,18 @@ async function loadDashboardStats() {
|
||||
: '<span class="dash-badge dash-warn">File storage</span>';
|
||||
|
||||
const totalRuns = stats?.total_runs || state.runs.length || 0;
|
||||
const totalFindings = stats?.total_findings || 0;
|
||||
const critFindings = stats?.critical_findings || 0;
|
||||
const highFindings = stats?.high_findings || 0;
|
||||
let totalFindings = stats?.total_findings || 0;
|
||||
let critFindings = stats?.critical_findings || 0;
|
||||
let highFindings = stats?.high_findings || 0;
|
||||
if (!totalFindings && state.runs.length) {
|
||||
for (const r of state.runs) {
|
||||
const n = r.findings ?? r.validated ?? 0;
|
||||
totalFindings += n;
|
||||
const sev = r.severity || {};
|
||||
critFindings += sev.critical || 0;
|
||||
highFindings += sev.high || 0;
|
||||
}
|
||||
}
|
||||
|
||||
const costUsd = cost?.total_usd ? `$${Number(cost.total_usd).toFixed(4)}` : '—';
|
||||
const budgetUsd = cost?.budget_usd ? `$${Number(cost.budget_usd).toFixed(2)}` : '∞';
|
||||
@@ -1472,20 +1481,25 @@ async function loadDashboardStats() {
|
||||
const gaps = coverage?.gaps || [];
|
||||
const topGaps = gaps.slice(0, 5).map(g => `<span class="dash-gap">${esc(typeof g === 'string' ? g : g.class || g.name || '')}</span>`).join('');
|
||||
|
||||
const medFindings = stats?.medium_findings || 0;
|
||||
const lowFindings = stats?.low_findings || 0;
|
||||
const infoFindings = stats?.info_findings || 0;
|
||||
|
||||
el.innerHTML = `
|
||||
<div class="dash-row">
|
||||
<div class="dash-card"><div class="dash-label">Storage</div><div class="dash-val">${dbBadge}</div></div>
|
||||
<div class="dash-card"><div class="dash-label">Total Runs</div><div class="dash-val">${totalRuns}</div></div>
|
||||
<div class="dash-card"><div class="dash-label">Findings</div><div class="dash-val">${totalFindings}</div></div>
|
||||
<div class="dash-card"><div class="dash-label">Critical</div><div class="dash-val" style="color:var(--sev-critical-fg)">${critFindings}</div></div>
|
||||
<div class="dash-card"><div class="dash-label">High</div><div class="dash-val" style="color:var(--sev-high-fg)">${highFindings}</div></div>
|
||||
<div class="dash-row dash-row-main">
|
||||
<div class="dash-card dash-card-accent"><div class="dash-val-big">${totalFindings}</div><div class="dash-label">Findings</div></div>
|
||||
<div class="dash-card dash-sev-crit"><div class="dash-val-big">${critFindings}</div><div class="dash-label">Critical</div></div>
|
||||
<div class="dash-card dash-sev-high"><div class="dash-val-big">${highFindings}</div><div class="dash-label">High</div></div>
|
||||
<div class="dash-card dash-sev-med"><div class="dash-val-big">${medFindings}</div><div class="dash-label">Medium</div></div>
|
||||
<div class="dash-card dash-sev-low"><div class="dash-val-big">${lowFindings}</div><div class="dash-label">Low</div></div>
|
||||
</div>
|
||||
<div class="dash-row">
|
||||
<div class="dash-row dash-row-meta">
|
||||
<div class="dash-card"><div class="dash-label">Runs</div><div class="dash-val">${totalRuns}</div></div>
|
||||
<div class="dash-card"><div class="dash-label">Coverage</div><div class="dash-val">${covPct}%</div></div>
|
||||
<div class="dash-card"><div class="dash-label">Cost</div><div class="dash-val">${costUsd}</div></div>
|
||||
<div class="dash-card"><div class="dash-label">Budget</div><div class="dash-val">${budgetUsd}</div></div>
|
||||
<div class="dash-card"><div class="dash-label">Coverage</div><div class="dash-val">${covPct}% <small>(${covCovered}/${covTotal})</small></div></div>
|
||||
</div>
|
||||
${topGaps ? `<div class="dash-row"><div class="dash-card dash-wide"><div class="dash-label">Top Gaps</div><div class="dash-val">${topGaps}</div></div></div>` : ''}
|
||||
${topGaps ? `<div class="dash-row"><div class="dash-card dash-wide"><div class="dash-label">Coverage Gaps</div><div class="dash-val">${topGaps}</div></div></div>` : ''}
|
||||
`;
|
||||
} catch { /* dashboard stats are non-critical */ }
|
||||
}
|
||||
@@ -3558,6 +3572,7 @@ async function renderDashboard() {
|
||||
$$('#dashBody tbody tr[data-target]').forEach((tr) => tr.addEventListener('click', () => {
|
||||
state.runFilter = tr.dataset.target;
|
||||
$('#runFilter').value = tr.dataset.target;
|
||||
switchView('pentests');
|
||||
renderSidebar();
|
||||
}));
|
||||
// A top contributor is a specific finding in a specific run — clicking it
|
||||
@@ -6285,6 +6300,49 @@ async function loadPrReviews() {
|
||||
} catch (e) { body.innerHTML = `<div class="empty-state">Failed to load: ${esc(e.message)}</div>`; }
|
||||
}
|
||||
|
||||
$('#btnNewPrReview')?.addEventListener('click', () => {
|
||||
const existing = $('#prReviewModal');
|
||||
if (existing) { existing.hidden = false; return; }
|
||||
document.body.insertAdjacentHTML('beforeend', `
|
||||
<div class="modal-overlay" id="prReviewModal">
|
||||
<div class="modal" style="max-width:480px;">
|
||||
<div class="modal-head"><h3>New PR review</h3><button class="modal-close" id="btnClosePrReview">×</button></div>
|
||||
<div class="modal-body">
|
||||
<label class="field-label">Repository <small class="muted">(owner/repo)</small></label>
|
||||
<input class="input" id="prReviewRepo" placeholder="owner/repo" />
|
||||
<label class="field-label" style="margin-top:12px;">PR number</label>
|
||||
<input class="input" id="prReviewNumber" type="number" min="1" placeholder="123" />
|
||||
<div id="prReviewError" class="form-error" style="margin-top:8px;"></div>
|
||||
</div>
|
||||
<div class="modal-foot">
|
||||
<button class="btn" id="btnPrReviewCancel">Cancel</button>
|
||||
<button class="btn btn-primary" id="btnPrReviewRun">Start review</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>`);
|
||||
$('#btnClosePrReview').addEventListener('click', () => $('#prReviewModal').hidden = true);
|
||||
$('#btnPrReviewCancel').addEventListener('click', () => $('#prReviewModal').hidden = true);
|
||||
$('#prReviewModal').addEventListener('click', (e) => { if (e.target.id === 'prReviewModal') e.target.hidden = true; });
|
||||
$('#btnPrReviewRun').addEventListener('click', async () => {
|
||||
const repo = $('#prReviewRepo').value.trim();
|
||||
const num = $('#prReviewNumber').value.trim();
|
||||
const errEl = $('#prReviewError');
|
||||
if (!repo || !num) { if (errEl) errEl.textContent = 'Repository and PR number are required.'; return; }
|
||||
if (errEl) errEl.textContent = '';
|
||||
try {
|
||||
await api('/api/start', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ target: `${repo}#${num}`, mode: 'pr' }),
|
||||
});
|
||||
$('#prReviewModal').hidden = true;
|
||||
switchView('live');
|
||||
} catch (e) {
|
||||
if (errEl) errEl.textContent = e.message || 'Failed to start review';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
async function loadIssues() {
|
||||
const tableBody = $('#issuesTableBody');
|
||||
if (!tableBody) return;
|
||||
|
||||
@@ -102,9 +102,6 @@
|
||||
<!-- ============ MAIN ============ -->
|
||||
<main class="main">
|
||||
|
||||
<!-- ============ DASHBOARD STATS ============ -->
|
||||
<div id="dashboardStats" hidden></div>
|
||||
|
||||
<!-- ============ HOME ============ -->
|
||||
<section class="page-view" id="homeView" hidden>
|
||||
<div class="home-landing">
|
||||
@@ -169,6 +166,7 @@
|
||||
<input type="text" id="pentestSearch" class="topbar-search" placeholder="Search pentests" />
|
||||
<button class="btn btn-primary" id="btnNewPentest2"><svg class="ico" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M12 5v14M5 12h14"/></svg> New pentest</button>
|
||||
</header>
|
||||
<div id="dashboardStats" hidden></div>
|
||||
<div class="page-body" id="pentestsBody"><div class="empty-state">Loading…</div></div>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -3212,3 +3212,18 @@ details.ag-sec > summary::-webkit-details-marker { display: none; }
|
||||
.dash-ok { background: color-mix(in srgb, var(--sev-low-bar) 20%, transparent); color: var(--sev-low-fg); border: 1px solid var(--sev-low-bar); }
|
||||
.dash-warn { background: color-mix(in srgb, var(--sev-medium-bar) 20%, transparent); color: var(--sev-medium-fg); border: 1px solid var(--sev-medium-bar); }
|
||||
.dash-gap { display: inline-block; font-size: 11px; background: var(--surface-3, var(--surface-2)); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; margin: 2px 4px 2px 0; color: var(--text-dim); }
|
||||
.dash-row-main { gap: 12px; }
|
||||
.dash-row-main .dash-card { text-align: center; padding: 16px 12px; }
|
||||
.dash-row-meta .dash-card { text-align: center; }
|
||||
.dash-val-big { font-size: 28px; font-weight: 800; color: var(--text); line-height: 1.1; }
|
||||
.dash-row-main .dash-label { margin-top: 6px; margin-bottom: 0; }
|
||||
.dash-card-accent { border-color: var(--accent, #7c5cff); }
|
||||
.dash-card-accent .dash-val-big { color: var(--accent, #7c5cff); }
|
||||
.dash-sev-crit { border-color: var(--sev-critical-bar, #e53e3e); }
|
||||
.dash-sev-crit .dash-val-big { color: var(--sev-critical-fg, #fc8181); }
|
||||
.dash-sev-high { border-color: var(--sev-high-bar, #dd6b20); }
|
||||
.dash-sev-high .dash-val-big { color: var(--sev-high-fg, #fbd38d); }
|
||||
.dash-sev-med { border-color: var(--sev-medium-bar, #d69e2e); }
|
||||
.dash-sev-med .dash-val-big { color: var(--sev-medium-fg, #fefcbf); }
|
||||
.dash-sev-low { border-color: var(--sev-low-bar, #38a169); }
|
||||
.dash-sev-low .dash-val-big { color: var(--sev-low-fg, #9ae6b4); }
|
||||
+15
-12
@@ -312,17 +312,19 @@ const PORT = Number(process.env.NEUROSPLOIT_WEB_PORT || process.env.PORT || 4173
|
||||
|
||||
async function toolsCall(args) {
|
||||
const out = await runCli(['tools', ...args, '--json']);
|
||||
const text = stripAnsi(out.buf || '').trim();
|
||||
const text = (out.buf || '').trim();
|
||||
if (out.code !== 0) {
|
||||
let msg = text || 'tool command failed';
|
||||
let msg = text || out.stderr || 'tool command failed';
|
||||
try { const v = JSON.parse(text); msg = v.error || msg; } catch { /* keep text */ }
|
||||
throw new Error(msg);
|
||||
}
|
||||
try { return JSON.parse(text); }
|
||||
catch {
|
||||
const m = text.match(/\{[\s\S]*\}\s*$/);
|
||||
if (m) { try { return JSON.parse(m[0]); } catch { /* fall through */ } }
|
||||
throw new Error(text || 'tool command returned no JSON');
|
||||
const arrMatch = text.match(/\[[\s\S]*\]\s*$/);
|
||||
if (arrMatch) { try { return JSON.parse(arrMatch[0]); } catch { /* fall through */ } }
|
||||
const objMatch = text.match(/\{[\s\S]*\}\s*$/);
|
||||
if (objMatch) { try { return JSON.parse(objMatch[0]); } catch { /* fall through */ } }
|
||||
throw new Error((text || '').slice(0, 200) || 'tool command returned no JSON');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,9 +345,9 @@ const C2_PROFILE_KEYS = ['sliver', 'havoc', 'mythic', 'adaptix', 'cobaltstrike']
|
||||
|
||||
async function c2xCall(args) {
|
||||
const out = await runCli(['c2x', ...args, '--json']);
|
||||
const text = stripAnsi(out.buf || '').trim();
|
||||
const text = (out.buf || '').trim();
|
||||
if (out.code !== 0) {
|
||||
let msg = text || 'c2x command failed';
|
||||
let msg = text || out.stderr || 'c2x command failed';
|
||||
try { const v = JSON.parse(text); msg = v.error || msg; } catch { /* keep */ }
|
||||
throw new Error(msg);
|
||||
}
|
||||
@@ -1764,11 +1766,12 @@ function runCli(args) {
|
||||
return new Promise((resolve) => {
|
||||
if (!BIN) return resolve({ code: -1, buf: 'neurosploit binary not found — run `cargo build --release` in neurosploit-rs/' });
|
||||
const child = spawn(BIN, args, { cwd: ROOT, env: { ...process.env, ...envOverrides() } });
|
||||
let buf = '';
|
||||
child.stdout.on('data', (c) => { buf += c.toString('utf8'); });
|
||||
child.stderr.on('data', (c) => { buf += c.toString('utf8'); });
|
||||
child.on('close', (code) => resolve({ code, buf: stripAnsi(buf) }));
|
||||
child.on('error', (e) => resolve({ code: -1, buf: e.message }));
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
child.stdout.on('data', (c) => { stdout += c.toString('utf8'); });
|
||||
child.stderr.on('data', (c) => { stderr += c.toString('utf8'); });
|
||||
child.on('close', (code) => resolve({ code, buf: stripAnsi(stdout), stderr: stripAnsi(stderr) }));
|
||||
child.on('error', (e) => resolve({ code: -1, buf: e.message, stderr: '' }));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user