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