Release / Plan (reuse the published image?) (push) Successful in 3s
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 28s
CI / Dependency audit (push) Successful in 20s
CI / Tests (Linux, race detector) (push) Successful in 1m10s
Release / ci (push) Successful in 1m10s
Release / Build image (arm64) (push) Successful in 55s
Release / Build image (amd64) (push) Successful in 1m16s
Release / Publish tags (push) Successful in 14s
Release / Gitea release (push) Skipped
New pages grouped in the rail (Monitor, Investigate, Analyze, Operate, Reports): Services (SLO, Apdex, latency app vs proxy), Sessions (stage funnel), Campaigns, Event search, MITRE ATT&CK matrix, Evolution, Concentration (Pareto, Gini), Survival (Kaplan-Meier per attack episode, recidivists), Where errors come from (application vs failed attack vs proxy vs client), Protocols and TLS, Defense (fail2ban, SSH, blocklist), Integrity, and a printable executive report. Chart library (donut, radar, stacked area, bars, heatmap, gauge), glossary with accessible "?" tooltips, self-explanatory category names (nonexistent page 404), page loader through pages.json. Unique visitors fixed: real browsers opening a page, one per IP per day, deduplicated across domains, with non-human clients counted apart. Anonymous legitimate visits on the Live page (?visits=1, no IP). Traefik origin, service, protocol and TLS fields parsed. Paths and Referer paths drop e-mail and token segments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
221 lines
12 KiB
JavaScript
221 lines
12 KiB
JavaScript
/* Urutau - SEARCH page: event search over /api/v1/events with cursor paging, CSV export
|
|
in the browser. Hostile data: textContent only; CSV cells starting with = + - @ get a ' prefix. */
|
|
(function () {
|
|
'use strict';
|
|
var CATS = ['notfound', 'scanner', 'bruteforce', 'exploit', 'ssh-fail', 'ssh-probe', 'ssh-ok', 'ban'];
|
|
var CAT_OK = {}; CATS.concat(['ok']).forEach(function (c) { CAT_OK[c] = 1; });
|
|
var ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="6.5"/><path d="M16 16l5 5"/></svg>';
|
|
var PAGE = 100, MAXROWS = 5000;
|
|
|
|
function boot() {
|
|
var U = window.Urutau;
|
|
if (!U || !U.registerPage) return false;
|
|
var t = U.t, nf = U.fmt.num;
|
|
function h(tag, a) { if (typeof a === 'string') a = { class: a }; return U.el.apply(null, [tag, a].concat([].slice.call(arguments, 2))); }
|
|
U.registerI18n({
|
|
en: {
|
|
'sr.title': 'Event search',
|
|
'sr.lead.one': '{n} event found',
|
|
'sr.lead.other': '{n} events found',
|
|
'sr.lead.more': 'More events match; load more to continue.',
|
|
'sr.lead.body': 'Events {range}, newest first.',
|
|
'sr.lead.empty': 'No event matches',
|
|
'sr.lead.emptyBody': 'Nothing {range} fits these filters, or the event registry is off.',
|
|
'sr.f.ip': 'IP or prefix',
|
|
'sr.f.q': 'Path contains',
|
|
'sr.f.fam': 'Family',
|
|
'sr.f.cat': 'Category',
|
|
'sr.f.status': 'Status',
|
|
'sr.f.host': 'Host',
|
|
'sr.f.period': 'Period',
|
|
'sr.f.all': 'All',
|
|
'sr.f.s2': '2xx',
|
|
'sr.f.s3': '3xx',
|
|
'sr.f.s4': '4xx',
|
|
'sr.f.s5': '5xx',
|
|
'sr.search': 'Search',
|
|
'sr.clear': 'Clear',
|
|
'sr.more': 'Load more',
|
|
'sr.csv': 'Export CSV',
|
|
'sr.csv.done': 'CSV saved',
|
|
'sr.c.time': 'Time',
|
|
'sr.c.ip': 'Address',
|
|
'sr.c.cat': 'Category',
|
|
'sr.c.host': 'Host',
|
|
'sr.c.path': 'Request',
|
|
'sr.c.status': 'Status',
|
|
'sr.c.fam': 'Family',
|
|
'sr.statusnote': 'The status filter applies to the rows already loaded.',
|
|
'sr.cap': 'Row limit reached ({n}); narrow the search.',
|
|
'sr.err': 'Search failed.',
|
|
'sr.retry': 'Try again',
|
|
'sr.busy': 'The server is busy; try again in a few seconds.',
|
|
'sr.badq': 'The server rejected these filters.'
|
|
},
|
|
'pt-BR': {
|
|
'sr.title': 'Busca de eventos',
|
|
'sr.lead.one': '{n} evento encontrado',
|
|
'sr.lead.other': '{n} eventos encontrados',
|
|
'sr.lead.more': 'Há mais eventos; carregue mais para continuar.',
|
|
'sr.lead.body': 'Eventos {range}, do mais novo ao mais antigo.',
|
|
'sr.lead.empty': 'Nenhum evento encontrado',
|
|
'sr.lead.emptyBody': 'Nada {range} combina com estes filtros, ou o registro de eventos está desligado.',
|
|
'sr.f.ip': 'IP ou prefixo',
|
|
'sr.f.q': 'Caminho contém',
|
|
'sr.f.fam': 'Família',
|
|
'sr.f.cat': 'Categoria',
|
|
'sr.f.status': 'Status',
|
|
'sr.f.host': 'Servidor',
|
|
'sr.f.period': 'Período',
|
|
'sr.f.all': 'Todos',
|
|
'sr.f.s2': '2xx',
|
|
'sr.f.s3': '3xx',
|
|
'sr.f.s4': '4xx',
|
|
'sr.f.s5': '5xx',
|
|
'sr.search': 'Buscar',
|
|
'sr.clear': 'Limpar',
|
|
'sr.more': 'Carregar mais',
|
|
'sr.csv': 'Exportar CSV',
|
|
'sr.csv.done': 'CSV salvo',
|
|
'sr.c.time': 'Hora',
|
|
'sr.c.ip': 'Endereço',
|
|
'sr.c.cat': 'Categoria',
|
|
'sr.c.host': 'Servidor',
|
|
'sr.c.path': 'Requisição',
|
|
'sr.c.status': 'Status',
|
|
'sr.c.fam': 'Família',
|
|
'sr.statusnote': 'O filtro de status vale para as linhas já carregadas.',
|
|
'sr.cap': 'Limite de linhas atingido ({n}); restrinja a busca.',
|
|
'sr.err': 'A busca falhou.',
|
|
'sr.retry': 'Tentar de novo',
|
|
'sr.busy': 'O servidor está ocupado; tente de novo em alguns segundos.',
|
|
'sr.badq': 'O servidor recusou estes filtros.'
|
|
}
|
|
});
|
|
function catKey(c) { return CAT_OK[c] ? c : 'ok'; }
|
|
function csvCell(v) {
|
|
var s = v === null || v === undefined ? '' : String(v);
|
|
if (/^[=+\-@\t\r]/.test(s)) s = "'" + s;
|
|
return /[",\n\r]/.test(s) ? '"' + s.replace(/"/g, '""') + '"' : s;
|
|
}
|
|
function statusOk(f, st) { return !f || String(Math.floor((st || 0) / 100)) === f; }
|
|
function iso(sec) { return new Date(sec * 1000).toISOString(); }
|
|
|
|
var inst = null;
|
|
function Page(root, ctx) {
|
|
var self = this, alive = true, seq = 0, rows = [], next = '', total = 0, loaded = false, busy = false, err = '', capped = false;
|
|
this.ctx = ctx;
|
|
var q0 = (ctx.params && ctx.params.query) || {};
|
|
var F = { ip: q0.ip || '', q: q0.q || '', fam: q0.fam || '', cat: CATS.indexOf(q0.cat) >= 0 ? q0.cat : '', status: '', host: '' };
|
|
var wrap = h('div', 'sr'), leadBox = h('div'), form = h('form', { class: 'sr-form', novalidate: true }), out = h('div');
|
|
root.appendChild(wrap); wrap.appendChild(leadBox); wrap.appendChild(form); wrap.appendChild(out);
|
|
var inputs = {};
|
|
function field(key, label, el) { inputs[key] = el; return h('label', 'sr-fld', h('span', { text: label }), el); }
|
|
function buildForm() {
|
|
form.textContent = ''; inputs = {};
|
|
function text(key, label, ph, max) { var i = h('input', { type: 'text', maxlength: max, autocomplete: 'off', spellcheck: 'false', placeholder: ph || '' }); i.value = F[key]; return field(key, label, i); }
|
|
form.appendChild(text('ip', t('sr.f.ip'), '198.51.100.7', 64));
|
|
form.appendChild(text('q', t('sr.f.q'), '/.env', 200));
|
|
form.appendChild(text('fam', t('sr.f.fam'), '', 40));
|
|
var cat = h('select'); cat.appendChild(h('option', { value: '', text: t('sr.f.all') }));
|
|
CATS.forEach(function (c) { cat.appendChild(h('option', { value: c, text: t('cat.short.' + c) })); }); cat.value = F.cat;
|
|
form.appendChild(field('cat', t('sr.f.cat'), cat));
|
|
var stt = h('select'); [['', t('sr.f.all')], ['2', t('sr.f.s2')], ['3', t('sr.f.s3')], ['4', t('sr.f.s4')], ['5', t('sr.f.s5')]].forEach(function (o) { stt.appendChild(h('option', { value: o[0], text: o[1] })); });
|
|
stt.value = F.status; stt.title = t('sr.statusnote');
|
|
form.appendChild(field('status', t('sr.f.status'), stt));
|
|
form.appendChild(text('host', t('sr.f.host'), '', 64));
|
|
form.appendChild(h('div', 'sr-fld', h('span', { text: t('sr.f.period') }), h('b', { class: 'sr-period', text: U.rangeLabel() })));
|
|
var go = h('button', { type: 'submit', class: 'btn primary', text: t('sr.search') });
|
|
var clr = h('button', { type: 'button', class: 'btn', text: t('sr.clear') });
|
|
clr.addEventListener('click', function () { F = { ip: '', q: '', fam: '', cat: '', status: '', host: '' }; buildForm(); run(); });
|
|
form.appendChild(h('div', 'sr-act', go, clr));
|
|
}
|
|
form.addEventListener('submit', function (e) { e.preventDefault(); readForm(); run(); });
|
|
inputs = {};
|
|
function readForm() { Object.keys(F).forEach(function (k) { if (inputs[k]) F[k] = String(inputs[k].value || '').trim(); }); }
|
|
function params(cursor) {
|
|
var p = Object.assign({ limit: PAGE }, U.rangeParams());
|
|
var host = F.host || (self.ctx.host && self.ctx.host !== 'all' ? self.ctx.host : '');
|
|
if (host) p.host = host;
|
|
['ip', 'q', 'fam', 'cat'].forEach(function (k) { if (F[k]) p[k] = F[k]; });
|
|
if (cursor) p.cursor = cursor;
|
|
return p;
|
|
}
|
|
function run() { rows = []; next = ''; total = 0; loaded = false; err = ''; capped = false; fetchPage(''); }
|
|
function fetchPage(cursor) {
|
|
var my = ++seq; busy = true; paint();
|
|
U.api('/api/v1/events', params(cursor)).then(function (d) {
|
|
if (!alive || my !== seq) return;
|
|
busy = false; loaded = true; err = '';
|
|
rows = rows.concat(d.events || []); total = d.total_estimate || rows.length; next = d.next || '';
|
|
if (rows.length >= MAXROWS) { capped = true; next = ''; }
|
|
paint();
|
|
}).catch(function (e) {
|
|
if (!alive || my !== seq) return;
|
|
busy = false; loaded = true; err = e && e.status === 503 ? 'sr.busy' : e && e.status === 400 ? 'sr.badq' : 'sr.err'; paint();
|
|
});
|
|
}
|
|
function visible() { return rows.filter(function (r) { return statusOk(F.status, r.status); }); }
|
|
function exportCsv() {
|
|
var cols = ['t', 'ip', 'cat', 'host', 'domain', 'method', 'path', 'status', 'fam', 'cc'];
|
|
var lines = [cols.join(',')];
|
|
visible().forEach(function (r) { lines.push(cols.map(function (c) { return csvCell(c === 't' ? iso(r.t) : r[c]); }).join(',')); });
|
|
var url = URL.createObjectURL(new Blob([lines.join('\r\n') + '\r\n'], { type: 'text/csv;charset=utf-8' }));
|
|
var a = document.createElement('a'); a.href = url; a.download = 'urutau-events.csv'; document.body.appendChild(a); a.click();
|
|
setTimeout(function () { URL.revokeObjectURL(url); if (a.parentNode) a.parentNode.removeChild(a); }, 500);
|
|
U.toast(t('sr.csv.done'));
|
|
}
|
|
function paint() {
|
|
leadBox.textContent = ''; out.textContent = '';
|
|
var vis = visible(), range = U.rangeLabel({ inline: true });
|
|
if (err) {
|
|
var rb = h('button', { type: 'button', class: 'btn', text: t('sr.retry') }); rb.addEventListener('click', run);
|
|
out.appendChild(h('div', 'state-error', h('strong', { text: t(err) }), rb)); return;
|
|
}
|
|
if (!loaded) { out.appendChild(h('div', 'skeleton')); return; }
|
|
leadBox.appendChild(vis.length ? U.ui.lead(U.pl('sr.lead', vis.length, { n: nf(vis.length) + (next ? '+' : '') }), t('sr.lead.body', { range: range }) + (next ? ' ' + t('sr.lead.more') : ''), 'ok')
|
|
: U.ui.lead(t('sr.lead.empty'), t('sr.lead.emptyBody', { range: range }), 'neutral'));
|
|
if (!vis.length) { if (next) out.appendChild(moreBtn()); return; }
|
|
var tb = h('tbody');
|
|
vis.forEach(function (r) {
|
|
function td(l, k, c) { return h('td', { 'data-label': l, class: c || null }, k); }
|
|
var c = catKey(r.cat), st = r.status ? String(r.status) : '';
|
|
tb.appendChild(h('tr', 'row',
|
|
td(t('sr.c.time'), h('span', { text: U.fmt.date(r.t) }), 'nw'),
|
|
td(t('sr.c.ip'), h('a', { class: 'mono sr-ip', href: '#/ip/' + encodeURIComponent(r.ip || ''), text: r.ip || '' })),
|
|
td(t('sr.c.cat'), h('span', { class: 'sr-cat sr-c-' + c, text: t('cat.short.' + c) })),
|
|
td(t('sr.c.host'), h('span', { text: r.domain || r.host || '' })),
|
|
td(t('sr.c.path'), h('span', { class: 'mono sr-path', text: ((r.method || '') + ' ' + (r.path || r.user || r.jail || '')).trim() })),
|
|
td(t('sr.c.status'), h('span', { class: 'num', text: st })),
|
|
td(t('sr.c.fam'), h('span', { text: r.fam || '' }))));
|
|
});
|
|
var th = h('tr'); ['time', 'ip', 'cat', 'host', 'path', 'status', 'fam'].forEach(function (k) { th.appendChild(h('th', { text: t('sr.c.' + k) })); });
|
|
var csv = h('button', { type: 'button', class: 'btn', text: t('sr.csv') }); csv.addEventListener('click', exportCsv);
|
|
out.appendChild(U.ui.panel({ title: t('sr.title'), help: 'cat.scanner', actions: [csv] }, h('table', 'stack sr-table', h('thead', null, th), tb)));
|
|
if (capped) out.appendChild(h('p', { class: 'note', text: t('sr.cap', { n: nf(MAXROWS) }) }));
|
|
if (next) out.appendChild(moreBtn());
|
|
}
|
|
function moreBtn() { var b = h('button', { type: 'button', class: 'btn sr-more', text: t('sr.more') }); b.disabled = busy; b.addEventListener('click', function () { fetchPage(next); }); return b; }
|
|
buildForm();
|
|
this.update = function (c) {
|
|
var lang = self.ctx.lang; self.ctx = c;
|
|
if (lang !== c.lang) { readForm(); buildForm(); }
|
|
else { var p = form.querySelector('.sr-period'); if (p) p.textContent = U.rangeLabel(); }
|
|
var key = JSON.stringify(U.rangeParams()) + c.host;
|
|
if (key !== self.lastKey) { self.lastKey = key; run(); }
|
|
};
|
|
this.destroy = function () { alive = false; seq++; root.textContent = ''; };
|
|
this.lastKey = JSON.stringify(U.rangeParams()) + ctx.host;
|
|
run();
|
|
}
|
|
U.registerPage({
|
|
id: 'search', group: 'investigate', icon: ICON, titleKey: 'sr.title',
|
|
mount: function (el, ctx) { if (inst) inst.destroy(); inst = new Page(el, ctx); },
|
|
update: function (ctx) { if (inst) inst.update(ctx); },
|
|
unmount: function () { if (inst) { inst.destroy(); inst = null; } }
|
|
});
|
|
return true;
|
|
}
|
|
if (!boot()) document.addEventListener('DOMContentLoaded', boot);
|
|
})();
|