mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 16:55:05 +02:00
Merge branch 'feature/rolling_release' into 'develop'
Feature/rolling release See merge request !151
This commit is contained in:
commit
e71c6070ad
4
pandora_console/extras/mr/.gitignore
vendored
Normal file
4
pandora_console/extras/mr/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# Ignorar todo en este directorio
|
||||
*
|
||||
# Excepto este archivo
|
||||
!.gitignore
|
@ -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 '<a class="white_bold footer" target="_blank" href="' . $config["homeurl"] . $license_file. '">';
|
||||
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 '</a><br />';
|
||||
echo '<a class="white footer">'. __('Page generated at') . ' '. ui_print_timestamp ($time, true, array ("prominent" => "timestamp")); //Always use timestamp here
|
||||
echo '</a>';
|
||||
|
@ -233,9 +233,18 @@ 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 '<div id="alert_messages" style="display: none"></div>';
|
||||
|
||||
echo '<div id="alert_messages" style="display: none"></div>';
|
||||
|
||||
if ($config["alert_cnt"] > 0) {
|
||||
|
105
pandora_console/include/ajax/rolling_release.ajax.php
Normal file
105
pandora_console/include/ajax/rolling_release.ajax.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2012 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation for version 2.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// Only accesible by ajax
|
||||
if (is_ajax ()) {
|
||||
global $config;
|
||||
check_login();
|
||||
|
||||
$updare_rr_open = get_parameter('updare_rr_open', 0);
|
||||
|
||||
if ($updare_rr_open) {
|
||||
$number = get_parameter('number');
|
||||
$dir = $config["homedir"]."/extras/mr";
|
||||
|
||||
$file = "$dir/$number.open.sql";
|
||||
|
||||
$dangerous_query = false;
|
||||
$mr_file = fopen($file, "r");
|
||||
while (!feof($mr_file)) {
|
||||
$line = fgets($mr_file);
|
||||
if ((preg_match("/^drop/", $line)) ||
|
||||
(preg_match("/^truncate table/", $line))) {
|
||||
$dangerous_query = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($dangerous_query) {
|
||||
$error_file = fopen($config["homedir"] . "/extras/mr/error.txt", "w");
|
||||
$message = "The sql file contains a dangerous query";
|
||||
fwrite($error_file, $message);
|
||||
fclose($error_file);
|
||||
}
|
||||
else {
|
||||
if (file_exists($dir) && is_dir($dir)) {
|
||||
if (is_readable($dir)) {
|
||||
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 {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -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])) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -181,6 +181,7 @@ if ($change_pass == 1) {
|
||||
$changed_pass = login_update_password_check ($password_old, $password_new, $password_confirm, $id);
|
||||
}
|
||||
|
||||
$minor_release_message = false;
|
||||
$searchPage = false;
|
||||
$search = get_parameter_get("head_search_keywords");
|
||||
if (strlen($search) > 0) {
|
||||
@ -443,6 +444,76 @@ if (! isset ($config['id_user'])) {
|
||||
$_SESSION['id_usuario'] = $nick_in_db;
|
||||
$config['id_user'] = $nick_in_db;
|
||||
|
||||
if (is_user_admin($config['id_user'])) {
|
||||
$have_minor_releases = db_check_minor_relase_available();
|
||||
|
||||
// PHP configuration values
|
||||
$PHPupload_max_filesize = config_return_in_bytes(ini_get('upload_max_filesize'));
|
||||
$PHPmemory_limit = config_return_in_bytes(ini_get('memory_limit'));
|
||||
$PHPmax_execution_time = ini_get('max_execution_time');
|
||||
|
||||
if ($PHPmax_execution_time !== '0') {
|
||||
set_time_limit(0);
|
||||
}
|
||||
|
||||
$PHPupload_max_filesize_min = config_return_in_bytes('800M');
|
||||
|
||||
if ($PHPupload_max_filesize < $PHPupload_max_filesize_min) {
|
||||
ini_set('upload_max_filesize', config_return_in_bytes('800M'));
|
||||
}
|
||||
|
||||
$PHPmemory_limit_min = config_return_in_bytes('500M');
|
||||
|
||||
if ($PHPmemory_limit < $PHPmemory_limit_min && $PHPmemory_limit !== '-1') {
|
||||
ini_set('memory_limit', config_return_in_bytes('500M'));
|
||||
}
|
||||
|
||||
if ($have_minor_releases) {
|
||||
$size_mr_o = get_number_of_mr('open');
|
||||
$size_mr_e = get_number_of_mr('enterprise');
|
||||
echo "<div class= 'dialog ui-dialog-content' title='".__("Minor release available")."' id='mr_dialog2'>" . __('') . "</div>";
|
||||
?>
|
||||
<script type="text/javascript" language="javascript">
|
||||
$(document).ready (function () {;
|
||||
$('#mr_dialog2').dialog ({
|
||||
resizable: true,
|
||||
draggable: true,
|
||||
modal: true,
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: 'black'
|
||||
},
|
||||
width: 600,
|
||||
height: 350,
|
||||
buttons: {
|
||||
"Apply minor releases": function() {
|
||||
var n_mr_o = '<?php echo implode(",", $size_mr_o);?>';
|
||||
var n_mr_e = '<?php echo implode(",", $size_mr_e);?>';
|
||||
$(this).dialog("close");
|
||||
apply_minor_release(n_mr_o.split(","), n_mr_e.split(","));
|
||||
},
|
||||
Cancel: function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var dialog_text = "<div><h3>Do you want to apply minor releases?</h3></br>";
|
||||
dialog_text = dialog_text + "<h2>We recommend launch a planned downtime to this process</h2></br>";
|
||||
dialog_text = dialog_text + "<a href=\"<?php echo $config['homeurl']; ?>index.php?sec=extensions&sec2=godmode/agentes/planned_downtime.list\">Planned downtimes</a></div>"
|
||||
|
||||
$('#mr_dialog2').html(dialog_text);
|
||||
$('#mr_dialog2').dialog('open');
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
set_time_limit((int)$PHPmax_execution_time);
|
||||
ini_set('upload_max_filesize', $PHPupload_max_filesize);
|
||||
ini_set('memory_limit', $PHPmemory_limit);
|
||||
|
||||
//==========================================================
|
||||
//-------- SET THE CUSTOM CONFIGS OF USER ------------------
|
||||
|
||||
@ -904,6 +975,62 @@ require('include/php_to_js_values.php');
|
||||
};
|
||||
})();
|
||||
|
||||
function apply_minor_release (n_mr_o, n_mr_e) {
|
||||
var error = false;
|
||||
$.each(n_mr_o, function(i, open_mr) {
|
||||
var params = {};
|
||||
params["updare_rr_open"] = 1;
|
||||
params["number"] = open_mr;
|
||||
params["page"] = "include/ajax/rolling_release.ajax";
|
||||
|
||||
jQuery.ajax ({
|
||||
data: params,
|
||||
async: false,
|
||||
dataType: "html",
|
||||
type: "POST",
|
||||
url: "ajax.php",
|
||||
success: function (data) {
|
||||
if (data != "") {
|
||||
alert("Error: " + data);
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (error == true) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
var error2 = false;
|
||||
$.each(n_mr_e, function(i, e_mr) {
|
||||
var params = {};
|
||||
params["updare_rr_enterprise"] = 1;
|
||||
params["number"] = e_mr;
|
||||
params["page"] = "enterprise/include/ajax/rolling_release.ajax";
|
||||
|
||||
jQuery.ajax ({
|
||||
data: params,
|
||||
async: false,
|
||||
dataType: "html",
|
||||
type: "POST",
|
||||
url: "ajax.php",
|
||||
success: function (data) {
|
||||
if (data != "") {
|
||||
alert("Error: " + data);
|
||||
error2 = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (error2 == true) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (!error && !error2) {
|
||||
alert("Updated finished successfully");
|
||||
}
|
||||
}
|
||||
|
||||
function force_run_register () {
|
||||
run_identification_wizard (1, 0, 0);
|
||||
|
@ -109,6 +109,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES
|
||||
('custom_report_front_logo', 'images/pandora_logo_white.jpg'),
|
||||
('custom_report_front_header', ''),
|
||||
('custom_report_front_footer', ''),
|
||||
('minor_release_open', 0),
|
||||
('identification_reminder', 1),
|
||||
('identification_reminder_timestamp', 0),
|
||||
('post_process_custom_values', '{"0.00000038580247":"Seconds to months","0.00000165343915":"Seconds to weeks","0.00001157407407":"Seconds to days","0.01666666666667":"Seconds to minutes","0.00000000093132":"Bytes to Gigabytes","0.00000095367432":"Bytes to Megabytes","0.0009765625":"Bytes to Kilobytes","0.00000001653439":"Timeticks to weeks","0.00000011574074":"Timeticks to days"}');
|
||||
|
Loading…
x
Reference in New Issue
Block a user