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

57 lines
1.3 KiB
PHP

#!/usr/bin/env php
<?php
/**
* GLPI CVE Plugin - CLI Cleanup Script
* This script removes old CVE data no longer needed
*/
// 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_cleanup';
Session::loadGroups();
}
// Run the CVE cleanup task
$task = new CronTask();
if ($task->getFromDBbyName('PluginCveCve', 'CleanOldCVEs')) {
echo "Starting CVE cleanup...\n";
$result = PluginCveCve::cronCleanOldCVEs($task);
if ($result) {
echo "CVE cleanup completed successfully.\n";
exit(0);
} else {
echo "CVE cleanup failed or no data to clean.\n";
exit(1);
}
} else {
echo "CVE cleanup task not found.\n";
exit(1);
}