Project

General

Profile

Download (19.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
        interfaces_opt.php
5
	Copyright (C) 2007 Scott Ullrich
6
        All rights reserved.
7

    
8
	interfaces_opt.php
9
	part of m0n0wall (http://m0n0.ch/wall)
10

    
11
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
	All rights reserved.
13

    
14
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16

    
17
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19

    
20
	2. Redistributions in binary form must reproduce the above copyright
21
	   notice, this list of conditions and the following disclaimer in the
22
	   documentation and/or other materials provided with the distribution.
23

    
24
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
	POSSIBILITY OF SUCH DAMAGE.
34
*/
35

    
36
require("guiconfig.inc");
37

    
38
unset($index);
39
if ($_GET['index'])
40
	$index = $_GET['index'];
41
else if ($_POST['index'])
42
	$index = $_POST['index'];
43

    
44
if (!$index)
45
	exit;
46

    
47
function remove_bad_chars($string) {
48
	return preg_replace('/[^a-z|_|0-9]/i','',$string);
49
}
50

    
51
if (!is_array($config['gateways']['gateway_item']))
52
	$config['gateways']['gateway_item'] = array();
53
$a_gateways = &$config['gateways']['gateway_item'];
54

    
55
$optcfg = &$config['interfaces']['opt' . $index];
56
$optcfg['descr'] = remove_bad_chars($optcfg['descr']);
57

    
58
$pconfig['descr'] = $optcfg['descr'];
59
$pconfig['bridge'] = $optcfg['bridge'];
60

    
61
$pconfig['enable'] = isset($optcfg['enable']);
62

    
63
$pconfig['blockpriv'] = isset($optcfg['blockpriv']);
64
$pconfig['blockbogons'] = isset($optcfg['blockbogons']);
65
$pconfig['spoofmac'] = $optcfg['spoofmac'];
66
$pconfig['mtu'] = $optcfg['mtu'];
67

    
68
$pconfig['disableftpproxy'] = isset($optcfg['disableftpproxy']);
69

    
70
/* Wireless interface? */
71
if (isset($optcfg['wireless'])) {
72
	require("interfaces_wlan.inc");
73
	wireless_config_init();
74
}
75

    
76
if ($optcfg['ipaddr'] == "dhcp") {
77
	$pconfig['type'] = "DHCP";
78
	$pconfig['dhcphostname'] = $optcfg['dhcphostname'];
79
	$pconfig['alias-address'] = $optcfg['alias-address'];
80
	$pconfig['alias-subnet'] = $optcfg['alias-subnet'];
81
} else {
82
	$pconfig['type'] = "Static";
83
	$pconfig['ipaddr'] = $optcfg['ipaddr'];
84
	$pconfig['subnet'] = $optcfg['subnet'];
85
	$pconfig['gateway'] = $optcfg['gateway'];
86
	$pconfig['pointtopoint'] = $optcfg['pointtopoint'];
87
}
88

    
89
if ($_POST) {
90

    
91
	unset($input_errors);
92

    
93
	/* filter out spaces from descriptions  */
94
	$POST['descr'] = remove_bad_chars($POST['descr']);
95

    
96
	if($_POST['gateway'] and $pconfig['gateway'] <> $_POST['gateway']) {
97
		/* enumerate slbd gateways and make sure we are not creating a route loop */
98
		if(is_array($config['load_balancer']['lbpool'])) {
99
			foreach($config['load_balancer']['lbpool'] as $lbpool) {
100
				if($lbpool['type'] == "gateway") {
101
				    foreach ((array) $lbpool['servers'] as $server) {
102
			            $svr = split("\|", $server);
103
			            if($svr[1] == $pconfig['gateway'])  {
104
			            		$_POST['gateway']  = $pconfig['gateway'];
105
			            		$input_errors[] = "Cannot change {$svr[1]} gateway.  It is currently referenced by the load balancer pools.";
106
			            		break;
107
			            }
108
					}
109
				}
110
			}
111
			foreach($config['filter']['rule'] as $rule) {
112
				if($rule['gateway'] == $_POST['gateway']) {
113
	            		$input_errors[] = "Cannot change {$_POST['gateway']} gateway.  It is currently referenced by the filter rules via policy based routing.";
114
	            		break;
115
				}
116
			}
117
		}
118
	}
119

    
120
	$pconfig = $_POST;
121

    
122
	/* input validation */
123
	if ($_POST['enable']) {
124

    
125
		/* description unique? */
126
		for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
127
			if ($i != $index) {
128
				if ($config['interfaces']['opt' . $i]['descr'] == $_POST['descr']) {
129
					$input_errors[] = "An interface with the specified description already exists.";
130
				}
131
			}
132
		}
133

    
134
		if ($_POST['bridge']) {
135
			/* double bridging? */
136
			for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
137
				if ($i != $index) {
138
					if ($config['interfaces']['opt' . $i]['bridge'] == $_POST['bridge']) {
139
						//$input_errors[] = "Optional interface {$i} " .
140
						//	"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
141
						//	"the specified interface.";
142
					} else if ($config['interfaces']['opt' . $i]['bridge'] == "opt{$index}") {
143
						//$input_errors[] = "Optional interface {$i} " .
144
						//	"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
145
						//	"this interface.";
146
					}
147
				}
148
			}
149
			if ($config['interfaces'][$_POST['bridge']]['bridge']) {
150
				//$input_errors[] = "The specified interface is already bridged to " .
151
				//	"another interface.";
152
			}
153
			/* captive portal on? */
154
			if (isset($config['captiveportal']['enable'])) {
155
				//$input_errors[] = "Interfaces cannot be bridged while the captive portal is enabled.";
156
			}
157
		} else {
158
			if ($_POST['type'] <> "DHCP") {
159
				$reqdfields = explode(" ", "descr ipaddr subnet");
160
				$reqdfieldsn = explode(",", "Description,IP address,Subnet bit count");
161
				do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
162
				if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
163
					$input_errors[] = "A valid IP address must be specified.";
164
				}
165
				if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
166
					$input_errors[] = "A valid subnet bit count must be specified.";
167
				}
168
				if ($_POST['gateway']) {
169
					$match = false;
170
					foreach($a_gateways as $gateway) {
171
						if(in_array($_POST['gateway'], $gateway)) {
172
							$match = true;
173
						}
174
					}
175
					if(!$match)
176
						$input_errors[] = "A valid gateway must be specified.";
177
				}
178
			}
179
		}
