Added changes to finish rr feature. Ticket #169

This commit is contained in:
Arturo Gonzalez 2017-02-14 09:36:11 +01:00
parent 22e81a0c2f
commit 584427de06
11 changed files with 116 additions and 187 deletions

View File

@ -156,6 +156,7 @@ ALTER TABLE trel_item ADD `id_map` int(11) NOT NULL DEFAULT 0;
INSERT INTO `tconfig` (`token`, `value`) VALUES ('big_operation_step_datos_purge', '100');
INSERT INTO `tconfig` (`token`, `value`) VALUES ('small_operation_step_datos_purge', '1000');
INSERT INTO `tconfig` (`token`, `value`) VALUES ('days_autodisable_deletion', '30');
INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 0);
-- ---------------------------------------------------------------------
-- Table `tplanned_downtime_agents`

View File

@ -79,6 +79,7 @@ UPDATE talert_commands SET fields_descriptions = '[\"Integria IMS API&
INSERT INTO tconfig (token, value) VALUES ('big_operation_step_datos_purge', '100');
INSERT INTO tconfig (token, value) VALUES ('small_operation_step_datos_purge', '1000');
INSERT INTO tconfig (token, value) VALUES ('days_autodisable_deletion', '30');
INSERT INTO tconfig (token, value) VALUES ('MR', 0);
-- ---------------------------------------------------------------------
-- Table `tplanned_downtime_agents`

View File

@ -26,22 +26,14 @@ 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;
}
if (!$config["MR"]) {
$config["MR"] = 0;
}
echo '<a class="white_bold footer" target="_blank" href="' . $config["homeurl"] . $license_file. '">';
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 sprintf(__('Pandora FMS %s - Build %s - MR %s', $pandora_version, $build_version, $config["MR"]));
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>';

View File

