Ajuste peticiones API y paginacion
This commit is contained in:
1 parent
6221817400
commit
5487b994c1
5 files changed
+741
-53
No files matched your search
+508
@@ -0,0 +1,508 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="es" class="h-full bg-slate-950 text-slate-100">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Portal de Seguridad Harbor - Inspector de Vulnerabilidades y SBOM</title>
|
||||
<script src="assets/js/tailwindcss.js"></script>
|
||||
<link rel="stylesheet" href="assets/css/fontawesome.all.min.css">
|
||||
<script>
|
||||
tailwind.config = {
|
||||
theme: {
|
||||
extend: {
|
||||
fontFamily: { sans: ['system-ui', '-apple-system', 'sans-serif'], mono: ['ui-monospace', 'monospace'] },
|
||||
colors: { harbor: { bg: '#0F172A', card: '#1E293B', border: '#334155', accent: '#0EA5E9' } }
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body class="h-full font-sans antialiased bg-slate-950 text-slate-200 flex flex-col">
|
||||
|
||||
<header class="bg-slate-900 border-b border-slate-800 px-6 py-4 flex flex-wrap items-center justify-between gap-4 sticky top-0 z-30 shadow-lg">
|
||||
<div class="flex items-center space-x-4">
|
||||
<div class="bg-sky-500/10 p-2.5 rounded-lg border border-sky-500/20 text-sky-400">
|
||||
<i class="fa-solid fa-shield-halved text-2xl"></i>
|
||||
</div>
|
||||
<div>
|
||||
<h1 class="text-xl font-bold tracking-tight text-white flex items-center gap-2">
|
||||
Portal de Seguridad Harbor
|
||||
<span class="text-xs font-normal px-2.5 py-0.5 rounded-full bg-sky-500/10 text-sky-400 border border-sky-500/20">API v2.0 Live</span>
|
||||
</h1>
|
||||
<p class="text-xs text-slate-400">Inspector Centralizado de Vulnerabilidades vía API</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center space-x-3">
|
||||
<div id="connection-badge" class="flex items-center space-x-2 bg-amber-500/10 border border-amber-500/20 text-amber-400 px-3 py-1.5 rounded-md text-xs font-medium">
|
||||
<span id="connection-dot" class="w-2 h-2 rounded-full bg-amber-400 animate-pulse"></span>
|
||||
<span id="connection-status-text">Sin Autenticar</span>
|
||||
</div>
|
||||
|
||||
<!-- Botón de Exportar a Excel (CSV) -->
|
||||
<button onclick="exportToCsv()" class="flex items-center space-x-2 bg-slate-800 hover:bg-slate-700 text-slate-200 border border-slate-700 px-3.5 py-2 rounded-lg text-sm font-medium transition">
|
||||
<i class="fa-solid fa-file-excel text-emerald-400"></i>
|
||||
<span>Exportar Excel</span>
|
||||
</button>
|
||||
|
||||
<button onclick="openConfigModal()" class="flex items-center space-x-2 bg-slate-800 hover:bg-slate-700 text-slate-200 border border-slate-700 px-3.5 py-2 rounded-lg text-sm font-medium transition">
|
||||
<i class="fa-solid fa-key text-sky-400"></i>
|
||||
<span>Credenciales</span>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="flex-1 w-full px-4 sm:px-6 lg:px-8 py-6 space-y-6">
|
||||
<!-- Métricas Globales (Summary) -->
|
||||
<div class="grid grid-cols-2 md:grid-cols-5 gap-4">
|
||||
<div class="bg-slate-900 border border-slate-800 p-4 rounded-xl flex items-center justify-between">
|
||||
<div><p class="text-xs text-slate-400 uppercase font-semibold">Total CVEs</p><p id="count-total" class="text-2xl font-bold text-white mt-1">0</p></div>
|
||||
<div class="p-3 bg-slate-800 rounded-lg text-slate-400"><i class="fa-solid fa-bug text-xl"></i></div>
|
||||
</div>
|
||||
<div class="bg-slate-900 border border-red-500/20 p-4 rounded-xl flex items-center justify-between">
|
||||
<div><p class="text-xs text-red-400 uppercase font-semibold">Críticas</p><p id="count-critical" class="text-2xl font-bold text-red-400 mt-1">0</p></div>
|
||||
<div class="p-3 bg-red-500/10 rounded-lg text-red-400"><i class="fa-solid fa-triangle-exclamation text-xl"></i></div>
|
||||
</div>
|
||||
<div class="bg-slate-900 border border-orange-500/20 p-4 rounded-xl flex items-center justify-between">
|
||||
<div><p class="text-xs text-orange-400 uppercase font-semibold">Altas</p><p id="count-high" class="text-2xl font-bold text-orange-400 mt-1">0</p></div>
|
||||
<div class="p-3 bg-orange-500/10 rounded-lg text-orange-400"><i class="fa-solid fa-radiation text-xl"></i></div>
|
||||
</div>
|
||||
<div class="bg-slate-900 border border-yellow-500/20 p-4 rounded-xl flex items-center justify-between">
|
||||
<div><p class="text-xs text-yellow-400 uppercase font-semibold">Medias</p><p id="count-medium" class="text-2xl font-bold text-yellow-400 mt-1">0</p></div>
|
||||
<div class="p-3 bg-yellow-500/10 rounded-lg text-yellow-400"><i class="fa-solid fa-circle-exclamation text-xl"></i></div>
|
||||
</div>
|
||||
<div class="bg-slate-900 border border-blue-500/20 p-4 rounded-xl flex items-center justify-between col-span-2 md:col-span-1">
|
||||
<div><p class="text-xs text-blue-400 uppercase font-semibold">Bajas</p><p id="count-low" class="text-2xl font-bold text-blue-400 mt-1">0</p></div>
|
||||
<div class="p-3 bg-blue-500/10 rounded-lg text-blue-400"><i class="fa-solid fa-circle-info text-xl"></i></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Panel de Filtros API -->
|
||||
<div class="bg-slate-900 border border-slate-800 rounded-xl p-5 shadow-sm space-y-4">
|
||||
<h2 class="text-lg font-semibold text-white flex items-center gap-2 border-b border-slate-800 pb-3">
|
||||
<i class="fa-solid fa-filter text-sky-400"></i> Búsqueda Directa en API de Harbor (/security/vul)
|
||||
</h2>
|
||||
|
||||
<div class="flex flex-col md:flex-row items-stretch md:items-center gap-4">
|
||||
<div class="w-full md:w-64 flex-shrink-0">
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1">Filter by</label>
|
||||
<select id="filter-type" onchange="onFilterTypeChange()" class="w-full bg-slate-800 border border-slate-700 text-slate-200 text-sm rounded-lg p-2.5 outline-none">
|
||||
<option value="All">All</option>
|
||||
<option value="Severity">Severity</option>
|
||||
<option value="CVE ID">CVE ID</option>
|
||||
<option value="CVSS3">CVSS3 (Rango)</option>
|
||||
<option value="Repository Name">Repository Name</option>
|
||||
<option value="Package">Package</option>
|
||||
<option value="Digest">Digest</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="flex-1" id="filter-input-container">
|
||||
<!-- Dinámico -->
|
||||
</div>
|
||||
|
||||
<div class="flex items-end gap-2 pt-5 md:pt-0">
|
||||
<button onclick="applyFilters(1)" class="bg-sky-500 hover:bg-sky-600 text-white font-semibold text-sm px-6 py-2.5 rounded-lg flex items-center gap-2 transition shadow-md">
|
||||
<i id="search-btn-icon" class="fa-solid fa-magnifying-glass"></i>
|
||||
<span>SEARCH API</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tabla -->
|
||||
<div class="bg-slate-900 border border-slate-800 rounded-xl overflow-hidden shadow-lg">
|
||||
<div class="p-4 border-b border-slate-800 flex flex-wrap justify-between items-center gap-4 bg-slate-900/50">
|
||||
<span class="text-sm font-medium text-slate-400">Registros en página actual: <span id="results-count" class="text-white font-bold">0</span></span>
|
||||
|
||||
<div class="flex items-center space-x-2 text-sm text-slate-400">
|
||||
<span>Mostrar:</span>
|
||||
<select id="page-size-select" onchange="changePageSize()" class="bg-slate-800 border border-slate-700 text-slate-200 text-xs rounded-lg px-2.5 py-1.5 outline-none font-semibold">
|
||||
<option value="10" selected>10</option>
|
||||
<option value="20">20</option>
|
||||
<option value="50">50</option>
|
||||
<option value="100">100</option>
|
||||
</select>
|
||||
<span>por página</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full text-left text-sm text-slate-300">
|
||||
<thead class="bg-slate-950 text-xs uppercase text-slate-400 font-semibold border-b border-slate-800">
|
||||
<tr>
|
||||
<th class="px-4 py-3.5">CVE ID</th>
|
||||
<th class="px-4 py-3.5">Severidad</th>
|
||||
<th class="px-4 py-3.5">Paquete Afectado</th>
|
||||
<th class="px-4 py-3.5">Proyecto</th>
|
||||
<th class="px-4 py-3.5">Repositorio</th>
|
||||
<th class="px-4 py-3.5">Tag / Digest</th>
|
||||
<th class="px-4 py-3.5 text-center">CVSS3</th>
|
||||
<th class="px-4 py-3.5 text-right">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="vulnerabilities-tbody" class="divide-y divide-slate-800/60"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div id="empty-state" class="py-16 text-center space-y-4">
|
||||
<div class="inline-flex items-center justify-center w-16 h-16 rounded-full bg-slate-800 text-slate-400 mb-2"><i class="fa-solid fa-magnifying-glass text-2xl"></i></div>
|
||||
<h3 class="text-lg font-medium text-slate-300">Realiza una búsqueda para consultar la API</h3>
|
||||
<p class="text-sm text-slate-500">Selecciona un filtro superior y pulsa SEARCH API.</p>
|
||||
</div>
|
||||
|
||||
<!-- Controles de Paginación -->
|
||||
<div class="p-4 border-t border-slate-800 flex items-center justify-between bg-slate-900/50">
|
||||
<span class="text-sm text-slate-400">
|
||||
Página <span id="current-page-label" class="text-white font-bold">1</span>
|
||||
</span>
|
||||
<div class="flex items-center space-x-2">
|
||||
<button onclick="changePage(-1)" id="prev-page-btn" class="bg-slate-800 hover:bg-slate-700 text-slate-300 border border-slate-700 px-3 py-1.5 rounded-lg text-xs font-medium transition disabled:opacity-50 disabled:cursor-not-allowed">
|
||||
<i class="fa-solid fa-chevron-left mr-1"></i> Anterior
|
||||
</button>
|
||||
<button onclick="changePage(1)" id="next-page-btn" class="bg-slate-800 hover:bg-slate-700 text-slate-300 border border-slate-700 px-3 py-1.5 rounded-lg text-xs font-medium transition">
|
||||
Siguiente <i class="fa-solid fa-chevron-right ml-1"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- Modal Config (Conectar) -->
|
||||
<div id="config-modal" class="fixed inset-0 z-50 bg-slate-950/80 backdrop-blur-sm hidden flex items-center justify-center p-4">
|
||||
<div class="bg-slate-900 border border-slate-800 rounded-xl w-full max-w-lg shadow-2xl p-6 space-y-5">
|
||||
<h3 class="text-lg font-bold text-white flex items-center gap-2"><i class="fa-solid fa-key text-sky-400"></i> Autenticación Harbor</h3>
|
||||
<div class="space-y-4">
|
||||
<div><label class="block text-xs text-slate-400 mb-1">Usuario</label><input type="text" id="config-harbor-user" class="w-full bg-slate-800 border border-slate-700 text-sm rounded-lg p-2.5 outline-none font-mono"></div>
|
||||
<div><label class="block text-xs text-slate-400 mb-1">Token / Contraseña</label><input type="password" id="config-harbor-token" class="w-full bg-slate-800 border border-slate-700 text-sm rounded-lg p-2.5 outline-none font-mono"></div>
|
||||
</div>
|
||||
<div class="flex justify-end gap-3 border-t border-slate-800 pt-4">
|
||||
<button onclick="closeConfigModal()" class="px-4 py-2 bg-slate-800 text-slate-300 rounded-lg text-sm">Cancelar</button>
|
||||
<button onclick="saveConfig()" class="px-5 py-2 bg-sky-500 hover:bg-sky-600 text-white rounded-lg text-sm font-semibold transition">Conectar</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal CVE con Alineación Izquierda Corregida -->
|
||||
<div id="cve-modal" class="fixed inset-0 z-50 bg-slate-950/80 backdrop-blur-sm hidden flex items-center justify-center p-4">
|
||||
<div class="bg-slate-900 border border-slate-800 rounded-xl w-full max-w-2xl shadow-2xl p-6 space-y-5">
|
||||
<div class="flex justify-between items-start border-b border-slate-800 pb-3">
|
||||
<div>
|
||||
<div class="flex items-center gap-3">
|
||||
<h3 id="modal-cve-id" class="text-xl font-mono font-bold text-sky-400">CVE</h3>
|
||||
<span id="modal-cve-severity-badge" class="px-2 py-0.5 rounded text-xs font-bold">CRITICAL</span>
|
||||
</div>
|
||||
<p id="modal-cve-package" class="text-xs text-slate-400 mt-1 font-mono"></p>
|
||||
</div>
|
||||
<button onclick="closeCveModal()" class="text-slate-400 hover:text-white text-lg"><i class="fa-solid fa-xmark"></i></button>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4 bg-slate-950 p-4 rounded-lg border border-slate-800">
|
||||
<div>
|
||||
<p class="text-xs text-slate-400 uppercase tracking-wider font-semibold">Puntuación CVSS v3</p>
|
||||
<p id="modal-cve-cvss" class="text-xl font-mono font-bold text-white mt-1">0.0</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-xs text-slate-400 uppercase tracking-wider font-semibold">Versión de Corrección (Fix)</p>
|
||||
<p id="modal-cve-fix" class="text-xl font-mono font-bold text-emerald-400 mt-1">N/A</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<p class="text-xs font-semibold uppercase text-slate-400">Descripción</p>
|
||||
<div id="modal-cve-desc" class="bg-slate-950 p-4 rounded-lg border border-slate-800 text-xs text-slate-300 leading-relaxed max-h-32 overflow-y-auto"></div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<p class="text-xs font-semibold uppercase text-slate-400">Ubicación del Artefacto en Harbor</p>
|
||||
<!-- Clases text-left, break-all para asegurar alineación izquierda limpia -->
|
||||
<div id="modal-cve-location" class="bg-slate-950 p-4 rounded-lg border border-slate-800 text-xs font-mono text-slate-300 space-y-1 text-left break-all"></div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end pt-2">
|
||||
<button onclick="closeCveModal()" class="px-5 py-2 bg-slate-800 hover:bg-slate-700 text-slate-200 rounded-lg text-sm font-medium transition">Cerrar</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let filteredVulnerabilities = [];
|
||||
let userAuth = { user: '', token: '' };
|
||||
let currentPage = 1;
|
||||
let pageSize = 10;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadSessionAuth();
|
||||
onFilterTypeChange();
|
||||
fetchGlobalSummary();
|
||||
applyFilters(1);
|
||||
});
|
||||
|
||||
async function fetchGlobalSummary() {
|
||||
try {
|
||||
const response = await fetch('/api/summary', { headers: getAuthHeaders() });
|
||||
if (!response.ok) return;
|
||||
const summary = await response.json();
|
||||
|
||||
document.getElementById('count-total').textContent = summary.total_vuls || 0;
|
||||
document.getElementById('count-critical').textContent = summary.critical_cnt || 0;
|
||||
document.getElementById('count-high').textContent = summary.high_cnt || 0;
|
||||
document.getElementById('count-medium').textContent = summary.medium_cnt || 0;
|
||||
document.getElementById('count-low').textContent = summary.low_cnt || 0;
|
||||
} catch (e) {
|
||||
console.error("Error obteniendo summary global:", e);
|
||||
}
|
||||
}
|
||||
|
||||
function onFilterTypeChange() {
|
||||
const filterType = document.getElementById('filter-type').value;
|
||||
const container = document.getElementById('filter-input-container');
|
||||
|
||||
if (filterType === 'Severity') {
|
||||
container.innerHTML = `
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1">Nivel de Severidad</label>
|
||||
<select id="search-severity" class="w-full bg-slate-800 border border-slate-700 text-slate-200 text-sm rounded-lg p-2.5 outline-none font-semibold">
|
||||
<option value="ALL">Todas</option>
|
||||
<option value="Critical">Critical</option>
|
||||
<option value="High">High</option>
|
||||
<option value="Medium">Medium</option>
|
||||
<option value="Low">Low</option>
|
||||
<option value="n/a">n/a</option>
|
||||
<option value="None">None</option>
|
||||
</select>
|
||||
`;
|
||||
} else if (filterType === 'CVSS3') {
|
||||
container.innerHTML = `
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1">Rango CVSS v3 (0.0 - 10.0)</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number" id="cvss-from" step="0.1" min="0" max="10" placeholder="Desde" class="w-full bg-slate-800 border border-slate-700 text-sm rounded-lg p-2.5 outline-none">
|
||||
<span class="text-slate-500">-</span>
|
||||
<input type="number" id="cvss-to" step="0.1" min="0" max="10" placeholder="Hasta" class="w-full bg-slate-800 border border-slate-700 text-sm rounded-lg p-2.5 outline-none">
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
let placeholderText = "Ej. CVE-2025-68121, netty...";
|
||||
if (filterType === 'Repository Name') placeholderText = "Ej. demo8/mysql";
|
||||
|
||||
container.innerHTML = `
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1">Término de Búsqueda (${filterType})</label>
|
||||
<input type="text" id="search-query" onkeyup="if(event.key==='Enter')applyFilters(1)" placeholder="${placeholderText}" class="w-full bg-slate-800 border border-slate-700 text-sm rounded-lg p-2.5 outline-none font-mono">
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
function loadSessionAuth() {
|
||||
userAuth.user = sessionStorage.getItem('harbor_user') || '';
|
||||
userAuth.token = sessionStorage.getItem('harbor_token') || '';
|
||||
document.getElementById('config-harbor-user').value = userAuth.user;
|
||||
document.getElementById('config-harbor-token').value = userAuth.token;
|
||||
if(userAuth.user) updateConnectionBadge(true, `Usuario: ${userAuth.user}`);
|
||||
else updateConnectionBadge(false, 'Sin Autenticar');
|
||||
}
|
||||
|
||||
function saveConfig() {
|
||||
userAuth.user = document.getElementById('config-harbor-user').value.trim();
|
||||
userAuth.token = document.getElementById('config-harbor-token').value.trim();
|
||||
sessionStorage.setItem('harbor_user', userAuth.user);
|
||||
sessionStorage.setItem('harbor_token', userAuth.token);
|
||||
closeConfigModal();
|
||||
loadSessionAuth();
|
||||
fetchGlobalSummary();
|
||||
applyFilters(1);
|
||||
}
|
||||
|
||||
function getAuthHeaders() {
|
||||
const headers = new Headers();
|
||||
headers.append('Accept', 'application/json');
|
||||
if (userAuth.user && userAuth.token) {
|
||||
headers.append('Authorization', `Basic ${btoa(`${userAuth.user}:${userAuth.token}`)}`);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
async function applyFilters(targetPage = 1) {
|
||||
currentPage = targetPage;
|
||||
const filterType = document.getElementById('filter-type').value;
|
||||
let query = '';
|
||||
let severity = '';
|
||||
let cvssFrom = '';
|
||||
let cvssTo = '';
|
||||
|
||||
if (filterType === 'Severity') {
|
||||
severity = document.getElementById('search-severity').value;
|
||||
} else if (filterType === 'CVSS3') {
|
||||
cvssFrom = document.getElementById('cvss-from').value;
|
||||
cvssTo = document.getElementById('cvss-to').value;
|
||||
} else {
|
||||
const qInput = document.getElementById('search-query');
|
||||
query = qInput ? qInput.value.trim() : '';
|
||||
}
|
||||
|
||||
const searchIcon = document.getElementById('search-btn-icon');
|
||||
searchIcon.className = "fa-solid fa-spinner fa-spin";
|
||||
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
filter_type: filterType,
|
||||
query,
|
||||
severity,
|
||||
cvss_from: cvssFrom,
|
||||
cvss_to: cvssTo,
|
||||
page: currentPage,
|
||||
page_size: pageSize
|
||||
});
|
||||
|
||||
const response = await fetch(`/api/search?${params.toString()}`, { headers: getAuthHeaders() });
|
||||
if(!response.ok) throw new Error("Error en la consulta a la API");
|
||||
|
||||
filteredVulnerabilities = await response.json();
|
||||
renderTable(filteredVulnerabilities);
|
||||
updatePaginationControls();
|
||||
} catch (e) {
|
||||
alert("Error consultando la API: " + e.message);
|
||||
} finally {
|
||||
searchIcon.className = "fa-solid fa-magnifying-glass";
|
||||
}
|
||||
}
|
||||
|
||||
function changePageSize() {
|
||||
const selectEl = document.getElementById('page-size-select');
|
||||
pageSize = parseInt(selectEl.value);
|
||||
applyFilters(1);
|
||||
}
|
||||
|
||||
function changePage(direction) {
|
||||
if (direction === -1 && currentPage > 1) {
|
||||
applyFilters(currentPage - 1);
|
||||
} else if (direction === 1) {
|
||||
if (filteredVulnerabilities.length < pageSize) return;
|
||||
applyFilters(currentPage + 1);
|
||||
}
|
||||
}
|
||||
|
||||
function updatePaginationControls() {
|
||||
document.getElementById('current-page-label').textContent = currentPage;
|
||||
document.getElementById('prev-page-btn').disabled = (currentPage <= 1);
|
||||
|
||||
const nextBtn = document.getElementById('next-page-btn');
|
||||
if (filteredVulnerabilities.length < pageSize) {
|
||||
nextBtn.disabled = true;
|
||||
nextBtn.classList.add('opacity-50', 'cursor-not-allowed');
|
||||
} else {
|
||||
nextBtn.disabled = false;
|
||||
nextBtn.classList.remove('opacity-50', 'cursor-not-allowed');
|
||||
}
|
||||
}
|
||||
|
||||
function renderTable(items) {
|
||||
const tbody = document.getElementById('vulnerabilities-tbody');
|
||||
const emptyState = document.getElementById('empty-state');
|
||||
document.getElementById('results-count').textContent = items.length;
|
||||
tbody.innerHTML = '';
|
||||
|
||||
if (items.length === 0) {
|
||||
emptyState.classList.remove('hidden');
|
||||
return;
|
||||
}
|
||||
emptyState.classList.add('hidden');
|
||||
|
||||
items.forEach((item, index) => {
|
||||
const tr = document.createElement('tr');
|
||||
tr.className = 'hover:bg-slate-800/40 transition';
|
||||
const sev = item.severity.toLowerCase();
|
||||
const sevColor = sev === 'critical' ? 'bg-red-500/10 text-red-400' :
|
||||
sev === 'high' ? 'bg-orange-500/10 text-orange-400' :
|
||||
sev === 'medium' ? 'bg-yellow-500/10 text-yellow-400' : 'bg-blue-500/10 text-blue-400';
|
||||
|
||||
tr.innerHTML = `
|
||||
<td class="px-4 py-3.5 font-mono text-sky-400"><button onclick="openCveModal(${index})" class="hover:underline">${item.cve_id}</button></td>
|
||||
<td class="px-4 py-3.5"><span class="px-2 py-1 rounded text-xs font-bold ${sevColor}">${item.severity}</span></td>
|
||||
<td class="px-4 py-3.5 font-mono text-white">${item.package} <span class="text-xs text-slate-500 block">${item.version}</span></td>
|
||||
<td class="px-4 py-3.5"><span class="px-2 py-0.5 rounded bg-slate-800 text-xs text-slate-300">${item.project}</span></td>
|
||||
<td class="px-4 py-3.5 font-mono text-xs text-slate-300">${item.repository}</td>
|
||||
<td class="px-4 py-3.5 font-mono text-xs text-slate-400">${item.tag}<br><span class="text-slate-500">${item.digest.substring(0,14)}...</span></td>
|
||||
<td class="px-4 py-3.5 text-center font-mono font-bold text-yellow-400">${item.cvss3}</td>
|
||||
<td class="px-4 py-3.5 text-right"><button onclick="openCveModal(${index})" class="bg-slate-800 hover:bg-slate-700 text-xs px-2.5 py-1.5 rounded">Ver</button></td>
|
||||
`;
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
}
|
||||
|
||||
async function exportToCsv() {
|
||||
if (!filteredVulnerabilities || filteredVulnerabilities.length === 0) {
|
||||
alert("No hay datos en la tabla para exportar.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const headers = ["CVE ID", "Severity", "Package", "Version", "Fixed Version", "Project", "Repository", "Tag", "Digest", "CVSS3", "Description"];
|
||||
let csvContent = "\uFEFF" + headers.join(";") + "\n";
|
||||
|
||||
filteredVulnerabilities.forEach(item => {
|
||||
const row = [
|
||||
item.cve_id,
|
||||
item.severity,
|
||||
item.package,
|
||||
item.version,
|
||||
item.fixed_version,
|
||||
item.project,
|
||||
item.repository,
|
||||
item.tag,
|
||||
item.digest,
|
||||
item.cvss3,
|
||||
`"${(item.description || "").replace(/"/g, '""')}"`
|
||||
];
|
||||
csvContent += row.join(";") + "\n";
|
||||
});
|
||||
|
||||
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.setAttribute('href', url);
|
||||
a.setAttribute('download', `harbor_vulnerabilities_export.csv`);
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
|
||||
} catch (e) {
|
||||
alert("Error al exportar los datos: " + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
function openCveModal(index) {
|
||||
const item = filteredVulnerabilities[index];
|
||||
const sev = item.severity.toLowerCase();
|
||||
const badgeEl = document.getElementById('modal-cve-severity-badge');
|
||||
|
||||
badgeEl.className = sev === 'critical' ? 'px-2 py-0.5 rounded text-xs font-bold bg-red-500/10 text-red-400 border border-red-500/20' :
|
||||
sev === 'high' ? 'px-2 py-0.5 rounded text-xs font-bold bg-orange-500/10 text-orange-400 border border-orange-500/20' :
|
||||
sev === 'medium' ? 'px-2 py-0.5 rounded text-xs font-bold bg-yellow-500/10 text-yellow-400 border border-yellow-500/20' : 'px-2 py-0.5 rounded text-xs font-bold bg-blue-500/10 text-blue-400 border border-blue-500/20';
|
||||
|
||||
badgeEl.textContent = item.severity;
|
||||
document.getElementById('modal-cve-id').textContent = item.cve_id;
|
||||
document.getElementById('modal-cve-package').textContent = `Paquete: ${item.package} (${item.version})`;
|
||||
document.getElementById('modal-cve-cvss').textContent = item.cvss3;
|
||||
document.getElementById('modal-cve-fix').textContent = item.fixed_version || 'N/A';
|
||||
document.getElementById('modal-cve-desc').textContent = item.description || 'Sin descripción disponible.';
|
||||
|
||||
// Estructura limpia en divs con alineación izquierda perfecta
|
||||
document.getElementById('modal-cve-location').innerHTML = `
|
||||
<div>Proyecto: ${item.project}</div>
|
||||
<div>Repositorio: ${item.repository}</div>
|
||||
<div>Digest: ${item.digest}</div>
|
||||
`;
|
||||
|
||||
document.getElementById('cve-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeCveModal() { document.getElementById('cve-modal').classList.add('hidden'); }
|
||||
function openConfigModal() { document.getElementById('config-modal').classList.remove('hidden'); }
|
||||
function closeConfigModal() { document.getElementById('config-modal').classList.add('hidden'); }
|
||||
|
||||
function updateConnectionBadge(isConnected, text) {
|
||||
const badge = document.getElementById('connection-badge');
|
||||
badge.className = isConnected ? "flex items-center space-x-2 bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 px-3 py-1.5 rounded-md text-xs font-medium" : "flex items-center space-x-2 bg-amber-500/10 border border-amber-500/20 text-amber-400 px-3 py-1.5 rounded-md text-xs font-medium";
|
||||
document.getElementById('connection-status-text').textContent = text;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user