Project

General

Profile

Download (9.09 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 4668f9f7 Scott Ullrich
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5 580182e2 Colin Smith
	system_firmware.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31 5b237745 Scott Ullrich
*/
32
33 3958d63b Colin Smith
$d_isfwfile = 1;
34 6605faea Scott Ullrich
require_once("guiconfig.inc");
35
require_once("xmlrpc_client.inc");
36 aa08f46b Bill Marquette
37 8b7c81d7 Scott Ullrich
/* if upgrade in progress, alert user */
38
if(file_exists($d_firmwarelock_path)) {
39
	$pgtitle = "System: Firmware: Manual Update";
40
	include("head.inc");
41
	echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
42
	include("fbegin.inc");
43
	echo "<p class=\"pgtitle\"><?=$pgtitle?></p>\n";
44
	echo "<div>\n";
45 fdcb3035 Scott Ullrich
	print_info_box("A upgrade is currently in progress.<p>The firewall will reboot when the operation is complete.<p><center><img src='/themes/{$g['theme']}/images/icons/icon_fw-update.gif'>");
46 8b7c81d7 Scott Ullrich
	echo "</div>\n";
47
	include("fend.inc");
48
	echo "</body>";
49
	echo "</html>";
50
	exit;
51
}
52
53 aa08f46b Bill Marquette
/* Handle manual upgrade */
54 5b237745 Scott Ullrich
if ($_POST && !file_exists($d_firmwarelock_path)) {
55
56 580182e2 Colin Smith
	unset($input_errors);
57
	unset($sig_warning);
58
59
	if (stristr($_POST['Submit'], "Enable"))
60
		$mode = "enable";
61
	else if (stristr($_POST['Submit'], "Disable"))
62
		$mode = "disable";
63
	else if (stristr($_POST['Submit'], "Upgrade") || $_POST['sig_override'])
64
		$mode = "upgrade";
65
	else if ($_POST['sig_no']) {
66
		if(file_exists("{$g['tmp_path']}/firmware.tgz"))
67
				unlink("{$g['tmp_path']}/firmware.tgz");
68
	}
69
	if ($mode) {
70
		if ($mode == "enable") {
71
			exec_rc_script("/etc/rc.firmware enable");
72
			touch($d_fwupenabled_path);
73
		} else if ($mode == "disable") {
74
			exec_rc_script("/etc/rc.firmware disable");
75
			if (file_exists($d_fwupenabled_path))
76
				unlink($d_fwupenabled_path);
77
		} else if ($mode == "upgrade") {
78
			if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
79
				/* verify firmware image(s) */
80
				if (!stristr($_FILES['ulfile']['name'], $g['platform']) && !$_POST['sig_override'])
81 f44a6ab5 Bill Marquette
					$input_errors[] = "The uploaded image file is not for this platform ({$g['platform']}).";
82 580182e2 Colin Smith
				else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
83
					/* probably out of memory for the MFS */
84
					$input_errors[] = "Image upload failed (out of memory?)";
85
					exec_rc_script("/etc/rc.firmware disable");
86
					if (file_exists($d_fwupenabled_path))
87
						unlink($d_fwupenabled_path);
88
				} else {
89
					/* move the image so PHP won't delete it */
90
					rename($_FILES['ulfile']['tmp_name'], "{$g['tmp_path']}/firmware.tgz");
91
92
					/* check digital signature */
93
					$sigchk = verify_digital_signature("{$g['tmp_path']}/firmware.tgz");
94
95
					if ($sigchk == 1)
96
						$sig_warning = "The digital signature on this image is invalid.";
97
					else if ($sigchk == 2)
98
						$sig_warning = "This image is not digitally signed.";
99
					else if (($sigchk == 3) || ($sigchk == 4))
100
						$sig_warning = "There has been an error verifying the signature on this image.";
101
102
					if (!verify_gzip_file("{$g['tmp_path']}/firmware.tgz")) {
103
						$input_errors[] = "The image file is corrupt.";
104
						unlink("{$g['tmp_path']}/firmware.tgz");
105
					}
106
				}
107
			}
108
109 e4296d11 Bill Marquette
                        /* Check for input errors, firmware locks, warnings, then check for firmware if sig_override is set */
110
                        if (!$input_errors && !file_exists($d_firmwarelock_path) && (!$sig_warning || $_POST['sig_override'])) {
111 473d3407 Bill Marquette
                                if (file_exists("{$g['tmp_path']}/firmware.tgz")) {
112 e4296d11 Bill Marquette
                                        /* fire up the update script in the background */
113
                                        touch($d_firmwarelock_path);
114
                                        $savemsg = "The firmware is now being updated. The firewall will reboot automatically.";
115
                                        mwexec_bg("/etc/rc.firmware pfSenseupgrade {$g['tmp_path']}/firmware.tgz");
116
                                } else {
117
                                        $savemsg = "Firmware image missing or other error, please try again.";
118
                                }
119
                        }
120 580182e2 Colin Smith
		}
121
	}
