Project

General

Profile

Download (17 KB) Statistics
| Branch: | Tag: | Revision:
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
	if($_POST['gateway'] and $pconfig['gateway'] <> $_POST['gateway']) {
87
		/* enumerate slbd gateways and make sure we are not creating a route loop */
88
		if(is_array($config['load_balancer']['lbpool'])) {
89
			foreach($config['load_balancer']['lbpool'] as $lbpool) {
90
				if($lbpool['type'] == "gateway") {
91
				    foreach ((array) $lbpool['servers'] as $server) {
92
			            $svr = split("\|", $server);
93
			            if($svr[1] == $pconfig['gateway'])  {
94
			            		$_POST['gateway']  = $pconfig['gateway'];
95
			            		$input_errors[] = "Cannot change {$svr[1]} gateway.  It is currently referenced by the load balancer pools.";
96
			            }
97
					}
98
				}
99
			}
100
			foreach($config['filter']['rule'] as $rule) {
101
				if($rule['gateway'] == $pconfig['gateway']) {
102
	            		$_POST['gateway']  = $pconfig['gateway'];
103
	            		$input_errors[] = "Cannot change {$svr[1]} gateway.  It is currently referenced by the filter rules via policy based routing.";
104
				}
105
			}
106
		}
107
	}
108

    
109
	$pconfig = $_POST;
110

    
111
	/* input validation */
112
	if ($_POST['enable']) {
113

    
114
		/* description unique? */
115
		for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
116
			if ($i != $index) {
117
				if ($config['interfaces']['opt' . $i]['descr'] == $_POST['descr']) {
118
					$input_errors[] = "An interface with the specified description already exists.";
119
				}
120
			}
121
		}
122

    
123
		if ($_POST['bridge']) {
124
			/* double bridging? */
125
			for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
126
				if ($i != $index) {
127
					if ($config['interfaces']['opt' . $i]['bridge'] == $_POST['bridge']) {
128
						//$input_errors[] = "Optional interface {$i} " .
129
						//	"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
130
						//	"the specified interface.";
131
					} else if ($config['interfaces']['opt' . $i]['bridge'] == "opt{$index}") {
132
						//$input_errors[] = "Optional interface {$i} " .
133
						//	"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
134
						//	"this interface.";
135
					}
136
				}
137
			}
138
			if ($config['interfaces'][$_POST['bridge']]['bridge']) {
139
				//$input_errors[] = "The specified interface is already bridged to " .
140
				//	"another interface.";
141
			}
142
			/* captive portal on? */
143
			if (isset($config['captiveportal']['enable'])) {
144
				//$input_errors[] = "Interfaces cannot be bridged while the captive portal is enabled.";
145
			}
146
		} else {
147
			if ($_POST['type'] <> "DHCP") {
148
				$reqdfields = explode(" ", "descr ipaddr subnet");
149
				$reqdfieldsn = explode(",", "Description,IP address,Subnet bit count");
150
				do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
151
				if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
152
					$input_errors[] = "A valid IP address must be specified.";
153
				}
154
				if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
155
					$input_errors[] = "A valid subnet bit count must be specified.";
156
				}
157
				if($_POST['gateway'] <> "" && !is_ipaddr($_POST['gateway'])) {
158
					$input_errors[] = "A valid gateway must be specified.";
159
				}
160
			}
161
		}
162
	        if ($_POST['mtu'] && (($_POST['mtu'] < 576) || ($_POST['mtu'] > 1500))) {
163
			$input_errors[] = "The MTU must be between 576 and 1500 bytes.";
164
		}		
165
		if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) {
166
			$input_errors[] = "A valid MAC address must be specified.";
167
		}		
168
	}
169

    
170
	if($_POST['mtu']) {
171
		if($_POST['mtu'] < 24 or $_POST['mtu'] > 1501)
172
			$input_errors[] = "A valid MTU is required 24-1500.";
173
	}
174
	
175
	/* Wireless interface? */
176
	if (isset($optcfg['wireless'])) {
177
		$wi_input_errors = wireless_config_post();
178
		if ($wi_input_errors) {
179
			$input_errors = array_merge($input_errors, $wi_input_errors);
180
		}
181
	}
