Project

General

Profile

Download (14.9 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 ipaddr subnet");
116
			$reqdfieldsn = explode(",", "Description,IP address,Subnet bit count");
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 = 0;
170
		if (!file_exists($d_sysrebootreqd_path)) {
171
			config_lock();
172
			$retval = interfaces_optional_configure();
173

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

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

    
192

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

    
196
?>
197

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

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

    
252
                <tr>
253
                  <td colspan="2" valign="top" height="16"></td>
254
                </tr>
255
                <tr>
256
                  <td colspan="2" valign="top" class="listtopic">General configuration</td>
257
                </tr>
258
                <tr>
259
                  <td valign="middle" class="vncell"><strong>Type</strong></td>
260
                  <td class="vtable"> <select name="type" class="formfld" id="type" onchange="type_change()">
261
                      <?php $opts = split(" ", "Static DHCP");
262
				foreach ($opts as $opt): ?>
263
                      <option <?php if ($opt == $pconfig['type']) echo "selected";?>>
264
                      <?=htmlspecialchars($opt);?>
265
                      </option>
266
                      <?php endforeach; ?>
267
                    </select></td>
268
                </tr>
269
                <tr>
270
                  <td valign="top" class="vncell">MAC address</td>
271
                  <td class="vtable"> <input name="spoofmac" type="text" class="formfld" id="spoofmac" size="30" value="<?=htmlspecialchars($pconfig['spoofmac']);?>">
272
		    <?php
273
			$ip = getenv('REMOTE_ADDR');
274
			$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
275
			$mac = str_replace("\n","",$mac);
276
		    ?>
277
		    <a OnClick="document.forms[0].spoofmac.value='<?=$mac?>';" href="#">Copy my MAC address</a>   
278
		    <br>
279
                    This field can be used to modify (&quot;spoof&quot;) the MAC
280
                    address of the WAN interface<br>
281
                    (may be required with some cable connections)<br>
282
                    Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx
283
                    or leave blank</td>
284
                </tr>
285
                <tr>
286
                  <td valign="top" class="vncell">MTU</td>
287
                  <td class="vtable"> <input name="mtu" type="text" class="formfld" id="mtu" size="8" value="<?=htmlspecialchars($pconfig['mtu']);?>">
288
                    <br>
289
                    If you enter a value in this field, then MSS clamping for
290
                    TCP connections to the value entered above minus 40 (TCP/IP
291
                    header size) will be in effect. If you leave this field blank,
292
                    an MTU of 1492 bytes for PPPoE and 1500 bytes for all other
293
                    connection types will be assumed.</td>
294
                </tr>
295
		
296
                <tr>
297
                  <td colspan="2" valign="top" height="16"></td>
298
				</tr>
299
				<tr>
300
                  <td colspan="2" valign="top" class="listtopic">IP configuration</td>
301
				</tr>
302
				<tr>
303
                  <td width="22%" valign="top" class="vncellreq">Bridge with</td>
304
                  <td width="78%" class="vtable">
305
			<select name="bridge" class="formfld" id="bridge" onChange="enable_change(false)">
306
				  	<option <?php if (!$pconfig['bridge']) echo "selected";?> value="">none</option>
307
                      <?php $opts = array('lan' => "LAN", 'wan' => "WAN");
308
					  	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
309
							if ($i != $index)
310
								$opts['opt' . $i] = "Optional " . $i . " (" .
311
									$config['interfaces']['opt' . $i]['descr'] . ")";
312
						}
313
					foreach ($opts as $opt => $optname): ?>
314
                      <option <?php if ($opt == $pconfig['bridge']) echo "selected";?> value="<?=htmlspecialchars($opt);?>">
315
                      <?=htmlspecialchars($optname);?>
316
                      </option>
317
                      <?php endforeach; ?>
318
                    </select> </td>
319
				</tr>
320
                <tr>
321
                  <td width="22%" valign="top" class="vncellreq">IP address</td>
322
                  <td width="78%" class="vtable">
323
                    <input name="ipaddr" type="text" class="formfld" id="ipaddr" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>" onchange="ipaddr_change()">
324
                    /
325
                	<select name="subnet" class="formfld" id="subnet">
326
					<?php
327
					for ($i = 32; $i > 0; $i--) {
328
						if($i <> 31) {
329
							echo "<option value=\"{$i}\" ";
330
							if ($i == $pconfig['subnet']) echo "selected";
331
							echo ">" . $i . "</option>";
332
						}
333
					}
334
					?>                    </select>
335
				 </td>
336
				</tr>
337
				<?php /* Wireless interface? */
338
				if (isset($optcfg['wireless']))
339
					wireless_config_print();
340
				?>
341
		<tr>
342
                  <td width="22%" valign="top" class="vncell">Gateway</td>
343
                  <td width="78%" class="vtable">
344
			<input name="gateway" value="<?php echo $pconfig['gateway']; ?>">
345
			<br>
346
			If you have multiple WAN connections, enter the next hop gateway (router) here.  Otherwise, leave this option blank.
347
		  </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="vnsepcell">Bandwidth Management (Traffic Shaping)</td>
355
                </tr>
356
                <tr>
357
                  <td valign="top" class="vncell">Interface Bandwidth Speed</td>
358
                  <td class="vtable"> <input name="bandwidth" type="text" class="formfld" id="bandwidth" size="30" value="<?=htmlspecialchars($pconfig['bandwidth']);?>">
359
			<select name="bandwidthtype">
360
				<option value="<?=htmlspecialchars($pconfig['bandwidthtype']);?>"><?=htmlspecialchars($pconfig['bandwidthtype']);?></option>
361
				<option value="b">bit/s</option>
362
				<option value="Kb">Kilobit/s</option>
363
				<option value="Mb">Megabit/s</option>
364
				<option value="Gb">Gigabit/s</option>
365
				<option value=""></option>
366
			</select>
367
			<br> The bandwidth setting will define the speed of the interface for traffic shaping.
368
		  </td>
369
                </tr>                <tr>
370
                  <td width="22%" valign="top">&nbsp;</td>
371
                  <td width="78%">
372
                    <input name="index" type="hidden" value="<?=$index;?>">
373
				  <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
374
                  </td>
375
                </tr>
376
                <tr>
377
                  <td width="22%" valign="top">&nbsp;</td>
378
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
379
                    </strong></span>be sure to add firewall rules to permit traffic
380
                    through the interface. Firewall rules for an interface in
381
                    bridged mode have no effect on packets to hosts other than
382
                    the firewall itself, unless &quot;Enable filtering bridge&quot;
383
                    is checked on the <a href="system_advanced.php">System:
384
                    Advanced functions</a> page.</span></td>
385
                </tr>
386
              </table>
387
</form>
388
<script language="JavaScript">
389
<!--
390
enable_change(false);
391
//-->
392
</script>
393
<?php else: ?>
394
<p><strong>Optional <?=$index;?> has been disabled because there is no OPT<?=$index;?> interface.</strong></p>
395
<?php endif; ?>
396
<?php include("fend.inc"); ?>
397
</body>
398
</html>
(59-59/133)