From b3d88e6f6e5916de5c7b1d2b9fc658bc129c2d8d Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 1 Jul 2021 00:37:13 +0200 Subject: [PATCH] Some general fixes, deprecated rrdir (use Files::rmrf) --- .../include/class/ConsoleSupervisor.php | 8 +++-- pandora_console/include/functions_db.php | 31 ++++++++++++++++--- .../include/functions_update_manager.php | 2 ++ pandora_console/include/lib/Tools/Files.php | 15 +++++++-- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 539504cd94..59f022b586 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -26,6 +26,8 @@ * ============================================================================ */ +use PandoraFMS\Tools\Files; + global $config; require_once $config['homedir'].'/include/functions_db.php'; @@ -2645,13 +2647,15 @@ class ConsoleSupervisor { global $config; - if ((int) $config['clean_phantomjs_cache'] !== 1) { + if (isset($config['clean_phantomjs_cache']) !== true + || (int) $config['clean_phantomjs_cache'] !== 1 + ) { return; } $cache_dir = $config['homedir'].'/attachment/cache'; if (is_dir($cache_dir) === true) { - rrmdir($cache_dir); + Files::rmrf($cache_dir); } // Clean process has ended. diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index aed0cfaf55..df2e9aa979 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -2241,7 +2241,10 @@ function db_get_lock(string $lockname, int $expiration_time=86400) :?int global $config; // Temporary disable to get a valid lock if any... - $cache = $config['dbcache']; + if (isset($config['dbcache']) === true) { + $cache = $config['dbcache']; + } + $config['dbcache'] = false; $lock_status = db_get_value_sql( @@ -2260,7 +2263,12 @@ function db_get_lock(string $lockname, int $expiration_time=86400) :?int ) ); - $config['dbcache'] = $cache; + if (isset($cache) === true) { + $config['dbcache'] = $cache; + } else { + unset($config['dbcache']); + } + if ($lock_status === false) { return null; } @@ -2268,7 +2276,12 @@ function db_get_lock(string $lockname, int $expiration_time=86400) :?int return (int) $lock_status; } - $config['dbcache'] = $cache; + if (isset($cache) === true) { + $config['dbcache'] = $cache; + } else { + unset($config['dbcache']); + } + return 0; } @@ -2285,7 +2298,11 @@ function db_get_lock(string $lockname, int $expiration_time=86400) :?int function db_release_lock($lockname) { global $config; - $cache = $config['dbcache']; + // Temporary disable to get a valid lock if any... + if (isset($config['dbcache']) === true) { + $cache = $config['dbcache']; + } + $config['dbcache'] = false; $return = db_get_value_sql( @@ -2295,7 +2312,11 @@ function db_release_lock($lockname) ) ); - $config['dbcache'] = $cache; + if (isset($cache) === true) { + $config['dbcache'] = $cache; + } else { + unset($config['dbcache']); + } return $return; diff --git a/pandora_console/include/functions_update_manager.php b/pandora_console/include/functions_update_manager.php index 7251bcec40..f9c8ad90c8 100755 --- a/pandora_console/include/functions_update_manager.php +++ b/pandora_console/include/functions_update_manager.php @@ -244,6 +244,8 @@ function update_manager_get_messages() * * @param string $dir Path to dir. * + * @deprecated 755 Use Files::rmrf. + * * @return void */ function rrmdir($dir) diff --git a/pandora_console/include/lib/Tools/Files.php b/pandora_console/include/lib/Tools/Files.php index 903b167878..7b9b8892a3 100644 --- a/pandora_console/include/lib/Tools/Files.php +++ b/pandora_console/include/lib/Tools/Files.php @@ -113,9 +113,18 @@ class Files } $zip = new \ZipArchive; - if ($zip->open($file, (\ZipArchive::RDONLY & \ZipArchive::ER_READ)) === true) { - $zip->close(); - return true; + if (defined('\ZipArchive::RDONLY') === true) { + // PHP >= 7.4. + if ($zip->open($file, (\ZipArchive::RDONLY)) === true) { + $zip->close(); + return true; + } + } else { + // PHP < 7.4. + if ($zip->open($file, (\ZipArchive::CHECKCONS)) === true) { + $zip->close(); + return true; + } } return false;