182

    
183
	if (!$input_errors) {
184

    
185
		$bridge = discover_bridge($optcfg['if'], filter_translate_type_to_real_interface($optcfg['bridge']));
186
		if($bridge <> "-1") {
187
			destroy_bridge($bridge);
188
		}
189

    
190
		unset($optcfg['dhcphostname']);
191
		unset($optcfg['disableftpproxy']);
192
		
193
		/* per interface pftpx helper */
194
		if($_POST['disableftpproxy'] == "yes") {
195
			$optcfg['disableftpproxy'] = true;
196
			system_start_ftp_helpers();
197
		} else {			
198
			system_start_ftp_helpers();
199
		}		
200

    
201
		$optcfg['descr'] = remove_bad_chars($_POST['descr']);
202
		$optcfg['bridge'] = $_POST['bridge'];
203
		$optcfg['enable'] = $_POST['enable'] ? true : false;
204

    
205
		if ($_POST['type'] == "Static") {
206
			$optcfg['ipaddr'] = $_POST['ipaddr'];
207
			$optcfg['subnet'] = $_POST['subnet'];
208
			$optcfg['gateway'] = $_POST['gateway'];
209
			if (isset($optcfg['ispointtopoint']))
210
				$optcfg['pointtopoint'] = $_POST['pointtopoint'];
211
		} else if ($_POST['type'] == "DHCP") {
212
			$optcfg['ipaddr'] = "dhcp";
213
			$optcfg['dhcphostname'] = $_POST['dhcphostname'];
214
		}
215

    
216
		$optcfg['blockpriv'] = $_POST['blockpriv'] ? true : false;
217
		$optcfg['blockbogons'] = $_POST['blockbogons'] ? true : false;
218
		$optcfg['spoofmac'] = $_POST['spoofmac'];
219
		$optcfg['mtu'] = $_POST['mtu'];
220

    
221
		write_config();
222
		
223
		$savemsg = get_std_save_message($retval);
224
	}
225
}
226

    
227

    
228
$pgtitle = "Interfaces: Optional {$index} (" . htmlspecialchars($optcfg['descr']) . ")";
229
include("head.inc");
230

    
231
?>
232

    
233
<script language="JavaScript">
234
<!--
235
function enable_change(enable_over) {
236
	var endis;
237
	endis = !((document.iform.bridge.selectedIndex == 0) || enable_over);
238
	document.iform.ipaddr.disabled = endis;
239
	document.iform.subnet.disabled = endis;
240
}
241
function ipaddr_change() {
242
	document.iform.subnet.selectedIndex = gen_bits_opt(document.iform.ipaddr.value);
243
}
244
function type_change(enable_change,enable_change_pptp) {
245
	switch (document.iform.type.selectedIndex) {
246
		case 0:
247
			document.iform.ipaddr.type.disabled = 0;
248
			document.iform.ipaddr.disabled = 0;
249
			document.iform.subnet.disabled = 0;
250
			document.iform.gateway.disabled = 0;
251
			break;
252
		case 1:
253
			document.iform.ipaddr.type.disabled = 1;
254
			document.iform.ipaddr.disabled = 1;
255
			document.iform.subnet.disabled = 1;
256
			document.iform.gateway.disabled = 1;
257
			break;
258
	}
259
}
260
//-->
261
</script>
262

    
263
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
264
<?php include("fbegin.inc"); ?>
265
<p class="pgtitle"><?=$pgtitle?></p>
266
<?php if ($input_errors) print_input_errors($input_errors); ?>
267
<?php if ($savemsg) print_info_box($savemsg); ?>
268
<?php if ($optcfg['if']): ?>
269
            <form action="interfaces_opt.php" method="post" name="iform" id="iform">
270
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
271
                <tr>
272
                  <td colspan="2" valign="top" class="listtopic">Optional Interface Configuration</td>
273
                </tr>	      
274
                <tr>
275
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
276
                  <td width="78%" class="vtable">
277
			<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
278
                    <strong>Enable Optional <?=$index;?> interface</strong></td>
279
		</tr>
280
                <tr>
281
                  <td width="22%" valign="top" class="vncell">Description</td>
282
                  <td width="78%" class="vtable">
283
                    <input name="descr" type="text" class="formfld" id="descr" size="30" value="<?=htmlspecialchars($pconfig['descr']);?>">
284
					<br> <span class="vexpl">Enter a description (name) for the interface here.</span>
285
		  </td>
286
		</tr>
287

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

    
444
<?php
445
if ($_POST) {
446

    
447
	if (!$input_errors) {
448
		
449
		ob_flush();
450
		flush();
451
		sleep(1);		
452
		
453
		interfaces_optional_configure_if($index);
454
		
455
		reset_carp();
456

    
457
		/* load graphing functions */
458
		enable_rrd_graphing();	
459
		
460
		/* sync filter configuration */
461
		filter_configure();
462
	}
463
}
464
?>
(66-66/164)