feat: 1.4.1 pagination, network probes, survival by blocker, report polish
Release / Publish tags (push) Successful in 18s
Release / Plan (reuse the published image?) (push) Successful in 5s
Release / ci (push) Successful in 1m47s
Release / Build image (amd64) (push) Successful in 21s
Release / Build image (arm64) (push) Successful in 28s
CI / Format and vet (push) Successful in 23s
CI / Tests (Linux, race detector) (push) Successful in 1m24s
CI / Dependency audit (push) Successful in 24s
CI / Docker image (build and smoke test) (push) Skipped
Release / Gitea release (push) Successful in 5s

Backend pagination with one pager for sessions, IPs, campaigns and events;
network probe source (port-scan, T1046, second firewall reason port-scan);
host kit logs inbound probes; urutau call on the report cover.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-15 00:21:43 -03:00
1 parent f27d8441a9
commit 432f521ed1
40 files changed
+927 -136

No files matched your search

+85 -20
View File
@@ -68,7 +68,7 @@
* heatmap(matrix[row][col], xLabels[], yLabels[], {format, title}) cells use --seq-1..5
* sparkline(values[]) gauge(value, max, thresholds[{at,tone:'ok|warn|danger|info'}], {label, format})
* colors are CSS token names ("--viz-1"); the default palette is --viz-1..8 in order.
* Urutau.ui = { panel, stat, metric, lead, empty, badge, bars, chart, sparkline } shared primitives
* Urutau.ui = { panel, stat, metric, lead, empty, badge, bars, chart, sparkline, pager } shared primitives
* (the same ones the core pages use; see their definitions below)
*
* Security rule of this file: log data is hostile. Dynamic text goes through
@@ -644,10 +644,47 @@
return function () { off(); clearTimeout(timer); timer = 0; };
}
// ---------------------------------------------------------------- pager
// pager({page, pages, total, onPage, hasNext, label}): numbered pages (first/prev/next/last, ellipses) when the
// page count is known; with only hasNext (cursor lists) just previous/next and "page N". Returns null when
// there is nothing to page through.
function pager(o) {
var page = Math.max(1, o.page || 1), known = typeof o.pages === 'number', pages = known ? Math.max(1, o.pages) : 0;
if (known && pages <= 1) return null;
if (!known && page <= 1 && !o.hasNext) return null;
var nav = el('nav', { class: 'pgr', 'aria-label': o.label || t('pager.nav') });
function go(n) { return function () { if (o.onPage) o.onPage(n); }; }
function btn(txt, aria, n, off, cls) {
var b = el('button', { type: 'button', class: 'btn pgr-b ' + (cls || ''), 'aria-label': aria, title: aria, disabled: off }, txt);
if (!off) b.addEventListener('click', go(n));
return b;
}
var atEnd = known ? page >= pages : !o.hasNext;
var list = h('div', 'pgr-l');
if (known) list.appendChild(btn('\u00ab', t('pager.first'), 1, page <= 1, 'pgr-edge'));
list.appendChild(btn('\u2039', t('pager.prev'), page - 1, page <= 1));
if (known) {
var seq = [], last = 0;
for (var i = 1; i <= pages; i++) if (i === 1 || i === pages || Math.abs(i - page) <= 1) seq.push(i);
seq.forEach(function (n) {
if (last && n - last > 1) list.appendChild(h('span', 'pgr-gap', n - last === 2 ? String(last + 1) : '\u2026'));
var b = el('button', { type: 'button', class: 'btn pgr-b pgr-n' + (n === page ? ' on' : ''), 'aria-label': t('pager.goto', { n: nf(n) }) }, nf(n));
if (n === page) b.setAttribute('aria-current', 'page'); else b.addEventListener('click', go(n));
list.appendChild(b); last = n;
});
}
list.appendChild(btn('\u203a', t('pager.next'), page + 1, atEnd));
if (known) list.appendChild(btn('\u00bb', t('pager.last'), pages, atEnd, 'pgr-edge'));
var info = known ? t('pager.page', { n: nf(page), m: nf(pages) }) + (o.total !== undefined && o.total !== null ? ' \u00b7 ' + (o.totalText || nf(o.total)) : '') : t('pager.pageN', { n: nf(page) });
nav.appendChild(h('span', 'pgr-i', info));
nav.appendChild(list);
return nav;
}
// ---------------------------------------------------------------- IP table
function sumCounts(c) { var s = 0; for (var k in c) s += c[k]; return s; }
function ipTable(full) {
var st = { sort: 'score', order: 'desc', page: 1, per: window.innerWidth < 768 ? 25 : (full ? 50 : 25), q: '', level: '', banned: false, total: 0, sig: '', ctxKey: '', multi: false, headSig: '' };
var st = { sort: 'score', order: 'desc', page: 1, per: 25, q: '', level: '', banned: false, total: 0, sig: '', ctxKey: '', multi: false, headSig: '' };
var timer = 0, alive = true, onTotal = null;
var search = el('input', { type: 'search', autocomplete: 'off', placeholder: t('ips.search'), 'aria-label': t('ips.search') });
var levelSel = el('select', { 'aria-label': t('ips.level') });
@@ -657,15 +694,14 @@
var perSel = null;
if (full) {
perSel = el('select', { 'aria-label': t('ips.perPage') });
[25, 50, 100, 200].forEach(function (n) { perSel.appendChild(el('option', { value: String(n) }, String(n))); });
[25, 50, 100].forEach(function (n) { perSel.appendChild(el('option', { value: String(n) }, String(n))); });
perSel.value = String(st.per);
toolbar.appendChild(perSel);
}
var thead = h('thead'), tbody = h('tbody');
var table = h('table', 'stack tbl-cards', thead, tbody);
var count = h('span'), page = h('span'), prev = el('button', { type: 'button', class: 'btn' }, t('pager.prev')), next = el('button', { type: 'button', class: 'btn' }, t('pager.next'));
var pager = h('div', 'pager', count, h('div', 'btns', page, prev, next));
var node = h('div', null, toolbar, h('div', 'tbl-wrap', table), pager);
var pagerBox = h('div', 'pgr-box');
var node = h('div', null, toolbar, h('div', 'tbl-wrap', table), pagerBox);
function cols() {
var c = [{ k: 'ip', s: 'ip' }, { k: 'score', s: 'score' }, { k: 'level' }, { k: 'cats' }, { k: 'origin' }];
@@ -690,7 +726,7 @@
var b = el('button', { type: 'button' }, colLabel(x.k));
b.addEventListener('click', function () {
if (st.sort === x.s) st.order = st.order === 'desc' ? 'asc' : 'desc'; else { st.sort = x.s; st.order = 'desc'; }
st.page = 1; load();
reset();
});
th.appendChild(b);
} else th.textContent = colLabel(x.k);
@@ -755,20 +791,30 @@
tr.addEventListener('keydown', function (ev) { if (ev.key === 'Enter' || ev.key === ' ') { ev.preventDefault(); openIP(x.ip); } });
tbody.appendChild(tr);
});
drawPager();
}
function drawPager() {
clear(pagerBox);
var pages = Math.max(1, Math.ceil(st.total / st.per));
count.textContent = pl('pager.count', st.total, { n: nf(st.total) });
page.textContent = full ? t('pager.page', { n: nf(st.page), m: nf(pages) }) : '';
prev.disabled = st.page <= 1;
next.disabled = st.page >= pages;
var pg = pager({ page: st.page, pages: pages, total: st.total, totalText: pl('pager.count', st.total, { n: nf(st.total) }), onPage: goPage });
if (pg) pagerBox.appendChild(pg); else pagerBox.appendChild(h('p', 'note', pl('pager.count', st.total, { n: nf(st.total) })));
}
// the full page keeps its page number in the URL (&p=3); the overview widget keeps it locally
function goPage(n) {
st.page = n;
if (full) setParam('p', n);
load();
}
function load() {
var c = ctx(), key = ctxKey(c);
if (key !== st.ctxKey) { st.ctxKey = key; st.page = 1; }
if (key !== st.ctxKey) { st.ctxKey = key; if (!full) st.page = 1; }
if (full) st.page = pageParam();
buildHead();
var params = qs({ sort: st.sort, order: st.order, page: st.page, per: st.per, q: st.q, level: st.level, banned: st.banned ? '1' : '0' });
var params = qs({ sort: st.sort, order: st.order, page: st.page, per_page: st.per, q: st.q, level: st.level, banned: st.banned ? '1' : '0' });
return api('/api/v1/ips', params).then(function (r) {
if (!alive) return;
st.total = r.total;
if (st.page > 1 && !r.items.length && r.total) { goPage(Math.max(1, r.pages || 1)); return; } // the list shrank under the page
if (onTotal) onTotal(r.total);
var sig = JSON.stringify([lang, st.multi, st.page, st.per, r.items.map(function (x) { return [x.ip, x.score, x.last, x.banned, x.level]; })]);
if (sig === st.sig) return;
@@ -776,18 +822,18 @@
renderRows(r.items);
}).catch(function () { /* banner already shown by api() */ });
}
function reset() { st.page = 1; return load(); }
function reset() { st.page = 1; if (full) setParam('p', 1); return load(); }
function onHash() { if (full && alive && pageParam() !== st.page) load(); }
window.addEventListener('hashchange', onHash); // back/forward between pages (route() runs first)
search.addEventListener('input', function () { clearTimeout(timer); timer = setTimeout(function () { st.q = search.value.trim(); reset(); }, 300); });
levelSel.addEventListener('change', function () { st.level = levelSel.value; reset(); });
bannedChk.addEventListener('change', function () { st.banned = bannedChk.checked; reset(); });
if (perSel) perSel.addEventListener('change', function () { st.per = parseInt(perSel.value, 10) || 50; reset(); });
prev.addEventListener('click', function () { if (st.page > 1) { st.page--; load(); } });
next.addEventListener('click', function () { st.page++; load(); });
return {
node: node, load: load, reset: reset,
setMulti: function (b) { if (st.multi !== b) { st.multi = b; st.sig = ''; } },
onTotal: function (cb) { onTotal = cb; },
dispose: function () { alive = false; clearTimeout(timer); }
dispose: function () { alive = false; clearTimeout(timer); window.removeEventListener('hashchange', onHash); }
};
}
@@ -1689,7 +1735,8 @@
function setShell(over) {
var sl = { range: state.range, from: state.from, to: state.to, host: state.host };
Object.keys(over).forEach(function (k) { sl[k] = over[k]; });
var id = current ? current.id : 'overview', hash = buildHash(id, state.params.segments, state.params.query, sl);
var q = Object.assign({}, state.params.query); delete q.p; // a new period or host starts at page 1
var id = current ? current.id : 'overview', hash = buildHash(id, state.params.segments, q, sl);
if (hash !== location.hash) history.pushState(null, '', hash);
route();
}
@@ -1850,6 +1897,23 @@
if (b) b.setAttribute('aria-expanded', open ? 'true' : 'false');
}
function mkParams(segments, extra) {
return { segments: segments, path: segments, query: extra, get: function (n) { return Object.prototype.hasOwnProperty.call(extra, n) ? extra[n] : null; } };
}
// one query parameter of the current page (e.g. p, the page number); null when absent
function param(name) { return state.params.get(name); }
// set or drop one query parameter in the hash without re-routing: the caller reloads its own data.
// p=1 is the default and never written, so the first page keeps a clean link.
function setParam(name, val) {
var q = Object.assign({}, state.params.query);
if (val === '' || val === null || val === undefined || (name === 'p' && String(val) === '1')) delete q[name]; else q[name] = String(val);
state.params = mkParams(state.params.segments, q);
var hash = buildHash(current ? current.id : 'overview', state.params.segments, q);
if (hash !== location.hash) history.pushState(null, '', hash);
if (current) current.sig = pageSig();
}
// page number of the URL (>= 1)
function pageParam() { var n = parseInt(param('p'), 10); return n >= 1 ? Math.min(n, 100000) : 1; }
function pageSig() { var c = ctx(); return ctxKey(c) + '|' + JSON.stringify(state.params.segments) + '|' + JSON.stringify(state.params.query); }
function route() {
var u = parseHash(), id = u.page;
@@ -1861,7 +1925,7 @@
readSlice(u.query);
var extra = {};
u.query.forEach(function (v, k) { if (['r', 'range', 'from', 'to', 'host'].indexOf(k) < 0) extra[k] = v; });
state.params = { segments: u.segments, path: u.segments, query: extra, get: function (n) { return Object.prototype.hasOwnProperty.call(extra, n) ? extra[n] : null; } };
state.params = mkParams(u.segments, extra);
var norm = buildHash(id, u.segments, extra);
if (norm !== location.hash) history.replaceState(null, '', norm);
setMore(false); closeRangePicker(false);
@@ -1996,7 +2060,8 @@
fmt: { num: nf, pct: pct, ago: ago, bytes: fmtBytes, flag: flag, country: countryName, clock: clock, date: dateTime },
world: world, el: el, css: cssVar, setSliceNote: setSliceNote,
charts: charts, help: help, glossary: glossary,
ui: { panel: panel, stat: stat, metric: metric, lead: lead, empty: empty, badge: badge, bars: bars, chart: chart, sparkline: sparkline }
param: param, setParam: setParam, pageParam: pageParam,
ui: { panel: panel, stat: stat, metric: metric, lead: lead, empty: empty, badge: badge, bars: bars, chart: chart, sparkline: sparkline, pager: pager }
};
// page scripts are listed in /pages.json ({"pages":[{"name":"geo","css":true}, ...]}); only files that exist
+12 -4
View File
@@ -4,6 +4,7 @@
(function () {
'use strict';
var NS = 'http://www.w3.org/2000/svg';
var PER = 12;
var STAGES = ['recon', 'probe', 'exploit', 'access', 'banned'];
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="12" cy="5" r="2.5"/><circle cx="5" cy="18" r="2.5"/><circle cx="19" cy="18" r="2.5"/><path d="M11 7.5L6 15.5M13 7.5l5 8M7.5 18h9"/></svg>';
var ID_OK = /^[A-Za-z0-9_-]{1,64}$/;
@@ -56,6 +57,8 @@
'cp.stage.exploit': 'Exploit',
'cp.stage.access': 'Access',
'cp.stage.banned': 'Banned',
'cp.n.one': '{n} campaign',
'cp.n.other': '{n} campaigns',
'cp.more': '+{n} more'
},
'pt-BR': {
@@ -100,6 +103,8 @@
'cp.stage.exploit': 'Exploração',
'cp.stage.access': 'Acesso',
'cp.stage.banned': 'Banido',
'cp.n.one': '{n} campanha',
'cp.n.other': '{n} campanhas',
'cp.more': '+{n} mais'
}
});
@@ -169,8 +174,10 @@
function load() {
var my = ++seq, cid = id(), path = cid ? '/api/v1/campaigns/' + encodeURIComponent(cid) : '/api/v1/campaigns';
if (cid && !ID_OK.test(cid)) { data = { missing: true }; paint(); return; }
U.api(path, Object.assign({ host: self.ctx.host }, U.rangeParams())).then(function (d) {
if (!alive || my !== seq) return; data = d; key = cid; paint();
U.api(path, Object.assign({ host: self.ctx.host }, cid ? {} : { page: U.pageParam(), per_page: PER }, U.rangeParams())).then(function (d) {
if (!alive || my !== seq) return;
if (!cid && d.page > 1 && !(d.campaigns || []).length && d.total) { U.setParam('p', d.pages); load(); return; }
data = d; key = cid; paint();
}).catch(function (e) {
if (!alive || my !== seq) return;
if (e && e.status === 404 && cid) { data = { missing: true }; key = cid; paint(); return; }
@@ -191,7 +198,7 @@
if (data.truncated) wrap.appendChild(h('p', { class: 'note', text: t('cp.truncated') }));
if (!cs.length) return;
var grid = h('div', 'cp-cards');
cs.slice(0, 60).forEach(function (c) {
cs.forEach(function (c) {
var sg = c.signature || {};
grid.appendChild(h('article', 'cp-card',
h('header', null, h('a', { class: 'cp-id mono', href: '#/campaigns/' + encodeURIComponent(c.id), text: short(c.id) }),
@@ -204,7 +211,8 @@
h('footer', null, h('a', { class: 'btn', href: '#/campaigns/' + encodeURIComponent(c.id), text: t('cp.open') }),
h('a', { class: 'btn', href: replayHref(c), text: t('cp.replay') }))));
});
wrap.appendChild(U.ui.panel({ title: t('cp.cards'), help: 'term.campaign' }, grid));
wrap.appendChild(U.ui.panel({ title: t('cp.cards'), help: 'term.campaign' }, grid,
U.ui.pager({ page: data.page, pages: data.pages, total: data.total, totalText: U.pl('cp.n', data.total, { n: nf(data.total) }), onPage: function (n) { U.setParam('p', n); load(); } })));
var top = cs.slice(0, 15), mn = Infinity, mx = 0;
top.forEach(function (c) { mn = Math.min(mn, sec(c.first)); mx = Math.max(mx, sec(c.last)); });
wrap.appendChild(U.ui.panel({ title: t('cp.gantt'), hint: t('cp.gantt.hint') },
+2
View File
@@ -113,6 +113,7 @@
'df.en.reason.webshell': 'Looking for or uploading a backdoor (webshell)',
'df.en.reason.sqli': 'Attempt to tamper with the database (SQL injection)',
'df.en.reason.log4shell': 'Log4Shell exploit attempt',
'df.en.reason.port-scan': 'Scanning many network ports on the server',
'df.en.error': 'Could not load the second firewall data.'
},
'pt-BR': {
@@ -217,6 +218,7 @@
'df.en.reason.webshell': 'Procura ou envio de porta dos fundos (webshell)',
'df.en.reason.sqli': 'Tentativa de adulterar o banco de dados (injeção de SQL)',
'df.en.reason.log4shell': 'Tentativa de explorar o Log4Shell',
'df.en.reason.port-scan': 'Varredura de muitas portas de rede do servidor',
'df.en.error': 'Não foi possível carregar os dados do segundo firewall.'
}
});
+14 -4
View File
@@ -187,8 +187,13 @@ window.URUTAU_I18N = {
'col.lines': 'Lines',
'col.malformed': 'Malformed',
'col.lastEvent': 'Last event',
'pager.prev': 'Previous',
'pager.next': 'Next',
'pager.nav': 'Pagination',
'pager.first': 'First page',
'pager.last': 'Last page',
'pager.goto': 'Go to page {n}',
'pager.pageN': 'Page {n}',
'pager.prev': 'Previous page',
'pager.next': 'Next page',
'pager.count.one': '{n} IP',
'pager.count.other': '{n} IPs',
'pager.page': 'Page {n} of {m}',
@@ -681,8 +686,13 @@ window.URUTAU_I18N = {
'col.lines': 'Linhas',
'col.malformed': 'Malformadas',
'col.lastEvent': 'Último evento',
'pager.prev': 'Anterior',
'pager.next': 'Próxima',
'pager.nav': 'Paginação',
'pager.first': 'Primeira página',
'pager.last': 'Última página',
'pager.goto': 'Ir para a página {n}',
'pager.pageN': 'Página {n}',
'pager.prev': 'Página anterior',
'pager.next': 'Próxima página',
'pager.count.one': '{n} IP',
'pager.count.other': '{n} IPs',
'pager.page': 'Página {n} de {m}',
+14 -17
View File
@@ -225,6 +225,7 @@
'ip.fam.iot-cgi': 'IoT and CGI',
'ip.fam.admin-panel': 'Admin panels',
'ip.fam.generic-404': 'Generic probing',
'ip.fam.port-scan': 'Network port scan',
'ip.ses.title': 'Sessions',
'ip.ses.hint': 'Bursts of activity separated by quiet gaps.',
'ip.ses.empty': 'No session found in this period.',
@@ -256,7 +257,6 @@
'ip.ev.request': 'Request',
'ip.ev.status': 'Status',
'ip.ev.bytes': 'Bytes',
'ip.ev.more': 'Load more',
'ip.ev.loading': 'Loading events.',
'ip.ev.empty': 'No raw events returned for this period.',
'ip.ev.unavailable': 'Raw events are not available right now.',
@@ -525,6 +525,7 @@
'ip.fam.iot-cgi': 'IoT e CGI',
'ip.fam.admin-panel': 'Painéis de administração',
'ip.fam.generic-404': 'Sondagem genérica',
'ip.fam.port-scan': 'Varredura de portas de rede',
'ip.ses.title': 'Sessões',
'ip.ses.hint': 'Rajadas de atividade separadas por intervalos quietos.',
'ip.ses.empty': 'Nenhuma sessão encontrada neste período.',
@@ -556,7 +557,6 @@
'ip.ev.request': 'Requisição',
'ip.ev.status': 'Status',
'ip.ev.bytes': 'Bytes',
'ip.ev.more': 'Carregar mais',
'ip.ev.loading': 'Carregando eventos.',
'ip.ev.empty': 'Nenhum evento bruto retornado para este período.',
'ip.ev.unavailable': 'Os eventos brutos não estão disponíveis agora.',
@@ -721,7 +721,7 @@
var LEVELS = ['hostile', 'suspicious', 'low'];
var LEVEL_TONE = { hostile: 'danger', suspicious: 'warn', low: 'info' };
var STAGES = ['recon', 'probe', 'exploit', 'access', 'banned'];
var FAMS = ['traversal', 'log4shell', 'sqli', 'xss', 'rce-injection', 'webshell', 'env-credentials', 'vcs', 'backup', 'wordpress', 'phpmyadmin-db', 'actuator-debug', 'iot-cgi', 'admin-panel', 'generic-404'];
var FAMS = ['traversal', 'log4shell', 'sqli', 'xss', 'rce-injection', 'webshell', 'env-credentials', 'vcs', 'backup', 'wordpress', 'phpmyadmin-db', 'actuator-debug', 'iot-cgi', 'admin-panel', 'generic-404', 'port-scan'];
var SENSITIVE = ['traversal', 'webshell', 'env-credentials', 'vcs', 'backup', 'phpmyadmin-db', 'actuator-debug'];
var NETTYPES = ['tor', 'vpn', 'research-scanner', 'isp-cn', 'hosting', 'mobile', 'isp/mobile', 'residential', 'unknown'];
var NT_TONE = { tor: 'danger', vpn: 'warn', 'research-scanner': 'info', 'isp-cn': 'warn', hosting: 'warn', mobile: 'info', 'isp/mobile': 'info', residential: 'info', unknown: 'neutral' };
@@ -1466,29 +1466,25 @@
h('th', null, t('ip.ev.status')), h('th', null, t('ip.ev.bytes')))), tb);
box.appendChild(h('div', 'ipx-tbl-w', table));
var foot = h('div', 'ipx-ev-f', h('span', 'ipx-faint ipx-num', t('ip.ev.shown', { n: N(ev.rows.length) })));
if (ev.cursor) {
var more = h('button', 'ipx-btn sm', { type: 'button' }, t(ev.loading ? 'ip.ev.loading' : 'ip.ev.more'));
if (ev.loading) more.disabled = true;
more.addEventListener('click', function () { loadEvents(s, true); });
foot.appendChild(more);
}
box.appendChild(foot);
var pg = U.ui.pager({ page: ev.page, pages: ev.pages, total: ev.total, onPage: function (n) { U.setParam('p', n); ev.page = n; loadEvents(s); } });
if (pg) box.appendChild(pg);
}
function loadEvents(s, more) {
function loadEvents(s) {
var ev = s.ev;
if (ev.loading) return;
ev.loading = true; ev.failed = false;
var my = ++ev.seq;
var p = rParams(s.ctx);
var q = { ip: s.ip, limit: 25, order: 'desc' };
var q = { ip: s.ip, per_page: 25, page: ev.page || 1, order: 'desc' };
Object.keys(p).forEach(function (k) { q[k] = p[k]; });
if (more && ev.cursor) q.cursor = ev.cursor;
paintEvents(s);
U.api('/api/v1/events', q).then(function (r) {
if (!s.alive || my !== ev.seq) return;
var rows = Array.isArray(r) ? r : arr(r && (r.events || r.items || r.rows)), cur = isObj(r) ? (r.next || r.next_cursor || r.cursor || '') : '';
ev.rows = more ? ev.rows.concat(rows.filter(isObj)) : rows.filter(isObj);
ev.cursor = rows.length ? str(cur) : '';
var rows = Array.isArray(r) ? r : arr(r && (r.events || r.items || r.rows));
if (isObj(r) && r.page > 1 && !rows.length && r.total) { ev.loading = false; ev.page = r.pages || 1; U.setParam('p', ev.page); loadEvents(s); return; } // stale link past the last page
ev.rows = rows.filter(isObj);
ev.total = isObj(r) ? num(r.total) : 0; ev.pages = isObj(r) && r.pages ? num(r.pages) : 1;
if (isObj(r) && r.enabled === false) ev.disabled = true;
if (s.statusPaint) s.statusPaint();
ev.loaded = true; ev.loading = false;
@@ -1845,7 +1841,7 @@
var my = ++s.seq;
s.ip = ipFromCtx(s.ctx);
s.key = ctxKey(s.ctx);
s.ev = { rows: [], cursor: '', loading: false, failed: false, loaded: false, disabled: !!(isObj(s.data && s.data.log) && s.data.log.available === false), seq: s.ev.seq + 1 };
s.ev = { rows: [], page: U.pageParam(), pages: 1, total: 0, loading: false, failed: false, loaded: false, disabled: !!(isObj(s.data && s.data.log) && s.data.log.available === false), seq: s.ev.seq + 1 };
if (!validIP(s.ip)) { showState(s, errorNode(s, 'ip.invalid', false)); return; }
document.title = s.ip + ' · ' + t('ip.title') + ' · Urutau';
if (!s.data) showState(s, loadingNode());
@@ -1855,7 +1851,7 @@
s.data = d;
s.ev.disabled = !!(isObj(d.log) && d.log.available === false);
render(s);
if (!s.ev.disabled) loadEvents(s, false);
if (!s.ev.disabled) loadEvents(s);
}).catch(function (e) {
if (!s.alive || my !== s.seq) return;
if (e && e.message === 'unauthorized') return;
@@ -1881,6 +1877,7 @@
S.ctx = ctx; S.lang = ctx.lang;
if (ctxKey(ctx) !== S.key) { S.data = S.data && ipFromCtx(ctx) === S.ip ? S.data : null; load(S); return; }
if (ctx.lang !== prevLang && S.data) { render(S); paintEvents(S); }
else if (S.data && !S.ev.disabled && S.ev.page !== U.pageParam()) { S.ev.page = U.pageParam(); loadEvents(S); } // back/forward
},
unmount: function () {
if (!S) return;
+19 -17
View File
@@ -5,7 +5,7 @@
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;
var PAGE = 100;
function boot() {
var U = window.Urutau;
@@ -17,7 +17,7 @@
'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.more': 'More events match; use Next page 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.',
@@ -35,7 +35,6 @@
'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',
@@ -46,7 +45,6 @@
'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.',
@@ -56,7 +54,7 @@
'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.more': 'Há mais eventos; use Próxima página 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.',
@@ -74,7 +72,6 @@
'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',
@@ -85,7 +82,6 @@
'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.',
@@ -103,7 +99,7 @@
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;
var self = this, alive = true, seq = 0, rows = [], next = '', total = 0, loaded = false, busy = false, err = '', stack = [''];
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: '' };
@@ -141,20 +137,27 @@
if (cursor) p.cursor = cursor;
return p;
}
function run() { rows = []; next = ''; total = 0; loaded = false; err = ''; capped = false; fetchPage(''); }
function fetchPage(cursor) {
// stack[i] is the cursor that opens page i+1; going back is popping, going forward pushes the `next` of the page shown
function run() { rows = []; next = ''; total = 0; loaded = false; err = ''; stack = ['']; fetchPage(0); }
function fetchPage(idx) {
var my = ++seq; busy = true; paint();
U.api('/api/v1/events', params(cursor)).then(function (d) {
U.api('/api/v1/events', params(stack[idx])).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 = ''; }
rows = d.events || []; total = d.total_estimate || rows.length; next = (d.events || []).length ? d.next || '' : '';
stack.length = idx + 1; cur = idx;
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();
});
}
var cur = 0;
function goto(n) { // n is the 0-based index of the page asked for
if (n === cur + 1 && next) stack[n] = next;
if (n < 0 || !stack[n] && n > 0) return;
fetchPage(n);
}
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'];
@@ -175,7 +178,7 @@
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; }
if (!vis.length) { var pe = pagerNode(); if (pe) out.appendChild(pe); return; }
var tb = h('tbody');
vis.forEach(function (r) {
function td(l, k, c) { return h('td', { 'data-label': l, class: c || null }, k); }
@@ -192,10 +195,9 @@
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());
var pn = pagerNode(); if (pn) out.appendChild(pn);
}
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; }
function pagerNode() { return U.ui.pager({ page: cur + 1, hasNext: !!next, onPage: function (n) { goto(n - 1); } }); }
buildForm();
this.update = function (c) {
var lang = self.ctx.lang; self.ctx = c;
+20 -22
View File
@@ -4,7 +4,7 @@
'use strict';
var STAGES = ['recon', 'probe', 'exploit', 'access', 'banned'];
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"><path d="M3 5h18l-7 8v6l-4 2v-8z"/></svg>';
var SHOW = 100;
var SHOW = 25;
function boot() {
var U = window.Urutau;
@@ -41,7 +41,8 @@
'ss.c.fam': 'Family',
'ss.c.replay': 'Replay',
'ss.replay': 'Replay',
'ss.more': 'Show more',
'ss.n.one': '{n} session',
'ss.n.other': '{n} sessions',
'ss.none': 'No session matches these filters',
'ss.esc': 'Escalation chains',
'ss.esc.hint': 'The steps of the most serious sessions.',
@@ -80,7 +81,8 @@
'ss.c.fam': 'Família',
'ss.c.replay': 'Reprodução',
'ss.replay': 'Reproduzir',
'ss.more': 'Mostrar mais',
'ss.n.one': '{n} sessão',
'ss.n.other': '{n} sessões',
'ss.none': 'Nenhuma sessão combina com estes filtros',
'ss.esc': 'Cadeias de escalada',
'ss.esc.hint': 'Os passos das sessões mais graves.',
@@ -100,14 +102,16 @@
var inst = null;
function Page(root, ctx) {
var self = this, data = null, seq = 0, alive = true, st = { stage: '', host: '', fam: '', shown: SHOW };
var self = this, data = null, seq = 0, alive = true, st = { stage: '', host: '', fam: '' };
this.ctx = ctx;
var wrap = h('div', 'ss');
root.appendChild(wrap);
function load() {
var my = ++seq;
U.api('/api/v1/sessions/funnel', Object.assign({ host: self.ctx.host }, U.rangeParams())).then(function (d) {
if (!alive || my !== seq) return; data = d; paint();
U.api('/api/v1/sessions/funnel', Object.assign({ host: self.ctx.host, page: U.pageParam(), per_page: SHOW, stage: st.stage, host_f: st.host, fam: st.fam }, U.rangeParams())).then(function (d) {
if (!alive || my !== seq) return;
if (d.page > 1 && !(d.sessions || []).length && d.total) { U.setParam('p', d.pages); load(); return; } // stale link past the last page
data = d; paint();
}).catch(function () {
if (!alive || my !== seq || data) return;
var b = h('button', { type: 'button', class: 'btn', text: t('ss.retry') });
@@ -116,6 +120,7 @@
wrap.appendChild(h('div', 'state-error', h('strong', { text: t('ss.err') }), b));
});
}
function refilter() { U.setParam('p', 1); load(); }
function paint() {
wrap.textContent = '';
var d = data, n = d.sessions_n || 0, k = d.exploited || 0, range = U.rangeLabel({ inline: true });
@@ -132,36 +137,32 @@
bar.appendChild(i);
b.appendChild(bar);
b.appendChild(h('span', { class: 'ss-fn num', text: nf(v) }));
b.addEventListener('click', function () { st.stage = st.stage === g ? '' : g; st.shown = SHOW; paint(); });
b.addEventListener('click', function () { st.stage = st.stage === g ? '' : g; refilter(); });
fb.appendChild(b);
});
wrap.appendChild(U.ui.panel({ title: t('ss.funnel'), help: 'term.session', hint: t('ss.funnel.hint') }, fb));
// filters
var hosts = {}, fams = {};
d.sessions.forEach(function (s) { (s.hosts || []).forEach(function (x) { hosts[x] = 1; }); Object.keys(s.fams || {}).forEach(function (x) { fams[x] = 1; }); });
var f = h('div', 'ss-filters');
function sel(label, key, values, labeler) {
var s = h('select', { 'aria-label': label });
opt(s, '', label + ': ' + t('ss.f.all'));
values.forEach(function (v) { opt(s, v, labeler ? labeler(v) : v); });
s.value = values.indexOf(st[key]) >= 0 ? st[key] : '';
s.addEventListener('change', function () { st[key] = s.value; st.shown = SHOW; paint(); });
s.addEventListener('change', function () { st[key] = s.value; refilter(); });
f.appendChild(s);
}
sel(t('ss.f.stage'), 'stage', STAGES, function (g) { return t('ss.stage.' + g); });
sel(t('ss.f.host'), 'host', Object.keys(hosts).sort());
sel(t('ss.f.fam'), 'fam', Object.keys(fams).sort());
sel(t('ss.f.host'), 'host', d.hosts || []);
sel(t('ss.f.fam'), 'fam', d.fams || []);
// list
var rows = d.sessions.filter(function (s) {
return (!st.stage || stg(s.stage) === st.stage) && (!st.host || (s.hosts || []).indexOf(st.host) >= 0) && (!st.fam || (s.fams || {})[st.fam]);
});
var rows = d.sessions || [];
var body = h('div');
if (d.sampled) body.appendChild(h('p', { class: 'note', text: t('ss.sampled', { n: nf(d.sessions.length), m: nf(n) }) }));
if (d.sampled && !st.stage && !st.host && !st.fam) body.appendChild(h('p', { class: 'note', text: t('ss.sampled', { n: nf(d.total), m: nf(n) }) }));
body.appendChild(f);
if (!rows.length) body.appendChild(U.ui.empty(t('ss.none')));
else {
var tb = h('tbody');
rows.slice(0, st.shown).forEach(function (s) {
rows.forEach(function (s) {
var a = Math.floor(Date.parse(s.start) / 1000), b = Math.floor(Date.parse(s.end) / 1000);
var rp = h('a', { class: 'btn ss-rp', href: '#/replay?ip=' + encodeURIComponent(s.ip) + '&from=' + encodeURIComponent(iso(a - 60)) + '&to=' + encodeURIComponent(iso(b + 60)), text: t('ss.replay') });
function td(label, kid, cls) { return h('td', { 'data-label': label, class: cls || null }, kid); }
@@ -178,11 +179,8 @@
var th = h('tr');
['ip', 'stage', 'start', 'dur', 'events', 'hosts', 'fam', 'replay'].forEach(function (c) { th.appendChild(h('th', { text: t('ss.c.' + c) })); });
body.appendChild(h('table', 'stack ss-table', h('thead', null, th), tb));
if (rows.length > st.shown) {
var more = h('button', { type: 'button', class: 'btn', text: t('ss.more') });
more.addEventListener('click', function () { st.shown += SHOW; paint(); });
body.appendChild(more);
}
var pg = U.ui.pager({ page: d.page, pages: d.pages, total: d.total, totalText: U.pl('ss.n', d.total, { n: nf(d.total) }), onPage: function (n) { U.setParam('p', n); load(); } });
if (pg) body.appendChild(pg);
}
wrap.appendChild(U.ui.panel({ title: t('ss.list') }, body));
// escalation chains
+11
View File
@@ -325,6 +325,17 @@ td small { display: block; color: var(--ink-muted); font-size: .8125rem; overflo
.toolbar input[type="number"] { width: 90px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: var(--s-2); margin-top: var(--s-3); color: var(--ink-muted); font-size: .875rem; flex-wrap: wrap; }
.pager .btns { display: flex; gap: var(--s-2); align-items: center; }
.pgr { display: flex; justify-content: space-between; align-items: center; gap: var(--s-2) var(--s-3); margin-top: var(--s-3); flex-wrap: wrap; color: var(--ink-muted); font-size: .875rem; }
.pgr-l { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pgr-b { min-width: 36px; padding: 2px 8px; justify-content: center; }
.pgr-n.on { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: 600; }
.pgr-gap { min-width: 20px; text-align: center; }
.pgr-b:disabled { opacity: .45; cursor: default; }
@media (max-width: 560px) {
.pgr { justify-content: center; }
.pgr-n:not(.on), .pgr-gap { display: none; }
.pgr-b { min-width: 44px; min-height: 44px; }
}
/* feed */
.feed { list-style: none; padding: 0; max-height: 420px; overflow-y: auto; }