From 9140757d593279628f6e102cbd896fe7a708d494 Mon Sep 17 00:00:00 2001 From: Bill Marquette Date: Thu, 24 Jul 2008 03:53:11 +0000 Subject: DRY up the code a tad, download_file_with_progress_bar isn't related to packages only anymore, move into pfsense-utils and allow for multiple file write functions (firmware upgrades use a different one than our standard) --- etc/inc/pkg-utils.inc | 61 --------------------------------------------------- 1 file changed, 61 deletions(-) (limited to 'etc/inc/pkg-utils.inc') diff --git a/etc/inc/pkg-utils.inc b/etc/inc/pkg-utils.inc index d62313a..c45a0a9 100644 --- a/etc/inc/pkg-utils.inc +++ b/etc/inc/pkg-utils.inc @@ -372,67 +372,6 @@ function pkg_fetch_recursive($pkgname, $filename, $dependlevel = 0, $base_url = return true; } -function download_file_with_progress_bar($url_file, $destination_file) { - global $ch, $fout, $file_size, $downloaded, $pkg_interface; - $file_size = 1; - $downloaded = 1; - /* open destination file */ - $fout = fopen($destination_file, "wb"); - - /* - * Originally by Author: Keyvan Minoukadeh - * Modified by Scott Ullrich to return Content-Length size - */ - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url_file); - curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header'); - curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body'); - curl_setopt($ch, CURLOPT_NOPROGRESS, '1'); - - curl_exec($ch); - $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); - if($fout) - fclose($fout); - curl_close($ch); - return ($http_code == 200) ? true : $http_code; -} - -function read_header($ch, $string) { - global $file_size, $fout; - $length = strlen($string); - $regs = ""; - ereg("(Content-Length:) (.*)", $string, $regs); - if($regs[2] <> "") { - $file_size = intval($regs[2]); - } - ob_flush(); - return $length; -} - -function read_body($ch, $string) { - global $fout, $file_size, $downloaded, $sendto, $static_status, $static_output, $lastseen, $pkg_interface; - $length = strlen($string); - $downloaded += intval($length); - $downloadProgress = round(100 * (1 - $downloaded / $file_size), 0); - $downloadProgress = 100 - $downloadProgress; - if($lastseen <> $downloadProgress and $downloadProgress < 101) { - if($sendto == "status") { - $tostatus = $static_status . $downloadProgress . "%"; - update_status($tostatus); - } else { - $tooutput = $static_output . $downloadProgress . "%"; - update_output_window($tooutput); - } - update_progress_bar($downloadProgress); - $lastseen = $downloadProgress; - } - if($fout) - fwrite($fout, $string); - ob_flush(); - return $length; -} - function install_package($package, $pkg_info = "") { global $g, $config, $pkg_interface, $fd_log, $static_output, $pkg_interface, $restart_sync; if($pkg_interface == "console") -- cgit v1.1