Files
GLPI-Plugin-CVE-Prototype/front/dashboard.php

176 lines
6.3 KiB
PHP

<?php
/**
* GLPI CVE Plugin - Dashboard Page
*/
include ("../../../inc/includes.php");
Session::checkRight("plugin_cve_cve", READ);
Html::header(
__('Dashboard', 'cve'),
$_SERVER['PHP_SELF'],
"tools",
"PluginCveCveMenu",
"dashboard"
);
// Get statistical data
$cve_stats = PluginCveCve::getCVEStatsDashboard();
$severity_data = PluginCveCve::getCVESeverityDashboard();
$recent_cves = PluginCveCve::getRecentCVEsDashboard();
$alert_stats = PluginCveCveAlert::getAlertStats();
// Display dashboard
echo "<div class='center'>";
// Statistics cards
echo "<div class='dashboard-card-container'>";
// Critical vulnerabilities card
echo "<div class='dashboard-card dashboard-card-critical'>";
echo "<div class='dashboard-card-icon'><i class='fas fa-exclamation-triangle'></i></div>";
echo "<div class='dashboard-card-content'>";
echo "<div class='dashboard-card-title'>" . __('Critical Vulnerabilities', 'cve') . "</div>";
echo "<div class='dashboard-card-value'>" . ($cve_stats['severity']['CRITICAL'] ?? 0) . "</div>";
echo "</div>";
echo "</div>";
// High risk card
echo "<div class='dashboard-card dashboard-card-high'>";
echo "<div class='dashboard-card-icon'><i class='fas fa-exclamation-circle'></i></div>";
echo "<div class='dashboard-card-content'>";
echo "<div class='dashboard-card-title'>" . __('High Vulnerabilities', 'cve') . "</div>";
echo "<div class='dashboard-card-value'>" . ($cve_stats['severity']['HIGH'] ?? 0) . "</div>";
echo "</div>";
echo "</div>";
// New alerts card
echo "<div class='dashboard-card dashboard-card-new'>";
echo "<div class='dashboard-card-icon'><i class='fas fa-bell'></i></div>";
echo "<div class='dashboard-card-content'>";
echo "<div class='dashboard-card-title'>" . __('New Alerts', 'cve') . "</div>";
echo "<div class='dashboard-card-value'>" . ($alert_stats['by_status']['NEW'] ?? 0) . "</div>";
echo "</div>";
echo "</div>";
// Resolved card
echo "<div class='dashboard-card dashboard-card-resolved'>";
echo "<div class='dashboard-card-icon'><i class='fas fa-check-circle'></i></div>";
echo "<div class='dashboard-card-content'>";
echo "<div class='dashboard-card-title'>" . __('Resolved', 'cve') . "</div>";
echo "<div class='dashboard-card-value'>" . ($cve_stats['status']['RESOLVED'] ?? 0) . "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
// Severity distribution chart
if (!empty($severity_data)) {
echo "<div class='dashboard-chart-container'>";
echo "<h2>" . __('CVE Severity Distribution', 'cve') . "</h2>";
echo "<div id='severity-chart'>";
// This would be replaced with an actual chart library in production
echo "<div class='severity-chart-bars'>";
foreach ($severity_data['labels'] as $i => $label) {
$value = $severity_data['series'][$i]['data'][0] ?? 0;
$color = $severity_data['series'][$i]['color'] ?? '#999999';
echo "<div class='severity-chart-bar-container'>";
echo "<div class='severity-chart-label'>" . $label . "</div>";
echo "<div class='severity-chart-bar' style='height: " . min(100, max(5, ($value / max(1, array_sum(array_column($severity_data['series'], 'data')[0])) * 100))) . "%; background-color: " . $color . ";'></div>";
echo "<div class='severity-chart-value'>" . $value . "</div>";
echo "</div>";
}
echo "</div>";
echo "</div>";
echo "</div>";
}
// Recent CVEs table
if (!empty($recent_cves)) {
echo "<div class='dashboard-table-container'>";
echo "<h2>" . __('Recent CVEs', 'cve') . "</h2>";
echo "<table class='tab_cadre_fixehov'>";
echo "<tr>";
foreach ($recent_cves['headers'] as $header) {
echo "<th>" . $header . "</th>";
}
echo "</tr>";
foreach ($recent_cves['rows'] as $row) {
echo "<tr class='tab_bg_1'>";
echo "<td><a href='" . PluginCveCve::getFormURLWithID($row['id'] ?? 0) . "'>" . $row['cve_id'] . "</a></td>";
echo "<td><span class='" . PluginCveCve::getSeverityClass($row['severity']) . "'>" . $row['severity'] . "</span></td>";
echo "<td>" . $row['cvss_score'] . "</td>";
echo "<td>" . Html::convDateTime($row['published']) . "</td>";
echo "<td><span class='" . PluginCveCve::getStatusClass($row['status']) . "'>" . $row['status'] . "</span></td>";
echo "</tr>";
}
echo "</table>";
echo "<div class='center'><a href='cve.php'>" . __('View all CVEs', 'cve') . "</a></div>";
echo "</div>";
}
// Device Vulnerability Alerts
echo "<div class='dashboard-table-container'>";
echo "<h2>" . __('Alerts by Device', 'cve') . "</h2>";
echo "<table class='tab_cadre_fixehov'>";
echo "<tr>";
echo "<th>" . __('Device', 'cve') . "</th>";
echo "<th>" . __('Total Alerts', 'cve') . "</th>";
echo "<th>" . __('Critical', 'cve') . "</th>";
echo "<th>" . __('High', 'cve') . "</th>";
echo "<th></th>";
echo "</tr>";
// This would be populated with actual data from the database
// Placeholder for demonstration purposes
$deviceAlerts = [
['name' => 'Windows Server 2019', 'alerts' => 12, 'critical' => 3, 'high' => 6],
['name' => 'Ubuntu 20.04 LTS', 'alerts' => 8, 'critical' => 2, 'high' => 3],
['name' => 'macOS Monterey', 'alerts' => 5, 'critical' => 0, 'high' => 2],
['name' => 'Cisco IOS Router', 'alerts' => 7, 'critical' => 4, 'high' => 2],
['name' => 'Database Server', 'alerts' => 9, 'critical' => 1, 'high' => 5],
];
foreach ($deviceAlerts as $device) {
echo "<tr class='tab_bg_1'>";
echo "<td>" . $device['name'] . "</td>";
echo "<td>" . $device['alerts'] . "</td>";
// Critical alerts with badge
echo "<td>";
if ($device['critical'] > 0) {
echo "<span class='cve-severity-critical badge'>" . $device['critical'] . "</span>";
} else {
echo "0";
}
echo "</td>";
// High alerts with badge
echo "<td>";
if ($device['high'] > 0) {
echo "<span class='cve-severity-high badge'>" . $device['high'] . "</span>";
} else {
echo "0";
}
echo "</td>";
echo "<td class='center'>";
echo "<a href='alert.php?criteria[0][field]=2&criteria[0][searchtype]=contains&criteria[0][value]=" . urlencode($device['name']) . "'>" . __('View', 'cve') . "</a>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "<div class='center'><a href='alert.php'>" . __('View all alerts', 'cve') . "</a></div>";
echo "</div>";
echo "</div>"; // End of dashboard container
Html::footer();