Project

General

Profile

Download (18.2 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
$optcfg = &$config['interfaces']['opt' . $index];
52
$optcfg['descr'] = remove_bad_chars($optcfg['descr']);
53

    
54
$pconfig['descr'] = $optcfg['descr'];
55
$pconfig['bridge'] = $optcfg['bridge'];
56

    
57
$pconfig['enable'] = isset($optcfg['enable']);
58

    
59
$pconfig['blockpriv'] = isset($optcfg['blockpriv']);
60
$pconfig['blockbogons'] = isset($optcfg['blockbogons']);
61
$pconfig['spoofmac'] = $optcfg['spoofmac'];
62
$pconfig['mtu'] = $optcfg['mtu'];
63

    
64
$pconfig['disableftpproxy'] = isset($optcfg['disableftpproxy']);
65

    
66
/* Wireless interface? */
67
if (isset($optcfg['wireless'])) {
68
	require("interfaces_wlan.inc");
69
	wireless_config_init();
70
}
71

    
72
if ($optcfg['ipaddr'] == "dhcp") {
73
	$pconfig['type'] = "DHCP";
74
	$pconfig['dhcphostname'] = $optcfg['dhcphostname'];
75
	$pconfig['use_rrd_gateway'] = $optcfg['use_rrd_gateway'];
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
					$input_errors[] = "A valid IP address must be specified.";
159
				}
160
				if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
161
					$input_errors[] = "A valid subnet bit count must be specified.";
162
				}
163
				if($_POST['gateway'] <> "" && !is_ipaddr($_POST['gateway'])) {
164
					$input_errors[] = "A valid gateway must be specified.";
165
				}
166
			}
167
		}
168
	        if ($_POST['mtu'] && (($_POST['mtu'] < 576) || ($_POST['mtu'] > 1500))) {
169
			$input_errors[] = "The MTU must be between 576 and 1500 bytes.";
170
		}		
171
		if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) {
172
			$input_errors[] = "A valid MAC address must be specified.";
173
		}		
174
	}
175

    
176
	if($_POST['mtu']) {
177
		if($_POST['mtu'] < 24 or $_POST['mtu'] > 1501)
178
			$input_errors[] = "A valid MTU is required 24-1500.";
179
	}
180
	
181
	/* Wireless interface? */
182
	if (isset($optcfg['wireless'])) {
183
		$wi_input_errors = wireless_config_post();
184
		if ($wi_input_errors) {
185
			$input_errors = array_merge($input_errors, $wi_input_errors);
186
		}
187
	}
188

    
189
	if (!$input_errors) {
190

    
191
		$bridge = discover_bridge($optcfg['if'], filter_translate_type_to_real_interface($optcfg['bridge']));
192
		if($bridge <> "-1") {
193
			destroy_bridge($bridge);
194
		}
195

    
196
		unset($optcfg['dhcphostname']);
197
		unset($optcfg['disableftpproxy']);
198
		
199
		/* per interface pftpx helper */
200
		if($_POST['disableftpproxy'] == "yes") {
201
			$optcfg['disableftpproxy'] = true;
202
			system_start_ftp_helpers();
203
		} else {			
204
			system_start_ftp_helpers();
205
		}		
206

    
207
		$optcfg['descr'] = remove_bad_chars($_POST['descr']);
208
		$optcfg['bridge'] = $_POST['bridge'];
209
		$optcfg['enable'] = $_POST['enable'] ? true : false;
210

    
211
		/* per interface rrd gateway monitor helper */
212
		if($_POST['use_rrd_gateway'] <> "") {
213
			$optcfg['use_rrd_gateway'] = $_POST['use_rrd_gateway'];
214
		}
215

    
216
		if ($_POST['type'] == "Static") {
217
			$optcfg['ipaddr'] = $_POST['ipaddr'];
218
			$optcfg['subnet'] = $_POST['subnet'];
219
			$optcfg['gateway'] = $_POST['gateway'];
220
			if (isset($optcfg['ispointtopoint']))
221
				$optcfg['pointtopoint'] = $_POST['pointtopoint'];
222
		} else if ($_POST['type'] == "DHCP") {
223
			$optcfg['ipaddr'] = "dhcp";
224
			$optcfg['dhcphostname'] = $_POST['dhcphostname'];
225
		}
226

    
227
		$optcfg['blockpriv'] = $_POST['blockpriv'] ? true : false;
228
		$optcfg['blockbogons'] = $_POST['blockbogons'] ? true : false;
229
		$optcfg['spoofmac'] = $_POST['spoofmac'];
230
		$optcfg['mtu'] = $_POST['mtu'];
231

    
232
		write_config();
233
		
234
		$savemsg = get_std_save_message($retval);
235
	}