180
		if (($_POST['alias-address'] && !is_ipaddr($_POST['alias-address']))) {
181
			$input_errors[] = "A valid alias IP address must be specified.";
182
		}
183
		if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) {
184
			$input_errors[] = "A valid alias subnet bit count must be specified.";
185
		}
186

    
187
	        if ($_POST['mtu'] && (($_POST['mtu'] < 576) || ($_POST['mtu'] > 1500))) {
188
			$input_errors[] = "The MTU must be between 576 and 1500 bytes.";
189
		}		
190
		if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) {
191
			$input_errors[] = "A valid MAC address must be specified.";
192
		}		
193
	}
194

    
195
	if($_POST['mtu']) {
196
		if($_POST['mtu'] < 24 or $_POST['mtu'] > 1501)
197
			$input_errors[] = "A valid MTU is required 24-1500.";
198
	}
199
	
200
	/* Wireless interface? */
201
	if (isset($optcfg['wireless'])) {
202
		$wi_input_errors = wireless_config_post();
203
		if ($wi_input_errors) {
204
			$input_errors = array_merge($input_errors, $wi_input_errors);
205
		}
206
	}
207

    
208
	if (!$input_errors) {
209

    
210
		$bridge = discover_bridge($optcfg['if'], filter_translate_type_to_real_interface($optcfg['bridge']));
211
		if($bridge <> "-1") {
212
			destroy_bridge($bridge);
213
		}
214

    
215
		unset($optcfg['dhcphostname']);
216
		unset($optcfg['disableftpproxy']);
217
		
218
		/* per interface pftpx helper */
219
		if($_POST['disableftpproxy'] == "yes") {
220
			$optcfg['disableftpproxy'] = true;
221
			system_start_ftp_helpers();
222
		} else {			
223
			system_start_ftp_helpers();
224
		}		
225

    
226
		$optcfg['descr'] = remove_bad_chars($_POST['descr']);
227
		$optcfg['bridge'] = $_POST['bridge'];
228
		$optcfg['enable'] = $_POST['enable'] ? true : false;
229

    
230
		if ($_POST['type'] == "Static") {
231
			$optcfg['ipaddr'] = $_POST['ipaddr'];
232
			$optcfg['subnet'] = $_POST['subnet'];
233
			$optcfg['gateway'] = $_POST['gateway'];
234
			if (isset($optcfg['ispointtopoint']))
235
				$optcfg['pointtopoint'] = $_POST['pointtopoint'];
236
		} else if ($_POST['type'] == "DHCP") {
237
			$optcfg['ipaddr'] = "dhcp";
238
			$optcfg['dhcphostname'] = $_POST['dhcphostname'];
239
			$optcfg['alias-address'] = $_POST['alias-address'];
240
			$optcfg['alias-subnet'] = $_POST['alias-subnet'];
241
		}
242

    
243
		$optcfg['blockpriv'] = $_POST['blockpriv'] ? true : false;
244
		$optcfg['blockbogons'] = $_POST['blockbogons'] ? true : false;
245
		$optcfg['spoofmac'] = $_POST['spoofmac'];
246
		$optcfg['mtu'] = $_POST['mtu'];
247

    
248
		write_config();
249
		
250
		$savemsg = get_std_save_message($retval);
251
	}
