diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 2085274e62..3e19574b32 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2014-06-10 Miguel de Dios + + * godmode/update_manager_xxx/update_manager.online.php, + include/functions_update_manager.php, + include/javascript/update_manager.js, + include/ajax/update_manager.ajax.php: work in the first version of + new update manager. + 2014-06-10 Mario Pulido * pandoradb_data.sql: Fixed bug in plugin exec #803 diff --git a/pandora_console/godmode/update_manager_xxx/update_manager.online.php b/pandora_console/godmode/update_manager_xxx/update_manager.online.php index 675bd63cc8..5151148742 100644 --- a/pandora_console/godmode/update_manager_xxx/update_manager.online.php +++ b/pandora_console/godmode/update_manager_xxx/update_manager.online.php @@ -17,6 +17,7 @@ global $config; ui_require_css_file('update_manager', 'godmode/update_manager_xxx/'); +require_once("include/functions_update_manager.php"); enterprise_include_once("include/functions_update_manager.php"); /* Translators: Do not translade Update Manager, it's the name of the program */ diff --git a/pandora_console/include/ajax/update_manager.ajax.php b/pandora_console/include/ajax/update_manager.ajax.php index 2cfc76707b..9f645660a0 100644 --- a/pandora_console/include/ajax/update_manager.ajax.php +++ b/pandora_console/include/ajax/update_manager.ajax.php @@ -31,6 +31,10 @@ $check_progress_enterprise_update = (boolean) get_parameter("check_progress_ente $install_package_step2 = (boolean)get_parameter("install_package_step2"); $enterprise_install_package = (boolean) get_parameter("enterprise_install_package"); $enterprise_install_package_step2 = (boolean)get_parameter("enterprise_install_package_step2"); +$check_online_free_packages = (bool)get_parameter('check_online_free_packages'); +$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'); if ($upload_file) { ob_clean(); @@ -318,4 +322,157 @@ if ($enterprise_install_package_step2) { return; } + +if ($check_online_free_packages) { + + update_manager_check_online_free_packages(); + + return; +} + +if ($update_last_free_package) { + + $package = get_parameter('package', ''); + $version = get_parameter('version', ''); + $package_url = base64_decode($package); + + $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, $config['url_updatemanager']); + curl_setopt($curlObj, CURLOPT_URL, $package_url); + curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curlObj, CURLOPT_FOLLOWLOCATION, true); + //curl_setopt($curlObj, CURLOPT_POST, true); + //curl_setopt($curlObj, CURLOPT_POSTFIELDS, $params); + curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false); + $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')); + } + } + + return; +} + +if ($check_update_free_package) { + + + $progress_update = db_get_value('value', 'tconfig', + 'token', 'progress_update'); + + $progress_update_status = db_get_value('value', 'tconfig', + 'token', 'progress_update_status'); + $progress_update_status = json_decode($progress_update_status, true); + + switch ($progress_update_status['status']) { + case 'in_progress': + $correct = true; + $end = false; + break; + case 'fail': + $correct = false; + $end = false; + break; + case 'end': + $correct = true; + $end = true; + break; + } + + $progressbar_tag = progressbar($progress_update, 400, 20, + __("progress"), $config['fontpath']); + preg_match("/src='(.*)'/", $progressbar_tag, $matches); + $progressbar = $matches[1]; + + echo json_encode(array( + 'correct' => $correct, + 'end' => $end, + 'message' => $progress_update_status['message'], + 'progressbar' => $progressbar + )); + + return; +} + +if ($install_free_package) { + $version = get_parameter('version', ''); + + update_manager_starting_update(); + + + db_process_sql_update('tconfig', array('`value`' => $version), + array('`token`' => "current_package")); + $config['current_package'] = $version; + + sleep(3); + + + + $return["status"] = "success"; + $return["message"]= __("The package is installed."); + echo json_encode($return); +} ?> \ No newline at end of file diff --git a/pandora_console/include/functions_update_manager.php b/pandora_console/include/functions_update_manager.php index db951a8041..96c4d55b9d 100755 --- a/pandora_console/include/functions_update_manager.php +++ b/pandora_console/include/functions_update_manager.php @@ -36,7 +36,11 @@ function update_manager_get_config_values() { //TO DO $license = "TESTMIGUEL00B0WAW9BU1QM0RZ2QM0MZ3QN5M41R35S5S1DP"; - //$current_update = 11; + //~ $current_update = 9; + //~ $limit_count = 2; + $build_version = "140514"; + $pandora_version = "4.1"; + $license = "INTEGRIA-FREE"; return array( @@ -65,7 +69,7 @@ function rrmdir($dir) { function update_manager_install_package_step2() { global $config; - + ob_clean(); $package = (string) get_parameter("package"); @@ -194,6 +198,185 @@ function update_manager_install_package_step2() { } function update_manager_main() { + global $config; + + ?> + + + 'newest_package', + 'license' => $um_config_values['license'], + 'limit_count' => $um_config_values['limit_count'], + 'current_package' => $um_config_values['current_update'], + 'version' => $um_config_values['version'], + 'build' => $um_config_values['build']); + + + $curlObj = curl_init(); + curl_setopt($curlObj, CURLOPT_URL, $config['url_update_manager']); + curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curlObj, CURLOPT_POST, true); + curl_setopt($curlObj, CURLOPT_POSTFIELDS, $params); + curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false); + + $result = curl_exec($curlObj); + $http_status = curl_getinfo($curlObj, CURLINFO_HTTP_CODE); + curl_close($curlObj); + + + + + if ($http_status >= 400 && $http_status < 500) { + if ($is_ajax) { + echo __("Server not found."); + } else { + $update_message = __("Server not found."); + } + } + elseif ($http_status >= 500) { + if ($is_ajax) { + echo $result; + } else { + $update_message = $result; + } + } + else { + if ($is_ajax) { + $result = json_decode($result, true); + + if (!empty($result)) { + echo "

