From b31da21e9ebfb1f1c78ad4e8d8418d23db43a817 Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Sun, 23 Aug 2009 19:51:27 -0400 Subject: Move download_file_with_progress bar back to shared are where it belongs. These functions can be called from both console and the webConfigurator. Unbreaks pkg operations on bootup such as resinstall broken packages --- usr/local/www/guiconfig.inc | 65 +-------------------------------------------- 1 file changed, 1 insertion(+), 64 deletions(-) (limited to 'usr') diff --git a/usr/local/www/guiconfig.inc b/usr/local/www/guiconfig.inc index 5aed15a..1459a40 100755 --- a/usr/local/www/guiconfig.inc +++ b/usr/local/www/guiconfig.inc @@ -954,41 +954,6 @@ function update_progress_bar($percent) { } } -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; - $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 rule_popup($src,$srcport,$dst,$dstport){ global $config; $aliases_array = array(); @@ -1051,32 +1016,4 @@ function rule_popup($src,$srcport,$dst,$dstport){ } } -function download_file_with_progress_bar($url_file, $destination_file, $readbody = 'read_body') { - global $ch, $fout, $file_size, $downloaded; - $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, $readbody); - curl_setopt($ch, CURLOPT_NOPROGRESS, '1'); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, '5'); - curl_setopt($ch, CURLOPT_TIMEOUT, 0); - - 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; -} - -?> +?> \ No newline at end of file -- cgit v1.1