Project

General

Profile

Download (9.44 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
require("guiconfig.inc");
46
require_once("pfsense-utils.inc");
47

    
48
$curcfg = $config['system']['firmware'];
49

    
50
if(isset($curcfg['alturl']['enable']))
51
	$updater_url = "{$config['system']['firmware']['alturl']['firmwareurl']}";
52
else
53
	$updater_url = $g['update_url'];
54
	
55
$pgtitle = array(gettext("Diagnostics"),gettext("Firmware"),gettext("Auto Update"));
56
include("head.inc");
57

    
58
?>
59

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

    
64
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
65

    
66
<?php include("fbegin.inc"); ?>
67

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

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

    
124
<?php
125

    
126
update_status(gettext("Downloading current version information") . "...");
127
$nanosize = "";
128
if ($g['platform'] == "nanobsd") {
129
	$nanosize = "-nanobsd-" . strtolower(trim(file_get_contents("/etc/nanosize.txt")));
130
}
131

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

    
168
/* launch external upgrade helper */
169
$external_upgrade_helper_text = "/etc/rc.firmware ";
170

    
171
if($g['platform'] == "nanobsd")
172
	$external_upgrade_helper_text .= "pfSenseNanoBSDupgrade ";
173
else
174
	$external_upgrade_helper_text .= "pfSenseupgrade ";
175

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

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

    
181
$sigchk = 0;
182

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

    
186
$exitstatus = 0;
187
if ($sigchk == 1) {
188
	$sig_warning = gettext("The digital signature on this image is invalid.");
189
	$exitstatus = 1;
190
} else if ($sigchk == 2) {
191
	$sig_warning = gettext("This image is not digitally signed.");
192
	if (!isset($config['system']['firmware']['allowinvalidsig']))
193
		$exitstatus = 1;
194
} else if (($sigchk >= 3)) {
195
	$sig_warning = gettext("There has been an error verifying the signature on this image.");
196
	$exitstatus = 1;
197
}
198

    
199
if ($exitstatus) {
200
        update_status($sig_warning);
201
        update_output_window(gettext("Update cannot continue"));
202
	require("fend.inc");
203
        exit;
204
} else if ($sigchk == 2)
205
        update_output_window("\n" . gettext("Image has no signature but the system configured to allow unsigned images.") . "\n");
206

    
207
if (!verify_gzip_file("{$g['upload_path']}/latest.tgz")) {
208
	update_status(gettext("The image file is corrupt."));
209
	update_output_window(gettext("Update cannot continue"));
210
	if (file_exists("{$g['upload_path']}/latest.tgz")) {
211
		conf_mount_rw();
212
		unlink("{$g['upload_path']}/latest.tgz");
213
		conf_mount_ro();
214
	}
215
	require("fend.inc");
216
	exit;
217
}
218

    
219
if($downloaded_latest_tgz_sha256 <> $upgrade_latest_tgz_sha256) {
220
	update_status(gettext("Downloading complete but sha256 does not match."));
221
	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);
222
} else {
223
	update_output_window($g['product_name'] . " " . gettext("is now upgrading.") . "\\n\\n" . gettext("The firewall will reboot once the operation is completed."));
224
	echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
225
	mwexec_bg("/usr/bin/nohup {$external_upgrade_helper_text}");
226
}
227

    
228
/*
229
	Helper functions
230
*/
231

    
232
function read_body_firmware($ch, $string) {
233
	global $fout, $file_size, $downloaded, $counter, $version, $latest_version, $current_installed_version;
234
	$length = strlen($string);
235
	$downloaded += intval($length);
236
	$downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
237
	$downloadProgress = 100 - $downloadProgress;
238
	$a = $file_size;
239
	$b = $downloaded;
240
	$c = $downloadProgress;
241
	$text  = "  " . gettext("Auto Update Download Status") . "\\n";
242
	$text .= "----------------------------------------------------\\n";
243
	$text .= "  " . gettext("Current Version") . " : {$current_installed_version}\\n";
244
	$text .= "  " . gettext("Latest Version") . "  : {$latest_version}\\n";
245
	$text .= "  " . gettext("File size") . "       : {$a}\\n";
246
	$text .= "  " . gettext("Downloaded") . "      : {$b}\\n";
247
	$text .= "  " . gettext("Percent") . "         : {$c}%\\n";
248
	$text .= "----------------------------------------------------\\n";
249
	$counter++;
250
	if($counter > 150) {
251
		update_output_window($text);
252
		update_progress_bar($downloadProgress);
253
		$counter = 0;
254
	}
255
	fwrite($fout, $string);
256
	return $length;
257
}
258

    
259
?>
(182-182/221)