1 |
5b237745
|
Scott Ullrich
|
#!/usr/local/bin/php
|
2 |
03b92764
|
Scott Ullrich
|
<?php
|
3 |
5b237745
|
Scott Ullrich
|
/*
|
4 |
|
|
interfaces_opt.php
|
5 |
|
|
part of m0n0wall (http://m0n0.ch/wall)
|
6 |
03b92764
|
Scott Ullrich
|
|
7 |
5b237745
|
Scott Ullrich
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
8 |
|
|
All rights reserved.
|
9 |
03b92764
|
Scott Ullrich
|
|
10 |
5b237745
|
Scott Ullrich
|
Redistribution and use in source and binary forms, with or without
|
11 |
|
|
modification, are permitted provided that the following conditions are met:
|
12 |
03b92764
|
Scott Ullrich
|
|
13 |
5b237745
|
Scott Ullrich
|
1. Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
this list of conditions and the following disclaimer.
|
15 |
03b92764
|
Scott Ullrich
|
|
16 |
5b237745
|
Scott Ullrich
|
2. Redistributions in binary form must reproduce the above copyright
|
17 |
|
|
notice, this list of conditions and the following disclaimer in the
|
18 |
|
|
documentation and/or other materials provided with the distribution.
|
19 |
03b92764
|
Scott Ullrich
|
|
20 |
5b237745
|
Scott Ullrich
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
30 |
|
|
*/
|
31 |
|
|
|
32 |
|
|
require("guiconfig.inc");
|
33 |
|
|
|
34 |
|
|
unset($index);
|
35 |
|
|
if ($_GET['index'])
|
36 |
|
|
$index = $_GET['index'];
|
37 |
|
|
else if ($_POST['index'])
|
38 |
|
|
$index = $_POST['index'];
|
39 |
03b92764
|
Scott Ullrich
|
|
40 |
5b237745
|
Scott Ullrich
|
if (!$index)
|
41 |
|
|
exit;
|
42 |
|
|
|
43 |
|
|
$optcfg = &$config['interfaces']['opt' . $index];
|
44 |
|
|
$pconfig['descr'] = $optcfg['descr'];
|
45 |
|
|
$pconfig['bridge'] = $optcfg['bridge'];
|
46 |
|
|
$pconfig['ipaddr'] = $optcfg['ipaddr'];
|
47 |
|
|
$pconfig['subnet'] = $optcfg['subnet'];
|
48 |
03b92764
|
Scott Ullrich
|
|
49 |
|
|
$pconfig['bandwidth'] = $optcfg['bandwidth'];
|
50 |
|
|
$pconfig['bandwidthtype'] = $optcfg['bandwidthtype'];
|
51 |
af539d78
|
Scott Ullrich
|
$pconfig['schedulertype'] = $optcfg['schedulertype'];
|
52 |
|
|
|
53 |
03b92764
|
Scott Ullrich
|
|
54 |
5b237745
|
Scott Ullrich
|
$pconfig['enable'] = isset($optcfg['enable']);
|
55 |
|
|
|
56 |
|
|
/* Wireless interface? */
|
57 |
|
|
if (isset($optcfg['wireless'])) {
|
58 |
|
|
require("interfaces_wlan.inc");
|
59 |
|
|
wireless_config_init();
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
if ($_POST) {
|
63 |
|
|
|
64 |
|
|
unset($input_errors);
|
65 |
|
|
$pconfig = $_POST;
|
66 |
|
|
|
67 |
|
|
/* input validation */
|
68 |
|
|
if ($_POST['enable']) {
|
69 |
03b92764
|
Scott Ullrich
|
|
70 |
5b237745
|
Scott Ullrich
|
/* description unique? */
|
71 |
|
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
72 |
|
|
if ($i != $index) {
|
73 |
|
|
if ($config['interfaces']['opt' . $i]['descr'] == $_POST['descr']) {
|
74 |
|
|
$input_errors[] = "An interface with the specified description already exists.";
|
75 |
|
|
}
|
76 |
|
|
}
|
77 |
|
|
}
|
78 |
03b92764
|
Scott Ullrich
|
|
79 |
5b237745
|
Scott Ullrich
|
if ($_POST['bridge']) {
|
80 |
|
|
/* double bridging? */
|
81 |
|
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
82 |
|
|
if ($i != $index) {
|
83 |
|
|
if ($config['interfaces']['opt' . $i]['bridge'] == $_POST['bridge']) {
|
84 |
03b92764
|
Scott Ullrich
|
$input_errors[] = "Optional interface {$i} " .
|
85 |
5b237745
|
Scott Ullrich
|
"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
|
86 |
|
|
"the specified interface.";
|
87 |
|
|
} else if ($config['interfaces']['opt' . $i]['bridge'] == "opt{$index}") {
|
88 |
03b92764
|
Scott Ullrich
|
$input_errors[] = "Optional interface {$i} " .
|
89 |
5b237745
|
Scott Ullrich
|
"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
|
90 |
|
|
"this interface.";
|
91 |
|
|
}
|
92 |
|
|
}
|
93 |
|
|
}
|
94 |
|
|
if ($config['interfaces'][$_POST['bridge']]['bridge']) {
|
95 |
|
|
$input_errors[] = "The specified interface is already bridged to " .
|
96 |
|
|
"another interface.";
|
97 |
|
|
}
|
98 |
|
|
/* captive portal on? */
|
99 |
|
|
if (isset($config['captiveportal']['enable'])) {
|
100 |
|
|
$input_errors[] = "Interfaces cannot be bridged while the captive portal is enabled.";
|
101 |
|
|
}
|
102 |
|
|
} else {
|
103 |
|
|
$reqdfields = explode(" ", "descr ipaddr subnet");
|
104 |
|
|
$reqdfieldsn = explode(",", "Description,IP address,Subnet bit count");
|
105 |
03b92764
|
Scott Ullrich
|
|
106 |
5b237745
|
Scott Ullrich
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
107 |
03b92764
|
Scott Ullrich
|
|
108 |
5b237745
|
Scott Ullrich
|
if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
|
109 |
|
|
$input_errors[] = "A valid IP address must be specified.";
|
110 |
|
|
}
|
111 |
|
|
if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
|
112 |
|
|
$input_errors[] = "A valid subnet bit count must be specified.";
|
113 |
|
|
}
|
114 |
|
|
}
|
115 |
|
|
}
|
116 |
03b92764
|
Scott Ullrich
|
|
117 |
5b237745
|
Scott Ullrich
|
/* Wireless interface? */
|
118 |
|
|
if (isset($optcfg['wireless'])) {
|
119 |
|
|
$wi_input_errors = wireless_config_post();
|
120 |
|
|
if ($wi_input_errors) {
|
121 |
|
|
$input_errors = array_merge($input_errors, $wi_input_errors);
|
122 |
|
|
}
|
123 |
|
|
}
|
124 |
03b92764
|
Scott Ullrich
|
|
125 |
5b237745
|
Scott Ullrich
|
if (!$input_errors) {
|
126 |
|
|
$optcfg['descr'] = $_POST['descr'];
|
127 |
|
|
$optcfg['ipaddr'] = $_POST['ipaddr'];
|
128 |
|
|
$optcfg['subnet'] = $_POST['subnet'];
|
129 |
|
|
$optcfg['bridge'] = $_POST['bridge'];
|
130 |
|
|
$optcfg['enable'] = $_POST['enable'] ? true : false;
|
131 |
03b92764
|
Scott Ullrich
|
$optcfg['bandwidth'] = $_POST['bandwidth'];
|
132 |
|
|
$optcfg['bandwidthtype'] = $_POST['bandwidthtype'];
|
133 |
af539d78
|
Scott Ullrich
|
$optcfg['schedulertype'] = $_POST['schedulertype'];
|
134 |
03b92764
|
Scott Ullrich
|
|
135 |
5b237745
|
Scott Ullrich
|
write_config();
|
136 |
03b92764
|
Scott Ullrich
|
|
137 |
5b237745
|
Scott Ullrich
|
$retval = 0;
|
138 |
|
|
if (!file_exists($d_sysrebootreqd_path)) {
|
139 |
|
|
config_lock();
|
140 |
|
|
$retval = interfaces_optional_configure();
|
141 |
03b92764
|
Scott Ullrich
|
|
142 |
5b237745
|
Scott Ullrich
|
/* is this the captive portal interface? */
|
143 |
03b92764
|
Scott Ullrich
|
if (isset($config['captiveportal']['enable']) &&
|
144 |
5b237745
|
Scott Ullrich
|
($config['captiveportal']['interface'] == ('opt' . $index))) {
|
145 |
|
|
captiveportal_configure();
|
146 |
|
|
}
|
147 |
|
|
config_unlock();
|
148 |
|
|
}
|
149 |
|
|
$savemsg = get_std_save_message($retval);
|
150 |
|
|
}
|
151 |
|
|
}
|
152 |
|
|
?>
|
153 |
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
154 |
|
|
<html>
|
155 |
|
|
<head>
|
156 |
|
|
<title><?=gentitle("Interfaces: Optional $index (" . htmlspecialchars($optcfg['descr']) . ")");?></title>
|
157 |
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
158 |
|
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
159 |
|
|
<script language="JavaScript">
|
160 |
|
|
<!--
|
161 |
|
|
function enable_change(enable_over) {
|
162 |
a23d7248
|
Scott Ullrich
|
var endis;
|
163 |
|
|
endis = !((document.iform.bridge.selectedIndex == 0) || enable_over);
|
164 |
|
|
document.iform.ipaddr.disabled = endis;
|
165 |
|
|
document.iform.subnet.disabled = endis;
|
166 |
5b237745
|
Scott Ullrich
|
}
|
167 |
|
|
function gen_bits(ipaddr) {
|
168 |
|
|
if (ipaddr.search(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) != -1) {
|
169 |
|
|
var adr = ipaddr.split(/\./);
|
170 |
|
|
if (adr[0] > 255 || adr[1] > 255 || adr[2] > 255 || adr[3] > 255)
|
171 |
|
|
return 0;
|
172 |
|
|
if (adr[0] == 0 && adr[1] == 0 && adr[2] == 0 && adr[3] == 0)
|
173 |
|
|
return 0;
|
174 |
03b92764
|
Scott Ullrich
|
|
175 |
5b237745
|
Scott Ullrich
|
if (adr[0] <= 127)
|
176 |
|
|
return 23;
|
177 |
|
|
else if (adr[0] <= 191)
|
178 |
|
|
return 15;
|
179 |
|
|
else
|
180 |
|
|
return 7;
|
181 |
|
|
}
|
182 |
|
|
else
|
183 |
|
|
return 0;
|
184 |
|
|
}
|
185 |
|
|
function ipaddr_change() {
|
186 |
|
|
document.iform.subnet.selectedIndex = gen_bits(document.iform.ipaddr.value);
|
187 |
|
|
}
|
188 |
|
|
//-->
|
189 |
|
|
</script>
|
190 |
|
|
</head>
|
191 |
|
|
|
192 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
193 |
|
|
<?php include("fbegin.inc"); ?>
|
194 |
af539d78
|
Scott Ullrich
|
<?php
|
195 |
|
|
$schedulertype = $pconfig['schedulertype'];
|
196 |
|
|
?>
|
197 |
5b237745
|
Scott Ullrich
|
<p class="pgtitle">Interfaces: Optional <?=$index;?> (<?=htmlspecialchars($optcfg['descr']);?>)</p>
|
198 |
|
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
199 |
|
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
200 |
|
|
<?php if ($optcfg['if']): ?>
|
201 |
|
|
<form action="interfaces_opt.php" method="post" name="iform" id="iform">
|
202 |
|
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
203 |
03b92764
|
Scott Ullrich
|
<tr>
|
204 |
5b237745
|
Scott Ullrich
|
<td width="22%" valign="top" class="vtable"> </td>
|
205 |
|
|
<td width="78%" class="vtable">
|
206 |
|
|
<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
|
207 |
|
|
<strong>Enable Optional <?=$index;?> interface</strong></td>
|
208 |
|
|
</tr>
|
209 |
03b92764
|
Scott Ullrich
|
<tr>
|
210 |
5b237745
|
Scott Ullrich
|
<td width="22%" valign="top" class="vncell">Description</td>
|
211 |
03b92764
|
Scott Ullrich
|
<td width="78%" class="vtable">
|
212 |
5b237745
|
Scott Ullrich
|
<input name="descr" type="text" class="formfld" id="descr" size="30" value="<?=htmlspecialchars($pconfig['descr']);?>">
|
213 |
|
|
<br> <span class="vexpl">Enter a description (name) for the interface here.</span>
|
214 |
|
|
</td>
|
215 |
|
|
</tr>
|
216 |
03b92764
|
Scott Ullrich
|
<tr>
|
217 |
5b237745
|
Scott Ullrich
|
<td colspan="2" valign="top" height="16"></td>
|
218 |
|
|
</tr>
|
219 |
03b92764
|
Scott Ullrich
|
<tr>
|
220 |
a23d7248
|
Scott Ullrich
|
<td colspan="2" valign="top" class="listtopic">IP configuration</td>
|
221 |
5b237745
|
Scott Ullrich
|
</tr>
|
222 |
03b92764
|
Scott Ullrich
|
<tr>
|
223 |
5b237745
|
Scott Ullrich
|
<td width="22%" valign="top" class="vncellreq">Bridge with</td>
|
224 |
|
|
<td width="78%" class="vtable">
|
225 |
|
|
<select name="bridge" class="formfld" id="bridge" onChange="enable_change(false)">
|
226 |
|
|
<option <?php if (!$pconfig['bridge']) echo "selected";?> value="">none</option>
|
227 |
|
|
<?php $opts = array('lan' => "LAN", 'wan' => "WAN");
|
228 |
|
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
229 |
|
|
if ($i != $index)
|
230 |
|
|
$opts['opt' . $i] = "Optional " . $i . " (" .
|
231 |
|
|
$config['interfaces']['opt' . $i]['descr'] . ")";
|
232 |
|
|
}
|
233 |
|
|
foreach ($opts as $opt => $optname): ?>
|
234 |
03b92764
|
Scott Ullrich
|
<option <?php if ($opt == $pconfig['bridge']) echo "selected";?> value="<?=htmlspecialchars($opt);?>">
|
235 |
5b237745
|
Scott Ullrich
|
<?=htmlspecialchars($optname);?>
|
236 |
|
|
</option>
|
237 |
|
|
<?php endforeach; ?>
|
238 |
|
|
</select> </td>
|
239 |
|
|
</tr>
|
240 |
03b92764
|
Scott Ullrich
|
<tr>
|
241 |
5b237745
|
Scott Ullrich
|
<td width="22%" valign="top" class="vncellreq">IP address</td>
|
242 |
03b92764
|
Scott Ullrich
|
<td width="78%" class="vtable">
|
243 |
5b237745
|
Scott Ullrich
|
<input name="ipaddr" type="text" class="formfld" id="ipaddr" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>" onchange="ipaddr_change()">
|
244 |
|
|
/
|
245 |
|
|
<select name="subnet" class="formfld" id="subnet">
|
246 |
40dd6441
|
Scott Ullrich
|
<?php for ($i = 32; $i > 0; $i--): ?>
|
247 |
5b237745
|
Scott Ullrich
|
<option value="<?=$i;?>" <?php if ($i == $pconfig['subnet']) echo "selected"; ?>><?=$i;?></option>
|
248 |
|
|
<?php endfor; ?>
|
249 |
|
|
</select>
|
250 |
|
|
</td>
|
251 |
|
|
</tr>
|
252 |
|
|
<?php /* Wireless interface? */
|
253 |
|
|
if (isset($optcfg['wireless']))
|
254 |
|
|
wireless_config_print();
|
255 |
|
|
?>
|
256 |
af539d78
|
Scott Ullrich
|
<tr>
|
257 |
|
|
<td colspan="2" valign="top" height="16"></td>
|
258 |
|
|
</tr>
|
259 |
|
|
<tr>
|
260 |
|
|
<td colspan="2" valign="top" class="vnsepcell">Bandwidth Management (Traffic Shaping)</td>
|
261 |
|
|
</tr>
|
262 |
|
|
<tr>
|
263 |
|
|
<td width="22%" valign="top" class="vncell"><b>Scheduler</b> </td>
|
264 |
|
|
<td width="78%" class="vtable">
|
265 |
|
|
<select id="schedulertype" name="schedulertype">
|
266 |
|
|
<?php
|
267 |
|
|
if($schedulertype == 'priq')
|
268 |
|
|
echo "<option value=\"priq\">Priority based queueing</option>";
|
269 |
|
|
if($schedulertype == 'cbq')
|
270 |
|
|
echo "<option value=\"cbq\">Class based queueing</option>";
|
271 |
|
|
if($schedulertype == 'hfsc')
|
272 |
|
|
echo "<option value=\"hfsc\">Hierarchical Fair Service Curve queueing</option>";
|
273 |
|
|
?>
|
274 |
|
|
<option value="priq">Priority based queueing</option>
|
275 |
|
|
<option value="cbq">Class based queueing</option>
|
276 |
|
|
<option value="hfsc">Hierarchical Fair Service Curve queueing</option>
|
277 |
|
|
</select>
|
278 |
|
|
<br> <span class="vexpl">Select which type of queueing you would like to use
|
279 |
|
|
</span></td>
|
280 |
|
|
</tr>
|
281 |
|
|
<tr>
|
282 |
|
|
<td valign="top" class="vncell">Interface Bandwidth Speed</td>
|
283 |
03b92764
|
Scott Ullrich
|
<td class="vtable"> <input name="bandwidth" type="text" class="formfld" id="bandwidth" size="30" value="<?=htmlspecialchars($pconfig['bandwidth']);?>">
|
284 |
|
|
<select name="bandwidthtype">
|
285 |
|
|
<option value="<?=htmlspecialchars($pconfig['bandwidthtype']);?>"><?=htmlspecialchars($pconfig['bandwidthtype']);?></option>
|
286 |
|
|
<option value="b">bit/s</option>
|
287 |
|
|
<option value="Kb">Kilobit/s</option>
|
288 |
|
|
<option value="Mb">Megabit/s</option>
|
289 |
|
|
<option value="Gb">Gigabit/s</option>
|
290 |
|
|
</select>
|
291 |
|
|
<br> The bandwidth setting will define the speed of the interface for traffic shaping.
|
292 |
|
|
</td>
|
293 |
af539d78
|
Scott Ullrich
|
</tr> <tr>
|
294 |
5b237745
|
Scott Ullrich
|
<td width="22%" valign="top"> </td>
|
295 |
03b92764
|
Scott Ullrich
|
<td width="78%">
|
296 |
|
|
<input name="index" type="hidden" value="<?=$index;?>">
|
297 |
|
|
<input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
|
298 |
5b237745
|
Scott Ullrich
|
</td>
|
299 |
|
|
</tr>
|
300 |
03b92764
|
Scott Ullrich
|
<tr>
|
301 |
5b237745
|
Scott Ullrich
|
<td width="22%" valign="top"> </td>
|
302 |
|
|
<td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
|
303 |
03b92764
|
Scott Ullrich
|
</strong></span>be sure to add firewall rules to permit traffic
|
304 |
|
|
through the interface. Firewall rules for an interface in
|
305 |
|
|
bridged mode have no effect on packets to hosts other than
|
306 |
|
|
m0n0wall itself, unless "Enable filtering bridge"
|
307 |
|
|
is checked on the <a href="system_advanced.php">System:
|
308 |
5b237745
|
Scott Ullrich
|
Advanced functions</a> page.</span></td>
|
309 |
|
|
</tr>
|
310 |
|
|
</table>
|
311 |
|
|
</form>
|
312 |
|
|
<script language="JavaScript">
|
313 |
|
|
<!--
|
314 |
|
|
enable_change(false);
|
315 |
|
|
//-->
|
316 |
|
|
</script>
|
317 |
|
|
<?php else: ?>
|
318 |
|
|
<p><strong>Optional <?=$index;?> has been disabled because there is no OPT<?=$index;?> interface.</strong></p>
|
319 |
|
|
<?php endif; ?>
|
320 |
|
|
<?php include("fend.inc"); ?>
|
321 |
|
|
</body>
|
322 |
|
|
</html>
|