Project

General

Profile

Download (15 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	interfaces_opt.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7

    
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10

    
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13

    
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16

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

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

    
33
require("guiconfig.inc");
34

    
35
unset($index);
36
if ($_GET['index'])
37
	$index = $_GET['index'];
38
else if ($_POST['index'])
39
	$index = $_POST['index'];
40

    
41
if (!$index)
42
	exit;
43

    
44
$optcfg = &$config['interfaces']['opt' . $index];
45
$optcfg['descr'] = str_replace(" ", "_", $optcfg['descr']);
46

    
47
$pconfig['descr'] = str_replace(" ", "_", $optcfg['descr']);
48
$pconfig['bridge'] = $optcfg['bridge'];
49

    
50
$pconfig['bandwidth'] = $optcfg['bandwidth'];
51
$pconfig['bandwidthtype'] = $optcfg['bandwidthtype'];
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
/* Wireless interface? */
61
if (isset($optcfg['wireless'])) {
62
	require("interfaces_wlan.inc");
63
	wireless_config_init();
64
}
65

    
66
if ($optcfg['ipaddr'] == "dhcp") {
67
	$pconfig['type'] = "DHCP";
68
} else {
69
	$pconfig['type'] = "Static";
70
	$pconfig['ipaddr'] = $optcfg['ipaddr'];
71
	$pconfig['subnet'] = $optcfg['subnet'];
72
	$pconfig['gateway'] = $optcfg['gateway'];
73
	$pconfig['pointtopoint'] = $optcfg['pointtopoint'];
74
}
75

    
76
if ($_POST) {
77

    
78
	unset($input_errors);
79

    
80
	/* filter out spaces from descriptions  */
81
	$POST['descr'] = str_replace(" ", "_", $POST['descr']);
82

    
83
	$pconfig = $_POST;
84

    
85
	/* input validation */
86
	if ($_POST['enable']) {
87

    
88
		/* description unique? */
89
		for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
90
			if ($i != $index) {
91
				if ($config['interfaces']['opt' . $i]['descr'] == $_POST['descr']) {
92
					$input_errors[] = "An interface with the specified description already exists.";
93
				}
94
			}
95
		}
96

    
97
		if ($_POST['bridge']) {
98
			/* double bridging? */
99
			for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
100
				if ($i != $index) {
101
					if ($config['interfaces']['opt' . $i]['bridge'] == $_POST['bridge']) {
102
						$input_errors[] = "Optional interface {$i} " .
103
							"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
104
							"the specified interface.";
105
					} else if ($config['interfaces']['opt' . $i]['bridge'] == "opt{$index}") {
106
						$input_errors[] = "Optional interface {$i} " .
107
							"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
108
							"this interface.";
109
					}
110
				}
111
			}
112
			if ($config['interfaces'][$_POST['bridge']]['bridge']) {
113
				$input_errors[] = "The specified interface is already bridged to " .
114
					"another interface.";
115
			}
116
			/* captive portal on? */
117
			if (isset($config['captiveportal']['enable'])) {
118
				$input_errors[] = "Interfaces cannot be bridged while the captive portal is enabled.";
119
			}
120
		} else {
121
			$reqdfields = explode(" ", "descr");
122
			$reqdfieldsn = explode(",", "Description");
123

    
124
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
125

    
126
			if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
127
				$input_errors[] = "A valid IP address must be specified.";
128
			}
129
			if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
130
				$input_errors[] = "A valid subnet bit count must be specified.";
131
			}
132
		}
133
	}
134

    
135
	/* Wireless interface? */
136
	if (isset($optcfg['wireless'])) {
137
		$wi_input_errors = wireless_config_post();
138
		if ($wi_input_errors) {
139
			$input_errors = array_merge($input_errors, $wi_input_errors);
140
		}
141
	}
