Project

General

Profile

Download (14.8 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 03b92764 Scott Ullrich
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5
	interfaces_opt.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7 03b92764 Scott Ullrich
8 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10 03b92764 Scott Ullrich
11 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13 03b92764 Scott Ullrich
14 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16 03b92764 Scott Ullrich
17 5b237745 Scott Ullrich
	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 03b92764 Scott Ullrich
21 5b237745 Scott Ullrich
	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 03b92764 Scott Ullrich
41 5b237745 Scott Ullrich
if (!$index)
42
	exit;
43
44
$optcfg = &$config['interfaces']['opt' . $index];
45
$pconfig['descr'] = $optcfg['descr'];
46
$pconfig['bridge'] = $optcfg['bridge'];
47 03b92764 Scott Ullrich
48
$pconfig['bandwidth'] = $optcfg['bandwidth'];
49
$pconfig['bandwidthtype'] = $optcfg['bandwidthtype'];
50
51 5b237745 Scott Ullrich
$pconfig['enable'] = isset($optcfg['enable']);
52
53 0311dbd5 Scott Ullrich
$pconfig['blockpriv'] = isset($optcfg['blockpriv']);
54
$pconfig['blockbogons'] = isset($optcfg['blockbogons']);
55
$pconfig['spoofmac'] = $optcfg['spoofmac'];
56
$pconfig['mtu'] = $optcfg['mtu'];
57
58 5b237745 Scott Ullrich
/* Wireless interface? */
59
if (isset($optcfg['wireless'])) {
60
	require("interfaces_wlan.inc");
61
	wireless_config_init();
62
}
63
64 0311dbd5 Scott Ullrich
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 5b237745 Scott Ullrich
if ($_POST) {
75
76
	unset($input_errors);
77
	$pconfig = $_POST;
78
79
	/* input validation */
80
	if ($_POST['enable']) {
81 03b92764 Scott Ullrich
82 5b237745 Scott Ullrich
		/* 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 03b92764 Scott Ullrich
91 5b237745 Scott Ullrich
		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 03b92764 Scott Ullrich
						$input_errors[] = "Optional interface {$i} " .
97 5b237745 Scott Ullrich
							"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
98
							"the specified interface.";
99
					} else if ($config['interfaces']['opt' . $i]['bridge'] == "opt{$index}") {
100 03b92764 Scott Ullrich
						$input_errors[] = "Optional interface {$i} " .
101 5b237745 Scott Ullrich
							"({$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 03b92764 Scott Ullrich
118 5b237745 Scott Ullrich
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
119 03b92764 Scott Ullrich
120 5b237745 Scott Ullrich
			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 03b92764 Scott Ullrich
129 5b237745 Scott Ullrich
	/* 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 03b92764 Scott Ullrich
137 5b237745 Scott Ullrich
	if (!$input_errors) {
138 0311dbd5 Scott Ullrich
139 5b237745 Scott Ullrich
		$optcfg['descr'] = $_POST['descr'];
140
		$optcfg['bridge'] = $_POST['bridge'];
141
		$optcfg['enable'] = $_POST['enable'] ? true : false;
142 0311dbd5 Scott Ullrich
		
143 001fdeea Scott Ullrich
		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 0311dbd5 Scott Ullrich
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 a12d2145 Scott Ullrich
162 2dfb79a4 Scott Ullrich
		$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 5b237745 Scott Ullrich
		write_config();
168 03b92764 Scott Ullrich
169 5b237745 Scott Ullrich
		$retval = 0;
170
		if (!file_exists($d_sysrebootreqd_path)) {
171
			config_lock();
172
			$retval = interfaces_optional_configure();
173 03b92764 Scott Ullrich
174 5b237745 Scott Ullrich
			/* is this the captive portal interface? */
175 03b92764 Scott Ullrich
			if (isset($config['captiveportal']['enable']) &&
176 5b237745 Scott Ullrich
				($config['captiveportal']['interface'] == ('opt' . $index))) {
177
				captiveportal_configure();
178
			}
179
			config_unlock();
180
		}
181 1f8caa36 Scott Ullrich
		
182
		/* setup carp interfaces */
183
		interfaces_carp_configure();
184
	
185
		/* bring up carp interfaces */
186
		interfaces_carp_bringup();
187
188 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
189
	}
190
}
191 7f43ca88 Scott Ullrich
192
193 931066a8 Bill Marquette
$pgtitle = "Interfaces: Optional {$index} (" . htmlspecialchars($optcfg['descr']) . ")";
194 7f43ca88 Scott Ullrich
include("head.inc");
195
196 5b237745 Scott Ullrich
?>
197 b9e255dd Bill Marquette
198
<script type="text/javascript" language="javascript" src="ip_helper.js">
199
</script>
200 5b237745 Scott Ullrich
<script language="JavaScript">
201
<!--
202
function enable_change(enable_over) {
203 a23d7248 Scott Ullrich
	var endis;
204
	endis = !((document.iform.bridge.selectedIndex == 0) || enable_over);
205
	document.iform.ipaddr.disabled = endis;
206
	document.iform.subnet.disabled = endis;
207 5b237745 Scott Ullrich
}
208
function ipaddr_change() {
209 6846116e Scott Ullrich
	document.iform.subnet.selectedIndex = gen_bits_opt(document.iform.ipaddr.value);
210 5b237745 Scott Ullrich
}
211 0311dbd5 Scott Ullrich
function type_change(enable_change,enable_change_pptp) {
212
	switch (document.iform.type.selectedIndex) {
213
		case 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.disabled = 1;
220
			document.iform.subnet.disabled = 1;
221
			document.iform.gateway.disabled = 1;
222
			break;
223
	}
224
}
225 5b237745 Scott Ullrich
//-->
226
</script>
227 b9e255dd Bill Marquette
228 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
229
<?php include("fbegin.inc"); ?>
230 931066a8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
231 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
232
<?php if ($savemsg) print_info_box($savemsg); ?>
233
<?php if ($optcfg['if']): ?>
234
            <form action="interfaces_opt.php" method="post" name="iform" id="iform">
