Project

General

Profile

Download (15.9 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
	$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
		touch("/tmp/reload_interfaces");
201
		
202
		/* sync filter configuration */
203
		filter_configure();
204

    
205
		$savemsg = get_std_save_message($retval);
206
	}
207
}
208

    
209

    
210
$pgtitle = "Interfaces: Optional {$index} (" . htmlspecialchars($optcfg['descr']) . ")";
211
include("head.inc");
212

    
213
?>
214

    
215
<script language="JavaScript">
216
<!--
217
function enable_change(enable_over) {
218
	var endis;
219
	endis = !((document.iform.bridge.selectedIndex == 0) || enable_over);
220
	document.iform.ipaddr.disabled = endis;
221
	document.iform.subnet.disabled = endis;
222
}
223
function ipaddr_change() {
224
	document.iform.subnet.selectedIndex = gen_bits_opt(document.iform.ipaddr.value);
225
}
226
function type_change(enable_change,enable_change_pptp) {
227
	switch (document.iform.type.selectedIndex) {
228
		case 0:
229
			document.iform.ipaddr.type.disabled = 0;
230
			document.iform.ipaddr.disabled = 0;
231
			document.iform.subnet.disabled = 0;
232
			document.iform.gateway.disabled = 0;
233
			break;
234
		case 1:
235
			document.iform.ipaddr.type.disabled = 1;
236
			document.iform.ipaddr.disabled = 1;
237
			document.iform.subnet.disabled = 1;
238
			document.iform.gateway.disabled = 1;
239
			break;
240
	}
241
}
242
//-->
243
</script>
244

    
245
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
246
<?php include("fbegin.inc"); ?>
247
<p class="pgtitle"><?=$pgtitle?></p>
248
<?php if ($input_errors) print_input_errors($input_errors); ?>
249
<?php if ($savemsg) print_info_box($savemsg); ?>
250
<?php if ($optcfg['if']): ?>
251
            <form action="interfaces_opt.php" method="post" name="iform" id="iform">
252
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
253
                <tr>
254
                  <td colspan="2" valign="top" class="listtopic">Optional Interface Configuration</td>
255
                </tr>	      
256
                <tr>
257
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
258
                  <td width="78%" class="vtable">
259
			<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
260
                    <strong>Enable Optional <?=$index;?> interface</strong></td>
261
		</tr>
262
                <tr>
263
                  <td width="22%" valign="top" class="vncell">Description</td>
264
                  <td width="78%" class="vtable">
265
                    <input name="descr" type="text" class="formfld" id="descr" size="30" value="<?=htmlspecialchars($pconfig['descr']);?>">
266
					<br> <span class="vexpl">Enter a description (name) for the interface here.</span>
267
		  </td>
268
		</tr>
269

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