summaryrefslogtreecommitdiffstats
path: root/usr
diff options
context:
space:
mode:
authorColin Smith <colin@pfsense.org>2005-04-11 15:50:25 +0000
committerColin Smith <colin@pfsense.org>2005-04-11 15:50:25 +0000
commit131bb57602c94b6017a0662def73cdfeb6f9eae9 (patch)
tree70aa765fa0888668d1ca20b85ccb36c66b14abd7 /usr
parentcc4d4ebda20584ce72be6f9c4c2316935df6878c (diff)
downloadpfsense-131bb57602c94b6017a0662def73cdfeb6f9eae9.zip
pfsense-131bb57602c94b6017a0662def73cdfeb6f9eae9.tar.gz
Move download/progress bar functions to guiconfig.inc - they'll be used in the package installer shortly.
Diffstat (limited to 'usr')
-rwxr-xr-xusr/local/www/guiconfig.inc64
-rwxr-xr-xusr/local/www/system_firmware_auto.php164
2 files changed, 109 insertions, 119 deletions
diff --git a/usr/local/www/guiconfig.inc b/usr/local/www/guiconfig.inc
index 07a1e28..ec01164 100755
--- a/usr/local/www/guiconfig.inc
+++ b/usr/local/www/guiconfig.inc
@@ -500,4 +500,68 @@ function update_if_changed($varname, & $orig, $new) {
return false;
}
+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);
+ return 1;
+
+ if ($error = curl_error($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;
+ $length = strlen($string);
+ $downloaded += intval($length);
+ $downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
+ $downloadProgress = 100 - $downloadProgress;
+ /*
+ $a = $file_size;
+ $b = $downloaded;
+ $c = $downloadProgress;
+ $text = " Download Status\\n";
+ $text .= "---------------------------------\\n";
+ $text .= " File size : {$a}\\n";
+ $text .= " Downloaded : {$b}\\n";
+ $text .= " Percent : {$c}%\\n";
+ $text .= "---------------------------------\\n";
+ */
+ $counter++;
+ if($counter > 150) {
+ $tostatus = $static_status . $downloadProgress;
+ update_status($tostatus);
+ update_progress_bar($downloadProgress);
+ $counter = 0;
+ }
+ fwrite($fout, $string);
+ return $length;
+}
?>
diff --git a/usr/local/www/system_firmware_auto.php b/usr/local/www/system_firmware_auto.php
index 0ade5b3..3c5fb4d 100755
--- a/usr/local/www/system_firmware_auto.php
+++ b/usr/local/www/system_firmware_auto.php
@@ -148,59 +148,59 @@ if($use_old_checkversion == true) {
}
if($use_old_checkversion == false) {
-if($versions != -1) {
- if($versions[0] == true) {
- if($versions[1] != $firmware_version) $needs_firmware_upgrade = true;
- if($versions[2] != $kernel_version) $needs_kernel_upgrade = true;
- if($versions[3] != $base_version) $needs_base_version = true;
- if(isset($versions[4])) $static_text = $versions[4] . '\n'; // If we have additional data (a CHANGELOG etc) to display, do so.
- update_output_window($static_text);
+ if($versions != -1) {
+ if($versions[0] == true) {
+ if($versions[1] != $firmware_version) $needs_firmware_upgrade = true;
+ if($versions[2] != $kernel_version) $needs_kernel_upgrade = true;
+ if($versions[3] != $base_version) $needs_base_version = true;
+ if(isset($versions[4])) $static_text = $versions[4] . '\n'; // If we have additional data (a CHANGELOG etc) to display, do so.
+ update_output_window($static_text);
+ } else {
+ update_status("No updates required.");
+ }
} else {
- update_status("No updates required.");
+ update_status("Could not retrieve version information.");
+ exit();
}
-} else {
- update_status("Could not retrieve version information.");
- exit();
-}
-if($needs_firmware_upgrade == true) {
- $static_status = "Downloading firmware update... ";
- update_status($static_status);
- $status = download_file_with_progress_bar("http://www.pfSense.com/latest.tgz", "/tmp/latest.tgz");
- $static_status .= "done. ";
-}
+ if($needs_firmware_upgrade == true) {
+ $static_status = "Downloading firmware update... ";
+ update_status($static_status);
+ $status = download_file_with_progress_bar("http://www.pfSense.com/latest.tgz", "/tmp/latest.tgz");
+ $static_status .= "done. ";
+ }
-if($needs_kernel_upgrade == true) {
- $static_status .= "Downloading kernel update... ";
- update_status($static_status);
- $status = download_file_with_progress_bar("http://www.pfSense.com/latest_kernel{$platform}.tgz", "/tmp/latest_kernel.tgz");
- $static_status .= "done. ";
-}
+ if($needs_kernel_upgrade == true) {
+ $static_status .= "Downloading kernel update... ";
+ update_status($static_status);
+ $status = download_file_with_progress_bar("http://www.pfSense.com/latest_kernel{$platform}.tgz", "/tmp/latest_kernel.tgz");
+ $static_status .= "done. ";
+ }
-if($needs_base_upgrade == true) {
- $static_status .= "Downloading base update... ";
- update_status($static_status);
- $status = download_file_with_progress_bar("http://www.pfSense.com/latest_base.tgz", "/tmp/latest_base.tgz");
- $static_status .= "done. ";
- update_status($static_status);
-}
+ if($needs_base_upgrade == true) {
+ $static_status .= "Downloading base update... ";
+ update_status($static_status);
+ $status = download_file_with_progress_bar("http://www.pfSense.com/latest_base.tgz", "/tmp/latest_base.tgz");
+ $static_status .= "done. ";
+ update_status($static_status);
+ }
-/* launch external upgrade helper */
-$external_upgrade_helper_text = "";
-if($needs_system_upgrade == true) {
- // XXX: check md5 of downloaded file.
- exec_rc_script_async("/etc/rc.firmware pfSense");
-}
+ /* launch external upgrade helper */
+ $external_upgrade_helper_text = "";
+ if($needs_system_upgrade == true) {
+ // XXX: check md5 of downloaded file.
+ exec_rc_script_async("/etc/rc.firmware pfSense");
+ }
-if($needs_kernel_upgrade == true) {
- // XXX: check md5 of downloaded file.
- exec_rc_script_async("/etc/rc.firmware pfSense_kernel");
-}
+ if($needs_kernel_upgrade == true) {
+ // XXX: check md5 of downloaded file.
+ exec_rc_script_async("/etc/rc.firmware pfSense_kernel");
+ }
-if($needs_base_upgrade == true) {
- // XXX: check md5 of downloaded file.
- exec_rc_script_async("/etc/rc.firmware pfSense_base");
-}
+ if($needs_base_upgrade == true) {
+ // XXX: check md5 of downloaded file.
+ exec_rc_script_async("/etc/rc.firmware pfSense_base");
+ }
} else {
if($versions != "") {
update_output_window("Using old checkversion method. Text returned from pfSense.com:\n\n" . $versions . "\n\nUpgrading...");
@@ -233,78 +233,4 @@ if($needs_base_upgrade == true) {
update_status("pfSense is now upgrading. The firewall will reboot once the operation has completed.");
echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
-
-/* end of upgrade script */
-
-
-
-/*
- Helper functions
-*/
-
-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);
- return 1;
-
- if ($error = curl_error($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;
- $length = strlen($string);
- $downloaded += intval($length);
- $downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
- $downloadProgress = 100 - $downloadProgress;
- /*
- $a = $file_size;
- $b = $downloaded;
- $c = $downloadProgress;
- $text = " Download Status\\n";
- $text .= "---------------------------------\\n";
- $text .= " File size : {$a}\\n";
- $text .= " Downloaded : {$b}\\n";
- $text .= " Percent : {$c}%\\n";
- $text .= "---------------------------------\\n";
- */
- $counter++;
- if($counter > 150) {
- $tostatus = $static_status . $downloadProgress;
- update_status($tostatus);
- update_progress_bar($downloadProgress);
- $counter = 0;
- }
- fwrite($fout, $string);
- return $length;
-}
-
?>
OpenPOWER on IntegriCloud