mirror of
https://github.com/tips-of-mine/GLPI-Plugin-CVE-Prototype.git
synced 2025-06-27 14:48:45 +02:00
171 lines
4.5 KiB
PHP
171 lines
4.5 KiB
PHP
<?php
|
|
/**
|
|
* GLPI CVE Plugin - Hook functions
|
|
* Contains installation and uninstallation functions
|
|
*/
|
|
|
|
if (!defined('GLPI_ROOT')) {
|
|
die("Sorry. You can't access this file directly");
|
|
}
|
|
|
|
/**
|
|
* Hook called when a ticket is created
|
|
*
|
|
* @param Ticket $ticket
|
|
*/
|
|
function plugin_cve_item_add_ticket(Ticket $ticket) {
|
|
// Check if the ticket is related to a CVE
|
|
// This would be implemented with actual logic to link tickets with CVEs
|
|
}
|
|
|
|
/**
|
|
* Hook called when a ticket is updated
|
|
*
|
|
* @param Ticket $ticket
|
|
*/
|
|
function plugin_cve_item_update_ticket(Ticket $ticket) {
|
|
// Check if the ticket is related to a CVE and update the CVE status if needed
|
|
// This would be implemented with actual status update logic
|
|
}
|
|
|
|
/**
|
|
* Hook called before a ticket is purged
|
|
*
|
|
* @param Ticket $ticket
|
|
*/
|
|
function plugin_cve_pre_item_purge_ticket(Ticket $ticket) {
|
|
// Remove any CVE associations before the ticket is purged
|
|
$cveTicket = new PluginCveCveTicket();
|
|
$cveTicket->deleteByCriteria(['tickets_id' => $ticket->getID()]);
|
|
|
|
// Also remove any alert associations
|
|
$alert = new PluginCveCveAlert();
|
|
$alert->deleteByCriteria(['tickets_id' => $ticket->getID()]);
|
|
}
|
|
|
|
/**
|
|
* Create dashboard cards for the plugin
|
|
*
|
|
* @param array $cards
|
|
* @return array
|
|
*/
|
|
function plugin_cve_dashboard_cards($cards) {
|
|
$new_cards = [];
|
|
|
|
// Add CVE statistics card
|
|
$new_cards['plugin_cve_stats'] = [
|
|
'widgettype' => 'statscard',
|
|
'title' => __('CVE Statistics', 'cve'),
|
|
'icon' => 'ti ti-shield',
|
|
'provider' => 'PluginCveCve::getCVEStatsDashboard'
|
|
];
|
|
|
|
// Add CVE severity distribution card
|
|
$new_cards['plugin_cve_severity'] = [
|
|
'widgettype' => 'donut',
|
|
'title' => __('CVE Severity Distribution', 'cve'),
|
|
'icon' => 'ti ti-chart-pie',
|
|
'provider' => 'PluginCveCve::getCVESeverityDashboard'
|
|
];
|
|
|
|
// Add recent CVEs card
|
|
$new_cards['plugin_cve_recent'] = [
|
|
'widgettype' => 'table',
|
|
'title' => __('Recent CVEs', 'cve'),
|
|
'icon' => 'ti ti-list',
|
|
'provider' => 'PluginCveCve::getRecentCVEsDashboard'
|
|
];
|
|
|
|
// Add software vulnerability statistics card
|
|
$new_cards['plugin_cve_software_vulnerabilities'] = [
|
|
'widgettype' => 'statscard',
|
|
'title' => __('Software Vulnerability Alerts', 'cve'),
|
|
'icon' => 'ti ti-alert-triangle',
|
|
'provider' => 'PluginCveCveAlert::getAlertStats'
|
|
];
|
|
|
|
return array_merge($cards, $new_cards);
|
|
}
|
|
|
|
/**
|
|
* Create the tables needed to run plugin
|
|
*
|
|
* @return boolean
|
|
*/
|
|
function plugin_cve_createTables() {
|
|
plugin_cve_install();
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Migration function
|
|
*
|
|
* @param string $version Version to upgrade from
|
|
* @return boolean
|
|
*/
|
|
function plugin_cve_upgradeTables($version) {
|
|
// Handle migrations based on version
|
|
// This would be implemented with version-specific upgrades
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Add plugin entries to GLPI's search engine
|
|
*
|
|
* @param string $itemtype
|
|
* @return array
|
|
*/
|
|
function plugin_cve_getAddSearchOptions($itemtype) {
|
|
$options = [];
|
|
|
|
if ($itemtype == 'Ticket') {
|
|
$options[9100] = [
|
|
'table' => 'glpi_plugin_cve_tickets',
|
|
'field' => 'id',
|
|
'name' => __('Associated CVEs', 'cve'),
|
|
'massiveaction' => false,
|
|
'joinparams' => [
|
|
'jointype' => 'child',
|
|
'condition' => "AND `REFTABLE`.`id` = `TABLE`.`tickets_id`"
|
|
]
|
|
];
|
|
}
|
|
|
|
if ($itemtype == 'Software') {
|
|
$options[9200] = [
|
|
'table' => 'glpi_plugin_cve_alerts',
|
|
'field' => 'id',
|
|
'name' => __('Vulnerability Alerts', 'cve'),
|
|
'massiveaction' => false,
|
|
'joinparams' => [
|
|
'jointype' => 'child',
|
|
'condition' => "AND `REFTABLE`.`id` = `TABLE`.`softwares_id`"
|
|
]
|
|
];
|
|
|
|
$options[9201] = [
|
|
'table' => 'glpi_plugin_cve_alerts',
|
|
'field' => 'severity',
|
|
'name' => __('Vulnerability Severity', 'cve'),
|
|
'massiveaction' => false,
|
|
'joinparams' => [
|
|
'jointype' => 'child',
|
|
'condition' => "AND `REFTABLE`.`id` = `TABLE`.`softwares_id`"
|
|
]
|
|
];
|
|
}
|
|
|
|
return $options;
|
|
}
|
|
|
|
/**
|
|
* Datainjection hook
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
function plugin_datainjection_populate_cve($data) {
|
|
// Logic for data injection support
|
|
// This would be implemented with actual data mapping logic
|
|
return $data;
|
|
} |