add delete files in update manager
Former-commit-id: 880dfc8079e7e85fa1fcba4746927caf1a2d2c06
This commit is contained in:
parent
0ccbb1198a
commit
a1aa480421
|
@ -1,23 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* Extension to manage a list of gateways and the node address where they should
|
||||
* point to.
|
||||
*
|
||||
* @category Update Manager Offline
|
||||
* @package Pandora FMS
|
||||
* @subpackage Community
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 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; 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.
|
||||
global $config;
|
||||
|
||||
// ui_require_css_file('update_manager', 'godmode/update_manager/');
|
||||
check_login();
|
||||
|
||||
// ui_require_css_file('update_manager', 'godmode/update_manager/');
|
||||
if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user'])) {
|
||||
if (! check_acl($config['id_user'], 0, 'PM')
|
||||
&& ! is_user_admin($config['id_user'])
|
||||
) {
|
||||
db_pandora_audit('ACL Violation', 'Trying to access Setup Management');
|
||||
include 'general/noaccess.php';
|
||||
return;
|
||||
|
@ -27,7 +43,8 @@ $baseurl = ui_get_full_url(false, false, false, false);
|
|||
|
||||
?>
|
||||
|
||||
<!-- Add the stylesheet here cause somehow the 'ui_require_css_file' is not working on the metaconsole and there is no time to fix it -->
|
||||
<!-- Add the stylesheet here cause somehow the 'ui_require_css_file'
|
||||
is not working on the metaconsole and there is no time to fix it -->
|
||||
<link rel="stylesheet" type="text/css" href="<?php echo $baseurl; ?>/godmode/update_manager/update_manager.css">
|
||||
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -1,16 +1,32 @@
|
|||
<?php
|
||||
/**
|
||||
* Extension to manage a list of gateways and the node address where they should
|
||||
* point to.
|
||||
*
|
||||
* @category Update Manager Ajax
|
||||
* @package Pandora FMS
|
||||
* @subpackage Community
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2010 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.
|
||||
global $config;
|
||||
|
||||
check_login();
|
||||
|
@ -44,6 +60,7 @@ $check_update_free_package = (bool) get_parameter('check_update_free_package');
|
|||
$install_free_package = (bool) get_parameter('install_free_package');
|
||||
$search_minor = (bool) get_parameter('search_minor');
|
||||
$unzip_free_package = (bool) get_parameter('unzip_free_package');
|
||||
$delete_desired_files = (bool) get_parameter('delete_desired_files');
|
||||
|
||||
if ($upload_file) {
|
||||
ob_clean();
|
||||
|
@ -591,3 +608,147 @@ if ($install_free_package) {
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Result info:
|
||||
* Types of status:
|
||||
* -1 -> Not exits file.
|
||||
* 0 -> File or directory deleted successfully.
|
||||
* 1 -> Problem delete file or directory.
|
||||
* 2 -> Not found file or directory.
|
||||
* 3 -> Don`t read file deleet_files.txt.
|
||||
* 4 -> "deleted" folder could not be created.
|
||||
* 5 -> "deleted" folder was created.
|
||||
* 6 -> The "delete files" could not be the "delete" folder.
|
||||
* 7 -> The "delete files" is moved to the "delete" folder.
|
||||
* Type:
|
||||
* f -> File
|
||||
* d -> Dir.
|
||||
* route: Path.
|
||||
*/
|
||||
|
||||
if ($delete_desired_files === true) {
|
||||
global $config;
|
||||
|
||||
// Initialize result.
|
||||
$result = [];
|
||||
|
||||
// Flag exist folder "deleted".
|
||||
$exist_deleted = true;
|
||||
|
||||
// Route delete_files.txt.
|
||||
$route_delete_files = $config['homedir'];
|
||||
$route_delete_files .= '/extras/delete_files/delete_files.txt';
|
||||
|
||||
// Route directory deleted.
|
||||
$route_dir_deleted = $config['homedir'];
|
||||
$route_dir_deleted .= '/extras/delete_files/deleted/';
|
||||
|
||||
// Check isset directory deleted
|
||||
// if it does not exist, try to create it.
|
||||
if (is_dir($route_dir_deleted) === false) {
|
||||
$res_mkdir = mkdir($route_dir_deleted, 0777, true);
|
||||
$res = [];
|
||||
if ($res_mkdir !== true) {
|
||||
$exist_deleted = false;
|
||||
$res['status'] = 4;
|
||||
} else {
|
||||
$res['status'] = 5;
|
||||
}
|
||||
|
||||
$res['type'] = 'd';
|
||||
$res['route'] = $url_to_delete;
|
||||
array_push($result, $res);
|
||||
}
|
||||
|
||||
// Check isset delete_files.txt.
|
||||
if (file_exists($route_delete_files) === true && $exist_deleted === true) {
|
||||
// Open file.
|
||||
$file_read = fopen($route_delete_files, 'r');
|
||||
// Check if read delete_files.txt.
|
||||
if ($file_read !== false) {
|
||||
while ($file_to_delete = stream_get_line($file_read, 65535, "\n")) {
|
||||
$file_to_delete = trim($file_to_delete);
|
||||
$url_to_delete = $config['homedir'].'/'.$file_to_delete;
|
||||
// Check is dir or file or not exists.
|
||||
if (is_dir($url_to_delete) === true) {
|
||||
$result = rmdir_recursive(
|
||||
$url_to_delete,
|
||||
$result
|
||||
);
|
||||
} else if (file_exists($url_to_delete) === true) {
|
||||
$unlink = unlink($url_to_delete);
|
||||
$res = [];
|
||||
if ($unlink === true) {
|
||||
$res['status'] = 0;
|
||||
} else {
|
||||
$res['status'] = 1;
|
||||
}
|
||||
|
||||
$res['type'] = 'f';
|
||||
$res['route'] = $url_to_delete;
|
||||
array_push($result, $res);
|
||||
} else {
|
||||
$res = [];
|
||||
$res['status'] = 2;
|
||||
$res['route'] = $url_to_delete;
|
||||
array_push($result, $res);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$res = [];
|
||||
$res['status'] = 3;
|
||||
$res['route'] = $url_to_delete;
|
||||
array_push($result, $res);
|
||||
}
|
||||
|
||||
// Close file.
|
||||
fclose($route_delete_files);
|
||||
|
||||
// Move delete_files.txt to dir extras/deleted/.
|
||||
$count_scandir = count(scandir($route_dir_deleted));
|
||||
$route_move = $route_dir_deleted.'/delete_files_'.$count_scandir.'.txt';
|
||||
$res_rename = rename(
|
||||
$route_delete_files,
|
||||
$route_move
|
||||
);
|
||||
|
||||
$res = [];
|
||||
if ($res_rename !== true) {
|
||||
$res['status'] = 6;
|
||||
} else {
|
||||
$res['status'] = 7;
|
||||
}
|
||||
|
||||
$res['type'] = 'f';
|
||||
$res['route'] = $route_move;
|
||||
array_push($result, $res);
|
||||
} else {
|
||||
if ($exist_deleted === true) {
|
||||
$res = [];
|
||||
$res['status'] = -1;
|
||||
array_push($result, $res);
|
||||
}
|
||||
}
|
||||
|
||||
// Translate diccionary neccesary.
|
||||
$result['translate'] = [
|
||||
'title' => __('Delete files'),
|
||||
'not_file' => __('The oum has no files to remove'),
|
||||
'not_found' => __('Not found'),
|
||||
'not_deleted' => __('Not deleted'),
|
||||
'not_read' => __('The file delete_file.txt can not be read'),
|
||||
'folder_deleted_f' => __('\'deleted\' folder could not be created'),
|
||||
'folder_deleted_t' => __('\'deleted\' folder was created'),
|
||||
'move_file_f' => __(
|
||||
'The "delete files" could not be the "delete" folder'
|
||||
),
|
||||
'move_file_d' => __(
|
||||
'The "delete files" is moved to the "delete" folder'
|
||||
),
|
||||
];
|
||||
|
||||
echo json_encode($result);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,20 +1,30 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2009 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 Lesser General Public License
|
||||
// as published by the Free Software Foundation; 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.
|
||||
|
||||
/**
|
||||
* @package Include
|
||||
* @subpackage UI
|
||||
* Extension to manage a list of gateways and the node address where they should
|
||||
* point to.
|
||||
*
|
||||
* @category Functions Update Manager
|
||||
* @package Pandora FMS
|
||||
* @subpackage Community
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
|
||||
|
@ -988,13 +998,71 @@ function update_manger_set_deleted_message($message_id)
|
|||
{
|
||||
global $config;
|
||||
|
||||
$rollback = db_get_value('description', 'tupdate', 'svn_version', $message_id);
|
||||
$rollback = db_get_value(
|
||||
'description',
|
||||
'tupdate',
|
||||
'svn_version',
|
||||
$message_id
|
||||
);
|
||||
$users_read = json_decode($rollback, true);
|
||||
$users_read[$config['id_user']] = 1;
|
||||
|
||||
$rollback = json_encode($users_read);
|
||||
db_process_sql_update('tupdate', ['description' => $rollback ], ['svn_version' => $message_id]);
|
||||
db_process_sql_update(
|
||||
'tupdate',
|
||||
['description' => $rollback ],
|
||||
['svn_version' => $message_id]
|
||||
);
|
||||
|
||||
// Mark as read too
|
||||
// Mark as read too.
|
||||
update_manger_set_read_message($message_id, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function recursive delete directory.
|
||||
*
|
||||
* @param string $dir Directory to delete.
|
||||
* @param array $result Array result state and message.
|
||||
*
|
||||
* @return array Return result array with status 0 valid or 1 false and
|
||||
* type 'f' file and 'd' dir and route path file or directory.
|
||||
*/
|
||||
function rmdir_recursive(string $dir, array $result)
|
||||
{
|
||||
foreach (scandir($dir) as $file) {
|
||||
if ('.' === $file || '..' === $file) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_dir($dir.'/'.$file) === true) {
|
||||
rmdir_recursive($dir.'/'.$file, $result, $i);
|
||||
} else {
|
||||
$unlink = unlink($dir.'/'.$file);
|
||||
$res = [];
|
||||
if ($unlink === true) {
|
||||
$res['status'] = 0;
|
||||
} else {
|
||||
$res['status'] = 1;
|
||||
}
|
||||
|
||||
$res['type'] = 'f';
|
||||
$res['route'] = $dir.'/'.$file;
|
||||
array_push($result, $res);
|
||||
}
|
||||
}
|
||||
|
||||
$rmdir = rmdir($dir);
|
||||
$res = [];
|
||||
if ($rmdir === true) {
|
||||
$res['status'] = 0;
|
||||
} else {
|
||||
$res['status'] = 1;
|
||||
}
|
||||
|
||||
$res['type'] = 'd';
|
||||
$res['route'] = $dir;
|
||||
array_push($result, $res);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/*
|
||||
globals $, jQuery
|
||||
*/
|
||||
|
||||
var correct_install_progress = true;
|
||||
|
||||
function form_upload(homeurl) {
|
||||
|
@ -1246,11 +1250,11 @@ function check_install_package(package, homeurl) {
|
|||
data: parameters,
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
// Print the updated files and take the scroll to the bottom
|
||||
$("#log_zone").html(data.info);
|
||||
// Print the updated files and take the scroll to the bottom.
|
||||
$("#log_zone").append(data.info);
|
||||
$("#log_zone").scrollTop($("#log_zone").prop("scrollHeight"));
|
||||
|
||||
// Change the progress bar
|
||||
// Change the progress bar.
|
||||
if (
|
||||
$("#form-offline_update ul")
|
||||
.find("li")
|
||||
|
@ -1271,14 +1275,17 @@ function check_install_package(package, homeurl) {
|
|||
.trigger("change");
|
||||
}
|
||||
|
||||
// The class loading is present until the update ends
|
||||
// The class loading is present until the update ends.
|
||||
var isInstalling = $("#form-offline_update ul")
|
||||
.find("li")
|
||||
.hasClass("loading");
|
||||
if (data.progress < 100 && isInstalling) {
|
||||
// Recursive call to check the update status
|
||||
// Recursive call to check the update status.
|
||||
check_install_package(package, homeurl);
|
||||
}
|
||||
|
||||
//Check if exist remove files.
|
||||
delete_desired_files(homeurl);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -2290,3 +2297,108 @@ function remove_rr_file_to_extras(homeurl) {
|
|||
success: function(data) {}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Function delete files desired and add extras/delete_files.txt.
|
||||
*
|
||||
* @param string homeurl Url.
|
||||
*/
|
||||
function delete_desired_files(homeurl) {
|
||||
var home_url = typeof homeurl !== "undefined" ? homeurl + "/" : "";
|
||||
|
||||
var parameters = {
|
||||
page: "include/ajax/update_manager.ajax",
|
||||
delete_desired_files: 1
|
||||
};
|
||||
|
||||
jQuery.ajax({
|
||||
data: parameters,
|
||||
type: "POST",
|
||||
url: home_url + "ajax.php",
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
var translate = data.translate;
|
||||
// Print the deleted files.
|
||||
// Print title
|
||||
$("#log_zone").append(
|
||||
"</br></br><span class='log_zone_line log_zone_line_bolder';>" +
|
||||
translate.title +
|
||||
": </span></br></br>"
|
||||
);
|
||||
$.each(data, function(key, value) {
|
||||
var log_zone_line_class = "log_zone_line ";
|
||||
var msg = "";
|
||||
switch (value.status) {
|
||||
case -1:
|
||||
//Not exits file.
|
||||
msg = translate.not_file;
|
||||
break;
|
||||
case 0:
|
||||
//File or directory deleted successfully.
|
||||
if (value.type === "f") {
|
||||
log_zone_line_class += "";
|
||||
} else {
|
||||
log_zone_line_class += "log_zone_line_bolder";
|
||||
}
|
||||
|
||||
msg = value.route;
|
||||
break;
|
||||
case 1:
|
||||
//Problem delete file or directory.
|
||||
if (value.type === "f") {
|
||||
log_zone_line_class += "log_zone_line_error";
|
||||
} else {
|
||||
log_zone_line_class += "log_zone_line_error log_zone_line_bolder";
|
||||
}
|
||||
|
||||
msg = value.route + " ( " + translate.not_deleted + " ) ";
|
||||
break;
|
||||
case 2:
|
||||
//Not found file or directory.
|
||||
if (value.type === "f") {
|
||||
log_zone_line_class += "log_zone_line_error";
|
||||
} else {
|
||||
log_zone_line_class += "log_zone_line_error log_zone_line_bolder";
|
||||
}
|
||||
|
||||
msg = value.route + " ( " + translate.not_found + " ) ";
|
||||
break;
|
||||
case 3:
|
||||
//Don`t read file deleet_files.txt.
|
||||
log_zone_line_class += "log_zone_line_error log_zone_line_bolder";
|
||||
msg = translate.not_read;
|
||||
break;
|
||||
case 4:
|
||||
//"deleted" folder could not be created.
|
||||
log_zone_line_class += "log_zone_line_error log_zone_line_bolder";
|
||||
msg = value.route + " ( " + translate.folder_deleted_f + " ) ";
|
||||
break;
|
||||
case 5:
|
||||
//"deleted" folder was created.
|
||||
log_zone_line_class += "log_zone_line_bolder";
|
||||
msg = translate.folder_deleted_t;
|
||||
break;
|
||||
case 6:
|
||||
//The "delete files" could not be the "delete" folder.
|
||||
log_zone_line_class += "log_zone_line_error log_zone_line_bolder";
|
||||
msg = value.route + " ( " + translate.move_file_f + " ) ";
|
||||
break;
|
||||
case 7:
|
||||
//The "delete files" is moved to the "delete" folder.
|
||||
log_zone_line_class += "log_zone_line_bolder";
|
||||
msg = translate.move_file_d;
|
||||
break;
|
||||
case "translate":
|
||||
default:
|
||||
// It can not come without state.
|
||||
break;
|
||||
}
|
||||
|
||||
//Print line.
|
||||
$("#log_zone").append(
|
||||
"<span class='" + log_zone_line_class + "' >" + msg + "</span><br>"
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -3920,6 +3920,18 @@ div.simple_value > a > span.text p {
|
|||
font-size: 18pt;
|
||||
}
|
||||
|
||||
span.log_zone_line {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
span.log_zone_line_error {
|
||||
color: red;
|
||||
}
|
||||
|
||||
span.log_zone_line_bolder {
|
||||
font-weight: bolder;
|
||||
}
|
||||
|
||||
/* global */
|
||||
.readonly {
|
||||
background-color: #dedede !important;
|
||||
|
|
Loading…
Reference in New Issue