Project

General

Profile

Download (10.5 KB) Statistics
| Branch: | Tag: | Revision:
1 25682561 Scott Ullrich
<?php
2
/* $Id$ */
3
/*
4
	system_firmware_auto.php
5 da55e467 Scott Ullrich
	Copyright (C) 2005 Scott Ullrich
6 29aef6c4 Jim Thompson
	Copyright (C) 2008 Scott Ullrich <sullrich@gmail.com>
7
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
8 5c59c339 Scott Ullrich
9 4b805dbc Renato Botelho
	Based originally on system_firmware.php
10
	(C)2003-2004 Manuel Kasper
11 25682561 Scott Ullrich
	All rights reserved.
12
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15
16
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18
19
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22
23
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34 1d333258 Scott Ullrich
/*
35
	pfSense_BUILDER_BINARIES:	/usr/bin/tar	/usr/bin/nohup	/bin/cat	/sbin/sha256
36
	pfSense_MODULE:	firmware
37
*/
38 25682561 Scott Ullrich
39 6b07c15a Matthew Grooms
##|+PRIV
40
##|*IDENT=page-system-firmware-checkforupdate
41
##|*NAME=System: Firmware: Check For Update page
42
##|*DESCR=Allow access to the 'System: Firmware: Check For Update' page.
43
##|*MATCH=system_firmware_auto.php*
44
##|-PRIV
45
46 7385a6b4 Scott Ullrich
$nocsrf = true;
47
48 da55e467 Scott Ullrich
require("guiconfig.inc");
49 4e6593de jim-p
require_once("pfsense-utils.inc");
50 da55e467 Scott Ullrich
51
$curcfg = $config['system']['firmware'];
52 9b7d7aa9 Scott Ullrich
53 ef794b01 Scott Ullrich
if(isset($curcfg['alturl']['enable']))
54 da55e467 Scott Ullrich
	$updater_url = "{$config['system']['firmware']['alturl']['firmwareurl']}";
55 ef794b01 Scott Ullrich
else
56
	$updater_url = $g['update_url'];
57 a30afe0e Scott Ullrich
58 4b805dbc Renato Botelho
if($_POST['backupbeforeupgrade'])
59 a30afe0e Scott Ullrich
	touch("/tmp/perform_full_backup.txt");
60 4b805dbc Renato Botelho
61 a18b04d8 Colin Fleming
$closehead = false;
62 499fea07 Carlos Eduardo Ramos
$pgtitle = array(gettext("Diagnostics"),gettext("Firmware"),gettext("Auto Update"));
63 52380979 Scott Ullrich
include("head.inc");
64
65 25682561 Scott Ullrich
?>
66
67 c3ab82a9 technical50
<meta http-equiv="Content-Type" content="text/html; charset=<?=system_get_language_codeset();?>" />
68 a18b04d8 Colin Fleming
<link href="gui.css" rel="stylesheet" type="text/css" />
69 da55e467 Scott Ullrich
</head>
70
71 25682561 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
72 da55e467 Scott Ullrich
73 25682561 Scott Ullrich
<?php include("fbegin.inc"); ?>
74
75
<form action="system_firmware_auto.php" method="post">
76 94b0ac1c Ermal LUÇI
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firmware auto-check">
77 da55e467 Scott Ullrich
	<tr>
78
		<td>
79 4b805dbc Renato Botelho
		<?php
80
			$tab_array = array();
81
			$tab_array[] = array(gettext("Manual Update"), false, "system_firmware.php");
82
			$tab_array[] = array(gettext("Auto Update"), true, "system_firmware_check.php");
83
			$tab_array[] = array(gettext("Updater Settings"), false, "system_firmware_settings.php");
84
			if($g['hidedownloadbackup'] == false)
85
				$tab_array[] = array(gettext("Restore Full Backup"), false, "system_firmware_restorefullbackup.php");
86
			display_top_tabs($tab_array);
87
		?>
88 da55e467 Scott Ullrich
		</td>
89
	</tr>
90 25682561 Scott Ullrich
	<tr>
91 4b805dbc Renato Botelho
		<td class="tabcont">
