From d73b391e16298154a0099e52ce3395516e8c373c Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 12 Apr 2012 11:31:45 +0000 Subject: [PATCH] 2012-04-12 Miguel de Dios * include/functions_config.php, extensions/update_manager.php, extensions/update_manager/lib/functions.ajax.php, extensions/update_manager/lib/libupdate_manager_client.php, extensions/update_manager/lib/functions.php, extensions/update_manager/settings.php, extensions/update_manager/main.php, extensions/update_manager/update_pandora.php: added feature to update the Pandora Console open. Merged from the branch "pandora_4.0" git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5957 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 13 + pandora_console/extensions/update_manager.php | 109 ++--- .../update_manager/lib/functions.ajax.php | 305 +++++++++---- .../update_manager/lib/functions.php | 205 ++++++++- .../lib/libupdate_manager_client.php | 4 + .../extensions/update_manager/main.php | 400 +++++++++--------- .../extensions/update_manager/settings.php | 50 ++- .../update_manager/update_pandora.php | 123 ++++-- pandora_console/include/functions_config.php | 199 +++++---- 9 files changed, 898 insertions(+), 510 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index cbb886f72d..ce5684c330 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,16 @@ +2012-04-12 Miguel de Dios + + * include/functions_config.php, extensions/update_manager.php, + extensions/update_manager/lib/functions.ajax.php, + extensions/update_manager/lib/libupdate_manager_client.php, + extensions/update_manager/lib/functions.php, + extensions/update_manager/settings.php, + extensions/update_manager/main.php, + extensions/update_manager/update_pandora.php: added feature to update the + Pandora Console open. + + Merged from the branch "pandora_4.0" + 2012-04-12 Ramon Novoa * operation/servers/recon_view.php: Fixed a broken link. diff --git a/pandora_console/extensions/update_manager.php b/pandora_console/extensions/update_manager.php index e78bdd9e8d..d127d416b7 100644 --- a/pandora_console/extensions/update_manager.php +++ b/pandora_console/extensions/update_manager.php @@ -14,6 +14,30 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +if (is_ajax ()) { + global $config; + + check_login (); + + if (! check_acl ($config["id_user"], 0, "PM")) { + db_pandora_audit("ACL Violation", + "Trying to access event viewer"); + require ("general/noaccess.php"); + return; + } + + require_once('update_manager/lib/functions.ajax.php'); + + $checking_online_enterprise_package = + (bool)get_parameter('checking_online_enterprise_package', false); + + if ($checking_online_enterprise_package) { + checking_online_enterprise_package(); + } + + return; +} + function load_update_manager_lib () { set_time_limit (0); require_once ('update_manager/load_updatemanager.php'); @@ -33,34 +57,6 @@ function update_settings_database_connection () { function pandora_update_manager_install () { global $config; - if (isset ($config['update_manager_installed'])) { - $update_server_path = db_get_value('value', 'tupdate_settings', '`key`', 'update_server_path'); - - - ////OVERWRITE EVER THE UPDATE SERVER PATH.////////////////////// - /* - The server path is ever the value from PHP. And you wonder - "Why?". Yes, I wonder too. And it is for when the user update - the Pandora Console PHP files to new version, this conf param - "automagic" change to new path for the new updates in the new - version. - */ - - if ($update_server_path != '/pandoraupdate4/server.php') { - $result = db_process_sql_update('tupdate_settings', - array('value' => '/pandoraupdate4/server.php'), - array('key' => 'update_server_path')); - - if ($result === false) { - db_pandora_audit("ERROR update extension", "Error in the update the extension 'update manager' when update the 'update_server_path' field."); - } - } - //////////////////////////////////////////////////////////////// - - /* Already installed */ - return; - } - load_update_manager_lib (); /* SQL installation */ @@ -97,21 +93,24 @@ function pandora_update_manager_uninstall () { switch ($config["dbtype"]) { case "mysql": - db_process_sql ('DELETE FROM `tconfig` WHERE `token` = "update_manager_installed"'); + db_process_sql ('DELETE FROM `tconfig` + WHERE `token` = "update_manager_installed"'); db_process_sql ('DROP TABLE `tupdate_settings`'); db_process_sql ('DROP TABLE `tupdate_journal`'); db_process_sql ('DROP TABLE `tupdate`'); db_process_sql ('DROP TABLE `tupdate_package`'); break; case "postgresql": - db_process_sql ('DELETE FROM "tconfig" WHERE "token" = \'update_manager_installed\''); + db_process_sql ('DELETE FROM "tconfig" + WHERE "token" = \'update_manager_installed\''); db_process_sql ('DROP TABLE "tupdate_settings"'); db_process_sql ('DROP TABLE "tupdate_journal"'); db_process_sql ('DROP TABLE "tupdate"'); db_process_sql ('DROP TABLE "tupdate_package"'); break; case "oracle": - db_process_sql ('DELETE FROM tconfig WHERE token = \'update_manager_installed\''); + db_process_sql ('DELETE FROM tconfig + WHERE token = \'update_manager_installed\''); db_process_sql ('DROP TABLE tupdate_settings'); db_process_sql ('DROP TABLE tupdate_journal'); db_process_sql ('DROP TABLE tupdate'); @@ -132,39 +131,41 @@ function pandora_update_manager_main () { update_settings_database_connection (); require_once ('update_manager/main.php'); + + main_view(); } function pandora_update_manager_login () { global $config; - // If first time, make the first autoupdate and disable it in DB - if (!isset($config["autoupdate"])){ - $config["autoupdate"] = 1; - - db_process_sql_insert('tconfig', array('token' => 'autoupdate', 'value' => 0)); - } - if ($config["autoupdate"] == 0) return; - load_update_manager_lib (); + unset($_SESSION['new_update']); - um_db_connect ('mysql', $config['dbhost'], $config['dbuser'], + if (enterprise_installed()) { + um_db_connect ('mysql', $config['dbhost'], $config['dbuser'], $config['dbpass'], $config['dbname']); - $settings = um_db_load_settings (); - - $user_key = get_user_key ($settings); - - $package = um_client_check_latest_update ($settings, $user_key); - - if (is_object ($package)) { - echo '
'; - echo 'info '; - echo __('There\'s a new update for Pandora'); - echo '. '; - echo __('More info'); - echo ''; - echo '
'; + $settings = um_db_load_settings (); + + $user_key = get_user_key ($settings); + + $package = um_client_check_latest_update ($settings, $user_key); + + if (is_object ($package)) { + if ($package->id != 'ERROR_NON_NUMERIC_FOUND') + $_SESSION['new_update'] = 'new'; + } + } + else { + require( + "extensions/update_manager/lib/functions.ajax.php"); + + $result = update_pandora_get_packages_online_ajax(false); + + if ($result['correct']) { + $_SESSION['new_update'] = 'new'; + } } } diff --git a/pandora_console/extensions/update_manager/lib/functions.ajax.php b/pandora_console/extensions/update_manager/lib/functions.ajax.php index 33e3a511ee..38d8ede4d6 100644 --- a/pandora_console/extensions/update_manager/lib/functions.ajax.php +++ b/pandora_console/extensions/update_manager/lib/functions.ajax.php @@ -14,8 +14,12 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -function update_pandora_get_packages_online_ajax() { +function update_pandora_get_packages_online_ajax($ajax = true) { global $config; + + require_once($config["homedir"] . + "/extensions/update_manager/lib/functions.php"); + global $conf_update_pandora; if (empty($conf_update_pandora)) $conf_update_pandora = update_pandora_get_conf(); @@ -56,7 +60,14 @@ function update_pandora_get_packages_online_ajax() { } else { $value = $result->value(); - $package = $value->scalarval(); + list($k,$v) = $value->structeach(); + if ($k == 'package') { + $package = $v->scalarval(); + } + list($k,$v) = $value->structeach(); + if ($k == 'timestamp') { + $timestamp = $v->scalarval(); + } $return['correct'] = 1; if (empty($package)) { @@ -65,10 +76,15 @@ function update_pandora_get_packages_online_ajax() { $return['last'] = $last; $return['package'] = $package; + $return['timestamp'] = date($config["date_format"], $timestamp); + $return['text_adv'] = html_print_image('images/world.png', true); $return['end'] = 1; } - echo json_encode($return); + if ($ajax) + echo json_encode($return); + else + return $return; } function update_pandora_download_package() { @@ -79,6 +95,10 @@ function update_pandora_download_package() { require_once ($config["homedir"] . "/extensions/update_manager/lib/libupdate_manager_client.php"); + require_once ($config["homedir"] . + "/extensions/update_manager/lib/libupdate_manager.php"); + require_once ($config["homedir"] . + "/extensions/update_manager/load_updatemanager.php"); $dir = $config['attachment_store'] . '/update_pandora/'; @@ -106,113 +126,158 @@ function update_pandora_download_package() { $return = array('correct' => 0); } else { - $conf_update_pandora['last_contact'] = time(); - update_pandora_update_conf(); - $value = $result->value(); $package_url = $value->scalarval(); - if (empty($package_url)) { - $info_json = json_encode(array('correct' => 0)); - - file_put_contents('/tmp/' . $package . '.info.txt', $info_json, LOCK_EX); + if ($conf_update_pandora['download_mode'] == 'wget') { + $command = "wget " . + $package_url . " -P " . $dir . + " -o /tmp/" . $package . ".info.txt"; $return = array('correct' => 0); + + exec($command); + unlink('/tmp/' . $package . '.info.txt'); + + $return['correct'] = 1; } else { - $targz = $package; - $url = $package_url; - - $file = fopen($dir . $targz, "w"); - - $mch = curl_multi_init(); - $c = curl_init(); - - curl_setopt($c, CURLOPT_URL, $url); - curl_setopt($c, CURLOPT_RETURNTRANSFER, true); - curl_setopt($c, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($c, CURLOPT_FILE, $file); - - curl_multi_add_handle($mch ,$c); - $running = null; - do { - curl_multi_exec($mch ,$running); - $info = curl_getinfo ($c); + if (empty($package_url)) { + $info_json = json_encode(array('correct' => 0)); - $data = array(); - $data['correct'] = 1; - $data['filename'] = $targz; - $data['size'] = $info['download_content_length']; - $data['size_download'] = $info['size_download']; - $data['speed_download'] = $info['speed_download']; + file_put_contents('/tmp/' . $package . '.info.txt', + $info_json, LOCK_EX); - $info_json = json_encode($data); - - file_put_contents('/tmp/' . $package . '.info.txt', $info_json, LOCK_EX); - - sleep(1); + $return = array('correct' => 0); } - while($running > 0); - - $return = array('correct' => 1); + else { + $targz = $package; + $url = $package_url; + + $file = fopen($dir . $targz, "w"); + + $mch = curl_multi_init(); + $c = curl_init(); + + curl_setopt($c, CURLOPT_URL, $url); + curl_setopt($c, CURLOPT_RETURNTRANSFER, true); + curl_setopt($c, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($c, CURLOPT_FILE, $file); + + curl_multi_add_handle($mch ,$c); + $running = null; + do { + curl_multi_exec($mch ,$running); + if ($running == 0) { + fclose($file); + } + + $info = curl_getinfo ($c); + html_debug_print($info, true); + + $data = array(); + $data['correct'] = 1; + $data['filename'] = $targz; + $data['size'] = $info['download_content_length']; + $data['size_download'] = $info['size_download']; + $data['speed_download'] = $info['speed_download']; + $data['total_time'] = $info['total_time']; + + $info_json = json_encode($data); + + file_put_contents('/tmp/' . $package . '.info.txt', + $info_json, LOCK_EX); + + sleep(1); + } + while($running > 0); + + $return = array('correct' => 1); + } + } + + if ($return['correct']) { + $conf_update_pandora['last_contact'] = time(); + update_pandora_update_conf(); } } + $return['mode'] = $conf_update_pandora['download_mode']; + $return['filename'] = $package; + echo json_encode($return); } function update_pandora_check_download_package() { global $config; + global $conf_update_pandora; + if (empty($conf_update_pandora)) + $conf_update_pandora = update_pandora_get_conf(); + require_once ($config["homedir"] . '/include/functions_graph.php'); sleep(1); - $package = get_parameter('package', ''); - $return = array('correct' => 1, - 'info_download' => "Size: %s/%s bytes Speed: %s bytes/second", - 'progres_bar' => progress_bar(0, 300, 20, '0%', 1, false, "#00ff00"), - 'progres_bar_text' => '0%', - 'percent' => 0); - - $info_json = @file_get_contents('/tmp/' . $package . '.info.txt'); - - $info = json_decode($info_json, true); - - if ($info['correct'] == 0) { - $return['correct'] = 0; - unlink('/tmp/' . $package . '.info.txt'); + if ($conf_update_pandora['download_mode'] == 'wget') { + $return = array('correct' => 1, + 'info_download' => __('In progress...') . html_print_image('images/spinner.gif', true), + 'mode' => 'wget'); } else { - $percent = 0; - $size_download = 0; - $size = 0; - $speed_download = 0; - if ($info['size_download'] > 0) { - $percent = format_numeric( - ($info['size_download'] / $info['size']) * 100, 2); - $return['percent'] = $percent; - $size_download = $info['size_download']; - $size = $info['size']; - $speed_download = $info['speed_download']; - - $return['info_download'] = sprintf($return['info_download'], - format_for_graph($size_download, 2), format_for_graph($size, 2), - format_for_graph($speed_download, 2)); + + $package = get_parameter('package', ''); + $return = array('correct' => 1, + 'info_download' => "" . __('Size') . ": %s/%s " . __('bytes') . " " . + "" . __('Speed') . ": %s " . __('bytes/second') ."
" . + "" . __('Time') . ": %s", + 'progres_bar' => progress_bar(0, 300, 20, '0%', 1, false, "#00ff00"), + 'progres_bar_text' => '0%', + 'percent' => 0, + 'mode' => 'curl'); + + $info_json = @file_get_contents('/tmp/' . $package . '.info.txt'); + + $info = json_decode($info_json, true); + + if ($info['correct'] == 0) { + $return['correct'] = 0; + unlink('/tmp/' . $package . '.info.txt'); } else { - $return['info_download'] = __('Starting: connect to server'); + $percent = 0; + $size_download = 0; + $size = 0; + $speed_download = 0; + $total_time = 0; + if ($info['size_download'] > 0) { + $percent = format_numeric( + ($info['size_download'] / $info['size']) * 100, 2); + $return['percent'] = $percent; + $size_download = $info['size_download']; + $size = $info['size']; + $speed_download = $info['speed_download']; + $total_time = $info['total_time']; + + $return['info_download'] = sprintf($return['info_download'], + format_for_graph($size_download, 2), format_for_graph($size, 2), + format_for_graph($speed_download, 2), + human_time_description_raw($total_time)); + } + else { + $return['info_download'] = __('Starting: connect to server'); + } + + $img = progress_bar($percent, 300, 20, $percent . '%', 1, false, "#00ff00"); + $return['progres_bar'] = $img; + preg_match_all('/src=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr); + $return['progres_bar_src'] = $attr[1]; + preg_match_all('/alt=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr); + $return['progres_bar_alt'] = $attr[1]; + preg_match_all('/title=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr); + $return['progres_bar_title'] = $attr[1]; + $return['filename'] = $info['filename']; } - - $img = progress_bar($percent, 300, 20, $percent . '%', 1, false, "#00ff00"); - $return['progres_bar'] = $img; - preg_match_all('/src=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr); - $return['progres_bar_src'] = $attr[1]; - preg_match_all('/alt=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr); - $return['progres_bar_alt'] = $attr[1]; - preg_match_all('/title=[\'\"]([^\"^\']*)[\'\"]/i', $img, $attr); - $return['progres_bar_title'] = $attr[1]; - $return['filename'] = $info['filename']; } echo json_encode($return); @@ -229,12 +294,16 @@ function update_pandora_install_package() { $package = get_parameter('package', ''); $filename = get_parameter('filename', ''); + unlink("/tmp/$package.info.txt"); + //Get total files - $command = 'tar tzvf ' . $dir . $filename . '| wc -l > /tmp/' . $package . '.info.txt'; + //The grep command is because the fucking tar don't apply + //strip-components in mode "t" + $command = 'tar tzvf ' . $dir . $filename . ' | grep -v "pandora_console/$" | wc -l > /tmp/' . $package . '.info.txt'; exec($command, $output, $status); html_debug_print($command, true); - $command = 'tar xzvf ' . $dir . $filename . ' -C ' . $config['homedir'] . ' 1>/tmp/' . $package . '.files.info.txt'; + $command = 'tar xzvf ' . $dir . $filename . ' --strip-components=1 -C ' . $config['homedir'] . ' 1>/tmp/' . $package . '.files.info.txt'; html_debug_print($command, true); //Maybe this line run for seconds or minutes @@ -263,7 +332,7 @@ function update_pandora_check_install_package() { $files = @file('/tmp/' . $package . '.files.info.txt'); if (empty($files)) $files = array(); - $total = (int)file_get_contents('/tmp/' . $package . '.info.txt'); + $total = (int)@file_get_contents('/tmp/' . $package . '.info.txt'); $return = array('correct' => 1, 'info' => "
1, 'text' => '', + 'enable_buttons' => false, 'details_text' => '', + 'version_package_text' => ''); + + $settings = um_db_load_settings(); + $user_key = get_user_key($settings); + + //Disabled output error messages + $package = @um_client_check_latest_update ($settings, $user_key); + //Get error message + $error_message = ''; + $error = error_get_last(); + if (!empty($error)) { + $error_message = $error['message']; + } + + if ($package === true) { + $return['text'] = ui_print_success_message( + array('message' => __('Your system is up-to-date'), + 'no_close' => true), '', true); + } + elseif ($package === false) { + $return['text'] = ui_print_error_message( + array('message' => __('Server authorization rejected'), + 'no_close' => true), '', true); + } + elseif ($package === 0) { + $return['text'] = ui_print_error_message( + array('message' => __('Server connection failed'), + 'no_close' => true), '', true) . '
' . + $error_message; + } + else { + if ($package->id == 'ERROR_NON_NUMERIC_FOUND') { + $return['text'] = ui_print_error_message( + array('message' => __('Server unknow error'), + 'no_close' => true), '', true); + } + else { + $return['enable_buttons'] = true; + $return['version_package_text'] = ''.__('Id').': ' . + $package->id . + ' '.__('Timestamp').': ' . + $package->timestamp; + + $return['text'] = ui_print_success_message( + array('message' => __('There\'s a new update for Pandora FMS'), + 'no_close' => true), '', true) . + $return['version_package_text']; + + $return['details_text'] = html_entity_decode($package->description); + } + } + + echo json_encode($return); +} ?> diff --git a/pandora_console/extensions/update_manager/lib/functions.php b/pandora_console/extensions/update_manager/lib/functions.php index 18fab9809c..5342a97517 100644 --- a/pandora_console/extensions/update_manager/lib/functions.php +++ b/pandora_console/extensions/update_manager/lib/functions.php @@ -37,6 +37,8 @@ function update_pandora_get_conf() { $conf['last_installed'] = $row['value']; $row = db_get_row('tconfig', 'token', 'update_pandora_conf_last_contact'); $conf['last_contact'] = $row['value']; + $row = db_get_row('tconfig', 'token', 'update_pandora_conf_download_mode'); + $conf['download_mode'] = $row['value']; $conf['dir'] = $config['attachment_store'] . '/update_pandora/'; @@ -52,7 +54,8 @@ function update_pandora_installation() { //The url of update manager. $conf_update_pandora = array('url' => 'http://192.168.70.213/pandora.tar.gz', 'last_installed' => '', - 'last_contact' => ''); + 'last_contact' => '', + 'download_mode' => 'curl'); $values = array('token' => 'update_pandora_conf_url', 'value' => $conf_update_pandora['url']); @@ -63,6 +66,9 @@ function update_pandora_installation() { $values = array('token' => 'update_pandora_conf_last_contact', 'value' => $conf_update_pandora['last_contact']); $return = db_process_sql_insert('tconfig', $values); + $values = array('token' => 'update_pandora_conf_download_mode', + 'value' => $conf_update_pandora['download_mode']); + $return = db_process_sql_insert('tconfig', $values); ui_print_result_message($return, __('Succesful store conf data in DB.'), __('Unsuccesful store conf data in DB.')); @@ -93,6 +99,9 @@ function update_pandora_update_conf() { $values = array('value' => $conf_update_pandora['last_contact']); $return = db_process_sql_update('tconfig', $values, array('token' => 'update_pandora_conf_last_contact')); + $values = array('value' => $conf_update_pandora['download_mode']); + $return = db_process_sql_update('tconfig', $values, + array('token' => 'update_pandora_conf_download_mode')); return $return; } @@ -113,16 +122,19 @@ function update_pandora_get_list_downloaded_packages($mode = 'operation') { $packages[] = $entry; } else { + $time_file = date($config["date_format"], + filemtime($conf_update_pandora['dir'] . $entry)); + if ($conf_update_pandora['last_installed'] == $entry) { $packages[] = array('name' => $entry, - 'current' => true); + 'current' => true, + 'time' => $time_file); } else { $packages[] = array('name' => $entry, - 'current' => false); + 'current' => false, + 'time' => $time_file); } - - } } } @@ -193,7 +205,9 @@ function update_pandora_print_javascript_admin() { ?> open($_FILES["fileloaded"]['tmp_name']) === TRUE) { + $zip->extractTo($tempDir); + $zip->close(); + } + else { + $error = ui_print_error_message(__('Update cannot be opened')); + } + + $package = um_package_info_from_paths ($tempDir); + if ($package === false) { + ui_print_error_message( + __('Error, the file package is empty or corrupted.')); + } + else { + $settings = um_db_load_settings (); + + if ($settings->current_update >= $package->id) { + ui_print_error_message( + __('Your system version is higher or equal than the loaded package')); + } + else { + $binary_paths = um_client_get_files ($tempDir."binary/"); + + foreach ($binary_paths as $key => $paths) { + foreach($paths as $index => $path) { + $tempDir_scaped = preg_replace('/\//', '\/', $tempDir."binary"); + $binary_paths[$key][$index] = preg_replace('/^'.$tempDir_scaped.'/', ' ', $path); + } + } + + $code_paths = um_client_get_files ($tempDir."code/"); + + foreach ($code_paths as $key => $paths) { + foreach($paths as $index => $path) { + $tempDir_scaped = preg_replace('/\//', '\/', $tempDir."code"); + $code_paths[$key][$index] = preg_replace('/^'.$tempDir_scaped.'/', ' ', $path); + } + } + + $sql_paths = um_client_get_files ($tempDir); + foreach ($sql_paths as $key => $paths) { + foreach ($paths as $index => $path) { + if ($path != $tempDir || ($key == 'info_package' && $path == $tempDir)) { + unset($sql_paths[$key]); + } + } + } + + $updates_binary = array(); + $updates_code = array(); + $updates_sql = array(); + + if (!empty($binary_paths)) { + $updates_binary = um_client_update_from_paths ($binary_paths, $tempDir, $package->id, 'binary'); + } + if (!empty($code_paths)) { + $updates_code = um_client_update_from_paths ($code_paths, $tempDir, $package->id, 'code'); + } + if (!empty($sql_paths)) { + $updates_sql = um_client_update_from_paths ($sql_paths, $tempDir, $package->id, 'sql'); + } + + um_delete_directory($tempDir); + + $updates= array_merge((array) $updates_binary, (array) $updates_code, (array) $updates_sql); + + $package->updates = $updates; + + $settings = um_db_load_settings (); + + if (um_client_upgrade_to_package($package, $settings, true)) { + ui_print_success_message( + __('Successfully upgraded')); + + //Refresh the settings object. + $settings = um_db_load_settings (); + } + else { + ui_print_error_message(__('Cannot be upgraded')); + } + } + } + } + } + else { + ui_print_error_message(__('File cannot be uploaded')); + } +} ?> diff --git a/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php b/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php index 5073a0bf92..225b9a18c4 100644 --- a/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php +++ b/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php @@ -634,6 +634,8 @@ function um_client_upgrade_to_package ($package, $settings, $force = true, $upda } function um_client_upgrade_to_latest ($user_key, $force = true) { + $success = false; + $settings = um_db_load_settings (); db_process_sql_begin(); do { @@ -655,6 +657,8 @@ function um_client_upgrade_to_latest ($user_key, $force = true) { /* Break on error, when there are no more packages on the server (server return true) or on auth failure (server return false) */ + + return $success; } function um_client_db_connect (&$settings = NULL) { diff --git a/pandora_console/extensions/update_manager/main.php b/pandora_console/extensions/update_manager/main.php index 7c5410147f..40c5307a53 100644 --- a/pandora_console/extensions/update_manager/main.php +++ b/pandora_console/extensions/update_manager/main.php @@ -12,240 +12,218 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// Load global vars -global $config; +return; -require_once("update_pandora.php"); - -check_login (); - -um_db_connect ('mysql', $config['dbhost'], $config['dbuser'], - $config['dbpass'], $config['dbname']); - -$settings = um_db_load_settings (); -$error = ''; - -$url = 'index.php?sec=extensions&sec2=extensions/update_manager'; - -$update_free = (bool)get_parameter('update_free', false); - -$buttons_active = array(); -if ($update_free) { - $buttons_active['updatemanager'] = false; - $buttons_active['updatefree'] = true; -} -else { - $buttons_active['updatemanager'] = true; - $buttons_active['updatefree'] = false; -} - -$buttons = array( - 'updatefree' => array('active' => $buttons_active['updatefree'], - 'text' => '' . - html_print_image("images/upd.png", true, array ("title" => __('Update free'))) .''), - 'updatemanager' => array('active' => $buttons_active['updatemanager'], - 'text' => '' . - html_print_image("images/package.png", true, array ("title" => __('Update manager'))) .'')); - - -ui_print_page_header (__('Update manager'), "images/extensions.png", - false, "", false, $buttons); - -if ($update_free) { - //Call to update pandora free. +function main_view() { + // Load global vars + global $config; - update_pandora_administration(); + require_once("update_pandora.php"); - //Don't call the code of update manager. - return; -} - - -if ($settings->customer_key == FREE_USER) { - echo '
'; - echo html_print_image("images/information.png", true) . ' '; - /* Translators: Do not translade Update Manager, it's the name of the program */ - echo __('The new Update Manager client is shipped with Pandora FMS It helps system administrators to update their Pandora FMS automatically, since the Update Manager does the task of getting new modules, new plugins and new features (even full migrations tools for future versions) automatically.'); - echo '

'; - echo __('Update Manager is one of the most advanced features of Pandora FMS Enterprise version, for more information visit http://pandorafms.com.'); - echo '

'; - echo __('Update Manager sends anonymous information about Pandora FMS usage (number of agents and modules running). To disable it, just delete extension or remove remote server address from Update Manager plugin setup.'); - echo '

'; -} - -$user_key = get_user_key ($settings); -$update_package = (bool) get_parameter_post ('update_package'); + check_login (); -if ($update_package) { - if ($config['enterprise_installed'] == 1) { - echo '

'.__('Updating').'...

'; - flush (); - $force = (bool) get_parameter_post ('force_update'); - - um_client_upgrade_to_latest ($user_key, $force); - /* TODO: Add a new in tnews */ + if (! check_acl ($config["id_user"], 0, "PM")) { + db_pandora_audit("ACL Violation", + "Trying to access event viewer"); + require ("general/noaccess.php"); + return; + } + um_db_connect ('mysql', $config['dbhost'], $config['dbuser'], + $config['dbpass'], $config['dbname']); + + $settings = um_db_load_settings (); + $user_key = get_user_key ($settings); + + $buttons = array( + 'admin' => array( + 'active' => false, + 'text' => '' . + html_print_image ("images/god7.png", + true, array ("title" => __('Update manager'))) .'')); + + ui_print_page_header (__('Update manager'), "images/extensions.png", + false, "", false, $buttons); + + if (enterprise_installed()) { + main_view_enterprise($settings, $user_key); } else { - echo '
' . __('This is an Enterprise feature. Visit %s for more information.', 'http://pandorafms.com') . '
'; + main_view_open($settings, $user_key); } } -if (isset($_FILES["fileloaded"]["error"]) && !$_FILES["fileloaded"]["error"]) { - $extension = substr($_FILES["fileloaded"]["name"], strlen($_FILES["fileloaded"]["name"])-4, 4); - if($extension != '.oum') { - $error = '
'.__('Incorrect file extension').'
'; - } - else { - $tempDir = sys_get_temp_dir()."/tmp_oum/"; - - $zip = new ZipArchive; - if ($zip->open($_FILES["fileloaded"]['tmp_name']) === TRUE) { - $zip->extractTo($tempDir); - $zip->close(); - } else { - $error = '
'.__('Update cannot be opened').'
'; - } - - $package = um_package_info_from_paths ($tempDir); - if ($package === false) { - $error = '
'.__('Error, the file package is empty or corrupted.').'
'; +function main_view_enterprise($settings, $user_key) { + global $config; + + $update_package = (bool) get_parameter_post ('update_package'); + + if ($update_package) { + if (enterprise_installed()) { + $force = (bool) get_parameter_post ('force_update'); + + $success = um_client_upgrade_to_latest ($user_key, $force); + /* TODO: Add a new in tnews */ + + ui_print_result_message($success, + __('Success update to the last package.'), + __('Error update to the last package.')); + + //Reload the update manager settings + + $settings = um_db_load_settings (); + $user_key = get_user_key ($settings); } else { - $settings = um_db_load_settings (); - - if($settings->current_update >= $package->id) { - $error = '
'.__('Your system version is higher or equal than the loaded package').'
'; - } - else { - $binary_paths = um_client_get_files ($tempDir."binary/"); - - foreach($binary_paths as $key => $paths) { - foreach($paths as $index => $path) { - $tempDir_scaped = preg_replace('/\//', '\/', $tempDir."binary"); - $binary_paths[$key][$index] = preg_replace('/^'.$tempDir_scaped.'/', ' ', $path); - } - } - - $code_paths = um_client_get_files ($tempDir."code/"); - - foreach($code_paths as $key => $paths) { - foreach($paths as $index => $path) { - $tempDir_scaped = preg_replace('/\//', '\/', $tempDir."code"); - $code_paths[$key][$index] = preg_replace('/^'.$tempDir_scaped.'/', ' ', $path); - } - } - - $sql_paths = um_client_get_files ($tempDir); - foreach($sql_paths as $key => $paths) { - foreach($paths as $index => $path) { - if($path != $tempDir || ($key == 'info_package' && $path == $tempDir)) { - unset($sql_paths[$key]); - } - } - } - - $updates_binary = array(); - $updates_code = array(); - $updates_sql = array(); - - if(!empty($binary_paths)) { - $updates_binary = um_client_update_from_paths ($binary_paths, $tempDir, $package->id, 'binary'); - } - if(!empty($code_paths)) { - $updates_code = um_client_update_from_paths ($code_paths, $tempDir, $package->id, 'code'); - } - if(!empty($sql_paths)) { - $updates_sql = um_client_update_from_paths ($sql_paths, $tempDir, $package->id, 'sql'); - } - - um_delete_directory($tempDir); - - $updates= array_merge((array) $updates_binary, (array) $updates_code, (array) $updates_sql); - - $package->updates = $updates; - - $settings = um_db_load_settings (); - - if(um_client_upgrade_to_package ($package, $settings, true)) { - echo '
'.__('Successfully upgraded').'.
'; - $settings = um_db_load_settings (); - } - else { - echo '
'.__('Cannot be upgraded').'
'; - } - } + ui_print_error_message(__('This is an Enterprise feature. Visit %s for more information.', 'http://pandorafms.com')); } } -} -else { - $error = '
'.__('File cannot be uploaded').'
'; -} - -db_clean_cache(); -$settings = um_db_load_settings (); -$user_key = get_user_key ($settings); - -$package = um_client_check_latest_update ($settings, $user_key); - -if (check_acl ($config['id_user'], 0, 'PM')) { - if ($package === true) { - echo '
'.__('Your system is up-to-date').'.
'; - } - elseif ($package === false) { - echo '
'.__('Server authorization rejected').'
'; - } - elseif ($package === 0) { - echo '
'.__('Server connection failed').'
'; - } - else { - echo '
'.__('There\'s a new update for Pandora FMS').'
'; - - $table->width = '98%'; - $table->data = array (); - - $table->data[0][0] = ''.__('Id').''; - $table->data[0][1] = $package->id; - $table->data[1][0] = ''.__('Timestamp').''; - $table->data[1][1] = $package->timestamp; - - $table->data[2][0] = ''.__('Description').''; - $table->data[2][1] = html_entity_decode ($package->description); - - html_print_table ($table); - echo '
'; - echo '
'; - echo __('Overwrite local changes'); - html_print_checkbox ('force_update', '1', false); - echo '

'; - html_print_input_hidden ('update_package', 1); - html_print_submit_button (__('Update'), 'update_button', false, 'class="sub upd"'); - echo '

'; - echo '
'; + if (!empty($_FILES)) { + install_offline_enterprise_package($settings, $user_key); } - if($error != '' && isset($_FILES["fileloaded"]["error"])) { - echo $error; - } - unset($table); + $table = null; $table->width = '98%'; - $table->data = array (); - $table->colspan[0][0] = 2; - - $table->data[0][0] = '

'.__('Offline packages loader').'

'; - $table->data[1][0] = ''; - $table->data[1][0] .= ''; - $table->data[1][1] = ''; + $table->style = array(); + $table->style[0] = 'font-weight: bolder; font-size: 20px;'; + $table->data = array(); + $table->data[0][0] = __('Your Pandora FMS Enterprise version number is') + . ' ' . $settings->current_update; + html_print_table($table); + + + + /* Translators: Do not translade Update Manager, it's the name of the program */ + ui_print_info_message( + '

' . + __('The new Update Manager client is shipped with Pandora FMS It helps system administrators to update their Pandora FMS automatically, since the Update Manager does the task of getting new modules, new plugins and new features (even full migrations tools for future versions) automatically.') . + '

' . + '

' . + __('Update Manager is one of the most advanced features of Pandora FMS Enterprise version, for more information visit http://pandorafms.com.') . + '

' . + '

' . + __('Update Manager sends anonymous information about Pandora FMS usage (number of agents and modules running). To disable it, just delete extension or remove remote server address from Update Manager plugin setup.') . + '

'); + + + echo '

' . __('Online') . '

'; + $table = null; + $table->width = '98%'; + $table->size = array(); + $table->size[0] = '60%'; + $table->size[1] = '15%'; + $table->size[2] = '25%'; + $table->colspan = array(); + $table->colspan[0][0] = 3; + $table->data = array(); + $table->data[1][0] = '' . + __('Checking for a update') . ' ' . html_print_image('images/spinner.gif', true) . + ''; + $table->data[1][1] = html_print_button(__('Details'), + 'details_online', true, 'show_details();', 'class="sub search"', true); + $table->data[1][2] = __('Force') . ': ' . + html_print_checkbox ('force_update', '1', false, true) . + html_print_submit_button(__('Update'), 'update_online', true, + 'class="sub upd"', true); + + echo '
'; + html_print_input_hidden ('update_package', 1); + html_print_table($table); + echo '
'; + + + + ?> + + ' . __('Offline') . ''; + $table = null; + $table->width = '98%'; + $table->data = array(); + $table->data[1][0] = '
'.__('Offline packages loader').'
' . + '' . + '' . + ' '; echo '
'; html_print_table($table); echo '
'; + + ?> + + '.__('Your system version number is').': '.$settings->current_update.''; - +function main_view_open($settings, $user_key) { + global $config; + + update_pandora_administration($settings, $user_key); +} ?> diff --git a/pandora_console/extensions/update_manager/settings.php b/pandora_console/extensions/update_manager/settings.php index 1ad4428a6a..988f5912ae 100644 --- a/pandora_console/extensions/update_manager/settings.php +++ b/pandora_console/extensions/update_manager/settings.php @@ -22,17 +22,39 @@ if (! check_acl ($config['id_user'], 0, 'PM')) { return; } +include ("extensions/update_manager/lib/functions.php"); + um_db_connect ('mysql', $config['dbhost'], $config['dbuser'], $config['dbpass'], $config['dbname']); $update_settings = (bool) get_parameter_post ('update_settings'); -ui_print_page_header (__('Update manager').' - '. __('Settings'), "images/extensions.png", false, "", true, "" ); +$buttons = array( + 'admin' => array( + 'active' => false, + 'text' => '' . + html_print_image ("images/eye.png", + true, array ("title" => __('Update manager'))) .'')); + +ui_print_page_header (__('Update manager').' - '. __('Settings'), + "images/extensions.png", false, "", true, $buttons); if ($update_settings) { foreach ($_POST['keys'] as $key => $value) { um_db_update_setting ($key, $value); } + + if (!enterprise_installed()) { + global $conf_update_pandora; + if (empty($conf_update_pandora)) + $conf_update_pandora = update_pandora_get_conf(); + + $conf_update_pandora['download_mode'] = + get_parameter('download_mode', 'curl'); + + update_pandora_update_conf(); + } + echo "

".__('Update manager settings updated')."

"; } @@ -49,9 +71,8 @@ $table->data[0][1] = html_print_input_text ('keys[customer_key]', $settings->cus $table->data[1][0] = ''.__('Update server host').''; $table->data[1][1] = html_print_input_text ('keys[update_server_host]', $settings->update_server_host, '', 20, 255, true); -$table->data[2][0] = ''.__('Update server path').'' - . ui_print_help_tip (__('The server path is automatically updated with each Pandora Console version.'), true); -$table->data[2][1] = html_print_input_text ('keys[update_server_path]', $settings->update_server_path, '', 40, 255, true, true); +$table->data[2][0] = ''.__('Update server path').''; +$table->data[2][1] = html_print_input_text ('keys[update_server_path]', $settings->update_server_path, '', 40, 255, true); $table->data[3][0] = ''.__('Update server port').''; $table->data[3][1] = html_print_input_text ('keys[update_server_port]', $settings->update_server_port, '', 5, 5, true); @@ -74,6 +95,21 @@ $table->data[8][1] = html_print_input_text ('keys[proxy_user]', $settings->proxy $table->data[9][0] = ''.__('Proxy password').''; $table->data[9][1] = html_print_input_password ('keys[proxy_pass]', $settings->proxy_pass, '', 40, 255, true); +if (!enterprise_installed()) { + global $conf_update_pandora; + if (empty($conf_update_pandora)) + $conf_update_pandora = update_pandora_get_conf(); + + $methods = array( + 'wget' => __('WGET, no interactive, external command, fast'), + 'curl' =>__('CURL, interactive, internal command, slow')); + + $table->data[10][0] = '' . __('Download Method') . ''; + $table->data[10][1] = html_print_select($methods, + 'download_mode', $conf_update_pandora['download_mode'], '', '', + 0, true); +} + html_print_table ($table); echo '
'; html_print_input_hidden ('update_settings', 1); @@ -82,9 +118,3 @@ echo '
'; echo ''; ?> - diff --git a/pandora_console/extensions/update_manager/update_pandora.php b/pandora_console/extensions/update_manager/update_pandora.php index e4a6e3c584..1fb24fb71f 100644 --- a/pandora_console/extensions/update_manager/update_pandora.php +++ b/pandora_console/extensions/update_manager/update_pandora.php @@ -50,7 +50,7 @@ if (is_ajax ()) { return; } -function update_pandora_administration() { +function update_pandora_administration($settings, $user_key) { global $config; global $conf_update_pandora; @@ -68,62 +68,62 @@ function update_pandora_administration() { update_pandora_installation(); } + $delete_package = (bool)get_parameter('delete_package'); + if ($delete_package) { + $package = get_parameter('package'); + + $dir = $config['attachment_store'] . '/update_pandora/'; + + $result = unlink($dir . $package); + } + $conf_update_pandora = update_pandora_get_conf(); - echo "

" . __('Downloaded Packages') . "

"; - $list_downloaded_packages = update_pandora_get_list_downloaded_packages('administration'); $table = null; - $table->width = '80%'; - $table->size = array('80%', '50px'); - $table->head = array(__('Packages'), __('Action')); - $table->align = array('left', 'center'); + $table->width = '98%'; + $table->style = array(); + $table->style[0] = 'font-weight: bolder; font-size: 20px;'; $table->data = array(); - foreach ($list_downloaded_packages as $package) { - $actions = ''; - if (!isset($package['empty'])) { - if (!$package['current']) { - $actions = '' . - html_print_image('images/b_white.png', true, array('alt'=> - __('Install this version'), 'title' => __('Install this version'))) . - ''; - } - else { - $actions = '' . - html_print_image('images/b_yellow.png', true, array('alt'=> - __('Reinstall this version'), 'title' => __('Reinstall this version'))) . - ''; - } - } - $table->data[] = array($package['name'], $actions); - } + $table->data[0][0] = __('Your Pandora FMS open source package installed is') . + ' ' . $conf_update_pandora['last_installed']; html_print_table($table); - echo "

" . __('Online Package') . "

"; - echo ''; - echo ' - - - '; - echo ' - - - - - '; - echo '
' . __('Package') . '' . __('Action') . '
' . - __('Get list online Package') . " " . html_print_image('images/spinner.gif', true) . - '
'; + ui_print_info_message( + '

' . + __('This is a automatilly update Pandora Console only. Be careful if you have changed any php file of console, please make a backup this modified files php. Because the update action ovewrite all php files in Pandora console.') . + '

' . + '

' . + __('Update Manager sends anonymous information about Pandora FMS usage (number of agents and modules running). To disable it, just delete extension or remove remote server address from Update Manager plugin setup.') . + '

' + ); + $table = null; + $table->width = '98%'; + $table->data = array(); + $table->data[0][0] = '

' . __('Online') . '

'; + $table->data[1][0] = + '' . + ' + + + + + ' . + '
' . + __('Get list online Package') . " " . html_print_image('images/spinner.gif', true) . + '
'; + html_print_table($table); ?>