1 |
25682561
|
Scott Ullrich
|
<?php
|
2 |
|
|
/* $Id$ */
|
3 |
|
|
/*
|
4 |
|
|
system_firmware_auto.php
|
5 |
1cecfbf7
|
Scott Ullrich
|
Copyright (C) 2008 Scott Ullrich <sullrich@gmail.com>
|
6 |
da55e467
|
Scott Ullrich
|
Copyright (C) 2005 Scott Ullrich
|
7 |
5c59c339
|
Scott Ullrich
|
|
8 |
da55e467
|
Scott Ullrich
|
Based originally on system_firmware.php
|
9 |
|
|
(C)2003-2004 Manuel Kasper
|
10 |
25682561
|
Scott Ullrich
|
All rights reserved.
|
11 |
|
|
|
12 |
|
|
Redistribution and use in source and binary forms, with or without
|
13 |
|
|
modification, are permitted provided that the following conditions are met:
|
14 |
|
|
|
15 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
16 |
|
|
this list of conditions and the following disclaimer.
|
17 |
|
|
|
18 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
19 |
|
|
notice, this list of conditions and the following disclaimer in the
|
20 |
|
|
documentation and/or other materials provided with the distribution.
|
21 |
|
|
|
22 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
24 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
25 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
26 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
27 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
29 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
30 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
32 |
|
|
*/
|
33 |
1d333258
|
Scott Ullrich
|
/*
|
34 |
|
|
pfSense_BUILDER_BINARIES: /usr/bin/tar /usr/bin/nohup /bin/cat /sbin/sha256
|
35 |
|
|
pfSense_MODULE: firmware
|
36 |
|
|
*/
|
37 |
25682561
|
Scott Ullrich
|
|
38 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
39 |
|
|
##|*IDENT=page-system-firmware-checkforupdate
|
40 |
|
|
##|*NAME=System: Firmware: Check For Update page
|
41 |
|
|
##|*DESCR=Allow access to the 'System: Firmware: Check For Update' page.
|
42 |
|
|
##|*MATCH=system_firmware_auto.php*
|
43 |
|
|
##|-PRIV
|
44 |
|
|
|
45 |
da55e467
|
Scott Ullrich
|
require("guiconfig.inc");
|
46 |
|
|
|
47 |
|
|
$curcfg = $config['system']['firmware'];
|
48 |
9b7d7aa9
|
Scott Ullrich
|
|
49 |
ef794b01
|
Scott Ullrich
|
if(isset($curcfg['alturl']['enable']))
|
50 |
da55e467
|
Scott Ullrich
|
$updater_url = "{$config['system']['firmware']['alturl']['firmwareurl']}";
|
51 |
ef794b01
|
Scott Ullrich
|
else
|
52 |
|
|
$updater_url = $g['update_url'];
|
53 |
|
|
|
54 |
da55e467
|
Scott Ullrich
|
$pgtitle = array("Diagnostics","Firmware","Auto Update");
|
55 |
52380979
|
Scott Ullrich
|
include("head.inc");
|
56 |
|
|
|
57 |
25682561
|
Scott Ullrich
|
?>
|
58 |
|
|
|
59 |
da55e467
|
Scott Ullrich
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
60 |
|
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
61 |
|
|
</head>
|
62 |
|
|
|
63 |
25682561
|
Scott Ullrich
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
64 |
da55e467
|
Scott Ullrich
|
|
65 |
25682561
|
Scott Ullrich
|
<?php include("fbegin.inc"); ?>
|
66 |
|
|
|
67 |
|
|
<form action="system_firmware_auto.php" method="post">
|
68 |
da55e467
|
Scott Ullrich
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
69 |
|
|
<tr>
|
70 |
|
|
<td>
|
71 |
4820d297
|
Scott Ullrich
|
<?php
|
72 |
|
|
$tab_array = array();
|
73 |
9df75243
|
Scott Dale
|
$tab_array[0] = array("Manual Update", false, "system_firmware.php");
|
74 |
|
|
$tab_array[1] = array("Auto Update", true, "system_firmware_check.php");
|
75 |
4820d297
|
Scott Ullrich
|
$tab_array[2] = array("Updater Settings", false, "system_firmware_settings.php");
|
76 |
|
|
display_top_tabs($tab_array);
|
77 |
|
|
?>
|
78 |
da55e467
|
Scott Ullrich
|
</td>
|
79 |
|
|
</tr>
|
80 |
25682561
|
Scott Ullrich
|
<tr>
|
81 |
da55e467
|
Scott Ullrich
|
<td class="tabcont">
|
82 |
|
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
83 |
|
|
<tr>
|
84 |
|
|
<td class="tabcont">
|
85 |
|
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
86 |
|
|
<tr>
|
87 |
|
|
<td>
|
88 |
|
|
<center>
|
89 |
|
|
<table height='15' width='420' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
|
90 |
|
|
|
91 |
|
|
<tr>
|
92 |
|
|
<td background="./themes/the_wall/images/misc/bar_left.gif" height='15' width='5'>
|
93 |
|
|
</td>
|
94 |
|
|
<td>
|
95 |
|
|
<table id="progholder" name="progholder" height='15' width='410' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
|
96 |
|
|
<td background="./themes/the_wall/images/misc/bar_gray.gif" valign="top" align="left">
|
97 |
|
|
<img src='./themes/the_wall/images/misc/bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'>
|
98 |
|
|
</td>
|
99 |
|
|
</table>
|
100 |
|
|
</td>
|
101 |
|
|
<td background="./themes/the_wall/images/misc/bar_right.gif" height='15' width='5'>
|
102 |
|
|
</td>
|
103 |
|
|
</tr>
|
104 |
|
|
</table>
|
105 |
|
|
<br>
|
106 |
|
|
<!-- status box -->
|
107 |
c622d660
|
Bill Marquette
|
<textarea cols="60" rows="1" name="status" id="status" wrap="hard">Beginning firmware upgrade.</textarea>
|
108 |
da55e467
|
Scott Ullrich
|
<!-- command output box -->
|
109 |
|
|
<textarea cols="60" rows="25" name="output" id="output" wrap="hard"></textarea>
|
110 |
|
|
</center>
|
111 |
|
|
</td>
|
112 |
|
|
</tr>
|
113 |
25682561
|
Scott Ullrich
|
</table>
|
114 |
da55e467
|
Scott Ullrich
|
</table>
|
115 |
25682561
|
Scott Ullrich
|
</td>
|
116 |
|
|
</tr>
|
117 |
1c0e3b99
|
Scott Ullrich
|
</table>
|
118 |
25682561
|
Scott Ullrich
|
</form>
|
119 |
|
|
<?php include("fend.inc"); ?>
|
120 |
|
|
</body>
|
121 |
|
|
</html>
|
122 |
|
|
|
123 |
|
|
<?php
|
124 |
|
|
|
125 |
da55e467
|
Scott Ullrich
|
update_status("Downloading current version information...");
|
126 |
|
|
$latest_version = download_file_with_progress_bar("{$updater_url}/version", "/tmp/{$g['product_name']}_version");
|
127 |
|
|
|
128 |
|
|
$current_installed_pfsense_version = str_replace("\n", "", file_get_contents("/etc/version"));
|
129 |
|
|
$latest_version = str_replace("\n", "", file_get_contents("/tmp/{$g['product_name']}_version"));
|
130 |
|
|
|
131 |
|
|
if($current_installed_pfsense_version <> $latest_version)
|
132 |
|
|
$needs_system_upgrade = true;
|
133 |
d40b3c36
|
Colin Smith
|
|
134 |
da55e467
|
Scott Ullrich
|
if($needs_system_upgrade == true) {
|
135 |
|
|
update_status("Downloading updates ...");
|
136 |
0ba45a79
|
Renato Botelho
|
conf_mount_rw();
|
137 |
|
|
$status = download_file_with_progress_bar("{$updater_url}/latest.tgz", "{$g['upload_path']}/latest.tgz", "read_body_firmware");
|
138 |
|
|
$status = download_file_with_progress_bar("{$updater_url}/latest.tgz.sha256", "{$g['upload_path']}/latest.tgz.sha256");
|
139 |
|
|
conf_mount_ro();
|
140 |
da55e467
|
Scott Ullrich
|
update_output_window("{$g['product_name']} download complete.");
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
/* launch external upgrade helper */
|
144 |
61ffe8b8
|
Renato Botelho
|
$external_upgrade_helper_text = "/etc/rc.firmware ";
|
145 |
|
|
|
146 |
|
|
if($g['platform'] == "nanobsd")
|
147 |
|
|
$external_upgrade_helper_text .= "pfSenseNanoBSDupgrade ";
|
148 |
|
|
else
|
149 |
|
|
$external_upgrade_helper_text .= "pfSenseupgrade ";
|
150 |
|
|
|
151 |
da55e467
|
Scott Ullrich
|
if($needs_system_upgrade == true)
|
152 |
0ba45a79
|
Renato Botelho
|
$external_upgrade_helper_text .= "{$g['upload_path']}/latest.tgz";
|
153 |
da55e467
|
Scott Ullrich
|
|
154 |
1d333258
|
Scott Ullrich
|
$downloaded_latest_tgz_sha256 = str_replace("\n", "", `/sbin/sha256 -q {$g['upload_path']}/latest.tgz`);
|
155 |
|
|
$upgrade_latest_tgz_sha256 = str_replace("\n", "", `/bin/cat {$g['upload_path']}/latest.tgz.sha256 | awk '{ print $4 }'`);
|
156 |
da55e467
|
Scott Ullrich
|
|
157 |
563f5b51
|
Scott Ullrich
|
$sigchk = 0;
|
158 |
|
|
|
159 |
|
|
if(!isset($curcfg['alturl']['enable']))
|
160 |
0ba45a79
|
Renato Botelho
|
$sigchk = verify_digital_signature("{$g['upload_path']}/latest.tgz");
|
161 |
563f5b51
|
Scott Ullrich
|
|
162 |
|
|
if ($sigchk == 1)
|
163 |
|
|
$sig_warning = "The digital signature on this image is invalid.";
|
164 |
|
|
else if ($sigchk == 2)
|
165 |
|
|
$sig_warning = "This image is not digitally signed.";
|
166 |
|
|
else if (($sigchk == 3) || ($sigchk == 4))
|
167 |
|
|
$sig_warning = "There has been an error verifying the signature on this image.";
|
168 |
|
|
|
169 |
0ba45a79
|
Renato Botelho
|
if (!verify_gzip_file("{$g['upload_path']}/latest.tgz")) {
|
170 |
563f5b51
|
Scott Ullrich
|
update_status("The image file is corrupt.");
|
171 |
|
|
update_output_window("Update cannot continue");
|
172 |
0ba45a79
|
Renato Botelho
|
if (file_exists("{$g['upload_path']}/latest.tgz")) {
|
173 |
|
|
conf_mount_rw();
|
174 |
7dde365c
|
Renato Botelho
|
unlink("{$g['upload_path']}/latest.tgz");
|
175 |
0ba45a79
|
Renato Botelho
|
conf_mount_ro();
|
176 |
|
|
}
|
177 |
563f5b51
|
Scott Ullrich
|
require("fend.inc");
|
178 |
|
|
exit;
|
179 |
|
|
}
|
180 |
|
|
|
181 |
|
|
if ($sigchk) {
|
182 |
|
|
update_status($sig_warning);
|
183 |
|
|
update_output_window("Update cannot continue");
|
184 |
0ba45a79
|
Renato Botelho
|
if (file_exists("{$g['upload_path']}/latest.tgz")) {
|
185 |
|
|
conf_mount_rw();
|
186 |
7dde365c
|
Renato Botelho
|
unlink("{$g['upload_path']}/latest.tgz");
|
187 |
0ba45a79
|
Renato Botelho
|
conf_mount_ro();
|
188 |
|
|
}
|
189 |
563f5b51
|
Scott Ullrich
|
require("fend.inc");
|
190 |
|
|
exit;
|
191 |
|
|
}
|
192 |
|
|
|
193 |
da55e467
|
Scott Ullrich
|
if($downloaded_latest_tgz_sha256 <> $upgrade_latest_tgz_sha256) {
|
194 |
|
|
update_status("Downloading complete but sha256 does not match.");
|
195 |
|
|
update_output_window("Auto upgrade aborted. \n\nDownloaded SHA256: $downloaded_latest_tgz_sha256 \n\nNeeded SHA256: $upgrade_latest_tgz_sha256");
|
196 |
d40b3c36
|
Colin Smith
|
} else {
|
197 |
da55e467
|
Scott Ullrich
|
update_output_window("{$g['product_name']} is now upgrading.\\n\\nThe firewall will reboot once the operation is completed.");
|
198 |
|
|
echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
|
199 |
1d333258
|
Scott Ullrich
|
mwexec("/usr/bin/nohup {$external_upgrade_helper_text}");
|
200 |
d40b3c36
|
Colin Smith
|
}
|
201 |
cdb0117c
|
Scott Ullrich
|
|
202 |
da55e467
|
Scott Ullrich
|
/*
|
203 |
|
|
Helper functions
|
204 |
|
|
*/
|
205 |
d40b3c36
|
Colin Smith
|
|
206 |
9140757d
|
Bill Marquette
|
function read_body_firmware($ch, $string) {
|
207 |
da55e467
|
Scott Ullrich
|
global $fout, $file_size, $downloaded, $counter, $version, $latest_version, $current_installed_pfsense_version;
|
208 |
|
|
$length = strlen($string);
|
209 |
|
|
$downloaded += intval($length);
|
210 |
|
|
$downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
|
211 |
|
|
$downloadProgress = 100 - $downloadProgress;
|
212 |
|
|
$a = $file_size;
|
213 |
|
|
$b = $downloaded;
|
214 |
|
|
$c = $downloadProgress;
|
215 |
|
|
$text = " Auto Update Download Status\\n";
|
216 |
5924fa0f
|
Scott Ullrich
|
$text .= "----------------------------------------------------\\n";
|
217 |
da55e467
|
Scott Ullrich
|
$text .= " Latest Version : {$latest_version}\\n";
|
218 |
|
|
$text .= " Current Version : {$current_installed_pfsense_version}\\n";
|
219 |
|
|
$text .= " File size : {$a}\\n";
|
220 |
|
|
$text .= " Downloaded : {$b}\\n";
|
221 |
|
|
$text .= " Percent : {$c}%\\n";
|
222 |
5924fa0f
|
Scott Ullrich
|
$text .= "----------------------------------------------------\\n";
|
223 |
da55e467
|
Scott Ullrich
|
$counter++;
|
224 |
|
|
if($counter > 150) {
|
225 |
|
|
update_output_window($text);
|
226 |
|
|
update_progress_bar($downloadProgress);
|
227 |
|
|
$counter = 0;
|
228 |
|
|
}
|
229 |
|
|
fwrite($fout, $string);
|
230 |
|
|
return $length;
|
231 |
ebe916cf
|
Colin Smith
|
}
|
232 |
853167d2
|
Colin Smith
|
|
233 |
1d333258
|
Scott Ullrich
|
?>
|