92 a18b04d8 Colin Fleming
			<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="outer">
93 4b805dbc Renato Botelho
				<tr>
94
					<td class="tabcont">
95 a18b04d8 Colin Fleming
						<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="inner">
96 4b805dbc Renato Botelho
							<tr>
97 a18b04d8 Colin Fleming
								<td align="center">
98
									<table style="height:15;colspacing:0" width="420" border="0" cellpadding="0" cellspacing="0" summary="images">
99 4b805dbc Renato Botelho
100
										<tr>
101 7bc1b968 Renato Botelho
											<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_left.gif')" height="15" width="5">	</td>
102 4b805dbc Renato Botelho
											<td>
103 a18b04d8 Colin Fleming
											<table id="progholder" style="height:15;colspacing:0" width="410" border="0" cellpadding="0" cellspacing="0" summary="">
104 7bc1b968 Renato Botelho
												<tr><td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_gray.gif')" valign="top" align="left">
105
												<img src="./themes/<?=$g['theme'];?>/images/misc/bar_blue.gif" width="0" height="15" name="progressbar" id="progressbar" alt="" />
106 a18b04d8 Colin Fleming
												</td></tr>
107 4b805dbc Renato Botelho
											</table>
108
											</td>
109 7bc1b968 Renato Botelho
											<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_right.gif')" height="15" width="5"></td>
110 4b805dbc Renato Botelho
										</tr>
111 da55e467 Scott Ullrich
									</table>
112 a18b04d8 Colin Fleming
									<br />
113 587ecd08 Colin Fleming
									<script type="text/javascript">
114
									//<![CDATA[
115
									window.onload=function(){
116
										document.getElementById("status").wrap='hard';
117
										document.getElementById("output").wrap='hard';
118
									}
119
									//]]>
120
									</script>
121 4b805dbc Renato Botelho
									<!-- status box -->
122 587ecd08 Colin Fleming
									<textarea cols="90" rows="1" name="status" id="status"><?=gettext("Beginning firmware upgrade"); ?>.</textarea>
123 e3e1f748 Colin Fleming
									<br />
124 4b805dbc Renato Botelho
									<!-- command output box -->
125 587ecd08 Colin Fleming
									<textarea cols="90" rows="25" name="output" id="output"></textarea>
126 da55e467 Scott Ullrich
								</td>
127
							</tr>
128
						</table>
129
					</td>
130
				</tr>
131 4b805dbc Renato Botelho
			</table>
132
		</td>
133 25682561 Scott Ullrich
	</tr>
