diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 11a34b5004..37acc9c347 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2011-08-31 Miguel de Dios + + * extensions/update_manager/lib/libupdate_manager_client.php, + extensions/update_manager/main.php: fixed when the file is corrupted or + empty. + + Fixes: #3400237 + 2011-08-31 Miguel de Dios * include/functions.php: fixed in function "string2image" when generate a 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 986a76eb88..9d66bd3e46 100644 --- a/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php +++ b/pandora_console/extensions/update_manager/lib/libupdate_manager_client.php @@ -373,14 +373,20 @@ function um_client_print_update ($update, $settings) { } function um_package_info_from_paths ($tmpDir) { - $f = fopen($tmpDir.'info_package', "r"); - $f_content = fread($f, filesize($tmpDir.'info_package')); - fclose($f); - $f_array = array(); + $f = @fopen($tmpDir.'info_package', "r"); - unset($f_content->status); + if ($f !== false) { + $f_content = fread($f, filesize($tmpDir.'info_package')); + fclose($f); + $f_array = array(); - return json_decode($f_content); + unset($f_content->status); + + return json_decode($f_content); + } + else { + return false; + } } function um_client_update_from_paths ($file_paths, $tmpDir, $num_package, $type) { diff --git a/pandora_console/extensions/update_manager/main.php b/pandora_console/extensions/update_manager/main.php index 088d8387d2..041e682c72 100644 --- a/pandora_console/extensions/update_manager/main.php +++ b/pandora_console/extensions/update_manager/main.php @@ -71,68 +71,72 @@ if (isset($_FILES["fileloaded"]["error"]) && !$_FILES["fileloaded"]["error"]) { } $package = um_package_info_from_paths ($tempDir); - - $settings = um_db_load_settings (); - - if($settings->current_update >= $package->id) { - $error = '
'.__('Your system version is higher or equal than the loaded package').'
'; + if ($package === false) { + $error = '
'.__('Error, the file package is empty or corrupted.').'
'; } - 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; - + else { $settings = um_db_load_settings (); - - if(um_client_upgrade_to_package ($package, $settings, true)) { - echo '
'.__('Successfully upgraded').'.
'; - $settings = um_db_load_settings (); + + if($settings->current_update >= $package->id) { + $error = '
'.__('Your system version is higher or equal than the loaded package').'
'; } else { - echo '
'.__('Cannot be upgraded').'
'; + $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').'
'; + } } } }