235 lines
6.8 KiB
PHP
235 lines
6.8 KiB
PHP
<?php
|
|
/*
|
|
* Plugin SIEM-Wazuh pour GLPI
|
|
* Description: Intégration SIEM Wazuh avec GLPI
|
|
* Version: 1.0.0
|
|
*/
|
|
|
|
define('PLUGIN_SIEM_WAZUH_VERSION', '1.0.0');
|
|
define('PLUGIN_SIEM_WAZUH_MIN_GLPI', '10.0.0');
|
|
define('PLUGIN_SIEM_WAZUH_MAX_GLPI', '10.0.99');
|
|
|
|
/**
|
|
* Plugin init function
|
|
*/
|
|
function plugin_init_siem_wazuh() {
|
|
global $PLUGIN_HOOKS, $CFG_GLPI;
|
|
|
|
$PLUGIN_HOOKS['csrf_compliant']['siem-wazuh'] = true;
|
|
|
|
// Enregistrement du plugin
|
|
Plugin::registerClass('PluginSiemWazuhServer', [
|
|
'linkgroup' => 'admin',
|
|
'linktext' => __('Wazuh Servers', 'siem-wazuh'),
|
|
'icon' => 'fas fa-shield-alt'
|
|
]);
|
|
|
|
Plugin::registerClass('PluginSiemWazuhConfig', [
|
|
'linkgroup' => 'tools',
|
|
'linktext' => __('SIEM Wazuh Configuration', 'siem-wazuh'),
|
|
'icon' => 'fas fa-cogs'
|
|
]);
|
|
|
|
Plugin::registerClass('PluginSiemWazuhAlert');
|
|
|
|
// Ajout des menus
|
|
if (Session::haveRight('plugin_siem_wazuh_server', READ)) {
|
|
$PLUGIN_HOOKS['menu_toadd']['siem-wazuh']['admin'] = 'PluginSiemWazuhServer';
|
|
}
|
|
|
|
if (Session::haveRight('plugin_siem_wazuh_config', READ)) {
|
|
$PLUGIN_HOOKS['menu_toadd']['siem-wazuh']['tools'] = 'PluginSiemWazuhConfig';
|
|
}
|
|
|
|
// Ajout des onglets sur les éléments
|
|
$PLUGIN_HOOKS['item_add_targets']['siem-wazuh'] = [
|
|
'Computer' => ['PluginSiemWazuhTab'],
|
|
'NetworkEquipment' => ['PluginSiemWazuhTab'],
|
|
'Peripheral' => ['PluginSiemWazuhTab'],
|
|
'Phone' => ['PluginSiemWazuhTab'],
|
|
'Printer' => ['PluginSiemWazuhTab']
|
|
];
|
|
|
|
// Hook pour l'affichage des onglets
|
|
$PLUGIN_HOOKS['display_item']['siem-wazuh'] = 'plugin_siem_wazuh_display_item';
|
|
|
|
// Hook pour les actions automatiques (cron)
|
|
$PLUGIN_HOOKS['cron']['siem-wazuh'] = 1;
|
|
|
|
// Hook pour les droits
|
|
$PLUGIN_HOOKS['change_profile']['siem-wazuh'] = ['PluginSiemWazuhProfile', 'changeProfile'];
|
|
$PLUGIN_HOOKS['init_profile']['siem-wazuh'] = ['PluginSiemWazuhProfile', 'initProfile'];
|
|
|
|
// CSS et JS
|
|
$PLUGIN_HOOKS['add_css']['siem-wazuh'][] = 'css/style.css';
|
|
$PLUGIN_HOOKS['add_javascript']['siem-wazuh'][] = 'js/wazuh.js';
|
|
|
|
// Import/Export
|
|
$PLUGIN_HOOKS['import_item']['siem-wazuh'] = ['Computer', 'NetworkEquipment'];
|
|
|
|
// Notification
|
|
$PLUGIN_HOOKS['item_get_events']['siem-wazuh'] = [
|
|
'PluginSiemWazuhAlert' => ['PluginSiemWazuhAlert', 'getEvents']
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Plugin version function
|
|
*/
|
|
function plugin_version_siem_wazuh() {
|
|
return [
|
|
'name' => 'SIEM - Wazuh',
|
|
'version' => PLUGIN_SIEM_WAZUH_VERSION,
|
|
'author' => 'SIEM-Wazuh Team',
|
|
'license' => 'GPLv2+',
|
|
'homepage' => 'https://github.com/siem-wazuh/glpi-plugin',
|
|
'requirements' => [
|
|
'glpi' => [
|
|
'min' => PLUGIN_SIEM_WAZUH_MIN_GLPI,
|
|
'max' => PLUGIN_SIEM_WAZUH_MAX_GLPI,
|
|
],
|
|
'php' => [
|
|
'min' => '7.4',
|
|
],
|
|
'params' => [
|
|
'check_prerequisites' => true,
|
|
]
|
|
]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Check plugin prerequisites
|
|
*/
|
|
function plugin_siem_wazuh_check_prerequisites() {
|
|
// Vérification de la version PHP
|
|
if (version_compare(PHP_VERSION, '7.4', '<')) {
|
|
echo "Ce plugin nécessite PHP 7.4 ou supérieur";
|
|
return false;
|
|
}
|
|
|
|
// Vérification de la version GLPI
|
|
if (!method_exists('Plugin', 'checkGlpiVersion')) {
|
|
echo "Cette version de GLPI n'est pas supportée";
|
|
return false;
|
|
}
|
|
|
|
if (!Plugin::checkGlpiVersion(PLUGIN_SIEM_WAZUH_MIN_GLPI, PLUGIN_SIEM_WAZUH_MAX_GLPI)) {
|
|
echo "Ce plugin nécessite GLPI >= " . PLUGIN_SIEM_WAZUH_MIN_GLPI . " et < " . PLUGIN_SIEM_WAZUH_MAX_GLPI;
|
|
return false;
|
|
}
|
|
|
|
// Vérification des extensions PHP nécessaires
|
|
$required_extensions = ['curl', 'json', 'mbstring', 'openssl'];
|
|
foreach ($required_extensions as $ext) {
|
|
if (!extension_loaded($ext)) {
|
|
echo "Extension PHP manquante: $ext";
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Check plugin configuration
|
|
*/
|
|
function plugin_siem_wazuh_check_config() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Plugin display item hook
|
|
*/
|
|
function plugin_siem_wazuh_display_item($item) {
|
|
if (in_array($item->getType(), ['Computer', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer'])) {
|
|
if (Session::haveRight('plugin_siem_wazuh_alert', READ)) {
|
|
$tab = new PluginSiemWazuhTab();
|
|
$tab->showForItem($item);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get cron description
|
|
*/
|
|
function plugin_siem_wazuh_cron_description($name) {
|
|
switch ($name) {
|
|
case 'sync_alerts':
|
|
return __('Synchronize Wazuh alerts', 'siem-wazuh');
|
|
case 'cleanup_old_alerts':
|
|
return __('Cleanup old alerts', 'siem-wazuh');
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Execute cron task
|
|
*/
|
|
function plugin_siem_wazuh_cron($name) {
|
|
global $DB;
|
|
|
|
switch ($name) {
|
|
case 'sync_alerts':
|
|
return PluginSiemWazuhAlert::cronSyncAlerts();
|
|
|
|
case 'cleanup_old_alerts':
|
|
return PluginSiemWazuhAlert::cronCleanupOldAlerts();
|
|
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get additional menu entries
|
|
*/
|
|
function plugin_siem_wazuh_get_additional_menu_entries($forcetab = '') {
|
|
$entries = [];
|
|
|
|
if (Session::haveRight('plugin_siem_wazuh_server', READ)) {
|
|
$entries['<img src="' . Plugin::getWebDir('siem-wazuh') . '/pics/wazuh-logo.png" width="16" height="16" alt=""> ' .
|
|
__('Wazuh Servers', 'siem-wazuh')] = '/plugins/siem-wazuh/front/wazuhserver.php';
|
|
}
|
|
|
|
return $entries;
|
|
}
|
|
|
|
/**
|
|
* Get dropdown values
|
|
*/
|
|
function plugin_siem_wazuh_get_dropdown_values($post, $dropdown_name = '') {
|
|
switch ($dropdown_name) {
|
|
case 'PluginSiemWazuhServer':
|
|
return PluginSiemWazuhServer::getDropdownValues($post);
|
|
default:
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get search options
|
|
*/
|
|
function plugin_siem_wazuh_getAddSearchOptions($itemtype) {
|
|
$sopt = [];
|
|
|
|
switch ($itemtype) {
|
|
case 'Computer':
|
|
case 'NetworkEquipment':
|
|
$sopt[5150]['table'] = 'glpi_plugin_siem_wazuh_alerts';
|
|
$sopt[5150]['field'] = 'id';
|
|
$sopt[5150]['name'] = __('Wazuh Alerts', 'siem-wazuh');
|
|
$sopt[5150]['forcegroupby'] = true;
|
|
$sopt[5150]['usehaving'] = true;
|
|
$sopt[5150]['datatype'] = 'count';
|
|
$sopt[5150]['massiveaction'] = false;
|
|
$sopt[5150]['joinparams'] = [
|
|
'jointype' => 'itemtype_item',
|
|
'specific_itemtype' => $itemtype
|
|
];
|
|
break;
|
|
}
|
|
|
|
return $sopt;
|
|
} |