Project

General

Profile

Download (11.3 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
		
155
		/* setup carp interfaces */
156
		interfaces_carp_configure();
157
	
158
		/* bring up carp interfaces */
159
		interfaces_carp_bringup();
160

    
161
		$savemsg = get_std_save_message($retval);
162
	}
163
}
164

    
165

    
166
$pgtitle = "Firewall: NAT: Inbound";
167
include("head.inc");
168

    
169
?>
170

    
171
<script type="text/javascript" language="javascript" src="ip_helper.js">
172
</script>
173
<script language="JavaScript">
174
<!--
175
function enable_change(enable_over) {
176
	var endis;
177
	endis = !((document.iform.bridge.selectedIndex == 0) || enable_over);
178
	document.iform.ipaddr.disabled = endis;
179
	document.iform.subnet.disabled = endis;
180
}
181
function ipaddr_change() {
182
	document.iform.subnet.selectedIndex = gen_bits(document.iform.ipaddr.value);
183
}
184
//-->
185
</script>
186

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

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