Project

General

Profile

Download (9.17 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

    
59
if ($_POST['backupbeforeupgrade']) {
60
	touch("/tmp/perform_full_backup.txt");
61
}
62

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

    
67
$tab_array = array();
68
$tab_array[] = array(gettext("Manual Update"), false, "system_firmware.php");
69
$tab_array[] = array(gettext("Auto Update"), true, "system_firmware_check.php");
70
$tab_array[] = array(gettext("Updater Settings"), false, "system_firmware_settings.php");
71
if($g['hidedownloadbackup'] == false)
72
	$tab_array[] = array(gettext("Restore Full Backup"), false, "system_firmware_restorefullbackup.php");
73

    
74
display_top_tabs($tab_array);
75
?>
76

    
77

    
78
<div id="statusheading" name="statusheading" class="panel panel-default">
79
   <div	 class="panel-heading" id="status" name="status"><?=gettext("Beginning firmware upgrade")?></div>
80
   <div id='output' name='output' class="panel-body"></div>
81
</div>
82

    
83

    
84
<?php
85
include("foot.inc"); ?>
86

    
87
<?php
88

    
89
panel_heading_text(gettext("Downloading current version information") . "...");
90
panel_heading_class('info');
91

    
92
$nanosize = "";
93
if ($g['platform'] == "nanobsd") {
94
	if (file_exists("/etc/nano_use_vga.txt")) {
95
		$nanosize = "-nanobsd-vga-";
96
	} else {
97
		$nanosize = "-nanobsd-";
98
	}
99

    
100
	$nanosize .= strtolower(trim(file_get_contents("/etc/nanosize.txt")));
101
}
102

    
103
@unlink("/tmp/{$g['product_name']}_version");
104
download_file_with_progress_bar("{$updater_url}/version{$nanosize}", "/tmp/{$g['product_name']}_version");
105
$latest_version = str_replace("\n", "", @file_get_contents("/tmp/{$g['product_name']}_version"));
106
if (!$latest_version) {
107
	update_output_window(gettext("Unable to check for updates."));
108
	require("foot.inc");
109
	exit;
110
} else {
111
	$current_installed_buildtime = trim(file_get_contents("/etc/version.buildtime"));
112
	$latest_version = trim(@file_get_contents("/tmp/{$g['product_name']}_version"));
113
	$latest_version_pfsense = strtotime($latest_version);
114
	if(!$latest_version) {
115
		panel_heading_class('danger');
116
		panel_heading_text(gettext('Version check'));
117
		update_output_window(gettext("Unable to check for updates."));
118
		require("foot.inc");
119
		exit;
120
	} else {
121
		if (pfs_version_compare($current_installed_buildtime, $current_installed_version, $latest_version) == -1) {
122
			panel_heading_text(gettext("Downloading updates") . '...');
123
			panel_heading_class('info');
124

    
125
			conf_mount_rw();
126
			if ($g['platform'] == "nanobsd") {
127
				$update_filename = "latest{$nanosize}.img.gz";
128
			} else {
129
				$update_filename = "latest.tgz";
130
			}
131

    
132
			$status = download_file_with_progress_bar("{$updater_url}/{$update_filename}", "{$g['upload_path']}/latest.tgz", "read_body_firmware");
133
			$status = download_file_with_progress_bar("{$updater_url}/{$update_filename}.sha256", "{$g['upload_path']}/latest.tgz.sha256");
134
			conf_mount_ro();
135
			update_output_window("{$g['product_name']} " . gettext("download complete."));
136
		} else {
137
			panel_heading_class('success');
138
			panel_heading_text(gettext('Version check complete'));
139
			update_output_window(gettext("You are on the latest version."));
140
			require("foot.inc");
141
			exit;
142
		}
143
	}
144
}
145

    
146
/* launch external upgrade helper */
147
$external_upgrade_helper_text = "/etc/rc.firmware ";
148

    
149
if ($g['platform'] == "nanobsd") {
150
	$external_upgrade_helper_text .= "pfSenseNanoBSDupgrade ";
151
} else {
152
	$external_upgrade_helper_text .= "pfSenseupgrade ";
153
}
154

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

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

    
160
$sigchk = 0;
161

    
162
if (!isset($curcfg['alturl']['enable'])) {
163
	$sigchk = verify_digital_signature("{$g['upload_path']}/latest.tgz");
164
}
165

    
166
$exitstatus = 0;
167
if ($sigchk == 1) {
168
	$sig_warning = gettext("The digital signature on this image is invalid.");
169
	$exitstatus = 1;
170
} else if ($sigchk == 2) {
171
	$sig_warning = gettext("This image is not digitally signed.");
172
	if (!isset($config['system']['firmware']['allowinvalidsig'])) {
173
		$exitstatus = 1;
174
	}
175
} else if (($sigchk >= 3)) {
176
	$sig_warning = gettext("There has been an error verifying the signature on this image.");
177
	$exitstatus = 1;
178
}
179

    
180
if ($exitstatus) {
181
	panel_heading_text($sig_warning);
182
	panel_heading_class('danger');
183

    
184
	update_output_window(gettext("Update cannot continue.  You can disable this check on the Updater Settings tab."));
185
	require("foot.inc");
186
	exit;
187
} else if ($sigchk == 2) {
188
	panel_heading_text(gettext('Upgrade in progress...'));
189
	panel_heading_class('info');
190

    
191
	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");
192
}
193

    
194
if (!verify_gzip_file("{$g['upload_path']}/latest.tgz")) {
195
	panel_heading_text(gettext("The image file is corrupt."));
196
	panel_heading_class('danger');
197

    
198
	update_output_window(gettext("Update cannot continue"));
199
	if (file_exists("{$g['upload_path']}/latest.tgz")) {
200
		conf_mount_rw();
201
		unlink("{$g['upload_path']}/latest.tgz");
202
		conf_mount_ro();
203
	}
204
	require("foot.inc");
205
	exit;
206
}
207

    
208
if($downloaded_latest_tgz_sha256 <> $upgrade_latest_tgz_sha256) {
209
	panel_heading_text(gettext("Downloading complete but sha256 does not match."));
210
	panel_heading_class('danger');
211

    
212
	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);
213
} else {
214
	update_output_window($g['product_name'] . " " . gettext("is now upgrading.") . "\\n\\n" . gettext("The firewall will reboot once the operation is completed."));
215
	mwexec_bg($external_upgrade_helper_text);
216
}
217

    
218
/*
219
	Helper functions
220
*/
221

    
222
function read_body_firmware($ch, $string) {
223
	global $g, $fout, $file_size, $downloaded, $counter, $version, $latest_version;
224
	$length = strlen($string);
225
	$downloaded += intval($length);
226
	$downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
227
	$downloadProgress = 100 - $downloadProgress;
228
	$a = $file_size;
229
	$b = $downloaded;
230
	$c = $downloadProgress;
231
	$text  = "	" . gettext("Auto Update Download Status") . "\\n";
232
	$text .= "----------------------------------------------------\\n";
233
	$text .= "  " . gettext("Current Version") . " : {$g['product_version']}\\n";
234
	$text .= "  " . gettext("Latest Version") . "  : {$latest_version}\\n";
235
	$text .= "  " . gettext("File size") . "       : {$a}\\n";
236
	$text .= "  " . gettext("Downloaded") . "      : {$b}\\n";
237
	$text .= "  " . gettext("Percent") . "         : {$c}%\\n";
238
	$text .= "----------------------------------------------------\\n";
239
	$counter++;
240
	if ($counter > 150) {
241
		update_output_window($text);
242
		update_progress_bar($downloadProgress);
243
		$counter = 0;
244
	}
245
	fwrite($fout, $string);
246
	return $length;
247
}
248

    
249
// Update the text in the panel-heading
250
function panel_heading_text($text) {
251
?>
252
	<script>
253
	events.push(function(){
254
		$('#status').html('<?=$text?>');
255
	});
256
	</script>
257
<?php
258
}
259

    
260
// Update the class of the message panel so that it's color changes
261
// Use danger, success, info, warning, default etc
262
function panel_heading_class($newclass = 'default') {
263
?>
264
	<script>
265
	events.push(function(){
266
		$('#statusheading').removeClass().addClass('panel panel-' + '<?=$newclass?>');
267
	});
268
	</script>
269
<?php
270
}
271

    
272
?>
273

    
(199-199/238)