()
| 11402 | |
| 11403 | async function runSrMplsWatch() { |
| 11404 | const out = document.getElementById('srmpls-results'); |
| 11405 | if (!out) return; |
| 11406 | const btn = (typeof event !== 'undefined' && event && event.target) ? event.target : null; |
| 11407 | const ifaceSel = document.getElementById('srmpls-iface'); |
| 11408 | const iface = ifaceSel && ifaceSel.value ? ifaceSel.value : ''; |
| 11409 | const secsEl = document.getElementById('srmpls-secs'); |
| 11410 | const secs = secsEl && secsEl.value ? secsEl.value : '20'; |
| 11411 | const roleEl = document.getElementById('srmpls-role'); |
| 11412 | const role = roleEl && roleEl.value ? roleEl.value : 'unknown'; |
| 11413 | _ndBusy(btn, true, 'Listening…'); |
| 11414 | out.classList.remove('hidden'); |
| 11415 | out.innerHTML = '<p class="text-sm text-gray-400">Passively capturing MPLS / SR-MPLS / SRv6 + SR control plane…</p>'; |
| 11416 | try { |
| 11417 | _fillIfaceSel('srmpls-iface'); |
| 11418 | const qs = '?seconds=' + encodeURIComponent(secs) + |
| 11419 | (iface ? '&interface=' + encodeURIComponent(iface) : '') + |
| 11420 | '&role=' + encodeURIComponent(role); |
| 11421 | const d = await fetchAPI('/api/net/srmpls-watch' + qs); |
| 11422 | if (!d || d.success === false) { |
| 11423 | const msg = (d && d.error) || 'failed'; |
| 11424 | let extra = ''; |
| 11425 | if (d && d.missing_tool) extra = ' <button onclick="installNetTool(\'tcpdump\', this, runSrMplsWatch)" class="ml-2 underline text-cyan-400">Install tcpdump</button>'; |
| 11426 | out.innerHTML = '<p class="text-sm text-red-400">Error: ' + escapeHtml(msg) + extra + '</p>'; |
| 11427 | return; |
| 11428 | } |
| 11429 | const [cls, label] = _SRM_VERDICT_STYLE[d.verdict] || _SRM_VERDICT_STYLE.unknown; |
| 11430 | const st = d.stats || {}; |
| 11431 | let html = `<div class="mb-2 px-3 py-2 rounded border ${cls} text-sm">${label}</div>`; |
| 11432 | html += `<p class="text-xs text-gray-500 mb-2">Interface: ${escapeHtml(d.interface || '—')} · ${d.seconds}s · role: <span class="font-mono">${escapeHtml(d.role || 'unknown')}</span> · frames: ${st.frames || 0}${st.mpls_frames ? ', MPLS: ' + st.mpls_frames : ''}${st.srh_frames ? ', SRH: ' + st.srh_frames : ''}</p>`; |
| 11433 | const findings = (d.findings || []).filter(f => ['critical', 'high', 'medium'].includes(f.severity)); |
| 11434 | if (findings.length) { |
| 11435 | html += '<table class="min-w-full text-xs text-gray-300 whitespace-nowrap"><thead>' + |
| 11436 | '<tr class="text-left text-gray-500"><th class="px-2 py-1">Sev</th><th class="px-2 py-1">Code</th><th class="px-2 py-1">Class</th><th class="px-2 py-1">Key</th></tr>' + |
| 11437 | '</thead><tbody>' + |
| 11438 | findings.slice(0, 40).map(f => `<tr class="border-t border-slate-800"> |
| 11439 | <td class="px-2 py-1 ${_SRM_SEV_STYLE[f.severity] || 'text-gray-400'}">${escapeHtml(f.severity)}</td> |
| 11440 | <td class="px-2 py-1 font-mono ${_SRM_SEV_STYLE[f.severity] || 'text-gray-300'}">${escapeHtml((f.code || '').replace(/^SRM-/, ''))}</td> |
| 11441 | <td class="px-2 py-1 text-gray-500">${escapeHtml(f.class || '')}</td> |
| 11442 | <td class="px-2 py-1 font-mono text-gray-400">${escapeHtml(f.key || '-')}</td> |
| 11443 | </tr>`).join('') + |
| 11444 | '</tbody></table>'; |
| 11445 | } |
| 11446 | if (d.reasons && d.reasons.length) { |
| 11447 | html += '<ul class="text-xs text-gray-400 mt-2 list-disc pl-5">' + |
| 11448 | d.reasons.map(r => '<li>' + escapeHtml(r) + '</li>').join('') + '</ul>'; |
| 11449 | } |
| 11450 | out.innerHTML = html; |
| 11451 | } catch (e) { |
nothing calls this directly
no test coverage detected