Project

General

Profile

Download (14.6 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
$pconfig['descr'] = $optcfg['descr'];
46
$pconfig['bridge'] = $optcfg['bridge'];
47

    
48
$pconfig['bandwidth'] = $optcfg['bandwidth'];
49
$pconfig['bandwidthtype'] = $optcfg['bandwidthtype'];
50

    
51
$pconfig['enable'] = isset($optcfg['enable']);
52

    
53
$pconfig['blockpriv'] = isset($optcfg['blockpriv']);
54
$pconfig['blockbogons'] = isset($optcfg['blockbogons']);
55
$pconfig['spoofmac'] = $optcfg['spoofmac'];
56
$pconfig['mtu'] = $optcfg['mtu'];
57

    
58
/* Wireless interface? */
59
if (isset($optcfg['wireless'])) {
60
	require("interfaces_wlan.inc");
61
	wireless_config_init();
62
}
63

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

    
74
if ($_POST) {
75

    
76
	unset($input_errors);
77
	$pconfig = $_POST;
78

    
79
	/* input validation */
80
	if ($_POST['enable']) {
81

    
82
		/* description unique? */
83
		for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
84
			if ($i != $index) {
85
				if ($config['interfaces']['opt' . $i]['descr'] == $_POST['descr']) {
86
					$input_errors[] = "An interface with the specified description already exists.";
87
				}
88
			}
89
		}
90

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

    
118
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
119

    
120
			if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
121
				$input_errors[] = "A valid IP address must be specified.";
122
			}
123
			if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
124
				$input_errors[] = "A valid subnet bit count must be specified.";
125
			}
126
		}
127
	}
128

    
129
	/* Wireless interface? */
130
	if (isset($optcfg['wireless'])) {
131
		$wi_input_errors = wireless_config_post();
132
		if ($wi_input_errors) {
133
			$input_errors = array_merge($input_errors, $wi_input_errors);
134
		}
135
	}
136

    
137
	if (!$input_errors) {
138

    
139
		$optcfg['descr'] = $_POST['descr'];
140
		$optcfg['bridge'] = $_POST['bridge'];
141
		$optcfg['enable'] = $_POST['enable'] ? true : false;
142
		
143
		if($_POST['bandwidth'] <> "" and $_POST['bandwidthtype'] <> "") {
144
			$optcfg['bandwidth'] = $_POST['bandwidth'];
145
			$optcfg['bandwidthtype'] = $_POST['bandwidthtype'];
146
		} else {
147
			unset($optcfg['bandwidth']);
148
			unset($optcfg['bandwidthtype']);
149
		}
150

    
151
		if ($_POST['type'] == "Static") {
152
			$optcfg['ipaddr'] = $_POST['ipaddr'];
153
			$optcfg['subnet'] = $_POST['subnet'];
154
			$optcfg['gateway'] = $_POST['gateway'];
155
			if (isset($optcfg['ispointtopoint']))
156
				$optcfg['pointtopoint'] = $_POST['pointtopoint'];
157
		} else if ($_POST['type'] == "DHCP") {
158
			$optcfg['ipaddr'] = "dhcp";
159
			$optcfg['dhcphostname'] = $_POST['dhcphostname'];
160
		}
161

    
162
		$optcfg['blockpriv'] = $_POST['blockpriv'] ? true : false;
163
		$optcfg['blockbogons'] = $_POST['blockbogons'] ? true : false;
164
		$optcfg['spoofmac'] = $_POST['spoofmac'];
165
		$optcfg['mtu'] = $_POST['mtu'];
166

    
167
		write_config();
168

    
169
		$retval = interfaces_optional_configure();
170

    
171
		/* is this the captive portal interface? */
172
		if (isset($config['captiveportal']['enable']) &&
173
			($config['captiveportal']['interface'] == ('opt' . $index))) {
174
			captiveportal_configure();
175
		}
176
		config_unlock();
177
		
178
		/* setup carp interfaces */
179
		interfaces_carp_configure();
180
	
181
		/* bring up carp interfaces */
182
		interfaces_carp_bringup();
183

    
184
		/* sync filter configuration */
185
		filter_configure();
186

    
187
		$savemsg = "The changes have been applied.";
188
	}
189
}
190

    
191

    
192
$pgtitle = "Interfaces: Optional {$index} (" . htmlspecialchars($optcfg['descr']) . ")";
193
include("head.inc");
194

    
195
?>
196

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

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

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

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