1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
interfaces_opt.php
|
5
|
part of m0n0wall (http://m0n0.ch/wall)
|
6
|
|
7
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
8
|
All rights reserved.
|
9
|
|
10
|
Redistribution and use in source and binary forms, with or without
|
11
|
modification, are permitted provided that the following conditions are met:
|
12
|
|
13
|
1. Redistributions of source code must retain the above copyright notice,
|
14
|
this list of conditions and the following disclaimer.
|
15
|
|
16
|
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
|
|
20
|
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
|
|
40
|
if (!$index)
|
41
|
exit;
|
42
|
|
43
|
function remove_bad_chars($string) {
|
44
|
return preg_replace('/[^a-z|_|0-9]/i','',$string);
|
45
|
}
|
46
|
|
47
|
$optcfg = &$config['interfaces']['opt' . $index];
|
48
|
$optcfg['descr'] = remove_bad_chars($optcfg['descr']);
|
49
|
|
50
|
$pconfig['descr'] = $optcfg['descr'];
|
51
|
$pconfig['bridge'] = $optcfg['bridge'];
|
52
|
|
53
|
$pconfig['enable'] = isset($optcfg['enable']);
|
54
|
|
55
|
$pconfig['blockpriv'] = isset($optcfg['blockpriv']);
|
56
|
$pconfig['blockbogons'] = isset($optcfg['blockbogons']);
|
57
|
$pconfig['spoofmac'] = $optcfg['spoofmac'];
|
58
|
$pconfig['mtu'] = $optcfg['mtu'];
|
59
|
|
60
|
$pconfig['disableftpproxy'] = isset($optcfg['disableftpproxy']);
|
61
|
|
62
|
/* Wireless interface? */
|
63
|
if (isset($optcfg['wireless'])) {
|
64
|
require("interfaces_wlan.inc");
|
65
|
wireless_config_init();
|
66
|
}
|
67
|
|
68
|
if ($optcfg['ipaddr'] == "dhcp") {
|
69
|
$pconfig['type'] = "DHCP";
|
70
|
$pconfig['dhcphostname'] = $optcfg['dhcphostname'];
|
71
|
} else {
|
72
|
$pconfig['type'] = "Static";
|
73
|
$pconfig['ipaddr'] = $optcfg['ipaddr'];
|
74
|
$pconfig['subnet'] = $optcfg['subnet'];
|
75
|
$pconfig['gateway'] = $optcfg['gateway'];
|
76
|
$pconfig['pointtopoint'] = $optcfg['pointtopoint'];
|
77
|
}
|
78
|
|
79
|
if ($_POST) {
|
80
|
|
81
|
unset($input_errors);
|
82
|
|
83
|
/* filter out spaces from descriptions */
|
84
|
$POST['descr'] = remove_bad_chars($POST['descr']);
|
85
|
|
86
|
$pconfig = $_POST;
|
87
|
|
88
|
/* input validation */
|
89
|
if ($_POST['enable']) {
|
90
|
|
91
|
/* description unique? */
|
92
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
93
|
if ($i != $index) {
|
94
|
if ($config['interfaces']['opt' . $i]['descr'] == $_POST['descr']) {
|
95
|
$input_errors[] = "An interface with the specified description already exists.";
|
96
|
}
|
97
|
}
|
98
|
}
|
99
|
|
100
|
if ($_POST['bridge']) {
|
101
|
/* double bridging? */
|
102
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
103
|
if ($i != $index) {
|
104
|
if ($config['interfaces']['opt' . $i]['bridge'] == $_POST['bridge']) {
|
105
|
//$input_errors[] = "Optional interface {$i} " .
|
106
|
// "({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
|
107
|
// "the specified interface.";
|
108
|
} else if ($config['interfaces']['opt' . $i]['bridge'] == "opt{$index}") {
|
109
|
//$input_errors[] = "Optional interface {$i} " .
|
110
|
// "({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
|
111
|
// "this interface.";
|
112
|
}
|
113
|
}
|
114
|
}
|
115
|
if ($config['interfaces'][$_POST['bridge']]['bridge']) {
|
116
|
//$input_errors[] = "The specified interface is already bridged to " .
|
117
|
// "another interface.";
|
118
|
}
|
119
|
/* captive portal on? */
|
120
|
if (isset($config['captiveportal']['enable'])) {
|
121
|
//$input_errors[] = "Interfaces cannot be bridged while the captive portal is enabled.";
|
122
|
}
|
123
|
} else {
|
124
|
if ($_POST['type'] <> "DHCP") {
|
125
|
$reqdfields = explode(" ", "descr ipaddr subnet");
|
126
|
$reqdfieldsn = explode(",", "Description,IP address,Subnet bit count");
|
127
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
128
|
if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
|
129
|
$input_errors[] = "A valid IP address must be specified.";
|
130
|
}
|
131
|
if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
|
132
|
$input_errors[] = "A valid subnet bit count must be specified.";
|
133
|
}
|
134
|
if($_POST['gateway'] <> "" && !is_ipaddr($_POST['gateway'])) {
|
135
|
$input_errors[] = "A valid gateway must be specified.";
|
136
|
}
|
137
|
}
|
138
|
}
|
139
|
if ($_POST['mtu'] && (($_POST['mtu'] < 576) || ($_POST['mtu'] > 1500))) {
|
140
|
$input_errors[] = "The MTU must be between 576 and 1500 bytes.";
|
141
|
}
|
142
|
if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) {
|
143
|
$input_errors[] = "A valid MAC address must be specified.";
|
144
|
}
|
145
|
}
|
146
|
|
147
|
if($_POST['mtu']) {
|
148
|
if($_POST['mtu'] < 24 or $_POST['mtu'] > 1501)
|
149
|
$input_errors[] = "A valid MTU is required 24-1500.";
|
150
|
}
|
151
|
|
152
|
/* Wireless interface? */
|
153
|
if (isset($optcfg['wireless'])) {
|
154
|
$wi_input_errors = wireless_config_post();
|
155
|
if ($wi_input_errors) {
|
156
|
$input_errors = array_merge($input_errors, $wi_input_errors);
|
157
|
}
|
158
|
}
|
159
|
|
160
|
if (!$input_errors) {
|
161
|
|
162
|
$bridge = discover_bridge($optcfg['if'], filter_translate_type_to_real_interface($optcfg['bridge']));
|
163
|
if($bridge <> "-1") {
|
164
|
destroy_bridge($bridge);
|
165
|
}
|
166
|
|
167
|
unset($optcfg['dhcphostname']);
|
168
|
unset($optcfg['disableftpproxy']);
|
169
|
|
170
|
/* per interface pftpx helper */
|
171
|
if($_POST['disableftpproxy'] == "yes") {
|
172
|
$optcfg['disableftpproxy'] = true;
|
173
|
system_start_ftp_helpers();
|
174
|
} else {
|
175
|
system_start_ftp_helpers();
|
176
|
}
|
177
|
|
178
|
$optcfg['descr'] = remove_bad_chars($_POST['descr']);
|
179
|
$optcfg['bridge'] = $_POST['bridge'];
|
180
|
$optcfg['enable'] = $_POST['enable'] ? true : false;
|
181
|
|
182
|
if ($_POST['type'] == "Static") {
|
183
|
$optcfg['ipaddr'] = $_POST['ipaddr'];
|
184
|
$optcfg['subnet'] = $_POST['subnet'];
|
185
|
$optcfg['gateway'] = $_POST['gateway'];
|
186
|
if (isset($optcfg['ispointtopoint']))
|
187
|
$optcfg['pointtopoint'] = $_POST['pointtopoint'];
|
188
|
} else if ($_POST['type'] == "DHCP") {
|
189
|
$optcfg['ipaddr'] = "dhcp";
|
190
|
$optcfg['dhcphostname'] = $_POST['dhcphostname'];
|
191
|
}
|
192
|
|
193
|
$optcfg['blockpriv'] = $_POST['blockpriv'] ? true : false;
|
194
|
$optcfg['blockbogons'] = $_POST['blockbogons'] ? true : false;
|
195
|
$optcfg['spoofmac'] = $_POST['spoofmac'];
|
196
|
$optcfg['mtu'] = $_POST['mtu'];
|
197
|
|
198
|
write_config();
|
199
|
|
200
|
$savemsg = get_std_save_message($retval);
|
201
|
}
|
202
|
}
|
203
|
|
204
|
|
205
|
$pgtitle = "Interfaces: Optional {$index} (" . htmlspecialchars($optcfg['descr']) . ")";
|
206
|
include("head.inc");
|
207
|
|
208
|
?>
|
209
|
|
210
|
<script language="JavaScript">
|
211
|
<!--
|
212
|
function enable_change(enable_over) {
|
213
|
var endis;
|
214
|
endis = !((document.iform.bridge.selectedIndex == 0) || enable_over);
|
215
|
document.iform.ipaddr.disabled = endis;
|
216
|
document.iform.subnet.disabled = endis;
|
217
|
}
|
218
|
function ipaddr_change() {
|
219
|
document.iform.subnet.selectedIndex = gen_bits_opt(document.iform.ipaddr.value);
|
220
|
}
|
221
|
function type_change(enable_change,enable_change_pptp) {
|
222
|
switch (document.iform.type.selectedIndex) {
|
223
|
case 0:
|
224
|
document.iform.ipaddr.type.disabled = 0;
|
225
|
document.iform.ipaddr.disabled = 0;
|
226
|
document.iform.subnet.disabled = 0;
|
227
|
document.iform.gateway.disabled = 0;
|
228
|
break;
|
229
|
case 1:
|
230
|
document.iform.ipaddr.type.disabled = 1;
|
231
|
document.iform.ipaddr.disabled = 1;
|
232
|
document.iform.subnet.disabled = 1;
|
233
|
document.iform.gateway.disabled = 1;
|
234
|
break;
|
235
|
}
|
236
|
}
|
237
|
//-->
|
238
|
</script>
|
239
|
|
240
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
241
|
<?php include("fbegin.inc"); ?>
|
242
|
<p class="pgtitle"><?=$pgtitle?></p>
|
243
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
244
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
245
|
<?php if ($optcfg['if']): ?>
|
246
|
<form action="interfaces_opt.php" method="post" name="iform" id="iform">
|
247
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
248
|
<tr>
|
249
|
<td colspan="2" valign="top" class="listtopic">Optional Interface Configuration</td>
|
250
|
</tr>
|
251
|
<tr>
|
252
|
<td width="22%" valign="top" class="vtable"> </td>
|
253
|
<td width="78%" class="vtable">
|
254
|
<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
|
255
|
<strong>Enable Optional <?=$index;?> interface</strong></td>
|
256
|
</tr>
|
257
|
<tr>
|
258
|
<td width="22%" valign="top" class="vncell">Description</td>
|
259
|
<td width="78%" class="vtable">
|
260
|
<input name="descr" type="text" class="formfld" id="descr" size="30" value="<?=htmlspecialchars($pconfig['descr']);?>">
|
261
|
<br> <span class="vexpl">Enter a description (name) for the interface here.</span>
|
262
|
</td>
|
263
|
</tr>
|
264
|
|
265
|
<tr>
|
266
|
<td colspan="2" valign="top" height="16"></td>
|
267
|
</tr>
|
268
|
<tr>
|
269
|
<td colspan="2" valign="top" class="listtopic">General configuration</td>
|
270
|
</tr>
|
271
|
<tr>
|
272
|
<td valign="middle" class="vncell"><strong>Type</strong></td>
|
273
|
<td class="vtable"> <select name="type" class="formfld" id="type" onchange="type_change()">
|
274
|
<?php $opts = split(" ", "Static DHCP");
|
275
|
foreach ($opts as $opt): ?>
|
276
|
<option <?php if ($opt == $pconfig['type']) echo "selected";?>>
|
277
|
<?=htmlspecialchars($opt);?>
|
278
|
</option>
|
279
|
<?php endforeach; ?>
|
280
|
</select></td>
|
281
|
</tr>
|
282
|
<tr>
|
283
|
<td valign="top" class="vncell">MAC address</td>
|
284
|
<td class="vtable"> <input name="spoofmac" type="text" class="formfld" id="spoofmac" size="30" value="<?=htmlspecialchars($pconfig['spoofmac']);?>">
|
285
|
<?php
|
286
|
$ip = getenv('REMOTE_ADDR');
|
287
|
$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
|
288
|
$mac = str_replace("\n","",$mac);
|
289
|
?>
|
290
|
<a OnClick="document.forms[0].spoofmac.value='<?=$mac?>';" href="#">Copy my MAC address</a>
|
291
|
<br>
|
292
|
This field can be used to modify ("spoof") the MAC
|
293
|
address of the WAN interface<br>
|
294
|
(may be required with some cable connections)<br>
|
295
|
Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx
|
296
|
or leave blank</td>
|
297
|
</tr>
|
298
|
<tr>
|
299
|
<td valign="top" class="vncell">MTU</td>
|
300
|
<td class="vtable"> <input name="mtu" type="text" class="formfld" id="mtu" size="8" value="<?=htmlspecialchars($pconfig['mtu']);?>">
|
301
|
<br>
|
302
|
If you enter a value in this field, then MSS clamping for
|
303
|
TCP connections to the value entered above minus 40 (TCP/IP
|
304
|
header size) will be in effect. If you leave this field blank,
|
305
|
an MTU of 1492 bytes for PPPoE and 1500 bytes for all other
|
306
|
connection types will be assumed.</td>
|
307
|
</tr>
|
308
|
|
309
|
<tr>
|
310
|
<td colspan="2" valign="top" height="16"></td>
|
311
|
</tr>
|
312
|
<tr>
|
313
|
<td colspan="2" valign="top" class="listtopic">IP configuration</td>
|
314
|
</tr>
|
315
|
<tr>
|
316
|
<td width="22%" valign="top" class="vncellreq">Bridge with</td>
|
317
|
<td width="78%" class="vtable">
|
318
|
<select name="bridge" class="formfld" id="bridge" onChange="enable_change(false)">
|
319
|
<option <?php if (!$pconfig['bridge']) echo "selected";?> value="">none</option>
|
320
|
<?php $opts = array('lan' => "LAN", 'wan' => "WAN");
|
321
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
322
|
if ($i != $index)
|
323
|
$opts['opt' . $i] = "Optional " . $i . " (" .
|
324
|
$config['interfaces']['opt' . $i]['descr'] . ")";
|
325
|
}
|
326
|
foreach ($opts as $opt => $optname): ?>
|
327
|
<option <?php if ($opt == $pconfig['bridge']) echo "selected";?> value="<?=htmlspecialchars($opt);?>">
|
328
|
<?=htmlspecialchars($optname);?>
|
329
|
</option>
|
330
|
<?php endforeach; ?>
|
331
|
</select> </td>
|
332
|
</tr>
|
333
|
<tr>
|
334
|
<td width="22%" valign="top" class="vncellreq">IP address</td>
|
335
|
<td width="78%" class="vtable">
|
336
|
<input name="ipaddr" type="text" class="formfld" id="ipaddr" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>">
|
337
|
/
|
338
|
<select name="subnet" class="formfld" id="subnet">
|
339
|
<?php
|
340
|
for ($i = 32; $i > 0; $i--) {
|
341
|
if($i <> 31) {
|
342
|
echo "<option value=\"{$i}\" ";
|
343
|
if ($i == $pconfig['subnet']) echo "selected";
|
344
|
echo ">" . $i . "</option>";
|
345
|
}
|
346
|
}
|
347
|
?> </select>
|
348
|
</td>
|
349
|
</tr>
|
350
|
<tr>
|
351
|
<td width="22%" valign="top" class="vncell">Gateway</td>
|
352
|
<td width="78%" class="vtable">
|
353
|
<input name="gateway" value="<?php echo $pconfig['gateway']; ?>">
|
354
|
<br>
|
355
|
If you have multiple WAN connections, enter the next hop gateway (router) IP address here. Otherwise, leave this option blank.
|
356
|
</td>
|
357
|
</tr>
|
358
|
<tr>
|
359
|
<td colspan="2" valign="top" height="16"></td>
|
360
|
</tr>
|
361
|
<tr>
|
362
|
<td colspan="2" valign="top" class="listtopic">FTP Helper</td>
|
363
|
</tr>
|
364
|
<tr>
|
365
|
<td width="22%" valign="top" class="vncell">FTP Helper</td>
|
366
|
<td width="78%" class="vtable">
|
367
|
<input name="disableftpproxy" type="checkbox" id="disableftpproxy" value="yes" <?php if ($pconfig['disableftpproxy']) echo "checked"; ?> onclick="enable_change(false)" />
|
368
|
<strong>Disable the userland FTP-Proxy application</strong>
|
369
|
<br />
|
370
|
</td>
|
371
|
</tr>
|
372
|
<?php /* Wireless interface? */
|
373
|
if (isset($optcfg['wireless']))
|
374
|
wireless_config_print();
|
375
|
?>
|
376
|
<tr>
|
377
|
<td colspan="2" valign="top" height="16"></td>
|
378
|
</tr>
|
379
|
<tr>
|
380
|
<td colspan="2" valign="top" class="listtopic">DHCP client configuration</td>
|
381
|
</tr>
|
382
|
<tr>
|
383
|
<td valign="top" class="vncell">Hostname</td>
|
384
|
<td class="vtable"> <input name="dhcphostname" type="text" class="formfld" id="dhcphostname" size="40" value="<?=htmlspecialchars($pconfig['dhcphostname']);?>">
|
385
|
<br>
|
386
|
The value in this field is sent as the DHCP client identifier
|
387
|
and hostname when requesting a DHCP lease. Some ISPs may require
|
388
|
this (for client identification).</td>
|
389
|
</tr>
|
390
|
<tr>
|
391
|
<td colspan="2" valign="top" height="16"></td>
|
392
|
</tr>
|
393
|
<tr>
|
394
|
<td width="22%" valign="top"> </td>
|
395
|
<td width="78%">
|
396
|
<input name="index" type="hidden" value="<?=$index;?>">
|
397
|
<input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
|
398
|
</td>
|
399
|
</tr>
|
400
|
<tr>
|
401
|
<td width="22%" valign="top"> </td>
|
402
|
<td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
|
403
|
</strong></span>be sure to add <a href="firewall_rules.php">firewall rules</a> to permit traffic
|
404
|
through the interface. You also need firewall rules for an interface in
|
405
|
bridged mode as the firewall acts as a filtering bridge.</span></td>
|
406
|
</tr>
|
407
|
</table>
|
408
|
</form>
|
409
|
<script language="JavaScript">
|
410
|
<!--
|
411
|
enable_change(false);
|
412
|
//-->
|
413
|
</script>
|
414
|
<?php else: ?>
|
415
|
<p><strong>Optional <?=$index;?> has been disabled because there is no OPT<?=$index;?> interface.</strong></p>
|
416
|
<?php endif; ?>
|
417
|
<?php include("fend.inc"); ?>
|
418
|
</body>
|
419
|
</html>
|
420
|
|
421
|
<?php
|
422
|
if ($_POST) {
|
423
|
|
424
|
if (!$input_errors) {
|
425
|
|
426
|
ob_flush();
|
427
|
flush();
|
428
|
sleep(1);
|
429
|
|
430
|
interfaces_optional_configure_if($index);
|
431
|
|
432
|
reset_carp();
|
433
|
|
434
|
/* load graphing functions */
|
435
|
enable_rrd_graphing();
|
436
|
|
437
|
/* sync filter configuration */
|
438
|
filter_configure();
|
439
|
}
|
440
|
}
|
441
|
?>
|