Project

General

Profile

Download (10.4 KB) Statistics
| Branch: | Tag: | Revision:
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 4b805dbc Renato Botelho
	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 7385a6b4 Scott Ullrich
$nocsrf = true;
46
47 da55e467 Scott Ullrich
require("guiconfig.inc");
48 4e6593de jim-p
require_once("pfsense-utils.inc");
49 da55e467 Scott Ullrich
50
$curcfg = $config['system']['firmware'];
51 9b7d7aa9 Scott Ullrich
52 ef794b01 Scott Ullrich
if(isset($curcfg['alturl']['enable']))
53 da55e467 Scott Ullrich
	$updater_url = "{$config['system']['firmware']['alturl']['firmwareurl']}";
54 ef794b01 Scott Ullrich
else
55
	$updater_url = $g['update_url'];
56 a30afe0e Scott Ullrich
57 4b805dbc Renato Botelho
if($_POST['backupbeforeupgrade'])
58 a30afe0e Scott Ullrich
	touch("/tmp/perform_full_backup.txt");
59 4b805dbc Renato Botelho
60 a18b04d8 Colin Fleming
$closehead = false;
61 499fea07 Carlos Eduardo Ramos
$pgtitle = array(gettext("Diagnostics"),gettext("Firmware"),gettext("Auto Update"));
62 52380979 Scott Ullrich
include("head.inc");
63
64 25682561 Scott Ullrich
?>
65
66 c3ab82a9 technical50
<meta http-equiv="Content-Type" content="text/html; charset=<?=system_get_language_codeset();?>" />
67 a18b04d8 Colin Fleming
<link href="gui.css" rel="stylesheet" type="text/css" />
68 da55e467 Scott Ullrich
</head>
69
70 25682561 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
71 da55e467 Scott Ullrich
72 25682561 Scott Ullrich
<?php include("fbegin.inc"); ?>
73
74
<form action="system_firmware_auto.php" method="post">
75 a18b04d8 Colin Fleming
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="firmware auto-check">
76 da55e467 Scott Ullrich
	<tr>
77
		<td>
78 4b805dbc Renato Botelho
		<?php
79
			$tab_array = array();
80
			$tab_array[] = array(gettext("Manual Update"), false, "system_firmware.php");
81
			$tab_array[] = array(gettext("Auto Update"), true, "system_firmware_check.php");
82
			$tab_array[] = array(gettext("Updater Settings"), false, "system_firmware_settings.php");
83
			if($g['hidedownloadbackup'] == false)
84
				$tab_array[] = array(gettext("Restore Full Backup"), false, "system_firmware_restorefullbackup.php");
85
			display_top_tabs($tab_array);
86
		?>
87 da55e467 Scott Ullrich
		</td>
88
	</tr>
89 25682561 Scott Ullrich
	<tr>
90 4b805dbc Renato Botelho
		<td class="tabcont">
91 a18b04d8 Colin Fleming
			<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="outer">
92 4b805dbc Renato Botelho
				<tr>
93
					<td class="tabcont">
94 a18b04d8 Colin Fleming
						<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="inner">
95 4b805dbc Renato Botelho
							<tr>
96 a18b04d8 Colin Fleming
								<td align="center">
97
									<table style="height:15;colspacing:0" width="420" border="0" cellpadding="0" cellspacing="0" summary="images">
98 4b805dbc Renato Botelho
99
										<tr>
100 7bc1b968 Renato Botelho
											<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_left.gif')" height="15" width="5">	</td>
101 4b805dbc Renato Botelho
											<td>
102 a18b04d8 Colin Fleming
											<table id="progholder" style="height:15;colspacing:0" width="410" border="0" cellpadding="0" cellspacing="0" summary="">
103 7bc1b968 Renato Botelho
												<tr><td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_gray.gif')" valign="top" align="left">
104
												<img src="./themes/<?=$g['theme'];?>/images/misc/bar_blue.gif" width="0" height="15" name="progressbar" id="progressbar" alt="" />
105 a18b04d8 Colin Fleming
												</td></tr>
106 4b805dbc Renato Botelho
											</table>
107
											</td>
108 7bc1b968 Renato Botelho
											<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_right.gif')" height="15" width="5"></td>
109 4b805dbc Renato Botelho
										</tr>
110 da55e467 Scott Ullrich
									</table>
111 a18b04d8 Colin Fleming
									<br />
112 587ecd08 Colin Fleming
									<script type="text/javascript">
113
									//<![CDATA[
114
									window.onload=function(){
115
										document.getElementById("status").wrap='hard';
116
										document.getElementById("output").wrap='hard';
117
									}
118
									//]]>
119
									</script>
120 4b805dbc Renato Botelho
									<!-- status box -->
121 587ecd08 Colin Fleming
									<textarea cols="90" rows="1" name="status" id="status"><?=gettext("Beginning firmware upgrade"); ?>.</textarea>
