Project

General

Profile

Download (7.94 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
/* Handle manual upgrade */
38 5b237745 Scott Ullrich
if ($_POST && !file_exists($d_firmwarelock_path)) {
39
40 580182e2 Colin Smith
	unset($input_errors);
41
	unset($sig_warning);
42
43
	if (stristr($_POST['Submit'], "Enable"))
44
		$mode = "enable";
45
	else if (stristr($_POST['Submit'], "Disable"))
46
		$mode = "disable";
47
	else if (stristr($_POST['Submit'], "Upgrade") || $_POST['sig_override'])
48
		$mode = "upgrade";
49
	else if ($_POST['sig_no']) {
50
		if(file_exists("{$g['tmp_path']}/firmware.tgz"))
51
				unlink("{$g['tmp_path']}/firmware.tgz");
52
	}
53
	if ($mode) {
54
		if ($mode == "enable") {
55
			exec_rc_script("/etc/rc.firmware enable");
56
			touch($d_fwupenabled_path);
57
		} else if ($mode == "disable") {
58
			exec_rc_script("/etc/rc.firmware disable");
59
			if (file_exists($d_fwupenabled_path))
60
				unlink($d_fwupenabled_path);
61
		} else if ($mode == "upgrade") {
62
			if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
63
				/* verify firmware image(s) */
64
				if (!stristr($_FILES['ulfile']['name'], $g['platform']) && !$_POST['sig_override'])
65
					$input_errors[] = "The uploaded image file is not for this platfom ({$g['platform']}).";
66
				else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
67
					/* probably out of memory for the MFS */
68
					$input_errors[] = "Image upload failed (out of memory?)";
69
					exec_rc_script("/etc/rc.firmware disable");
70
					if (file_exists($d_fwupenabled_path))
71
						unlink($d_fwupenabled_path);
72
				} else {
73
					/* move the image so PHP won't delete it */
74
					rename($_FILES['ulfile']['tmp_name'], "{$g['tmp_path']}/firmware.tgz");
75
76
					/* check digital signature */
77
					$sigchk = verify_digital_signature("{$g['tmp_path']}/firmware.tgz");
78
79
					if ($sigchk == 1)
80
						$sig_warning = "The digital signature on this image is invalid.";
81
					else if ($sigchk == 2)
82
						$sig_warning = "This image is not digitally signed.";
83
					else if (($sigchk == 3) || ($sigchk == 4))
84
						$sig_warning = "There has been an error verifying the signature on this image.";
85
86
					if (!verify_gzip_file("{$g['tmp_path']}/firmware.tgz")) {
87
						$input_errors[] = "The image file is corrupt.";
88
						unlink("{$g['tmp_path']}/firmware.tgz");
89
					}
90
				}
91
			}
92
93
			if (!$input_errors && !file_exists($d_firmwarelock_path) && (!$sig_warning || $_POST['sig_override'])) {
94
				/* fire up the update script in the background */
95
				touch($d_firmwarelock_path);
96 59fe3cdf Scott Ullrich
				$savemsg = "The firmware is now being updated. The firewall will reboot automatically.";
97
				mwexec_bg("/etc/rc.firmware pfSenseupgrade {$g['tmp_path']}/firmware.tgz");
98 580182e2 Colin Smith
			}
99
		}
100
	}
101 5b237745 Scott Ullrich
}
102 e2fa4962 Scott Ullrich
103 97a9a675 Scott Ullrich
/* upload progress bar id */
104 e2fa4962 Scott Ullrich
$id = rand() . '.' . time();
105
$mth = ini_get('upload_progress_meter.store_method');
106
$dir = ini_get('upload_progress_meter.file.filename_template');
107
108 94656ba5 Bill Marquette
$pgtitle = "System: Firmware: Manual Update";
109 52380979 Scott Ullrich
include("head.inc");
110
111 5b237745 Scott Ullrich
?>
112 580182e2 Colin Smith
<!--
113
generated new UPLOAD_IDENTIFIER = <?=$id?>
114
php-config.upload_progress_meter.store_method = <?=$mth?>
115
php-config.upload_progress_meter.file.filename_template = <?=$dir?>
116
-->
117
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
118
<?php include("fbegin.inc"); ?>
119 74f446e8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
120 580182e2 Colin Smith
<?php if ($input_errors) print_input_errors($input_errors); ?>
121
<?php if ($savemsg) print_info_box($savemsg); ?>  	 
122
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
123 77720bd3 Colin Smith
<?php if ($sig_warning && !$input_errors): ?>
124 5b237745 Scott Ullrich
<form action="system_firmware.php" method="post">
125 4668f9f7 Scott Ullrich
<?php
126 5b237745 Scott Ullrich
$sig_warning = "<strong>" . $sig_warning . "</strong><br>This means that the image you uploaded " .
127 580182e2 Colin Smith
	"is not an official/supported image and may lead to unexpected behavior or security " .
