Project

General

Profile

Download (14.8 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 = get_std_save_message($retval);
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.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
//-->
226
</script>
227

    
228
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
229
<?php include("fbegin.inc"); ?>
230
<p class="pgtitle"><?=$pgtitle?></p>
231
<?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
                <tr>
237
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
238
                  <td width="78%" class="vtable">
239
			<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
240
                    <strong>Enable Optional <?=$index;?> interface</strong></td>
241
		</tr>
242
                <tr>
243
                  <td width="22%" valign="top" class="vncell">Description</td>
244
                  <td width="78%" class="vtable">
245
                    <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
		  </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
                <tr>
295
                  <td colspan="2" valign="top" height="16"></td>
296
				</tr>
297
				<tr>
298
                  <td colspan="2" valign="top" class="listtopic">IP configuration</td>
299
				</tr>
300
				<tr>
301
                  <td width="22%" valign="top" class="vncellreq">Bridge with</td>
302
                  <td width="78%" class="vtable">
303
			<select name="bridge" class="formfld" id="bridge" onChange="enable_change(false)">
304
				  	<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
                      <option <?php if ($opt == $pconfig['bridge']) echo "selected";?> value="<?=htmlspecialchars($opt);?>">
313
                      <?=htmlspecialchars($optname);?>
314
                      </option>
315
                      <?php endforeach; ?>
316
                    </select> </td>
317
				</tr>
318
                <tr>
319
                  <td width="22%" valign="top" class="vncellreq">IP address</td>
320
                  <td width="78%" class="vtable">
321
                    <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
					<?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
				 </td>
334
				</tr>
335
				<?php /* Wireless interface? */
336
				if (isset($optcfg['wireless']))
337
					wireless_config_print();
338
				?>
339
		<tr>
340
                  <td width="22%" valign="top" class="vncell">Gateway</td>
341
                  <td width="78%" class="vtable">
342
			<input name="gateway" value="<?php echo $pconfig['gateway']; ?>">
343
			<br>
344
			If you have multiple WAN connections, enter the next hop gateway (router) here.  Otherwise, leave this option blank.
345
		  </td>
346
		</tr>
347

    
348
                <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
                  <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
				<option value=""></option>
364
			</select>
365
			<br> The bandwidth setting will define the speed of the interface for traffic shaping.
366
		  </td>
367
                </tr>                <tr>
368
                  <td width="22%" valign="top">&nbsp;</td>
369
                  <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
                  </td>
373
                </tr>
374
                <tr>
375
                  <td width="22%" valign="top">&nbsp;</td>
376
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
377
                    </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
                    the firewall itself, unless &quot;Enable filtering bridge&quot;
381
                    is checked on the <a href="system_advanced.php">System:
382
                    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>
(59-59/133)