252
}
253

    
254

    
255
$pgtitle = array("Interfaces","Optional {$index} (" . htmlspecialchars($optcfg['descr']) . ")");
256
include("head.inc");
257

    
258
?>
259

    
260
<script language="JavaScript">
261
<!--
262
function enable_change(enable_over) {
263
	var endis;
264
	endis = !((document.iform.bridge.selectedIndex == 0) || enable_over);
265
	document.iform.ipaddr.disabled = endis;
266
	document.iform.subnet.disabled = endis;
267
}
268
function ipaddr_change() {
269
	document.iform.subnet.selectedIndex = gen_bits_opt(document.iform.ipaddr.value);
270
}
271
function type_change(enable_change,enable_change_pptp) {
272
	switch (document.iform.type.selectedIndex) {
273
		case 0:
274
			document.iform.ipaddr.type.disabled = 0;
275
			document.iform.ipaddr.disabled = 0;
276
			document.iform.subnet.disabled = 0;
277
			document.iform.gateway.disabled = 0;
278
			break;
279
		case 1:
280
			document.iform.ipaddr.type.disabled = 1;
281
			document.iform.ipaddr.disabled = 1;
282
			document.iform.subnet.disabled = 1;
283
			document.iform.gateway.disabled = 1;
284
			break;
285
	}
286
}
287

    
288
function show_mon_config() {
289
	document.getElementById("showmonbox").innerHTML='';
290
	aodiv = document.getElementById('showmon');
291
	aodiv.style.display = "block";
292
}
293

    
294
//-->
295
</script>
296

    
297
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
298
<?php include("fbegin.inc"); ?>
299
<?php if ($input_errors) print_input_errors($input_errors); ?>
300
<?php if ($savemsg) print_info_box($savemsg); ?>
301
<?php if ($optcfg['if']): ?>
302
            <form action="interfaces_opt.php" method="post" name="iform" id="iform">
303
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
304
                <tr>
305
                  <td colspan="2" valign="top" class="listtopic">Optional Interface Configuration</td>
306
                </tr>	      
307
                <tr>
308
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
309
                  <td width="78%" class="vtable">
310
			<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
311
                    <strong>Enable Optional <?=$index;?> interface</strong></td>
312
		</tr>
313
                <tr>
314
                  <td width="22%" valign="top" class="vncell">Description</td>
315
                  <td width="78%" class="vtable">
316
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="30" value="<?=htmlspecialchars($pconfig['descr']);?>">
317
					<br> <span class="vexpl">Enter a description (name) for the interface here.</span>
318
		  </td>
319
		</tr>
320

    
321
                <tr>
322
                  <td colspan="2" valign="top" height="16"></td>
323
                </tr>
324
                <tr>
325
                  <td colspan="2" valign="top" class="listtopic">General configuration</td>
326
                </tr>
327
                <tr>
328
                  <td valign="middle" class="vncell"><strong>Type</strong></td>
329
                  <td class="vtable"> <select name="type" class="formselect" id="type" onchange="type_change()">
330
                      <?php $opts = split(" ", "Static DHCP");
