diff --git a/pandora_console/extras/mr/.gitignore b/pandora_console/extras/mr/.gitignore new file mode 100644 index 0000000000..41ac4672e6 --- /dev/null +++ b/pandora_console/extras/mr/.gitignore @@ -0,0 +1,4 @@ +# Ignorar todo en este directorio +* +# Excepto este archivo +!.gitignore diff --git a/pandora_console/general/footer.php b/pandora_console/general/footer.php index 23022c3d75..d134e8c715 100644 --- a/pandora_console/general/footer.php +++ b/pandora_console/general/footer.php @@ -26,8 +26,22 @@ if (! file_exists ($config["homedir"] . $license_file)) { $license_file = 'general/license/pandora_info_en.html'; } +if (!$config["minor_release_open"]) { + $config["minor_release_open"] = 0; +} +if (enterprise_installed()) { + if (!$config["minor_release_enterprise"]) { + $config["minor_release_enterprise"] = 0; + } +} + echo ''; -echo sprintf(__('Pandora FMS %s - Build %s', $pandora_version, $build_version)); +if (enterprise_installed()) { + echo sprintf(__('Pandora FMS %s - Build %s - MR %s', $pandora_version, $build_version, $config["minor_release_enterprise"])); +} +else { + echo sprintf(__('Pandora FMS %s - Build %s - MR %s', $pandora_version, $build_version, $config["minor_release_open"])); +} echo '
'; echo ''. __('Page generated at') . ' '. ui_print_timestamp ($time, true, array ("prominent" => "timestamp")); //Always use timestamp here echo ''; diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index 3f3f7ff2da..eb48cbfb2e 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -233,12 +233,21 @@ config_check(); //====================================================== - + $check_minor_release_available = false; $pandora_management = check_acl($config['id_user'], 0, "PM"); + $check_minor_release_available = db_check_minor_relase_available (); + + if ($check_minor_release_available) { + set_pandora_error_for_header('There are one or more minor releases waiting for update, there are required administrator permissions', 'minor release/s available'); + } + + if ($config["alert_cnt"] > 0) { + echo ''; + echo ''; - if ($config["alert_cnt"] > 0) { + if ($config["alert_cnt"] > 0) { $maintenance_link = 'javascript:'; $maintenance_title = __("System alerts detected - Please fix as soon as possible"); $maintenance_class = $maintenance_id = 'show_systemalert_dialog white'; diff --git a/pandora_console/include/ajax/rolling_release.ajax.php b/pandora_console/include/ajax/rolling_release.ajax.php new file mode 100644 index 0000000000..37da049647 --- /dev/null +++ b/pandora_console/include/ajax/rolling_release.ajax.php @@ -0,0 +1,105 @@ += $number) { + if (!file_exists($dir."/updated") || !is_dir($dir."/updated")) { + mkdir($dir."/updated"); + } + $file_dest = "$dir/updated/$number.open.sql"; + if (copy($file, $file_dest)) { + unlink($file); + } + } + else { + $result = db_run_sql_file($file); + + if ($result) { + $update_config = update_config_token("minor_release_open", $number); + if ($update_config) { + $config["minor_release_open"] = $number; + } + + if ($config["minor_release_open"] == $number) { + if (!file_exists($dir."/updated") || !is_dir($dir."/updated")) { + mkdir($dir."/updated"); + } + + $file_dest = "$dir/updated/$number.open.sql"; + + if (copy($file, $file_dest)) { + unlink($file); + } + } + } + else { + $error_file = fopen($config["homedir"] . "/extras/mr/error.txt", "w"); + $message = "An error occurred while updating the database schema to the minor release " . $number; + fwrite($error_file, $message); + fclose($error_file); + } + } + } + else { + $error_file = fopen($config["homedir"] . "/extras/mr/error.txt", "w"); + $message = "The directory ' . $dir . ' should have read permissions in order to update the database schema"; + fwrite($error_file, $message); + fclose($error_file); + } + } + else { + $error_file = fopen($config["homedir"] . "/extras/mr/error.txt", "w"); + $message = "The directory ' . $dir . ' does not exist"; + fwrite($error_file, $message); + fclose($error_file); + } + } + + echo $message; + return; + } +} + +?> diff --git a/pandora_console/include/api.php b/pandora_console/include/api.php index 1397b70644..457c63f8b3 100644 --- a/pandora_console/include/api.php +++ b/pandora_console/include/api.php @@ -56,7 +56,21 @@ $no_login_msg = ""; // Don't change the format, it is parsed by applications switch($info) { case 'version': - echo 'Pandora FMS ' . $pandora_version . ' - ' . $build_version; + if (!$config["minor_release_open"]) { + $config["minor_release_open"] = 0; + } + if (enterprise_installed()) { + if (!$config["minor_release_enterprise"]) { + $config["minor_release_enterprise"] = 0; + } + } + + if (enterprise_installed()) { + echo 'Pandora FMS ' . $pandora_version . ' - ' . $build_version . " MR" . $config["minor_release_enterprise"]; + } + else { + echo 'Pandora FMS ' . $pandora_version . ' - ' . $build_version . " MR" . $config["minor_release_open"]; + } exit; } diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index 23aa78e434..5aa9a2ac40 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -1315,4 +1315,49 @@ function mysql_db_process_file ($path, $handle_error = true) { return false; } } + +// --------------------------------------------------------------- +// Initiates a transaction and run the queries of an sql file +// --------------------------------------------------------------- + +function db_run_sql_file ($location) { + global $config; + + // Load file + $commands = file_get_contents($location); + + // Delete comments + $lines = explode("\n", $commands); + $commands = ''; + foreach ($lines as $line) { + $line = trim($line); + if ($line && !preg_match('/^--/', $line) && !preg_match('/^\/\*/', $line)) { + $commands .= $line; + } + } + + // Convert to array + $commands = explode(";", $commands); + + // Run commands + mysql_db_process_sql_begin(); // Begin transaction + foreach ($commands as $command) { + if (trim($command)) { + $result = mysql_query($command); + + if (!$result) { + break; // Error + } + } + } + if ($result) { + mysql_db_process_sql_commit(); // Save results + return true; + } + else { + mysql_db_process_sql_rollback(); // Undo results + return false; + } +} + ?> diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 3e0521f7ff..a9b429caef 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -2667,6 +2667,76 @@ function pandora_setlocale() { str_replace(array_keys($replace_locale), $replace_locale, $user_language)); } +function update_config_token ($cfgtoken, $cfgvalue) { + global $config; + + $delete = db_process_sql ("DELETE FROM tconfig WHERE token = '$cfgtoken'"); + $insert = db_process_sql ("INSERT INTO tconfig (token, value) VALUES ('$cfgtoken', '$cfgvalue')"); + + if ($delete && $insert) { + return true; + } + else { + return false; + } +} + +function update_conf_minor_release() { + global $config; + + $config['minor_release_open'] = db_get_value ('value', 'tconfig', 'token', 'minor_release_open'); + + if (enterprise_installed()) { + $config['minor_release_enterprise'] = db_get_value ('value', 'tconfig', 'token', 'minor_release_enterprise'); + } +} + +function get_number_of_mr($mode) { + global $config; + + $dir = $config["homedir"]."/extras/mr"; + $mr_size = array(); + + if (file_exists($dir) && is_dir($dir)) { + if (is_readable($dir)) { + if ($mode == 'open') { + $files = scandir($dir); // Get all the files from the directory ordered by asc + + if ($files !== false) { + $pattern = "/^\d+\.open\.sql$/"; + $sqlfiles = preg_grep($pattern, $files); // Get the name of the correct files + $pattern = "/\.open\.sql$/"; + $replacement = ""; + $sqlfiles_num = preg_replace($pattern, $replacement, $sqlfiles); + + foreach ($sqlfiles_num as $num) { + $mr_size[] = $num; + } + } + } + else { + if (enterprise_installed()) { + $files2 = scandir($dir); // Get all the files from the directory ordered by asc + + if ($files2 !== false) { + $pattern2 = "/^\d+\.ent\.sql$/"; + $sqlfiles2 = preg_grep($pattern2, $files2); // Get the name of the correct files + + $pattern2 = "/\.ent\.sql$/"; + $replacement2 = ""; + $sqlfiles_num2 = preg_replace($pattern2, $replacement2, $sqlfiles2); // Get the number of the file + + foreach ($sqlfiles_num2 as $num2) { + $mr_size[] = $num2; + } + } + } + } + } + } + return $mr_size; +} + function remove_right_zeros ($value) { $is_decimal = explode(".", $value); if (isset($is_decimal[1])) { diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index ed50ec1cae..88d8d9a963 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -1672,4 +1672,86 @@ function db_process_file ($path, $handle_error = true) { } } +/** + * Search for minor release files. + * + * @return bool Return if minor release is available or not + */ +function db_check_minor_relase_available () { + global $config; + + $dir = $config["homedir"]."/extras/mr"; + + $have_ent_minor = false; + $have_open_minor = false; + + if (file_exists($dir) && is_dir($dir)) { + if (is_readable($dir)) { + $files = scandir($dir); // Get all the files from the directory ordered by asc + if ($files !== false) { + // Enterprise installed + if (enterprise_installed()) { + $pattern = "/^\d+\.open\.sql$/"; + $sqlfiles = preg_grep($pattern, $files); // Get the name of the correct files + $pattern = "/\.open\.sql$/"; + $replacement = ""; + $sqlfiles_num = preg_replace($pattern, $replacement, $sqlfiles); // Get the number of the file + + $sqlfiles = null; + + if ($sqlfiles_num) { + foreach ($sqlfiles_num as $sqlfile_num) { + if ($config["minor_release_open"] < $sqlfile_num) { + $have_open_minor = true; + } + } + } + + $pattern2 = "/^\d+\.ent\.sql$/"; + $sqlfiles2 = preg_grep($pattern2, $files); // Get the name of the correct files + $files = null; + $pattern2 = "/\.ent\.sql$/"; + $replacement2 = ""; + $sqlfiles_num2 = preg_replace($pattern2, $replacement2, $sqlfiles2); // Get the number of the file + + $sqlfiles2 = null; + + if ($sqlfiles_num2) { + foreach ($sqlfiles_num2 as $sqlfile_num2) { + if ($config["minor_release_enterprise"] < $sqlfile_num2) { + $have_ent_minor = true; + } + } + } + } + else { + $pattern = "/^\d+\.open.sql$/"; + $sqlfiles = preg_grep($pattern, $files); // Get the name of the correct files + $files = null; + $pattern = "/\.open.sql$/"; + $replacement = ""; + $sqlfiles_num = preg_replace($pattern, $replacement, $sqlfiles); // Get the number of the file + + $sqlfiles = null; + + if ($sqlfiles_num) { + foreach ($sqlfiles_num as $sqlfile_num) { + if ($config["minor_release"] < $sqlfile_num) { + $have_open_minor = true; + } + } + } + } + } + } + } + + if ($have_open_minor || $have_ent_minor) { + return true; + } + else { + return false; + } +} + ?> \ No newline at end of file diff --git a/pandora_console/index.php b/pandora_console/index.php index 9dff0107e6..8b6a62fb0c 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -36,7 +36,7 @@ if ($develop_bypass != 1) { exit; } } - + if (filesize("include/config.php") == 0) { include ("install.php"); exit; @@ -100,7 +100,7 @@ if (!empty ($config["https"]) && empty ($_SERVER['HTTPS'])) { if (sizeof ($_REQUEST)) //Some (old) browsers don't like the ?&key=var $query .= '?1=1'; - + //We don't clean these variables up as they're only being passed along foreach ($_GET as $key => $value) { if ($key == 1) @@ -111,11 +111,11 @@ if (!empty ($config["https"]) && empty ($_SERVER['HTTPS'])) { $query .= '&'.$key.'='.$value; } $url = ui_get_full_url($query); - + // Prevent HTTP response splitting attacks // http://en.wikipedia.org/wiki/HTTP_response_splitting $url = str_replace ("\n", "", $url); - + header ('Location: '.$url); exit; //Always exit after sending location headers } @@ -141,7 +141,7 @@ echo '' . "\n"; //This starts the page head. In the call back function, things from $page['head'] array will be processed into the head ob_start ('ui_process_page_head'); -// Enterprise main +// Enterprise main enterprise_include ('index.php'); echo ' + $param) { @@ -825,7 +896,7 @@ else { } if (isset($_GET['sec2'])) { $file = $_GET['sec2'] . '.php'; - + if (!file_exists ($file)) { unset($_GET['sec2']); require('general/logon_ok.php'); @@ -883,15 +954,15 @@ require('include/php_to_js_values.php');