Project

General

Profile

Download (9.75 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
$pgtitle = array(gettext("Diagnostics"),gettext("Firmware"),gettext("Auto Update"));
58
include("head.inc");
59

    
60
?>
61

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

    
66
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
67

    
68
<?php include("fbegin.inc"); ?>
69

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

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

    
126
<?php
127

    
128
update_status(gettext("Downloading current version information") . "...");
129
$nanosize = "";
130
if ($g['platform'] == "nanobsd") {
131
	if (file_exists("/etc/nano_use_vga.txt"))
132
		$nanosize = "-nanobsd-vga-";
133
	else
134
		$nanosize = "-nanobsd-";
135

    
136
	$nanosize .= strtolower(trim(file_get_contents("/etc/nanosize.txt")));
137
}
138

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

    
176
/* launch external upgrade helper */
177
$external_upgrade_helper_text = "/etc/rc.firmware ";
178

    
179
if($g['platform'] == "nanobsd")
180
	$external_upgrade_helper_text .= "pfSenseNanoBSDupgrade ";
181
else
182
	$external_upgrade_helper_text .= "pfSenseupgrade ";
183

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

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

    
189
$sigchk = 0;
190

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

    
194
$exitstatus = 0;
195
if ($sigchk == 1) {
196
	$sig_warning = gettext("The digital signature on this image is invalid.");
197
	$exitstatus = 1;
198
} else if ($sigchk == 2) {
199
	$sig_warning = gettext("This image is not digitally signed.");
200
	if (!isset($config['system']['firmware']['allowinvalidsig']))
201
		$exitstatus = 1;
202
} else if (($sigchk >= 3)) {
203
	$sig_warning = gettext("There has been an error verifying the signature on this image.");
204
	$exitstatus = 1;
205
}
206

    
207
if ($exitstatus) {
208
        update_status($sig_warning);
209
        update_output_window(gettext("Update cannot continue.  You can disable this check on the Updater Settings tab."));
210
		require("fend.inc");
211
        exit;
212
} else if ($sigchk == 2) {
213
        update_status("Upgrade in progress...");
214
        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");
215
}
216

    
217
if (!verify_gzip_file("{$g['upload_path']}/latest.tgz")) {
218
	update_status(gettext("The image file is corrupt."));
219
	update_output_window(gettext("Update cannot continue"));
220
	if (file_exists("{$g['upload_path']}/latest.tgz")) {
221
		conf_mount_rw();
222
		unlink("{$g['upload_path']}/latest.tgz");
223
		conf_mount_ro();
224
	}
225
	require("fend.inc");
226
	exit;
227
}
228

    
229
if($downloaded_latest_tgz_sha256 <> $upgrade_latest_tgz_sha256) {
230
	update_status(gettext("Downloading complete but sha256 does not match."));
231
	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);
232
} else {
233
	update_output_window($g['product_name'] . " " . gettext("is now upgrading.") . "\\n\\n" . gettext("The firewall will reboot once the operation is completed."));
234
	echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
235
	mwexec_bg("/usr/bin/nohup {$external_upgrade_helper_text}");
236
}
237

    
238
/*
239
	Helper functions
240
*/
241

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

    
269
?>
(187-187/224)