Projet

Général

Profil

Télécharger (10,5 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / system_firmware_auto.php @ e3e1f748

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
$closehead = false;
61
$pgtitle = array(gettext("Diagnostics"),gettext("Firmware"),gettext("Auto Update"));
62
include("head.inc");
63

    
64
?>
65

    
66
<meta http-equiv="Content-Type" content="text/html; charset=<?=system_get_language_codeset();?>" />
67
<link href="gui.css" rel="stylesheet" type="text/css" />
68
</head>
69

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

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

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

    
99
										<tr>
100
											<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_left.gif')" height="15" width="5">	</td>
101
											<td>
102
											<table id="progholder" style="height:15;colspacing:0" width="410" border="0" cellpadding="0" cellspacing="0" summary="">
103
												<tr><td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_gray.gif')" valign="top" align="left">
104
												<img src="./themes/<?=$g['theme'];?>/images/misc/bar_blue.gif" width="0" height="15" name="progressbar" id="progressbar" alt="" />
105
												</td></tr>
106
											</table>
107
											</td>
108
											<td style="background:url('./themes/<?=$g['theme'];?>/images/misc/bar_right.gif')" height="15" width="5"></td>
109
										</tr>
110
									</table>
111
									<br />
112
									<script type="text/javascript">
113
									//<![CDATA[
114
									window.onload=function(){
115
										document.getElementById("status").wrap='hard';
116
										document.getElementById("output").wrap='hard';
117
									}
118
									//]]>
119
									</script>
120
									<!-- status box -->
121
									<textarea cols="90" rows="1" name="status" id="status"><?=gettext("Beginning firmware upgrade"); ?>.</textarea>
122
									<br />
123
									<!-- command output box -->
124
									<textarea cols="90" rows="25" name="output" id="output"></textarea>
125
								</td>
126
							</tr>
127
						</table>
128
					</td>
129
				</tr>
130
			</table>
131
		</td>
132
	</tr>
133
</table>
134
</form>
135

    
136
<?php include("fend.inc"); ?>
137

    
138
<?php
139

    
140
update_status(gettext("Downloading current version information") . "...");
141
$nanosize = "";
142
if ($g['platform'] == "nanobsd") {
143
	if (file_exists("/etc/nano_use_vga.txt"))
144
		$nanosize = "-nanobsd-vga-";
145
	else
146
		$nanosize = "-nanobsd-";
147

    
148
	$nanosize .= strtolower(trim(file_get_contents("/etc/nanosize.txt")));
149
}
150

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

    
188
/* launch external upgrade helper */
189
$external_upgrade_helper_text = "/etc/rc.firmware ";
190

    
191
if($g['platform'] == "nanobsd")
192
	$external_upgrade_helper_text .= "pfSenseNanoBSDupgrade ";
193
else
194
	$external_upgrade_helper_text .= "pfSenseupgrade ";
195

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

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

    
201
$sigchk = 0;
202

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

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

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

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

    
241
if($downloaded_latest_tgz_sha256 <> $upgrade_latest_tgz_sha256) {
242
	update_status(gettext("Downloading complete but sha256 does not match."));
243
	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);
244
} else {
245
	update_output_window($g['product_name'] . " " . gettext("is now upgrading.") . "\\n\\n" . gettext("The firewall will reboot once the operation is completed."));
246
	echo "\n<script type=\"text/javascript\">";
247
	echo "\n//<![CDATA[";
248
	echo "\ndocument.progressbar.style.visibility='hidden';";
249
	echo "\n//]]>";
250
	echo "\n</script>";
251
	mwexec_bg($external_upgrade_helper_text);
252
}
253

    
254
/*
255
	Helper functions
256
*/
257

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

    
285
?>
286

    
287
</body>
288
</html>
(216-216/256)