331
				foreach ($opts as $opt): ?>
332
                      <option <?php if ($opt == $pconfig['type']) echo "selected";?>>
333
                      <?=htmlspecialchars($opt);?>
334
                      </option>
335
                      <?php endforeach; ?>
336
                    </select></td>
337
                </tr>
338
                <tr>
339
                  <td valign="top" class="vncell">MAC address</td>
340
                  <td class="vtable"> <input name="spoofmac" type="text" class="formfld unknown" id="spoofmac" size="30" value="<?=htmlspecialchars($pconfig['spoofmac']);?>">
341
		    <?php
342
			$ip = getenv('REMOTE_ADDR');
343
			$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
344
			$mac = str_replace("\n","",$mac);
345
		    ?>
346
		    <a OnClick="document.forms[0].spoofmac.value='<?=$mac?>';" href="#">Copy my MAC address</a>   
347
		    <br>
348
                    This field can be used to modify (&quot;spoof&quot;) the MAC
349
                    address of the WAN interface<br>
350
                    (may be required with some cable connections)<br>
351
                    Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx
352
                    or leave blank</td>
353
                </tr>
354
                <tr>
355
                  <td valign="top" class="vncell">MTU</td>
356
                  <td class="vtable"> <input name="mtu" type="text" class="formfld unknown" id="mtu" size="8" value="<?=htmlspecialchars($pconfig['mtu']);?>">
357
                    <br>
358
                    If you enter a value in this field, then MSS clamping for
359
                    TCP connections to the value entered above minus 40 (TCP/IP
360
                    header size) will be in effect. If you leave this field blank,
361
                    an MTU of 1492 bytes for PPPoE and 1500 bytes for all other
362
                    connection types will be assumed.</td>
363
                </tr>
364
		
365
                <tr>
366
                  <td colspan="2" valign="top" height="16"></td>
367
		</tr>
368
		<tr>
369
                  <td colspan="2" valign="top" class="listtopic">IP configuration</td>
370
		</tr>
371
		<tr>
372
                  <td width="22%" valign="top" class="vncellreq">Bridge with</td>
373
                  <td width="78%" class="vtable">
374
			<select name="bridge" class="formselect" id="bridge" onChange="enable_change(false)">
375
				  	<option <?php if (!$pconfig['bridge']) echo "selected";?> value="">none</option>
376
                      <?php $opts = array('lan' => "LAN", 'wan' => "WAN");
377
					  	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
378
							if ($i != $index)
379
								$opts['opt' . $i] = "Optional " . $i . " (" .
380
									$config['interfaces']['opt' . $i]['descr'] . ")";
381
						}
382
					foreach ($opts as $opt => $optname): ?>
383
                      <option <?php if ($opt == $pconfig['bridge']) echo "selected";?> value="<?=htmlspecialchars($opt);?>">
384
                      <?=htmlspecialchars($optname);?>
385
                      </option>
386
                      <?php endforeach; ?>
387
                    </select> </td>
388
		</tr>
389
                <tr>
390
                  <td width="22%" valign="top" class="vncellreq">IP address</td>
391
                  <td width="78%" class="vtable">
392
                    <input name="ipaddr" type="text" class="formfld unknown" id="ipaddr" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>">
393
                    /
394
                	<select name="subnet" class="formselect" id="subnet">
395
					<?php
396
					for ($i = 32; $i > 0; $i--) {
397
						if($i <> 31) {
398
							echo "<option value=\"{$i}\" ";
399
							if ($i == $pconfig['subnet']) echo "selected";
400
							echo ">" . $i . "</option>";
401
						}
402
					}
403
					?>                    </select>
404
				 </td>
405
				</tr>
406
		<tr>
407
		  <td valign="top" class="vncellreq">Gateway</td>
408
		  <td class="vtable"><select name="gateway" class="formselect" id="gateway">
409
			<?php
410
			if(count($a_gateways) > 0) {
411
				foreach ($a_gateways as $gateway) {
412
					if($gateway['interface'] == "opt{$index}") {
413
			?>
414
				<option value="<?=$gateway['name'];?>" <?php if ($gateway['name'] == $pconfig['gateway']) echo "selected"; ?>>
415
				<?=htmlspecialchars($gateway['name']);?>
416
				</option>
417
			<?php
418
					}
419
				}
420
			}
