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