feat(api,gui): implement target groups CRUD, scanner hot-reload, and CSV export
This commit is contained in:
1 parent
bc72dbffbd
commit
e8e529b09c
7 files changed
+1154
-41
No files matched your search
+29
-6
@@ -321,7 +321,7 @@ html[data-theme="light"] .bar-track { fill: rgba(20, 48, 64, 0.06); }
|
||||
|
||||
.field { display: grid; gap: 6px; flex: 1; }
|
||||
.field > span { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 600; }
|
||||
input, select {
|
||||
input, select, textarea {
|
||||
width: 100%;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid var(--line-strong);
|
||||
@@ -330,11 +330,17 @@ input, select {
|
||||
outline: none;
|
||||
color: var(--text);
|
||||
font-size: 0.85rem;
|
||||
font-family: inherit;
|
||||
resize: vertical;
|
||||
}
|
||||
html[data-theme="light"] input, html[data-theme="light"] select { background: rgba(255, 255, 255, 0.8); }
|
||||
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.14); }
|
||||
html[data-theme="light"] input, html[data-theme="light"] select, html[data-theme="light"] textarea { background: rgba(255, 255, 255, 0.8); }
|
||||
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.14); }
|
||||
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
padding: 10px 15px;
|
||||
border: 1px solid var(--line-strong);
|
||||
border-radius: 10px;
|
||||
@@ -342,13 +348,30 @@ input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px r
|
||||
color: var(--text);
|
||||
font-size: 0.84rem;
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
transition: 140ms ease;
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn:hover { border-color: var(--accent); }
|
||||
.btn:hover { border-color: var(--accent); text-decoration: none; color: var(--text); }
|
||||
.btn.primary { background: var(--accent); border-color: var(--accent); color: #041b24; font-weight: 700; }
|
||||
.btn.primary:hover { filter: brightness(1.08); }
|
||||
.btn.small { padding: 6px 10px; font-size: 0.72rem; }
|
||||
.btn.primary:hover { filter: brightness(1.08); color: #041b24; }
|
||||
.btn.secondary { background: rgba(255, 255, 255, 0.03); border-color: var(--line); }
|
||||
.btn.secondary:hover { border-color: var(--line-strong); background: rgba(255, 255, 255, 0.07); }
|
||||
.btn.danger { background: rgba(244, 63, 94, 0.12); border-color: rgba(244, 63, 94, 0.35); color: #fda4af; }
|
||||
.btn.danger:hover { background: rgba(244, 63, 94, 0.22); border-color: #f43f5e; color: #fff; }
|
||||
.btn:disabled, .btn[disabled] { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
|
||||
.btn.small, .btn.btn-sm, .btn-sm { padding: 6px 11px; font-size: 0.74rem; border-radius: 8px; }
|
||||
|
||||
.panel-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
||||
.group-card-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
|
||||
.group-card-targets { font-family: var(--mono); font-size: 0.74rem; color: var(--muted); margin: 6px 0; word-break: break-all; }
|
||||
.group-card-badge { display: inline-block; padding: 2px 7px; border-radius: 6px; font-size: 0.68rem; font-weight: 600; text-transform: uppercase; background: rgba(56, 189, 248, 0.12); color: var(--accent); }
|
||||
.group-dlg { width: min(540px, calc(100vw - 32px)); }
|
||||
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
||||
.form-error { background: rgba(244, 63, 94, 0.15); border: 1px solid #f43f5e; color: #fda4af; padding: 10px 14px; border-radius: 8px; font-size: 0.8rem; margin-bottom: 14px; line-height: 1.4; }
|
||||
.field-hint { font-size: 0.72rem; color: var(--muted); margin-top: 2px; display: block; }
|
||||
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin: 20px 0 0; padding: 0; }
|
||||
|
||||
/* ------------------------------------------------------------------ SEVERITY BADGES */
|
||||
.sev-badge {
|
||||
|
||||
+211
-1
@@ -55,12 +55,28 @@ const findingsList = $('#findingsList');
|
||||
const groupsCount = $('#groupsCount');
|
||||
const groupsGrid = $('#groupsGrid');
|
||||
const feedsSummary = $('#feedsSummary');
|
||||
const btnNewGroup = $('#btnNewGroup');
|
||||
|
||||
// Group Modal
|
||||
const groupDlg = $('#groupDlg');
|
||||
const groupForm = $('#groupForm');
|
||||
const groupDlgTitle = $('#groupDlgTitle');
|
||||
const closeGroupDlg = $('#closeGroupDlg');
|
||||
const cancelGroupDlg = $('#cancelGroupDlg');
|
||||
const groupFormError = $('#groupFormError');
|
||||
const groupName = $('#groupName');
|
||||
const groupTargets = $('#groupTargets');
|
||||
const groupExclude = $('#groupExclude');
|
||||
const groupCron = $('#groupCron');
|
||||
const groupProfile = $('#groupProfile');
|
||||
const groupCriticality = $('#groupCriticality');
|
||||
|
||||
// Changes View
|
||||
const changesCount = $('#changesCount');
|
||||
const changesPeriodFilters = $('#changesPeriodFilters');
|
||||
const changesSearch = $('#changesSearch');
|
||||
const changesTimeline = $('#changesTimeline');
|
||||
const btnExportChangesCsv = $('#btnExportChangesCsv');
|
||||
|
||||
// Application State
|
||||
const state = {
|
||||
@@ -69,6 +85,7 @@ const state = {
|
||||
status: null,
|
||||
hosts: [],
|
||||
changes: [],
|
||||
config: null,
|
||||
lastUpdated: null,
|
||||
pollTimer: null,
|
||||
expandedHosts: new Set(),
|
||||
@@ -84,6 +101,8 @@ const state = {
|
||||
},
|
||||
};
|
||||
|
||||
let editingGroupName = null;
|
||||
|
||||
const VIEW_META = {
|
||||
overview: {
|
||||
title: 'Visão geral',
|
||||
@@ -211,11 +230,12 @@ function getAllFindings() {
|
||||
async function fetchData() {
|
||||
try {
|
||||
const period = state.filters.changesPeriod || '24h';
|
||||
const [healthRes, statusRes, hostsRes, changesRes] = await Promise.all([
|
||||
const [healthRes, statusRes, hostsRes, changesRes, configRes] = await Promise.all([
|
||||
fetch('/api/health').catch(() => null),
|
||||
fetch('/api/status').catch(() => null),
|
||||
fetch('/api/hosts').catch(() => null),
|
||||
fetch(`/api/changes?since=${encodeURIComponent(period)}`).catch(() => null),
|
||||
fetch('/api/config').catch(() => null),
|
||||
]);
|
||||
|
||||
if (!healthRes || !statusRes || !hostsRes) {
|
||||
@@ -226,6 +246,7 @@ async function fetchData() {
|
||||
state.status = await statusRes.json();
|
||||
state.hosts = await hostsRes.json();
|
||||
state.changes = changesRes && changesRes.ok ? await changesRes.json() : [];
|
||||
state.config = configRes && configRes.ok ? await configRes.json() : null;
|
||||
|
||||
state.lastUpdated = new Date();
|
||||
connection.classList.remove('offline');
|
||||
@@ -1031,8 +1052,22 @@ function renderGroups() {
|
||||
el('span', 'group-name', g.group),
|
||||
el('span', 'cron-tag', g.cron),
|
||||
);
|
||||
|
||||
const configGroup = state.config && state.config.grupo
|
||||
? state.config.grupo.find((cg) => cg.nome === g.group)
|
||||
: null;
|
||||
|
||||
if (configGroup && configGroup.criticidade) {
|
||||
head.append(el('span', 'group-card-badge', configGroup.criticidade));
|
||||
}
|
||||
card.append(head);
|
||||
|
||||
if (configGroup && configGroup.alvos && configGroup.alvos.length > 0) {
|
||||
const targetsDiv = el('div', 'group-card-targets');
|
||||
targetsDiv.textContent = configGroup.alvos.join(', ');
|
||||
card.append(targetsDiv);
|
||||
}
|
||||
|
||||
const details = el('div', 'hint');
|
||||
details.append(
|
||||
el('span', '', `${t('Perfil:')} `),
|
||||
@@ -1047,6 +1082,19 @@ function renderGroups() {
|
||||
);
|
||||
card.append(next);
|
||||
|
||||
// Actions row
|
||||
const actions = el('div', 'group-card-actions');
|
||||
const editBtn = el('button', 'btn secondary small', t('Editar'));
|
||||
editBtn.type = 'button';
|
||||
editBtn.addEventListener('click', () => openEditGroupDialog(g.group));
|
||||
|
||||
const removeBtn = el('button', 'btn danger small', t('Remover'));
|
||||
removeBtn.type = 'button';
|
||||
removeBtn.addEventListener('click', () => deleteGroup(g.group));
|
||||
|
||||
actions.append(editBtn, removeBtn);
|
||||
card.append(actions);
|
||||
|
||||
groupsGrid.append(card);
|
||||
});
|
||||
}
|
||||
@@ -1072,6 +1120,146 @@ function renderGroups() {
|
||||
}
|
||||
}
|
||||
|
||||
function populateProfilesDropdown() {
|
||||
groupProfile.replaceChildren();
|
||||
const profiles = state.config && state.config.perfis ? Object.keys(state.config.perfis) : ['padrao'];
|
||||
if (!profiles.includes('padrao')) {
|
||||
profiles.unshift('padrao');
|
||||
}
|
||||
profiles.forEach((p) => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = p;
|
||||
opt.textContent = p;
|
||||
groupProfile.append(opt);
|
||||
});
|
||||
}
|
||||
|
||||
function openCreateGroupDialog() {
|
||||
editingGroupName = null;
|
||||
groupDlgTitle.textContent = t('Novo Grupo');
|
||||
groupFormError.hidden = true;
|
||||
groupFormError.textContent = '';
|
||||
groupName.value = '';
|
||||
groupName.disabled = false;
|
||||
groupTargets.value = '';
|
||||
groupExclude.value = '';
|
||||
groupCron.value = '';
|
||||
populateProfilesDropdown();
|
||||
groupProfile.value = 'padrao';
|
||||
groupCriticality.value = '';
|
||||
groupDlg.showModal();
|
||||
}
|
||||
|
||||
function openEditGroupDialog(name) {
|
||||
const group = state.config && state.config.grupo
|
||||
? state.config.grupo.find((g) => g.nome === name)
|
||||
: null;
|
||||
if (!group) return;
|
||||
|
||||
editingGroupName = name;
|
||||
groupDlgTitle.textContent = `${t('Editar Grupo')} — ${name}`;
|
||||
groupFormError.hidden = true;
|
||||
groupFormError.textContent = '';
|
||||
groupName.value = group.nome || '';
|
||||
groupName.disabled = false;
|
||||
groupTargets.value = (group.alvos || []).join('\n');
|
||||
groupExclude.value = (group.excluir || []).join('\n');
|
||||
groupCron.value = group.cron || '';
|
||||
populateProfilesDropdown();
|
||||
groupProfile.value = group.perfil || 'padrao';
|
||||
groupCriticality.value = group.criticidade || '';
|
||||
groupDlg.showModal();
|
||||
}
|
||||
|
||||
async function handleGroupFormSubmit(e) {
|
||||
e.preventDefault();
|
||||
groupFormError.hidden = true;
|
||||
groupFormError.textContent = '';
|
||||
|
||||
const name = groupName.value.trim();
|
||||
if (!name) {
|
||||
groupFormError.hidden = false;
|
||||
groupFormError.textContent = t('Nome do grupo é obrigatório.');
|
||||
return;
|
||||
}
|
||||
|
||||
const targets = groupTargets.value
|
||||
.split(/[\n,]+/)
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
if (targets.length === 0) {
|
||||
groupFormError.hidden = false;
|
||||
groupFormError.textContent = t('Pelo menos um alvo autorizado é obrigatório.');
|
||||
return;
|
||||
}
|
||||
|
||||
const exclude = groupExclude.value
|
||||
.split(/[\n,]+/)
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
const payload = {
|
||||
nome: name,
|
||||
alvos: targets,
|
||||
};
|
||||
if (exclude.length > 0) payload.excluir = exclude;
|
||||
if (groupCron.value.trim()) payload.cron = groupCron.value.trim();
|
||||
if (groupProfile.value) payload.perfil = groupProfile.value;
|
||||
if (groupCriticality.value) payload.criticidade = groupCriticality.value;
|
||||
|
||||
try {
|
||||
let res;
|
||||
if (editingGroupName) {
|
||||
res = await fetch(`/api/config/groups/${encodeURIComponent(editingGroupName)}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
} else {
|
||||
res = await fetch('/api/config/groups', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
|
||||
if (!res.ok) {
|
||||
const errText = await res.text();
|
||||
groupFormError.hidden = false;
|
||||
groupFormError.textContent = errText || t('Erro ao salvar grupo');
|
||||
return;
|
||||
}
|
||||
|
||||
groupDlg.close();
|
||||
await fetchData();
|
||||
} catch (err) {
|
||||
groupFormError.hidden = false;
|
||||
groupFormError.textContent = err.message || t('Erro de rede ao salvar grupo');
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteGroup(name) {
|
||||
const confirmed = window.confirm(
|
||||
`${t('Tem certeza que deseja remover o grupo')} "${name}"?`
|
||||
);
|
||||
if (!confirmed) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/config/groups/${encodeURIComponent(name)}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (!res.ok) {
|
||||
const errText = await res.text();
|
||||
alert(errText || t('Erro ao remover grupo'));
|
||||
return;
|
||||
}
|
||||
await fetchData();
|
||||
} catch (err) {
|
||||
alert(err.message || t('Erro de rede ao remover grupo'));
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ CHANGES VIEW
|
||||
function renderChanges() {
|
||||
changesTimeline.replaceChildren();
|
||||
@@ -1260,10 +1448,32 @@ function initEvents() {
|
||||
changesPeriodFilters.querySelectorAll('button').forEach((b) => b.classList.remove('active'));
|
||||
btn.classList.add('active');
|
||||
state.filters.changesPeriod = btn.dataset.period;
|
||||
if (btnExportChangesCsv) {
|
||||
btnExportChangesCsv.href = `/api/export/changes.csv?since=${encodeURIComponent(btn.dataset.period)}`;
|
||||
}
|
||||
fetchData();
|
||||
});
|
||||
});
|
||||
|
||||
// Group Dialog
|
||||
if (btnNewGroup) {
|
||||
btnNewGroup.addEventListener('click', openCreateGroupDialog);
|
||||
}
|
||||
if (closeGroupDlg) {
|
||||
closeGroupDlg.addEventListener('click', () => groupDlg.close());
|
||||
}
|
||||
if (cancelGroupDlg) {
|
||||
cancelGroupDlg.addEventListener('click', () => groupDlg.close());
|
||||
}
|
||||
if (groupForm) {
|
||||
groupForm.addEventListener('submit', handleGroupFormSubmit);
|
||||
}
|
||||
if (groupDlg) {
|
||||
groupDlg.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape') groupDlg.close();
|
||||
});
|
||||
}
|
||||
|
||||
// Keyboard shortcut for settings: Escape to close dialog
|
||||
settingsDlg.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape') settingsDlg.close();
|
||||
|
||||
@@ -152,4 +152,26 @@ export const EN = {
|
||||
'Auto': 'Auto',
|
||||
'Português': 'Português',
|
||||
'English': 'English',
|
||||
|
||||
// Actions, Exports & Group Management
|
||||
'Exportar CSV': 'Export CSV',
|
||||
'Exportar relatório executivo (em breve)': 'Export executive report (coming soon)',
|
||||
'+ Novo grupo': '+ New group',
|
||||
'Novo Grupo': 'New Group',
|
||||
'Editar Grupo': 'Edit Group',
|
||||
'Editar': 'Edit',
|
||||
'Remover': 'Remove',
|
||||
'Nome do grupo *': 'Group name *',
|
||||
'Alvos autorizados (um por linha ou separados por vírgula) *': 'Authorized targets (one per line or comma-separated) *',
|
||||
'Exclusões (opcional, um por linha ou separados por vírgula)': 'Exclusions (optional, one per line or comma-separated)',
|
||||
'Expressão Cron (opcional)': 'Cron expression (optional)',
|
||||
'Em branco usa o padrão global (@daily)': 'Blank uses global default (@daily)',
|
||||
'Perfil de portas': 'Port profile',
|
||||
'Criticidade (opcional)': 'Criticality (optional)',
|
||||
'Padrão / Não definida': 'Default / Unset',
|
||||
'Salvar Grupo': 'Save Group',
|
||||
'Cancelar': 'Cancel',
|
||||
'Tem certeza que deseja remover o grupo': 'Are you sure you want to remove the group',
|
||||
'Pelo menos um alvo autorizado é obrigatório.': 'At least one authorized target is required.',
|
||||
'Nome do grupo é obrigatório.': 'Group name is required.',
|
||||
};
|
||||
+65
-4
@@ -154,7 +154,11 @@
|
||||
<h2>Hosts e Superfície Descoberta</h2>
|
||||
<p class="hint">Ativos mapeados no escopo. Clique em uma linha para ver as portas abertas, serviços e achados correlacionados.</p>
|
||||
</div>
|
||||
<span id="hostCount" class="panel-tag">—</span>
|
||||
<div class="panel-actions">
|
||||
<span id="hostCount" class="panel-tag">—</span>
|
||||
<a href="/api/export/hosts.csv" class="btn secondary btn-sm" download>Exportar CSV</a>
|
||||
<button type="button" class="btn secondary btn-sm" disabled title="Em breve">Exportar relatório executivo (em breve)</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="toolbar toolbar-slim">
|
||||
@@ -201,7 +205,10 @@
|
||||
<h2>Inventário de Vulnerabilidades e Checagens</h2>
|
||||
<p class="hint">Filtre, ordene e expanda cada achado para inspecionar a evidência determinística completa.</p>
|
||||
</div>
|
||||
<span id="findingsCount" class="panel-tag">—</span>
|
||||
<div class="panel-actions">
|
||||
<span id="findingsCount" class="panel-tag">—</span>
|
||||
<a href="/api/export/findings.csv" class="btn secondary btn-sm" download>Exportar CSV</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="toolbar">
|
||||
@@ -242,7 +249,10 @@
|
||||
<h2>Grupos e Cadência de Varredura</h2>
|
||||
<p class="hint">Definições de alvos, perfis de portas e próximas execuções do agendador contínuo.</p>
|
||||
</div>
|
||||
<span id="groupsCount" class="panel-tag">—</span>
|
||||
<div class="panel-actions">
|
||||
<span id="groupsCount" class="panel-tag">—</span>
|
||||
<button type="button" id="btnNewGroup" class="btn primary btn-sm">+ Novo grupo</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="groupsGrid" class="groups-grid">
|
||||
@@ -269,7 +279,10 @@
|
||||
<h2>Histórico de Mudanças na Superfície</h2>
|
||||
<p class="hint">Diferenças detectadas entre lotes: hosts novos ou sumidos, portas abertas/fechadas e alterações de serviço.</p>
|
||||
</div>
|
||||
<span id="changesCount" class="panel-tag">—</span>
|
||||
<div class="panel-actions">
|
||||
<span id="changesCount" class="panel-tag">—</span>
|
||||
<a id="btnExportChangesCsv" href="/api/export/changes.csv?since=24h" class="btn secondary btn-sm" download>Exportar CSV</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="toolbar toolbar-slim">
|
||||
@@ -327,6 +340,54 @@
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
<!-- MODAL DE CRIAR / EDITAR GRUPO -->
|
||||
<dialog id="groupDlg" class="group-dlg" aria-labelledby="groupDlgTitle">
|
||||
<form id="groupForm" method="dialog">
|
||||
<div class="dialog-head">
|
||||
<h2 id="groupDlgTitle">Novo Grupo</h2>
|
||||
<button type="button" id="closeGroupDlg" class="icon-btn" aria-label="Fechar" title="Fechar">×</button>
|
||||
</div>
|
||||
<div id="groupFormError" class="form-error" hidden></div>
|
||||
<label class="field">
|
||||
<span>Nome do grupo *</span>
|
||||
<input type="text" id="groupName" name="name" required placeholder="ex: servidores-web" autocomplete="off">
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Alvos autorizados (um por linha ou separados por vírgula) *</span>
|
||||
<textarea id="groupTargets" name="targets" rows="3" required placeholder="192.168.1.0/24 10.0.0.1" spellcheck="false"></textarea>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Exclusões (opcional, um por linha ou separados por vírgula)</span>
|
||||
<textarea id="groupExclude" name="exclude" rows="2" placeholder="192.168.1.1" spellcheck="false"></textarea>
|
||||
</label>
|
||||
<div class="form-row">
|
||||
<label class="field">
|
||||
<span>Expressão Cron (opcional)</span>
|
||||
<input type="text" id="groupCron" name="cron" placeholder="ex: 0 2 * * * ou @daily" autocomplete="off">
|
||||
<small class="field-hint">Em branco usa o padrão global (@daily)</small>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Perfil de portas</span>
|
||||
<select id="groupProfile" name="profile"></select>
|
||||
</label>
|
||||
</div>
|
||||
<label class="field">
|
||||
<span>Criticidade (opcional)</span>
|
||||
<select id="groupCriticality" name="criticality">
|
||||
<option value="">Padrão / Não definida</option>
|
||||
<option value="baixa">Baixa</option>
|
||||
<option value="media">Média</option>
|
||||
<option value="alta">Alta</option>
|
||||
<option value="critica">Crítica</option>
|
||||
</select>
|
||||
</label>
|
||||
<menu class="dlg-actions">
|
||||
<button type="button" id="cancelGroupDlg" class="btn secondary">Cancelar</button>
|
||||
<button type="submit" id="saveGroupBtn" class="btn primary">Salvar Grupo</button>
|
||||
</menu>
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
<script type="module" src="/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user