235
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
236 03b92764 Scott Ullrich
                <tr>
237 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
238
                  <td width="78%" class="vtable">
239 007be4f3 Scott Ullrich
			<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
240 5b237745 Scott Ullrich
                    <strong>Enable Optional <?=$index;?> interface</strong></td>
241 0311dbd5 Scott Ullrich
		</tr>
242 03b92764 Scott Ullrich
                <tr>
243 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Description</td>
244 03b92764 Scott Ullrich
                  <td width="78%" class="vtable">
245 5b237745 Scott Ullrich
                    <input name="descr" type="text" class="formfld" id="descr" size="30" value="<?=htmlspecialchars($pconfig['descr']);?>">
246
					<br> <span class="vexpl">Enter a description (name) for the interface here.</span>
247 0311dbd5 Scott Ullrich
		  </td>
248
		</tr>
249
250
                <tr>
251
                  <td colspan="2" valign="top" height="16"></td>
252
                </tr>
253
                <tr>
254
                  <td colspan="2" valign="top" class="listtopic">General configuration</td>
255
                </tr>
256
                <tr>
257
                  <td valign="middle" class="vncell"><strong>Type</strong></td>
258
                  <td class="vtable"> <select name="type" class="formfld" id="type" onchange="type_change()">
259
                      <?php $opts = split(" ", "Static DHCP");
260
				foreach ($opts as $opt): ?>
261
                      <option <?php if ($opt == $pconfig['type']) echo "selected";?>>
262
                      <?=htmlspecialchars($opt);?>
263
                      </option>
264
                      <?php endforeach; ?>
265
                    </select></td>
266
                </tr>
267
                <tr>
268
                  <td valign="top" class="vncell">MAC address</td>
269
                  <td class="vtable"> <input name="spoofmac" type="text" class="formfld" id="spoofmac" size="30" value="<?=htmlspecialchars($pconfig['spoofmac']);?>">
270
		    <?php
271
			$ip = getenv('REMOTE_ADDR');
272
			$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
273
			$mac = str_replace("\n","",$mac);
274
		    ?>
275
		    <a OnClick="document.forms[0].spoofmac.value='<?=$mac?>';" href="#">Copy my MAC address</a>   
276
		    <br>
277
                    This field can be used to modify (&quot;spoof&quot;) the MAC
278
                    address of the WAN interface<br>
279
                    (may be required with some cable connections)<br>
280
                    Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx
281
                    or leave blank</td>
282
                </tr>
283
                <tr>
284
                  <td valign="top" class="vncell">MTU</td>
285
                  <td class="vtable"> <input name="mtu" type="text" class="formfld" id="mtu" size="8" value="<?=htmlspecialchars($pconfig['mtu']);?>">
286
                    <br>
287
                    If you enter a value in this field, then MSS clamping for
288
                    TCP connections to the value entered above minus 40 (TCP/IP
289
                    header size) will be in effect. If you leave this field blank,
290
                    an MTU of 1492 bytes for PPPoE and 1500 bytes for all other
291
                    connection types will be assumed.</td>
292
                </tr>
293
		
294 03b92764 Scott Ullrich
                <tr>
295 5b237745 Scott Ullrich
                  <td colspan="2" valign="top" height="16"></td>
296
				</tr>
297 03b92764 Scott Ullrich
				<tr>
298 a23d7248 Scott Ullrich
                  <td colspan="2" valign="top" class="listtopic">IP configuration</td>
299 5b237745 Scott Ullrich
				</tr>
300 03b92764 Scott Ullrich
				<tr>
301 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Bridge with</td>
302
                  <td width="78%" class="vtable">
303 007be4f3 Scott Ullrich
			<select name="bridge" class="formfld" id="bridge" onChange="enable_change(false)">
