diff --git a/pandora_console/extras/delete_files/delete_files.txt b/pandora_console/extras/delete_files/delete_files.txt index 2419ea0cb3..7e9650d18c 100644 --- a/pandora_console/extras/delete_files/delete_files.txt +++ b/pandora_console/extras/delete_files/delete_files.txt @@ -74,4 +74,7 @@ enterprise/extensions/ipam enterprise/extensions/disabled/visual_console_manager.php enterprise/extensions/visual_console_manager.php pandora_console/extensions/net_tools.php +include/lib/WSManager.php +include/lib/WebSocketServer.php +include/lib/WebSocketUser.php operation/network/network_explorer.php diff --git a/pandora_console/godmode/setup/performance.php b/pandora_console/godmode/setup/performance.php index 995ef3365e..d3a71e641f 100644 --- a/pandora_console/godmode/setup/performance.php +++ b/pandora_console/godmode/setup/performance.php @@ -29,7 +29,10 @@ // Load global vars. global $config; -require_once 'include/config.php'; +require_once $config['homedir'].'/include/config.php'; +require_once $config['homedir'].'/vendor/autoload.php'; + +use PandoraFMS\Core\Config; check_login(); @@ -388,44 +391,11 @@ if ($config['history_db_enabled'] == 1) { ); } - $config_history = false; - if ($config['history_db_connection']) { - $history_connect = mysql_db_process_sql( - 'DESCRIBE tconfig', - 'affected_rows', - $config['history_db_connection'], - false - ); - - if ($history_connect !== false) { - $config_history_array = mysql_db_process_sql( - 'SELECT * FROM tconfig', - 'affected_rows', - $config['history_db_connection'], - false - ); - - if (isset($config_history_array) && is_array($config_history_array)) { - foreach ($config_history_array as $key => $value) { - $config_history[$value['token']] = $value['value']; - $config_history = true; - } - } - } else { - echo ui_print_error_message( - __('The tconfig table does not exist in the historical database') - ); - } - } - - if ($config_history === false) { - $config_history = []; - $config_history['days_purge'] = 180; - $config_history['days_compact'] = 120; - $config_history['step_compact'] = 1; - $config_history['event_purge'] = 180; - $config_history['string_purge'] = 180; - } + $config_history['days_purge'] = Config::get('days_purge', 180, true); + $config_history['days_compact'] = Config::get('days_compact', 120, true); + $config_history['step_compact'] = Config::get('step_compact', 1, true); + $config_history['event_purge'] = Config::get('event_purge', 180, true); + $config_history['string_purge'] = Config::get('string_purge', 180, true); $table_historical = new StdClass(); $table_historical->width = '100%'; diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index 3f1867591e..a7c6cccf25 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -337,6 +337,18 @@ if (isset($config['error_config_update_config'])) { ui_print_success_message(__('Correct update the setup options')); } + if (is_array($config['error_config_update_config']['errors']) === true) { + foreach ($config['error_config_update_config']['errors'] as $msg) { + ui_print_error_message($msg); + } + } + + if (is_array($config['error_config_update_config']['warnings']) === true) { + foreach ($config['error_config_update_config']['warnings'] as $msg) { + ui_print_warning_message($msg); + } + } + unset($config['error_config_update_config']); } diff --git a/pandora_console/include/ajax/rolling_release.ajax.php b/pandora_console/include/ajax/rolling_release.ajax.php index 1ce72167a0..d802a2d9ee 100644 --- a/pandora_console/include/ajax/rolling_release.ajax.php +++ b/pandora_console/include/ajax/rolling_release.ajax.php @@ -88,6 +88,11 @@ if (is_ajax()) { $file_dest = $config['homedir']."/extras/mr/updated/$number.sql"; copy($file, $file_dest); + + // After successfully update, schedule history + // database upgrade. + enterprise_include_once('include/functions_config.php'); + enterprise_hook('history_db_install'); } } else { $error_file = fopen($config['homedir'].'/extras/mr/error.txt', 'w'); diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 231e35a00a..6833e14d6f 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -148,7 +148,8 @@ class ConsoleSupervisor */ public function runBasic() { - global $config; + // Ensure functions are installed and up to date. + enterprise_hook('cron_extension_install_functions'); /* * PHP configuration warnings: diff --git a/pandora_console/include/class/HelpFeedBack.class.php b/pandora_console/include/class/HelpFeedBack.class.php index 2c6cd0e677..7b035dd74e 100644 --- a/pandora_console/include/class/HelpFeedBack.class.php +++ b/pandora_console/include/class/HelpFeedBack.class.php @@ -236,6 +236,7 @@ class HelpFeedBack extends Wizard */ public function sendMailMethod() { + global $config; $suggestion = get_parameter('type', 'false'); $feedback_text = get_parameter('feedback_text', null); $feedback_mail = get_parameter('feedback_email', null); diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 61888f79c3..f38b4c5ec9 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -97,7 +97,7 @@ require_once $ownDir.'functions.php'; // We need a timezone BEFORE calling config_process_config. // If not we will get ugly warnings. Set Europe/Madrid by default // Later will be replaced by the good one. -if (!is_dir($_SERVER['DOCUMENT_ROOT'].$config['homeurl']) || !is_dir($_SERVER['DOCUMENT_ROOT'].$config['homeurl_static'])) { +if (!is_dir($config['homedir'])) { $url = explode('/', $_SERVER['REQUEST_URI']); $flag_url = 0; foreach ($url as $key => $value) { diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index 13e59f7247..8b7c81c9f9 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -1496,6 +1496,7 @@ function db_run_sql_file($location) // Undo results } + $config['db_run_sql_file_error'] = $mysqli->error; return false; } } diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 49ae33b20d..322e630485 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -26,7 +26,12 @@ * ============================================================================ */ - // Config functions. +// Config functions. +require_once __DIR__.'/../vendor/autoload.php'; +require_once __DIR__.'/functions.php'; +enterprise_include_once('include/functions_config.php'); +use PandoraFMS\Core\DBMaintainer; +use PandoraFMS\Core\Config; /** @@ -147,6 +152,8 @@ function config_update_config() } $error_update = []; + $errors = []; + $warnings = []; $sec2 = get_parameter('sec2'); @@ -1452,6 +1459,31 @@ function config_update_config() break; case 'hist_db': + if ($config['dbname'] == get_parameter('history_db_name') + && $config['dbport'] == get_parameter('history_db_port') + && $config['dbhost'] == io_input_password(get_parameter('history_db_host')) + ) { + // Same definition for active and historical database! + // This is a critical error. + $config['error_config_update_config']['correct'] = false; + $config['error_config_update_config']['message'] = __( + 'Active and historical database cannot be the same.' + ); + return; + } else { + if (!config_update_value('history_db_host', get_parameter('history_db_host'))) { + $error_update[] = __('Host'); + } + + if (!config_update_value('history_db_port', get_parameter('history_db_port'))) { + $error_update[] = __('Port'); + } + + if (!config_update_value('history_db_name', get_parameter('history_db_name'))) { + $error_update[] = __('Database name'); + } + } + if (!config_update_value('history_db_enabled', get_parameter('history_db_enabled'))) { $error_update[] = __('Enable history database'); } @@ -1460,18 +1492,6 @@ function config_update_config() $error_update[] = __('Enable history event'); } - if (!config_update_value('history_db_host', get_parameter('history_db_host'))) { - $error_update[] = __('Host'); - } - - if (!config_update_value('history_db_port', get_parameter('history_db_port'))) { - $error_update[] = __('Port'); - } - - if (!config_update_value('history_db_name', get_parameter('history_db_name'))) { - $error_update[] = __('Database name'); - } - if (!config_update_value('history_db_user', get_parameter('history_db_user'))) { $error_update[] = __('Database user'); } @@ -1511,6 +1531,68 @@ function config_update_config() ) { $error_update[] = __('Delay'); } + + if ((bool) $config['history_db_enabled'] === true) { + $dbm = new DBMaintainer( + [ + 'host' => $config['history_db_host'], + 'port' => $config['history_db_port'], + 'name' => $config['history_db_name'], + 'user' => $config['history_db_user'], + 'pass' => $config['history_db_pass'], + ] + ); + + // Performs several checks and installs if needed. + if ($dbm->checkDatabaseDefinition() === true + && $dbm->isInstalled() === false + ) { + // Target is ready but several tasks are pending. + $dbm->process(); + } else if ($dbm->check() !== true) { + $errors[] = $dbm->getLastError(); + } + } + + // Historical configuration tokens (stored in historical db). + if (Config::set( + 'days_purge', + get_parameter('history_dbh_purge'), + true + ) !== true + ) { + $error_update[] = __('Historical database purge'); + } + + if (Config::set( + 'history_partitions_auto', + get_parameter_switch('history_partitions_auto', 0), + true + ) !== true + ) { + $error_update[] = __('Historical database partitions'); + } + + if (Config::set( + 'event_purge', + get_parameter('history_dbh_events_purge'), + true + ) !== true + ) { + $error_update[] = __('Historical database events purge'); + } + + if (Config::set( + 'string_purge', + get_parameter('history_dbh_string_purge'), + true + ) !== true + ) { + $error_update[] = __('Historical database string purge'); + } + + // Disable history db in history db. + Config::set('history_db_enabled', 0, true); break; case 'ehorus': @@ -1685,6 +1767,14 @@ function config_update_config() $config['error_config_update_config']['correct'] = true; } + if (count($errors) > 0) { + $config['error_config_update_config']['errors'] = $errors; + } + + if (count($warnings) > 0) { + $config['error_config_update_config']['warnings'] = $warnings; + } + enterprise_include_once('include/functions_policies.php'); $enterprise = enterprise_include_once('include/functions_skins.php'); if ($enterprise !== ENTERPRISE_NOT_HOOK) { diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 267b5123c4..25e656e2be 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -3770,6 +3770,7 @@ function ui_print_event_priority( * @param string $attributes_switch Switch attributes. * @param string $toggl_attr Main box extra attributes. * @param boolean|null $switch_on Switch enabled disabled or depending on hidden_Default. + * @param string|null $switch_name Use custom switch input name or generate one. * * @return string HTML. */ @@ -3790,7 +3791,8 @@ function ui_toggle( $switch=false, $attributes_switch='', $toggl_attr='', - $switch_on=null + $switch_on=null, + $switch_name=null ) { // Generate unique Id. $uniqid = uniqid(''); @@ -3826,7 +3828,7 @@ function ui_toggle( $main_class = ''; } - if (empty($container_class) === true) { + if ($container_class == 'white-box-content') { $container_class = 'white-box-content-clean'; } } @@ -3836,11 +3838,15 @@ function ui_toggle( $output .= '