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