/* Urutau - page PROTOCOL ("Protocols and TLS"): HTTP version and TLS version by error class, cipher suites, unusual methods, http against https. Data: /api/v1/protocols. textContent only. */ (function () { 'use strict'; var U = window.Urutau; if (!U || !U.registerPage) return; var el = U.el, t = U.t; var CLS = ['ok', 'app', 'proxy', 'blocked', 'attack', 'bot', 'client']; var COLOR = { ok: '--ok', app: '--danger', proxy: '--warn', blocked: '--info', attack: '--cat-exploit', bot: '--viz-6', client: '--viz-5' }; var PROTO = ['http1', 'http2', 'http3', 'other']; var TLS = ['tls13', 'tls12', 'tls_old', 'none']; U.registerI18n({ en: { 'hl.pr.title': 'Protocols and TLS', 'hl.pr.lead': '{pct} of requests use HTTP/2 or newer over TLS 1.3', 'hl.pr.lead.body': '{plain} arrive over plain http {range}. Attack traffic leans on {atk}.', 'hl.pr.lead.empty': 'No protocol data yet', 'hl.pr.lead.empty.body': 'No Traefik requests with protocol fields {range}. Older log formats do not carry them.', 'hl.pr.proto': 'HTTP version by class', 'hl.pr.proto.hint': 'Share of each class per protocol. Scripts and scanners often speak HTTP/1.1 or 1.0.', 'hl.pr.tls': 'TLS version by class', 'hl.pr.tls.hint': 'Plain http and old TLS versions stand out here.', 'hl.pr.ciphers': 'Cipher suites', 'hl.pr.ciphers.hint': 'What clients negotiated.', 'hl.pr.methods': 'Methods', 'hl.pr.methods.hint': 'Methods outside GET, HEAD, POST, PUT, PATCH, DELETE and OPTIONS are marked.', 'hl.pr.scheme': 'http against https', 'hl.pr.scheme.hint': 'Requests that reached the proxy on each entry point.', 'hl.pr.odd': 'unusual', 'hl.pr.col.method': 'Method', 'hl.pr.col.n': 'Requests', 'hl.pr.col.errs': 'Errors', 'hl.pr.p.http1': 'HTTP/1.x', 'hl.pr.p.http2': 'HTTP/2', 'hl.pr.p.http3': 'HTTP/3', 'hl.pr.p.other': 'Other', 'hl.pr.t.tls13': 'TLS 1.3', 'hl.pr.t.tls12': 'TLS 1.2', 'hl.pr.t.tls_old': 'TLS 1.1 or older', 'hl.pr.t.none': 'No TLS (http)', 'hl.pr.s.https': 'https', 'hl.pr.s.http': 'http', 'hl.pr.c.ok': 'Succeeded', 'hl.pr.c.app': 'Application', 'hl.pr.c.proxy': 'Proxy', 'hl.pr.c.blocked': 'Blocked', 'hl.pr.c.attack': 'Attack', 'hl.pr.c.bot': 'Crawlers', 'hl.pr.c.client': 'Client', 'hl.pr.err': 'Could not load the protocol data.', 'hl.pr.retry': 'Try again', 'hl.pr.empty': 'Nothing to show for this range.' }, 'pt-BR': { 'hl.pr.title': 'Protocolos e TLS', 'hl.pr.lead': '{pct} das requisições usam HTTP/2 ou mais novo sobre TLS 1.3', 'hl.pr.lead.body': '{plain} chegam por http puro {range}. O tráfego de ataque se concentra em {atk}.', 'hl.pr.lead.empty': 'Ainda sem dados de protocolo', 'hl.pr.lead.empty.body': 'Nenhuma requisição do Traefik com campos de protocolo {range}. Formatos de log antigos não os trazem.', 'hl.pr.proto': 'Versão do HTTP por classe', 'hl.pr.proto.hint': 'Parcela de cada classe por protocolo. Scripts e varreduras costumam falar HTTP/1.1 ou 1.0.', 'hl.pr.tls': 'Versão do TLS por classe', 'hl.pr.tls.hint': 'Http puro e versões antigas de TLS aparecem aqui.', 'hl.pr.ciphers': 'Suítes de cifra', 'hl.pr.ciphers.hint': 'O que os clientes negociaram.', 'hl.pr.methods': 'Métodos', 'hl.pr.methods.hint': 'Métodos fora de GET, HEAD, POST, PUT, PATCH, DELETE e OPTIONS ficam marcados.', 'hl.pr.scheme': 'http contra https', 'hl.pr.scheme.hint': 'Requisições que chegaram ao proxy em cada entrada.', 'hl.pr.odd': 'incomum', 'hl.pr.col.method': 'Método', 'hl.pr.col.n': 'Requisições', 'hl.pr.col.errs': 'Erros', 'hl.pr.p.http1': 'HTTP/1.x', 'hl.pr.p.http2': 'HTTP/2', 'hl.pr.p.http3': 'HTTP/3', 'hl.pr.p.other': 'Outro', 'hl.pr.t.tls13': 'TLS 1.3', 'hl.pr.t.tls12': 'TLS 1.2', 'hl.pr.t.tls_old': 'TLS 1.1 ou anterior', 'hl.pr.t.none': 'Sem TLS (http)', 'hl.pr.s.https': 'https', 'hl.pr.s.http': 'http', 'hl.pr.c.ok': 'Sucesso', 'hl.pr.c.app': 'Aplicação', 'hl.pr.c.proxy': 'Proxy', 'hl.pr.c.blocked': 'Bloqueado', 'hl.pr.c.attack': 'Ataque', 'hl.pr.c.bot': 'Rastreadores', 'hl.pr.c.client': 'Cliente', 'hl.pr.err': 'Não foi possível carregar os dados de protocolo.', 'hl.pr.retry': 'Tentar de novo', 'hl.pr.empty': 'Nada para mostrar neste período.' } }); function clear(n) { while (n.firstChild) n.removeChild(n.firstChild); } function sum(o) { var n = 0; Object.keys(o || {}).forEach(function (k) { n += o[k]; }); return n; } // rows (one per protocol/version) of parts (one per class), each row scaled to 100% function stacked(rows, label, host) { var data = rows.map(function (r) { var tot = sum(r.c); return { key: r.k, label: label(r.k) + ' (' + U.fmt.num(tot) + ')', value: 100, parts: CLS.map(function (k) { return { label: t('hl.pr.c.' + k), value: tot ? (r.c[k] || 0) / tot * 100 : 0, color: COLOR[k] }; }) }; }); if (U.charts && U.charts.bars) host.appendChild(U.charts.bars(data, { horizontal: true, stacked: true, format: function () { return ''; }, title: '' })); else host.appendChild(U.ui.empty(t('hl.pr.empty'))); var lg = el('div', { class: 'hl-legend' }); CLS.forEach(function (k) { lg.appendChild(el('span', null, el('i', { style: { background: 'var(' + COLOR[k] + ')' } }), t('hl.pr.c.' + k))); }); host.appendChild(lg); } // a client class collapses its subtypes (the API already sums them under "client") function rowsOf(map, names) { return names.filter(function (k) { return map && map[k]; }).map(function (k) { return { k: k, c: map[k] }; }); } var inst = null; function create(root, ctx) { var seq = 0, alive = true, data = null, c = ctx; var grid = el('div', { class: 'grid-12 hl-page' }); var lead = el('div', { class: 'span-12' }); var pp = U.ui.panel({ title: t('hl.pr.proto'), hint: t('hl.pr.proto.hint'), variant: 'chart', loading: true, cls: 'span-6' }); var pt = U.ui.panel({ title: t('hl.pr.tls'), hint: t('hl.pr.tls.hint'), variant: 'chart', loading: true, cls: 'span-6' }); var ps = U.ui.panel({ title: t('hl.pr.scheme'), hint: t('hl.pr.scheme.hint'), loading: true, cls: 'span-4' }); var pc = U.ui.panel({ title: t('hl.pr.ciphers'), hint: t('hl.pr.ciphers.hint'), variant: 'chart', loading: true, cls: 'span-8' }); var pm = U.ui.panel({ title: t('hl.pr.methods'), hint: t('hl.pr.methods.hint'), loading: true, cls: 'span-12' }); [lead, pp, pt, ps, pc, pm].forEach(function (n) { grid.appendChild(n); }); root.appendChild(grid); function paint() { clear(lead); [pp, pt, ps, pc, pm].forEach(function (p) { clear(p.body); }); if (!data) return; var d = data, range = U.rangeLabel({ inline: true }); var protoTot = {}, total = 0; PROTO.forEach(function (k) { protoTot[k] = sum((d.protocols || {})[k]); total += protoTot[k]; }); if (!total) { lead.appendChild(U.ui.lead(t('hl.pr.lead.empty'), t('hl.pr.lead.empty.body', { range: range }), 'neutral')); [pp, pt, ps, pc, pm].forEach(function (p) { p.body.appendChild(U.ui.empty(t('hl.pr.empty'))); }); return; } var modern = ((d.tls || {}).tls13 ? sum(d.tls.tls13) : 0), h2 = protoTot.http2 + protoTot.http3; var plain = (d.scheme || {}).http || 0, https = (d.scheme || {}).https || 0; var atkP = PROTO.slice().sort(function (a, b) { return ((d.protocols[b] || {}).attack || 0) - ((d.protocols[a] || {}).attack || 0); })[0]; lead.appendChild(U.ui.lead(t('hl.pr.lead', { pct: U.fmt.pct(Math.min(modern, h2) / total) }), t('hl.pr.lead.body', { plain: U.fmt.pct(plain / Math.max(1, plain + https)), range: range, atk: t('hl.pr.p.' + atkP) }), plain > 0 ? 'warn' : 'neutral')); stacked(rowsOf(d.protocols, PROTO), function (k) { return t('hl.pr.p.' + k); }, pp.body); stacked(rowsOf(d.tls, TLS), function (k) { return t('hl.pr.t.' + k); }, pt.body); // http vs https if (U.charts && U.charts.donut) ps.body.appendChild(U.charts.donut([{ key: 'https', label: t('hl.pr.s.https'), value: https }, { key: 'http', label: t('hl.pr.s.http'), value: plain }], { title: t('hl.pr.scheme'), colors: ['--ok', '--warn'], centerLabel: t('hl.pr.col.n') })); var ci = (d.ciphers || []).slice(0, 12).map(function (x) { return { key: x.name, label: String(x.name).replace(/_/g, '_\u200b'), value: x.n }; }); if (ci.length && U.charts && U.charts.bars) pc.body.appendChild(U.charts.bars(ci, { horizontal: true, title: t('hl.pr.ciphers') })); else pc.body.appendChild(U.ui.empty(t('hl.pr.empty'))); var tb = el('tbody'); (d.methods || []).forEach(function (m) { var errs = sum(m.classes) - (m.classes.ok || 0); var brk = CLS.filter(function (k) { return m.classes[k]; }).map(function (k) { return t('hl.pr.c.' + k) + ' ' + U.fmt.num(m.classes[k]); }).join(' · '); // on phones the breakdown moves under the method (the 4th column is hidden) tb.appendChild(el('tr', null, el('td', { class: 'mono' }, m.method, m.odd ? U.ui.badge(t('hl.pr.odd'), 'warn') : null, el('div', { class: 'hl-brk-m' }, brk)), el('td', { class: 'num' }, U.fmt.num(m.n)), el('td', { class: 'num' }, U.fmt.num(errs)), el('td', { class: 'hl-brk' }, brk))); }); pm.body.appendChild(el('div', { class: 'hl-scroll' }, el('table', { class: 'hl-table' }, el('thead', null, el('tr', null, el('th', null, t('hl.pr.col.method')), el('th', { class: 'num' }, t('hl.pr.col.n')), el('th', { class: 'num' }, t('hl.pr.col.errs')), el('th', { class: 'hl-brk' }, ''))), tb))); } function load() { var my = ++seq; var p = Object.assign({}, U.rangeParams()); if (c.domain && c.domain !== 'all') p.host = c.domain; U.api('/api/v1/protocols', p).then(function (r) { if (alive && my === seq) { data = r; paint(); } }, function () { if (!alive || my !== seq || data) return; clear(lead); var b = el('button', { type: 'button', class: 'btn' }, t('hl.pr.retry')); b.addEventListener('click', load); lead.appendChild(el('div', { class: 'state-error' }, el('strong', null, t('hl.pr.err')), b)); }); } load(); return { update: function (cx) { c = cx; load(); }, destroy: function () { alive = false; seq++; clear(root); } }; } U.registerPage({ id: 'protocol', group: 'analyze', titleKey: 'hl.pr.title', icon: '', mount: function (node, ctx) { if (inst) inst.destroy(); inst = create(node, ctx || {}); }, update: function (ctx) { if (inst) inst.update(ctx); }, unmount: function () { if (inst) { inst.destroy(); inst = null; } } }); })();