Network Security Dashboard

Network Security Dashboard

Monitor threats, alerts, and system vulnerabilities.

Security Overview

Security Events Over Time

Alerts by Severity

Recent Alert Log

Date Description Threat Type Severity Status

Enter Security Events

${openAlerts}

Resolved Threats

${resolved}

`; }; const renderDataTable = () => { dataTableBody.innerHTML = ''; const sortedEvents = [...state.events].sort((a, b) => new Date(b.date) - new Date(a.date)); const severityColors = { 'Critical': 'bg-red-600 text-white', 'High': 'bg-red-500 text-white', 'Medium': 'bg-yellow-400 text-gray-800', 'Low': 'bg-blue-400 text-white' }; const statusColors = { 'Investigating': 'text-yellow-600', 'Resolved': 'text-green-600', 'Pending': 'text-blue-600' }; sortedEvents.forEach(e => { const row = ` ${e.date} ${e.description} ${e.type} ${e.severity} ${e.status} `; dataTableBody.innerHTML += row; }); }; const renderCharts = () => { // Events Trend Chart (Line) const eventsByDate = state.events.reduce((acc, e) => { acc[e.date] = (acc[e.date] || 0) + 1; return acc; }, {}); const sortedDates = Object.keys(eventsByDate).sort((a, b) => new Date(a) - new Date(b)); if (eventsTrendChart) eventsTrendChart.destroy(); eventsTrendChart = new Chart(eventsTrendCanvas.getContext('2d'), { type: 'line', data: { labels: sortedDates, datasets: [{ label: 'Events per Day', data: sortedDates.map(date => eventsByDate[date]), borderColor: '#ef4444', backgroundColor: 'rgba(239, 68, 68, 0.1)', fill: true, tension: 0.3 }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false } }, scales: { x: { type: 'time', time: { unit: 'day' } }, y: { beginAtZero: true, ticks: { stepSize: 1 } } } } }); // Severity Chart (Doughnut) const eventsBySeverity = state.events.reduce((acc, e) => { acc[e.severity] = (acc[e.severity] || 0) + 1; return acc; }, {}); const severityLabels = ['Critical', 'High', 'Medium', 'Low']; const severityData = severityLabels.map(label => eventsBySeverity[label] || 0); if (severityChart) severityChart.destroy(); severityChart = new Chart(severityCanvas.getContext('2d'), { type: 'doughnut', data: { labels: severityLabels, datasets: [{ data: severityData, backgroundColor: ['#b91c1c', '#ef4444', '#f59e0b', '#3b82f6'], }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'top' } } } }); }; const renderConfigRows = () => { configRowsContainer.innerHTML = ''; state.events.forEach(e => { const row = `
`; configRowsContainer.innerHTML += row; }); addConfigEventListeners(); }; // --- EVENT HANDLERS --- const handleConfigChange = (e) => { const id = parseInt(e.target.dataset.id); const field = e.target.dataset.field; const value = e.target.value; const event = state.events.find(ev => ev.id === id); if (event) event[field] = value; renderAll(); }; const handleAddEvent = () => { const newId = state.events.length > 0 ? Math.max(...state.events.map(e => e.id)) + 1 : 1; const today = new Date().toISOString().split('T')[0]; state.events.push({ id: newId, date: today, description: "New Event", type: "Unknown", severity: "Low", status: "Pending" }); renderAll(); }; const handleRemoveEvent = (e) => { const id = parseInt(e.target.dataset.id); state.events = state.events.filter(ev => ev.id !== id); renderAll(); }; const addConfigEventListeners = () => { document.querySelectorAll('.config-input').forEach(input => input.addEventListener('change', handleConfigChange)); document.querySelectorAll('.remove-event-btn').forEach(button => button.addEventListener('click', handleRemoveEvent)); }; const handleDownloadPdf = () => { const { jsPDF } = window.jspdf; const pdfContent = document.getElementById('pdf-content'); document.querySelectorAll('.no-print').forEach(el => el.style.visibility = 'hidden'); Chart.defaults.animation = false; html2canvas(pdfContent, { scale: 2, useCORS: true, backgroundColor: '#ffffff' }).then(canvas => { document.querySelectorAll('.no-print').forEach(el => el.style.visibility = 'visible'); Chart.defaults.animation = true; const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgWidth = pdfWidth - 20; const imgHeight = canvas.height * imgWidth / canvas.width; pdf.addImage(imgData, 'PNG', 10, 10, imgWidth, imgHeight); pdf.save('Network-Security-Dashboard.pdf'); }); }; // --- TABBING LOGIC --- let currentTabIndex = 0; const updateTabButtons = () => { prevTabBtn.disabled = currentTabIndex === 0; nextTabBtn.disabled = currentTabIndex === tabContents.length - 1; }; const switchTab = (index) => { tabButtons.forEach(btn => btn.classList.remove('active')); tabContents.forEach(content => content.classList.remove('active')); tabButtons[index].classList.add('active'); tabContents[index].classList.add('active'); currentTabIndex = index; updateTabButtons(); }; tabButtons.forEach((button, index) => button.addEventListener('click', () => switchTab(index))); prevTabBtn.addEventListener('click', () => { if (currentTabIndex > 0) switchTab(currentTabIndex - 1); }); nextTabBtn.addEventListener('click', () => { if (currentTabIndex < tabContents.length - 1) switchTab(currentTabIndex + 1); }); // --- INITIALIZATION --- if (kpiCardsContainer && addEventBtn && downloadPdfBtn) { addEventBtn.addEventListener('click', handleAddEvent); downloadPdfBtn.addEventListener('click', handleDownloadPdf); renderAll(); updateTabButtons(); } else { console.error("Essential dashboard elements could not be found."); } });
Scroll to Top