122 4b805dbc Renato Botelho
									<!-- command output box -->
123 587ecd08 Colin Fleming
									<textarea cols="90" rows="25" name="output" id="output"></textarea>
124 da55e467 Scott Ullrich
								</td>
125
							</tr>
126
						</table>
127
					</td>
128
				</tr>
129 4b805dbc Renato Botelho
			</table>
130
		</td>
131 25682561 Scott Ullrich
	</tr>
132 1c0e3b99 Scott Ullrich
</table>
133 25682561 Scott Ullrich
</form>
134 a18b04d8 Colin Fleming
135 25682561 Scott Ullrich
<?php include("fend.inc"); ?>
136
137
<?php
138
139 89f0ac4c Renato Botelho
update_status(gettext("Downloading current version information") . "...");
140 414053da jim-p
$nanosize = "";
141
if ($g['platform'] == "nanobsd") {
142 0d7715eb Renato Botelho
	if (file_exists("/etc/nano_use_vga.txt"))
143
		$nanosize = "-nanobsd-vga-";
144
	else
145
		$nanosize = "-nanobsd-";
146
147
	$nanosize .= strtolower(trim(file_get_contents("/etc/nanosize.txt")));
148 414053da jim-p
}
149
150 bd2b98c9 Ermal
@unlink("/tmp/{$g['product_name']}_version");
151 414053da jim-p
download_file_with_progress_bar("{$updater_url}/version{$nanosize}", "/tmp/{$g['product_name']}_version");
152 773c99bc Ermal
$latest_version = str_replace("\n", "", @file_get_contents("/tmp/{$g['product_name']}_version"));
153
if(!$latest_version) {
154 89f0ac4c Renato Botelho
	update_output_window(gettext("Unable to check for updates."));
155 773c99bc Ermal
	require("fend.inc");
156
	exit;
157
} else {
158 4e6593de jim-p
	$current_installed_buildtime = trim(file_get_contents("/etc/version.buildtime"));
159
	$current_installed_version = trim(file_get_contents("/etc/version"));
160
	$latest_version = trim(@file_get_contents("/tmp/{$g['product_name']}_version"));
161 773c99bc Ermal
	$latest_version_pfsense = strtotime($latest_version);
162
	if(!$latest_version) {
163 89f0ac4c Renato Botelho
		update_output_window(gettext("Unable to check for updates."));
164 773c99bc Ermal
		require("fend.inc");
165
		exit;
166
	} else {
167 4e6593de jim-p
		if (pfs_version_compare($current_installed_buildtime, $current_installed_version, $latest_version) == -1) {
168 89f0ac4c Renato Botelho
			update_status(gettext("Downloading updates") . "...");
169 773c99bc Ermal
			conf_mount_rw();
170 087d875c jim-p
			if ($g['platform'] == "nanobsd") {
171
				$update_filename = "latest{$nanosize}.img.gz";
172
			} else {
173
				$update_filename = "latest.tgz";
174
			}
175 4b805dbc Renato Botelho
			$status = download_file_with_progress_bar("{$updater_url}/{$update_filename}", "{$g['upload_path']}/latest.tgz", "read_body_firmware");
176 087d875c jim-p
			$status = download_file_with_progress_bar("{$updater_url}/{$update_filename}.sha256", "{$g['upload_path']}/latest.tgz.sha256");
177 773c99bc Ermal
			conf_mount_ro();
178 b7596b80 Carlos Eduardo Ramos
			update_output_window("{$g['product_name']} " . gettext("download complete."));
179 773c99bc Ermal
		} else {
180 89f0ac4c Renato Botelho
			update_output_window(gettext("You are on the latest version."));
181 773c99bc Ermal
			require("fend.inc");
182
			exit;
183
		}
184
	}
185 da55e467 Scott Ullrich
}
186
187
/* launch external upgrade helper */
188 61ffe8b8 Renato Botelho
$external_upgrade_helper_text = "/etc/rc.firmware ";
189
190
if($g['platform'] == "nanobsd")
191
	$external_upgrade_helper_text .= "pfSenseNanoBSDupgrade ";
192
else
193
	$external_upgrade_helper_text .= "pfSenseupgrade ";
194
195 4e6593de jim-p
$external_upgrade_helper_text .= "{$g['upload_path']}/latest.tgz";
196 da55e467 Scott Ullrich
197 1d333258 Scott Ullrich
$downloaded_latest_tgz_sha256 = str_replace("\n", "", `/sbin/sha256 -q {$g['upload_path']}/latest.tgz`);
198
$upgrade_latest_tgz_sha256 = str_replace("\n", "", `/bin/cat {$g['upload_path']}/latest.tgz.sha256 | awk '{ print $4 }'`);
199 da55e467 Scott Ullrich
200 563f5b51 Scott Ullrich
$sigchk = 0;
201
202
if(!isset($curcfg['alturl']['enable']))
203 0ba45a79 Renato Botelho
	$sigchk = verify_digital_signature("{$g['upload_path']}/latest.tgz");
