request([ 'FROM' => $this->getTable(), 'WHERE' => [ 'name' => $name, 'context' => $context ], 'LIMIT' => 1 ]); if (count($iterator) > 0) { $row = $iterator->current(); return $row['value']; } return $default; } /** * Set configuration value */ function setConfiguration($name, $value, $context = 'global') { global $DB; // Vérifier si la configuration existe $iterator = $DB->request([ 'FROM' => $this->getTable(), 'WHERE' => [ 'name' => $name, 'context' => $context ], 'LIMIT' => 1 ]); if (count($iterator) > 0) { // Mettre à jour $row = $iterator->current(); return $this->update([ 'id' => $row['id'], 'value' => $value ]); } else { // Créer return $this->add([ 'name' => $name, 'value' => $value, 'context' => $context ]); } } /** * Display configuration form */ function showConfigForm() { global $CFG_GLPI; echo "
"; echo "
"; echo ""; echo ""; // Configuration générale echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; // Configuration des tickets par défaut echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; if ($this->getConfiguration('auto_assign_tickets', 0)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } // Configuration de mapping echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; // Configuration de debug echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
" . __('General Configuration', 'siem-wazuh') . "
" . __('Enable synchronization', 'siem-wazuh') . ""; Dropdown::showYesNo("sync_enabled", $this->getConfiguration('sync_enabled', 1)); echo "" . __('Auto-create tickets', 'siem-wazuh') . ""; Dropdown::showYesNo("auto_create_ticket", $this->getConfiguration('auto_create_ticket', 1)); echo "
" . __('Maximum alerts per sync', 'siem-wazuh') . ""; Dropdown::showNumber("max_alerts_per_sync", [ 'value' => $this->getConfiguration('max_alerts_per_sync', 100), 'min' => 10, 'max' => 1000, 'step' => 10 ]); echo "" . __('Alert retention (days)', 'siem-wazuh') . ""; Dropdown::showNumber("alert_retention_days", [ 'value' => $this->getConfiguration('alert_retention_days', 90), 'min' => 7, 'max' => 365, 'step' => 7 ]); echo "
" . __('Minimum rule level', 'siem-wazuh') . ""; Dropdown::showNumber("min_rule_level", [ 'value' => $this->getConfiguration('min_rule_level', 5), 'min' => 0, 'max' => 15 ]); echo "" . __('Enable notifications', 'siem-wazuh') . ""; Dropdown::showYesNo("notification_enabled", $this->getConfiguration('notification_enabled', 1)); echo "
" . __('Default Ticket Settings', 'siem-wazuh') . "
" . __('Default Priority', 'siem-wazuh') . ""; Ticket::dropdownPriority('default_ticket_priority', $this->getConfiguration('default_ticket_priority', 3)); echo "" . __('Default Urgency', 'siem-wazuh') . ""; Ticket::dropdownUrgency('default_ticket_urgency', $this->getConfiguration('default_ticket_urgency', 3)); echo "
" . __('Default Impact', 'siem-wazuh') . ""; Ticket::dropdownImpact('default_ticket_impact', $this->getConfiguration('default_ticket_impact', 3)); echo "" . __('Auto-assign tickets', 'siem-wazuh') . ""; Dropdown::showYesNo("auto_assign_tickets", $this->getConfiguration('auto_assign_tickets', 0)); echo "
" . __('Default Assignee', 'siem-wazuh') . ""; User::dropdown([ 'name' => 'default_assignee', 'value' => $this->getConfiguration('default_assignee', 0), 'right' => 'own_ticket' ]); echo "" . __('Default Group', 'siem-wazuh') . ""; Group::dropdown([ 'name' => 'default_group', 'value' => $this->getConfiguration('default_group', 0) ]); echo "
" . __('Asset Mapping Configuration', 'siem-wazuh') . "
" . __('Match by hostname', 'siem-wazuh') . ""; Dropdown::showYesNo("match_by_hostname", $this->getConfiguration('match_by_hostname', 1)); echo "" . __('Match by IP address', 'siem-wazuh') . ""; Dropdown::showYesNo("match_by_ip", $this->getConfiguration('match_by_ip', 1)); echo "
" . __('Case sensitive matching', 'siem-wazuh') . ""; Dropdown::showYesNo("case_sensitive_matching", $this->getConfiguration('case_sensitive_matching', 0)); echo "" . __('Create unknown assets', 'siem-wazuh') . ""; Dropdown::showYesNo("create_unknown_assets", $this->getConfiguration('create_unknown_assets', 0)); echo "
" . __('Debug Configuration', 'siem-wazuh') . "
" . __('Enable debug mode', 'siem-wazuh') . ""; Dropdown::showYesNo("debug_mode", $this->getConfiguration('debug_mode', 0)); echo "" . __('Log level', 'siem-wazuh') . ""; $log_levels = [ 'error' => __('Error only', 'siem-wazuh'), 'warning' => __('Warning and above', 'siem-wazuh'), 'info' => __('Info and above', 'siem-wazuh'), 'debug' => __('All messages', 'siem-wazuh') ]; Dropdown::showFromArray('log_level', $log_levels, [ 'value' => $this->getConfiguration('log_level', 'info') ]); echo "
" . __('Keep debug logs (days)', 'siem-wazuh') . ""; Dropdown::showNumber("debug_retention_days", [ 'value' => $this->getConfiguration('debug_retention_days', 30), 'min' => 1, 'max' => 90 ]); echo "
"; echo ""; echo "
"; echo "
"; Html::closeForm(); // Affichage des statistiques $this->showStatistics(); } /** * Process configuration form */ function processConfigForm() { if (isset($_POST['update_config'])) { $config_fields = [ 'sync_enabled', 'auto_create_ticket', 'max_alerts_per_sync', 'alert_retention_days', 'min_rule_level', 'notification_enabled', 'default_ticket_priority', 'default_ticket_urgency', 'default_ticket_impact', 'auto_assign_tickets', 'default_assignee', 'default_group', 'match_by_hostname', 'match_by_ip', 'case_sensitive_matching', 'create_unknown_assets', 'debug_mode', 'log_level', 'debug_retention_days' ]; foreach ($config_fields as $field) { if (isset($_POST[$field])) { $this->setConfiguration($field, $_POST[$field]); } } Session::addMessageAfterRedirect(__('Configuration updated successfully', 'siem-wazuh')); Html::back(); } } /** * Show statistics */ function showStatistics() { global $DB; echo "
"; echo ""; echo ""; // Statistiques des serveurs $servers_count = countElementsInTable('glpi_plugin_siem_wazuh_servers'); $active_servers = countElementsInTable('glpi_plugin_siem_wazuh_servers', ['is_active' => 1]); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; // Statistiques des alertes $total_alerts = countElementsInTable('glpi_plugin_siem_wazuh_alerts'); $new_alerts = countElementsInTable('glpi_plugin_siem_wazuh_alerts', ['status' => 'new']); $processed_alerts = countElementsInTable('glpi_plugin_siem_wazuh_alerts', ['status' => 'processed']); $tickets_created = countElementsInTable('glpi_plugin_siem_wazuh_alerts', ['status' => 'ticket_created']); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; // Alertes par sévérité $severities = PluginSiemWazuhAlert::getSeverityArray(); foreach ($severities as $severity => $label) { $count = countElementsInTable('glpi_plugin_siem_wazuh_alerts', ['severity' => $severity]); echo ""; echo ""; echo ""; if (next($severities) !== false) { $next_severity = key($severities); $next_label = current($severities); $next_count = countElementsInTable('glpi_plugin_siem_wazuh_alerts', ['severity' => $next_severity]); echo ""; echo ""; next($severities); } else { echo ""; } echo ""; } // Dernière synchronisation $last_sync = $DB->request([ 'SELECT' => ['MAX' => 'last_sync AS last_sync'], 'FROM' => 'glpi_plugin_siem_wazuh_servers', 'WHERE' => ['is_active' => 1] ])->current(); echo ""; echo ""; echo ""; echo ""; echo "
" . __('Statistics', 'siem-wazuh') . "
" . __('Total servers', 'siem-wazuh') . "$servers_count" . __('Active servers', 'siem-wazuh') . "$active_servers
" . __('Total alerts', 'siem-wazuh') . "$total_alerts" . __('New alerts', 'siem-wazuh') . "$new_alerts
" . __('Processed alerts', 'siem-wazuh') . "$processed_alerts" . __('Tickets created', 'siem-wazuh') . "$tickets_created
" . sprintf(__('%s alerts', 'siem-wazuh'), $label) . "$count" . sprintf(__('%s alerts', 'siem-wazuh'), $next_label) . "$next_count
" . __('Last global sync', 'siem-wazuh') . ""; echo $last_sync['last_sync'] ? Html::convDateTime($last_sync['last_sync']) : __('Never'); echo "
"; echo "
"; } /** * Get menu content */ static function getMenuContent() { $menu = []; if (Session::haveRight(static::$rightname, READ)) { $menu['title'] = self::getMenuName(); $menu['page'] = "/plugins/siem-wazuh/front/wazuhconfig.php"; $menu['links']['config'] = "/plugins/siem-wazuh/front/wazuhconfig.php"; } return $menu; } /** * Get menu name */ static function getMenuName() { return self::getTypeName(1); } /** * Get default configurations */ static function getDefaultConfigurations() { return [ 'sync_enabled' => 1, 'auto_create_ticket' => 1, 'max_alerts_per_sync' => 100, 'alert_retention_days' => 90, 'min_rule_level' => 5, 'notification_enabled' => 1, 'default_ticket_priority' => 3, 'default_ticket_urgency' => 3, 'default_ticket_impact' => 3, 'auto_assign_tickets' => 0, 'default_assignee' => 0, 'default_group' => 0, 'match_by_hostname' => 1, 'match_by_ip' => 1, 'case_sensitive_matching' => 0, 'create_unknown_assets' => 0, 'debug_mode' => 0, 'log_level' => 'info', 'debug_retention_days' => 30 ]; } /** * Install default configuration */ static function installDefaultConfiguration() { $config = new self(); $defaults = self::getDefaultConfigurations(); foreach ($defaults as $name => $value) { $config->setConfiguration($name, $value); } } }