142

    
143
	if (!$input_errors) {
144

    
145
		$optcfg['descr'] = str_replace(" ", "_", $_POST['descr']);
146
		$optcfg['bridge'] = $_POST['bridge'];
147
		$optcfg['enable'] = $_POST['enable'] ? true : false;
148
		
149
		if($_POST['bandwidth'] <> "" and $_POST['bandwidthtype'] <> "") {
150
			$optcfg['bandwidth'] = $_POST['bandwidth'];
151
			$optcfg['bandwidthtype'] = $_POST['bandwidthtype'];
152
		} else {
153
			unset($optcfg['bandwidth']);
154
			unset($optcfg['bandwidthtype']);
155
		}
156

    
157
		if ($_POST['type'] == "Static") {
158
			$optcfg['ipaddr'] = $_POST['ipaddr'];
159
			$optcfg['subnet'] = $_POST['subnet'];
160
			$optcfg['gateway'] = $_POST['gateway'];
161
			if (isset($optcfg['ispointtopoint']))
162
				$optcfg['pointtopoint'] = $_POST['pointtopoint'];
163
		} else if ($_POST['type'] == "DHCP") {
164
			$optcfg['ipaddr'] = "dhcp";
165
			$optcfg['dhcphostname'] = $_POST['dhcphostname'];
166
		}
167

    
168
		$optcfg['blockpriv'] = $_POST['blockpriv'] ? true : false;
169
		$optcfg['blockbogons'] = $_POST['blockbogons'] ? true : false;
170
		$optcfg['spoofmac'] = $_POST['spoofmac'];
171
		$optcfg['mtu'] = $_POST['mtu'];
172

    
173
		write_config();
174

    
175
		$retval = interfaces_optional_configure();
176

    
177
		/* is this the captive portal interface? */
178
		if (isset($config['captiveportal']['enable']) &&
179
			($config['captiveportal']['interface'] == ('opt' . $index))) {
180
			captiveportal_configure();
181
		}
182
		config_unlock();
183
		
184
		/* setup carp interfaces */
185
		interfaces_carp_configure();
186
	
187
		/* bring up carp interfaces */
188
		interfaces_carp_bringup();
189

    
190
		/* sync filter configuration */
191
		filter_configure();
192

    
193
		$savemsg = "The changes have been applied.";
194
	}
195
}
196

    
197

    
198
$pgtitle = "Interfaces: Optional {$index} (" . htmlspecialchars($optcfg['descr']) . ")";
199
include("head.inc");
200

    
201
?>
202

    
203
<script type="text/javascript" language="javascript" src="ip_helper.js">
204
</script>
205
<script language="JavaScript">
206
<!--
207
function enable_change(enable_over) {
208
	var endis;
209
	endis = !((document.iform.bridge.selectedIndex == 0) || enable_over);
210
	document.iform.ipaddr.disabled = endis;
211
	document.iform.subnet.disabled = endis;
212
}
213
function ipaddr_change() {
214
	document.iform.subnet.selectedIndex = gen_bits_opt(document.iform.ipaddr.value);
215
}
216
function type_change(enable_change,enable_change_pptp) {
217
	switch (document.iform.type.selectedIndex) {
218
		case 0:
219
			document.iform.ipaddr.type.disabled = 0;
220
			document.iform.ipaddr.disabled = 0;
221
			document.iform.subnet.disabled = 0;
222
			document.iform.gateway.disabled = 0;
223
			break;
224
		case 1:
225
			document.iform.ipaddr.type.disabled = 1;
226
			document.iform.ipaddr.disabled = 1;
227
			document.iform.subnet.disabled = 1;
228
			document.iform.gateway.disabled = 1;
229
			break;
230
	}
231
}
232
//-->
233
</script>
234

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

    
260
                <tr>
261
                  <td colspan="2" valign="top" height="16"></td>
262
                </tr>
263
                <tr>
264
                  <td colspan="2" valign="top" class="listtopic">General configuration</td>
265
                </tr>
266
                <tr>
267
                  <td valign="middle" class="vncell"><strong>Type</strong></td>
268
                  <td class="vtable"> <select name="type" class="formfld" id="type" onchange="type_change()">
269
                      <?php $opts = split(" ", "Static DHCP");
270
				foreach ($opts as $opt): ?>
271
                      <option <?php if ($opt == $pconfig['type']) echo "selected";?>>
272
                      <?=htmlspecialchars($opt);?>
273
                      </option>
274
                      <?php endforeach; ?>
275
                    </select></td>
276
                </tr>
277
                <tr>
278
                  <td valign="top" class="vncell">MAC address</td>
279
                  <td class="vtable"> <input name="spoofmac" type="text" class="formfld" id="spoofmac" size="30" value="<?=htmlspecialchars($pconfig['spoofmac']);?>">
280
		    <?php
281
			$ip = getenv('REMOTE_ADDR');
282
			$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
283
			$mac = str_replace("\n","",$mac);
284
		    ?>
285
		    <a OnClick="document.forms[0].spoofmac.value='<?=$mac?>';" href="#">Copy my MAC address</a>   
286
		    <br>
287
                    This field can be used to modify (&quot;spoof&quot;) the MAC
288
                    address of the WAN interface<br>
289
                    (may be required with some cable connections)<br>
290
                    Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx
291
                    or leave blank</td>
292
                </tr>
293
                <tr>
294
                  <td valign="top" class="vncell">MTU</td>
295
                  <td class="vtable"> <input name="mtu" type="text" class="formfld" id="mtu" size="8" value="<?=htmlspecialchars($pconfig['mtu']);?>">
296
                    <br>
297
                    If you enter a value in this field, then MSS clamping for
298
                    TCP connections to the value entered above minus 40 (TCP/IP
299
                    header size) will be in effect. If you leave this field blank,