204 563f5b51 Scott Ullrich
205 4b798102 Ermal
$exitstatus = 0;
206
if ($sigchk == 1) {
207 89f0ac4c Renato Botelho
	$sig_warning = gettext("The digital signature on this image is invalid.");
208 4b798102 Ermal
	$exitstatus = 1;
209
} else if ($sigchk == 2) {
210 89f0ac4c Renato Botelho
	$sig_warning = gettext("This image is not digitally signed.");
211 4b798102 Ermal
	if (!isset($config['system']['firmware']['allowinvalidsig']))
212
		$exitstatus = 1;
213
} else if (($sigchk >= 3)) {
214 89f0ac4c Renato Botelho
	$sig_warning = gettext("There has been an error verifying the signature on this image.");
215 4b798102 Ermal
	$exitstatus = 1;
216
}
217
218
if ($exitstatus) {
219 4b805dbc Renato Botelho
	update_status($sig_warning);
220
	update_output_window(gettext("Update cannot continue.  You can disable this check on the Updater Settings tab."));
221
	require("fend.inc");
222
	exit;
223 2646434b Scott Ullrich
} else if ($sigchk == 2) {
224 4b805dbc Renato Botelho
	update_status("Upgrade in progress...");
225
	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");
226 2646434b Scott Ullrich
}
227 563f5b51 Scott Ullrich
228 0ba45a79 Renato Botelho
if (!verify_gzip_file("{$g['upload_path']}/latest.tgz")) {
229 89f0ac4c Renato Botelho
	update_status(gettext("The image file is corrupt."));
230
	update_output_window(gettext("Update cannot continue"));
231 0ba45a79 Renato Botelho
	if (file_exists("{$g['upload_path']}/latest.tgz")) {
232
		conf_mount_rw();
233 7dde365c Renato Botelho
		unlink("{$g['upload_path']}/latest.tgz");
234 0ba45a79 Renato Botelho
		conf_mount_ro();
235
	}
236 563f5b51 Scott Ullrich
	require("fend.inc");
237
	exit;
238
}
239
240 da55e467 Scott Ullrich
if($downloaded_latest_tgz_sha256 <> $upgrade_latest_tgz_sha256) {
241 89f0ac4c Renato Botelho
	update_status(gettext("Downloading complete but sha256 does not match."));
242
	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);
243 d40b3c36 Colin Smith
} else {
244 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."));
245 a18b04d8 Colin Fleming
	echo "\n<script type=\"text/javascript\">";
246
	echo "\n//<![CDATA[";
247
	echo "\ndocument.progressbar.style.visibility='hidden';";
248
	echo "\n//]]>";
249
	echo "\n</script>";
250 22ef0a3d Ermal
	mwexec_bg($external_upgrade_helper_text);
251 d40b3c36 Colin Smith
}
252 cdb0117c Scott Ullrich
253 da55e467 Scott Ullrich
/*
254
	Helper functions
255
*/
256 d40b3c36 Colin Smith
257 9140757d Bill Marquette
function read_body_firmware($ch, $string) {
258 4e6593de jim-p
	global $fout, $file_size, $downloaded, $counter, $version, $latest_version, $current_installed_version;
259 da55e467 Scott Ullrich
	$length = strlen($string);
260
	$downloaded += intval($length);
261
	$downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
262
	$downloadProgress = 100 - $downloadProgress;
263
	$a = $file_size;
264
	$b = $downloaded;
265
	$c = $downloadProgress;
266 89f0ac4c Renato Botelho
	$text  = "  " . gettext("Auto Update Download Status") . "\\n";
267 5924fa0f Scott Ullrich
	$text .= "----------------------------------------------------\\n";
268 4e6593de jim-p
	$text .= "  " . gettext("Current Version") . " : {$current_installed_version}\\n";
269 89f0ac4c Renato Botelho
	$text .= "  " . gettext("Latest Version") . "  : {$latest_version}\\n";
270
	$text .= "  " . gettext("File size") . "       : {$a}\\n";
271
	$text .= "  " . gettext("Downloaded") . "      : {$b}\\n";
272
	$text .= "  " . gettext("Percent") . "         : {$c}%\\n";
273 5924fa0f Scott Ullrich
	$text .= "----------------------------------------------------\\n";
274 da55e467 Scott Ullrich
	$counter++;
275
	if($counter > 150) {
276
		update_output_window($text);
277
		update_progress_bar($downloadProgress);
278
		$counter = 0;
279
	}
280
	fwrite($fout, $string);
281
	return $length;
282 ebe916cf Colin Smith
}
283 853167d2 Colin Smith
284 773c99bc Ermal
?>
285 a18b04d8 Colin Fleming
286
</body>
287
</html>