@ -17,13 +17,14 @@ if (is_ajax ()) {
global $config;
check_login();
$updare_rr_open = get_parameter('updare_rr_open', 0);
$updare_rr = get_parameter('updare_rr', 0);
if ($updare_rr_open) {
if ($updare_rr) {
$number = get_parameter('number');
$dir = $config["homedir"]."/extras/mr";
$file = "$dir/$number.open.sql";
$file = "$dir/$number.sql";
$dangerous_query = false;
$mr_file = fopen($file, "r");
@ -44,30 +45,29 @@ if (is_ajax ()) {
else {
if (file_exists($dir) && is_dir($dir)) {
if (is_readable($dir)) {
if ($config["minor_release_open"] >= $number) {
if ($config["MR"] >= $number) {
if (!file_exists($dir."/updated") || !is_dir($dir."/updated")) {
mkdir($dir."/updated");
}
$file_dest = "$dir/updated/$number.open.sql";
$file_dest = "$dir/updated/$number.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);
$update_config = update_config_token("MR", $number);
if ($update_config) {
$config["minor_release_open"] = $number;
$config["MR"] = $number;
}
if ($config["minor_release_open"] == $number) {
if ($config["MR"] == $number) {
if (!file_exists($dir."/updated") || !is_dir($dir."/updated")) {
mkdir($dir."/updated");
}
$file_dest = "$dir/updated/$number.open.sql";
$file_dest = "$dir/updated/$number.sql";
if (copy($file, $file_dest)) {
unlink($file);

View File

@ -56,21 +56,12 @@ $no_login_msg = "";
// Don't change the format, it is parsed by applications
switch($info) {
case '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 (!$config["MR"]) {
$config["MR"] = 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"];
}
echo 'Pandora FMS ' . $pandora_version . ' - ' . $build_version . " MR" . $config["MR"];
exit;
}

View File

@ -37,9 +37,9 @@ function mysql_connect_db($host = null, $db = null, $user = null, $pass = null,
// Non-persistent connection: This will help to avoid mysql errors like "has gone away" or locking problems
// If you want persistent connections change it to mysql_pconnect().
if ($config["mysqli"] === true) {
if ($config["mysqli"]) {
$connect_id = mysqli_connect($host, $user, $pass, $db, $port);
if (mysqli_connect_error() > 0) {
if (mysqli_connect_errno() > 0) {
return false;
}
db_change_cache_id ($db, $host);
@ -1080,7 +1080,7 @@ function mysql_db_get_all_row_by_steps_sql($new = true, &$result, $sql = null) {
function mysql_db_process_sql_begin() {
global $config;
if ($config["mysqli"] === true) {
if ($config["mysqli"]) {
mysqli_query ($config['dbconnection'], 'SET AUTOCOMMIT = 0');
mysqli_query ($config['dbconnection'], 'START TRANSACTION');
}
@ -1096,7 +1096,7 @@ function mysql_db_process_sql_begin() {
function mysql_db_process_sql_commit() {
global $config;
if ($config["mysqli"] === true) {
if ($config["mysqli"]) {
mysqli_query ($config['dbconnection'], 'COMMIT');
mysqli_query ($config['dbconnection'], 'SET AUTOCOMMIT = 1');
}
@ -1112,7 +1112,7 @@ function mysql_db_process_sql_commit() {
function mysql_db_process_sql_rollback() {
global $config;
if ($config["mysqli"] === true) {
if ($config["mysqli"]) {
mysqli_query ($config['dbconnection'], 'ROLLBACK ');
mysqli_query ($config['dbconnection'], 'SET AUTOCOMMIT = 1');
}
@ -1144,7 +1144,7 @@ function mysql_safe_sql_string($string) {
function mysql_db_get_last_error() {
global $config;
if ($config["mysqli"] === true) {
if ($config["mysqli"]) {
return mysqli_error();
}
else {
@ -1188,7 +1188,7 @@ function mysql_get_system_time() {
function mysql_db_get_type_field_table($table, $field) {
global $config;
if ($config["mysqli"] === true) {
if ($config["mysqli"]) {
$result = mysqli_query($config['dbconnection'], 'SELECT parameters FROM ' . $table);
return mysqli_fetch_field_direct($result, $field);
@ -1221,7 +1221,7 @@ function mysql_db_get_table_count($sql, $search_history_db = false) {
// Connect to the history DB
if (! isset ($config['history_db_connection']) || $config['history_db_connection'] === false) {
if ($config["mysqli"] === true) {
if ($config["mysqli"]) {
$config['history_db_connection'] = mysqli_connect_db ($config['history_db_host'], $config['history_db_user'], io_output_password($config['history_db_pass']), $config['history_db_name'], $config['history_db_port'], false);
}
else {
@ -1272,7 +1272,7 @@ function mysql_db_process_file ($path, $handle_error = true) {
$query .= $sql_line;
if (preg_match("/;[\040]*\$/", $sql_line)) {
if ($config["mysqli"] === true) {
if ($config["mysqli"]) {
$query_result = mysqli_query($config['dbconnection'], $query);
}
else {
@ -1325,7 +1325,6 @@ function db_run_sql_file ($location) {
// Load file
$commands = file_get_contents($location);
// Delete comments
$lines = explode("\n", $commands);
$commands = '';
@ -1339,23 +1338,51 @@ function db_run_sql_file ($location) {
// Convert to array
$commands = explode(";", $commands);
// Run commands
mysql_db_process_sql_begin(); // Begin transaction
if ($config['mysqli']) {
$mysqli = new mysqli($config["dbhost"], $config["dbuser"], $config["dbpass"], $config["dbname"], $config["dbport"]);
// Run commands
$mysqli->query($config['dbconnection'], 'SET AUTOCOMMIT = 0');
$mysqli->query($config['dbconnection'], 'START TRANSACTION');
}
else {
// Run commands
mysql_db_process_sql_begin(); // Begin transaction
}
foreach ($commands as $command) {
if (trim($command)) {
$result = mysql_query($command);
if ($config['mysqli']) {
$result = $mysqli->query($command);
}
else {
$result = mysql_query($command);
}
if (!$result) {
break; // Error
}
}
}
if ($result) {
mysql_db_process_sql_commit(); // Save results
if ($config['mysqli']) {
$mysqli->query($config['dbconnection'], 'COMMIT');
$mysqli->query($config['dbconnection'], 'SET AUTOCOMMIT = 1');
}
else {
mysql_db_process_sql_commit(); // Save results
}
return true;
}
else {
mysql_db_process_sql_rollback(); // Undo results
if ($config['mysqli']) {
$mysqli->query($config['dbconnection'], 'ROLLBACK ');
$mysqli->query($config['dbconnection'], 'SET AUTOCOMMIT = 1');
}
else {
mysql_db_process_sql_rollback(); // Undo results
}
return false;
}
}

View File

@ -2681,17 +2681,7 @@ function update_config_token ($cfgtoken, $cfgvalue) {
}
}
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) {
function get_number_of_mr() {
global $config;
$dir = $config["homedir"]."/extras/mr";
@ -2699,37 +2689,17 @@ function get_number_of_mr($mode) {
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
$files = scandir($dir); // Get all the files from the directory ordered by asc
if ($files !== false) {
$pattern = "/^\d+\.sql$/";
$sqlfiles = preg_grep($pattern, $files); // Get the name of the correct files
$pattern = "/\.sql$/";
$replacement = "";
$sqlfiles_num = preg_replace($pattern, $replacement, $sqlfiles);
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;
}
}
foreach ($sqlfiles_num as $num) {
$mr_size[] = $num;
}
}
}

View File

@ -1682,63 +1682,24 @@ function db_check_minor_relase_available () {
$dir = $config["homedir"]."/extras/mr";
$have_ent_minor = false;
$have_open_minor = false;
$have_minor_release = 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;
}
$pattern = "/^\d+\.sql$/";
$sqlfiles = preg_grep($pattern, $files); // Get the name of the correct files
$files = null;
$pattern = "/\.sql$/";
$replacement = "";
$sqlfiles_num = preg_replace($pattern, $replacement, $sqlfiles); // Get the number of the file
if ($sqlfiles_num) {
foreach ($sqlfiles_num as $sqlfile_num) {
if ($config["MR"] < $sqlfile_num) {
$have_minor_release = true;
}
}
}
@ -1746,7 +1707,7 @@ function db_check_minor_relase_available () {
}
}
if ($have_open_minor || $have_ent_minor) {
if ($have_minor_release) {
return true;
}
else {

View File

@ -469,8 +469,7 @@ if (! isset ($config['id_user'])) {
}
if ($have_minor_releases) {
$size_mr_o = get_number_of_mr('open');
$size_mr_e = get_number_of_mr('enterprise');
$size_mr = get_number_of_mr();
echo "<div class= 'dialog ui-dialog-content' title='".__("Minor release available")."' id='mr_dialog2'>" . __('') . "</div>";
?>
<script type="text/javascript" language="javascript">
@ -486,17 +485,18 @@ if (! isset ($config['id_user'])) {
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(","));
"Apply minor releases": function () {
var n_mr = '<?php echo implode(",", $size_mr);?>';
apply_minor_release(n_mr.split(","));
},
Cancel: function() {
"Cancel": function () {
$(this).dialog("close");
}
}
});
$('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>";
@ -975,14 +975,18 @@ require('include/php_to_js_values.php');
};
})();
function apply_minor_release (n_mr_o, n_mr_e) {
function apply_minor_release (n_mr) {
var error = false;
$.each(n_mr_o, function(i, open_mr) {
$("#apply_rr_button").remove();
$("#cancel_rr_button").text("Close");
$('#mr_dialog2').empty();
$('#mr_dialog2').append("<img id=\"rr_image\" src=\"<?php echo $config['homeurl'] . 'images/spinner.gif'; ?>\">");
$.each(n_mr, function(i, mr) {
var params = {};
params["updare_rr_open"] = 1;
params["number"] = open_mr;
params["updare_rr"] = 1;
params["number"] = mr;
params["page"] = "include/ajax/rolling_release.ajax";
jQuery.ajax ({
data: params,
async: false,
@ -991,44 +995,25 @@ require('include/php_to_js_values.php');
url: "ajax.php",
success: function (data) {
if (data != "") {
alert("Error: " + data);
$('#mr_dialog2').empty();
$('#mr_dialog2').html("<h2>" + data + "</h2>");
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;
else {
$('#mr_dialog2').append("<p>- Applying DB MR #" + mr + "</p>");
}
}
});
if (error2 == true) {
if (error) {
return false;
}
});
if (!error && !error2) {
alert("Updated finished successfully");
$('#rr_image').remove();
if (!error) {
$('#mr_dialog2').append("<h2>Updated finished successfully</h2>");
}
}

View File

@ -137,6 +137,7 @@ INSERT INTO tconfig (token, value) VALUES ('custom_report_front_header', '');
INSERT INTO tconfig (token, value) VALUES ('custom_report_front_footer', '');
INSERT INTO tconfig (token, value) VALUES ('identification_reminder', 1);
INSERT INTO tconfig (token, value) VALUES ('identification_reminder_timestamp', 0);
INSERT INTO tconfig (token, value) VALUES ('MR', 0);
INSERT INTO tconfig (token, value) VALUES ('post_process_custom_values', '{"0.00000038580247":"Seconds&#x20;to&#x20;months","0.00000165343915":"Seconds&#x20;to&#x20;weeks","0.00001157407407":"Seconds&#x20;to&#x20;days","0.01666666666667":"Seconds&#x20;to&#x20;minutes","0.00000000093132":"Bytes&#x20;to&#x20;Gigabytes","0.00000095367432":"Bytes&#x20;to&#x20;Megabytes","0.0009765625":"Bytes&#x20;to&#x20;Kilobytes","0.00000001653439":"Timeticks&#x20;to&#x20;weeks","0.00000011574074":"Timeticks&#x20;to&#x20;days"}');
COMMIT;

View File

@ -109,7 +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),
('MR', 0),
('identification_reminder', 1),
('identification_reminder_timestamp', 0),
('post_process_custom_values', '{"0.00000038580247":"Seconds&#x20;to&#x20;months","0.00000165343915":"Seconds&#x20;to&#x20;weeks","0.00001157407407":"Seconds&#x20;to&#x20;days","0.01666666666667":"Seconds&#x20;to&#x20;minutes","0.00000000093132":"Bytes&#x20;to&#x20;Gigabytes","0.00000095367432":"Bytes&#x20;to&#x20;Megabytes","0.0009765625":"Bytes&#x20;to&#x20;Kilobytes","0.00000001653439":"Timeticks&#x20;to&#x20;weeks","0.00000011574074":"Timeticks&#x20;to&#x20;days"}');