Project

General

Profile

Download (10.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_firmware_auto.php
5
	Copyright (C) 2005 Scott Ullrich
6
	Copyright (C) 2008 Scott Ullrich <sullrich@gmail.com>
7
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8

    
9
	Based originally on system_firmware.php
10
	(C)2003-2004 Manuel Kasper
11
	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
/*
35
	pfSense_BUILDER_BINARIES:	/usr/bin/tar	/usr/bin/nohup	/bin/cat	/sbin/sha256
36
	pfSense_MODULE:	firmware
37
*/
38

    
39
##|+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
$nocsrf = true;
47

    
48
require("guiconfig.inc");
49
require_once("pfsense-utils.inc");
50

    
51
$curcfg = $config['system']['firmware'];
52

    
53
if(isset($curcfg['alturl']['enable']))
54
	$updater_url = "{$config['system']['firmware']['alturl']['firmwareurl']}";
55
else
56
	$updater_url = $g['update_url'];
57

    
58
if($_POST['backupbeforeupgrade'])
59
	touch("/tmp/perform_full_backup.txt");
60

    
61
$closehead = false;
62
$pgtitle = array(gettext("Diagnostics"),gettext("Firmware"),gettext("Auto Update"));
63
include("head.inc");
64

    
65
?>
66

    
67
<meta http-equiv="Content-Type" content="text/html; charset=<?=system_get_language_codeset();?>" />
68
<link href="gui.css" rel="stylesheet" type="text/css" />
69
</head>
70

    
71
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
72

    
73
<?php include("fbegin.inc"); ?>
74

    
75
<form action="system_firmware_auto.php" method="post">
76
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firmware auto-check">
77
	<tr>
78
		<td>
79
		<?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
		</td>
89
	</tr>
90
	<tr>
91
		<td class="tabcont">
92
			<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="outer">
93
				<tr>
94
					<td class="tabcont">
95
						<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="inner">
96
							<tr>
97
								<td align="center">
98
									<table style="height:15;colspacing:0" width="420" border="0" cellpadding="0" cellspacing="0" summary="images">
99

    
100
										<tr>
101
											<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_left.gif')" height="15" width="5">	</td>
102
											<td>
103
											<table id="progholder" style="height:15;colspacing:0" width="410" border="0" cellpadding="0" cellspacing="0" summary="">
104
												<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
												</td></tr>
107
											</table>
108
											</td>
109
											<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_right.gif')" height="15" width="5"></td>
110
										</tr>
111
									</table>
112
									<br />
113
									<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
									<!-- status box -->
122
									<textarea cols="90" rows="1" name="status" id="status"><?=gettext("Beginning firmware upgrade"); ?>.</textarea>
123
									<br />
124
									<!-- command output box -->
125
									<textarea cols="90" rows="25" name="output" id="output"></textarea>
126
								</td>
127
							</tr>
128
						</table>
129
					</td>
130
				</tr>
131
			</table>
132
		</td>
133
	</tr>
134
</table>
135
</form>
136

    
137
<?php include("fend.inc"); ?>
138

    
139
<?php
140

    
141
update_status(gettext("Downloading current version information") . "...");
142
$nanosize = "";
143
if ($g['platform'] == "nanobsd") {
144
	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
}
151

    
152
@unlink("/tmp/{$g['product_name']}_version");
153
download_file_with_progress_bar("{$updater_url}/version{$nanosize}", "/tmp/{$g['product_name']}_version");
154
$latest_version = str_replace("\n", "", @file_get_contents("/tmp/{$g['product_name']}_version"));
155
if(!$latest_version) {
156
	update_output_window(gettext("Unable to check for updates."));
157
	require("fend.inc");
158
	exit;
159
} else {
160
	$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
	$latest_version_pfsense = strtotime($latest_version);
164
	if(!$latest_version) {
165
		update_output_window(gettext("Unable to check for updates."));
166
		require("fend.inc");
167
		exit;
168
	} else {
169
		if (pfs_version_compare($current_installed_buildtime, $current_installed_version, $latest_version) == -1) {
170
			update_status(gettext("Downloading updates") . "...");
171
			conf_mount_rw();
172
			if ($g['platform'] == "nanobsd") {
173
				$update_filename = "latest{$nanosize}.img.gz";
174
			} else {
175
				$update_filename = "latest.tgz";
176
			}
177
			$status = download_file_with_progress_bar("{$updater_url}/{$update_filename}", "{$g['upload_path']}/latest.tgz", "read_body_firmware");
178
			$status = download_file_with_progress_bar("{$updater_url}/{$update_filename}.sha256", "{$g['upload_path']}/latest.tgz.sha256");
179
			conf_mount_ro();
180
			update_output_window("{$g['product_name']} " . gettext("download complete."));
181
		} else {
182
			update_output_window(gettext("You are on the latest version."));
183
			require("fend.inc");
184
			exit;
185
		}
186
	}
187
}
188

    
189
/* launch external upgrade helper */
190
$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
$external_upgrade_helper_text .= "{$g['upload_path']}/latest.tgz";
198

    
199
$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

    
202
$sigchk = 0;
203

    
204
if(!isset($curcfg['alturl']['enable']))
205
	$sigchk = verify_digital_signature("{$g['upload_path']}/latest.tgz");
206

    
207
$exitstatus = 0;
208
if ($sigchk == 1) {
209
	$sig_warning = gettext("The digital signature on this image is invalid.");
210
	$exitstatus = 1;
211
} else if ($sigchk == 2) {
212
	$sig_warning = gettext("This image is not digitally signed.");
213
	if (!isset($config['system']['firmware']['allowinvalidsig']))
214
		$exitstatus = 1;
215
} else if (($sigchk >= 3)) {
216
	$sig_warning = gettext("There has been an error verifying the signature on this image.");
217
	$exitstatus = 1;
218
}
219

    
220
if ($exitstatus) {
221
	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
} else if ($sigchk == 2) {
226
	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
}
229

    
230
if (!verify_gzip_file("{$g['upload_path']}/latest.tgz")) {
231
	update_status(gettext("The image file is corrupt."));
232
	update_output_window(gettext("Update cannot continue"));
233
	if (file_exists("{$g['upload_path']}/latest.tgz")) {
234
		conf_mount_rw();
235
		unlink("{$g['upload_path']}/latest.tgz");
236
		conf_mount_ro();
237
	}
238
	require("fend.inc");
239
	exit;
240
}
241

    
242
if($downloaded_latest_tgz_sha256 <> $upgrade_latest_tgz_sha256) {
243
	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
} else {
246
	update_output_window($g['product_name'] . " " . gettext("is now upgrading.") . "\\n\\n" . gettext("The firewall will reboot once the operation is completed."));
247
	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
	mwexec_bg($external_upgrade_helper_text);
253
}
254

    
255
/*
256
	Helper functions
257
*/
258

    
259
function read_body_firmware($ch, $string) {
260
	global $fout, $file_size, $downloaded, $counter, $version, $latest_version, $current_installed_version;
261
	$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
	$text  = "  " . gettext("Auto Update Download Status") . "\\n";
269
	$text .= "----------------------------------------------------\\n";
270
	$text .= "  " . gettext("Current Version") . " : {$current_installed_version}\\n";
271
	$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
	$text .= "----------------------------------------------------\\n";
276
	$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
}
285

    
286
?>
287

    
288
</body>
289
</html>
(216-216/256)