Project

General

Profile

Download (7.95 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
##|+PRIV
35
##|*IDENT=page-system-firmware-checkforupdate
36
##|*NAME=System: Firmware: Check For Update page
37
##|*DESCR=Allow access to the 'System: Firmware: Check For Update' page.
38
##|*MATCH=system_firmware_auto.php*
39
##|-PRIV
40

    
41

    
42
require("guiconfig.inc");
43

    
44
$curcfg = $config['system']['firmware'];
45

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

    
54
?>
55

    
56
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
57
<link href="gui.css" rel="stylesheet" type="text/css">
58
</head>
59

    
60
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
61

    
62
<?php include("fbegin.inc"); ?>
63

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

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

    
120
<?php
121

    
122
update_status("Downloading current version information...");
123
$latest_version = download_file_with_progress_bar("{$updater_url}/version", "/tmp/{$g['product_name']}_version");
124

    
125
$current_installed_pfsense_version = str_replace("\n", "", file_get_contents("/etc/version"));
126
$latest_version = str_replace("\n", "", file_get_contents("/tmp/{$g['product_name']}_version"));
127

    
128
if($current_installed_pfsense_version <> $latest_version) 
129
	$needs_system_upgrade = true;
130

    
131
if($needs_system_upgrade == true) {
132
	update_status("Downloading updates ...");
133
	conf_mount_rw();
134
	$status = download_file_with_progress_bar("{$updater_url}/latest.tgz", "{$g['upload_path']}/latest.tgz", "read_body_firmware");	
135
	$status = download_file_with_progress_bar("{$updater_url}/latest.tgz.sha256", "{$g['upload_path']}/latest.tgz.sha256");
136
	conf_mount_ro();
137
	update_output_window("{$g['product_name']} download complete.");
138
}
139

    
140
/* launch external upgrade helper */
141
$external_upgrade_helper_text = "/etc/rc.firmware ";
142

    
143
if($g['platform'] == "nanobsd")
144
	$external_upgrade_helper_text .= "pfSenseNanoBSDupgrade ";
145
else
146
	$external_upgrade_helper_text .= "pfSenseupgrade ";
147

    
148
if($needs_system_upgrade == true)
149
	$external_upgrade_helper_text .= "{$g['upload_path']}/latest.tgz";
150

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

    
154
$sigchk = 0;
155

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

    
159
if ($sigchk == 1)
160
	$sig_warning = "The digital signature on this image is invalid.";
161
else if ($sigchk == 2)
162
	$sig_warning = "This image is not digitally signed.";
163
else if (($sigchk == 3) || ($sigchk == 4))
164
	$sig_warning = "There has been an error verifying the signature on this image.";
165

    
166
if (!verify_gzip_file("{$g['upload_path']}/latest.tgz")) {
167
	update_status("The image file is corrupt.");
168
	update_output_window("Update cannot continue");
169
	if (file_exists("{$g['upload_path']}/latest.tgz")) {
170
		conf_mount_rw();
171
		unlink("{$g['upload_path']}/latest.tgz");
172
		conf_mount_ro();
173
	}
174
	require("fend.inc");
175
	exit;
176
}
177

    
178
if ($sigchk) {
179
	update_status($sig_warning);
180
	update_output_window("Update cannot continue");
181
	if (file_exists("{$g['upload_path']}/latest.tgz")) {
182
		conf_mount_rw();
183
		unlink("{$g['upload_path']}/latest.tgz");
184
		conf_mount_ro();
185
	}
186
	require("fend.inc");
187
	exit;
188
}
189

    
190
if($downloaded_latest_tgz_sha256 <> $upgrade_latest_tgz_sha256) {
191
	update_status("Downloading complete but sha256 does not match.");
192
	update_output_window("Auto upgrade aborted.  \n\nDownloaded SHA256: $downloaded_latest_tgz_sha256 \n\nNeeded SHA256: $upgrade_latest_tgz_sha256");	
193
} else {
194
	update_output_window("{$g['product_name']} is now upgrading.\\n\\nThe firewall will reboot once the operation is completed.");
195
	echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
196
	mwexec("nohup {$external_upgrade_helper_text}");
197
}
198

    
199
/*
200
	Helper functions
201
*/
202

    
203
function read_body_firmware($ch, $string) {
204
	global $fout, $file_size, $downloaded, $counter, $version, $latest_version, $current_installed_pfsense_version;
205
	$length = strlen($string);
206
	$downloaded += intval($length);
207
	$downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
208
	$downloadProgress = 100 - $downloadProgress;
209
	$a = $file_size;
210
	$b = $downloaded;
211
	$c = $downloadProgress;
212
	$text  = "  Auto Update Download Status\\n";
213
	$text .= "----------------------------------------------------\\n";
214
	$text .= "  Latest Version  : {$latest_version}\\n";
215
	$text .= "  Current Version : {$current_installed_pfsense_version}\\n";
216
	$text .= "  File size       : {$a}\\n";
217
	$text .= "  Downloaded      : {$b}\\n";
218
	$text .= "  Percent         : {$c}%\\n";
219
	$text .= "----------------------------------------------------\\n";
220
	$counter++;
221
	if($counter > 150) {
222
		update_output_window($text);
223
		update_progress_bar($downloadProgress);
224
		$counter = 0;
225
	}
226
	fwrite($fout, $string);
227
	return $length;
228
}
229

    
230
?>
(179-179/217)