128
	"compromises. Only install images that come from sources that you trust, and make sure ".
129
	"that the image has not been tampered with.<br><br>".
130 d28303ed Scott Ullrich
	"Please note that we do not sign alpha and or beta images.<br><br>".
131 580182e2 Colin Smith
	"Do you want to install this image anyway (on your own risk)?";
132 5b237745 Scott Ullrich
print_info_box($sig_warning);
133
?>
134
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" Yes ">
135
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" No ">
136
</form>
137
<?php else: ?>
138
            <?php if (!file_exists($d_firmwarelock_path)): ?>
139 52d69e6a Scott Ullrich
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
140 580182e2 Colin Smith
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
141
	<tr>
142
		<td>
143 4820d297 Scott Ullrich
<?php
144
	$tab_array = array();
145
	$tab_array[0] = array("Manual Update", true, "system_firmware.php");
146
	$tab_array[1] = array("Auto Update", false, "system_firmware_check.php");
147 9f0d40c1 Scott Ullrich
	$tab_array[2] = array("Updater Settings", false, "system_firmware_settings.php");
148 4820d297 Scott Ullrich
	display_top_tabs($tab_array);
149
?>
150 580182e2 Colin Smith
		</td>
151
	</tr>
152 222494af Colin Smith
  <tr>
153 e12d98ea Bill Marquette
    <td>
154
	<div id="mainarea">
155
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
156 3958d63b Colin Smith
                <tr>
157 580182e2 Colin Smith
		 <td colspan="2" class="listtopic">Invoke pfSense Manual Upgrade</td>
158
		</tr>
159
		  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
160 db7f4f2b Scott Ullrich
                  <td width="78%" class="vtable">
161 aa08f46b Bill Marquette
            <p>Click &quot;Enable firmware
162 3aed9904 Scott Ullrich
              upload&quot; below, then choose the image file (<?=$g['platform'];?>-*.tgz)
163 580182e2 Colin Smith
			  to be uploaded.<br>Click &quot;Upgrade firmware&quot;
164 aa08f46b Bill Marquette
              to start the upgrade process.</p>
165 5b237745 Scott Ullrich
                    <?php if (!file_exists($d_sysrebootreqd_path)): ?>
166
                    <?php if (!file_exists($d_fwupenabled_path)): ?>
167
                    <input name="Submit" type="submit" class="formbtn" value="Enable firmware upload">
168 580182e2 Colin Smith
				  <?php else: ?>
169
				   <input name="Submit" type="submit" class="formbtn" value="Disable firmware upload">
170 5b237745 Scott Ullrich
                    <br><br>
171 580182e2 Colin Smith
					<strong>Firmware image file: </strong>&nbsp;
172
					<input type="hidden" name="UPLOAD_IDENTIFIER" value="<?=$id?>">
173
					<input name="ulfile" type="file" class="formfld">
174 5b237745 Scott Ullrich
                    <br><br>
175 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; ">
176
				  <?php endif; else: ?>
177
				    <strong>You must reboot the system before you can upgrade the firmware.</strong>
178
				  <?php endif; ?>
179 5b237745 Scott Ullrich
                  </td>
180 580182e2 Colin Smith
		</td>
181 5b237745 Scott Ullrich
                </tr>
182 4668f9f7 Scott Ullrich
                <tr>
183 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
184
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Warning:<br>
185 4668f9f7 Scott Ullrich
                    </strong></span>DO NOT abort the firmware upgrade once it
186
                    has started. The firewall will reboot automatically after
187 5b237745 Scott Ullrich
                    storing the new firmware. The configuration will be maintained.</span></td>
188
              </table>
189 e12d98ea Bill Marquette
		</div>
190 580182e2 Colin Smith
		</tr>
191
		</td>
192 222494af Colin Smith
</table>
193 580182e2 Colin Smith
194 5b237745 Scott Ullrich
</form>
195
<?php endif; endif; ?>
196
<?php include("fend.inc"); ?>
197
</body>
198
</html>