134 1c0e3b99 Scott Ullrich
</table>
135 25682561 Scott Ullrich
</form>
136 a18b04d8 Colin Fleming
137 25682561 Scott Ullrich
<?php include("fend.inc"); ?>
138
139
<?php
140
141 89f0ac4c Renato Botelho
update_status(gettext("Downloading current version information") . "...");
142 414053da jim-p
$nanosize = "";
143
if ($g['platform'] == "nanobsd") {
144 0d7715eb Renato Botelho
	if (file_exists("/etc/nano_use_vga.txt"))
145
		$nanosize = "-nanobsd-vga-";
146
	else
147
		$nanosize = "-nanobsd-";
148
149
	$nanosize .= strtolower(trim(file_get_contents("/etc/nanosize.txt")));
150 414053da jim-p
}
151
152 bd2b98c9 Ermal
@unlink("/tmp/{$g['product_name']}_version");
153 414053da jim-p
download_file_with_progress_bar("{$updater_url}/version{$nanosize}", "/tmp/{$g['product_name']}_version");
154 773c99bc Ermal
$latest_version = str_replace("\n", "", @file_get_contents("/tmp/{$g['product_name']}_version"));
155
if(!$latest_version) {
156 89f0ac4c Renato Botelho
	update_output_window(gettext("Unable to check for updates."));
157 773c99bc Ermal
	require("fend.inc");
158
	exit;
159
} else {
160 4e6593de jim-p
	$current_installed_buildtime = trim(file_get_contents("/etc/version.buildtime"));
161
	$current_installed_version = trim(file_get_contents("/etc/version"));
162
	$latest_version = trim(@file_get_contents("/tmp/{$g['product_name']}_version"));
163 773c99bc Ermal
	$latest_version_pfsense = strtotime($latest_version);
164
	if(!$latest_version) {
165 89f0ac4c Renato Botelho
		update_output_window(gettext("Unable to check for updates."));
166 773c99bc Ermal
		require("fend.inc");
167
		exit;
168
	} else {
169 4e6593de jim-p
		if (pfs_version_compare($current_installed_buildtime, $current_installed_version, $latest_version) == -1) {
170 89f0ac4c Renato Botelho
			update_status(gettext("Downloading updates") . "...");
171 773c99bc Ermal
			conf_mount_rw();
172 087d875c jim-p
			if ($g['platform'] == "nanobsd") {
173
				$update_filename = "latest{$nanosize}.img.gz";
174
			} else {
175
				$update_filename = "latest.tgz";
176
			}
177 4b805dbc Renato Botelho
			$status = download_file_with_progress_bar("{$updater_url}/{$update_filename}", "{$g['upload_path']}/latest.tgz", "read_body_firmware");
178 087d875c jim-p
			$status = download_file_with_progress_bar("{$updater_url}/{$update_filename}.sha256", "{$g['upload_path']}/latest.tgz.sha256");
179 773c99bc Ermal
			conf_mount_ro();
180 b7596b80 Carlos Eduardo Ramos
			update_output_window("{$g['product_name']} " . gettext("download complete."));
181 773c99bc Ermal
		} else {
182 89f0ac4c Renato Botelho
			update_output_window(gettext("You are on the latest version."));
183 773c99bc Ermal
			require("fend.inc");
184
			exit;
185
		}
186
	}
187 da55e467 Scott Ullrich
}
188
189
/* launch external upgrade helper */
190 61ffe8b8 Renato Botelho
$external_upgrade_helper_text = "/etc/rc.firmware ";
191
192
if($g['platform'] == "nanobsd")
193
	$external_upgrade_helper_text .= "pfSenseNanoBSDupgrade ";
194
else
195
	$external_upgrade_helper_text .= "pfSenseupgrade ";
196
197 4e6593de jim-p
$external_upgrade_helper_text .= "{$g['upload_path']}/latest.tgz";
198 da55e467 Scott Ullrich
199 1d333258 Scott Ullrich
$downloaded_latest_tgz_sha256 = str_replace("\n", "", `/sbin/sha256 -q {$g['upload_path']}/latest.tgz`);
200
$upgrade_latest_tgz_sha256 = str_replace("\n", "", `/bin/cat {$g['upload_path']}/latest.tgz.sha256 | awk '{ print $4 }'`);
201 da55e467 Scott Ullrich
202 563f5b51 Scott Ullrich
$sigchk = 0;
203
204
if(!isset($curcfg['alturl']['enable']))
205 0ba45a79 Renato Botelho
	$sigchk = verify_digital_signature("{$g['upload_path']}/latest.tgz");
