first sync
This commit is contained in:
81
ajax/test_connection.php
Normal file
81
ajax/test_connection.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/*
|
||||
* Plugin SIEM-Wazuh pour GLPI
|
||||
* AJAX - Test de connexion aux serveurs Wazuh
|
||||
*/
|
||||
|
||||
include ('../../../inc/includes.php');
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// Vérification des droits et du plugin
|
||||
if (!Session::haveRight("plugin_siem_wazuh_server", READ) || !Plugin::isPluginActive('siem-wazuh')) {
|
||||
echo json_encode(['success' => false, 'message' => __('Access denied', 'siem-wazuh')]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Vérification CSRF
|
||||
if (!Session::validateCSRF($_POST)) {
|
||||
echo json_encode(['success' => false, 'message' => __('Invalid CSRF token', 'siem-wazuh')]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$response = ['success' => false, 'message' => ''];
|
||||
|
||||
try {
|
||||
$server_id = intval($_POST['server_id'] ?? 0);
|
||||
|
||||
if ($server_id <= 0) {
|
||||
throw new Exception(__('Invalid server ID', 'siem-wazuh'));
|
||||
}
|
||||
|
||||
$server = new PluginSiemWazuhServer();
|
||||
if (!$server->getFromDB($server_id)) {
|
||||
throw new Exception(__('Server not found', 'siem-wazuh'));
|
||||
}
|
||||
|
||||
// Test de connexion
|
||||
$result = $server->testConnection();
|
||||
|
||||
if ($result['success']) {
|
||||
$response = [
|
||||
'success' => true,
|
||||
'message' => $result['message'],
|
||||
'server_info' => $result['data'] ?? null,
|
||||
'timestamp' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
// Log du test réussi
|
||||
Event::log(
|
||||
$server_id,
|
||||
"PluginSiemWazuhServer",
|
||||
5,
|
||||
"connection",
|
||||
sprintf(__('Connection test successful for server %s'), $server->fields['name'])
|
||||
);
|
||||
} else {
|
||||
$response = [
|
||||
'success' => false,
|
||||
'message' => $result['message'],
|
||||
'error_type' => 'connection_failed'
|
||||
];
|
||||
|
||||
// Log du test échoué
|
||||
Event::log(
|
||||
$server_id,
|
||||
"PluginSiemWazuhServer",
|
||||
2,
|
||||
"connection",
|
||||
sprintf(__('Connection test failed for server %s: %s'), $server->fields['name'], $result['message'])
|
||||
);
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
$response = [
|
||||
'success' => false,
|
||||
'message' => $e->getMessage(),
|
||||
'error_type' => 'exception'
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
Reference in New Issue
Block a user