236
}
237

    
238

    
239
$pgtitle = "Interfaces: Optional {$index} (" . htmlspecialchars($optcfg['descr']) . ")";
240
include("head.inc");
241

    
242
?>
243

    
244
<script language="JavaScript">
245
<!--
246
function enable_change(enable_over) {
247
	var endis;
248
	endis = !((document.iform.bridge.selectedIndex == 0) || enable_over);
249
	document.iform.ipaddr.disabled = endis;
250
	document.iform.subnet.disabled = endis;
251
}
252
function ipaddr_change() {
253
	document.iform.subnet.selectedIndex = gen_bits_opt(document.iform.ipaddr.value);
254
}
255
function type_change(enable_change,enable_change_pptp) {
256
	switch (document.iform.type.selectedIndex) {
257
		case 0:
258
			document.iform.ipaddr.type.disabled = 0;
259
			document.iform.ipaddr.disabled = 0;
260
			document.iform.subnet.disabled = 0;
261
			document.iform.gateway.disabled = 0;
262
			break;
263
		case 1:
264
			document.iform.ipaddr.type.disabled = 1;
265
			document.iform.ipaddr.disabled = 1;
266
			document.iform.subnet.disabled = 1;
267
			document.iform.gateway.disabled = 1;
268
			break;
269
	}
270
}
271

    
272
function show_mon_config() {
273
	document.getElementById("showmonbox").innerHTML='';
274
	aodiv = document.getElementById('showmon');
275
	aodiv.style.display = "block";
276
}
277

    
278
//-->
279
</script>
280

    
281
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
282
<?php include("fbegin.inc"); ?>
283
<p class="pgtitle"><?=$pgtitle?></p>
284
<?php if ($input_errors) print_input_errors($input_errors); ?>
285
<?php if ($savemsg) print_info_box($savemsg); ?>
286
<?php if ($optcfg['if']): ?>
287
            <form action="interfaces_opt.php" method="post" name="iform" id="iform">
288
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
289
                <tr>
290
                  <td colspan="2" valign="top" class="listtopic">Optional Interface Configuration</td>
291
                </tr>	      
292
                <tr>
293
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
294
                  <td width="78%" class="vtable">
295
			<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
296
                    <strong>Enable Optional <?=$index;?> interface</strong></td>
297
		</tr>
298
                <tr>
299
                  <td width="22%" valign="top" class="vncell">Description</td>
300
                  <td width="78%" class="vtable">
301
                    <input name="descr" type="text" class="formfld" id="descr" size="30" value="<?=htmlspecialchars($pconfig['descr']);?>">
302
					<br> <span class="vexpl">Enter a description (name) for the interface here.</span>
303
		  </td>
304
		</tr>
305

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

    
478
<?php
479
if ($_POST) {
480

    
481
	if (!$input_errors) {
482
		
483
		ob_flush();
484
		flush();
485
		sleep(1);		
486
		
487
		interfaces_optional_configure_if($index);
488
		
489
		reset_carp();
490

    
491
		/* load graphing functions */
492
		enable_rrd_graphing();	
493
		
494
		/* sync filter configuration */
495
		filter_configure();
496
	}
497
}
498
?>
(76-76/183)