From b9702a5b003b2aefae2c776e956c88110e462d3b Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Thu, 16 Mar 2017 18:07:19 +0100 Subject: [PATCH] Added a lot of changes in update manager online open to integrate with mr --- .../include/ajax/rolling_release.ajax.php | 2 - .../include/ajax/update_manager.ajax.php | 180 +++++++++--------- .../include/functions_update_manager.php | 24 ++- .../include/javascript/update_manager.js | 137 ++++++++----- 4 files changed, 205 insertions(+), 138 deletions(-) diff --git a/pandora_console/include/ajax/rolling_release.ajax.php b/pandora_console/include/ajax/rolling_release.ajax.php index d5fa664dd2..be5d6fec66 100644 --- a/pandora_console/include/ajax/rolling_release.ajax.php +++ b/pandora_console/include/ajax/rolling_release.ajax.php @@ -78,8 +78,6 @@ if (is_ajax ()) { $file_dest = $config["homedir"] . "/extras/mr/updated/$number.sql"; - chmod($file, 0777); - chmod($config["homedir"] . "/extras/mr/updated", 0777); if (copy($file, $file_dest)) { unlink($file); } diff --git a/pandora_console/include/ajax/update_manager.ajax.php b/pandora_console/include/ajax/update_manager.ajax.php index fba4ca45fa..41e7fd8983 100644 --- a/pandora_console/include/ajax/update_manager.ajax.php +++ b/pandora_console/include/ajax/update_manager.ajax.php @@ -37,6 +37,7 @@ $update_last_free_package = (bool)get_parameter('update_last_free_package'); $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'); if ($upload_file) { ob_clean(); @@ -377,93 +378,85 @@ if ($update_last_free_package) { $accept = (boolean)get_parameter('accept', false); $package_url = base64_decode($package); - if ($accept) { - $params = array('action' => 'get_package', - 'license' => $license, - 'limit_count' => $users, - 'current_package' => $current_package, - 'package' => $package, - 'version' => $config['version'], - 'build' => $config['build']); - - $curlObj = curl_init(); - curl_setopt($curlObj, CURLOPT_URL, $package_url); - curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curlObj, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false); - if (isset($config['update_manager_proxy_server'])) { - curl_setopt($curlObj, CURLOPT_PROXY, $config['update_manager_proxy_server']); - } - if (isset($config['update_manager_proxy_port'])) { - curl_setopt($curlObj, CURLOPT_PROXYPORT, $config['update_manager_proxy_port']); - } - if (isset($config['update_manager_proxy_user'])) { - curl_setopt($curlObj, CURLOPT_PROXYUSERPWD, $config['update_manager_proxy_user'] . ':' . $config['update_manager_proxy_password']); - } - - $result = curl_exec($curlObj); - $http_status = curl_getinfo($curlObj, CURLINFO_HTTP_CODE); - - curl_close($curlObj); + $params = array('action' => 'get_package', + 'license' => $license, + 'limit_count' => $users, + 'current_package' => $current_package, + 'package' => $package, + 'version' => $config['version'], + 'build' => $config['build']); + + $curlObj = curl_init(); + curl_setopt($curlObj, CURLOPT_URL, $package_url); + curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curlObj, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false); + if (isset($config['update_manager_proxy_server'])) { + curl_setopt($curlObj, CURLOPT_PROXY, $config['update_manager_proxy_server']); + } + if (isset($config['update_manager_proxy_port'])) { + curl_setopt($curlObj, CURLOPT_PROXYPORT, $config['update_manager_proxy_port']); + } + if (isset($config['update_manager_proxy_user'])) { + curl_setopt($curlObj, CURLOPT_PROXYUSERPWD, $config['update_manager_proxy_user'] . ':' . $config['update_manager_proxy_password']); + } + + $result = curl_exec($curlObj); + $http_status = curl_getinfo($curlObj, CURLINFO_HTTP_CODE); + + curl_close($curlObj); - if (empty($result)) { - echo json_encode(array( - 'in_progress' => false, - 'message' => __('Fail to update to the last package.'))); - } - else { - file_put_contents( - $config['attachment_store'] . "/downloads/last_package.tgz" , $result); - - echo json_encode(array( - 'in_progress' => true, - 'message' => __('Starting to update to the last package.'))); - - - $progress_update_status = db_get_value( - 'value', 'tconfig', 'token', 'progress_update_status'); - - - - if (empty($progress_update_status)) { - db_process_sql_insert('tconfig', - array( - 'value' => 0, - 'token' => 'progress_update') - ); - - db_process_sql_insert('tconfig', - array( - 'value' => json_encode( - array( - 'status' => 'in_progress', - 'message' => '' - )), - 'token' => 'progress_update_status') - ); - } - else { - db_process_sql_update('tconfig', - array('value' => 0), - array('token' => 'progress_update')); - - db_process_sql_update('tconfig', - array('value' => json_encode( - array( - 'status' => 'in_progress', - 'message' => '' - ) - ) - ), - array('token' => 'progress_update_status')); - } - } + if (empty($result)) { + echo json_encode(array( + 'in_progress' => false, + 'message' => __('Fail to update to the last package.'))); } else { - $return["in_progress"] = false; - $return["message"] = __("Package rejected."); - - echo json_encode($return); + file_put_contents( + $config['attachment_store'] . "/downloads/last_package.tgz" , $result); + + echo json_encode(array( + 'in_progress' => true, + 'message' => __('Starting to update to the last package.'))); + + + $progress_update_status = db_get_value( + 'value', 'tconfig', 'token', 'progress_update_status'); + + + + if (empty($progress_update_status)) { + db_process_sql_insert('tconfig', + array( + 'value' => 0, + 'token' => 'progress_update') + ); + + db_process_sql_insert('tconfig', + array( + 'value' => json_encode( + array( + 'status' => 'in_progress', + 'message' => '' + )), + 'token' => 'progress_update_status') + ); + } + else { + db_process_sql_update('tconfig', + array('value' => 0), + array('token' => 'progress_update')); + + db_process_sql_update('tconfig', + array('value' => json_encode( + array( + 'status' => 'in_progress', + 'message' => '' + ) + ) + ), + array('token' => 'progress_update_status')); + } } return; @@ -509,19 +502,32 @@ if ($check_update_free_package) { return; } -if ($install_free_package) { +if ($unzip_free_package) { $version = get_parameter('version', ''); $result = update_manager_starting_update(); + if ($result) { + $return["status"] = "correct"; + $return["message"]= __("The package is extracted."); + } + else { + $return["status"] = "error"; + $return["message"]= __("Error in package extraction."); + } + + echo json_encode($return); +} + +if ($install_free_package) { + $version = get_parameter('version', ''); + if ($result) update_manager_set_current_package($version); sleep(3); - - $return["status"] = "success"; $return["message"]= __("The package is installed."); echo json_encode($return); diff --git a/pandora_console/include/functions_update_manager.php b/pandora_console/include/functions_update_manager.php index c822005a5c..312d8fc963 100755 --- a/pandora_console/include/functions_update_manager.php +++ b/pandora_console/include/functions_update_manager.php @@ -604,11 +604,7 @@ function update_manager_remote_read_messages ($id_message) { return $result['success']; } -/** - * The update copy entirire the tgz or fail (leave some parts copies and some part not). - * This does make any thing with the BD. - */ -function update_manager_starting_update() { +function update_manager_extract_package() { global $config; $path_package = $config['attachment_store'] . @@ -636,8 +632,11 @@ function update_manager_starting_update() { $extracted = false; } } + $return = true; if($extracted === false) { + $return = false; + if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { // unsupported OS echo "This OS [" . PHP_OS . "] does not support direct extraction of tgz files. Upgrade PHP version to be > 5.5.0"; @@ -668,8 +667,21 @@ function update_manager_starting_update() { db_process_sql_update('tconfig', array('value' => 50), array('token' => 'progress_update')); + + return $return; +} + +/** + * The update copy entirire the tgz or fail (leave some parts copies and some part not). + * This does make any thing with the BD. + */ +function update_manager_starting_update() { + global $config; + + $path_package = $config['attachment_store'] . + "/downloads/last_package.tgz"; - + $full_path = $config['attachment_store'] . "/downloads/unix"; $homedir = $config['homedir']; diff --git a/pandora_console/include/javascript/update_manager.js b/pandora_console/include/javascript/update_manager.js index eda8f1a2ef..235531f425 100644 --- a/pandora_console/include/javascript/update_manager.js +++ b/pandora_console/include/javascript/update_manager.js @@ -844,6 +844,100 @@ function update_last_package(package, version, homeurl) { $("#box_online .loading").show(); $("#box_online .download_package").show(); + var parameters = {}; + parameters['page'] = 'include/ajax/update_manager.ajax'; + parameters['update_last_free_package'] = 1; + parameters['package'] = package; + parameters['version'] = version; + parameters['accept'] = 0; + + jQuery.post( + home_url + "ajax.php", + parameters, + function (data) { + if (data['in_progress']) { + $("#box_online .loading").hide(); + $("#box_online .download_package").hide(); + + $("#box_online .content").html(data['message']); + + var parameters2 = {}; + parameters2['page'] = 'include/ajax/update_manager.ajax'; + parameters2['unzip_free_package'] = 1; + parameters2['package'] = package; + parameters2['version'] = version; + + jQuery.post( + home_url + "ajax.php", + parameters2, + function (data) { + if (data['correct']) { + $("#box_online .loading").hide(); + $("#box_online .download_package").hide(); + + $("#box_online .content").html(data['message']); + + install_free_package_prev_step(package, version, homeurl); + } + else { + $("#box_online .content").html(data['message']); + } + }, + "json" + ); + } + else { + $("#box_online .content").html(data['message']); + } + }, + "json" + ); +} + +function check_progress_update(homeurl) { + var home_url = (typeof homeurl !== 'undefined') ? homeurl + '/' : ''; + + if (stop_check_progress) { + return; + } + + var parameters = {}; + parameters['page'] = 'include/ajax/update_manager.ajax'; + parameters['check_update_free_package'] = 1; + + jQuery.post( + home_url + "ajax.php", + parameters, + function (data) { + if (stop_check_progress) { + return; + } + + if (data['correct']) { + if (data['end']) { + //$("#box_online .content").html(data['message']); + } + else { + $("#box_online .progressbar").show(); + + $("#box_online .progressbar .progressbar_img").attr('src', + data['progressbar']); + + setTimeout(function () { + check_progress_update(homeurl); + }, 1000); + } + } + else { + correct_install_progress = false; + $("#box_online .content").html(data['message']); + } + }, + "json" + ); +} + +function install_free_package_prev_step(package, version, homeurl) { $("
").dialog ({ resizable: true, draggable: true, @@ -1244,49 +1338,6 @@ function update_last_package(package, version, homeurl) { $('#pkg_apply_dialog').dialog('open'); } -function check_progress_update(homeurl) { - var home_url = (typeof homeurl !== 'undefined') ? homeurl + '/' : ''; - - if (stop_check_progress) { - return; - } - - var parameters = {}; - parameters['page'] = 'include/ajax/update_manager.ajax'; - parameters['check_update_free_package'] = 1; - - jQuery.post( - home_url + "ajax.php", - parameters, - function (data) { - if (stop_check_progress) { - return; - } - - if (data['correct']) { - if (data['end']) { - //$("#box_online .content").html(data['message']); - } - else { - $("#box_online .progressbar").show(); - - $("#box_online .progressbar .progressbar_img").attr('src', - data['progressbar']); - - setTimeout(function () { - check_progress_update(homeurl); - }, 1000); - } - } - else { - correct_install_progress = false; - $("#box_online .content").html(data['message']); - } - }, - "json" - ); -} - function install_free_package(package, version, homeurl) { var home_url = (typeof homeurl !== 'undefined') ? homeurl + '/' : '';