Project

General

Profile

Download (9.96 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 da55e467 Scott Ullrich
        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
if($_POST['backupbeforeupgrade']) 
58
	touch("/tmp/perform_full_backup.txt");
59 ef794b01 Scott Ullrich
	
60 499fea07 Carlos Eduardo Ramos
$pgtitle = array(gettext("Diagnostics"),gettext("Firmware"),gettext("Auto Update"));
61 52380979 Scott Ullrich
include("head.inc");
62
63 25682561 Scott Ullrich
?>
64
65 da55e467 Scott Ullrich
<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 25682561 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
70 da55e467 Scott Ullrich
71 25682561 Scott Ullrich
<?php include("fbegin.inc"); ?>
72
73
<form action="system_firmware_auto.php" method="post">
74 da55e467 Scott Ullrich
<table width="100%" border="0" cellpadding="6" cellspacing="0">
75
	<tr>
76
		<td>
77 4820d297 Scott Ullrich
<?php
78
	$tab_array = array();
79 3ff39566 Scott Ullrich
	$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 4820d297 Scott Ullrich
	display_top_tabs($tab_array);
85
?>
86 da55e467 Scott Ullrich
		</td>
87
	</tr>
88 25682561 Scott Ullrich
	<tr>
89 da55e467 Scott Ullrich
	  <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 4944d592 Scott Ullrich
						<textarea cols="90" rows="1" name="status" id="status" wrap="hard"><?=gettext("Beginning firmware upgrade"); ?>.</textarea>
116 da55e467 Scott Ullrich
						<!-- command output box -->
117 4944d592 Scott Ullrich
						<textarea cols="90" rows="25" name="output" id="output" wrap="hard"></textarea>
118 da55e467 Scott Ullrich
					</center>
119
					</td>
120
				</tr>
121 25682561 Scott Ullrich
	      </table>
122 da55e467 Scott Ullrich
		</table>
123 25682561 Scott Ullrich
	  </td>
124
	</tr>
125 1c0e3b99 Scott Ullrich
</table>
126 25682561 Scott Ullrich
</form>
127
<?php include("fend.inc"); ?>
128
</body>
129
</html>
130
131
<?php
132
133 89f0ac4c Renato Botelho
update_status(gettext("Downloading current version information") . "...");
134 414053da jim-p
$nanosize = "";
135
if ($g['platform'] == "nanobsd") {
136 0d7715eb Renato Botelho
	if (file_exists("/etc/nano_use_vga.txt"))
137
		$nanosize = "-nanobsd-vga-";
138
	else
139
		$nanosize = "-nanobsd-";
140
141
	$nanosize .= strtolower(trim(file_get_contents("/etc/nanosize.txt")));
142 414053da jim-p
}
143
144 bd2b98c9 Ermal
@unlink("/tmp/{$g['product_name']}_version");
145 414053da jim-p
download_file_with_progress_bar("{$updater_url}/version{$nanosize}", "/tmp/{$g['product_name']}_version");
146 773c99bc Ermal
$latest_version = str_replace("\n", "", @file_get_contents("/tmp/{$g['product_name']}_version"));
147
if(!$latest_version) {
148 89f0ac4c Renato Botelho
	update_output_window(gettext("Unable to check for updates."));
149 773c99bc Ermal
	require("fend.inc");
150
	exit;
151
} else {
152 4e6593de jim-p
	$current_installed_buildtime = trim(file_get_contents("/etc/version.buildtime"));
153
	$current_installed_version = trim(file_get_contents("/etc/version"));
154
	$latest_version = trim(@file_get_contents("/tmp/{$g['product_name']}_version"));
155 773c99bc Ermal
	$latest_version_pfsense = strtotime($latest_version);
156
	if(!$latest_version) {
157 89f0ac4c Renato Botelho
		update_output_window(gettext("Unable to check for updates."));
158 773c99bc Ermal
		require("fend.inc");
159
		exit;
160
	} else {
161 4e6593de jim-p
		if (pfs_version_compare($current_installed_buildtime, $current_installed_version, $latest_version) == -1) {
162 89f0ac4c Renato Botelho
			update_status(gettext("Downloading updates") . "...");
163 773c99bc Ermal
			conf_mount_rw();
164 087d875c jim-p
			if ($g['platform'] == "nanobsd") {
165
				$update_filename = "latest{$nanosize}.img.gz";
166
			} else {
167
				$update_filename = "latest.tgz";
168
			}
169
			$status = download_file_with_progress_bar("{$updater_url}/{$update_filename}", "{$g['upload_path']}/latest.tgz", "read_body_firmware");	
170
			$status = download_file_with_progress_bar("{$updater_url}/{$update_filename}.sha256", "{$g['upload_path']}/latest.tgz.sha256");
171 773c99bc Ermal
			conf_mount_ro();
172 b7596b80 Carlos Eduardo Ramos
			update_output_window("{$g['product_name']} " . gettext("download complete."));
173 773c99bc Ermal
		} else {
174 89f0ac4c Renato Botelho
			update_output_window(gettext("You are on the latest version."));
175 773c99bc Ermal
			require("fend.inc");
176
			exit;
177
		}
178
	}
179 da55e467 Scott Ullrich
}
180
181
/* launch external upgrade helper */
182 61ffe8b8 Renato Botelho
$external_upgrade_helper_text = "/etc/rc.firmware ";
183
184
if($g['platform'] == "nanobsd")
185
	$external_upgrade_helper_text .= "pfSenseNanoBSDupgrade ";
186
else
187
	$external_upgrade_helper_text .= "pfSenseupgrade ";
188
189 4e6593de jim-p
$external_upgrade_helper_text .= "{$g['upload_path']}/latest.tgz";
190 da55e467 Scott Ullrich
191 1d333258 Scott Ullrich
$downloaded_latest_tgz_sha256 = str_replace("\n", "", `/sbin/sha256 -q {$g['upload_path']}/latest.tgz`);
192
$upgrade_latest_tgz_sha256 = str_replace("\n", "", `/bin/cat {$g['upload_path']}/latest.tgz.sha256 | awk '{ print $4 }'`);
193 da55e467 Scott Ullrich
194 563f5b51 Scott Ullrich
$sigchk = 0;
195
196
if(!isset($curcfg['alturl']['enable']))
197 0ba45a79 Renato Botelho
	$sigchk = verify_digital_signature("{$g['upload_path']}/latest.tgz");
198 563f5b51 Scott Ullrich
199 4b798102 Ermal
$exitstatus = 0;
200
if ($sigchk == 1) {
201 89f0ac4c Renato Botelho
	$sig_warning = gettext("The digital signature on this image is invalid.");
202 4b798102 Ermal
	$exitstatus = 1;
203
} else if ($sigchk == 2) {
204 89f0ac4c Renato Botelho
	$sig_warning = gettext("This image is not digitally signed.");
205 4b798102 Ermal
	if (!isset($config['system']['firmware']['allowinvalidsig']))
206
		$exitstatus = 1;
207
} else if (($sigchk >= 3)) {
208 89f0ac4c Renato Botelho
	$sig_warning = gettext("There has been an error verifying the signature on this image.");
209 4b798102 Ermal
	$exitstatus = 1;
210
}
211
212
if ($exitstatus) {
213
        update_status($sig_warning);
214 bdf790aa Scott Ullrich
        update_output_window(gettext("Update cannot continue.  You can disable this check on the Updater Settings tab."));
215 2646434b Scott Ullrich
		require("fend.inc");
216 a0116247 Ermal
        exit;
217 2646434b Scott Ullrich
} else if ($sigchk == 2) {
218
        update_status("Upgrade in progress...");
219 bdf790aa Scott Ullrich
        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");
220 2646434b Scott Ullrich
}
221 563f5b51 Scott Ullrich
222 0ba45a79 Renato Botelho
if (!verify_gzip_file("{$g['upload_path']}/latest.tgz")) {
223 89f0ac4c Renato Botelho
	update_status(gettext("The image file is corrupt."));
224
	update_output_window(gettext("Update cannot continue"));
225 0ba45a79 Renato Botelho
	if (file_exists("{$g['upload_path']}/latest.tgz")) {
226
		conf_mount_rw();
227 7dde365c Renato Botelho
		unlink("{$g['upload_path']}/latest.tgz");
228 0ba45a79 Renato Botelho
		conf_mount_ro();
229
	}
230 563f5b51 Scott Ullrich
	require("fend.inc");
231
	exit;
232
}
233
234 da55e467 Scott Ullrich
if($downloaded_latest_tgz_sha256 <> $upgrade_latest_tgz_sha256) {
235 89f0ac4c Renato Botelho
	update_status(gettext("Downloading complete but sha256 does not match."));
236
	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);
237 d40b3c36 Colin Smith
} else {
238 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."));
239 da55e467 Scott Ullrich
	echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
240 ecae7e91 sullrich
	mwexec_bg("/usr/bin/nohup {$external_upgrade_helper_text}");
241 d40b3c36 Colin Smith
}
242 cdb0117c Scott Ullrich
243 da55e467 Scott Ullrich
/*
244
	Helper functions
245
*/
246 d40b3c36 Colin Smith
247 9140757d Bill Marquette
function read_body_firmware($ch, $string) {
248 4e6593de jim-p
	global $fout, $file_size, $downloaded, $counter, $version, $latest_version, $current_installed_version;
249 da55e467 Scott Ullrich
	$length = strlen($string);
250
	$downloaded += intval($length);
251
	$downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
252
	$downloadProgress = 100 - $downloadProgress;
253
	$a = $file_size;
254
	$b = $downloaded;
255
	$c = $downloadProgress;
256 89f0ac4c Renato Botelho
	$text  = "  " . gettext("Auto Update Download Status") . "\\n";
257 5924fa0f Scott Ullrich
	$text .= "----------------------------------------------------\\n";
258 4e6593de jim-p
	$text .= "  " . gettext("Current Version") . " : {$current_installed_version}\\n";
259 89f0ac4c Renato Botelho
	$text .= "  " . gettext("Latest Version") . "  : {$latest_version}\\n";
260
	$text .= "  " . gettext("File size") . "       : {$a}\\n";
261
	$text .= "  " . gettext("Downloaded") . "      : {$b}\\n";
262
	$text .= "  " . gettext("Percent") . "         : {$c}%\\n";
263 5924fa0f Scott Ullrich
	$text .= "----------------------------------------------------\\n";
264 da55e467 Scott Ullrich
	$counter++;
265
	if($counter > 150) {
266
		update_output_window($text);
267
		update_progress_bar($downloadProgress);
268
		$counter = 0;
269
	}
270
	fwrite($fout, $string);
271
	return $length;
272 ebe916cf Colin Smith
}
273 853167d2 Colin Smith
274 773c99bc Ermal
?>