Project

General

Profile

Download (7.48 KB) Statistics
| Branch: | Tag: | Revision:
1 25682561 Scott Ullrich
<?php
2
/* $Id$ */
3
/*
4
	system_firmware_auto.php
5 1cecfbf7 Scott Ullrich
	Copyright (C) 2008 Scott Ullrich <sullrich@gmail.com>
6 da55e467 Scott Ullrich
	Copyright (C) 2005 Scott Ullrich
7 5c59c339 Scott Ullrich
8 da55e467 Scott Ullrich
        Based originally on system_firmware.php
9
        (C)2003-2004 Manuel Kasper
10 25682561 Scott Ullrich
	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 6b07c15a Matthew Grooms
##|+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 da55e467 Scott Ullrich
require("guiconfig.inc");
43
44
$curcfg = $config['system']['firmware'];
45 9b7d7aa9 Scott Ullrich
46 ef794b01 Scott Ullrich
if(isset($curcfg['alturl']['enable']))
47 da55e467 Scott Ullrich
	$updater_url = "{$config['system']['firmware']['alturl']['firmwareurl']}";
48 ef794b01 Scott Ullrich
else
49
	$updater_url = $g['update_url'];
50
	
51 da55e467 Scott Ullrich
$pgtitle = array("Diagnostics","Firmware","Auto Update");
52 52380979 Scott Ullrich
include("head.inc");
53
54 25682561 Scott Ullrich
?>
55
56 da55e467 Scott Ullrich
<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 25682561 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
61 da55e467 Scott Ullrich
62 25682561 Scott Ullrich
<?php include("fbegin.inc"); ?>
63
64
<form action="system_firmware_auto.php" method="post">
65 da55e467 Scott Ullrich
<table width="100%" border="0" cellpadding="6" cellspacing="0">
66
	<tr>
67
		<td>
68 4820d297 Scott Ullrich
<?php
69
	$tab_array = array();
70 9df75243 Scott Dale
	$tab_array[0] = array("Manual Update", false, "system_firmware.php");
71
	$tab_array[1] = array("Auto Update", true, "system_firmware_check.php");
72 4820d297 Scott Ullrich
	$tab_array[2] = array("Updater Settings", false, "system_firmware_settings.php");
73
	display_top_tabs($tab_array);
74
?>
75 da55e467 Scott Ullrich
		</td>
76
	</tr>
77 25682561 Scott Ullrich
	<tr>
78 da55e467 Scott Ullrich
	  <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 package installation.</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 25682561 Scott Ullrich
	      </table>
111 da55e467 Scott Ullrich
		</table>
112 25682561 Scott Ullrich
	  </td>
113
	</tr>
114 1c0e3b99 Scott Ullrich
</table>
115 25682561 Scott Ullrich
</form>
116
<?php include("fend.inc"); ?>
117
</body>
118
</html>
119
120
<?php
121
122 da55e467 Scott Ullrich
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 d40b3c36 Colin Smith
131 da55e467 Scott Ullrich
if($needs_system_upgrade == true) {
132
	update_status("Downloading updates ...");
133 9140757d Bill Marquette
	$status = download_file_with_progress_bar("{$updater_url}/latest.tgz", "/tmp/latest.tgz", "read_body_firmware");	
134 da55e467 Scott Ullrich
	$status = download_file_with_progress_bar("{$updater_url}/latest.tgz.sha256", "/tmp/latest.tgz.sha256");
135
	update_output_window("{$g['product_name']} download complete.");
136
}
137
138
/* launch external upgrade helper */
139
$external_upgrade_helper_text = "/etc/rc.firmware pfSenseupgrade ";
140
if($needs_system_upgrade == true)
141
	$external_upgrade_helper_text .= "/tmp/latest.tgz";
142
143
$downloaded_latest_tgz_sha256 = str_replace("\n", "", `sha256 /tmp/latest.tgz  | awk '{ print $4 }'`);
144
$upgrade_latest_tgz_sha256 = str_replace("\n", "", `cat /tmp/latest.tgz.sha256 | awk '{ print $4 }'`);
145
146 563f5b51 Scott Ullrich
$sigchk = 0;
147
148
if(!isset($curcfg['alturl']['enable']))
149
	$sigchk = verify_digital_signature("/tmp/latest.tgz");
150
151
if ($sigchk == 1)
152
	$sig_warning = "The digital signature on this image is invalid.";
153
else if ($sigchk == 2)
154
	$sig_warning = "This image is not digitally signed.";
155
else if (($sigchk == 3) || ($sigchk == 4))
156
	$sig_warning = "There has been an error verifying the signature on this image.";
157
158
if (!verify_gzip_file("/tmp/latest.tgz")) {
159
	update_status("The image file is corrupt.");
160
	update_output_window("Update cannot continue");
161
	unlink("{$g['upload_path']}/latest.tgz");
162
	require("fend.inc");
163
	exit;
164
}
165
166
if ($sigchk) {
167
	update_status($sig_warning);
168
	update_output_window("Update cannot continue");
169
	unlink("{$g['upload_path']}/latest.tgz");
170
	require("fend.inc");
171
	exit;
172
}
173
174 da55e467 Scott Ullrich
if($downloaded_latest_tgz_sha256 <> $upgrade_latest_tgz_sha256) {
175
	update_status("Downloading complete but sha256 does not match.");
176
	update_output_window("Auto upgrade aborted.  \n\nDownloaded SHA256: $downloaded_latest_tgz_sha256 \n\nNeeded SHA256: $upgrade_latest_tgz_sha256");	
177 d40b3c36 Colin Smith
} else {
178 da55e467 Scott Ullrich
	update_output_window("{$g['product_name']} is now upgrading.\\n\\nThe firewall will reboot once the operation is completed.");
179
	echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
180
	exec_rc_script_async("{$external_upgrade_helper_text}");
181 d40b3c36 Colin Smith
}
182 cdb0117c Scott Ullrich
183 da55e467 Scott Ullrich
/*
184
	Helper functions
185
*/
186 d40b3c36 Colin Smith
187 9140757d Bill Marquette
function read_body_firmware($ch, $string) {
188 da55e467 Scott Ullrich
	global $fout, $file_size, $downloaded, $counter, $version, $latest_version, $current_installed_pfsense_version;
189
	$length = strlen($string);
190
	$downloaded += intval($length);
191
	$downloadProgress = round(100 * (1 - $downloaded / $file_size), 0);
192
	$downloadProgress = 100 - $downloadProgress;
193
	$a = $file_size;
194
	$b = $downloaded;
195
	$c = $downloadProgress;
196
	$text  = "  Auto Update Download Status\\n";
197
	$text .= "---------------------------------\\n";
198
	$text .= "  Latest Version  : {$latest_version}\\n";
199
	$text .= "  Current Version : {$current_installed_pfsense_version}\\n";
200
	$text .= "  File size       : {$a}\\n";
201
	$text .= "  Downloaded      : {$b}\\n";
202
	$text .= "  Percent         : {$c}%\\n";
203
	$text .= "---------------------------------\\n";
204
	$counter++;
205
	if($counter > 150) {
206
		update_output_window($text);
207
		update_progress_bar($downloadProgress);
208
		$counter = 0;
209
	}
210
	fwrite($fout, $string);
211
	return $length;
212 ebe916cf Colin Smith
}
213 853167d2 Colin Smith
214 9140757d Bill Marquette
?>