122 5b237745 Scott Ullrich
}
123 e2fa4962 Scott Ullrich
124 97a9a675 Scott Ullrich
/* upload progress bar id */
125 e2fa4962 Scott Ullrich
$id = rand() . '.' . time();
126
$mth = ini_get('upload_progress_meter.store_method');
127
$dir = ini_get('upload_progress_meter.file.filename_template');
128
129 94656ba5 Bill Marquette
$pgtitle = "System: Firmware: Manual Update";
130 52380979 Scott Ullrich
include("head.inc");
131
132 5b237745 Scott Ullrich
?>
133 580182e2 Colin Smith
<!--
134
generated new UPLOAD_IDENTIFIER = <?=$id?>
135
php-config.upload_progress_meter.store_method = <?=$mth?>
136
php-config.upload_progress_meter.file.filename_template = <?=$dir?>
137
-->
138
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
139
<?php include("fbegin.inc"); ?>
140 74f446e8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
141 580182e2 Colin Smith
<?php if ($input_errors) print_input_errors($input_errors); ?>
142
<?php if ($savemsg) print_info_box($savemsg); ?>  	 
143
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
144 77720bd3 Colin Smith
<?php if ($sig_warning && !$input_errors): ?>
145 5b237745 Scott Ullrich
<form action="system_firmware.php" method="post">
146 4668f9f7 Scott Ullrich
<?php
147 5b237745 Scott Ullrich
$sig_warning = "<strong>" . $sig_warning . "</strong><br>This means that the image you uploaded " .
148 580182e2 Colin Smith
	"is not an official/supported image and may lead to unexpected behavior or security " .
149
	"compromises. Only install images that come from sources that you trust, and make sure ".
150
	"that the image has not been tampered with.<br><br>".
151 d28303ed Scott Ullrich
	"Please note that we do not sign alpha and or beta images.<br><br>".
152 580182e2 Colin Smith
	"Do you want to install this image anyway (on your own risk)?";
153 5b237745 Scott Ullrich
print_info_box($sig_warning);
154
?>
155
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" Yes ">
156
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" No ">
157
</form>
158
<?php else: ?>
159
            <?php if (!file_exists($d_firmwarelock_path)): ?>
160 52d69e6a Scott Ullrich
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
161 580182e2 Colin Smith
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
162
	<tr>
163
		<td>
164 4820d297 Scott Ullrich
<?php
165
	$tab_array = array();
166
	$tab_array[0] = array("Manual Update", true, "system_firmware.php");
167
	$tab_array[1] = array("Auto Update", false, "system_firmware_check.php");
168 9f0d40c1 Scott Ullrich
	$tab_array[2] = array("Updater Settings", false, "system_firmware_settings.php");
169 4820d297 Scott Ullrich
	display_top_tabs($tab_array);
170
?>
171 580182e2 Colin Smith
		</td>
172
	</tr>
173 222494af Colin Smith
  <tr>
174 e12d98ea Bill Marquette
    <td>
175
	<div id="mainarea">
176
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
177 3958d63b Colin Smith
                <tr>
178 580182e2 Colin Smith
		 <td colspan="2" class="listtopic">Invoke pfSense Manual Upgrade</td>
179
		</tr>
180
		  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
181 db7f4f2b Scott Ullrich
                  <td width="78%" class="vtable">
182 aa08f46b Bill Marquette
            <p>Click &quot;Enable firmware
183 3aed9904 Scott Ullrich
              upload&quot; below, then choose the image file (<?=$g['platform'];?>-*.tgz)
184 580182e2 Colin Smith
			  to be uploaded.<br>Click &quot;Upgrade firmware&quot;
185 aa08f46b Bill Marquette
              to start the upgrade process.</p>
186 5b237745 Scott Ullrich
                    <?php if (!file_exists($d_sysrebootreqd_path)): ?>
187
                    <?php if (!file_exists($d_fwupenabled_path)): ?>
188
                    <input name="Submit" type="submit" class="formbtn" value="Enable firmware upload">
189 580182e2 Colin Smith
				  <?php else: ?>
190
				   <input name="Submit" type="submit" class="formbtn" value="Disable firmware upload">
191 5b237745 Scott Ullrich
                    <br><br>
192 580182e2 Colin Smith
					<strong>Firmware image file: </strong>&nbsp;
193
					<input type="hidden" name="UPLOAD_IDENTIFIER" value="<?=$id?>">
194
					<input name="ulfile" type="file" class="formfld">
195 5b237745 Scott Ullrich
                    <br><br>
196 580182e2 Colin Smith
		    <input name="Submit" type="submit" class="formbtn" value="Upgrade firmware" onClick="window.open('progress.php?UPLOAD_IDENTIFIER=<?=$id?>','UploadMeter','width=400,height=200', true); return true; ">
197
				  <?php endif; else: ?>
198
				    <strong>You must reboot the system before you can upgrade the firmware.</strong>
199
				  <?php endif; ?>
200 5b237745 Scott Ullrich
                  </td>
201 580182e2 Colin Smith
		</td>
202 5b237745 Scott Ullrich
                </tr>
203 4668f9f7 Scott Ullrich
                <tr>
204 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
205
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Warning:<br>
206 4668f9f7 Scott Ullrich
                    </strong></span>DO NOT abort the firmware upgrade once it
207
                    has started. The firewall will reboot automatically after
208 5b237745 Scott Ullrich
                    storing the new firmware. The configuration will be maintained.</span></td>
209
              </table>
210 e12d98ea Bill Marquette
		</div>
211 580182e2 Colin Smith
		</tr>
212
		</td>
213 222494af Colin Smith
</table>
214 580182e2 Colin Smith
215 5b237745 Scott Ullrich
</form>
216
<?php endif; endif; ?>
217
<?php include("fend.inc"); ?>
218
</body>
219
</html>