300
                    an MTU of 1492 bytes for PPPoE and 1500 bytes for all other
301
                    connection types will be assumed.</td>
302
                </tr>
303
		
304
                <tr>
305
                  <td colspan="2" valign="top" height="16"></td>
306
		</tr>
307
		<tr>
308
                  <td colspan="2" valign="top" class="listtopic">IP configuration</td>
309
		</tr>
310
		<tr>
311
                  <td width="22%" valign="top" class="vncellreq">Bridge with</td>
312
                  <td width="78%" class="vtable">
313
			<select name="bridge" class="formfld" id="bridge" onChange="enable_change(false)">
314
				  	<option <?php if (!$pconfig['bridge']) echo "selected";?> value="">none</option>
315
                      <?php $opts = array('lan' => "LAN", 'wan' => "WAN");
316
					  	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
317
							if ($i != $index)
318
								$opts['opt' . $i] = "Optional " . $i . " (" .
319
									$config['interfaces']['opt' . $i]['descr'] . ")";
320
						}
321
					foreach ($opts as $opt => $optname): ?>
322
                      <option <?php if ($opt == $pconfig['bridge']) echo "selected";?> value="<?=htmlspecialchars($opt);?>">
323
                      <?=htmlspecialchars($optname);?>
324
                      </option>
325
                      <?php endforeach; ?>
326
                    </select> </td>
327
		</tr>
328
                <tr>
329
                  <td width="22%" valign="top" class="vncellreq">IP address</td>
330
                  <td width="78%" class="vtable">
331
                    <input name="ipaddr" type="text" class="formfld" id="ipaddr" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>" onchange="ipaddr_change()">
332
                    /
333
                	<select name="subnet" class="formfld" id="subnet">
334
					<?php
335
					for ($i = 32; $i > 0; $i--) {
336
						if($i <> 31) {
337
							echo "<option value=\"{$i}\" ";
338
							if ($i == $pconfig['subnet']) echo "selected";
339
							echo ">" . $i . "</option>";
340
						}
341
					}
342
					?>                    </select>
343
				 </td>
344
				</tr>
345
				<?php /* Wireless interface? */
346
				if (isset($optcfg['wireless']))
347
					wireless_config_print();
348
				?>
349
		<tr>
350
                  <td width="22%" valign="top" class="vncell">Gateway</td>
351
                  <td width="78%" class="vtable">
352
			<input name="gateway" value="<?php echo $pconfig['gateway']; ?>">
353
			<br>
354
			If you have multiple WAN connections, enter the next hop gateway (router) here.  Otherwise, leave this option blank.
355
		  </td>
356
		</tr>
357

    
358
                <tr>
359
                  <td colspan="2" valign="top" height="16"></td>
360
                </tr>
361
                <tr>
362
                  <td colspan="2" valign="top" class="vnsepcell">Bandwidth Management (Traffic Shaping)</td>
363
                </tr>
364
                <tr>
365
                  <td valign="top" class="vncell">Interface Bandwidth Speed</td>
366
                  <td class="vtable"> <input name="bandwidth" type="text" class="formfld" id="bandwidth" size="30" value="<?=htmlspecialchars($pconfig['bandwidth']);?>">
367
			<select name="bandwidthtype">
368
				<option value="<?=htmlspecialchars($pconfig['bandwidthtype']);?>"><?=htmlspecialchars($pconfig['bandwidthtype']);?></option>
369
				<option value="b">bit/s</option>
370
				<option value="Kb">Kilobit/s</option>
371
				<option value="Mb">Megabit/s</option>
372
				<option value="Gb">Gigabit/s</option>
373
				<option value=""></option>
374
			</select>
375
			<br> The bandwidth setting will define the speed of the interface for traffic shaping.
376
		  </td>
377
                </tr>                <tr>
378
                  <td width="22%" valign="top">&nbsp;</td>
379
                  <td width="78%">
380
                    <input name="index" type="hidden" value="<?=$index;?>">
381
				  <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
382
                  </td>
383
                </tr>
384
                <tr>
385
                  <td width="22%" valign="top">&nbsp;</td>
386
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
387
                    </strong></span>be sure to add <a href="firewall_rules.php">firewall rules</a> to permit traffic
388
                    through the interface. You also need firewall rules for an interface in
389
                    bridged mode as the firewall acts as a filtering bridge.</span></td>
390
                </tr>
391
              </table>
392
</form>
393
<script language="JavaScript">
394
<!--
395
enable_change(false);
396
//-->
397
</script>
398
<?php else: ?>
399
<p><strong>Optional <?=$index;?> has been disabled because there is no OPT<?=$index;?> interface.</strong></p>
400
<?php endif; ?>
401
<?php include("fend.inc"); ?>
402
</body>
403
</html>
(59-59/137)