1 |
25682561
|
Scott Ullrich
|
#!/usr/local/bin/php
|
2 |
|
|
<?php
|
3 |
|
|
/* $Id$ */
|
4 |
|
|
/*
|
5 |
|
|
system_firmware_auto.php
|
6 |
853167d2
|
Colin Smith
|
part of pfSense (http://www.pfsense.com)
|
7 |
5c59c339
|
Scott Ullrich
|
|
8 |
1c0e3b99
|
Scott Ullrich
|
Copyright (C) 2005 Scott Ullrich
|
9 |
5c59c339
|
Scott Ullrich
|
|
10 |
853167d2
|
Colin Smith
|
Based originally on system_firmware.php
|
11 |
1c0e3b99
|
Scott Ullrich
|
(C)2003-2004 Manuel Kasper
|
12 |
5c59c339
|
Scott Ullrich
|
|
13 |
25682561
|
Scott Ullrich
|
All rights reserved.
|
14 |
|
|
|
15 |
|
|
Redistribution and use in source and binary forms, with or without
|
16 |
|
|
modification, are permitted provided that the following conditions are met:
|
17 |
|
|
|
18 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
19 |
|
|
this list of conditions and the following disclaimer.
|
20 |
|
|
|
21 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
22 |
|
|
notice, this list of conditions and the following disclaimer in the
|
23 |
|
|
documentation and/or other materials provided with the distribution.
|
24 |
|
|
|
25 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
26 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
27 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
28 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
29 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
30 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
31 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
32 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
33 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
34 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
35 |
|
|
*/
|
36 |
|
|
|
37 |
|
|
require("guiconfig.inc");
|
38 |
|
|
|
39 |
|
|
?>
|
40 |
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
41 |
|
|
<html>
|
42 |
|
|
<head>
|
43 |
|
|
<title><?=gentitle("System: Firmware: Invoke Auto Upgrade");?></title>
|
44 |
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
45 |
|
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
46 |
|
|
</head>
|
47 |
|
|
|
48 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
49 |
|
|
|
50 |
|
|
<?php include("fbegin.inc"); ?>
|
51 |
|
|
<p class="pgtitle">System: Firmware: Invoke Auto Upgrade</p>
|
52 |
|
|
|
53 |
|
|
<form action="system_firmware_auto.php" method="post">
|
54 |
1c0e3b99
|
Scott Ullrich
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
55 |
25682561
|
Scott Ullrich
|
<tr>
|
56 |
|
|
<td class="tabcont">
|
57 |
|
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
58 |
1c0e3b99
|
Scott Ullrich
|
<tr>
|
59 |
|
|
<td>
|
60 |
|
|
<!-- progress bar -->
|
61 |
|
|
<center>
|
62 |
|
|
<table id="progholder" name="progholder" height='20' border='1' bordercolor='black' width='420' bordercolordark='#000000' bordercolorlight='#000000' style='border-collapse: collapse' colspacing='2' cellpadding='2' cellspacing='2'><tr><td><img border='0' src='progress_bar.gif' width='280' height='23' name='progressbar' id='progressbar'></td></tr></table>
|
63 |
|
|
<br>
|
64 |
|
|
<!-- status box -->
|
65 |
3db58e13
|
Scott Ullrich
|
<textarea border='1' bordercolordark='#000000' bordercolorlight='#000000' style='background-color: #EEEEEE; border-collapse: collapse' cols="60" rows="1" name="status" id="status" wrap="hard">
|
66 |
853167d2
|
Colin Smith
|
Beginning system autoupdate...
|
67 |
3db58e13
|
Scott Ullrich
|
</textarea>
|
68 |
1c0e3b99
|
Scott Ullrich
|
<!-- command output box -->
|
69 |
3db58e13
|
Scott Ullrich
|
<textarea border='1' bordercolordark='#000000' bordercolorlight='#000000' style='background-color: #EEEEEE; border-collapse: collapse' cols="60" rows="25" name="output" id="output" wrap="hard">
|
70 |
|
|
</textarea>
|
71 |
1c0e3b99
|
Scott Ullrich
|
</center>
|
72 |
|
|
</td>
|
73 |
|
|
</tr>
|
74 |
25682561
|
Scott Ullrich
|
</table>
|
75 |
|
|
</td>
|
76 |
|
|
</tr>
|
77 |
1c0e3b99
|
Scott Ullrich
|
</table>
|
78 |
25682561
|
Scott Ullrich
|
</form>
|
79 |
|
|
<?php include("fend.inc"); ?>
|
80 |
|
|
</body>
|
81 |
|
|
</html>
|
82 |
|
|
|
83 |
|
|
<?php
|
84 |
|
|
|
85 |
5c59c339
|
Scott Ullrich
|
/* Define necessary variables. */
|
86 |
853167d2
|
Colin Smith
|
$platform = trim(file_get_contents('/etc/platform'));
|
87 |
|
|
$firmware_version = trim(file_get_contents('/etc/version'));
|
88 |
|
|
$kernel_version = trim(file_get_contents('/etc/version_kernel'));
|
89 |
|
|
$base_version = trim(file_get_contents('/etc/version_base'));
|
90 |
cdb0117c
|
Scott Ullrich
|
|
91 |
25682561
|
Scott Ullrich
|
update_status("Downloading current version information...");
|
92 |
853167d2
|
Colin Smith
|
$versions = check_firmware_version();
|
93 |
cdb0117c
|
Scott Ullrich
|
|
94 |
0b26b9ea
|
Colin Smith
|
if($versions != -1) {
|
95 |
4315832e
|
Colin Smith
|
if($versions[0] == true) {
|
96 |
|
|
if($versions[1] != $firmware_version) $needs_firmware_upgrade = true;
|
97 |
|
|
if($versions[2] != $kernel_version) $needs_kernel_upgrade = true;
|
98 |
|
|
if($versions[3] != $base_version) $needs_base_version = true;
|
99 |
1b934970
|
Colin Smith
|
if(isset($versions[4])) $static_text = $versions[4] . '\n'; // If we have additional data (a CHANGELOG etc) to display, do so.
|
100 |
|
|
update_output_window($static_text);
|
101 |
4315832e
|
Colin Smith
|
} else {
|
102 |
|
|
update_status("No updates required.");
|
103 |
|
|
}
|
104 |
0b26b9ea
|
Colin Smith
|
} else {
|
105 |
|
|
update_status("Could not retrieve version information.");
|
106 |
|
|
exit();
|
107 |
|
|
}
|
108 |
25682561
|
Scott Ullrich
|
|
109 |
853167d2
|
Colin Smith
|
if($needs_firmware_upgrade == true) {
|
110 |
1b934970
|
Colin Smith
|
$static_status = "Downloading firmware update... ";
|
111 |
|
|
update_status($static_status);
|
112 |
25682561
|
Scott Ullrich
|
$status = download_file_with_progress_bar("http://www.pfSense.com/latest.tgz", "/tmp/latest.tgz");
|
113 |
1b934970
|
Colin Smith
|
$static_status .= "done. ";
|
114 |
25682561
|
Scott Ullrich
|
}
|
115 |
|
|
|
116 |
853167d2
|
Colin Smith
|
if($needs_kernel_upgrade == true) {
|
117 |
1b934970
|
Colin Smith
|
$static_status .= "Downloading kernel update... ";
|
118 |
|
|
update_status($static_status);
|
119 |
853167d2
|
Colin Smith
|
$status = download_file_with_progress_bar("http://www.pfSense.com/latest_kernel{$platform}.tgz", "/tmp/latest_kernel.tgz");
|
120 |
1b934970
|
Colin Smith
|
$static_status .= "done. ";
|
121 |
|
|
}
|
122 |
853167d2
|
Colin Smith
|
|
123 |
25682561
|
Scott Ullrich
|
if($needs_base_upgrade == true) {
|
124 |
1b934970
|
Colin Smith
|
$static_status .= "Downloading base update... ";
|
125 |
|
|
update_status($static_status);
|
126 |
25682561
|
Scott Ullrich
|
$status = download_file_with_progress_bar("http://www.pfSense.com/latest_base.tgz", "/tmp/latest_base.tgz");
|
127 |
1b934970
|
Colin Smith
|
$static_status .= "done. ";
|
128 |
|
|
update_status($static_status);
|
129 |
25682561
|
Scott Ullrich
|
}
|
130 |
|
|
|
131 |
|
|
/* launch external upgrade helper */
|
132 |
5c59c339
|
Scott Ullrich
|
$external_upgrade_helper_text = "";
|
133 |
|
|
if($needs_system_upgrade == true) {
|
134 |
|
|
exec_rc_script_async("/etc/rc.firmware pfSense");
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
if($needs_kernel_upgrade == true) {
|
138 |
|
|
exec_rc_script_async("/etc/rc.firmware pfSense_kernel");
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
if($needs_base_upgrade == true) {
|
142 |
|
|
exec_rc_script_async("/etc/rc.firmware pfSense_base");
|
143 |
|
|
}
|
144 |
25682561
|
Scott Ullrich
|
|
145 |
853167d2
|
Colin Smith
|
update_status("pfSense is now upgrading. The firewall will reboot once the operation is completed.");
|
146 |
|
|
|
147 |
1c0e3b99
|
Scott Ullrich
|
echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
|
148 |
853167d2
|
Colin Smith
|
|
149 |
3db58e13
|
Scott Ullrich
|
/* end of upgrade script */
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
1c0e3b99
|
Scott Ullrich
|
/*
|
154 |
|
|
Helper functions
|
155 |
|
|
*/
|
156 |
25682561
|
Scott Ullrich
|
|
157 |
|
|
function download_file_with_progress_bar($url_file, $destination_file) {
|
158 |
|
|
global $ch, $fout, $file_size, $downloaded, $counter;
|
159 |
|
|
$file_size = 1;
|
160 |
|
|
$downloaded = 1;
|
161 |
|
|
/* open destination file */
|
162 |
|
|
$fout = fopen($destination_file, "wb");
|
163 |
|
|
|
164 |
|
|
/*
|
165 |
|
|
Originally by Author: Keyvan Minoukadeh
|
166 |
|
|
Modified by Scott Ullrich to return Content-Length size
|
167 |
|
|
*/
|
168 |
|
|
|
169 |
|
|
$ch = curl_init();
|
170 |
|
|
curl_setopt($ch, CURLOPT_URL, $url_file);
|
171 |
|
|
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');
|
172 |
|
|
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body');
|
173 |
|
|
curl_setopt($ch, CURLOPT_NOPROGRESS, '1');
|
174 |
|
|
|
175 |
|
|
curl_exec($ch);
|
176 |
|
|
fclose($fout);
|
177 |
|
|
return 1;
|
178 |
|
|
|
179 |
|
|
if ($error = curl_error($ch)) {
|
180 |
|
|
return -1;
|
181 |
|
|
}
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
function read_header($ch, $string) {
|
185 |
1c0e3b99
|
Scott Ullrich
|
global $file_size, $ch, $fout;
|
186 |
|
|
$length = strlen($string);
|
187 |
|
|
ereg("(Content-Length:) (.*)", $string, $regs);
|
188 |
|
|
if($regs[2] <> "") {
|
189 |
|
|
$file_size = intval($regs[2]);
|
190 |
|
|
}
|
191 |
|
|
return $length;
|
192 |
25682561
|
Scott Ullrich
|
}
|
193 |
|
|
|
194 |
|
|
function read_body($ch, $string) {
|
195 |
|
|
global $fout, $file_size, $downloaded, $counter;
|
196 |
|
|
$length = strlen($string);
|
197 |
|
|
$downloaded += intval($length);
|
198 |
|
|
$downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
|
199 |
|
|
$downloadProgress = 100 - $downloadProgress;
|
200 |
1b934970
|
Colin Smith
|
/*
|
201 |
1c0e3b99
|
Scott Ullrich
|
$a = $file_size;
|
202 |
|
|
$b = $downloaded;
|
203 |
|
|
$c = $downloadProgress;
|
204 |
8d958459
|
Colin Smith
|
$text = " Download Status\\n";
|
205 |
1c0e3b99
|
Scott Ullrich
|
$text .= "---------------------------------\\n";
|
206 |
|
|
$text .= " File size : {$a}\\n";
|
207 |
|
|
$text .= " Downloaded : {$b}\\n";
|
208 |
|
|
$text .= " Percent : {$c}%\\n";
|
209 |
|
|
$text .= "---------------------------------\\n";
|
210 |
1b934970
|
Colin Smith
|
*/
|
211 |
25682561
|
Scott Ullrich
|
$counter++;
|
212 |
|
|
if($counter > 150) {
|
213 |
1b934970
|
Colin Smith
|
$tostatus = $static_status . $downloadProgress;
|
214 |
|
|
update_status($tostatus);
|
215 |
25682561
|
Scott Ullrich
|
update_progress_bar($downloadProgress);
|
216 |
|
|
$counter = 0;
|
217 |
|
|
}
|
218 |
|
|
fwrite($fout, $string);
|
219 |
|
|
return $length;
|
220 |
|
|
}
|
221 |
|
|
|
222 |
853167d2
|
Colin Smith
|
?>
|