mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 00:34:46 +02:00
Changed rolling release manager system.
This commit is contained in:
parent
b706e92b34
commit
8c20874a88
@ -233,12 +233,10 @@ config_check();
|
||||
$check_minor_release_available = false;
|
||||
$pandora_management = check_acl($config['id_user'], 0, "PM");
|
||||
|
||||
if (is_user_admin($config['id_user'])) {
|
||||
$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', 'minor release/s available');
|
||||
}
|
||||
$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) {
|
||||
|
104
pandora_console/include/ajax/rolling_release.ajax.php
Normal file
104
pandora_console/include/ajax/rolling_release.ajax.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?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);
|
||||
$check_minor_number = get_parameter('check_minor_number', 0);
|
||||
$check_finish = get_parameter('check_finish', 0);
|
||||
|
||||
if ($updare_rr_open) {
|
||||
$number = get_parameter('number');
|
||||
$dir = $config["homedir"]."/extras/mr";
|
||||
|
||||
$file = "$dir/$number.open.sql";
|
||||
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;
|
||||
}
|
||||
else if ($check_finish) {
|
||||
$check = db_check_minor_relase_available();
|
||||
|
||||
if (file_exists($config["homedir"] . "/extras/mr/error.txt")) {
|
||||
unlink($config["homedir"] . "/extras/mr/error.txt");
|
||||
$check = 2;
|
||||
}
|
||||
|
||||
echo $check;
|
||||
return;
|
||||
}
|
||||
else if ($check_minor_number) {
|
||||
echo $config['minor_release_open'];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1220,194 +1220,4 @@ function db_run_sql_file ($location) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the file or files in /extras/mr and apply minor releases.
|
||||
*
|
||||
* @return string Return error/success message.
|
||||
*/
|
||||
function db_update_schema () {
|
||||
global $config;
|
||||
|
||||
$dir = $config["homedir"]."/extras/mr";
|
||||
$message = '';
|
||||
|
||||
if (file_exists($dir) && is_dir($dir)) {
|
||||
if (is_readable($dir)) {
|
||||
if (enterprise_installed()) {
|
||||
$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); // Get the number of the file
|
||||
$sqlfiles = null;
|
||||
|
||||
if ($sqlfiles_num) {
|
||||
foreach ($sqlfiles_num as $sqlfile_num) {
|
||||
|
||||
$file = "$dir/$sqlfile_num.open.sql";
|
||||
|
||||
if ($config["minor_release_open"] >= $sqlfile_num) {
|
||||
if (!file_exists($dir."/updated") || !is_dir($dir."/updated")) {
|
||||
mkdir($dir."/updated");
|
||||
}
|
||||
$file_dest = "$dir/updated/$sqlfile_num.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", $sqlfile_num);
|
||||
if ($update_config) {
|
||||
$config["minor_release_open"] = $sqlfile_num;
|
||||
}
|
||||
|
||||
if ($config["minor_release_open"] == $sqlfile_num) {
|
||||
if (!file_exists($dir."/updated") || !is_dir($dir."/updated")) {
|
||||
mkdir($dir."/updated");
|
||||
}
|
||||
|
||||
$file_dest = "$dir/updated/$sqlfile_num.open.sql";
|
||||
|
||||
if (copy($file, $file_dest)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
$message = "<h3 class='suc'>".__('The database schema has been updated to the minor release')." $sqlfile_num</h3>";
|
||||
}
|
||||
else {
|
||||
$message = "<h3 class='error'>".__('An error occurred while updating the database schema to the minor release')." $sqlfile_num</h3>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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) {
|
||||
|
||||
$file = "$dir/$sqlfile_num2.ent.sql";
|
||||
|
||||
if ($config["minor_release_enterprise"] >= $sqlfile_num2) {
|
||||
if (!file_exists($dir."/updated") || !is_dir($dir."/updated")) {
|
||||
mkdir($dir."/updated");
|
||||
}
|
||||
$file_dest = "$dir/updated/$sqlfile_num2.ent.sql";
|
||||
if (copy($file, $file_dest)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$result = db_run_sql_file($file);
|
||||
|
||||
if ($result) {
|
||||
$update_config2 = update_config_token("minor_release_enterprise", $sqlfile_num2);
|
||||
if ($update_config2) {
|
||||
$config["minor_release_enterprise"] = $sqlfile_num2;
|
||||
}
|
||||
|
||||
if ($config["minor_release_enterprise"] == $sqlfile_num2) {
|
||||
if (!file_exists($dir."/updated") || !is_dir($dir."/updated")) {
|
||||
mkdir($dir."/updated");
|
||||
}
|
||||
$file_dest = "$dir/updated/$sqlfile_num2.ent.sql";
|
||||
if (copy($file, $file_dest)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
$message = "<h3 class='suc'>".__('The database schema has been updated to the minor release')." $sqlfile_num2</h3>";
|
||||
}
|
||||
else {
|
||||
$message = "<h3 class='error'>".__('An error occurred while updating the database schema to the minor release')." $sqlfile_num2</h3>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$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
|
||||
$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) {
|
||||
|
||||
$file = "$dir/$sqlfile_num.open.sql";
|
||||
|
||||
if ($config["minor_release_open"] >= $sqlfile_num) {
|
||||
if (!file_exists($dir."/updated") || !is_dir($dir."/updated")) {
|
||||
mkdir($dir."/updated");
|
||||
}
|
||||
$file_dest = "$dir/updated/$sqlfile_num.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", $sqlfile_num);
|
||||
if ($update_config) {
|
||||
$config["minor_release_open"] = $sqlfile_num;
|
||||
}
|
||||
|
||||
if ($config["minor_release_open"] == $sqlfile_num) {
|
||||
if (!file_exists($dir."/updated") || !is_dir($dir."/updated")) {
|
||||
mkdir($dir."/updated");
|
||||
}
|
||||
|
||||
$file_dest = "$dir/updated/$sqlfile_num.open.sql";
|
||||
if (copy($file, $file_dest)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
$message = "<h3 class='suc'>".__('The database schema has been updated to the minor release')." $sqlfile_num</h3>";
|
||||
}
|
||||
else {
|
||||
$message = "<h3 class='error'>".__('An error occurred while updating the database schema to the minor release ')." $sqlfile_num</h3>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$message = "<h3 class='error'>".__('The directory '.$dir.' should have read permissions in order to update the database schema')."</h3>";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$message = "<h3 class='error'>".__('The directory '.$dir.' does not exist')."</h3>";
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -2633,4 +2633,61 @@ function update_config_token ($cfgtoken, $cfgvalue) {
|
||||
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;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -433,7 +433,43 @@ if (! isset ($config['id_user'])) {
|
||||
$config['id_user'] = $nick_in_db;
|
||||
|
||||
if (is_user_admin($config['id_user'])) {
|
||||
$minor_release_message = db_update_schema();
|
||||
$have_minor_releases = db_check_minor_relase_available();
|
||||
|
||||
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: 400,
|
||||
height: 150,
|
||||
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");
|
||||
}
|
||||
}
|
||||
});
|
||||
$('#mr_dialog2').text('Do you want to apply minor releases?');
|
||||
$('#mr_dialog2').dialog('open');
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================
|
||||
@ -601,26 +637,6 @@ if ($old_global_counter_chat != $now_global_counter_chat) {
|
||||
$_SESSION['new_chat'] = true;
|
||||
}
|
||||
|
||||
if ($minor_release_message) {
|
||||
echo "<div class= 'dialog ui-dialog-content' title='".__("Minor release update")."' id='mr_dialog'>$minor_release_message</div>";
|
||||
echo "<script type='text/javascript'>";
|
||||
echo "$(document).ready (function () {";
|
||||
echo "$('#mr_dialog').dialog ({
|
||||
resizable: true,
|
||||
draggable: true,
|
||||
modal: true,
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: 'black'
|
||||
},
|
||||
width: 400,
|
||||
height: 150
|
||||
});";
|
||||
echo "$('#mr_dialog').dialog('open');";
|
||||
echo " });";
|
||||
echo "</script>";
|
||||
}
|
||||
|
||||
if (get_parameter ('login', 0) !== 0) {
|
||||
// Display news dialog
|
||||
include_once("general/news_dialog.php");
|
||||
@ -848,7 +864,84 @@ require('include/php_to_js_values.php');
|
||||
return rv;
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
function apply_minor_release (n_mr_o, n_mr_e) {
|
||||
$.each(n_mr_o, function(i, open_mr) {
|
||||
var params = {};
|
||||
var error = false;
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
$.each(n_mr_e, function(i, e_mr) {
|
||||
var params = {};
|
||||
var error2 = false;
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
check_is_finished_mr();
|
||||
}
|
||||
|
||||
function check_is_finished_mr () {
|
||||
var params = {};
|
||||
params["check_finish"] = 1;
|
||||
params["page"] = "include/ajax/rolling_release.ajax";
|
||||
|
||||
jQuery.ajax ({
|
||||
data: params,
|
||||
dataType: "html",
|
||||
type: "POST",
|
||||
url: "ajax.php",
|
||||
success: function (data) {
|
||||
if (data == 1) {
|
||||
setInterval(check_is_finished_mr, 2000);
|
||||
}
|
||||
else if (data == 0) {
|
||||
alert("Updated finished successfully");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//Dynamically assign footer position and width.
|
||||
function adjustFooter() {
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user