Project

General

Profile

Download (11.5 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
$pconfig['ipaddr'] = $optcfg['ipaddr'];
48
$pconfig['subnet'] = $optcfg['subnet'];
49
$pconfig['gateway'] = $optcfg['gateway'];
50

    
51
$pconfig['bandwidth'] = $optcfg['bandwidth'];
52
$pconfig['bandwidthtype'] = $optcfg['bandwidthtype'];
53

    
54
$pconfig['enable'] = isset($optcfg['enable']);
55

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

    
62
if ($_POST) {
63

    
64
	unset($input_errors);
65
	$pconfig = $_POST;
66

    
67
	/* input validation */
68
	if ($_POST['enable']) {
69

    
70
		/* description unique? */
71
		for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
72
			if ($i != $index) {
73
				if ($config['interfaces']['opt' . $i]['descr'] == $_POST['descr']) {
74
					$input_errors[] = "An interface with the specified description already exists.";
75
				}
76
			}
77
		}
78

    
79
		if ($_POST['bridge']) {
80
			/* double bridging? */
81
			for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
82
				if ($i != $index) {
83
					if ($config['interfaces']['opt' . $i]['bridge'] == $_POST['bridge']) {
84
						$input_errors[] = "Optional interface {$i} " .
85
							"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
86
							"the specified interface.";
87
					} else if ($config['interfaces']['opt' . $i]['bridge'] == "opt{$index}") {
88
						$input_errors[] = "Optional interface {$i} " .
89
							"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
90
							"this interface.";
91
					}
92
				}
93
			}
94
			if ($config['interfaces'][$_POST['bridge']]['bridge']) {
95
				$input_errors[] = "The specified interface is already bridged to " .
96
					"another interface.";
97
			}
98
			/* captive portal on? */
99
			if (isset($config['captiveportal']['enable'])) {
100
				$input_errors[] = "Interfaces cannot be bridged while the captive portal is enabled.";
101
			}
102
		} else {
103
			$reqdfields = explode(" ", "descr ipaddr subnet");
104
			$reqdfieldsn = explode(",", "Description,IP address,Subnet bit count");
105

    
106
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
107

    
108
			if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
109
				$input_errors[] = "A valid IP address must be specified.";
110
			}
111
			if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
112
				$input_errors[] = "A valid subnet bit count must be specified.";
113
			}
114
		}
115
	}
116

    
117
	/* Wireless interface? */
118
	if (isset($optcfg['wireless'])) {
119
		$wi_input_errors = wireless_config_post();
120
		if ($wi_input_errors) {
121
			$input_errors = array_merge($input_errors, $wi_input_errors);
122
		}
123
	}
124

    
125
	if (!$input_errors) {
126
		$optcfg['descr'] = $_POST['descr'];
127
		$optcfg['ipaddr'] = $_POST['ipaddr'];
128
		$optcfg['subnet'] = $_POST['subnet'];
129
		$optcfg['bridge'] = $_POST['bridge'];
130
		$optcfg['enable'] = $_POST['enable'] ? true : false;
131
		if($_POST['bandwidth'] <> "" and $_POST['bandwidthtype'] <> "") {
132
			$optcfg['bandwidth'] = $_POST['bandwidth'];
133
			$optcfg['bandwidthtype'] = $_POST['bandwidthtype'];
134
		} else {
135
			unset($optcfg['bandwidth']);
136
			unset($optcfg['bandwidthtype']);
137
		}
138
		$optcfg['gateway'] = $_POST['gateway'];
139

    
140
		write_config();
141

    
142
		$retval = 0;
143
		if (!file_exists($d_sysrebootreqd_path)) {
144
			config_lock();
145
			$retval = interfaces_optional_configure();
146

    
147
			/* is this the captive portal interface? */
148
			if (isset($config['captiveportal']['enable']) &&
149
				($config['captiveportal']['interface'] == ('opt' . $index))) {
150
				captiveportal_configure();
151
			}
152
			config_unlock();
153
		}
154
		$savemsg = get_std_save_message($retval);
155
	}
156
}
157
?>
158
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
159
<html>
160
<head>
161
<title><?=gentitle("Interfaces: Optional $index (" . htmlspecialchars($optcfg['descr']) . ")");?></title>
162
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
163
<link href="gui.css" rel="stylesheet" type="text/css">
164

    
165
<script type="text/javascript" language="javascript" src="ip_helper.js">
166
</script>
167

    
168
<script language="JavaScript">
169
<!--
170
function enable_change(enable_over) {
171
	var endis;
172
	endis = !((document.iform.bridge.selectedIndex == 0) || enable_over);
173
	document.iform.ipaddr.disabled = endis;
174
	document.iform.subnet.disabled = endis;
175
}
176
function ipaddr_change() {
177
	document.iform.subnet.selectedIndex = gen_bits(document.iform.ipaddr.value);
178
}
179
//-->
180
</script>
181

    
182
</head>
183

    
184
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
185
<?php include("fbegin.inc"); ?>
186
<p class="pgtitle">Interfaces: Optional <?=$index;?> (<?=htmlspecialchars($optcfg['descr']);?>)</p>
187
<?php if ($input_errors) print_input_errors($input_errors); ?>
188
<?php if ($savemsg) print_info_box($savemsg); ?>
189
<?php if ($optcfg['if']): ?>
190
            <form action="interfaces_opt.php" method="post" name="iform" id="iform">
