CI / Format and vet (pull_request) Successful in 1m1s
CI / Dependency audit (pull_request) Successful in 32s
CI / Tests (Linux, race detector) (pull_request) Successful in 1m55s
Release / Plan (reuse the published image?) (push) Successful in 4s
Release / ci (push) Skipped
Release / Build hub image (amd64) (push) Skipped
Release / Build probe image (amd64) (push) Skipped
Release / Build hub image (arm64) (push) Skipped
Release / Build probe image (arm64) (push) Skipped
Release / Publish tags (hub) (push) Skipped
Release / Publish tags (probe) (push) Skipped
Release / Gitea release (push) Skipped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
801 lines
51 KiB
JavaScript
801 lines
51 KiB
JavaScript
/* Urutau - INCIDENTS page: every finding of the outbound traffic (egress) becomes a ticket that
|
||
people triage (open, investigating, true/false positive, benign, resolved), comment on and,
|
||
for false positives, suppress. #/incidents is the list, #/incidents/<id> the ticket.
|
||
Data: /api/v1/incidents (GET list, GET one, PATCH, POST comments, POST create).
|
||
Ticket text (workload names, details, comments, tags) comes from hostile logs and from users:
|
||
dynamic text goes through textContent only. */
|
||
(function () {
|
||
'use strict';
|
||
|
||
var STATUSES = ['open', 'investigating', 'true_positive', 'false_positive', 'benign', 'resolved'];
|
||
var STATUS_TONE = { open: 'warn', investigating: 'info', true_positive: 'danger', false_positive: 'neutral', benign: 'neutral', resolved: 'ok' };
|
||
var SEVS = ['critical', 'high', 'medium', 'low', 'info'];
|
||
var SEV_TONE = { critical: 'danger', high: 'danger', medium: 'warn', low: 'info', info: 'neutral' };
|
||
var SORTS = ['updated', 'severity', 'last_seen'];
|
||
var SUPPRESSIBLE = ['false_positive', 'benign'];
|
||
var PER_PAGE = 25;
|
||
var AUTHOR_KEY = 'urutau.author';
|
||
|
||
// Ticket ids are per host (each probe keeps its own INC-n sequence): shown and linked as host/INC-n.
|
||
function splitId(it) {
|
||
var id = String(it.id || ''), host = it.host ? String(it.host) : '', i = id.lastIndexOf('/');
|
||
if (i > 0) { host = id.slice(0, i); id = id.slice(i + 1); }
|
||
return { host: host, num: id, full: host ? host + '/' + id : id };
|
||
}
|
||
function idSegs(it) { var q = splitId(it); return q.host ? [q.host, q.num] : [q.num]; }
|
||
|
||
function boot() {
|
||
var U = window.Urutau;
|
||
if (!U || !U.registerPage) return false;
|
||
var el = U.el, t = U.t;
|
||
|
||
U.registerI18n({
|
||
en: {
|
||
'inc.title': 'Incidents',
|
||
'inc.nav.open': '{n} open or under investigation',
|
||
'inc.lead': 'Every outbound finding is a ticket. Open it, investigate, write down what you found, and close it as a real incident, a false positive or benign.',
|
||
'inc.author': 'Your name',
|
||
'inc.author.hint': 'Saved in this browser and shown next to your comments and changes.',
|
||
'inc.new': 'New ticket',
|
||
'inc.search': 'Search tickets',
|
||
'inc.sev.all': 'All severities',
|
||
'inc.sev.critical': 'Critical', 'inc.sev.high': 'High', 'inc.sev.medium': 'Medium', 'inc.sev.low': 'Low', 'inc.sev.info': 'Info',
|
||
'inc.sort': 'Sort by',
|
||
'inc.sort.updated': 'Recently updated', 'inc.sort.severity': 'Severity', 'inc.sort.last_seen': 'Last seen',
|
||
'inc.h.created': '{who} opened the ticket (severity: {sev})', 'inc.h.flood': 'flood grouping',
|
||
'inc.status.open': 'Open', 'inc.status.investigating': 'Investigating', 'inc.status.true_positive': 'True positive',
|
||
'inc.status.false_positive': 'False positive', 'inc.status.benign': 'Benign', 'inc.status.resolved': 'Resolved',
|
||
'inc.tab.active': 'Active', 'inc.tab.all': 'All',
|
||
'inc.tabs': 'Filter by status',
|
||
'inc.list.empty': 'No tickets here',
|
||
'inc.list.empty.sub': 'Nothing matches these filters. Findings from the outbound traffic page appear here by themselves.',
|
||
'inc.list.err': 'Could not load the tickets.',
|
||
'inc.retry': 'Try again',
|
||
'inc.comments.n.one': '{n} comment', 'inc.comments.n.other': '{n} comments',
|
||
'inc.seen': 'seen {when}',
|
||
'inc.source.egress': 'Outbound traffic', 'inc.source.manual': 'Manual',
|
||
'inc.back': 'All incidents',
|
||
'inc.notfound': 'Ticket not found',
|
||
'inc.notfound.sub': 'It may have been removed, or the link is wrong.',
|
||
'inc.f.title': 'Title', 'inc.f.severity': 'Severity', 'inc.f.status': 'Status', 'inc.f.assignee': 'Assigned to',
|
||
'inc.f.tags': 'Tags', 'inc.f.tags.hint': 'Separate with commas.',
|
||
'inc.f.verdict': 'Conclusion', 'inc.f.verdict.hint': 'What you found and why you closed it this way.',
|
||
'inc.f.detail': 'Details', 'inc.f.host': 'Server',
|
||
'inc.f.suppress': 'Suppress identical alerts',
|
||
'inc.f.suppress.help': 'Only for false positive or benign. Future findings with the same fingerprint stop showing on the outbound traffic page (they stay behind "show suppressed").',
|
||
'inc.f.suppress.off': 'Pick False positive or Benign to enable this.',
|
||
'inc.edit': 'Ticket',
|
||
'inc.save': 'Save changes',
|
||
'inc.saved': 'Ticket updated',
|
||
'inc.quick': 'Quick actions',
|
||
'inc.quick.fp': 'Mark false positive', 'inc.quick.tp': 'Confirm incident', 'inc.quick.resolve': 'Resolve',
|
||
'inc.tech': 'Technical data',
|
||
'inc.t.kind': 'Pattern', 'inc.t.source': 'Source', 'inc.t.workload': 'Workload', 'inc.t.dst': 'Destination', 'inc.t.port': 'Port',
|
||
'inc.t.proto': 'Protocol', 'inc.t.host': 'Server', 'inc.t.first': 'First seen', 'inc.t.last': 'Last seen', 'inc.t.count': 'Occurrences',
|
||
'inc.t.key': 'Fingerprint', 'inc.t.created': 'Opened', 'inc.t.updated': 'Updated',
|
||
'inc.comments': 'Comments',
|
||
'inc.comments.none': 'No comments yet.',
|
||
'inc.comment.ph': 'Write what you checked or decided',
|
||
'inc.comment.add': 'Add comment',
|
||
'inc.comment.added': 'Comment added',
|
||
'inc.history': 'History',
|
||
'inc.history.none': 'No changes yet.',
|
||
'inc.h.line': '{who} changed {field}',
|
||
'inc.h.field.status': 'status', 'inc.h.field.severity': 'severity', 'inc.h.field.assignee': 'assignee', 'inc.h.field.tags': 'tags',
|
||
'inc.h.field.title': 'title', 'inc.h.field.verdict': 'conclusion', 'inc.h.field.suppress': 'alert suppression',
|
||
'inc.h.empty': 'empty', 'inc.h.on': 'on', 'inc.h.off': 'off',
|
||
'inc.err.save': 'Could not save. Check the fields and try again.',
|
||
'inc.err.suppress': 'Suppression is only allowed for False positive or Benign.',
|
||
'inc.err.comment': 'Could not add the comment.',
|
||
'inc.err.create': 'Could not create the ticket.',
|
||
'inc.new.title': 'New ticket',
|
||
'inc.new.explain': 'Open a ticket by hand for something you saw that the system did not flag.',
|
||
'inc.new.create': 'Create ticket',
|
||
'inc.cancel': 'Cancel',
|
||
'inc.required': 'Title is required.',
|
||
'eg.f.ticket': 'Ticket {id}',
|
||
'eg.suppressed.toggle': 'Show suppressed ({n})',
|
||
'eg.suppressed.chip': 'suppressed'
|
||
},
|
||
'pt-BR': {
|
||
'inc.title': 'Incidentes',
|
||
'inc.nav.open': '{n} em aberto ou em investigação',
|
||
'inc.lead': 'Cada achado de tráfego de saída é um chamado. Abra, investigue, anote o que descobriu e encerre como incidente real, falso positivo ou benigno.',
|
||
'inc.author': 'Seu nome',
|
||
'inc.author.hint': 'Fica salvo neste navegador e aparece junto dos seus comentários e alterações.',
|
||
'inc.new': 'Novo chamado',
|
||
'inc.search': 'Buscar chamados',
|
||
'inc.sev.all': 'Todas as severidades',
|
||
'inc.sev.critical': 'Crítica', 'inc.sev.high': 'Alta', 'inc.sev.medium': 'Média', 'inc.sev.low': 'Baixa', 'inc.sev.info': 'Informativa',
|
||
'inc.sort': 'Ordenar por',
|
||
'inc.sort.updated': 'Atualizados recentemente', 'inc.sort.severity': 'Severidade', 'inc.sort.last_seen': 'Última ocorrência',
|
||
'inc.h.created': '{who} abriu o chamado (severidade: {sev})', 'inc.h.flood': 'agrupamento de flood',
|
||
'inc.status.open': 'Aberto', 'inc.status.investigating': 'Em investigação', 'inc.status.true_positive': 'Verdadeiro positivo',
|
||
'inc.status.false_positive': 'Falso positivo', 'inc.status.benign': 'Benigno', 'inc.status.resolved': 'Resolvido',
|
||
'inc.tab.active': 'Ativos', 'inc.tab.all': 'Todos',
|
||
'inc.tabs': 'Filtrar por status',
|
||
'inc.list.empty': 'Nenhum chamado aqui',
|
||
'inc.list.empty.sub': 'Nada corresponde a estes filtros. Os achados da página de tráfego de saída aparecem aqui sozinhos.',
|
||
'inc.list.err': 'Não foi possível carregar os chamados.',
|
||
'inc.retry': 'Tentar de novo',
|
||
'inc.comments.n.one': '{n} comentário', 'inc.comments.n.other': '{n} comentários',
|
||
'inc.seen': 'visto {when}',
|
||
'inc.source.egress': 'Tráfego de saída', 'inc.source.manual': 'Manual',
|
||
'inc.back': 'Todos os incidentes',
|
||
'inc.notfound': 'Chamado não encontrado',
|
||
'inc.notfound.sub': 'Ele pode ter sido removido ou o link está errado.',
|
||
'inc.f.title': 'Título', 'inc.f.severity': 'Severidade', 'inc.f.status': 'Status', 'inc.f.assignee': 'Responsável',
|
||
'inc.f.tags': 'Etiquetas', 'inc.f.tags.hint': 'Separe com vírgulas.',
|
||
'inc.f.verdict': 'Conclusão', 'inc.f.verdict.hint': 'O que você descobriu e por que encerrou assim.',
|
||
'inc.f.detail': 'Detalhes', 'inc.f.host': 'Servidor',
|
||
'inc.f.suppress': 'Suprimir alertas iguais',
|
||
'inc.f.suppress.help': 'Só para falso positivo ou benigno. Os próximos achados com a mesma impressão digital deixam de aparecer na página de tráfego de saída (ficam atrás de "mostrar suprimidos").',
|
||
'inc.f.suppress.off': 'Escolha Falso positivo ou Benigno para habilitar.',
|
||
'inc.edit': 'Chamado',
|
||
'inc.save': 'Salvar alterações',
|
||
'inc.saved': 'Chamado atualizado',
|
||
'inc.quick': 'Ações rápidas',
|
||
'inc.quick.fp': 'Marcar falso positivo', 'inc.quick.tp': 'Confirmar incidente', 'inc.quick.resolve': 'Resolver',
|
||
'inc.tech': 'Dados técnicos',
|
||
'inc.t.kind': 'Padrão', 'inc.t.source': 'Origem', 'inc.t.workload': 'Carga de trabalho', 'inc.t.dst': 'Destino', 'inc.t.port': 'Porta',
|
||
'inc.t.proto': 'Protocolo', 'inc.t.host': 'Servidor', 'inc.t.first': 'Primeira vez', 'inc.t.last': 'Última vez', 'inc.t.count': 'Ocorrências',
|
||
'inc.t.key': 'Impressão digital', 'inc.t.created': 'Aberto em', 'inc.t.updated': 'Atualizado em',
|
||
'inc.comments': 'Comentários',
|
||
'inc.comments.none': 'Nenhum comentário ainda.',
|
||
'inc.comment.ph': 'Escreva o que você verificou ou decidiu',
|
||
'inc.comment.add': 'Comentar',
|
||
'inc.comment.added': 'Comentário adicionado',
|
||
'inc.history': 'Histórico',
|
||
'inc.history.none': 'Nenhuma alteração ainda.',
|
||
'inc.h.line': '{who} alterou {field}',
|
||
'inc.h.field.status': 'o status', 'inc.h.field.severity': 'a severidade', 'inc.h.field.assignee': 'o responsável', 'inc.h.field.tags': 'as etiquetas',
|
||
'inc.h.field.title': 'o título', 'inc.h.field.verdict': 'a conclusão', 'inc.h.field.suppress': 'a supressão de alertas',
|
||
'inc.h.empty': 'vazio', 'inc.h.on': 'ligada', 'inc.h.off': 'desligada',
|
||
'inc.err.save': 'Não foi possível salvar. Confira os campos e tente de novo.',
|
||
'inc.err.suppress': 'A supressão só é permitida em Falso positivo ou Benigno.',
|
||
'inc.err.comment': 'Não foi possível adicionar o comentário.',
|
||
'inc.err.create': 'Não foi possível criar o chamado.',
|
||
'inc.new.title': 'Novo chamado',
|
||
'inc.new.explain': 'Abra um chamado à mão para algo que você viu e o sistema não sinalizou.',
|
||
'inc.new.create': 'Criar chamado',
|
||
'inc.cancel': 'Cancelar',
|
||
'inc.required': 'O título é obrigatório.',
|
||
'eg.f.ticket': 'Chamado {id}',
|
||
'eg.suppressed.toggle': 'Mostrar suprimidos ({n})',
|
||
'eg.suppressed.chip': 'suprimido'
|
||
}
|
||
});
|
||
|
||
// layout v2 strings
|
||
U.registerI18n({
|
||
en: {
|
||
'inc.col.id': 'ID', 'inc.col.title': 'Title', 'inc.col.status': 'Status', 'inc.col.assignee': 'Assignee', 'inc.col.where': 'Server / destination', 'inc.col.seen': 'Last seen',
|
||
'inc.empty.all': 'View all ({n})',
|
||
'inc.summary': 'Summary', 'inc.edit.btn': 'Edit', 'inc.save.one': 'Save', 'inc.concl.add': 'Add conclusion', 'inc.detail.label': 'Detail',
|
||
'inc.activity': 'Activity',
|
||
'inc.commenting': 'Commenting as', 'inc.author.change': 'Change name', 'inc.comment.hint': 'Ctrl+Enter to send',
|
||
'inc.props': 'Properties',
|
||
'inc.assign.me': 'Assign to me',
|
||
'inc.sup.short': 'Hide identical alerts', 'inc.sup.hint': 'Only for false positive or benign.',
|
||
'inc.meta': 'opened {a} · updated {b} · {n} occurrences',
|
||
'inc.h.group': '{who} made {n} changes',
|
||
'inc.copy': 'Copy', 'inc.copied': 'Copied',
|
||
'inc.title.edit': 'Edit title',
|
||
'inc.col.count': 'Hits', 'inc.unassigned': 'Unassigned', 'inc.evidence': 'What was detected',
|
||
'inc.summary.none': 'No conclusion yet. Write what you found once you know.',
|
||
'inc.sup.on': 'On: new identical findings are hidden from the outbound traffic page.',
|
||
'inc.sup.what': 'Hide new findings with this same fingerprint from the outbound traffic page.',
|
||
'inc.sup.more': 'How it works',
|
||
'inc.sup.until': 'Suppressed until {date} (turned on {ago}).', 'inc.sup.until.short': 'Suppressed until {date}',
|
||
'inc.sup.only.egress': 'Only tickets from outbound traffic findings can be suppressed.',
|
||
'inc.sup.only.low': 'High or critical findings cannot be suppressed.',
|
||
'inc.sup.for': 'Suppress for', 'inc.sup.days': '{n} days',
|
||
'inc.sup.reopen': 'The ticket reopens by itself when the period ends or if the severity goes up.'
|
||
},
|
||
'pt-BR': {
|
||
'inc.col.id': 'ID', 'inc.col.title': 'Título', 'inc.col.status': 'Status', 'inc.col.assignee': 'Responsável', 'inc.col.where': 'Servidor / destino', 'inc.col.seen': 'Última vez',
|
||
'inc.empty.all': 'Ver todos ({n})',
|
||
'inc.summary': 'Resumo', 'inc.edit.btn': 'Editar', 'inc.save.one': 'Salvar', 'inc.concl.add': 'Adicionar conclusão', 'inc.detail.label': 'Detalhe',
|
||
'inc.activity': 'Atividade',
|
||
'inc.commenting': 'Comentando como', 'inc.author.change': 'Alterar nome', 'inc.comment.hint': 'Ctrl+Enter para enviar',
|
||
'inc.props': 'Propriedades',
|
||
'inc.assign.me': 'Atribuir a mim',
|
||
'inc.sup.short': 'Ocultar alertas iguais', 'inc.sup.hint': 'Só para falso positivo ou benigno.',
|
||
'inc.meta': 'aberto {a} · atualizado {b} · {n} ocorrências',
|
||
'inc.h.group': '{who} fez {n} alterações',
|
||
'inc.copy': 'Copiar', 'inc.copied': 'Copiado',
|
||
'inc.title.edit': 'Editar título',
|
||
'inc.col.count': 'Ocorr.', 'inc.unassigned': 'Sem responsável', 'inc.evidence': 'O que foi detectado',
|
||
'inc.summary.none': 'Ainda sem conclusão. Escreva o que descobriu quando souber.',
|
||
'inc.sup.on': 'Ligada: novos achados iguais ficam ocultos na página de tráfego de saída.',
|
||
'inc.sup.what': 'Oculta da página de tráfego de saída os novos achados com esta mesma impressão digital.',
|
||
'inc.sup.more': 'Como funciona',
|
||
'inc.sup.until': 'Suprimido até {date} (ligado {ago}).', 'inc.sup.until.short': 'Suprimido até {date}',
|
||
'inc.sup.only.egress': 'Só chamados de achados do tráfego de saída podem ser suprimidos.',
|
||
'inc.sup.only.low': 'Achados de severidade alta ou crítica não podem ser suprimidos.',
|
||
'inc.sup.for': 'Suprimir por', 'inc.sup.days': '{n} dias',
|
||
'inc.sup.reopen': 'O chamado reabre sozinho quando o prazo vence ou se a severidade subir.'
|
||
}
|
||
});
|
||
|
||
var root = null, ctx = null, view = null;
|
||
|
||
// ------------------------------------------------------------ helpers
|
||
function clear(n) { while (n.firstChild) n.removeChild(n.firstChild); }
|
||
function pick(list, v, d) { return list.indexOf(v) >= 0 ? v : d; }
|
||
function nf(n) { return U.fmt.num(n || 0); }
|
||
function sevOf(s) { return pick(SEVS, s, 'info'); }
|
||
function statusOf(s) { return pick(STATUSES, s, 'open'); }
|
||
function sevBadge(s) { s = sevOf(s); return U.ui.badge(t('inc.sev.' + s), SEV_TONE[s]); }
|
||
function statusBadge(s) { s = statusOf(s); return U.ui.badge(t('inc.status.' + s), STATUS_TONE[s]); }
|
||
function dot(sev) { return el('span', { class: 'inc-dot inc-d-' + sevOf(sev), title: t('inc.sev.' + sevOf(sev)) }); }
|
||
function isIP(s) { s = String(s || ''); return /^\d{1,3}(\.\d{1,3}){3}$/.test(s) || (s.indexOf(':') > 0 && /^[0-9a-f:.]+$/i.test(s)); }
|
||
function tr(key, fallback) { var v = t(key); return v === key ? fallback : v; }
|
||
function tagChips(list, cls) { return (Array.isArray(list) ? list : []).map(function (x) { return el('span', { class: 'chip ' + (cls || '') }, String(x)); }); }
|
||
function when(ts) { return el('time', { title: ts ? U.fmt.date(ts) : '' }, ts ? U.fmt.ago(ts) : '-'); }
|
||
function getAuthor() {
|
||
var v = '';
|
||
try { v = (localStorage.getItem(AUTHOR_KEY) || '').trim(); } catch (e) { /* storage blocked */ }
|
||
return v.slice(0, 64);
|
||
}
|
||
function setAuthor(v) { try { localStorage.setItem(AUTHOR_KEY, String(v || '').trim().slice(0, 64)); } catch (e) { /* storage blocked */ } }
|
||
function authorName() { return getAuthor() || 'operator'; }
|
||
function field(label, control, hint, id) {
|
||
return el('div', { class: 'inc-field' }, el('label', { for: id }, label), control, hint ? el('span', { class: 'inc-hint' }, hint) : null);
|
||
}
|
||
function selectOf(id, values, labelFn, cur) {
|
||
var s = el('select', { id: id });
|
||
values.forEach(function (v) { var o = el('option', { value: v }, labelFn(v)); if (v === cur) o.selected = true; s.appendChild(o); });
|
||
return s;
|
||
}
|
||
function parseTags(s) {
|
||
var out = [];
|
||
String(s || '').split(',').forEach(function (x) { x = x.trim().slice(0, 40); if (x && out.indexOf(x) < 0) out.push(x); });
|
||
return out.slice(0, 20);
|
||
}
|
||
function sameList(a, b) { return JSON.stringify(a || []) === JSON.stringify(b || []); }
|
||
|
||
// open + investigating counter in the rail
|
||
function pollBadge() {
|
||
if (document.hidden) return;
|
||
U.api('/api/v1/incidents', { status: 'open,investigating', per_page: 1 }).then(function (r) {
|
||
var c = (r && r.counts) || {};
|
||
var n = (c.open || 0) + (c.investigating || 0);
|
||
U.setNavBadge('incidents', n, n ? t('inc.nav.open', { n: nf(n) }) : '');
|
||
}, function () { /* the page itself shows its errors */ });
|
||
}
|
||
|
||
// ------------------------------------------------------------ list
|
||
function listView(host) {
|
||
var seq = 0, on = true, timer = 0;
|
||
var results = el('div', { class: 'inc-results', 'aria-live': 'polite', 'aria-busy': 'false' });
|
||
var tabsBox = el('div', { class: 'inc-tabs', role: 'group', 'aria-label': t('inc.tabs') });
|
||
var counts = null;
|
||
|
||
function cur() {
|
||
var s = U.param('s') || U.param('status') || 'active';
|
||
return { s: s === 'active' || s === 'all' || STATUSES.indexOf(s) >= 0 ? s : 'active', sev: pick(SEVS, U.param('sev'), ''), q: (U.param('q') || '').slice(0, 200), sort: pick(SORTS, U.param('sort'), 'updated'), p: U.pageParam() };
|
||
}
|
||
function query(f) {
|
||
var p = { per_page: PER_PAGE, page: f.p, sort: f.sort };
|
||
if (f.s === 'active') p.status = 'open,investigating';
|
||
else if (f.s !== 'all') p.status = f.s;
|
||
if (f.sev) p.severity = f.sev;
|
||
if (f.q) p.q = f.q;
|
||
if (ctx && ctx.host && ctx.host !== 'all') p.host = ctx.host;
|
||
return p;
|
||
}
|
||
var search = el('input', { type: 'search', class: 'inc-search', autocomplete: 'off', placeholder: t('inc.search') + ' /', 'aria-label': t('inc.search') });
|
||
search.value = cur().q;
|
||
var sevSel = el('select', { 'aria-label': t('inc.f.severity') });
|
||
sevSel.appendChild(el('option', { value: '' }, t('inc.sev.all')));
|
||
SEVS.forEach(function (s) { sevSel.appendChild(el('option', { value: s }, t('inc.sev.' + s))); });
|
||
sevSel.value = cur().sev;
|
||
var sortSel = el('select', { 'aria-label': t('inc.sort') });
|
||
SORTS.forEach(function (s) { sortSel.appendChild(el('option', { value: s }, t('inc.sort.' + s))); });
|
||
sortSel.value = cur().sort;
|
||
var newBtn = el('button', { type: 'button', class: 'btn primary' }, t('inc.new'));
|
||
newBtn.addEventListener('click', function () { newDialog(); });
|
||
|
||
function reload() { U.setParam('p', ''); load(); }
|
||
search.addEventListener('input', function () {
|
||
clearTimeout(timer);
|
||
timer = setTimeout(function () { U.setParam('q', search.value.trim()); reload(); }, 300);
|
||
});
|
||
sevSel.addEventListener('change', function () { U.setParam('sev', sevSel.value); reload(); });
|
||
sortSel.addEventListener('change', function () { U.setParam('sort', sortSel.value === 'updated' ? '' : sortSel.value); reload(); });
|
||
|
||
function slash(e) {
|
||
if (e.key !== '/' || e.ctrlKey || e.metaKey || e.altKey) return;
|
||
var a = document.activeElement, tag = a && a.tagName;
|
||
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT' || (a && a.isContentEditable) || document.querySelector('dialog[open]')) return;
|
||
e.preventDefault(); search.focus();
|
||
}
|
||
document.addEventListener('keydown', slash);
|
||
search.setAttribute('aria-keyshortcuts', '/');
|
||
var info = el('span', { class: 'inc-info', tabindex: '0', role: 'img', title: t('inc.lead'), 'aria-label': t('inc.lead') }, 'ⓘ');
|
||
host.appendChild(el('div', { class: 'inc-bar' }, el('div', { class: 'inc-tabwrap' }, info, tabsBox), el('div', { class: 'inc-toolbar' }, search, sevSel, sortSel, newBtn)));
|
||
host.appendChild(results);
|
||
|
||
function paintTabs(f) {
|
||
clear(tabsBox);
|
||
var c = counts || {}, total = 0;
|
||
STATUSES.forEach(function (s) { total += c[s] || 0; });
|
||
var items = [['active', t('inc.tab.active'), (c.open || 0) + (c.investigating || 0)], ['all', t('inc.tab.all'), total], null]
|
||
.concat(STATUSES.map(function (s) { return [s, t('inc.status.' + s), c[s] || 0]; }));
|
||
items.forEach(function (it) {
|
||
if (!it) { tabsBox.appendChild(el('span', { class: 'inc-tab-sep', 'aria-hidden': 'true' })); return; }
|
||
var b = el('button', { type: 'button', class: 'inc-tab' + (f.s === it[0] ? ' on' : '') + (counts && !it[2] ? ' zero' : ''), 'aria-pressed': f.s === it[0] ? 'true' : 'false' },
|
||
el('span', null, it[1]), counts ? el('span', { class: 'inc-n num' }, nf(it[2])) : null);
|
||
b.addEventListener('click', function () { U.setParam('s', it[0] === 'active' ? '' : it[0]); reload(); });
|
||
tabsBox.appendChild(b);
|
||
});
|
||
}
|
||
function row(it) {
|
||
var sev = sevOf(it.severity), q = splitId(it);
|
||
var dst = it.dst ? it.dst + (it.dport ? ':' + it.dport : '') : '';
|
||
// egress tickets: pattern as the headline, workload -> destination in the meta line (the auto title repeats both and gets cut)
|
||
var auto = it.source === 'egress' && it.kind && it.workload;
|
||
var head = auto ? tr('eg.kind.' + it.kind, String(it.kind)) : String(it.title || q.full);
|
||
var meta = el('span', { class: 'inc-rmeta' }, el('span', { class: 'mono inc-rid' }, q.full));
|
||
function add(node) { meta.appendChild(el('span', { class: 'inc-sep', 'aria-hidden': 'true' }, '·')); meta.appendChild(node); }
|
||
if (auto) add(el('span', { class: 'mono inc-trunc', title: String(it.workload) + (dst ? ' → ' + dst : '') }, String(it.workload) + (dst ? ' → ' + dst : '')));
|
||
else if (dst) add(el('span', { class: 'mono inc-trunc' }, dst));
|
||
(Array.isArray(it.tags) ? it.tags.slice(0, 2) : []).forEach(function (g) { add(el('span', { class: 'inc-tag' }, String(g))); });
|
||
if (it.suppress) add(el('span', { class: 'inc-tag inc-supl', title: it.suppress_until ? t('inc.sup.until.short', { date: U.fmt.date(it.suppress_until) }) : '' }, t('eg.suppressed.chip')));
|
||
if (it.comment_count) add(el('span', { class: 'inc-cc', title: t(it.comment_count === 1 ? 'inc.comments.n.one' : 'inc.comments.n.other', { n: nf(it.comment_count) }) }, nf(it.comment_count)));
|
||
return el('a', { class: 'inc-row inc-s-' + sev, href: U.href('incidents', idSegs(it)), title: String(it.title || q.full) },
|
||
el('span', { class: 'inc-c-sev' }, el('span', { class: 'inc-sev inc-sev-' + sev }, t('inc.sev.' + sev))),
|
||
el('span', { class: 'inc-main' }, el('strong', { class: 'inc-title' }, head), meta),
|
||
el('span', { class: 'inc-c-st' }, statusBadge(it.status)),
|
||
el('span', { class: 'inc-who' + (it.assignee ? '' : ' none') }, it.assignee ? String(it.assignee) : t('inc.unassigned')),
|
||
el('span', { class: 'inc-cnt num', title: t('inc.t.count') }, '×' + nf(it.count || 1)),
|
||
el('span', { class: 'inc-when' }, when(it.last_seen)));
|
||
}
|
||
function paint(r, f) {
|
||
clear(results);
|
||
var items = Array.isArray(r.items) ? r.items : [];
|
||
var box = el('div', { class: 'inc-table' });
|
||
results.appendChild(box);
|
||
if (!items.length) {
|
||
var c = counts || {}, total = 0;
|
||
STATUSES.forEach(function (s) { total += c[s] || 0; });
|
||
var e = el('div', { class: 'inc-empty' }, el('strong', null, t('inc.list.empty')), el('span', { class: 'inc-hint' }, t('inc.list.empty.sub')));
|
||
if (f.s === 'active' && total > 0) {
|
||
var all = el('button', { type: 'button', class: 'btn' }, t('inc.empty.all', { n: nf(total) }));
|
||
all.addEventListener('click', function () { U.setParam('s', 'all'); reload(); });
|
||
e.appendChild(all);
|
||
}
|
||
box.appendChild(e);
|
||
return;
|
||
}
|
||
box.appendChild(el('div', { class: 'inc-thead', 'aria-hidden': 'true' }, el('span', null, t('inc.f.severity')), el('span', null, t('inc.col.title')), el('span', null, t('inc.col.status')),
|
||
el('span', null, t('inc.col.assignee')), el('span', { class: 'r' }, t('inc.col.count')), el('span', { class: 'r' }, t('inc.col.seen'))));
|
||
items.forEach(function (it) { box.appendChild(row(it)); });
|
||
var total2 = r.total || items.length, pages = Math.max(1, Math.ceil(total2 / PER_PAGE));
|
||
var pg = U.ui.pager({ page: f.p, pages: pages, total: total2, onPage: function (n) { U.setParam('p', n); load(); window.scrollTo(0, 0); } });
|
||
if (pg) results.appendChild(pg);
|
||
}
|
||
function load() {
|
||
var my = ++seq, f = cur();
|
||
paintTabs(f);
|
||
if (!results.firstChild) results.appendChild(el('div', { class: 'skeleton', style: { height: '8rem' } }));
|
||
U.api('/api/v1/incidents', query(f)).then(function (r) {
|
||
if (!on || my !== seq) return;
|
||
counts = r.counts || {};
|
||
paintTabs(f);
|
||
paint(r, f);
|
||
var n = (counts.open || 0) + (counts.investigating || 0);
|
||
U.setNavBadge('incidents', n, n ? t('inc.nav.open', { n: nf(n) }) : '');
|
||
}, function () {
|
||
if (!on || my !== seq) return;
|
||
clear(results);
|
||
var b = el('button', { type: 'button', class: 'btn' }, t('inc.retry'));
|
||
b.addEventListener('click', load);
|
||
results.appendChild(el('div', { class: 'state-error' }, el('strong', null, t('inc.list.err')), b));
|
||
});
|
||
}
|
||
load();
|
||
return { refresh: load, update: load, destroy: function () { on = false; seq++; clearTimeout(timer); document.removeEventListener('keydown', slash); } };
|
||
}
|
||
|
||
// ------------------------------------------------------------ new ticket dialog
|
||
function newDialog() {
|
||
var prev = document.activeElement;
|
||
var dlg = el('dialog', { class: 'unban-dlg inc-dlg', 'aria-labelledby': 'inc-new-h', 'aria-describedby': 'inc-new-p' });
|
||
var err = el('p', { class: 'unban-err', role: 'alert', hidden: true });
|
||
var title = el('input', { type: 'text', id: 'inc-n-title', maxlength: '200', required: true });
|
||
var detail = el('textarea', { id: 'inc-n-detail', rows: '4', maxlength: '4000' });
|
||
var sev = selectOf('inc-n-sev', SEVS, function (s) { return t('inc.sev.' + s); }, 'medium');
|
||
var hostIn = el('input', { type: 'text', id: 'inc-n-host', maxlength: '100' });
|
||
if (ctx && ctx.host && ctx.host !== 'all') hostIn.value = ctx.host;
|
||
var tg = el('input', { type: 'text', id: 'inc-n-tags', maxlength: '300' });
|
||
var who = el('input', { type: 'text', id: 'inc-n-who', maxlength: '64', placeholder: 'operator' });
|
||
who.value = getAuthor();
|
||
var ok = el('button', { type: 'button', class: 'btn primary' }, t('inc.new.create'));
|
||
var cancel = el('button', { type: 'button', class: 'btn' }, t('inc.cancel'));
|
||
dlg.appendChild(el('h2', { id: 'inc-new-h' }, t('inc.new.title')));
|
||
dlg.appendChild(el('p', { id: 'inc-new-p' }, t('inc.new.explain')));
|
||
dlg.appendChild(el('div', { class: 'inc-form' },
|
||
field(t('inc.f.title'), title, null, 'inc-n-title'),
|
||
field(t('inc.f.detail'), detail, null, 'inc-n-detail'),
|
||
field(t('inc.f.severity'), sev, null, 'inc-n-sev'),
|
||
field(t('inc.f.host'), hostIn, null, 'inc-n-host'),
|
||
field(t('inc.f.tags'), tg, t('inc.f.tags.hint'), 'inc-n-tags'),
|
||
field(t('inc.author'), who, t('inc.author.hint'), 'inc-n-who')));
|
||
dlg.appendChild(err);
|
||
dlg.appendChild(el('div', { class: 'unban-btns' }, cancel, ok));
|
||
function close() { dlg.close(); }
|
||
cancel.addEventListener('click', close);
|
||
dlg.addEventListener('close', function () {
|
||
if (dlg.parentNode) dlg.parentNode.removeChild(dlg);
|
||
if (prev && prev.focus && document.contains(prev)) prev.focus();
|
||
});
|
||
ok.addEventListener('click', function () {
|
||
var ttl = title.value.trim();
|
||
if (!ttl) { err.textContent = t('inc.required'); err.hidden = false; title.focus(); return; }
|
||
ok.disabled = true;
|
||
setAuthor(who.value);
|
||
U.apiSend('POST', '/api/v1/incidents', { title: ttl, detail: detail.value.trim(), severity: sev.value, host: hostIn.value.trim(), tags: parseTags(tg.value), author: authorName() }).then(function (r) {
|
||
close();
|
||
pollBadge();
|
||
if (r && r.id) location.hash = U.href('incidents', idSegs(r.host || !hostIn.value.trim() ? r : { id: r.id, host: hostIn.value.trim() })); else if (view && view.update) view.update();
|
||
}, function () {
|
||
ok.disabled = false;
|
||
err.textContent = t('inc.err.create');
|
||
err.hidden = false;
|
||
});
|
||
});
|
||
document.body.appendChild(dlg);
|
||
if (dlg.showModal) dlg.showModal(); else dlg.setAttribute('open', '');
|
||
title.focus();
|
||
}
|
||
|
||
// ------------------------------------------------------------ one ticket
|
||
function detailView(host, id, idHost) {
|
||
var seq = 0, on = true, tk = null, busy = false;
|
||
var box = el('div', { class: 'inc-detail' });
|
||
host.appendChild(el('nav', { class: 'inc-backnav', 'aria-label': t('inc.title') }, el('a', { class: 'inc-back', href: U.href('incidents') }, '← ' + t('inc.back'))));
|
||
host.appendChild(box);
|
||
var errBox = el('p', { class: 'inc-err', role: 'alert', hidden: true });
|
||
|
||
function url(suffix) { return '/api/v1/incidents/' + encodeURIComponent(id) + (suffix || '') + (idHost ? '?host=' + encodeURIComponent(idHost) : ''); }
|
||
function send(method, suffix, body, errKey, okKey) {
|
||
if (busy) return;
|
||
busy = true; box.classList.add('busy');
|
||
body.author = authorName();
|
||
errBox.hidden = true;
|
||
U.apiSend(method, url(suffix), body).then(function () {
|
||
busy = false; box.classList.remove('busy');
|
||
if (okKey) U.toast(t(okKey));
|
||
pollBadge();
|
||
load(true);
|
||
}, function (e) {
|
||
busy = false; box.classList.remove('busy');
|
||
errBox.textContent = t(e && e.status === 409 ? 'inc.err.suppress' : errKey);
|
||
errBox.hidden = false;
|
||
load(true); // put the controls back to the saved values
|
||
});
|
||
}
|
||
function patch(body) { send('PATCH', '', body, 'inc.err.save', 'inc.saved'); }
|
||
|
||
// ---- header
|
||
function header(x) {
|
||
var title = el('h1', { class: 'inc-h-title' });
|
||
function showTitle() {
|
||
clear(title);
|
||
var b = el('button', { type: 'button', class: 'inc-title-btn', title: t('inc.title.edit') }, String(x.title || x.id));
|
||
b.addEventListener('click', editTitle);
|
||
title.appendChild(b);
|
||
}
|
||
function editTitle() {
|
||
clear(title);
|
||
var inp = el('input', { type: 'text', class: 'inc-title-in', maxlength: '200', 'aria-label': t('inc.f.title') });
|
||
inp.value = String(x.title || '');
|
||
var done = false;
|
||
function finish(save) {
|
||
if (done) return; done = true;
|
||
var v = inp.value.trim();
|
||
if (save && v && v !== x.title) patch({ title: v }); else showTitle();
|
||
}
|
||
inp.addEventListener('keydown', function (e) { if (e.key === 'Enter') finish(true); else if (e.key === 'Escape') finish(false); });
|
||
inp.addEventListener('blur', function () { finish(true); });
|
||
title.appendChild(inp);
|
||
inp.focus(); inp.select();
|
||
}
|
||
showTitle();
|
||
function quick(label, status, tone) {
|
||
var b = el('button', { type: 'button', class: 'btn sm inc-q-' + tone }, label);
|
||
b.disabled = statusOf(x.status) === status;
|
||
b.addEventListener('click', function () {
|
||
var d = { status: status };
|
||
if (x.suppress && SUPPRESSIBLE.indexOf(status) < 0) d.suppress = false;
|
||
patch(d);
|
||
});
|
||
return b;
|
||
}
|
||
var q = el('div', { class: 'inc-quick', role: 'group', 'aria-label': t('inc.quick') },
|
||
quick(t('inc.quick.fp'), 'false_positive', 'fp'), quick(t('inc.quick.tp'), 'true_positive', 'tp'), quick(t('inc.quick.resolve'), 'resolved', 'ok'));
|
||
var q2 = splitId(x), sev = sevOf(x.severity);
|
||
var facts = el('p', { class: 'inc-facts' });
|
||
function fact(k, v) { if (facts.firstChild) facts.appendChild(el('span', { class: 'inc-sep', 'aria-hidden': 'true' }, '·')); facts.appendChild(el('span', null, el('span', { class: 'inc-fk' }, k + ' '), v)); }
|
||
fact(t('inc.t.created'), when(x.created_at));
|
||
fact(t('inc.t.last'), when(x.last_seen || x.updated_at));
|
||
fact(t('inc.t.count'), el('strong', { class: 'num' }, nf(x.count || 1)));
|
||
if (x.assignee) fact(t('inc.f.assignee'), el('strong', null, String(x.assignee)));
|
||
return el('header', { class: 'inc-head inc-s-' + sev },
|
||
el('div', { class: 'inc-crumb mono' }, q2.host ? el('span', null, q2.host) : null, q2.host ? el('span', { class: 'inc-sep', 'aria-hidden': 'true' }, '/') : null, el('span', null, q2.num)),
|
||
el('div', { class: 'inc-h1' }, title, q),
|
||
el('div', { class: 'inc-h2' }, el('span', { class: 'inc-sev inc-sev-' + sev }, t('inc.sev.' + sev)), statusBadge(x.status),
|
||
x.suppress ? el('span', { class: 'badge inc-supb' }, t('eg.suppressed.chip')) : null, tagChips(x.tags, 'inc-tag')),
|
||
facts);
|
||
}
|
||
|
||
// ---- properties (each control saves by itself)
|
||
function propsCard(x) {
|
||
function row(label, control, id) { return el('div', { class: 'inc-prop' }, el('label', { for: id }, label), el('div', { class: 'inc-prop-c' }, control)); }
|
||
var st = selectOf('inc-e-status', STATUSES, function (s) { return t('inc.status.' + s); }, statusOf(x.status));
|
||
var sev = selectOf('inc-e-sev', SEVS, function (s) { return t('inc.sev.' + s); }, sevOf(x.severity));
|
||
var asg = el('input', { type: 'text', id: 'inc-e-asg', maxlength: '64' });
|
||
asg.value = String(x.assignee || '');
|
||
var me = el('button', { type: 'button', class: 'inc-link' }, t('inc.assign.me'));
|
||
var tg = el('input', { type: 'text', id: 'inc-e-tags', maxlength: '300', 'aria-describedby': 'inc-e-tags-h' });
|
||
tg.value = (x.tags || []).join(', ');
|
||
var sup = el('input', { type: 'checkbox', id: 'inc-e-sup', role: 'switch', class: 'inc-switch', 'aria-describedby': 'inc-e-sup-h' });
|
||
sup.checked = !!x.suppress;
|
||
var hi = ['critical', 'high'];
|
||
var supWhy = x.source !== 'egress' ? 'inc.sup.only.egress' : (hi.indexOf(sevOf(x.severity)) >= 0 || hi.indexOf(String(x.max_severity || '')) >= 0) ? 'inc.sup.only.low' : SUPPRESSIBLE.indexOf(statusOf(x.status)) < 0 ? 'inc.f.suppress.off' : '';
|
||
sup.disabled = !x.suppress && !!supWhy;
|
||
st.addEventListener('change', function () {
|
||
var d = { status: st.value };
|
||
if (x.suppress && SUPPRESSIBLE.indexOf(st.value) < 0) d.suppress = false;
|
||
patch(d);
|
||
});
|
||
sev.addEventListener('change', function () { patch({ severity: sev.value }); });
|
||
function saveAsg() { var v = asg.value.trim(); if (v !== (x.assignee || '')) patch({ assignee: v }); }
|
||
asg.addEventListener('change', saveAsg);
|
||
asg.addEventListener('keydown', function (e) { if (e.key === 'Enter') { e.preventDefault(); asg.blur(); } });
|
||
me.addEventListener('click', function () { if (authorName() !== (x.assignee || '')) patch({ assignee: authorName() }); });
|
||
tg.addEventListener('change', function () { var l = parseTags(tg.value); if (!sameList(l, x.tags)) patch({ tags: l }); });
|
||
tg.addEventListener('keydown', function (e) { if (e.key === 'Enter') { e.preventDefault(); tg.blur(); } });
|
||
var days = el('select', { id: 'inc-e-days', 'aria-label': t('inc.sup.for') });
|
||
[7, 30, 90].forEach(function (d) { var o = el('option', { value: String(d) }, t('inc.sup.days', { n: d })); if (d === 30) o.selected = true; days.appendChild(o); });
|
||
sup.addEventListener('change', function () {
|
||
if (sup.checked) patch({ suppress: true, suppress_until: Math.floor(Date.now() / 1000) + Number(days.value) * 86400 });
|
||
else patch({ suppress: false });
|
||
});
|
||
var supState = x.suppress
|
||
? t('inc.sup.until', { date: x.suppress_until ? U.fmt.date(x.suppress_until) : '-', ago: x.suppressed_at ? U.fmt.ago(x.suppressed_at) : '-' })
|
||
: (supWhy ? t(supWhy) : t('inc.sup.what'));
|
||
var supHint = el('details', { class: 'inc-why' }, el('summary', null, t('inc.sup.more')), el('p', { class: 'inc-hint' }, t('inc.f.suppress.help')));
|
||
return el('section', { class: 'inc-card inc-props' }, el('h2', null, t('inc.props')),
|
||
row(t('inc.f.status'), st, 'inc-e-status'),
|
||
row(t('inc.f.severity'), sev, 'inc-e-sev'),
|
||
row(t('inc.f.assignee'), el('div', { class: 'inc-stack' }, asg, me), 'inc-e-asg'),
|
||
row(t('inc.f.tags'), el('div', { class: 'inc-stack' }, tg, el('span', { class: 'inc-hint', id: 'inc-e-tags-h' }, t('inc.f.tags.hint'))), 'inc-e-tags'),
|
||
errBox,
|
||
el('div', { class: 'inc-supbox' + (sup.disabled ? ' off' : '') + (x.suppress ? ' on' : '') },
|
||
el('div', { class: 'inc-sup-row' }, el('label', { for: 'inc-e-sup' }, t('inc.f.suppress')), sup),
|
||
el('p', { class: 'inc-hint', id: 'inc-e-sup-h' }, supState),
|
||
(!x.suppress && !sup.disabled) ? el('div', { class: 'inc-sup-row' }, el('label', { for: 'inc-e-days', class: 'inc-hint' }, t('inc.sup.for')), days) : null,
|
||
el('p', { class: 'inc-hint' }, t('inc.sup.reopen')),
|
||
supHint));
|
||
}
|
||
|
||
// ---- summary: conclusion + original detail
|
||
function summaryBlock(x) {
|
||
var node = el('section', { class: 'inc-card inc-summary' });
|
||
function render(edit) {
|
||
clear(node);
|
||
var has = !!(x.verdict || x.detail);
|
||
node.classList.toggle('empty', !has && !edit);
|
||
if (!has && !edit) {
|
||
var add = el('button', { type: 'button', class: 'btn sm' }, t('inc.concl.add'));
|
||
add.addEventListener('click', function () { render(true); });
|
||
node.appendChild(el('div', { class: 'inc-card-h' }, el('h2', null, t('inc.summary')), add));
|
||
node.appendChild(el('p', { class: 'inc-hint' }, t('inc.summary.none')));
|
||
return;
|
||
}
|
||
var head = el('div', { class: 'inc-card-h' }, el('h2', null, t('inc.summary')));
|
||
if (!edit) {
|
||
var eb = el('button', { type: 'button', class: 'btn sm' }, t('inc.edit.btn'));
|
||
eb.addEventListener('click', function () { render(true); });
|
||
head.appendChild(eb);
|
||
}
|
||
node.appendChild(head);
|
||
if (edit) {
|
||
var ta = el('textarea', { rows: '4', maxlength: '4000', 'aria-label': t('inc.f.verdict') });
|
||
ta.value = String(x.verdict || '');
|
||
var sv = el('button', { type: 'button', class: 'btn sm primary' }, t('inc.save.one'));
|
||
var cn = el('button', { type: 'button', class: 'btn sm' }, t('inc.cancel'));
|
||
sv.addEventListener('click', function () { var v = ta.value.trim(); if (v !== (x.verdict || '').trim()) patch({ verdict: v }); else render(false); });
|
||
cn.addEventListener('click', function () { render(false); });
|
||
node.appendChild(ta);
|
||
node.appendChild(el('div', { class: 'inc-btns' }, cn, sv));
|
||
setTimeout(function () { ta.focus(); }, 0);
|
||
} else if (x.verdict) node.appendChild(el('div', { class: 'inc-verdict' }, el('h3', null, t('inc.f.verdict')), el('p', { class: 'inc-text' }, String(x.verdict))));
|
||
if (x.detail) node.appendChild(el('div', { class: 'inc-evid' }, el('h3', null, t('inc.evidence')), el('pre', { class: 'inc-pre' }, String(x.detail))));
|
||
}
|
||
render(false);
|
||
return node;
|
||
}
|
||
|
||
// ---- activity
|
||
function histValue(f, v) {
|
||
if (v === undefined || v === null || v === '' || (Array.isArray(v) && !v.length)) return t('inc.h.empty');
|
||
if (f === 'status') return tr('inc.status.' + v, String(v));
|
||
if (f === 'severity') return tr('inc.sev.' + v, String(v));
|
||
if (f === 'suppress') return t(v === true || v === 'true' ? 'inc.h.on' : 'inc.h.off');
|
||
if (Array.isArray(v)) return v.join(', ');
|
||
return String(v);
|
||
}
|
||
function histLine(h) {
|
||
var f = String(h.field || '');
|
||
var li = el('li', { class: 'inc-ev' }, el('span', { class: 'inc-ev-dot', 'aria-hidden': 'true' }));
|
||
var body = el('span', { class: 'inc-ev-t' });
|
||
if (f === 'created') {
|
||
body.appendChild(document.createTextNode(t('inc.h.created', { who: String(h.author || '-'), sev: h.to === 'flood' ? t('inc.h.flood') : histValue('severity', h.to) })));
|
||
} else {
|
||
body.appendChild(document.createTextNode(t('inc.h.line', { who: String(h.author || '-'), field: tr('inc.h.field.' + f, f) }) + ' '));
|
||
body.appendChild(el('span', { class: 'inc-ev-chg' }, el('span', { class: 'inc-from' }, histValue(f, h.from)), ' → ', el('strong', null, histValue(f, h.to))));
|
||
}
|
||
li.appendChild(body);
|
||
li.appendChild(el('span', { class: 'inc-ev-when' }, when(h.at)));
|
||
return li;
|
||
}
|
||
function commentCard(c) {
|
||
var a = String(c.author || '-');
|
||
return el('li', { class: 'inc-cmt' },
|
||
el('span', { class: 'inc-av', 'aria-hidden': 'true' }, (a.trim().charAt(0) || '?').toUpperCase()),
|
||
el('div', { class: 'inc-cmt-b' },
|
||
el('div', { class: 'inc-c-h' }, el('strong', null, a), el('span', { class: 'inc-hint' }, when(c.at))),
|
||
el('p', { class: 'inc-text' }, String(c.text || ''))));
|
||
}
|
||
function composer() {
|
||
var ta = el('textarea', { id: 'inc-comment', rows: '2', maxlength: '4000', placeholder: t('inc.comment.ph'), 'aria-label': t('inc.comment.ph') });
|
||
var err = el('p', { class: 'inc-err', role: 'alert', hidden: true });
|
||
var add = el('button', { type: 'button', class: 'btn sm primary' }, t('inc.comment.add'));
|
||
var who = el('span', { class: 'inc-as' });
|
||
function paintWho() {
|
||
clear(who);
|
||
var b = el('button', { type: 'button', class: 'inc-link', title: t('inc.author.change'), 'aria-label': t('inc.author.change') }, '✎');
|
||
b.addEventListener('click', function () {
|
||
clear(who);
|
||
var inp = el('input', { type: 'text', class: 'inc-as-in', maxlength: '64', placeholder: 'operator', 'aria-label': t('inc.author') });
|
||
inp.value = getAuthor();
|
||
function fin() { setAuthor(inp.value); paintWho(); }
|
||
inp.addEventListener('keydown', function (e) { if (e.key === 'Enter' || e.key === 'Escape') { e.preventDefault(); fin(); } });
|
||
inp.addEventListener('blur', fin);
|
||
who.appendChild(inp); inp.focus();
|
||
});
|
||
who.appendChild(document.createTextNode(t('inc.commenting') + ' '));
|
||
who.appendChild(el('strong', null, authorName()));
|
||
who.appendChild(document.createTextNode(' '));
|
||
who.appendChild(b);
|
||
}
|
||
paintWho();
|
||
function submit() {
|
||
var txt = ta.value.trim();
|
||
if (!txt) { ta.focus(); return; }
|
||
send('POST', '/comments', { text: txt }, 'inc.err.comment', 'inc.comment.added');
|
||
}
|
||
add.addEventListener('click', submit);
|
||
ta.addEventListener('focus', function () { ta.rows = 4; });
|
||
ta.addEventListener('keydown', function (e) { if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) { e.preventDefault(); submit(); } });
|
||
return el('div', { class: 'inc-newc' }, ta, el('div', { class: 'inc-newc-f' }, who, el('span', { class: 'inc-hint inc-kbd' }, t('inc.comment.hint')), add));
|
||
}
|
||
function activity(x) {
|
||
var evs = [];
|
||
(x.comments || []).forEach(function (c) { evs.push({ at: c.at || 0, c: c }); });
|
||
(x.history || []).forEach(function (h) { evs.push({ at: h.at || 0, h: h }); });
|
||
evs.sort(function (a, b) { return b.at - a.at; });
|
||
var ul = el('ul', { class: 'inc-feed' });
|
||
for (var i = 0; i < evs.length; i++) {
|
||
var e = evs[i];
|
||
if (e.c) { ul.appendChild(commentCard(e.c)); continue; }
|
||
// consecutive changes by the same author in the same minute collapse into one expandable line
|
||
var grp = [e.h];
|
||
while (i + 1 < evs.length && evs[i + 1].h && evs[i + 1].h.author === e.h.author && String(evs[i + 1].h.field) !== 'created' && String(e.h.field) !== 'created' &&
|
||
Math.floor(evs[i + 1].at / 60) === Math.floor(e.at / 60)) { grp.push(evs[i + 1].h); i++; }
|
||
if (grp.length < 2) { ul.appendChild(histLine(e.h)); continue; }
|
||
var inner = el('ul', { class: 'inc-feed inc-sub' }, grp.map(histLine));
|
||
ul.appendChild(el('li', { class: 'inc-ev inc-grp' }, el('details', null,
|
||
el('summary', null, el('span', { class: 'inc-ev-dot', 'aria-hidden': 'true' }), t('inc.h.group', { who: String(e.h.author || '-'), n: grp.length }), ' ', el('span', { class: 'inc-ev-when' }, when(e.at))), inner)));
|
||
}
|
||
return el('section', { class: 'inc-card inc-activity', 'aria-label': t('inc.activity') }, el('div', { class: 'inc-card-h' }, el('h2', null, t('inc.activity')), el('span', { class: 'inc-hint' }, t('inc.comments.n.' + ((x.comments || []).length === 1 ? 'one' : 'other'), { n: nf((x.comments || []).length) }))),
|
||
composer(), evs.length ? ul : el('p', { class: 'inc-hint' }, t('inc.comments.none')));
|
||
}
|
||
|
||
// ---- technical data
|
||
function techRow(dl, k, v, cls) {
|
||
if (v === undefined || v === null || v === '') return;
|
||
dl.appendChild(el('dt', null, t(k)));
|
||
dl.appendChild(el('dd', { class: cls || '' }, v));
|
||
}
|
||
function techCard(x) {
|
||
var dl = el('dl', { class: 'inc-dl' });
|
||
var kind = String(x.kind || '');
|
||
techRow(dl, 'inc.t.source', tr('inc.source.' + x.source, String(x.source || '')));
|
||
techRow(dl, 'inc.t.kind', kind ? tr('eg.kind.' + kind, kind) : '');
|
||
techRow(dl, 'inc.t.workload', x.workload ? String(x.workload) : '', 'mono');
|
||
techRow(dl, 'inc.t.dst', x.dst ? (isIP(x.dst) ? el('a', { href: U.href('ip', [String(x.dst)]) }, String(x.dst)) : String(x.dst)) : '', 'mono');
|
||
techRow(dl, 'inc.t.port', x.dport ? String(x.dport) : '', 'mono');
|
||
techRow(dl, 'inc.t.proto', x.proto ? String(x.proto) : '', 'mono');
|
||
techRow(dl, 'inc.t.host', x.host ? String(x.host) : '');
|
||
techRow(dl, 'inc.t.first', x.first_seen ? when(x.first_seen) : '');
|
||
techRow(dl, 'inc.t.last', x.last_seen ? when(x.last_seen) : '');
|
||
techRow(dl, 'inc.t.count', x.count ? nf(x.count) : '');
|
||
if (x.key) {
|
||
var cp = el('button', { type: 'button', class: 'inc-link', 'aria-label': t('inc.copy') }, t('inc.copy'));
|
||
cp.addEventListener('click', function () {
|
||
try { navigator.clipboard.writeText(String(x.key)).then(function () { U.toast(t('inc.copied')); }, function () { }); } catch (e) { /* clipboard blocked */ }
|
||
});
|
||
dl.appendChild(el('dt', null, t('inc.t.key')));
|
||
dl.appendChild(el('dd', { class: 'inc-keyrow' }, el('span', { class: 'mono inc-key', title: String(x.key) }, String(x.key)), cp));
|
||
}
|
||
var d = el('details', { class: 'inc-card inc-tech' }, el('summary', null, t('inc.tech')), dl);
|
||
if (window.innerWidth > 900) d.open = true;
|
||
return d;
|
||
}
|
||
|
||
function paint() {
|
||
clear(box);
|
||
var x = tk;
|
||
box.appendChild(header(x));
|
||
var main = el('div', { class: 'inc-maincol' });
|
||
main.appendChild(summaryBlock(x));
|
||
main.appendChild(activity(x));
|
||
box.appendChild(el('div', { class: 'inc-layout' }, main, el('aside', { class: 'inc-aside' }, propsCard(x), techCard(x))));
|
||
}
|
||
function load(keepScroll) {
|
||
var my = ++seq;
|
||
var y = window.scrollY;
|
||
U.api(url()).then(function (r) {
|
||
if (!on || my !== seq) return;
|
||
tk = r; paint();
|
||
if (keepScroll) window.scrollTo(0, y);
|
||
}, function (e) {
|
||
if (!on || my !== seq) return;
|
||
clear(box);
|
||
if (e && e.status === 404) { box.appendChild(U.ui.empty(t('inc.notfound'), t('inc.notfound.sub'))); return; }
|
||
var b = el('button', { type: 'button', class: 'btn' }, t('inc.retry'));
|
||
b.addEventListener('click', function () { load(); });
|
||
box.appendChild(el('div', { class: 'state-error' }, el('strong', null, t('inc.list.err')), b));
|
||
});
|
||
}
|
||
box.appendChild(el('div', { class: 'skeleton', style: { height: '10rem' } }));
|
||
load();
|
||
return { refresh: null, update: function () { load(true); }, destroy: function () { on = false; seq++; } };
|
||
}
|
||
|
||
// ------------------------------------------------------------ page
|
||
function render() {
|
||
if (view) { view.destroy(); view = null; }
|
||
clear(root);
|
||
var seg = ctx && ctx.params && ctx.params.segments ? ctx.params.segments : [];
|
||
var id = seg[0] ? String(seg[0]).slice(0, 64) : '', idHost = '';
|
||
if (seg[1]) { idHost = id.slice(0, 64); id = String(seg[1]).slice(0, 64); }
|
||
else if (id.indexOf('/') > 0) { idHost = id.slice(0, id.lastIndexOf('/')); id = id.slice(id.lastIndexOf('/') + 1); }
|
||
view = id ? detailView(root, id, idHost) : listView(root);
|
||
}
|
||
|
||
U.registerPage({
|
||
id: 'incidents', group: 'investigate', titleKey: 'inc.title',
|
||
icon: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M4 5h16v11H9l-5 4z"/><path d="M12 8.5v3.5"/><path d="M12 14.2h.01"/></svg>',
|
||
mount: function (node, cx) { root = el('div', { class: 'inc-page' }); node.appendChild(root); ctx = cx; render(); },
|
||
update: function (cx) { ctx = cx; if (root) render(); },
|
||
refresh: function () { if (view && view.refresh) view.refresh(); },
|
||
unmount: function () { if (view) { view.destroy(); view = null; } if (root && root.parentNode) root.parentNode.removeChild(root); root = null; }
|
||
});
|
||
|
||
// the rail counter works from any page
|
||
pollBadge();
|
||
setInterval(function () { if (!document.hidden) pollBadge(); }, 30000);
|
||
return true;
|
||
}
|
||
|
||
if (!boot()) {
|
||
var tries = 0, iv = setInterval(function () { if (boot() || ++tries > 50) clearInterval(iv); }, 100);
|
||
}
|
||
})();
|