feat: 1.3.0 thirteen new pages, charts, tooltips and error analysis
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>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-14 22:39:33 -03:00
1 parent b7462c14fa
commit 2ebda1e4d7
79 files changed
+9091 -171

No files matched your search

+400 -60
View File
@@ -28,6 +28,19 @@
* pt-BR "nas últimas 6 horas" / "na última hora" / "nos últimos 7 dias" / "entre 12 nov 10:00 e 14 nov 18:00"
* Urutau.href(pageId, segments?, query?) -> hash that keeps the current slice
* Urutau.toast(msg) short confirmation toast
* Urutau.help(node, key) appends an accessible "?" button to node (keyboard focus, aria-describedby,
* popover with a short text and "what to do"). Urutau.glossary = { has(key), get(key) -> {text, action} }.
* Keys (central dictionary, en + pt-BR, each with a ".do" companion): help.cat.<category>,
* help.metric.<name> (requests, malicious, unique_ips, attacks_per_hour_24h, moving_avg_7d_per_hour, trend,
* active_attackers_24h/_1h, new_attackers, returning_rate, sessions_per_day, exposure_rate, exploits_refused_pct,
* ban_coverage, blocklist_coverage, blocklist_leak, mttb, visitors, pages, bytes, latency, bots) and
* help.term.<term> (session, stage.recon|probe|exploit|access|banned, campaign, family, mitre, net_type, cadence,
* score, level, fcrdns, exposure, blocklist, peer, hub, client_type, status_class, attack_profile).
* Pass the key WITHOUT the "help." prefix: Urutau.help(el, 'metric.mttb'). Metric cards accept {help:'metric.x'},
* panels accept {help:'term.x'}. Category names: t('cat.<c>') is the long name, t('cat.short.<c>') the short one.
* Groups: registerPage({..., group:'monitor|investigate|analyze|operate|reports'}); known ids are placed by the built-in
* order, unknown ids go to the end of their group (default group: analyze).
* Page scripts load from /pages.json ({"pages":[{"name":"geo","css":true}]}): add your name there when you create <name>.js.
* Urutau.registerI18n({ en: {...}, 'pt-BR': {...} }) merge keys (existing keys win)
* Urutau.t(key, vars?) vars: a number (fills {n}) or an object ({name: ...})
* Urutau.api(path, params) -> Promise<json> GET with query params; 401 goes to
@@ -45,6 +58,16 @@
* function handlers, any other attribute as a string. SVG tags work.
* Urutau.css(name) reads a design token, e.g. css('accent') or css('--cat-exploit')
* Urutau.setSliceNote(text) optional extra words appended to the slice sentence
* Urutau.charts: own SVG chart library (no dependencies, CSP-safe, theme tokens, ResizeObserver,
* every chart also renders a visually hidden <table> for screen readers, and an empty
* state when there is nothing to draw). Every function returns a DOM node; append it.
* donut(data[{key,label,value}], {title, colors:['--viz-3',...], centerLabel, format})
* radar(axes[{key,label}], series[{label,values[]}], {max, format, colors, title})
* stackedArea(series[{key,label,values[]}], stepSeconds, {start (unix), colors, title})
* bars(rows[{key,label,value,color?:'--token',parts?:[{label,value,color?}]}], {horizontal=true, stacked, format, colors, title})
* 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
* (the same ones the core pages use; see their definitions below)
*
@@ -357,6 +380,7 @@
var acts = opts.actions ? [].concat(opts.actions) : null;
var head = h('div', 'panel-h', h('h2', null, opts.title), acts ? h('div', 'acts', acts) : null);
var body = h('div', 'panel-b', kids);
if (opts.help) help(head.firstChild, opts.help);
var variant = pick(['list', 'chart', 'map'], opts.variant, '');
var foot = opts.footer ? h('div', 'panel-f', opts.footer) : null;
var node = h('section', 'panel' + (variant ? ' card-' + variant : '') + (opts.cls ? ' ' + opts.cls : ''), head, opts.hint ? h('p', 'hint', opts.hint) : null, body, foot);
@@ -384,11 +408,13 @@
var arrow = o.delta === 0 ? '\u25A0' : up ? '\u25B2' : '\u25BC';
dl = h('p', 'cm-delta' + (big && o.delta !== 0 ? (good ? ' good' : ' bad') : ''), arrow + ' ' + nfFor({ maximumFractionDigits: 0 }, 'd0').format(Math.abs(o.delta)) + '%');
}
var n = h('div', 'card-metric' + (tn === 'neutral' ? '' : ' tone-' + tn), h('p', 'cm-label', label), h('p', 'cm-value num', value), dl, o.sub ? h('p', 'cm-sub', o.sub) : null, sparkline(o.spark));
var lab = h('p', 'cm-label', label);
if (o.help) help(lab, o.help);
var n = h('div', 'card-metric' + (tn === 'neutral' ? '' : ' tone-' + tn), lab, h('p', 'cm-value num', value), dl, o.sub ? h('p', 'cm-sub', o.sub) : null, sparkline(o.spark));
if (o.hint) n.title = o.hint;
return n;
}
function stat(label, value, sub, tone, hint) { return metric(label, value, { sub: sub, tone: tone, hint: hint }); }
function stat(label, value, sub, tone, hint, helpKey) { return metric(label, value, { sub: sub, tone: tone, hint: hint, help: helpKey }); }
function lead(title, body, tone) {
var tn = pick(['ok', 'danger', 'neutral'], tone, 'ok');
return h('section', 'lead tone-' + tn, h('div', null, h('h2', null, title), body ? h('p', null, body) : null), h('span', 'pulse', ''));
@@ -402,7 +428,47 @@
function showSkeleton(box, n, cls) { clear(box); for (var i = 0; i < n; i++) box.appendChild(h('div', cls || 'skeleton')); }
function badge(text, tone) { var tn = pick(KNOWN_TONES, tone, 'neutral'); return h('span', 'badge' + (tn === 'neutral' ? '' : ' tone-' + tn), text); }
function levelBadge(l) { l = pick(KNOWN_LEVELS, l, 'low'); return badge(t('level.' + l), LEVEL_TONE[l]); }
function catPill(c, label) { var k = pick(KNOWN_CATS, c, 'ok'); return h('span', 'cat c-' + k, label || t('cat.' + k)); }
function catShort(c) { var k = pick(KNOWN_CATS, c, 'ok'); return t('cat.short.' + k); }
function catPill(c, label) { var k = pick(KNOWN_CATS, c, 'ok'), n = h('span', 'cat c-' + k, label || catShort(k)); n.title = t('cat.' + k); return n; }
// ---------------------------------------------------------------- help and glossary
// help.cat.<cat>, help.metric.<name>, help.term.<term> (+ ".do" = what to do) live in the central dictionary
var glossary = {
has: function (key) { var k = 'help.' + key; return t(k) !== k; },
get: function (key) { var k = 'help.' + key, tx = t(k); if (tx === k) return null; var dk = k + '.do', d = t(dk); return { text: tx, action: d === dk ? '' : d }; }
};
var helpPop = null, helpBtn = null, helpPinned = false;
function ensureHelpPop() {
if (!helpPop) { helpPop = h('div', 'help-pop'); helpPop.id = 'help-pop'; helpPop.setAttribute('role', 'tooltip'); helpPop.hidden = true; document.body.appendChild(helpPop); }
return helpPop;
}
function hideHelp() { if (helpPop) helpPop.hidden = true; helpBtn = null; helpPinned = false; }
function showHelp(btn, key) {
var g = glossary.get(key), pop = ensureHelpPop();
if (!g) return;
clear(pop);
pop.appendChild(h('p', 'help-t', g.text));
if (g.action) pop.appendChild(h('p', 'help-do', h('strong', null, t('help.do') + ': '), g.action));
pop.hidden = false; helpBtn = btn;
var r = btn.getBoundingClientRect(), w = pop.offsetWidth, ph = pop.offsetHeight;
var left = Math.max(8, Math.min(r.left, window.innerWidth - w - 8)), top = r.bottom + 6;
if (top + ph > window.innerHeight - 8) top = Math.max(8, r.top - ph - 6);
pop.style.left = left + 'px'; pop.style.top = top + 'px';
}
// append an accessible "?" to a node: focusable, aria-describedby, popover with short text + what to do
function help(node, key) {
if (!node || !glossary.has(key)) return null;
var b = el('button', { type: 'button', class: 'help-btn', 'aria-label': t('help.label'), 'aria-describedby': 'help-pop' }, '?');
ensureHelpPop();
b.addEventListener('mouseenter', function () { if (!helpPinned) showHelp(b, key); });
b.addEventListener('focus', function () { if (!helpPinned) showHelp(b, key); });
b.addEventListener('mouseleave', function () { if (!helpPinned) hideHelp(); });
b.addEventListener('blur', function () { if (!helpPinned) hideHelp(); });
b.addEventListener('click', function (e) { e.stopPropagation(); if (helpBtn === b && helpPinned) hideHelp(); else { showHelp(b, key); helpPinned = true; } });
node.appendChild(b);
return b;
}
// ranked list with a proportional bar; rows: [{key, n, label?}]
function bars(rows, opts) {
@@ -628,6 +694,8 @@
});
th.appendChild(b);
} else th.textContent = colLabel(x.k);
var hk = { score: 'term.score', level: 'term.level', cats: 'term.categories', origin: 'term.net_type' }[x.k];
if (hk) help(th, hk);
tr.appendChild(th);
});
thead.appendChild(tr);
@@ -665,7 +733,7 @@
var chips = h('span');
var kinds = Object.keys(x.counts || {}).filter(function (k) { return k !== 'ok' && k !== 'ssh-ok' && KNOWN_CATS.indexOf(k) >= 0; })
.sort(function (a, b) { return x.counts[b] - x.counts[a]; });
kinds.slice(0, 2).forEach(function (k) { chips.appendChild(h('span', 'chip', t('cat.' + k) + ' ' + nf(x.counts[k]))); });
kinds.slice(0, 2).forEach(function (k) { { var cp = h('span', 'chip', catShort(k) + ' ' + nf(x.counts[k])); cp.title = t('cat.' + k); chips.appendChild(cp); } });
if (kinds.length > 2) chips.appendChild(h('span', 'chip', '+' + (kinds.length - 2)));
cell('cats', chips); break;
}
@@ -822,7 +890,7 @@
bar.appendChild(fill);
[[1, 'drawer.cut.susp'], [5, 'drawer.cut.host']].forEach(function (c) { var tk = h('b', 'tick'); tk.style.left = c[0] + '%'; tk.title = t(c[1]); bar.appendChild(tk); });
var verdict = h('section', 'ip-verdict lv-' + pick(KNOWN_LEVELS, level, 'low'),
h('div', 'iv-top', levelBadge(level), h('span', 'iv-score num', nf(score)), h('span', 'iv-max', '/ 1000')), bar,
h('div', 'iv-top', (function () { var w = h('span', 'iv-lv', levelBadge(level)); help(w, 'term.level'); return w; })(), h('span', 'iv-score num', nf(score)), h('span', 'iv-max', '/ 1000'), (function () { var w = h('span', 'iv-h'); help(w, 'term.score'); return w; })()), bar,
h('p', 'note iv-cuts', t('drawer.cuts')),
origin ? h('p', 'iv-origin', origin) : null,
first && last ? h('p', 'note', t('drawer.active', { v: spanText(last - first) }) + ' \u00b7 ' + t('detail.last') + ': ' + ago(last)) : null);
@@ -836,7 +904,7 @@
var days = typeof tm.active_days === 'number' ? nf(tm.active_days) : '\u2014';
var nbans = (d.bans && d.bans.length) || (d.jails || []).length;
box.appendChild(h('div', 'drawer-metrics',
metric(t('drawer.m.events'), nf(evs)), metric(t('drawer.m.days'), days), metric(t('drawer.m.hosts'), nf((d.hosts || []).length)), metric(t('drawer.m.bans'), nf(nbans), { hint: t('drawer.m.bans') })));
metric(t('drawer.m.events'), nf(evs)), metric(t('drawer.m.days'), days), metric(t('drawer.m.hosts'), nf((d.hosts || []).length)), metric(t('drawer.m.bans'), nf(nbans), { hint: t('drawer.m.bans'), help: 'cat.ban' })));
var tstep = (d.timeline && d.timeline.step) || 3600, all = numbersOf(d.timeline), keep = Math.round(7 * 86400 / tstep), vals = all.slice(-keep);
if (vals.length > 1 && Math.max.apply(null, vals) > 0) {
var t0 = ((d.timeline && d.timeline.start) || 0) + (all.length - vals.length) * tstep;
@@ -845,10 +913,11 @@
if (Array.isArray(d.techniques) && d.techniques.length) {
var chips = h('div', 'chip-group');
d.techniques.slice(0, 8).forEach(function (x) { chips.appendChild(h('span', 'chip-mitre', (x.id ? x.id + ' ' : '') + (x.name || '') + (x.n ? ' \u00d7' + nf(x.n) : ''))); });
box.appendChild(h('section', 'drawer-sec', h('h3', null, t('drawer.techniques')), chips));
var th3 = h('h3', null, t('drawer.techniques')); help(th3, 'term.mitre');
box.appendChild(h('section', 'drawer-sec', th3, chips));
}
var kinds = Object.keys(d.counts || {}).filter(function (c) { return KNOWN_CATS.indexOf(c) >= 0 && c !== 'ok' && c !== 'ssh-ok'; });
if (kinds.length) { var cc = h('div', 'chip-group'); kinds.forEach(function (c) { cc.appendChild(h('span', 'chip', (c === 'ban' ? t('drawer.banEvents') : t('cat.' + c)) + ' ' + nf(d.counts[c]))); }); box.appendChild(h('section', 'drawer-sec', h('h3', null, t('drawer.categories')), cc)); }
if (kinds.length) { var cc = h('div', 'chip-group'); kinds.forEach(function (c) { cc.appendChild(h('span', 'chip', (c === 'ban' ? t('drawer.banEvents') : t('cat.' + c)) + ' ' + nf(d.counts[c]))); }); var ch3 = h('h3', null, t('drawer.categories')); help(ch3, 'term.categories'); box.appendChild(h('section', 'drawer-sec', ch3, cc)); }
if (Array.isArray(v.reasons) && v.reasons.length) {
var ul = h('ul'); v.reasons.slice(0, 3).forEach(function (r) { ul.appendChild(h('li', null, reasonText(r))); });
box.appendChild(h('section', 'drawer-sec', h('h3', null, t('drawer.reasons')), ul));
@@ -874,8 +943,203 @@
setTimeout(function () { if (n.parentNode) n.parentNode.removeChild(n); }, 2600);
}
// ---------------------------------------------------------------- charts library (own SVG, no dependencies)
var VIZ = ['--viz-1', '--viz-2', '--viz-3', '--viz-4', '--viz-5', '--viz-6', '--viz-7', '--viz-8'];
function vizColor(i, colors) { return 'var(' + ((colors && colors[i % colors.length]) || VIZ[i % VIZ.length]) + ')'; }
// run fn(width) now and whenever the box is resized
function watch(node, fn) {
if (!window.ResizeObserver) { fn(node.clientWidth || 320); return; }
var last = 0;
new ResizeObserver(function (es) { var w = Math.round(es[0].contentRect.width); if (w > 0 && w !== last) { last = w; fn(w); } }).observe(node);
}
// screen-reader alternative: a real table with the same numbers
function srTable(caption, head, rows) {
return h('table', 'sr-only', h('caption', null, caption || ''), h('thead', null, h('tr', null, head.map(function (x) { return el('th', { scope: 'col' }, x); }))),
h('tbody', null, rows.map(function (r) { return h('tr', null, r.map(function (c) { return h('td', null, String(c)); })); })));
}
function sumOf(a) { var s = 0; a.forEach(function (x) { s += x; }); return s; }
function legendList(items, colors, fmt, onHover) {
var ul = h('ul', 'vz-legend');
items.forEach(function (d, i) {
var li = h('li', null, h('span', 'sw'), h('span', 'vz-l', d.label), h('span', 'vz-v num', fmt(d)));
li.firstChild.style.background = vizColor(i, colors);
if (onHover) { li.addEventListener('mouseenter', function () { onHover(i); }); li.addEventListener('mouseleave', function () { onHover(-1); }); }
ul.appendChild(li);
});
return ul;
}
// donut(data [{key,label,value}], {title, colors:[token], centerLabel, format})
function donut(data, o) {
o = o || {};
data = (data || []).filter(function (x) { return x && x.value > 0; });
var total = sumOf(data.map(function (x) { return x.value; })), fmt = o.format || nf;
if (!total) return empty(t('charts.empty'));
var R = 70, C = 2 * Math.PI * R, acc = 0, segs = [];
var svg = svgEl('svg', { viewBox: '0 0 200 200', 'class': 'vz-donut', role: 'img', 'aria-label': o.title || '' });
var cv = svgEl('text', { x: 100, y: 102, 'text-anchor': 'middle', 'class': 'vz-c-v' }), cl = svgEl('text', { x: 100, y: 124, 'text-anchor': 'middle', 'class': 'vz-c-l' });
function center(i) {
if (i < 0) { cv.textContent = fmt(total); cl.textContent = o.centerLabel || t('charts.total'); return; }
cv.textContent = pct(data[i].value, total); cl.textContent = data[i].label;
}
data.forEach(function (d, i) {
var len = d.value / total * C, vis = Math.max(0.5, len - (data.length > 1 ? 1.5 : 0));
var c = svgEl('circle', { cx: 100, cy: 100, r: R, fill: 'none', 'stroke-width': 26, 'stroke-dasharray': vis + ' ' + (C - vis), 'stroke-dashoffset': -acc, transform: 'rotate(-90 100 100)', 'class': 'vz-seg', tabindex: 0, 'aria-label': d.label + ': ' + fmt(d.value) + ' (' + pct(d.value, total) + ')' });
c.style.stroke = vizColor(i, o.colors);
c.addEventListener('mouseenter', function () { center(i); }); c.addEventListener('focus', function () { center(i); });
c.addEventListener('mouseleave', function () { center(-1); }); c.addEventListener('blur', function () { center(-1); });
segs.push(c); svg.appendChild(c); acc += len;
});
svg.appendChild(cv); svg.appendChild(cl); center(-1);
var legend = legendList(data, o.colors, function (d) { return fmt(d.value) + ' · ' + pct(d.value, total); }, function (i) { center(i); segs.forEach(function (s, k) { s.classList.toggle('dim', i >= 0 && k !== i); }); });
return h('div', 'vz vz-donut-wrap', h('div', 'vz-donut-svg', svg), legend, srTable(o.title, [t('charts.item'), t('charts.value')], data.map(function (d) { return [d.label, fmt(d.value) + ' (' + pct(d.value, total) + ')']; })));
}
// radar(axes [{key,label}], series [{label, values[]}], {max, format, colors})
function radar(axes, series, o) {
o = o || {};
var n = axes.length;
series = (series || []).filter(function (s) { return s && s.values && s.values.length; });
var mx = o.max || Math.max.apply(null, [0].concat.apply([], series.map(function (s) { return s.values; })));
if (n < 3 || !series.length || !(mx > 0)) return empty(t('charts.empty'));
var fmt = o.format || nf, W = 360, H = 290, cx = 180, cy = 145, R = 82;
var svg = svgEl('svg', { viewBox: '0 0 ' + W + ' ' + H, 'class': 'vz-radar', role: 'img', 'aria-label': o.title || '' });
function pt(i, f) { var a = -Math.PI / 2 + i * 2 * Math.PI / n; return [cx + Math.cos(a) * R * f, cy + Math.sin(a) * R * f, Math.cos(a), Math.sin(a)]; }
[.25, .5, .75, 1].forEach(function (f) {
svg.appendChild(svgEl('polygon', { points: axes.map(function (_, i) { var p = pt(i, f); return p[0].toFixed(1) + ',' + p[1].toFixed(1); }).join(' '), 'class': 'vz-ring' }));
});
var rl = svgEl('text', { x: cx + 4, y: cy - R + 12, 'class': 'axis' }); rl.textContent = fmt(mx); svg.appendChild(rl);
axes.forEach(function (a, i) {
var p = pt(i, 1), q = pt(i, 1.14);
svg.appendChild(svgEl('line', { x1: cx, y1: cy, x2: p[0], y2: p[1], 'class': 'gridline' }));
var tx = svgEl('text', { x: q[0], y: q[1] + 4, 'text-anchor': q[2] > .3 ? 'start' : q[2] < -.3 ? 'end' : 'middle', 'class': 'vz-axl' });
tx.textContent = a.label; svg.appendChild(tx);
});
series.forEach(function (s, k) {
var col = vizColor(k, o.colors);
var poly = svgEl('polygon', { points: axes.map(function (_, i) { var p = pt(i, Math.min(1, (s.values[i] || 0) / mx)); return p[0].toFixed(1) + ',' + p[1].toFixed(1); }).join(' '), 'class': 'vz-rs' });
poly.style.stroke = col; poly.style.fill = col; svg.appendChild(poly);
axes.forEach(function (a, i) {
var p = pt(i, Math.min(1, (s.values[i] || 0) / mx)), c = svgEl('circle', { cx: p[0], cy: p[1], r: 3, 'class': 'vz-dot', tabindex: 0, 'aria-label': s.label + ', ' + a.label + ': ' + fmt(s.values[i] || 0) });
c.style.fill = col; var ti = svgEl('title', {}); ti.textContent = s.label + ' · ' + a.label + ': ' + fmt(s.values[i] || 0); c.appendChild(ti); svg.appendChild(c);
});
});
var legend = legendList(series.map(function (s) { return { label: s.label }; }), o.colors, function () { return ''; });
return h('div', 'vz vz-radar-wrap', svg, legend, srTable(o.title, [t('charts.item')].concat(series.map(function (s) { return s.label; })), axes.map(function (a, i) { return [a.label].concat(series.map(function (s) { return fmt(s.values[i] || 0); })); })));
}
// stackedArea(series [{key,label,values[]}], step seconds, {start, colors, title})
function stackedArea(series, step, o) {
o = o || {};
series = (series || []).filter(function (s) { return s && s.values && s.values.length; });
var n = series.length ? series[0].values.length : 0, tot = [], mx = 0, i;
if (n < 2) return empty(t('charts.empty'));
for (i = 0; i < n; i++) { var v = 0; series.forEach(function (s) { v += s.values[i] || 0; }); tot.push(v); if (v > mx) mx = v; }
var wrap = h('div', 'chart-wrap vz-area'), box = h('div', 'vz');
var colors = o.colors;
function draw(Wpx) {
clear(wrap);
var W = Math.max(280, Wpx), H = 220, L = 40, R = 6, Tp = 8, B = 22, top = niceMax(mx), ph = H - Tp - B, dx = (W - L - R) / (n - 1);
var svg = svgEl('svg', { viewBox: '0 0 ' + W + ' ' + H, role: 'img', 'aria-label': o.title || '' }), k;
for (k = 0; k <= 4; k++) {
var y = Tp + ph - ph * k / 4;
svg.appendChild(svgEl('line', { x1: L, x2: W - R, y1: y, y2: y, 'class': 'gridline' }));
var lb = svgEl('text', { x: L - 5, y: y + 3, 'text-anchor': 'end', 'class': 'axis' }); lb.textContent = top >= 10000 ? nfCompact(Math.round(top * k / 4)) : nf(Math.round(top * k / 4)); svg.appendChild(lb);
}
var nt = W < 520 ? 3 : 5, longSpan = step * n > 2 * 86400;
for (k = 0; k < nt; k++) {
var ix = Math.round((n - 1) * k / (nt - 1)), xl = svgEl('text', { x: L + dx * ix, y: H - 6, 'text-anchor': k === 0 ? 'start' : k === nt - 1 ? 'end' : 'middle', 'class': 'axis' });
xl.textContent = tickLabel((o.start || 0) + ix * step, longSpan); svg.appendChild(xl);
}
var base = []; for (i = 0; i < n; i++) base.push(0);
series.forEach(function (s, si) {
var up = [], down = [];
for (i = 0; i < n; i++) { var lo = base[i], hi = lo + (s.values[i] || 0); up.push((L + dx * i).toFixed(1) + ',' + (Tp + ph - hi / top * ph).toFixed(1)); down.unshift((L + dx * i).toFixed(1) + ',' + (Tp + ph - lo / top * ph).toFixed(1)); base[i] = hi; }
var p = svgEl('polygon', { points: up.concat(down).join(' '), 'class': 'vz-area-s' }); p.style.fill = vizColor(si, colors); svg.appendChild(p);
});
var tip = h('div', 'tip'); tip.hidden = true;
var guide = svgEl('line', { y1: Tp, y2: Tp + ph, 'class': 'vz-guide' }); guide.style.display = 'none'; svg.appendChild(guide);
var hit = svgEl('rect', { x: L, y: Tp, width: W - L - R, height: ph, fill: 'transparent' });
function at(ev) {
var r = svg.getBoundingClientRect(), px = (ev.clientX - r.left) * W / r.width, ix = Math.max(0, Math.min(n - 1, Math.round((px - L) / dx)));
clear(tip); tip.appendChild(h('strong', null, new Date(((o.start || 0) + ix * step) * 1000).toLocaleString(lang, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' })));
series.forEach(function (s) { tip.appendChild(h('div', null, h('span', null, s.label), h('span', 'num', nf(s.values[ix] || 0)))); });
tip.hidden = false; tip.style.left = Math.max(0, Math.min(L + dx * ix + 12, W - 170)) + 'px'; tip.style.top = '4px';
guide.setAttribute('x1', L + dx * ix); guide.setAttribute('x2', L + dx * ix); guide.style.display = '';
}
hit.addEventListener('mousemove', at); hit.addEventListener('click', at);
hit.addEventListener('mouseleave', function () { tip.hidden = true; guide.style.display = 'none'; });
svg.appendChild(hit); wrap.appendChild(svg); wrap.appendChild(tip);
}
box.appendChild(wrap);
box.appendChild(legendList(series.map(function (s) { return { label: s.label }; }), colors, function (d, j) { return ''; }));
box.appendChild(srTable(o.title, [t('charts.item'), t('charts.value')], series.map(function (s) { return [s.label, nf(sumOf(s.values))]; })));
watch(wrap, draw);
return box;
}
// bars(rows [{key,label,value,color?,parts?:[{label,value,color?}]}], {horizontal (default true), stacked, format, colors})
function barChart(rows, o) {
o = o || {};
rows = (rows || []).filter(function (r) { return r; });
var fmt = o.format || nf, hor = o.horizontal !== false;
function rowTotal(r) { return r.parts ? sumOf(r.parts.map(function (p) { return p.value; })) : r.value; }
var mx = Math.max.apply(null, [0].concat(rows.map(rowTotal)));
if (!mx) return empty(t('charts.empty'));
var box = h('div', 'vz vz-bars' + (hor ? '' : ' vz-cols'));
rows.forEach(function (r, i) {
var tot = rowTotal(r), track = h('div', 'vz-track');
var parts = r.parts && o.stacked !== false ? r.parts : [{ label: r.label, value: r.value, color: r.color }];
parts.forEach(function (p, j) {
var seg = h('i'); seg.style[hor ? 'width' : 'height'] = Math.max(p.value ? 1 : 0, p.value / mx * 100) + '%';
seg.style.background = p.color ? 'var(' + p.color + ')' : vizColor(r.parts ? j : (r.color ? 0 : i), r.color ? [r.color] : o.colors);
seg.title = p.label + ': ' + fmt(p.value); track.appendChild(seg);
});
box.appendChild(h('div', 'vz-row', h('span', 'vz-l', r.label), track, h('span', 'vz-v num', fmt(tot))));
});
box.appendChild(srTable(o.title, [t('charts.item'), t('charts.value')], rows.map(function (r) { return [r.label, fmt(rowTotal(r))]; })));
return box;
}
// heatmap(matrix [row][col] numbers, xLabels, yLabels, {format, title}); cell colour from --seq-1..5
function heatmap(matrix, xl, yl, o) {
o = o || {};
var mx = 0; (matrix || []).forEach(function (r) { r.forEach(function (v) { if (v > mx) mx = v; }); });
if (!mx) return empty(t('charts.empty'));
var fmt = o.format || nf, wrap = h('div', 'vz vz-heat');
function draw(Wpx) {
clear(wrap);
var ny = matrix.length, nx = matrix[0].length, LW = 56, W = Math.max(240, Wpx), cw = (W - LW) / nx, ch = Math.min(26, Math.max(12, cw)), H = ny * ch + 22;
var svg = svgEl('svg', { viewBox: '0 0 ' + W + ' ' + H, role: 'img', 'aria-label': o.title || '' }), step = Math.ceil(26 / cw);
matrix.forEach(function (row, y) {
var yt = svgEl('text', { x: LW - 6, y: y * ch + ch / 2 + 4, 'text-anchor': 'end', 'class': 'axis' }); yt.textContent = yl[y]; svg.appendChild(yt);
row.forEach(function (v, x) {
var lvl = v ? Math.min(5, 1 + Math.floor(v / mx * 4.999)) : 0;
var r = svgEl('rect', { x: LW + x * cw + 1, y: y * ch + 1, width: Math.max(1, cw - 2), height: ch - 2, rx: 2, 'class': 'vz-cell s' + lvl, tabindex: 0, 'aria-label': yl[y] + ' ' + xl[x] + ': ' + fmt(v) });
var ti = svgEl('title', {}); ti.textContent = yl[y] + ' ' + xl[x] + ': ' + fmt(v); r.appendChild(ti); svg.appendChild(r);
});
});
for (var x = 0; x < nx; x += step) { var xt = svgEl('text', { x: LW + x * cw + cw / 2, y: ny * ch + 15, 'text-anchor': 'middle', 'class': 'axis' }); xt.textContent = xl[x]; svg.appendChild(xt); }
wrap.appendChild(svg);
}
var box = h('div', null, wrap, srTable(o.title, [''].concat(xl), matrix.map(function (r, y) { return [yl[y]].concat(r.map(fmt)); })));
watch(wrap, draw);
return box;
}
// gauge(value, max, thresholds [{at, tone: ok|warn|danger|info}], {label, format})
function gauge(value, max, thr, o) {
o = o || {};
max = max > 0 ? max : 1;
var fmt = o.format || nf, v = Math.max(0, Math.min(max, Number(value) || 0));
thr = thr && thr.length ? thr : [{ at: 0, tone: 'ok' }, { at: max * .5, tone: 'warn' }, { at: max * .8, tone: 'danger' }];
var tone = 'ok'; thr.forEach(function (x) { if (v >= x.at) tone = pick(['ok', 'warn', 'danger', 'info'], x.tone, 'ok'); });
var d = 'M20 100 A80 80 0 0 1 180 100';
var svg = svgEl('svg', { viewBox: '0 0 200 120', 'class': 'vz-gauge', role: 'img', 'aria-label': (o.label || '') + ' ' + fmt(v) + ' / ' + fmt(max) });
svg.appendChild(svgEl('path', { d: d, pathLength: 100, 'class': 'vz-g-bg' }));
svg.appendChild(svgEl('path', { d: d, pathLength: 100, 'class': 'vz-g-fg tone-' + tone, 'stroke-dasharray': (v / max * 100) + ' 100' }));
var tv = svgEl('text', { x: 100, y: 92, 'text-anchor': 'middle', 'class': 'vz-c-v' }); tv.textContent = fmt(v); svg.appendChild(tv);
var lo = svgEl('text', { x: 20, y: 116, 'text-anchor': 'middle', 'class': 'axis' }); lo.textContent = '0'; svg.appendChild(lo);
var hi = svgEl('text', { x: 180, y: 116, 'text-anchor': 'middle', 'class': 'axis' }); hi.textContent = fmt(max); svg.appendChild(hi);
return h('div', 'vz vz-gauge-wrap', svg, o.label ? h('div', 'vz-c-l', o.label) : null);
}
var charts = { donut: donut, radar: radar, stackedArea: stackedArea, bars: barChart, heatmap: heatmap, sparkline: sparkline, gauge: gauge };
// ---------------------------------------------------------------- page registry
var ORDER = ['overview', 'threats', 'geo', 'live', 'replay', 'traffic', 'ips', 'sources'];
var pages = {};
var current = null; // { page, el }
function registerPage(p) {
@@ -883,9 +1147,27 @@
pages[p.id] = p;
if (booted) { renderNav(); route(); }
}
// rail groups; ids not listed go to the end of their group (page.group, else Analyze)
var GROUPS = [
['monitor', ['overview', 'live', 'slo']],
['investigate', ['ips', 'sessions', 'campaigns', 'replay', 'search']],
['analyze', ['threats', 'mitre', 'geo', 'evolution', 'concentration', 'survival', 'traffic', 'errors', 'protocol']],
['operate', ['defense', 'sources', 'integrity']],
['reports', ['reports']]
];
function groupOf(p) {
if (p.group) for (var i = 0; i < GROUPS.length; i++) if (GROUPS[i][0] === p.group) return p.group;
for (var j = 0; j < GROUPS.length; j++) if (GROUPS[j][1].indexOf(p.id) >= 0) return GROUPS[j][0];
return 'analyze';
}
function orderedPages() {
var ids = Object.keys(pages);
return ORDER.filter(function (id) { return pages[id]; }).concat(ids.filter(function (id) { return ORDER.indexOf(id) < 0; }).sort()).map(function (id) { return pages[id]; }).filter(function (p) { return p.nav !== false && p.id !== 'ip'; });
var visible = Object.keys(pages).map(function (id) { return pages[id]; }).filter(function (p) { return p.nav !== false && p.id !== 'ip'; }), out = [];
GROUPS.forEach(function (g) {
var mine = visible.filter(function (p) { return groupOf(p) === g[0]; });
g[1].forEach(function (id) { mine.filter(function (p) { return p.id === id; }).forEach(function (p) { out.push(p); }); });
mine.filter(function (p) { return g[1].indexOf(p.id) < 0; }).sort(function (a, b) { return a.id < b.id ? -1 : 1; }).forEach(function (p) { out.push(p); });
});
return out;
}
function sp(n, node) { node.classList.add('span-' + n); return node; }
function grid12() { return h('div', 'grid-12'); }
@@ -937,7 +1219,7 @@
function bucketNote(step) { return step ? t('timeline.bucket', { n: nf(Math.max(1, Math.round(step / 60))) }) : ''; }
function timelinePanel() {
var wrap = h('div', 'chart-wrap'), legend = h('div', 'legend'), note = h('span', 'note bucket-note');
var node = panel({ title: t('timeline.title'), hint: t('timeline.hint'), variant: 'chart', loading: true }, wrap, legend);
var node = panel({ title: t('timeline.title'), hint: t('timeline.hint'), variant: 'chart', loading: true, help: 'metric.attacks_per_hour_24h' }, wrap, legend);
var data = null;
function renderLegend() {
clear(legend);
@@ -945,7 +1227,9 @@
var b = el('button', { type: 'button', 'aria-pressed': state.hidden[c] ? 'false' : 'true' }, h('span', 'sw b-' + c), h('span', null, t('cat.' + c)));
b.addEventListener('click', function () { state.hidden[c] = !state.hidden[c]; renderLegend(); draw(); });
legend.appendChild(b);
b.title = t('cat.' + c);
});
help(legend, 'term.categories');
legend.appendChild(note);
}
function draw() {
@@ -1003,7 +1287,7 @@
clear(box);
keys.forEach(function (k) {
var x = m[k];
box.appendChild(metric(metricLabel(k), metricValue(k, x.value), { delta: typeof x.delta_pct === 'number' ? x.delta_pct : undefined, goodUp: !!GOOD_UP[k], spark: Array.isArray(x.spark) ? x.spark : null, sub: metricSub(k, x) }));
box.appendChild(metric(metricLabel(k), metricValue(k, x.value), { delta: typeof x.delta_pct === 'number' ? x.delta_pct : undefined, goodUp: !!GOOD_UP[k], spark: Array.isArray(x.spark) ? x.spark : null, sub: metricSub(k, x), help: 'metric.' + k }));
});
return true;
}
@@ -1012,12 +1296,12 @@
var T = s.totals, hosts = s.hosts || [], on = hosts.filter(function (x) { return x.online; }).length;
var range = rangeLower();
clear(box);
box.appendChild(stat(t('kpi.requests'), nf(T.requests), hosts.length > 1 ? t('kpi.sub.hosts', { n: on, m: hosts.length }) : t('kpi.sub.range', { range: range })));
box.appendChild(stat(t('kpi.malicious'), nf(T.malicious), t('kpi.sub.malicious'), T.malicious > 0 ? 'warn' : 'neutral'));
box.appendChild(stat(t('kpi.hostile'), nf(T.hostile_ips), t('kpi.sub.share', { p: pct(T.hostile_ips, T.unique_ips), n: nf(T.unique_ips) }), T.hostile_ips > 0 ? 'danger' : 'neutral'));
box.appendChild(stat(t('kpi.suspicious'), nf(T.suspicious_ips), t('kpi.sub.share', { p: pct(T.suspicious_ips, T.unique_ips), n: nf(T.unique_ips) }), T.suspicious_ips > 0 ? 'warn' : 'neutral'));
box.appendChild(stat(t('kpi.bans'), nf(T.active_bans), t('kpi.sub.bans')));
box.appendChild(stat(t('kpi.ips'), nf(T.unique_ips), t('kpi.sub.range', { range: range })));
box.appendChild(stat(t('kpi.requests'), nf(T.requests), hosts.length > 1 ? t('kpi.sub.hosts', { n: on, m: hosts.length }) : t('kpi.sub.range', { range: range }), 'neutral', null, 'metric.requests'));
box.appendChild(stat(t('kpi.malicious'), nf(T.malicious), t('kpi.sub.malicious'), T.malicious > 0 ? 'warn' : 'neutral', null, 'metric.malicious'));
box.appendChild(stat(t('kpi.hostile'), nf(T.hostile_ips), t('kpi.sub.share', { p: pct(T.hostile_ips, T.unique_ips), n: nf(T.unique_ips) }), T.hostile_ips > 0 ? 'danger' : 'neutral', null, 'term.level'));
box.appendChild(stat(t('kpi.suspicious'), nf(T.suspicious_ips), t('kpi.sub.share', { p: pct(T.suspicious_ips, T.unique_ips), n: nf(T.unique_ips) }), T.suspicious_ips > 0 ? 'warn' : 'neutral', null, 'term.level'));
box.appendChild(stat(t('kpi.bans'), nf(T.active_bans), t('kpi.sub.bans'), 'neutral', null, 'cat.ban'));
box.appendChild(stat(t('kpi.ips'), nf(T.unique_ips), t('kpi.sub.range', { range: range }), 'neutral', null, 'metric.unique_ips'));
}
function overviewLead(s) {
var T = s.totals;
@@ -1043,17 +1327,19 @@
}
// ---------------------------------------------------------------- page: overview
var RADAR_CATS = ['notfound', 'scanner', 'bruteforce', 'exploit', 'ssh-fail', 'ssh-probe'];
var pOverview = corePage({
id: 'overview', icon: ICONS.overview, titleKey: 'nav.overview',
build: function (root) {
var v = {}, g = grid12();
v.lead = sp(12, h('div', 'skeleton lead-skel')); v.kpis = h('div', 'kpi-row'); skeletonCards(v.kpis, 6);
v.timeline = timelinePanel();
v.radar = panel({ title: t('ov.radar'), hint: t('ov.radar.hint'), loading: true, help: 'term.attack_profile' });
v.countries = panel({ title: t('ov.countries'), hint: t('ov.countries.hint'), variant: 'list', loading: true, footer: el('a', { href: '#/geo' }, t('ov.all')) });
v.topips = panel({ title: t('ov.topips'), hint: t('ov.topips.hint'), variant: 'list', loading: true, footer: el('a', { href: '#/ips' }, t('ov.all')) });
v.feedList = feedList(30);
v.feed = panel({ title: t('ov.feed'), hint: t('ov.feed.hint'), variant: 'list', footer: el('a', { href: '#/live' }, t('ov.all')) }, v.feedList.node);
g.appendChild(v.lead); g.appendChild(v.kpis); g.appendChild(sp(12, v.timeline.node));
g.appendChild(v.lead); g.appendChild(v.kpis); g.appendChild(sp(8, v.timeline.node)); g.appendChild(sp(4, v.radar));
g.appendChild(sp(4, v.countries)); g.appendChild(sp(4, v.topips)); g.appendChild(sp(4, v.feed));
root.appendChild(g);
v.offResize = onResize(function () { v.timeline.draw(); });
@@ -1061,9 +1347,21 @@
v.feedList.render();
return v;
},
load: function (c) { return getSummary(c).then(function (s) { return getMetrics(c).then(function (m) { return Object.assign({}, s, { metrics: m }); }); }); },
load: function (c) {
return getSummary(c).then(function (s) {
var hosts = (s.hosts || []).filter(function (x) { return x.online !== false; }).slice(0, 4);
var rq = c.from !== null && c.from !== undefined ? { from: c.from, to: c.to } : { range: c.range };
var jobs = hosts.length > 1 ? hosts.map(function (x) { return api('/api/v1/summary', Object.assign({ host: x.name }, rq)).then(function (r) { return { label: x.name, s: r }; }, function () { return null; }); }) : [Promise.resolve({ label: (hosts[0] && hosts[0].name) || t('host.all'), s: s })];
return Promise.all(jobs).then(function (rs) { return getMetrics(c).then(function (m) { return Object.assign({}, s, { metrics: m, radar: rs.filter(Boolean) }); }); });
});
},
render: function (v, s) {
clear(v.lead); v.lead.classList.remove('skeleton', 'lead-skel'); v.lead.appendChild(overviewLead(s));
ready(v.radar); clear(v.radar.body);
v.radar.body.appendChild(charts.radar(RADAR_CATS.map(function (c) { return { key: c, label: catShort(c) }; }), (s.radar || []).map(function (r) {
var vals = RADAR_CATS.map(function (c) { var n = 0; ((r.s.timeline.series || {})[c] || []).forEach(function (x) { n += x; }); return n; }), tot = sumOf(vals) || 1;
return { label: r.label, values: vals.map(function (x) { return Math.round(x / tot * 1000) / 10; }) };
}), { title: t('ov.radar'), format: function (x) { return nf(x) + '%' } }));
kpiRow(s, v.kpis, s.metrics, 'overview');
v.timeline.set(s);
clear(v.countries.body); v.countries.body.appendChild(bars(s.countries, { label: function (r) { return countryLabel(r.key); } }));
@@ -1097,13 +1395,13 @@
v.lead = sp(12, h('div', 'skeleton lead-skel')); v.kpis = h('div', 'kpi-row'); skeletonCards(v.kpis, 6); v.mon = sp(12, h('p', 'note'));
v.timeline = timelinePanel();
v.mapbox = mapBox();
v.map = panel({ title: t('map.attacks'), hint: t('map.attacks.hint'), variant: 'map', loading: true }, v.mapbox);
v.map = panel({ title: t('map.attacks'), hint: t('map.attacks.hint'), variant: 'map', loading: true, help: 'term.categories' }, v.mapbox);
v.tbl = ipTable(false);
v.ips = panel({ title: t('ips.title'), hint: t('ips.hint'), actions: el('a', { class: 'btn', href: '#/ips' }, t('ov.all')) }, v.tbl.node);
v.ips = panel({ title: t('ips.title'), hint: t('ips.hint'), help: 'term.score', actions: el('a', { class: 'btn', href: '#/ips' }, t('ov.all')) }, v.tbl.node);
v.feedList = feedList(100);
v.feed = panel({ title: t('feed.title'), variant: 'list', footer: el('a', { href: '#/live' }, t('ov.all')) }, v.feedList.node);
v.paths = panel({ title: t('top.paths'), variant: 'list', loading: true }); v.domains = panel({ title: t('top.domains'), variant: 'list', loading: true });
v.uas = panel({ title: t('top.uas'), variant: 'list', loading: true }); v.users = panel({ title: t('top.users'), variant: 'list', loading: true });
v.paths = panel({ title: t('top.paths'), variant: 'list', loading: true, help: 'cat.scanner' }); v.domains = panel({ title: t('top.domains'), variant: 'list', loading: true, help: 'metric.requests' });
v.uas = panel({ title: t('top.uas'), variant: 'list', loading: true, help: 'term.family' }); v.users = panel({ title: t('top.users'), variant: 'list', loading: true, help: 'cat.ssh-fail' });
g.appendChild(v.lead); g.appendChild(v.kpis); g.appendChild(v.mon); g.appendChild(sp(12, v.timeline.node)); g.appendChild(sp(8, v.map)); g.appendChild(sp(4, v.feed));
g.appendChild(sp(12, v.ips));
[v.paths, v.domains, v.uas, v.users].forEach(function (x) { g.appendChild(sp(3, x)); });
@@ -1149,24 +1447,31 @@
sel.value = state.domain;
if (sel.value !== state.domain) sel.value = 'all';
}
var CLIENT_COLORS = { desktop: '--viz-1', mobile: '--viz-6', tablet: '--viz-5', bot: '--viz-3', tool: '--viz-7', unknown: '--viz-8', misc: '--viz-2' };
var CLIENT_ORDER = ['desktop', 'mobile', 'tablet', 'bot', 'tool', 'unknown', 'misc'];
var STATUS_TOKENS = ['--ok', '--info', '--warn', '--danger'];
var pTraffic = corePage({
id: 'traffic', icon: ICONS.traffic, titleKey: 'nav.traffic', domain: true,
build: function (root) {
var v = {}, g = grid12();
v.lead = sp(12, h('div', 'skeleton lead-skel')); v.kpis = h('div', 'kpi-row'); skeletonCards(v.kpis, 6);
v.wrap = h('div', 'chart-wrap'); v.note = h('span', 'note bucket-note');
v.legend = h('div', 'legend', h('span', 'li', h('span', 'sw b-treq'), t('traffic.requests')), h('span', 'li', h('span', 'sw b-tpages'), t('traffic.pages')), v.note);
v.timeline = panel({ title: t('traffic.timeline'), hint: t('traffic.timeline.hint'), variant: 'chart', loading: true }, v.wrap, v.legend);
v.wrap = h('div'); v.note = h('span', 'note bucket-note');
v.timeline = panel({ title: t('traffic.timeline'), hint: t('traffic.area.hint'), variant: 'chart', loading: true, help: 'metric.pages' }, v.wrap, h('div', 'legend', v.note));
v.mapbox = mapBox();
v.map = panel({ title: t('map.visitors'), hint: t('map.visitors.hint'), variant: 'map', loading: true }, v.mapbox);
var ids = [['pages', 'traffic.topPages'], ['refs', 'traffic.referrers'], ['cities', 'traffic.cities'], ['browsers', 'traffic.browsers'], ['oses', 'traffic.oses'], ['devices', 'traffic.devices'], ['bots', 'traffic.bots'], ['status', 'traffic.status']];
var ids = [['pages', 'traffic.topPages'], ['refs', 'traffic.referrers'], ['cities', 'traffic.cities'], ['bots', 'traffic.bots']];
ids.forEach(function (p) { v[p[0]] = panel({ title: t(p[1]), variant: 'list', loading: true }); });
v.client = panel({ title: t('traffic.client'), hint: t('traffic.client.hint'), loading: true, help: 'term.client_type' });
v.browsers = panel({ title: t('traffic.browsers'), hint: t('traffic.browsers.hint'), loading: true });
v.oses = panel({ title: t('traffic.oses'), hint: t('traffic.oses.hint'), loading: true });
v.status = panel({ title: t('traffic.status'), hint: t('traffic.status.hint'), loading: true, help: 'term.status_class' });
v.privacy = sp(12, h('p', 'note', t('traffic.privacy')));
g.appendChild(v.lead); g.appendChild(v.kpis); g.appendChild(sp(12, v.timeline)); g.appendChild(sp(12, v.map));
['pages', 'refs', 'cities', 'browsers', 'oses', 'devices'].forEach(function (k) { g.appendChild(sp(4, v[k])); });
g.appendChild(sp(6, v.bots)); g.appendChild(sp(6, v.status)); g.appendChild(v.privacy);
g.appendChild(sp(4, v.client)); g.appendChild(sp(4, v.browsers)); g.appendChild(sp(4, v.oses));
g.appendChild(sp(6, v.status)); g.appendChild(sp(6, v.bots));
['pages', 'refs', 'cities'].forEach(function (k) { g.appendChild(sp(4, v[k])); });
g.appendChild(v.privacy);
root.appendChild(g);
v.offResize = onResize(function () { if (v.data) drawTraffic(v, v.data); });
return v;
},
load: function (c) { return api('/api/v1/traffic', Object.assign({ host: c.host, domain: c.domain }, c.from !== null && c.from !== undefined ? { from: c.from, to: c.to } : { range: c.range })); },
@@ -1179,31 +1484,35 @@
? lead(t('tr.lead.some', { n: nf(d.visitors), p: nf(d.pages) }), t('tr.lead.body', { r: nf(d.requests), b: nf(d.bots), a: nf(Math.round(d.p50_ms)), c: nf(Math.round(d.p95_ms)) }), 'ok')
: lead(t('tr.lead.none'), t('tr.lead.noneBody'), 'neutral'));
clear(v.kpis);
v.kpis.appendChild(stat(t('traffic.requests'), nf(d.requests), t('traffic.sub.requests')));
v.kpis.appendChild(stat(t('traffic.pages'), nf(d.pages), t('traffic.sub.pages', { n: nf(d.requests) })));
v.kpis.appendChild(stat(t('traffic.visitors'), nf(d.visitors), t('traffic.sub.visitors')));
v.kpis.appendChild(stat(t('traffic.bytes'), fmtBytes(d.bytes), t('kpi.sub.range', { range: rangeLower() })));
v.kpis.appendChild(stat(t('traffic.latency'), Math.round(d.p50_ms) + ' / ' + Math.round(d.p95_ms) + ' ms', t('kpi.sub.range', { range: rangeLower() })));
v.kpis.appendChild(stat(t('traffic.bots'), nf(d.bots), t('traffic.sub.bots', { n: nf(d.requests) })));
ready(v.timeline); ready(v.map);
drawTraffic(v, d);
var rg = rangeLower();
v.kpis.appendChild(stat(t('traffic.requests'), nf(d.requests), t('traffic.sub.requests'), 'neutral', null, 'metric.requests'));
v.kpis.appendChild(stat(t('traffic.pages'), nf(d.pages), t('traffic.sub.pages', { n: nf(d.requests) }), 'neutral', null, 'metric.pages'));
v.kpis.appendChild(stat(t('traffic.visitors'), nf(d.visitors), t('traffic.sub.visitors'), 'neutral', null, 'metric.visitors'));
v.kpis.appendChild(stat(t('traffic.bytes'), fmtBytes(d.bytes), t('kpi.sub.range', { range: rg }), 'neutral', null, 'metric.bytes'));
v.kpis.appendChild(stat(t('traffic.latency'), Math.round(d.p50_ms) + ' / ' + Math.round(d.p95_ms), 'ms \u00b7 ' + t('kpi.sub.range', { range: rg }), 'neutral', null, 'metric.latency'));
v.kpis.appendChild(stat(t('traffic.bots'), nf(d.bots), t('traffic.sub.bots', { n: nf(d.requests) }), 'neutral', null, 'metric.bots'));
// time series: page views and the rest of the requests
var tl = d.timeline, pg = tl.pages || [], other = (tl.req || []).map(function (x, i) { return Math.max(0, x - (pg[i] || 0)); });
ready(v.timeline); clear(v.wrap);
v.note.textContent = bucketNote(tl.step);
v.wrap.appendChild(charts.stackedArea([{ key: 'pages', label: t('traffic.pages'), values: pg }, { key: 'other', label: t('traffic.otherReq'), values: other }], tl.step, { start: tl.start, colors: ['--accent', '--viz-8'], title: t('traffic.timeline') }));
ready(v.map);
renderMap(v.mapbox, d.countries, true, t('map.visitors'));
function fill(key, rows, mono) { clear(v[key].body); v[key].body.appendChild(bars(rows, { mono: mono })); }
fill('pages', d.top_pages, true); fill('refs', d.referrers, true); fill('cities', d.cities, false);
fill('browsers', d.browsers, false); fill('oses', d.oses, false);
fill('devices', (d.devices || []).map(function (x) { return { key: t('device.' + pick(['desktop', 'mobile', 'tablet', 'bot', 'tool'], x.key, 'unknown')), n: x.n }; }), false);
fill('bots', d.bot_names, false);
fill('status', ['2xx', '3xx', '4xx', '5xx'].map(function (k, i) { return { key: k, n: d.status[i] }; }).filter(function (x) { return x.n > 0; }), true);
fill('pages', d.top_pages, true); fill('refs', d.referrers, true); fill('cities', d.cities, false); fill('bots', d.bot_names, false);
// client type: devices as reported, plus bots when the devices list has no bot entry
var dev = (d.devices || []).map(function (x) { return { k: pick(CLIENT_ORDER, x.key, 'misc'), n: x.n }; });
dev.sort(function (a, b) { return CLIENT_ORDER.indexOf(a.k) - CLIENT_ORDER.indexOf(b.k); });
function donutOf(box, data, colors, title) { ready(box); clear(box.body); box.body.appendChild(charts.donut(data, { title: title, colors: colors })); }
donutOf(v.client, dev.map(function (x) { return { key: x.k, label: t('device.' + x.k), value: x.n }; }), dev.map(function (x) { return CLIENT_COLORS[x.k]; }), t('traffic.client'));
donutOf(v.browsers, (d.browsers || []).map(function (x) { return { key: x.key, label: x.key, value: x.n }; }), null, t('traffic.browsers'));
donutOf(v.oses, (d.oses || []).map(function (x) { return { key: x.key, label: x.key, value: x.n }; }), null, t('traffic.oses'));
var cls = ['2xx', '3xx', '4xx', '5xx'];
ready(v.status); clear(v.status.body);
v.status.body.appendChild(charts.bars(cls.map(function (k, i) { return { key: k, label: t('traffic.status.' + k), value: (d.status || [])[i] || 0, color: STATUS_TOKENS[i] }; }), { title: t('traffic.status') }));
},
dispose: function (v) { v.offResize(); }
dispose: function () { }
});
function drawTraffic(v, d) {
var tl = d.timeline;
v.note.textContent = bucketNote(tl.step);
chart(v.wrap, { start: tl.start, step: tl.step, stacked: false, aria: t('traffic.timeline'), layers: [
{ cls: 'b-treq', label: t('traffic.requests'), vals: tl.req }, { cls: 'b-tpages', label: t('traffic.pages'), vals: tl.pages }
] });
}
// ---------------------------------------------------------------- page: ips
var pIPs = corePage({
@@ -1213,7 +1522,7 @@
v.lead = sp(12, h('div'));
v.tbl = ipTable(true);
v.tbl.onTotal(function (n) { setSliceNote(pl('slice.ips', n, { n: nf(n) })); });
v.ips = panel({ title: t('ips.title'), hint: t('ips.hint') }, v.tbl.node);
v.ips = panel({ title: t('ips.title'), hint: t('ips.hint'), help: 'term.score' }, v.tbl.node);
g.appendChild(v.lead); g.appendChild(sp(12, v.ips)); root.appendChild(g);
return v;
},
@@ -1242,7 +1551,7 @@
var copy = el('button', { type: 'button', class: 'btn primary' }, t('blocklist.copy'));
var dlTxt = el('a', { class: 'btn', href: '/api/v1/blocklist.txt' }, t('blocklist.download'));
var dlJson = el('a', { class: 'btn', href: '/api/v1/blocklist.json' }, t('blocklist.downloadJson'));
var node = panel({ title: t('blocklist.title'), hint: t('blocklist.help') },
var node = panel({ title: t('blocklist.title'), hint: t('blocklist.help'), help: 'term.blocklist' },
h('div', 'toolbar', h('label', 'check', h('span', null, t('blocklist.minScore')), minScore), fam, copy, dlTxt, dlJson), count, msg);
var timer = 0, alive = true;
function query(extra) {
@@ -1294,11 +1603,11 @@
var v = {}, g = grid12();
v.lead = sp(12, h('div'));
v.hostsBox = h('div', 'hosts');
v.hosts = panel({ title: t('hosts.title'), hint: t('hosts.hint') }, v.hostsBox);
v.hosts = panel({ title: t('hosts.title'), hint: t('hosts.hint'), help: 'term.peer' }, v.hostsBox);
var thead = h('thead', null, h('tr', null, ['col.host', 'col.source', 'col.state', 'col.lines', 'col.malformed', 'col.lastEvent'].map(function (k) { return el('th', { scope: 'col' }, t(k)); })));
v.tbody = h('tbody');
v.srcEmpty = h('div');
v.sources = panel({ title: t('sources.title'), hint: t('sources.hint') }, h('div', 'tbl-wrap', h('table', 'stack tbl-cards', thead, v.tbody)), v.srcEmpty);
v.sources = panel({ title: t('sources.title'), hint: t('sources.hint'), help: 'term.integrity_gap' }, h('div', 'tbl-wrap', h('table', 'stack tbl-cards', thead, v.tbody)), v.srcEmpty);
v.geoBox = h('div');
v.geo = panel({ title: t('src.geo.title'), hint: t('src.geo.hint') }, v.geoBox);
v.bl = blocklistPanel();
@@ -1504,8 +1813,10 @@
function renderNav() {
var list = orderedPages(), nav = $('#nav'), bar = $('#tabbar'), more = $('#more'), cur = navId();
clear(nav); clear(bar); clear(more);
var lastGroup = null;
list.forEach(function (p) {
var label = t(p.titleKey);
var label = t(p.titleKey), gr = groupOf(p);
if (gr !== lastGroup) { nav.appendChild(h('div', 'nav-group', t('nav.group.' + gr))); lastGroup = gr; }
var a = el('a', { class: 'nav-item', href: hrefFor(p.id), title: label }, h('span', 'nav-ico', iconNode(p.icon)), h('span', 'nav-label', label));
if (cur === p.id) a.setAttribute('aria-current', 'page');
nav.appendChild(a);
@@ -1522,7 +1833,10 @@
if (rest.some(function (p) { return p.id === cur; })) mb.setAttribute('aria-current', 'page');
mb.addEventListener('click', function () { setMore(more.hidden); });
bar.appendChild(mb);
var rg = null;
rest.forEach(function (p) {
var g2 = groupOf(p);
if (g2 !== rg) { more.appendChild(h('div', 'nav-group', t('nav.group.' + g2))); rg = g2; }
var a = el('a', { href: hrefFor(p.id) }, h('span', 'nav-ico', iconNode(p.icon)), h('span', null, t(p.titleKey)));
if (cur === p.id) a.setAttribute('aria-current', 'page');
more.appendChild(a);
@@ -1639,7 +1953,7 @@
});
$('#scrim').addEventListener('click', closeDetail);
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape') { closeDetail(); setMore(false); closeRangePicker(true); return; }
if (e.key === 'Escape') { hideHelp(); closeDetail(); setMore(false); closeRangePicker(true); return; }
var box = $('#detail');
if (e.key === 'Tab' && !box.hidden) {
var f = Array.prototype.slice.call(box.querySelectorAll('button, a[href], [tabindex="0"]'));
@@ -1660,6 +1974,7 @@
var more = $('#more');
if (!more.hidden && !more.contains(e.target) && !$('#tabbar').contains(e.target)) setMore(false);
if (rp.open && !$('#range-picker').contains(e.target)) closeRangePicker(false);
if (helpPinned) hideHelp();
});
window.addEventListener('hashchange', route);
window.matchMedia && matchMedia('(prefers-color-scheme: light)').addEventListener && matchMedia('(prefers-color-scheme: light)').addEventListener('change', notifyPage);
@@ -1680,8 +1995,33 @@
rangeParams: rangeParams, rangeLabel: rangeLabel, href: hrefFor, toast: toast,
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 }
};
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot); else setTimeout(boot, 0);
// page scripts are listed in /pages.json ({"pages":[{"name":"geo","css":true}, ...]}); only files that exist
// are listed, so nothing 404s. Each name loads /<name>.js (and /<name>.css) in order, then the app boots.
var DEFAULT_PAGES = [{ name: 'geo', css: true }, { name: 'live', css: true }, { name: 'ip', css: true }, { name: 'replay', css: true }];
function loadScript(src) {
return new Promise(function (ok) {
var sc = document.createElement('script');
sc.src = src; sc.async = false;
sc.onload = ok; sc.onerror = function () { console.warn('page script failed: ' + src); ok(); };
document.head.appendChild(sc);
});
}
function loadPages() {
return fetch('/pages.json', { credentials: 'same-origin' }).then(function (r) { return r.ok ? r.json() : null; }, function () { return null; }).then(function (m) {
var list = m && Array.isArray(m.pages) ? m.pages : DEFAULT_PAGES, chain = Promise.resolve();
list.forEach(function (p) {
var name = p && String(p.name || '');
if (!/^[a-z][a-z0-9-]*$/.test(name)) return;
if (p.css) { var l = document.createElement('link'); l.rel = 'stylesheet'; l.href = '/' + name + '.css'; document.head.appendChild(l); }
chain = chain.then(function () { return loadScript('/' + name + '.js'); });
});
return chain;
});
}
function start() { loadPages().then(boot, boot); }
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start); else setTimeout(start, 0);
})();