191
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
192
                <tr>
193
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
194
                  <td width="78%" class="vtable">
195
			<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
196
                    <strong>Enable Optional <?=$index;?> interface</strong></td>
197
				</tr>
198
                <tr>
199
                  <td width="22%" valign="top" class="vncell">Description</td>
200
                  <td width="78%" class="vtable">
201
                    <input name="descr" type="text" class="formfld" id="descr" size="30" value="<?=htmlspecialchars($pconfig['descr']);?>">
202
					<br> <span class="vexpl">Enter a description (name) for the interface here.</span>
203
				 </td>
204
				</tr>
205
                <tr>
206
                  <td colspan="2" valign="top" height="16"></td>
207
				</tr>
208
				<tr>
209
                  <td colspan="2" valign="top" class="listtopic">IP configuration</td>
210
				</tr>
211
				<tr>
212
                  <td width="22%" valign="top" class="vncellreq">Bridge with</td>
213
                  <td width="78%" class="vtable">
214
			<select name="bridge" class="formfld" id="bridge" onChange="enable_change(false)">
215
				  	<option <?php if (!$pconfig['bridge']) echo "selected";?> value="">none</option>
216
                      <?php $opts = array('lan' => "LAN", 'wan' => "WAN");
217
					  	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
218
							if ($i != $index)
219
								$opts['opt' . $i] = "Optional " . $i . " (" .
220
									$config['interfaces']['opt' . $i]['descr'] . ")";
221
						}
222
					foreach ($opts as $opt => $optname): ?>
223
                      <option <?php if ($opt == $pconfig['bridge']) echo "selected";?> value="<?=htmlspecialchars($opt);?>">
224
                      <?=htmlspecialchars($optname);?>
225
                      </option>
226
                      <?php endforeach; ?>
227
                    </select> </td>
228
				</tr>
229
                <tr>
230
                  <td width="22%" valign="top" class="vncellreq">IP address</td>
231
                  <td width="78%" class="vtable">
232
                    <input name="ipaddr" type="text" class="formfld" id="ipaddr" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>" onchange="ipaddr_change()">
233
                    /
234
                	<select name="subnet" class="formfld" id="subnet">
235
					<?php
236
					for ($i = 32; $i > 0; $i--) {
237
						if($i <> 31) {
238
							echo "<option value=\"{$i}\" ";
239
							if ($i == $pconfig['subnet']) echo "selected";
240
							echo ">" . $i . "</option>";
241
						}
242
					}
243
					?>                    </select>
244
				 </td>
245
				</tr>
246
				<?php /* Wireless interface? */
247
				if (isset($optcfg['wireless']))
248
					wireless_config_print();
249
				?>
250
		<tr>
251
                  <td width="22%" valign="top" class="vncell">Gateway</td>
252
                  <td width="78%" class="vtable">
253
			<input name="gateway" value="<?php echo $pconfig['gateway']; ?>">
254
			<br>
255
			If you have multiple WAN connections, enter the next hop gateway (router) here.  Otherwise, leave this option blank.
256
		  </td>
257
		</tr>
258

    
259
                <tr>
260
                  <td colspan="2" valign="top" height="16"></td>
261
                </tr>
262
                <tr>
263
                  <td colspan="2" valign="top" class="vnsepcell">Bandwidth Management (Traffic Shaping)</td>
264
                </tr>
265
                <tr>
266
                  <td valign="top" class="vncell">Interface Bandwidth Speed</td>
267
                  <td class="vtable"> <input name="bandwidth" type="text" class="formfld" id="bandwidth" size="30" value="<?=htmlspecialchars($pconfig['bandwidth']);?>">
268
			<select name="bandwidthtype">
269
				<option value="<?=htmlspecialchars($pconfig['bandwidthtype']);?>"><?=htmlspecialchars($pconfig['bandwidthtype']);?></option>
270
				<option value="b">bit/s</option>
271
				<option value="Kb">Kilobit/s</option>
272
				<option value="Mb">Megabit/s</option>
273
				<option value="Gb">Gigabit/s</option>
274
				<option value=""></option>
275
			</select>
276
			<br> The bandwidth setting will define the speed of the interface for traffic shaping.
277
		  </td>
278
                </tr>                <tr>
279
                  <td width="22%" valign="top">&nbsp;</td>
280
                  <td width="78%">
281
                    <input name="index" type="hidden" value="<?=$index;?>">
282
				  <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
283
                  </td>
284
                </tr>
285
                <tr>
286
                  <td width="22%" valign="top">&nbsp;</td>
287
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
288
                    </strong></span>be sure to add firewall rules to permit traffic
289
                    through the interface. Firewall rules for an interface in
290
                    bridged mode have no effect on packets to hosts other than
291
                    the firewall itself, unless &quot;Enable filtering bridge&quot;
292
                    is checked on the <a href="system_advanced.php">System:
293
                    Advanced functions</a> page.</span></td>
294
                </tr>
295
              </table>
296
</form>
297
<script language="JavaScript">
298
<!--
299
enable_change(false);
300
//-->
301
</script>
302
<?php else: ?>
303
<p><strong>Optional <?=$index;?> has been disabled because there is no OPT<?=$index;?> interface.</strong></p>
304
<?php endif; ?>
305
<?php include("fend.inc"); ?>
306
</body>
307
</html>
(52-52/117)