Added rr to um offline. Ticket #510

This commit is contained in:
Arturo Gonzalez 2017-03-13 16:30:04 +01:00
parent 44ac96ae5e
commit 6a39147940
3 changed files with 286 additions and 121 deletions

View File

@ -43,6 +43,8 @@ $baseurl = ui_get_full_url(false, false, false, false);
var package_updated_successfully = "<?php echo __('Package updated successfully.'); ?>\n";
var if_there_are_any_database_change = "<?php echo __('If there are any database change, it will be applied on the next login.'); ?>\n";
var package_not_updated = "<?php echo __('Package not updated.'); ?>\n";
var error_in_mr = "<?php echo __('Error in MR file'); ?>\n";
var error_in_mr_accept = "<?php echo __('MR not accepted'); ?>\n";
</script>
<form id="form-offline_update" method="post" enctype="multipart/form-data" class="fileupload_form">

View File

@ -109,128 +109,137 @@ if ($install_package) {
global $config;
ob_clean();
$package = (string) get_parameter("package");
$package = trim($package);
$chunks = explode("_", basename($package));
$chunks = explode(".", $chunks[1]);
$version = $chunks[0];
// All files extracted
$files_total = $package . "/files.txt";
// Files copied
$files_copied = $package . "/files.copied.txt";
$return = array();
if (file_exists($files_copied)) {
unlink($files_copied);
}
if (file_exists($package)) {
$accept = (bool)get_parameter("accept", false);
if ($accept) {
$package = (string) get_parameter("package");
$package = trim($package);
if ($files_h = fopen($files_total, "r")) {
$chunks = explode("_", basename($package));
$chunks = explode(".", $chunks[1]);
$version = $chunks[0];
// All files extracted
$files_total = $package . "/files.txt";
// Files copied
$files_copied = $package . "/files.copied.txt";
$return = array();
if (file_exists($files_copied)) {
unlink($files_copied);
}
if (file_exists($package)) {
while ($line = stream_get_line($files_h, 65535, "\n")) {
$line = trim($line);
if ($files_h = fopen($files_total, "r")) {
// Tries to move the old file to the directory backup inside the extracted package
if (file_exists($config["homedir"] . "/" . $line)) {
rename($config["homedir"] . "/" . $line,
$package . "/backup/" . $line);
}
// Tries to move the new file to the Pandora directory
$dirname = dirname($line);
if (!file_exists($config["homedir"] . "/" . $dirname)) {
$dir_array = explode("/", $dirname);
$temp_dir = "";
foreach ($dir_array as $dir) {
$temp_dir .= "/" . $dir;
if (!file_exists($config["homedir"] . $temp_dir)) {
mkdir($config["homedir"] . $temp_dir);
while ($line = stream_get_line($files_h, 65535, "\n")) {
$line = trim($line);
// Tries to move the old file to the directory backup inside the extracted package
if (file_exists($config["homedir"] . "/" . $line)) {
rename($config["homedir"] . "/" . $line,
$package . "/backup/" . $line);
}
// Tries to move the new file to the Pandora directory
$dirname = dirname($line);
if (!file_exists($config["homedir"] . "/" . $dirname)) {
$dir_array = explode("/", $dirname);
$temp_dir = "";
foreach ($dir_array as $dir) {
$temp_dir .= "/" . $dir;
if (!file_exists($config["homedir"] . $temp_dir)) {
mkdir($config["homedir"] . $temp_dir);
}
}
}
}
if (is_dir($package . "/" . $line)) {
if (!file_exists($config["homedir"] . "/" . $line)) {
mkdir($config["homedir"] . "/" . $line);
file_put_contents($files_copied, $line."\n", FILE_APPEND | LOCK_EX);
if (is_dir($package . "/" . $line)) {
if (!file_exists($config["homedir"] . "/" . $line)) {
mkdir($config["homedir"] . "/" . $line);
file_put_contents($files_copied, $line."\n", FILE_APPEND | LOCK_EX);
}
}
}
else {
if (rename($package."/".$line, $config["homedir"]."/".$line)) {
// Append the moved file to the copied files txt
if (!file_put_contents($files_copied, $line."\n", FILE_APPEND | LOCK_EX)) {
else {
if (rename($package."/".$line, $config["homedir"]."/".$line)) {
// Append the moved file to the copied files txt
if (!file_put_contents($files_copied, $line."\n", FILE_APPEND | LOCK_EX)) {
// If the copy process fail, this code tries to restore the files backed up before
if ($files_copied_h = fopen($files_copied, "r")) {
while ($line_c = stream_get_line($files_copied_h, 65535, "\n")) {
$line_c = trim($line_c);
if (!rename($package."/backup/".$line, $config["homedir"]."/".$line_c)) {
$backup_status = __("Some of your files might not be recovered.");
}
}
if (!rename($package."/backup/".$line, $config["homedir"]."/".$line)) {
$backup_status = __("Some of your files might not be recovered.");
}
fclose($files_copied_h);
} else {
$backup_status = __("Some of your old files might not be recovered.");
}
fclose($files_h);
$return["status"] = "error";
$return["message"]= __("Line '$line' not copied to the progress file.")."&nbsp;".$backup_status;
echo json_encode($return);
return;
}
}
else {
// If the copy process fail, this code tries to restore the files backed up before
if ($files_copied_h = fopen($files_copied, "r")) {
while ($line_c = stream_get_line($files_copied_h, 65535, "\n")) {
$line_c = trim($line_c);
if (!rename($package."/backup/".$line, $config["homedir"]."/".$line_c)) {
$backup_status = __("Some of your files might not be recovered.");
if (!rename($package."/backup/".$line, $config["homedir"]."/".$line)) {
$backup_status = __("Some of your old files might not be recovered.");
}
}
if (!rename($package."/backup/".$line, $config["homedir"]."/".$line)) {
$backup_status = __("Some of your files might not be recovered.");
}
fclose($files_copied_h);
} else {
$backup_status = __("Some of your old files might not be recovered.");
}
else {
$backup_status = __("Some of your files might not be recovered.");
}
fclose($files_h);
$return["status"] = "error";
$return["message"]= __("Line '$line' not copied to the progress file.")."&nbsp;".$backup_status;
$return["message"]= __("File '$line' not copied.")."&nbsp;".$backup_status;
echo json_encode($return);
return;
}
}
else {
// If the copy process fail, this code tries to restore the files backed up before
if ($files_copied_h = fopen($files_copied, "r")) {
while ($line_c = stream_get_line($files_copied_h, 65535, "\n")) {
$line_c = trim($line_c);
if (!rename($package."/backup/".$line, $config["homedir"]."/".$line)) {
$backup_status = __("Some of your old files might not be recovered.");
}
}
fclose($files_copied_h);
}
else {
$backup_status = __("Some of your files might not be recovered.");
}
fclose($files_h);
$return["status"] = "error";
$return["message"]= __("File '$line' not copied.")."&nbsp;".$backup_status;
echo json_encode($return);
return;
}
}
fclose($files_h);
}
else {
$return["status"] = "error";
$return["message"]= __("An error ocurred while reading a file.");
echo json_encode($return);
return;
}
fclose($files_h);
}
else {
$return["status"] = "error";
$return["message"]= __("An error ocurred while reading a file.");
$return["message"]= __("The package does not exist");
echo json_encode($return);
return;
}
}
else {
$return["status"] = "error";
$return["message"]= __("The package does not exist");
update_manager_enterprise_set_version($version);
db_pandora_audit("Update Pandora", "Update version: $version of Pandora FMS by ".$config['id_user']);
$return["status"] = "success";
echo json_encode($return);
return;
}
else {
$return["status"] = "error";
$return["message"]= __("Package not accepted");
echo json_encode($return);
return;
}
update_manager_enterprise_set_version($version);
db_pandora_audit("Update Pandora", "Update version: $version of Pandora FMS by ".$config['id_user']);
$return["status"] = "success";
echo json_encode($return);
return;
}
if ($check_install_package) {

View File

@ -193,40 +193,196 @@ function formatFileSize(bytes) {
function install_package (package, homeurl) {
var home_url = (typeof homeurl !== 'undefined') ? homeurl + '/' : '';
var parameters = {};
parameters['page'] = 'include/ajax/update_manager.ajax';
parameters['install_package'] = 1;
parameters['package'] = package;
$('#form-offline_update ul').find('li').removeClass('suc');
$('#form-offline_update ul').find('li').addClass('loading');
$.ajax({
type: 'POST',
url: home_url + 'ajax.php',
data: parameters,
dataType: "json",
success: function (data) {
$('#form-offline_update ul').find('li').removeClass('loading');
if (data.status == "success") {
$('#form-offline_update ul').find('li').addClass('suc');
$('#form-offline_update ul').find('li').find('p').html(package_updated_successfully)
.append("<i>" + if_there_are_any_database_change + "</i>");
$("<div id='pkg_apply_dialog' class= 'dialog ui-dialog-content'></div>").dialog ({
resizable: true,
draggable: true,
modal: true,
overlay: {
opacity: 0.5,
background: 'black'
},
width: 600,
height: 350,
buttons: {
"Apply package": function () {
$("#pkg_apply_dialog").dialog("close");
var parameters = {};
parameters['page'] = 'include/ajax/update_manager.ajax';
parameters['search_minor'] = 1;
$.ajax({
type: 'POST',
url: home_url + 'ajax.php',
data: parameters,
dataType: "json",
success: function (data) {
if (data['have_minor']) {
$("<div id='mr_dialog2' class='dialog ui-dialog-content' title='Menor release available'></div>").dialog ({
resizable: true,
draggable: true,
modal: true,
overlay: {
opacity: 0.5,
background: 'black'
},
width: 600,
height: 350,
buttons: {
"Apply minor releases": function () {
var no_error = apply_minor_release(data['mr']);
$("#apply_rr_button").remove();
$("#cancel_rr_button").remove();
if (no_error) {
var parameters = {};
parameters['page'] = 'include/ajax/update_manager.ajax';
parameters['install_package'] = 1;
parameters['package'] = package;
parameters['accept'] = 1;
$('#form-offline_update ul').find('li').removeClass('suc');
$('#form-offline_update ul').find('li').addClass('loading');
$.ajax({
type: 'POST',
url: home_url + 'ajax.php',
data: parameters,
dataType: "json",
success: function (data) {
$('#form-offline_update ul').find('li').removeClass('loading');
if (data.status == "success") {
$('#form-offline_update ul').find('li').addClass('suc');
$('#form-offline_update ul').find('li').find('p').html(package_updated_successfully)
.append("<i>" + if_there_are_any_database_change + "</i>");
}
else {
$('#form-offline_update ul').find('li').addClass('error');
$('#form-offline_update ul').find('li').find('p').html(package_not_updated)
.append("<i>"+data.message+"</i>");
}
$('#form-offline_update ul').find('li').css("cursor", "pointer");
$('#form-offline_update ul').find('li').click(function() {
window.location.reload();
});
}
});
// Check the status of the update
check_install_package(package, homeurl);
}
else {
$('#form-offline_update ul').find('li').addClass('error');
$('#form-offline_update ul').find('li').find('p').html(error_in_mr)
.append("<i>"+data.message+"</i>");
}
},
"Cancel": function () {
$("#mr_dialog2").dialog("close");
$('#form-offline_update ul').find('li').addClass('error');
$('#form-offline_update ul').find('li').find('p').html(error_in_mr_accept)
.append("<i>"+data.message+"</i>");
}
}
});
$('button:contains(Apply minor releases)').attr("id","apply_rr_button");
$('button:contains(Cancel)').attr("id","cancel_rr_button");
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');
}
else {
$("#pkg_apply_dialog").dialog("close");
var parameters = {};
parameters['page'] = 'include/ajax/update_manager.ajax';
parameters['install_package'] = 1;
parameters['package'] = package;
parameters['accept'] = 1;
$('#form-offline_update ul').find('li').removeClass('suc');
$('#form-offline_update ul').find('li').addClass('loading');
$.ajax({
type: 'POST',
url: home_url + 'ajax.php',
data: parameters,
dataType: "json",
success: function (data) {
$('#form-offline_update ul').find('li').removeClass('loading');
if (data.status == "success") {
$('#form-offline_update ul').find('li').addClass('suc');
$('#form-offline_update ul').find('li').find('p').html(package_updated_successfully)
.append("<i>" + if_there_are_any_database_change + "</i>");
}
else {
$('#form-offline_update ul').find('li').addClass('error');
$('#form-offline_update ul').find('li').find('p').html(package_not_updated)
.append("<i>"+data.message+"</i>");
}
$('#form-offline_update ul').find('li').css("cursor", "pointer");
$('#form-offline_update ul').find('li').click(function() {
window.location.reload();
});
}
});
// Check the status of the update
check_install_package(package, homeurl);
}
}
});
},
"Cancel": function () {
$(this).dialog("close");
var parameters = {};
parameters['page'] = 'include/ajax/update_manager.ajax';
parameters['install_package'] = 1;
parameters['package'] = package;
parameters['accept'] = 0;
$('#form-offline_update ul').find('li').removeClass('suc');
$('#form-offline_update ul').find('li').addClass('loading');
$.ajax({
type: 'POST',
url: home_url + 'ajax.php',
data: parameters,
dataType: "json",
success: function (data) {
$('#form-offline_update ul').find('li').removeClass('loading');
if (data.status == "success") {
$('#form-offline_update ul').find('li').addClass('suc');
$('#form-offline_update ul').find('li').find('p').html(package_updated_successfully)
.append("<i>" + if_there_are_any_database_change + "</i>");
}
else {
$('#form-offline_update ul').find('li').addClass('error');
$('#form-offline_update ul').find('li').find('p').html(package_not_updated)
.append("<i>"+data.message+"</i>");
}
$('#form-offline_update ul').find('li').css("cursor", "pointer");
$('#form-offline_update ul').find('li').click(function() {
window.location.reload();
});
}
});
// Check the status of the update
check_install_package(package, homeurl);
}
else {
$('#form-offline_update ul').find('li').addClass('error');
$('#form-offline_update ul').find('li').find('p').html(package_not_updated)
.append("<i>"+data.message+"</i>");
}
$('#form-offline_update ul').find('li').css("cursor", "pointer");
$('#form-offline_update ul').find('li').click(function() {
window.location.reload();
});
}
});
var dialog_text = "<div><h3>Do you want to apply the package?</h3></br>";
// Check the status of the update
check_install_package(package, homeurl);
$('#pkg_apply_dialog').html(dialog_text);
$('#pkg_apply_dialog').dialog('open');
}
function check_install_package(package, homeurl) {
@ -552,8 +708,6 @@ function install_free_package(package, version, homeurl) {
function apply_minor_release (n_mr) {
var error = false;
$("#apply_rr_button").remove();
$("#cancel_rr_button").remove();
$('#mr_dialog2').empty();
$.each(n_mr, function(i, mr) {
var params = {};