421
			?>
422
			</select>Select a existing Gateway from the list or add one on the <a href="/system_gateways.php">Gateways</a> page<br>
423
		  </td>
424
		</tr>
425
                <tr>
426
                  <td colspan="2" valign="top" height="16"></td>
427
                </tr>
428
                <tr>
429
                  <td colspan="2" valign="top" class="listtopic">Other</td>
430
                </tr>		
431
		<tr>
432
			<td width="22%" valign="top" class="vncell">FTP Helper</td>
433
			<td width="78%" class="vtable">
434
				<input name="disableftpproxy" type="checkbox" id="disableftpproxy" value="yes" <?php if ($pconfig['disableftpproxy']) echo "checked"; ?> onclick="enable_change(false)" />
435
				<strong>Disable the userland FTP-Proxy application</strong>
436
				<br />
437
			</td>
438
		</tr>
439
				<?php /* Wireless interface? */
440
				if (isset($optcfg['wireless']))
441
					wireless_config_print();
442
				?>		
443
                <tr>
444
                  <td colspan="2" valign="top" height="16"></td>
445
                </tr>
446
                <tr>
447
                  <td colspan="2" valign="top" class="listtopic">DHCP client configuration</td>
448
                </tr>
449
                <tr>
450
                  <td valign="top" class="vncell">Hostname</td>
451
                  <td class="vtable"> <input name="dhcphostname" type="text" class="formfld unknown" id="dhcphostname" size="40" value="<?=htmlspecialchars($pconfig['dhcphostname']);?>">
452
                    <br>
453
                    The value in this field is sent as the DHCP client identifier
454
                    and hostname when requesting a DHCP lease. Some ISPs may require
455
                    this (for client identification).</td>
456
                </tr>
457
		<tr>
458
		  <td width="100" valign="top" class="vncellreq">Alias IP address</td>
459
		  <td class="vtable"> <input name="alias-address" type="text" class="formfld unknown" id="alias-address" size="20" value="<?=htmlspecialchars($pconfig['alias-address']);?>">
460
		    <select name="alias-subnet" class="formselect" id="alias-subnet">
461
		        <?php
462
		        for ($i = 32; $i > 0; $i--) {
463
		                if($i <> 31) {
464
		                        echo "<option value=\"{$i}\" ";
465
		                        if ($i == $pconfig['alias-subnet']) echo "selected";
466
		                        echo ">" . $i . "</option>";
467
		                }
468
		        }
469
		        ?>
470
		    </select>
471
		    The value in this field is used as a fixed alias IP address by the
472
		    DHCP client.</td>
473
		</tr>
474
                <tr>
475
                  <td colspan="2" valign="top" height="16"></td>
476
                </tr>		
477
		<tr>
478
                  <td width="22%" valign="top">&nbsp;</td>
479
                  <td width="78%">
480
                    <input name="index" type="hidden" value="<?=$index;?>">
481
				  <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
482
                  </td>
483
                </tr>
484
                <tr>
485
                  <td width="22%" valign="top">&nbsp;</td>
486
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
487
                    </strong></span>be sure to add <a href="firewall_rules.php">firewall rules</a> to permit traffic
488
                    through the interface. You also need firewall rules for an interface in
489
                    bridged mode as the firewall acts as a filtering bridge.</span></td>
490
                </tr>
491
              </table>
492
</form>
493
<script language="JavaScript">
494
<!--
495
enable_change(false);
496
//-->
497
</script>
498
<?php else: ?>
499
<p><strong>Optional <?=$index;?> has been disabled because there is no OPT<?=$index;?> interface.</strong></p>
500
<?php endif; ?>
501
<?php include("fend.inc"); ?>
502
</body>
503
</html>
504

    
505
<?php
506
if ($_POST) {
507

    
508
	if (!$input_errors) {
509
		
510
		ob_flush();
511
		flush();
512
		sleep(1);		
513
		
514
		interfaces_optional_configure_if($index);
515
		
516
		reset_carp();
517

    
518
		/* load graphing functions */
519
		enable_rrd_graphing();	
520
		
521
		/* sync filter configuration */
522
		filter_configure();
523

    
524
 		/* set up static routes */
525
		system_routing_configure();
526

    
527
	}
528
}
529
?>
(76-76/187)