mirror of
https://github.com/tips-of-mine/GLPI-Plugin-CVE-Prototype.git
synced 2025-06-28 07:08:44 +02:00
Start repository
This commit is contained in:
66
ajax/sync_now.php
Normal file
66
ajax/sync_now.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* GLPI CVE Plugin - Immediate Sync Handler
|
||||
* This file handles immediate synchronization requests
|
||||
*/
|
||||
|
||||
include ("../../../inc/includes.php");
|
||||
|
||||
// Check CSRF token
|
||||
Session::checkLoginUser();
|
||||
Session::checkRight("config", UPDATE);
|
||||
|
||||
// Force no time limit for long-running operations
|
||||
set_time_limit(0);
|
||||
|
||||
// Start synchronization of all active sources
|
||||
$source = new PluginCveCveSource();
|
||||
$sources = $source->find(['is_active' => 1]);
|
||||
|
||||
$success = true;
|
||||
$count = 0;
|
||||
|
||||
foreach ($sources as $data) {
|
||||
$source->getFromDB($data['id']);
|
||||
|
||||
// Log the start of sync
|
||||
Toolbox::logInFile('cve_plugin', sprintf('Starting synchronization of source: %s (ID: %d)',
|
||||
$data['name'], $data['id']));
|
||||
|
||||
// Update source status to in progress
|
||||
$source->update([
|
||||
'id' => $data['id'],
|
||||
'sync_status' => 'IN_PROGRESS',
|
||||
]);
|
||||
|
||||
try {
|
||||
$result = $source->syncNow($data['id']);
|
||||
$count += $result ? 1 : 0;
|
||||
$success = $success && $result;
|
||||
|
||||
// Log the result
|
||||
Toolbox::logInFile('cve_plugin', sprintf('Sync of source %s %s',
|
||||
$data['name'], ($result ? 'succeeded' : 'failed')));
|
||||
} catch (Exception $e) {
|
||||
$success = false;
|
||||
|
||||
// Log the error
|
||||
Toolbox::logInFile('cve_plugin', sprintf('Error during sync of source %s: %s',
|
||||
$data['name'], $e->getMessage()), true);
|
||||
|
||||
// Update source status to failed
|
||||
$source->update([
|
||||
'id' => $data['id'],
|
||||
'sync_status' => 'FAILED',
|
||||
'last_sync' => $_SESSION['glpi_currenttime']
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Log the overall result
|
||||
if ($count > 0) {
|
||||
Toolbox::logInFile('cve_plugin', sprintf('CVE synchronization completed: %d sources processed with %s',
|
||||
$count, ($success ? 'success' : 'some failures')));
|
||||
}
|
||||
|
||||
// No HTML output needed for background task
|
Reference in New Issue
Block a user