summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorColin Smith <colin@pfsense.org>2005-05-30 03:21:01 +0000
committerColin Smith <colin@pfsense.org>2005-05-30 03:21:01 +0000
commit6db88af64703b462ae1d6c2e6872e6b4ae425cbe (patch)
treec230362b3440c7ee172a7dfe25b30b3160cc5124 /etc
parent3a6cd22a65855c22876c2e4168ca7a3f8e725a4b (diff)
downloadpfsense-6db88af64703b462ae1d6c2e6872e6b4ae425cbe.zip
pfsense-6db88af64703b462ae1d6c2e6872e6b4ae425cbe.tar.gz
Add cURL functions. These may be moved to pkg-utils.inc soonish.
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/pfsense-utils.inc61
1 files changed, 61 insertions, 0 deletions
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc
index 65ade10..31a9c59 100644
--- a/etc/inc/pfsense-utils.inc
+++ b/etc/inc/pfsense-utils.inc
@@ -1172,4 +1172,65 @@ 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, $counter;
+ $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);
+ fclose($fout);
+ curl_close($ch);
+
+ return 1;
+}
+
+function read_header($ch, $string) {
+ global $file_size, $ch, $fout;
+ $length = strlen($string);
+ ereg("(Content-Length:) (.*)", $string, $regs);
+ if($regs[2] <> "") {
+ $file_size = intval($regs[2]);
+ }
+ return $length;
+}
+
+function read_body($ch, $string) {
+ global $fout, $file_size, $downloaded, $counter, $sendto, $static_output, $lastseen;
+ $length = strlen($string);
+ $downloaded += intval($length);
+ $downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
+ $downloadProgress = 100 - $downloadProgress;
+ /*
+ lastseen is used to prevent from spamming firefox with hundreds of
+ unnecessary javascript update messages which sends the clients
+ firefox utilization to 100%
+ */
+ 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;
+ }
+ fwrite($fout, $string);
+ return $length;
+}
+
?>
OpenPOWER on IntegriCloud