Project

General

Profile

Download (9.98 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_firmware_auto.php
5
	Copyright (C) 2008 Scott Ullrich <sullrich@gmail.com>
6
	Copyright (C) 2005 Scott Ullrich
7

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

    
38
##|+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
$nocsrf = true;
46

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

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

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

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

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

    
63
?>
64

    
65
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
66
<link href="gui.css" rel="stylesheet" type="text/css">
67
</head>
68

    
69
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
70

    
71
<?php include("fbegin.inc"); ?>
72

    
73
<form action="system_firmware_auto.php" method="post">
74
<table width="100%" border="0" cellpadding="6" cellspacing="0">
75
	<tr>
76
		<td>
77
		<?php
78
			$tab_array = array();
79
			$tab_array[] = array(gettext("Manual Update"), false, "system_firmware.php");
80
			$tab_array[] = array(gettext("Auto Update"), true, "system_firmware_check.php");
81
			$tab_array[] = array(gettext("Updater Settings"), false, "system_firmware_settings.php");
82
			if($g['hidedownloadbackup'] == false)
83
				$tab_array[] = array(gettext("Restore Full Backup"), false, "system_firmware_restorefullbackup.php");
84
			display_top_tabs($tab_array);
85
		?>
86
		</td>
87
	</tr>
88
	<tr>
89
		<td class="tabcont">
90
			<table width="100%" border="0" cellpadding="6" cellspacing="0">
91
				<tr>
92
					<td class="tabcont">
93
						<table width="100%" border="0" cellpadding="6" cellspacing="0">
94
							<tr>
95
								<td>
96
									<center>
97
									<table height='15' width='420' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
98

    
99
										<tr>
100
											<td background="./themes/the_wall/images/misc/bar_left.gif" height='15' width='5'>
101
											</td>
102
											<td>
103
											<table id="progholder" name="progholder" height='15' width='410' border='0' colspacing='0' cellpadding='0' cellspacing='0'>
104
												<td background="./themes/the_wall/images/misc/bar_gray.gif" valign="top" align="left">
105
												<img src='./themes/the_wall/images/misc/bar_blue.gif' width='0' height='15' name='progressbar' id='progressbar'>
106
												</td>
107
											</table>
108
											</td>
109
											<td background="./themes/the_wall/images/misc/bar_right.gif" height='15' width='5'>
110
											</td>
111
										</tr>
112
									</table>
113
									<br>
114
									<!-- status box -->
115
									<textarea cols="90" rows="1" name="status" id="status" wrap="hard"><?=gettext("Beginning firmware upgrade"); ?>.</textarea>
116
									<!-- command output box -->
117
									<textarea cols="90" rows="25" name="output" id="output" wrap="hard"></textarea>
118
									</center>
119
								</td>
120
							</tr>
121
						</table>
122
					</td>
123
				</tr>
124
			</table>
125
		</td>
126
	</tr>
127
</table>
128
</form>
129
<?php include("fend.inc"); ?>
130
</body>
131
</html>
132

    
133
<?php
134

    
135
update_status(gettext("Downloading current version information") . "...");
136
$nanosize = "";
137
if ($g['platform'] == "nanobsd") {
138
	if (file_exists("/etc/nano_use_vga.txt"))
139
		$nanosize = "-nanobsd-vga-";
140
	else
141
		$nanosize = "-nanobsd-";
142

    
143
	$nanosize .= strtolower(trim(file_get_contents("/etc/nanosize.txt")));
144
}
145

    
146
@unlink("/tmp/{$g['product_name']}_version");
147
download_file_with_progress_bar("{$updater_url}/version{$nanosize}", "/tmp/{$g['product_name']}_version");
148
$latest_version = str_replace("\n", "", @file_get_contents("/tmp/{$g['product_name']}_version"));
149
if(!$latest_version) {
150
	update_output_window(gettext("Unable to check for updates."));
151
	require("fend.inc");
152
	exit;
153
} else {
154
	$current_installed_buildtime = trim(file_get_contents("/etc/version.buildtime"));
155
	$current_installed_version = trim(file_get_contents("/etc/version"));
156
	$latest_version = trim(@file_get_contents("/tmp/{$g['product_name']}_version"));
157
	$latest_version_pfsense = strtotime($latest_version);
158
	if(!$latest_version) {
159
		update_output_window(gettext("Unable to check for updates."));
160
		require("fend.inc");
161
		exit;
162
	} else {
163
		if (pfs_version_compare($current_installed_buildtime, $current_installed_version, $latest_version) == -1) {
164
			update_status(gettext("Downloading updates") . "...");
165
			conf_mount_rw();
166
			if ($g['platform'] == "nanobsd") {
167
				$update_filename = "latest{$nanosize}.img.gz";
168
			} else {
169
				$update_filename = "latest.tgz";
170
			}
171
			$status = download_file_with_progress_bar("{$updater_url}/{$update_filename}", "{$g['upload_path']}/latest.tgz", "read_body_firmware");
172
			$status = download_file_with_progress_bar("{$updater_url}/{$update_filename}.sha256", "{$g['upload_path']}/latest.tgz.sha256");
173
			conf_mount_ro();
174
			update_output_window("{$g['product_name']} " . gettext("download complete."));
175
		} else {
176
			update_output_window(gettext("You are on the latest version."));
177
			require("fend.inc");
178
			exit;
179
		}
180
	}
181
}
182

    
183
/* launch external upgrade helper */
184
$external_upgrade_helper_text = "/etc/rc.firmware ";
185

    
186
if($g['platform'] == "nanobsd")
187
	$external_upgrade_helper_text .= "pfSenseNanoBSDupgrade ";
188
else
189
	$external_upgrade_helper_text .= "pfSenseupgrade ";
190

    
191
$external_upgrade_helper_text .= "{$g['upload_path']}/latest.tgz";
192

    
193
$downloaded_latest_tgz_sha256 = str_replace("\n", "", `/sbin/sha256 -q {$g['upload_path']}/latest.tgz`);
194
$upgrade_latest_tgz_sha256 = str_replace("\n", "", `/bin/cat {$g['upload_path']}/latest.tgz.sha256 | awk '{ print $4 }'`);
195

    
196
$sigchk = 0;
197

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

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

    
214
if ($exitstatus) {
215
	update_status($sig_warning);
216
	update_output_window(gettext("Update cannot continue.  You can disable this check on the Updater Settings tab."));
217
	require("fend.inc");
218
	exit;
219
} else if ($sigchk == 2) {
220
	update_status("Upgrade in progress...");
221
	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");
222
}
223

    
224
if (!verify_gzip_file("{$g['upload_path']}/latest.tgz")) {
225
	update_status(gettext("The image file is corrupt."));
226
	update_output_window(gettext("Update cannot continue"));
227
	if (file_exists("{$g['upload_path']}/latest.tgz")) {
228
		conf_mount_rw();
229
		unlink("{$g['upload_path']}/latest.tgz");
230
		conf_mount_ro();
231
	}
232
	require("fend.inc");
233
	exit;
234
}
235

    
236
if($downloaded_latest_tgz_sha256 <> $upgrade_latest_tgz_sha256) {
237
	update_status(gettext("Downloading complete but sha256 does not match."));
238
	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);
239
} else {
240
	update_output_window($g['product_name'] . " " . gettext("is now upgrading.") . "\\n\\n" . gettext("The firewall will reboot once the operation is completed."));
241
	echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
242
	mwexec_bg($external_upgrade_helper_text);
243
}
244

    
245
/*
246
	Helper functions
247
*/
248

    
249
function read_body_firmware($ch, $string) {
250
	global $fout, $file_size, $downloaded, $counter, $version, $latest_version, $current_installed_version;
251
	$length = strlen($string);
252
	$downloaded += intval($length);
253
	$downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
254
	$downloadProgress = 100 - $downloadProgress;
255
	$a = $file_size;
256
	$b = $downloaded;
257
	$c = $downloadProgress;
258
	$text  = "  " . gettext("Auto Update Download Status") . "\\n";
259
	$text .= "----------------------------------------------------\\n";
260
	$text .= "  " . gettext("Current Version") . " : {$current_installed_version}\\n";
261
	$text .= "  " . gettext("Latest Version") . "  : {$latest_version}\\n";
262
	$text .= "  " . gettext("File size") . "       : {$a}\\n";
263
	$text .= "  " . gettext("Downloaded") . "      : {$b}\\n";
264
	$text .= "  " . gettext("Percent") . "         : {$c}%\\n";
265
	$text .= "----------------------------------------------------\\n";
266
	$counter++;
267
	if($counter > 150) {
268
		update_output_window($text);
269
		update_progress_bar($downloadProgress);
270
		$counter = 0;
271
	}
272
	fwrite($fout, $string);
273
	return $length;
274
}
275

    
276
?>
(207-207/246)