Files
GLPI-Plugin-CVE-Prototype/front/inventory.php
2025-05-31 10:03:48 +02:00

162 lines
4.7 KiB
PHP

<?php
/**
* GLPI CVE Plugin - Software Inventory Analysis Page
*/
include ("../../../inc/includes.php");
Session::checkRight("plugin_cve_inventory", READ);
Html::header(
PluginCveCveInventory::getTypeName(Session::getPluralNumber()),
$_SERVER['PHP_SELF'],
"tools",
"PluginCveCveMenu",
"inventory"
);
// Manual scan trigger
if (isset($_POST['scan_now']) && Session::haveRight("plugin_cve_inventory", UPDATE)) {
$task = new CronTask();
if ($task->getFromDBbyName('PluginCveCveInventory', 'AnalyzeInventory')) {
$task_id = $task->fields['id'];
// Execute the task
$result = PluginCveCveInventory::cronAnalyzeInventory($task);
if ($result) {
Session::addMessageAfterRedirect(
__('Software vulnerability analysis completed successfully.', 'cve'),
true,
INFO
);
} else {
Session::addMessageAfterRedirect(
__('Software vulnerability analysis completed with no new alerts.', 'cve'),
true,
INFO
);
}
} else {
Session::addMessageAfterRedirect(
__('Software vulnerability analysis task not found.', 'cve'),
true,
ERROR
);
}
Html::redirect($_SERVER['PHP_SELF']);
} else {
$alert = new PluginCveCveAlert();
// Get alert statistics
$stats = PluginCveCveAlert::getAlertStats();
echo "<div class='center'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Software Vulnerability Analysis', 'cve') . "</th></tr>";
// Show manual scan button
if (Session::haveRight("plugin_cve_inventory", UPDATE)) {
echo "<tr class='tab_bg_1'><td colspan='2' class='center'>";
echo "<form method='post' action='" . $_SERVER['PHP_SELF'] . "'>";
echo "<input type='submit' name='scan_now' value=\"" . __('Scan Software Inventory Now', 'cve') . "\" class='submit'>";
Html::closeForm();
echo "</td></tr>";
}
// Show statistics
echo "<tr class='tab_bg_2'>";
echo "<td>" . __('Total Vulnerability Alerts', 'cve') . "</td>";
echo "<td>" . $stats['total'] . "</td>";
echo "</tr>";
echo "<tr class='tab_bg_2'>";
echo "<td>" . __('New Alerts', 'cve') . "</td>";
echo "<td>" . $stats['by_status']['NEW'] . "</td>";
echo "</tr>";
echo "<tr class='tab_bg_2'>";
echo "<td>" . __('Critical Vulnerabilities', 'cve') . "</td>";
echo "<td>" . $stats['by_severity']['CRITICAL'] . "</td>";
echo "</tr>";
echo "<tr class='tab_bg_2'>";
echo "<td>" . __('High Vulnerabilities', 'cve') . "</td>";
echo "<td>" . $stats['by_severity']['HIGH'] . "</td>";
echo "</tr>";
echo "</table>";
echo "</div>";
// Show recent alerts
$alerts = PluginCveCveAlert::getRecentAlerts(10);
echo "<div class='center'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_2'><th colspan='6'>" . __('Recent Vulnerability Alerts', 'cve') . "</th></tr>";
echo "<tr class='tab_bg_1'>";
echo "<th>" . __('Software', 'cve') . "</th>";
echo "<th>" . __('Version', 'cve') . "</th>";
echo "<th>" . __('CVE ID', 'cve') . "</th>";
echo "<th>" . __('Severity', 'cve') . "</th>";
echo "<th>" . __('Status', 'cve') . "</th>";
echo "<th>" . __('Date', 'cve') . "</th>";
echo "</tr>";
if (empty($alerts)) {
echo "<tr class='tab_bg_1'><td colspan='6' class='center'>" . __('No alerts found', 'cve') . "</td></tr>";
} else {
foreach ($alerts as $alert_data) {
echo "<tr class='tab_bg_1'>";
// Software
echo "<td>";
echo $alert_data['software_name'];
echo "</td>";
// Version
echo "<td>";
echo $alert_data['version_name'];
echo "</td>";
// CVE ID
echo "<td>";
echo "<a href='" . PluginCveCve::getFormURLWithID($alert_data['cves_id']) . "'>";
echo $alert_data['cve_id'];
echo "</a>";
echo "</td>";
// Severity
echo "<td>";
echo "<span class='" . PluginCveCve::getSeverityClass($alert_data['severity']) . "'>";
echo $alert_data['severity'];
echo "</span>";
echo "</td>";
// Status
echo "<td>";
echo $alert_data['status'];
echo "</td>";
// Date
echo "<td>";
echo Html::convDateTime($alert_data['date_creation']);
echo "</td>";
echo "</tr>";
}
}
echo "</table>";
// Link to all alerts
echo "<div class='center'>";
echo "<a href='alert.php'>" . __('View all vulnerability alerts', 'cve') . "</a>";
echo "</div>";
echo "</div>";
}
Html::footer();