There is a new version: " . $result[0]['version'] . "

"; + echo "" . + __("Update to the last version") . ""; + } + else { + echo __("There is no update available."); + } + return; + } else { + if (!empty($result)) { + $result = json_decode($result, true); + $update_message = "There is a new version: " . $result[0]['version']; + } + + return $update_message; + } + } } + + +/** + * 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"; + + try { + $phar = new PharData($path_package); + rrmdir($config['attachment_store'] . "/downloads/temp_update/trunk"); + $phar->extractTo($config['attachment_store'] . "/downloads/temp_update"); + } + catch (Exception $e) { + // handle errors + + db_process_sql_update('tconfig', + array('value' => json_encode( + array( + 'status' => 'fail', + 'message' => __('Failed extracting the package to temp directory.') + ) + ) + ), + array('token' => 'progress_update_status')); + } + + db_process_sql_update('tconfig', + array('value' => 50), + array('token' => 'progress_update')); + + $full_path = $config['attachment_store'] . "/downloads/temp_update/trunk"; + + $homedir = $config['homedir']; + + $result = update_manager_recurse_copy($full_path, $homedir, + array('install.php')); + + if (!$result) { + db_process_sql_update('tconfig', + array('value' => json_encode( + array( + 'status' => 'fail', + 'message' => __('Failed the copying of the files.') + ) + ) + ), + array('token' => 'progress_update_status')); + } + else { + db_process_sql_update('tconfig', + array('value' => 100), + array('token' => 'progress_update')); + db_process_sql_update('tconfig', + array('value' => json_encode( + array( + 'status' => 'end', + 'message' => __('Package extracted successfully.') + ) + ) + ), + array('token' => 'progress_update_status')); + } +} + + +function update_manager_recurse_copy($src, $dst, $black_list) { + $dir = opendir($src); + @mkdir($dst); + @trigger_error("NONE"); + + //debugPrint("mkdir(" . $dst . ")", true); + while (false !== ( $file = readdir($dir)) ) { + if (( $file != '.' ) && ( $file != '..' ) && (!in_array($file, $black_list))) { + if ( is_dir($src . '/' . $file) ) { + if (!update_manager_recurse_copy($src . '/' . $file,$dst . '/' . $file, $black_list)) { + return false; + } + } + else { + $result = copy($src . '/' . $file,$dst . '/' . $file); + $error = error_get_last(); + + if (strstr($error['message'], "copy(") ) { + return false; + } + } + } + } + closedir($dir); + + return true; +} ?> \ No newline at end of file diff --git a/pandora_console/include/javascript/update_manager.js b/pandora_console/include/javascript/update_manager.js index f6f09614a0..6a74b9a254 100644 --- a/pandora_console/include/javascript/update_manager.js +++ b/pandora_console/include/javascript/update_manager.js @@ -277,4 +277,125 @@ function check_install_package(package) { } } }) +} + +function check_online_free_packages() { + $("#box_online .checking_package").show(); + + var parameters = {}; + parameters['page'] = 'include/ajax/update_manager.ajax'; + parameters['check_online_free_packages'] = 1; + + jQuery.post( + "ajax.php", + parameters, + function (data) { + $("#box_online .checking_package").hide(); + + $("#box_online .loading").hide(); + $("#box_online .content").html(data); + }, + "html" + ); +} + +function update_last_package(package, version) { + version_update = version; + + $("#box_online .content").html(""); + $("#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; + + jQuery.post( + "ajax.php", + parameters, + function (data) { + if (data['in_progress']) { + $("#box_online .loading").hide(); + $("#box_online .download_package").hide(); + + $("#box_online .content").html(data['message']); + + install_free_package(package,version); + setTimeout(check_progress_update, 1000); + } + else { + $("#box_online .content").html(data['message']); + } + }, + "json" + ); +} + +function check_progress_update() { + if (stop_check_progress) { + return; + } + + var parameters = {}; + parameters['page'] = 'include/ajax/update_manager.ajax'; + parameters['check_update_free_package'] = 1; + + jQuery.post( + "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(check_progress_update, 1000); + } + } + else { + //$("#box_online .content").html(data['message']); + } + }, + "json" + ); +} + +function install_free_package(package,version) { + var parameters = {}; + parameters['page'] = 'include/ajax/update_manager.ajax'; + parameters['install_free_package'] = 1; + parameters['package'] = package; + parameters['version'] = version; + + jQuery.post( + "ajax.php", + parameters, + function (data) { + if (data["status"] == "success") { + $("#box_online .loading").hide(); + $("#box_online .progressbar").hide(); + $("#box_online .content").html(data['message']); + stop_check_progress = 1; + } + else { + $("#box_online .loading").hide(); + $("#box_online .progressbar").hide(); + $("#box_online .content").html(data['message']); + stop_check_progress = 1; + } + }, + "json" + ); } \ No newline at end of file