Mejora de filtros - Se igualan a Harbor
This commit is contained in:
1 parent
c1ece44486
commit
104d2ce3b8
1 file changed
+151
-213
+151
-213
@@ -8,8 +8,6 @@
|
||||
<script src="assets/js/tailwindcss.js"></script>
|
||||
<!-- FontAwesome Icons -->
|
||||
<link rel="stylesheet" href="assets/css/fontawesome.all.min.css">
|
||||
<!-- Google Fonts -->
|
||||
<!-- <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet"> -->
|
||||
<script>
|
||||
tailwind.config = {
|
||||
theme: {
|
||||
@@ -95,7 +93,7 @@
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Contenido Principal -->
|
||||
<!-- Contenido Principal Dinámico de Ancho Completo -->
|
||||
<main class="flex-1 w-full px-4 sm:px-6 lg:px-8 py-6 space-y-6">
|
||||
|
||||
<!-- Métricas Rápidas -->
|
||||
@@ -151,7 +149,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tarjeta de Filtros idéntica a la captura de Harbor Interrogation Services -->
|
||||
<!-- Tarjeta de Filtros Dinámicos -->
|
||||
<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 y Filtrado de Vulnerabilidades
|
||||
@@ -161,28 +159,20 @@
|
||||
<!-- Desplegable Filter by -->
|
||||
<div class="w-full md:w-64 flex-shrink-0">
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1">Filter by <i class="fa-solid fa-circle-info text-slate-500" title="Selecciona la categoría del filtro"></i></label>
|
||||
<select id="filter-type" class="w-full bg-slate-800 border border-slate-700 text-slate-200 text-sm rounded-lg p-2.5 focus:ring-2 focus:ring-sky-500 focus:border-sky-500 outline-none">
|
||||
<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 focus:ring-2 focus:ring-sky-500 focus:border-sky-500 outline-none">
|
||||
<option value="All">All</option>
|
||||
<option value="CVE ID">CVE ID</option>
|
||||
<option value="Severity">Severity</option>
|
||||
<option value="CVSS3">CVSS3</option>
|
||||
<option value="CVE ID">CVE ID</option>
|
||||
<option value="CVSS3">CVSS3 (Puntuación)</option>
|
||||
<option value="Project Name">Project Name</option>
|
||||
<option value="Repository Name">Repository Name</option>
|
||||
<option value="Package">Package</option>
|
||||
<option value="Tag">Tag</option>
|
||||
<option value="Digest">Digest</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Input de consulta textual -->
|
||||
<div class="flex-1">
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1">Término de Búsqueda</label>
|
||||
<div class="relative">
|
||||
<div class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none text-slate-500">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
</div>
|
||||
<input type="text" id="search-query" onkeyup="handleKeySearch(event)" placeholder="Ej. netty-tcnative, CVE-2023-3446, log4j, calidad..." class="w-full bg-slate-800 border border-slate-700 text-slate-100 text-sm rounded-lg pl-10 p-2.5 focus:ring-2 focus:ring-sky-500 focus:border-sky-500 outline-none">
|
||||
</div>
|
||||
<!-- Contenedor Dinámico de Inputs según el Filtro -->
|
||||
<div class="flex-1" id="filter-input-container">
|
||||
<!-- Se renderiza dinámicamente mediante JS -->
|
||||
</div>
|
||||
|
||||
<!-- Botones de Acción -->
|
||||
@@ -227,13 +217,13 @@
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Estado Vacío (Coincide con captura de pantalla) -->
|
||||
<!-- Estado Vacío -->
|
||||
<div id="empty-state" class="hidden py-16 text-center space-y-4">
|
||||
<div class="inline-flex items-center justify-center w-16 h-16 rounded-full bg-slate-800/80 border border-slate-700 text-slate-400 mb-2">
|
||||
<i class="fa-solid fa-filter text-2xl"></i>
|
||||
</div>
|
||||
<h3 class="text-lg font-medium text-slate-300">We could not find any vulnerability</h3>
|
||||
<p class="text-sm text-slate-500 max-w-md mx-auto">No se han encontrado vulnerabilidades con los criterios especificados o las imágenes no han sido escaneadas aún.</p>
|
||||
<p class="text-sm text-slate-500 max-w-md mx-auto">No se han encontrado vulnerabilidades con los criterios especificados.</p>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
@@ -252,9 +242,8 @@
|
||||
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-xs font-semibold text-slate-400 mb-1">URL / URI Base de Harbor</label>
|
||||
<input type="url" id="config-harbor-url" placeholder="https://harbor.tu-empresa.com" class="w-full bg-slate-800 border border-slate-700 text-slate-100 text-sm rounded-lg p-2.5 focus:ring-2 focus:ring-sky-500 outline-none font-mono">
|
||||
<p class="text-[11px] text-slate-500 mt-1">Dirección del servidor donde corre Harbor REST API v2.0</p>
|
||||
<label class="block text-xs font-semibold text-slate-400 mb-1">URL / URI Base de Harbor (o Proxy Local)</label>
|
||||
<input type="url" id="config-harbor-url" placeholder="http://localhost:8080" class="w-full bg-slate-800 border border-slate-700 text-slate-100 text-sm rounded-lg p-2.5 focus:ring-2 focus:ring-sky-500 outline-none font-mono">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@@ -267,16 +256,10 @@
|
||||
<input type="password" id="config-harbor-token" placeholder="••••••••••••••••••••" class="w-full bg-slate-800 border border-slate-700 text-slate-100 text-sm rounded-lg p-2.5 focus:ring-2 focus:ring-sky-500 outline-none font-mono">
|
||||
</div>
|
||||
|
||||
<!-- Opción de Guardar Credenciales -->
|
||||
<div class="flex items-center space-x-2 pt-2">
|
||||
<input type="checkbox" id="config-remember" class="w-4 h-4 rounded bg-slate-800 border-slate-700 text-sky-500 focus:ring-sky-500">
|
||||
<label for="config-remember" class="text-xs text-slate-300">Guardar credenciales en el navegador (localStorage)</label>
|
||||
</div>
|
||||
|
||||
<div class="bg-slate-800/60 p-3 rounded-lg border border-slate-700/60 text-xs text-slate-400 space-y-1">
|
||||
<p class="font-medium text-slate-300 flex items-center gap-1"><i class="fa-solid fa-shield-cat text-sky-400"></i> Fallback Inteligente:</p>
|
||||
<p>Si la URL se deja en blanco o la API no es accesible (ej. políticas de CORS del servidor Harbor), el portal cargará automáticamente datos de demostración con vulnerabilidades reales (como <code class="text-sky-300 font-mono">netty-tcnative</code>, <code class="text-sky-300 font-mono">log4j</code>, <code class="text-sky-300 font-mono">openssl</code>).</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-between items-center border-t border-slate-800 pt-4">
|
||||
@@ -292,7 +275,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal para Inspeccionar CVE individual -->
|
||||
<!-- Modal CVE Individual -->
|
||||
<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">
|
||||
@@ -330,7 +313,6 @@
|
||||
<div>
|
||||
<h4 class="text-xs uppercase font-semibold text-slate-400 mb-1">Ubicación del Artefacto en Harbor</h4>
|
||||
<div id="modal-cve-target" class="font-mono text-xs bg-slate-950 p-2.5 rounded border border-slate-800 text-slate-300 space-y-1">
|
||||
<!-- Ruta del artefacto -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -341,9 +323,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Lógica JavaScript Principal de la Aplicación -->
|
||||
<!-- Lógica JavaScript Principal -->
|
||||
<script>
|
||||
// Datos Simulados (Fallback en caso de no haber conexión con servidor Harbor)
|
||||
const MOCK_DATA = [
|
||||
{
|
||||
cve_id: "CVE-2021-43797",
|
||||
@@ -356,7 +337,7 @@
|
||||
tag: "v1.4.2",
|
||||
digest: "sha256:e8a3a921d1982b1c",
|
||||
cvss3: 9.8,
|
||||
description: "Vulnerabilidad en Netty-tcnative anterior a 2.0.46.Final que permite lectura fuera de límites durante la verificación de certificados SSL, provocando fuga de información o ejecución remota."
|
||||
description: "Vulnerabilidad en Netty-tcnative anterior a 2.0.46.Final que permite lectura fuera de límites durante la verificación de certificados SSL."
|
||||
},
|
||||
{
|
||||
cve_id: "CVE-2023-3446",
|
||||
@@ -438,19 +419,13 @@
|
||||
}
|
||||
];
|
||||
|
||||
// Estado global de la app
|
||||
let vulnerabilities = [...MOCK_DATA];
|
||||
let filteredVulnerabilities = [...MOCK_DATA];
|
||||
let harborConfig = {
|
||||
url: '',
|
||||
user: '',
|
||||
token: '',
|
||||
remember: false
|
||||
};
|
||||
let harborConfig = { url: 'http://localhost:8080', user: '', token: '', remember: false };
|
||||
|
||||
// Inicialización al cargar el DOM
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadSavedConfig();
|
||||
onFilterTypeChange();
|
||||
if (harborConfig.url) {
|
||||
syncWithHarbor();
|
||||
} else {
|
||||
@@ -459,29 +434,69 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Cargar configuración guardada desde localStorage
|
||||
// Cambiar dinámicamente los campos según la opción de Filter By
|
||||
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" onchange="applyFilters()" class="w-full bg-slate-800 border border-slate-700 text-slate-200 text-sm rounded-lg p-2.5 focus:ring-2 focus:ring-sky-500 outline-none font-semibold">
|
||||
<option value="ALL">Todas las severidades</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 de Puntuación CVSS v3 (1.0 - 10.0)</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="relative flex-1">
|
||||
<input type="number" id="cvss-from" step="0.1" min="1.0" max="10.0" placeholder="Desde (1.0)" onkeyup="handleKeySearch(event)" class="w-full bg-slate-800 border border-slate-700 text-slate-100 text-sm rounded-lg p-2.5 focus:ring-2 focus:ring-sky-500 outline-none">
|
||||
</div>
|
||||
<span class="text-slate-500 font-bold">-</span>
|
||||
<div class="relative flex-1">
|
||||
<input type="number" id="cvss-to" step="0.1" min="1.0" max="10.0" placeholder="Hasta (10.0)" onkeyup="handleKeySearch(event)" class="w-full bg-slate-800 border border-slate-700 text-slate-100 text-sm rounded-lg p-2.5 focus:ring-2 focus:ring-sky-500 outline-none">
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
let placeholderText = "Buscar en todos los campos...";
|
||||
if (filterType === 'CVE ID') placeholderText = "Ej. CVE-2021-43797, CVE-2023-3446...";
|
||||
if (filterType === 'Project Name') placeholderText = "Ej. calidad, produccion, sistemas...";
|
||||
if (filterType === 'Package') placeholderText = "Ej. netty-tcnative, log4j, openssl...";
|
||||
if (filterType === 'Digest') placeholderText = "Ej. sha256:e8a3a921d1982b1c...";
|
||||
|
||||
container.innerHTML = `
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1">Término de Búsqueda (${filterType})</label>
|
||||
<div class="relative">
|
||||
<div class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none text-slate-500">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
</div>
|
||||
<input type="text" id="search-query" onkeyup="handleKeySearch(event)" placeholder="${placeholderText}" class="w-full bg-slate-800 border border-slate-700 text-slate-100 text-sm rounded-lg pl-10 p-2.5 focus:ring-2 focus:ring-sky-500 outline-none">
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
function loadSavedConfig() {
|
||||
const savedUrl = localStorage.getItem('harbor_url') || '';
|
||||
const savedUrl = localStorage.getItem('harbor_url') || 'http://localhost:8080';
|
||||
const savedUser = localStorage.getItem('harbor_user') || '';
|
||||
const savedToken = localStorage.getItem('harbor_token') || '';
|
||||
const savedRemember = localStorage.getItem('harbor_remember') === 'true';
|
||||
|
||||
harborConfig = {
|
||||
url: savedUrl,
|
||||
user: savedUser,
|
||||
token: savedToken,
|
||||
remember: savedRemember
|
||||
};
|
||||
|
||||
harborConfig = { url: savedUrl, user: savedUser, token: savedToken, remember: savedRemember };
|
||||
document.getElementById('config-harbor-url').value = savedUrl;
|
||||
document.getElementById('config-harbor-user').value = savedUser;
|
||||
document.getElementById('config-harbor-token').value = savedToken;
|
||||
document.getElementById('config-remember').checked = savedRemember;
|
||||
|
||||
updateConnectionBadge(false, savedUrl ? 'Configurado' : 'Modo Simulación');
|
||||
}
|
||||
|
||||
// Guardar configuración en modal
|
||||
function saveConfig() {
|
||||
const url = document.getElementById('config-harbor-url').value.trim().replace(/\/+$/, '');
|
||||
const user = document.getElementById('config-harbor-user').value.trim();
|
||||
@@ -489,78 +504,45 @@
|
||||
const remember = document.getElementById('config-remember').checked;
|
||||
|
||||
harborConfig = { url, user, token, remember };
|
||||
|
||||
if (remember) {
|
||||
localStorage.setItem('harbor_url', url);
|
||||
localStorage.setItem('harbor_user', user);
|
||||
localStorage.setItem('harbor_token', token);
|
||||
localStorage.setItem('harbor_remember', 'true');
|
||||
} else {
|
||||
clearLocalStorageCredentials();
|
||||
localStorage.clear();
|
||||
}
|
||||
|
||||
closeConfigModal();
|
||||
syncWithHarbor();
|
||||
}
|
||||
|
||||
function clearConfig() {
|
||||
clearLocalStorageCredentials();
|
||||
document.getElementById('config-harbor-url').value = '';
|
||||
localStorage.clear();
|
||||
document.getElementById('config-harbor-url').value = 'http://localhost:8080';
|
||||
document.getElementById('config-harbor-user').value = '';
|
||||
document.getElementById('config-harbor-token').value = '';
|
||||
document.getElementById('config-remember').checked = false;
|
||||
harborConfig = { url: '', user: '', token: '', remember: false };
|
||||
|
||||
vulnerabilities = [...MOCK_DATA];
|
||||
filteredVulnerabilities = [...MOCK_DATA];
|
||||
renderTable(filteredVulnerabilities);
|
||||
updateCounters(filteredVulnerabilities);
|
||||
updateConnectionBadge(false, 'Modo Simulación (Demo)');
|
||||
closeConfigModal();
|
||||
harborConfig = { url: 'http://localhost:8080', user: '', token: '', remember: false };
|
||||
syncWithHarbor();
|
||||
}
|
||||
|
||||
function clearLocalStorageCredentials() {
|
||||
localStorage.removeItem('harbor_url');
|
||||
localStorage.removeItem('harbor_user');
|
||||
localStorage.removeItem('harbor_token');
|
||||
localStorage.removeItem('harbor_remember');
|
||||
}
|
||||
|
||||
// Sincronización real con la API v2.0 de Harbor
|
||||
async function syncWithHarbor() {
|
||||
const syncIcon = document.getElementById('sync-icon');
|
||||
syncIcon.classList.add('fa-spin');
|
||||
|
||||
if (!harborConfig.url) {
|
||||
console.log('No hay URL configurada. Cargando datos de prueba.');
|
||||
vulnerabilities = [...MOCK_DATA];
|
||||
filteredVulnerabilities = [...MOCK_DATA];
|
||||
renderTable(filteredVulnerabilities);
|
||||
updateCounters(filteredVulnerabilities);
|
||||
updateConnectionBadge(false, 'Modo Simulación (Demo)');
|
||||
syncIcon.classList.remove('fa-spin');
|
||||
document.getElementById('last-sync-time').textContent = 'Modo Simulación Activo';
|
||||
return;
|
||||
}
|
||||
|
||||
updateConnectionBadge(false, 'Conectando...', 'animate-pulse');
|
||||
updateConnectionBadge(false, 'Sincronizando...');
|
||||
|
||||
try {
|
||||
const headers = new Headers();
|
||||
headers.append('Accept', 'application/json');
|
||||
if (harborConfig.user && harborConfig.token) {
|
||||
const credentials = btoa(`${harborConfig.user}:${harborConfig.token}`);
|
||||
headers.append('Authorization', `Basic ${credentials}`);
|
||||
headers.append('Authorization', `Basic ${btoa(`${harborConfig.user}:${harborConfig.token}`)}`);
|
||||
}
|
||||
|
||||
// 1. Obtener lista de proyectos
|
||||
const projectsResponse = await fetch(`${harborConfig.url}/api/v2.0/projects?page_size=15`, { headers });
|
||||
if (!projectsResponse.ok) throw new Error(`HTTP ${projectsResponse.status}: Error al obtener proyectos`);
|
||||
if (!projectsResponse.ok) throw new Error(`HTTP ${projectsResponse.status}`);
|
||||
const projects = await projectsResponse.json();
|
||||
|
||||
let fetchedVulns = [];
|
||||
|
||||
// 2. Recorrer repositorios de cada proyecto
|
||||
for (const proj of projects) {
|
||||
try {
|
||||
const reposResp = await fetch(`${harborConfig.url}/api/v2.0/projects/${proj.name}/repositories?page_size=10`, { headers });
|
||||
@@ -569,19 +551,17 @@
|
||||
|
||||
for (const repo of repos) {
|
||||
const repoShortName = repo.name.replace(`${proj.name}/`, '');
|
||||
// 3. Obtener artefactos
|
||||
const artifactsResp = await fetch(`${harborConfig.url}/api/v2.0/projects/${proj.name}/repositories/${repoShortName}/artifacts?page_size=5`, { headers });
|
||||
if (!artifactsResp.ok) continue;
|
||||
const artifacts = await artifactsResp.json();
|
||||
|
||||
for (const art of artifacts) {
|
||||
// 4. Consultar adiciones/vulnerabilidades de cada artefacto
|
||||
const vulnResp = await fetch(`${harborConfig.url}/api/v2.0/projects/${proj.name}/repositories/${repoShortName}/artifacts/${art.digest}/additions/vulnerabilities`, { headers });
|
||||
if (!vulnResp.ok) continue;
|
||||
const vulnsData = await vulnResp.json();
|
||||
|
||||
const reportKey = Object.keys(vulnsData)[0];
|
||||
if (reportKey && vulnsData[reportKey] && vulnsData[reportKey].vulnerabilities) {
|
||||
if (reportKey && vulnsData[reportKey]?.vulnerabilities) {
|
||||
const items = vulnsData[reportKey].vulnerabilities.map(v => ({
|
||||
cve_id: v.id || 'N/A',
|
||||
severity: (v.severity || 'UNKNOWN').toUpperCase(),
|
||||
@@ -590,42 +570,40 @@
|
||||
fixed_version: v.fix_version || 'N/A',
|
||||
project: proj.name,
|
||||
repository: repo.name,
|
||||
tag: art.tags && art.tags.length > 0 ? art.tags[0].name : 'latest',
|
||||
tag: art.tags?.[0]?.name || 'latest',
|
||||
digest: art.digest || 'N/A',
|
||||
cvss3: v.preferred_cvss ? v.preferred_cvss.scoreV3 || 0 : (v.severity === 'CRITICAL' ? 9.5 : 7.0),
|
||||
description: v.description || 'Sin descripción provista por el escaner de Harbor.'
|
||||
cvss3: v.preferred_cvss?.scoreV3 || (v.severity === 'CRITICAL' ? 9.5 : 7.0),
|
||||
description: v.description || 'Sin descripción.'
|
||||
}));
|
||||
fetchedVulns.push(...items);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(`Error procesando proyecto ${proj.name}:`, e);
|
||||
console.warn(`Proyecto omitido: ${proj.name}`, e);
|
||||
}
|
||||
}
|
||||
|
||||
if (fetchedVulns.length > 0) {
|
||||
vulnerabilities = fetchedVulns;
|
||||
} else {
|
||||
console.log('No se encontraron vulnerabilidades reportadas en la API. Manteniendo vista.');
|
||||
vulnerabilities = [...MOCK_DATA];
|
||||
}
|
||||
|
||||
filteredVulnerabilities = [...vulnerabilities];
|
||||
renderTable(filteredVulnerabilities);
|
||||
updateCounters(filteredVulnerabilities);
|
||||
//updateConnectionBadge(true, `Conectado: ${new URL(harborConfig.url).hostname}`);
|
||||
updateConnectionBadge(true, `Conectado a HARBOR`);
|
||||
updateConnectionBadge(true, 'Conectado a HARBOR');
|
||||
document.getElementById('last-sync-time').textContent = `Sincronizado: ${new Date().toLocaleTimeString()}`;
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error al conectar con la API de Harbor:', error);
|
||||
alert(`No se pudo conectar a Harbor API:\n${error.message}\n\nSe cargarán los datos simulados en modo de prueba.`);
|
||||
console.warn('Usando datos simulados debido a fallo de conexión:', error);
|
||||
vulnerabilities = [...MOCK_DATA];
|
||||
filteredVulnerabilities = [...MOCK_DATA];
|
||||
renderTable(filteredVulnerabilities);
|
||||
updateCounters(filteredVulnerabilities);
|
||||
updateConnectionBadge(false, 'Error API - Modo Simulación');
|
||||
document.getElementById('last-sync-time').textContent = 'Fallo de conexión';
|
||||
updateConnectionBadge(false, 'Modo Simulación (Demo)');
|
||||
document.getElementById('last-sync-time').textContent = 'Fallo de conexión API';
|
||||
} finally {
|
||||
syncIcon.classList.remove('fa-spin');
|
||||
}
|
||||
@@ -635,7 +613,6 @@
|
||||
const badge = document.getElementById('connection-badge');
|
||||
const dot = document.getElementById('connection-dot');
|
||||
const label = document.getElementById('connection-status-text');
|
||||
|
||||
label.textContent = text;
|
||||
if (isConnected) {
|
||||
badge.className = "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";
|
||||
@@ -646,43 +623,52 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Lógica de filtrado de la tabla
|
||||
// Lógica de filtrado dinámico según la opción seleccionada
|
||||
function applyFilters() {
|
||||
const filterType = document.getElementById('filter-type').value;
|
||||
const query = document.getElementById('search-query').value.trim().toLowerCase();
|
||||
|
||||
filteredVulnerabilities = vulnerabilities.filter(item => {
|
||||
if (!query) return true;
|
||||
if (filterType === 'Severity') {
|
||||
const selectedSev = document.getElementById('search-severity').value.toUpperCase();
|
||||
if (selectedSev === 'ALL') return true;
|
||||
return item.severity.toUpperCase() === selectedSev;
|
||||
}
|
||||
else if (filterType === 'CVSS3') {
|
||||
const cvssFrom = parseFloat(document.getElementById('cvss-from').value);
|
||||
const cvssTo = parseFloat(document.getElementById('cvss-to').value);
|
||||
const itemCvss = parseFloat(item.cvss3);
|
||||
|
||||
switch(filterType) {
|
||||
case 'CVE ID':
|
||||
return item.cve_id.toLowerCase().includes(query);
|
||||
case 'Severity':
|
||||
return item.severity.toLowerCase().includes(query);
|
||||
case 'CVSS3':
|
||||
return item.cvss3.toString().includes(query);
|
||||
case 'Project Name':
|
||||
return item.project.toLowerCase().includes(query);
|
||||
case 'Repository Name':
|
||||
return item.repository.toLowerCase().includes(query);
|
||||
case 'Package':
|
||||
return item.package.toLowerCase().includes(query);
|
||||
case 'Tag':
|
||||
return item.tag.toLowerCase().includes(query);
|
||||
case 'Digest':
|
||||
return item.digest.toLowerCase().includes(query);
|
||||
case 'All':
|
||||
default:
|
||||
return (
|
||||
item.cve_id.toLowerCase().includes(query) ||
|
||||
item.severity.toLowerCase().includes(query) ||
|
||||
item.package.toLowerCase().includes(query) ||
|
||||
item.project.toLowerCase().includes(query) ||
|
||||
item.repository.toLowerCase().includes(query) ||
|
||||
item.tag.toLowerCase().includes(query) ||
|
||||
item.digest.toLowerCase().includes(query) ||
|
||||
item.cvss3.toString().includes(query)
|
||||
);
|
||||
if (!isNaN(cvssFrom) && itemCvss < cvssFrom) return false;
|
||||
if (!isNaN(cvssTo) && itemCvss > cvssTo) return false;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
const queryInput = document.getElementById('search-query');
|
||||
const query = queryInput ? queryInput.value.trim().toLowerCase() : '';
|
||||
if (!query) return true;
|
||||
|
||||
switch(filterType) {
|
||||
case 'CVE ID':
|
||||
return item.cve_id.toLowerCase().includes(query);
|
||||
case 'Project Name':
|
||||
return item.project.toLowerCase().includes(query);
|
||||
case 'Package':
|
||||
return item.package.toLowerCase().includes(query);
|
||||
case 'Digest':
|
||||
return item.digest.toLowerCase().includes(query);
|
||||
case 'All':
|
||||
default:
|
||||
return (
|
||||
item.cve_id.toLowerCase().includes(query) ||
|
||||
item.severity.toLowerCase().includes(query) ||
|
||||
item.package.toLowerCase().includes(query) ||
|
||||
item.project.toLowerCase().includes(query) ||
|
||||
item.repository.toLowerCase().includes(query) ||
|
||||
item.tag.toLowerCase().includes(query) ||
|
||||
item.digest.toLowerCase().includes(query) ||
|
||||
item.cvss3.toString().includes(query)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -690,13 +676,13 @@
|
||||
updateCounters(filteredVulnerabilities);
|
||||
}
|
||||
|
||||
function handleKeySearch(event) {
|
||||
if (event.key === 'Enter') applyFilters();
|
||||
function handleKeySearch(e) {
|
||||
if (e.key === 'Enter') applyFilters();
|
||||
}
|
||||
|
||||
function resetFilters() {
|
||||
document.getElementById('filter-type').value = 'All';
|
||||
document.getElementById('search-query').value = '';
|
||||
onFilterTypeChange();
|
||||
filteredVulnerabilities = [...vulnerabilities];
|
||||
renderTable(filteredVulnerabilities);
|
||||
updateCounters(filteredVulnerabilities);
|
||||
@@ -704,25 +690,22 @@
|
||||
|
||||
function quickFilterSeverity(sev) {
|
||||
document.getElementById('filter-type').value = 'Severity';
|
||||
document.getElementById('search-query').value = sev;
|
||||
onFilterTypeChange();
|
||||
document.getElementById('search-severity').value = sev;
|
||||
applyFilters();
|
||||
}
|
||||
|
||||
// Renderizado de tabla HTML
|
||||
function renderTable(items) {
|
||||
const tbody = document.getElementById('vulnerabilities-tbody');
|
||||
const emptyState = document.getElementById('empty-state');
|
||||
const resultsCount = document.getElementById('results-count');
|
||||
|
||||
document.getElementById('results-count').textContent = items.length;
|
||||
tbody.innerHTML = '';
|
||||
resultsCount.textContent = items.length;
|
||||
|
||||
if (items.length === 0) {
|
||||
emptyState.classList.remove('hidden');
|
||||
return;
|
||||
} else {
|
||||
emptyState.classList.add('hidden');
|
||||
}
|
||||
emptyState.classList.add('hidden');
|
||||
|
||||
items.forEach((item, index) => {
|
||||
const tr = document.createElement('tr');
|
||||
@@ -774,8 +757,12 @@
|
||||
case 'MEDIUM':
|
||||
return `<span class="bg-yellow-500/10 text-yellow-400 border border-yellow-500/30 px-2.5 py-1 rounded text-xs font-bold tracking-wide">MEDIUM</span>`;
|
||||
case 'LOW':
|
||||
default:
|
||||
return `<span class="bg-blue-500/10 text-blue-400 border border-blue-500/30 px-2.5 py-1 rounded text-xs font-bold tracking-wide">LOW</span>`;
|
||||
case 'N/A':
|
||||
return `<span class="bg-slate-500/10 text-slate-400 border border-slate-500/30 px-2.5 py-1 rounded text-xs font-bold tracking-wide">N/A</span>`;
|
||||
case 'NONE':
|
||||
default:
|
||||
return `<span class="bg-slate-700/30 text-slate-300 border border-slate-600/30 px-2.5 py-1 rounded text-xs font-bold tracking-wide">NONE</span>`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -787,7 +774,6 @@
|
||||
document.getElementById('count-low').textContent = data.filter(i => i.severity.toUpperCase() === 'LOW').length;
|
||||
}
|
||||
|
||||
// Modales
|
||||
function openCveModal(index) {
|
||||
const item = filteredVulnerabilities[index];
|
||||
document.getElementById('modal-cve-id').textContent = item.cve_id;
|
||||
@@ -796,79 +782,31 @@
|
||||
document.getElementById('modal-cve-cvss').textContent = item.cvss3;
|
||||
document.getElementById('modal-cve-fixed').textContent = item.fixed_version || 'N/A';
|
||||
document.getElementById('modal-cve-desc').textContent = item.description;
|
||||
|
||||
document.getElementById('modal-cve-target').innerHTML = `
|
||||
<div><span class="text-slate-500">Proyecto:</span> ${escapeHtml(item.project)}</div>
|
||||
<div><span class="text-slate-500">Repositorio:</span> ${escapeHtml(item.repository)}:${escapeHtml(item.tag)}</div>
|
||||
<div><span class="text-slate-500">Digest:</span> ${escapeHtml(item.digest)}</div>
|
||||
`;
|
||||
|
||||
document.getElementById('modal-cve-target').innerHTML = `<div>Proyecto: ${escapeHtml(item.project)}</div><div>Repositorio: ${escapeHtml(item.repository)}:${escapeHtml(item.tag)}</div><div>Digest: ${escapeHtml(item.digest)}</div>`;
|
||||
document.getElementById('cve-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeCveModal() {
|
||||
document.getElementById('cve-modal').classList.add('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 openConfigModal() {
|
||||
document.getElementById('config-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeConfigModal() {
|
||||
document.getElementById('config-modal').classList.add('hidden');
|
||||
}
|
||||
|
||||
// Exportación de datos
|
||||
function exportData(format) {
|
||||
if (filteredVulnerabilities.length === 0) {
|
||||
alert("No hay vulnerabilidades para exportar con los filtros actuales.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (filteredVulnerabilities.length === 0) return alert("No hay datos para exportar.");
|
||||
const timestamp = new Date().toISOString().slice(0,10);
|
||||
|
||||
if (format === 'json') {
|
||||
const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(filteredVulnerabilities, null, 2));
|
||||
const a = document.createElement('a');
|
||||
a.setAttribute("href", dataStr);
|
||||
a.setAttribute("download", `harbor_vulnerabilities_${timestamp}.json`);
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
} else if (format === 'csv') {
|
||||
const headers = ["CVE ID", "Severidad", "Paquete", "Version Afectada", "Version Correccion", "Proyecto", "Repositorio", "Tag", "CVSS3", "Digest"];
|
||||
const rows = filteredVulnerabilities.map(i => [
|
||||
`"${i.cve_id}"`,
|
||||
`"${i.severity}"`,
|
||||
`"${i.package}"`,
|
||||
`"${i.version}"`,
|
||||
`"${i.fixed_version}"`,
|
||||
`"${i.project}"`,
|
||||
`"${i.repository}"`,
|
||||
`"${i.tag}"`,
|
||||
i.cvss3,
|
||||
`"${i.digest}"`
|
||||
]);
|
||||
|
||||
const a = document.createElement('a'); a.href = dataStr; a.download = `harbor_vulnerabilities_${timestamp}.json`; a.click(); a.remove();
|
||||
} else {
|
||||
const headers = ["CVE ID", "Severidad", "Paquete", "Version", "Fix", "Proyecto", "Repositorio", "Tag", "CVSS3", "Digest"];
|
||||
const rows = filteredVulnerabilities.map(i => [`"${i.cve_id}"`, `"${i.severity}"`, `"${i.package}"`, `"${i.version}"`, `"${i.fixed_version}"`, `"${i.project}"`, `"${i.repository}"`, `"${i.tag}"`, i.cvss3, `"${i.digest}"`]);
|
||||
const csvContent = "data:text/csv;charset=utf-8," + [headers.join(","), ...rows.map(e => e.join(","))].join("\n");
|
||||
const encodedUri = encodeURI(csvContent);
|
||||
const a = document.createElement("a");
|
||||
a.setAttribute("href", encodedUri);
|
||||
a.setAttribute("download", `harbor_vulnerabilities_${timestamp}.csv`);
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
const a = document.createElement('a'); a.href = encodeURI(csvContent); a.download = `harbor_vulnerabilities_${timestamp}.csv`; a.click(); a.remove();
|
||||
}
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
if (!text) return '';
|
||||
return text.toString()
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
return text.toString().replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in new issue
Block a user