/** * Spec 037-DNS-VIEWER — painel DNS unificado (Desk) * Depende de: auth.js (api, esc) */ (function () { function dnsPurposeLabel(purpose) { return { mx: 'MX', spf: 'SPF', dkim: 'DKIM', dmarc: 'DMARC', 'mail-host': 'Mail host', autodiscover: 'Autodiscover', 'mail-alias': 'Alias', other: 'Outro', }[purpose] || purpose || '—'; } function sourceLabel(source) { return { cf_ligbox: 'CF Ligbox', cf_byo: 'CF cliente', public_resolver: 'Público', planned_ligbox: 'Planeado', openpanel_bind: 'OpenPanel', }[source] || source || '—'; } function checkIcon(c) { if (!c) return '—'; if (c.ok) return '✅'; if (c.warn) return '⚠'; return '❌'; } async function fetchDnsViewer(domain, emailService) { const q = new URLSearchParams(); if (emailService != null) q.set('email_service', emailService ? 'true' : 'false'); const qs = q.toString(); return api(`/v1/dns/viewer/${encodeURIComponent(domain)}${qs ? `?${qs}` : ''}`); } async function fetchDomainDns(domain, emailService) { try { const viewer = await fetchDnsViewer(domain, emailService); if (viewer && viewer.domain) return { ...viewer, _viewer: true }; } catch (e) { if (e?.status === 404) { /* DNS_VIEWER_ENABLED=0 — legado */ } else if (e?.status !== 403) { console.warn('DnsViewer fallback:', e?.message || e); } } try { const legacy = await api( `/v1/dns/cloudflare/records?domain=${encodeURIComponent(domain)}&email_service=${emailService ? 'true' : 'false'}` ); return legacy; } catch (e) { return { domain, records: [], email_records: [], summary: { total: 0, email_related: 0 }, error: e.message || 'Falha ao carregar DNS', }; } } function publicChecksRow(checks) { if (!checks || !Object.keys(checks).length) return ''; const parts = ['mx', 'spf', 'dkim', 'dmarc'].map( (k) => `${k.toUpperCase()} ${checkIcon(checks[k])}` ); return `
`; } function nsRow(data) { const ns = data.nameservers || {}; const current = ns.current_public || []; if (!current.length) return ''; const match = ns.match_ligbox; const warn = data.display_mode === 'planned' || (data.dns_mode?.startsWith('ligbox_cf') && !match); return ``; } function recordRows(records, compact) { return (records || []).map((r) => { const src = r.source ? `${esc(sourceLabel(r.source))}` : ''; const state = r.status === 'planned' ? ' planeado' : ''; if (compact) { return `${esc(r.name)}${esc(r.name)}Dados DNS indisponíveis.
' : `Dados DNS indisponíveis.
| Função | Nome | Tipo | Conteúdo | ${compact ? '' : 'Origem | '}
|---|---|---|---|---|
| — | ||||
| Função | Nome | Tipo | Conteúdo | ${compact ? '' : 'Origem | '}
|---|---|---|---|---|
| Sem registos para este domínio. | ||||
${esc(data.errors.join(' · '))}
` : ''}`; if (compact) return inner; return `${esc(dns.error)}
`; } const rows = recordRows(dns.records, true); const summary = dns.summary || {}; return `| Função | Nome | Tipo | Conteúdo |
|---|---|---|---|
| Sem registos. | |||