Files
GLPI-Plugin-CVE-Prototype/scripts/sync_cve.php
2025-05-31 10:03:48 +02:00

57 lines
1.4 KiB
PHP

#!/usr/bin/env php
<?php
/**
* GLPI CVE Plugin - CLI Sync Script
* This script can be called from cron to sync CVE data
*/
// Define GLPI's constants
define('GLPI_ROOT', dirname(__FILE__, 4));
// Include necessary files
include(GLPI_ROOT . "/inc/autoload.function.php");
include(GLPI_ROOT . "/inc/db.function.php");
include_once(GLPI_ROOT . "/inc/includes.php");
// No time limit for potentially long-running operation
set_time_limit(0);
// Ensure CLI mode is used
if (PHP_SAPI != 'cli') {
echo "This script must be run from command line";
exit(1);
}
// Initialize GLPI
$DB = new DB();
Session::setPath();
Session::start();
Session::loadLanguage();
// Use GLPI's CLI mode
if (!Session::getLoginUserID()) {
Session::setGlpiSessionPath();
Session::setGlpiSessionID('cli_' . getmypid());
$_SESSION['glpi_use_mode'] = Session::NORMAL_MODE;
$_SESSION['glpiname'] = 'cli_cve_sync';
Session::loadGroups();
}
// Run the CVE synchronization
$task = new CronTask();
if ($task->getFromDBbyName('PluginCveCveSource', 'SyncCVESources')) {
echo "Starting CVE synchronization...\n";
$result = PluginCveCveSource::cronSyncSources($task);
if ($result) {
echo "CVE synchronization completed successfully.\n";
exit(0);
} else {
echo "CVE synchronization failed or no sources to sync.\n";
exit(1);
}
} else {
echo "CVE synchronization task not found.\n";
exit(1);
}