304 5b237745 Scott Ullrich
				  	<option <?php if (!$pconfig['bridge']) echo "selected";?> value="">none</option>
305
                      <?php $opts = array('lan' => "LAN", 'wan' => "WAN");
306
					  	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
307
							if ($i != $index)
308
								$opts['opt' . $i] = "Optional " . $i . " (" .
309
									$config['interfaces']['opt' . $i]['descr'] . ")";
310
						}
311
					foreach ($opts as $opt => $optname): ?>
312 03b92764 Scott Ullrich
                      <option <?php if ($opt == $pconfig['bridge']) echo "selected";?> value="<?=htmlspecialchars($opt);?>">
313 5b237745 Scott Ullrich
                      <?=htmlspecialchars($optname);?>
314
                      </option>
315
                      <?php endforeach; ?>
316
                    </select> </td>
317
				</tr>
318 03b92764 Scott Ullrich
                <tr>
319 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">IP address</td>
320 03b92764 Scott Ullrich
                  <td width="78%" class="vtable">
321 5b237745 Scott Ullrich
                    <input name="ipaddr" type="text" class="formfld" id="ipaddr" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>" onchange="ipaddr_change()">
322
                    /
323
                	<select name="subnet" class="formfld" id="subnet">
324 21ab1cde Scott Ullrich
					<?php
325
					for ($i = 32; $i > 0; $i--) {
326
						if($i <> 31) {
327
							echo "<option value=\"{$i}\" ";
328
							if ($i == $pconfig['subnet']) echo "selected";
329
							echo ">" . $i . "</option>";
330
						}
331
					}
332
					?>                    </select>
333 5b237745 Scott Ullrich
				 </td>
334
				</tr>
335
				<?php /* Wireless interface? */
336
				if (isset($optcfg['wireless']))
337
					wireless_config_print();
338
				?>
339 007be4f3 Scott Ullrich
		<tr>
340 1aaa2a5f Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Gateway</td>
341 007be4f3 Scott Ullrich
                  <td width="78%" class="vtable">
342
			<input name="gateway" value="<?php echo $pconfig['gateway']; ?>">
343 a12d2145 Scott Ullrich
			<br>
344
			If you have multiple WAN connections, enter the next hop gateway (router) here.  Otherwise, leave this option blank.
345 007be4f3 Scott Ullrich
		  </td>
346
		</tr>
347 a12d2145 Scott Ullrich
348 af539d78 Scott Ullrich
                <tr>
349
                  <td colspan="2" valign="top" height="16"></td>
350
                </tr>
351
                <tr>
352
                  <td colspan="2" valign="top" class="vnsepcell">Bandwidth Management (Traffic Shaping)</td>
353
                </tr>
354
                <tr>
355
                  <td valign="top" class="vncell">Interface Bandwidth Speed</td>
356 03b92764 Scott Ullrich
                  <td class="vtable"> <input name="bandwidth" type="text" class="formfld" id="bandwidth" size="30" value="<?=htmlspecialchars($pconfig['bandwidth']);?>">
357
			<select name="bandwidthtype">
358
				<option value="<?=htmlspecialchars($pconfig['bandwidthtype']);?>"><?=htmlspecialchars($pconfig['bandwidthtype']);?></option>
359
				<option value="b">bit/s</option>
360
				<option value="Kb">Kilobit/s</option>
361
				<option value="Mb">Megabit/s</option>
362
				<option value="Gb">Gigabit/s</option>
363 d09c8936 Scott Ullrich
				<option value=""></option>
364 03b92764 Scott Ullrich
			</select>
365
			<br> The bandwidth setting will define the speed of the interface for traffic shaping.
366
		  </td>
367 af539d78 Scott Ullrich
                </tr>                <tr>
368 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
369 03b92764 Scott Ullrich
                  <td width="78%">
370
                    <input name="index" type="hidden" value="<?=$index;?>">
371
				  <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
372 5b237745 Scott Ullrich
                  </td>
373
                </tr>
374 03b92764 Scott Ullrich
                <tr>
375 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
376
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
377 03b92764 Scott Ullrich
                    </strong></span>be sure to add firewall rules to permit traffic
378
                    through the interface. Firewall rules for an interface in
379
                    bridged mode have no effect on packets to hosts other than
380 e05b4a54 Bill Marquette
                    the firewall itself, unless &quot;Enable filtering bridge&quot;
381 03b92764 Scott Ullrich
                    is checked on the <a href="system_advanced.php">System:
382 5b237745 Scott Ullrich
                    Advanced functions</a> page.</span></td>
383
                </tr>
384
              </table>
385
</form>
386
<script language="JavaScript">
387
<!--
388
enable_change(false);
389
//-->
390
</script>
391
<?php else: ?>
392
<p><strong>Optional <?=$index;?> has been disabled because there is no OPT<?=$index;?> interface.</strong></p>
393
<?php endif; ?>
394
<?php include("fend.inc"); ?>
395
</body>
396
</html>