206 563f5b51 Scott Ullrich
207 4b798102 Ermal
$exitstatus = 0;
208
if ($sigchk == 1) {
209 89f0ac4c Renato Botelho
	$sig_warning = gettext("The digital signature on this image is invalid.");
210 4b798102 Ermal
	$exitstatus = 1;
211
} else if ($sigchk == 2) {
212 89f0ac4c Renato Botelho
	$sig_warning = gettext("This image is not digitally signed.");
213 4b798102 Ermal
	if (!isset($config['system']['firmware']['allowinvalidsig']))
214
		$exitstatus = 1;
215
} else if (($sigchk >= 3)) {
216 89f0ac4c Renato Botelho
	$sig_warning = gettext("There has been an error verifying the signature on this image.");
217 4b798102 Ermal
	$exitstatus = 1;
218
}
219
220
if ($exitstatus) {
221 4b805dbc Renato Botelho
	update_status($sig_warning);
222
	update_output_window(gettext("Update cannot continue.  You can disable this check on the Updater Settings tab."));
223
	require("fend.inc");
224
	exit;
225 2646434b Scott Ullrich
} else if ($sigchk == 2) {
226 4b805dbc Renato Botelho
	update_status("Upgrade in progress...");
227
	update_output_window("\n" . gettext("Upgrade Image does not contain a signature but the system has been configured to allow unsigned images. One moment please...") . "\n");
228 2646434b Scott Ullrich
}
229 563f5b51 Scott Ullrich
230 0ba45a79 Renato Botelho
if (!verify_gzip_file("{$g['upload_path']}/latest.tgz")) {
231 89f0ac4c Renato Botelho
	update_status(gettext("The image file is corrupt."));
232
	update_output_window(gettext("Update cannot continue"));
233 0ba45a79 Renato Botelho
	if (file_exists("{$g['upload_path']}/latest.tgz")) {
234
		conf_mount_rw();
235 7dde365c Renato Botelho
		unlink("{$g['upload_path']}/latest.tgz");
236 0ba45a79 Renato Botelho
		conf_mount_ro();
237
	}
238 563f5b51 Scott Ullrich
	require("fend.inc");
239
	exit;
240
}
241
242 da55e467 Scott Ullrich
if($downloaded_latest_tgz_sha256 <> $upgrade_latest_tgz_sha256) {
243 89f0ac4c Renato Botelho
	update_status(gettext("Downloading complete but sha256 does not match."));
244
	update_output_window(gettext("Auto upgrade aborted.") . "  \n\n" . gettext("Downloaded SHA256") . ": " . $downloaded_latest_tgz_sha256 . "\n\n" . gettext("Needed SHA256") . ": " . $upgrade_latest_tgz_sha256);
245 d40b3c36 Colin Smith
} else {
246 89f0ac4c Renato Botelho
	update_output_window($g['product_name'] . " " . gettext("is now upgrading.") . "\\n\\n" . gettext("The firewall will reboot once the operation is completed."));
247 a18b04d8 Colin Fleming
	echo "\n<script type=\"text/javascript\">";
248
	echo "\n//<![CDATA[";
249
	echo "\ndocument.progressbar.style.visibility='hidden';";
250
	echo "\n//]]>";
251
	echo "\n</script>";
252 22ef0a3d Ermal
	mwexec_bg($external_upgrade_helper_text);
253 d40b3c36 Colin Smith
}
254 cdb0117c Scott Ullrich
255 da55e467 Scott Ullrich
/*
256
	Helper functions
257
*/
258 d40b3c36 Colin Smith
259 9140757d Bill Marquette
function read_body_firmware($ch, $string) {
260 4e6593de jim-p
	global $fout, $file_size, $downloaded, $counter, $version, $latest_version, $current_installed_version;
261 da55e467 Scott Ullrich
	$length = strlen($string);
262
	$downloaded += intval($length);
263
	$downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
264
	$downloadProgress = 100 - $downloadProgress;
265
	$a = $file_size;
266
	$b = $downloaded;
267
	$c = $downloadProgress;
268 89f0ac4c Renato Botelho
	$text  = "  " . gettext("Auto Update Download Status") . "\\n";
269 5924fa0f Scott Ullrich
	$text .= "----------------------------------------------------\\n";
270 4e6593de jim-p
	$text .= "  " . gettext("Current Version") . " : {$current_installed_version}\\n";
271 89f0ac4c Renato Botelho
	$text .= "  " . gettext("Latest Version") . "  : {$latest_version}\\n";
272
	$text .= "  " . gettext("File size") . "       : {$a}\\n";
273
	$text .= "  " . gettext("Downloaded") . "      : {$b}\\n";
274
	$text .= "  " . gettext("Percent") . "         : {$c}%\\n";
275 5924fa0f Scott Ullrich
	$text .= "----------------------------------------------------\\n";
276 da55e467 Scott Ullrich
	$counter++;
277
	if($counter > 150) {
278
		update_output_window($text);
279
		update_progress_bar($downloadProgress);
280
		$counter = 0;
281
	}
282
	fwrite($fout, $string);
283
	return $length;
284 ebe916cf Colin Smith
}
285 853167d2 Colin Smith
286 773c99bc Ermal
?>
287 a18b04d8 Colin Fleming
288
</body>
289
</html>