first sync
This commit is contained in:
393
front/wazuhconfig.php
Normal file
393
front/wazuhconfig.php
Normal file
@@ -0,0 +1,393 @@
|
||||
<?php
|
||||
/*
|
||||
* Plugin SIEM-Wazuh pour GLPI
|
||||
* Interface de configuration du plugin
|
||||
*/
|
||||
|
||||
include ('../../../inc/includes.php');
|
||||
|
||||
// Vérification des droits
|
||||
Session::checkRight("plugin_siem_wazuh_config", READ);
|
||||
|
||||
// Vérification du plugin
|
||||
if (!Plugin::isPluginActive('siem-wazuh')) {
|
||||
Html::displayNotFoundError();
|
||||
}
|
||||
|
||||
$config = new PluginSiemWazuhConfig();
|
||||
|
||||
// Traitement du formulaire
|
||||
$config->processConfigForm();
|
||||
|
||||
// Initialisation de l'affichage
|
||||
Html::header(
|
||||
PluginSiemWazuhConfig::getTypeName(1),
|
||||
$_SERVER['PHP_SELF'],
|
||||
'tools',
|
||||
'PluginSiemWazuhConfig'
|
||||
);
|
||||
|
||||
echo "<div class='spaced'>";
|
||||
|
||||
// Affichage des onglets de configuration
|
||||
$tabs = [
|
||||
'config' => __('Configuration', 'siem-wazuh'),
|
||||
'mapping' => __('Asset Mapping', 'siem-wazuh'),
|
||||
'notifications' => __('Notifications', 'siem-wazuh'),
|
||||
'debug' => __('Debug & Logs', 'siem-wazuh')
|
||||
];
|
||||
|
||||
$active_tab = $_GET['tab'] ?? 'config';
|
||||
|
||||
echo "<div class='config-tabs'>";
|
||||
echo "<ul class='nav nav-tabs'>";
|
||||
foreach ($tabs as $tab_key => $tab_name) {
|
||||
$active_class = ($active_tab == $tab_key) ? ' active' : '';
|
||||
echo "<li class='nav-item'>";
|
||||
echo "<a class='nav-link$active_class' href='?tab=$tab_key'>$tab_name</a>";
|
||||
echo "</li>";
|
||||
}
|
||||
echo "</ul>";
|
||||
echo "</div>";
|
||||
|
||||
echo "<div class='tab-content'>";
|
||||
|
||||
switch ($active_tab) {
|
||||
case 'config':
|
||||
// Configuration générale
|
||||
$config->showConfigForm();
|
||||
break;
|
||||
|
||||
case 'mapping':
|
||||
// Configuration du mapping des assets
|
||||
echo "<div class='tab-pane active'>";
|
||||
echo "<h3>" . __('Asset Mapping Configuration', 'siem-wazuh') . "</h3>";
|
||||
showMappingConfiguration($config);
|
||||
echo "</div>";
|
||||
break;
|
||||
|
||||
case 'notifications':
|
||||
// Configuration des notifications
|
||||
echo "<div class='tab-pane active'>";
|
||||
echo "<h3>" . __('Notification Configuration', 'siem-wazuh') . "</h3>";
|
||||
showNotificationConfiguration($config);
|
||||
echo "</div>";
|
||||
break;
|
||||
|
||||
case 'debug':
|
||||
// Configuration de debug et logs
|
||||
echo "<div class='tab-pane active'>";
|
||||
echo "<h3>" . __('Debug & Logs Configuration', 'siem-wazuh') . "</h3>";
|
||||
showDebugConfiguration($config);
|
||||
showRecentLogs();
|
||||
echo "</div>";
|
||||
break;
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
echo "</div>";
|
||||
|
||||
/**
|
||||
* Show mapping configuration
|
||||
*/
|
||||
function showMappingConfiguration($config) {
|
||||
echo "<form method='post' action=''>";
|
||||
echo "<table class='tab_cadre_fixe'>";
|
||||
echo "<tr class='tab_bg_2'>";
|
||||
echo "<th colspan='4'>" . __('Asset Detection Rules', 'siem-wazuh') . "</th>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
echo "<td>" . __('Match computers by hostname', 'siem-wazuh') . "</td>";
|
||||
echo "<td>";
|
||||
Dropdown::showYesNo("match_computers_hostname", $config->getConfiguration('match_computers_hostname', 1));
|
||||
echo "</td>";
|
||||
echo "<td>" . __('Match network equipment by hostname', 'siem-wazuh') . "</td>";
|
||||
echo "<td>";
|
||||
Dropdown::showYesNo("match_netequip_hostname", $config->getConfiguration('match_netequip_hostname', 1));
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
echo "<td>" . __('Match by IP address', 'siem-wazuh') . "</td>";
|
||||
echo "<td>";
|
||||
Dropdown::showYesNo("match_by_ip", $config->getConfiguration('match_by_ip', 1));
|
||||
echo "</td>";
|
||||
echo "<td>" . __('Case sensitive matching', 'siem-wazuh') . "</td>";
|
||||
echo "<td>";
|
||||
Dropdown::showYesNo("case_sensitive_matching", $config->getConfiguration('case_sensitive_matching', 0));
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
echo "<td>" . __('Hostname patterns to ignore', 'siem-wazuh') . "</td>";
|
||||
echo "<td colspan='3'>";
|
||||
echo "<textarea name='ignore_hostname_patterns' rows='3' cols='80' placeholder='localhost,127.0.0.1,*.local'>";
|
||||
echo $config->getConfiguration('ignore_hostname_patterns', '');
|
||||
echo "</textarea>";
|
||||
echo "<br><small>" . __('One pattern per line. Use * as wildcard.', 'siem-wazuh') . "</small>";
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "<tr class='tab_bg_2'>";
|
||||
echo "<td class='center' colspan='4'>";
|
||||
echo "<input type='submit' name='update_mapping' value='" . _sx('button', 'Save') . "' class='submit'>";
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "</table>";
|
||||
echo Html::closeForm();
|
||||
|
||||
// Test de correspondance
|
||||
echo "<br>";
|
||||
echo "<table class='tab_cadre_fixe'>";
|
||||
echo "<tr class='tab_bg_2'>";
|
||||
echo "<th colspan='2'>" . __('Test Asset Mapping', 'siem-wazuh') . "</th>";
|
||||
echo "</tr>";
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
echo "<td>" . __('Agent name or IP', 'siem-wazuh') . "</td>";
|
||||
echo "<td>";
|
||||
echo "<input type='text' name='test_agent' id='test_agent' size='30' placeholder='agent-hostname or 192.168.1.100'>";
|
||||
echo " <button type='button' onclick='testAssetMapping()' class='btn btn-primary'>" . __('Test', 'siem-wazuh') . "</button>";
|
||||
echo "<div id='mapping_result' style='margin-top: 10px;'></div>";
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
echo "</table>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Show notification configuration
|
||||
*/
|
||||
function showNotificationConfiguration($config) {
|
||||
echo "<form method='post' action=''>";
|
||||
echo "<table class='tab_cadre_fixe'>";
|
||||
echo "<tr class='tab_bg_2'>";
|
||||
echo "<th colspan='4'>" . __('Email Notifications', 'siem-wazuh') . "</th>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
echo "<td>" . __('Enable email notifications', 'siem-wazuh') . "</td>";
|
||||
echo "<td>";
|
||||
Dropdown::showYesNo("email_notifications", $config->getConfiguration('email_notifications', 1));
|
||||
echo "</td>";
|
||||
echo "<td>" . __('Notification for critical alerts only', 'siem-wazuh') . "</td>";
|
||||
echo "<td>";
|
||||
Dropdown::showYesNo("notify_critical_only", $config->getConfiguration('notify_critical_only', 0));
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
echo "<td>" . __('Default notification recipients', 'siem-wazuh') . "</td>";
|
||||
echo "<td colspan='3'>";
|
||||
echo "<input type='text' name='notification_recipients' size='80' value='" . $config->getConfiguration('notification_recipients', '') . "' placeholder='admin@domain.com, security@domain.com'>";
|
||||
echo "<br><small>" . __('Comma-separated email addresses', 'siem-wazuh') . "</small>";
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "<tr class='tab_bg_2'>";
|
||||
echo "<td class='center' colspan='4'>";
|
||||
echo "<input type='submit' name='update_notifications' value='" . _sx('button', 'Save') . "' class='submit'>";
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "</table>";
|
||||
echo Html::closeForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show debug configuration
|
||||
*/
|
||||
function showDebugConfiguration($config) {
|
||||
echo "<form method='post' action=''>";
|
||||
echo "<table class='tab_cadre_fixe'>";
|
||||
echo "<tr class='tab_bg_2'>";
|
||||
echo "<th colspan='4'>" . __('Debug Configuration', 'siem-wazuh') . "</th>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
echo "<td>" . __('Enable debug mode', 'siem-wazuh') . "</td>";
|
||||
echo "<td>";
|
||||
Dropdown::showYesNo("debug_mode", $config->getConfiguration('debug_mode', 0));
|
||||
echo "</td>";
|
||||
echo "<td>" . __('Log API requests', 'siem-wazuh') . "</td>";
|
||||
echo "<td>";
|
||||
Dropdown::showYesNo("log_api_requests", $config->getConfiguration('log_api_requests', 0));
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
echo "<td>" . __('Log level', 'siem-wazuh') . "</td>";
|
||||
echo "<td>";
|
||||
$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' => $config->getConfiguration('log_level', 'info')
|
||||
]);
|
||||
echo "</td>";
|
||||
echo "<td>" . __('Keep logs for (days)', 'siem-wazuh') . "</td>";
|
||||
echo "<td>";
|
||||
Dropdown::showNumber("log_retention_days", [
|
||||
'value' => $config->getConfiguration('log_retention_days', 30),
|
||||
'min' => 1,
|
||||
'max' => 365
|
||||
]);
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "<tr class='tab_bg_2'>";
|
||||
echo "<td class='center' colspan='2'>";
|
||||
echo "<input type='submit' name='update_debug' value='" . _sx('button', 'Save') . "' class='submit'>";
|
||||
echo "</td>";
|
||||
echo "<td class='center' colspan='2'>";
|
||||
echo "<button type='button' onclick='clearLogs()' class='btn btn-warning'>" . __('Clear All Logs', 'siem-wazuh') . "</button>";
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "</table>";
|
||||
echo Html::closeForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show recent logs
|
||||
*/
|
||||
function showRecentLogs() {
|
||||
global $DB;
|
||||
|
||||
echo "<br>";
|
||||
echo "<table class='tab_cadre_fixehov'>";
|
||||
echo "<tr class='tab_bg_2'>";
|
||||
echo "<th colspan='4'>" . __('Recent Logs', 'siem-wazuh') . " (100 dernières entrées)</th>";
|
||||
echo "</tr>";
|
||||
|
||||
echo "<tr class='tab_bg_2'>";
|
||||
echo "<th>" . __('Date') . "</th>";
|
||||
echo "<th>" . __('Level') . "</th>";
|
||||
echo "<th>" . __('Server') . "</th>";
|
||||
echo "<th>" . __('Message') . "</th>";
|
||||
echo "</tr>";
|
||||
|
||||
$iterator = $DB->request([
|
||||
'SELECT' => [
|
||||
'glpi_plugin_siem_wazuh_logs.*',
|
||||
'glpi_plugin_siem_wazuh_servers.name AS server_name'
|
||||
],
|
||||
'FROM' => 'glpi_plugin_siem_wazuh_logs',
|
||||
'LEFT JOIN' => [
|
||||
'glpi_plugin_siem_wazuh_servers' => [
|
||||
'ON' => [
|
||||
'glpi_plugin_siem_wazuh_logs' => 'wazuh_server_id',
|
||||
'glpi_plugin_siem_wazuh_servers' => 'id'
|
||||
]
|
||||
]
|
||||
],
|
||||
'ORDER' => 'date_creation DESC',
|
||||
'LIMIT' => 100
|
||||
]);
|
||||
|
||||
if (count($iterator) == 0) {
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
echo "<td colspan='4' class='center'>" . __('No logs found', 'siem-wazuh') . "</td>";
|
||||
echo "</tr>";
|
||||
} else {
|
||||
foreach ($iterator as $log) {
|
||||
$level_class = 'log-' . $log['level'];
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
echo "<td>" . Html::convDateTime($log['date_creation']) . "</td>";
|
||||
echo "<td><span class='badge $level_class'>" . ucfirst($log['level']) . "</span></td>";
|
||||
echo "<td>" . ($log['server_name'] ?: __('System', 'siem-wazuh')) . "</td>";
|
||||
echo "<td>" . Html::clean($log['message']) . "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
}
|
||||
|
||||
echo "</table>";
|
||||
}
|
||||
|
||||
// JavaScript pour les fonctionnalités interactives
|
||||
echo "<script>
|
||||
function testAssetMapping() {
|
||||
var agentValue = document.getElementById('test_agent').value;
|
||||
if (!agentValue) {
|
||||
alert('" . __('Please enter an agent name or IP address', 'siem-wazuh') . "');
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('" . Plugin::getWebDir('siem-wazuh') . "/ajax/test_mapping.php', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: 'agent=' + encodeURIComponent(agentValue)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
var resultDiv = document.getElementById('mapping_result');
|
||||
if (data.success) {
|
||||
resultDiv.innerHTML = '<div class=\"alert alert-success\">' + data.message + '</div>';
|
||||
} else {
|
||||
resultDiv.innerHTML = '<div class=\"alert alert-info\">' + data.message + '</div>';
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
document.getElementById('mapping_result').innerHTML = '<div class=\"alert alert-danger\">" . __('Test failed', 'siem-wazuh') . "</div>';
|
||||
});
|
||||
}
|
||||
|
||||
function clearLogs() {
|
||||
if (confirm('" . __('Are you sure you want to clear all logs?', 'siem-wazuh') . "')) {
|
||||
fetch('" . Plugin::getWebDir('siem-wazuh') . "/ajax/clear_logs.php', {
|
||||
method: 'POST'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
alert('" . __('Logs cleared successfully', 'siem-wazuh') . "');
|
||||
location.reload();
|
||||
} else {
|
||||
alert('" . __('Failed to clear logs', 'siem-wazuh') . "');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>";
|
||||
|
||||
// CSS pour les logs et badges
|
||||
echo "<style>
|
||||
.config-tabs .nav-tabs {
|
||||
border-bottom: 1px solid #ddd;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.config-tabs .nav-item {
|
||||
display: inline-block;
|
||||
}
|
||||
.config-tabs .nav-link {
|
||||
display: block;
|
||||
padding: 10px 15px;
|
||||
text-decoration: none;
|
||||
color: #337ab7;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 4px 4px 0 0;
|
||||
margin-right: 2px;
|
||||
}
|
||||
.config-tabs .nav-link:hover,
|
||||
.config-tabs .nav-link.active {
|
||||
background-color: #337ab7;
|
||||
color: white;
|
||||
border-color: #337ab7;
|
||||
}
|
||||
.log-debug { background-color: #d1ecf1; color: #0c5460; }
|
||||
.log-info { background-color: #bee5eb; color: #0c5460; }
|
||||
.log-warning { background-color: #fff3cd; color: #856404; }
|
||||
.log-error { background-color: #f8d7da; color: #721c24; }
|
||||
.log-critical { background-color: #f5c6cb; color: #721c24; }
|
||||
.alert { padding: 10px; margin: 10px 0; border-radius: 4px; }
|
||||
.alert-success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
|
||||
.alert-danger { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
|
||||
.alert-info { background-color: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
|
||||
</style>";
|
||||
|
||||
Html::footer();
|
Reference in New Issue
Block a user