172 lines
4.9 KiB
PHP
172 lines
4.9 KiB
PHP
<?php
|
|
/*
|
|
* Plugin SIEM-Wazuh pour GLPI
|
|
* Interface de gestion des serveurs Wazuh
|
|
*/
|
|
|
|
include ('../../../inc/includes.php');
|
|
|
|
// Vérification des droits
|
|
Session::checkRight("plugin_siem_wazuh_server", READ);
|
|
|
|
// Vérification du plugin
|
|
if (!Plugin::isPluginActive('siem-wazuh')) {
|
|
Html::displayNotFoundError();
|
|
}
|
|
|
|
// Initialisation de l'affichage
|
|
Html::header(
|
|
PluginSiemWazuhServer::getTypeName(Session::getPluralNumber()),
|
|
$_SERVER['PHP_SELF'],
|
|
'admin',
|
|
'PluginSiemWazuhServer'
|
|
);
|
|
|
|
// Gestion des actions
|
|
if (isset($_GET['action'])) {
|
|
$server = new PluginSiemWazuhServer();
|
|
|
|
switch ($_GET['action']) {
|
|
case 'test_connection':
|
|
if (isset($_GET['id']) && $server->getFromDB($_GET['id'])) {
|
|
$result = $server->testConnection();
|
|
echo json_encode($result);
|
|
exit;
|
|
}
|
|
break;
|
|
|
|
case 'sync_alerts':
|
|
if (isset($_GET['id']) && $server->getFromDB($_GET['id'])) {
|
|
$result = $server->syncAlerts();
|
|
echo json_encode($result);
|
|
exit;
|
|
}
|
|
break;
|
|
|
|
case 'toggle_active':
|
|
if (isset($_GET['id']) && $server->getFromDB($_GET['id'])) {
|
|
if (Session::haveRight("plugin_siem_wazuh_server", UPDATE)) {
|
|
$new_status = $server->fields['is_active'] ? 0 : 1;
|
|
$server->update([
|
|
'id' => $_GET['id'],
|
|
'is_active' => $new_status
|
|
]);
|
|
Session::addMessageAfterRedirect(
|
|
$new_status ? __('Server activated', 'siem-wazuh') : __('Server deactivated', 'siem-wazuh')
|
|
);
|
|
}
|
|
}
|
|
Html::back();
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Initialisation de la recherche
|
|
$search = Search::show('PluginSiemWazuhServer');
|
|
|
|
// Ajout de CSS pour l'interface
|
|
echo "<style>
|
|
.server-status {
|
|
display: inline-block;
|
|
padding: 3px 8px;
|
|
border-radius: 3px;
|
|
font-size: 11px;
|
|
font-weight: bold;
|
|
}
|
|
.server-status.active {
|
|
background-color: #5cb85c;
|
|
color: white;
|
|
}
|
|
.server-status.inactive {
|
|
background-color: #d9534f;
|
|
color: white;
|
|
}
|
|
.sync-status {
|
|
font-size: 11px;
|
|
color: #666;
|
|
}
|
|
.action-buttons {
|
|
white-space: nowrap;
|
|
}
|
|
.action-buttons .btn {
|
|
margin: 0 2px;
|
|
padding: 2px 6px;
|
|
font-size: 11px;
|
|
}
|
|
</style>";
|
|
|
|
// Ajout de JavaScript pour les actions AJAX
|
|
echo "<script>
|
|
function testWazuhConnection(serverId) {
|
|
var button = document.querySelector('.test-connection-' + serverId);
|
|
var resultDiv = document.getElementById('test-result-' + serverId);
|
|
|
|
if (button) {
|
|
button.disabled = true;
|
|
button.innerHTML = '" . __('Testing...', 'siem-wazuh') . "';
|
|
}
|
|
|
|
fetch('?action=test_connection&id=' + serverId)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (resultDiv) {
|
|
if (data.success) {
|
|
resultDiv.innerHTML = '<div class=\"alert alert-success\">' + data.message + '</div>';
|
|
} else {
|
|
resultDiv.innerHTML = '<div class=\"alert alert-danger\">' + data.message + '</div>';
|
|
}
|
|
}
|
|
})
|
|
.catch(error => {
|
|
if (resultDiv) {
|
|
resultDiv.innerHTML = '<div class=\"alert alert-danger\">" . __('Connection test failed', 'siem-wazuh') . "</div>';
|
|
}
|
|
})
|
|
.finally(() => {
|
|
if (button) {
|
|
button.disabled = false;
|
|
button.innerHTML = '" . __('Test Connection', 'siem-wazuh') . "';
|
|
}
|
|
});
|
|
}
|
|
|
|
function syncWazuhAlerts(serverId) {
|
|
if (!confirm('" . __('Are you sure you want to synchronize alerts from this server?', 'siem-wazuh') . "')) {
|
|
return;
|
|
}
|
|
|
|
var button = document.querySelector('.sync-alerts-' + serverId);
|
|
if (button) {
|
|
button.disabled = true;
|
|
button.innerHTML = '" . __('Synchronizing...', 'siem-wazuh') . "';
|
|
}
|
|
|
|
fetch('?action=sync_alerts&id=' + serverId)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
alert(data.message);
|
|
location.reload();
|
|
} else {
|
|
alert('" . __('Sync failed:', 'siem-wazuh') . " ' + data.message);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
alert('" . __('An error occurred during synchronization', 'siem-wazuh') . "');
|
|
})
|
|
.finally(() => {
|
|
if (button) {
|
|
button.disabled = false;
|
|
button.innerHTML = '" . __('Sync Alerts', 'siem-wazuh') . "';
|
|
}
|
|
});
|
|
}
|
|
|
|
function toggleServerStatus(serverId) {
|
|
if (confirm('" . __('Are you sure you want to change the status of this server?', 'siem-wazuh') . "')) {
|
|
window.location.href = '?action=toggle_active&id=' + serverId;
|
|
}
|
|
}
|
|
</script>";
|
|
|
|
Html::footer(); |