Project

General

Profile

Download (11.2 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
	interfaces_opt.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31

    
32
require("guiconfig.inc");
33

    
34
unset($index);
35
if ($_GET['index'])
36
	$index = $_GET['index'];
37
else if ($_POST['index'])
38
	$index = $_POST['index'];
39

    
40
if (!$index)
41
	exit;
42

    
43
$optcfg = &$config['interfaces']['opt' . $index];
44
$pconfig['descr'] = $optcfg['descr'];
45
$pconfig['bridge'] = $optcfg['bridge'];
46
$pconfig['ipaddr'] = $optcfg['ipaddr'];
47
$pconfig['subnet'] = $optcfg['subnet'];
48

    
49
$pconfig['bandwidth'] = $optcfg['bandwidth'];
50
$pconfig['bandwidthtype'] = $optcfg['bandwidthtype'];
51

    
52
$pconfig['enable'] = isset($optcfg['enable']);
53

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

    
60
if ($_POST) {
61

    
62
	unset($input_errors);
63
	$pconfig = $_POST;
64

    
65
	/* input validation */
66
	if ($_POST['enable']) {
67

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

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

    
104
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
105

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

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

    
123
	if (!$input_errors) {
124
		$optcfg['descr'] = $_POST['descr'];
125
		$optcfg['ipaddr'] = $_POST['ipaddr'];
126
		$optcfg['subnet'] = $_POST['subnet'];
127
		$optcfg['bridge'] = $_POST['bridge'];
128
		$optcfg['enable'] = $_POST['enable'] ? true : false;
129
		$optcfg['bandwidth'] = $_POST['bandwidth'];
130
		$optcfg['bandwidthtype'] = $_POST['bandwidthtype'];
131

    
132
		write_config();
133

    
134
		$retval = 0;
135
		if (!file_exists($d_sysrebootreqd_path)) {
136
			config_lock();
137
			$retval = interfaces_optional_configure();
138

    
139
			/* is this the captive portal interface? */
140
			if (isset($config['captiveportal']['enable']) &&
141
				($config['captiveportal']['interface'] == ('opt' . $index))) {
142
				captiveportal_configure();
143
			}
144
			config_unlock();
145
		}
146
		$savemsg = get_std_save_message($retval);
147
	}
148
}
149
?>
150
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
151
<html>
152
<head>
153
<title><?=gentitle("Interfaces: Optional $index (" . htmlspecialchars($optcfg['descr']) . ")");?></title>
154
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
155
<link href="gui.css" rel="stylesheet" type="text/css">
156
<script language="JavaScript">
157
<!--
158
function enable_change(enable_over) {
159
	var endis;
160
	endis = !((document.iform.bridge.selectedIndex == 0) || enable_over);
161
	document.iform.ipaddr.disabled = endis;
162
	document.iform.subnet.disabled = endis;
163
}
164
function gen_bits(ipaddr) {
165
    if (ipaddr.search(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) != -1) {
166
        var adr = ipaddr.split(/\./);
167
        if (adr[0] > 255 || adr[1] > 255 || adr[2] > 255 || adr[3] > 255)
168
            return 0;
169
        if (adr[0] == 0 && adr[1] == 0 && adr[2] == 0 && adr[3] == 0)
170
            return 0;
171

    
172
		if (adr[0] <= 127)
173
			return 23;
174
		else if (adr[0] <= 191)
175
			return 15;
176
		else
177
			return 7;
178
    }
179
    else
180
        return 0;
181
}
182
function ipaddr_change() {
183
	document.iform.subnet.selectedIndex = gen_bits(document.iform.ipaddr.value);
184
}
185
//-->
186
</script>
187
</head>
188

    
189
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
190
<?php include("fbegin.inc"); ?>
191
<p class="pgtitle">Interfaces: Optional <?=$index;?> (<?=htmlspecialchars($optcfg['descr']);?>)</p>
192
<?php if ($input_errors) print_input_errors($input_errors); ?>
193
<?php if ($savemsg) print_info_box($savemsg); ?>
194
<?php if ($optcfg['if']): ?>
195
            <form action="interfaces_opt.php" method="post" name="iform" id="iform">
196
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
197
                <tr>
198
                  <td width="22%" valign="top" class="vtable">&nbsp;</td>
199
                  <td width="78%" class="vtable">
200
<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
201
                    <strong>Enable Optional <?=$index;?> interface</strong></td>
202
				</tr>
203
                <tr>
204
                  <td width="22%" valign="top" class="vncell">Description</td>
205
                  <td width="78%" class="vtable">
206
                    <input name="descr" type="text" class="formfld" id="descr" size="30" value="<?=htmlspecialchars($pconfig['descr']);?>">
207
					<br> <span class="vexpl">Enter a description (name) for the interface here.</span>
208
				 </td>
209
				</tr>
210
                <tr>
211
                  <td colspan="2" valign="top" height="16"></td>
212
				</tr>
213
				<tr>
214
                  <td colspan="2" valign="top" class="listtopic">IP configuration</td>
215
				</tr>
216
				<tr>
217
                  <td width="22%" valign="top" class="vncellreq">Bridge with</td>
218
                  <td width="78%" class="vtable">
219
<select name="bridge" class="formfld" id="bridge" onChange="enable_change(false)">
220
				  	<option <?php if (!$pconfig['bridge']) echo "selected";?> value="">none</option>
221
                      <?php $opts = array('lan' => "LAN", 'wan' => "WAN");
222
					  	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
223
							if ($i != $index)
224
								$opts['opt' . $i] = "Optional " . $i . " (" .
225
									$config['interfaces']['opt' . $i]['descr'] . ")";
226
						}
227
					foreach ($opts as $opt => $optname): ?>
228
                      <option <?php if ($opt == $pconfig['bridge']) echo "selected";?> value="<?=htmlspecialchars($opt);?>">
229
                      <?=htmlspecialchars($optname);?>
230
                      </option>
231
                      <?php endforeach; ?>
232
                    </select> </td>
233
				</tr>
234
                <tr>
235
                  <td width="22%" valign="top" class="vncellreq">IP address</td>
236
                  <td width="78%" class="vtable">
237
                    <input name="ipaddr" type="text" class="formfld" id="ipaddr" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>" onchange="ipaddr_change()">
238
                    /
239
                	<select name="subnet" class="formfld" id="subnet">
240
					<?php
241
					for ($i = 32; $i > 0; $i--) {
242
						if($i <> 31) {
243
							echo "<option value=\"{$i}\" ";
244
							if ($i == $pconfig['subnet']) echo "selected";
245
							echo ">" . $i . "</option>";
246
						}
247
					}
248
					?>                    </select>
249
				 </td>
250
				</tr>
251
				<?php /* Wireless interface? */
252
				if (isset($optcfg['wireless']))
253
					wireless_config_print();
254
				?>
255
                <tr>
256
                  <td colspan="2" valign="top" height="16"></td>
257
                </tr>
258
                <tr>
259
                  <td colspan="2" valign="top" class="vnsepcell">Bandwidth Management (Traffic Shaping)</td>
260
                </tr>
261
                <tr>
262
                  <td valign="top" class="vncell">Interface Bandwidth Speed</td>
263
                  <td class="vtable"> <input name="bandwidth" type="text" class="formfld" id="bandwidth" size="30" value="<?=htmlspecialchars($pconfig['bandwidth']);?>">
264
			<select name="bandwidthtype">
265
				<option value="<?=htmlspecialchars($pconfig['bandwidthtype']);?>"><?=htmlspecialchars($pconfig['bandwidthtype']);?></option>
266
				<option value="b">bit/s</option>
267
				<option value="Kb">Kilobit/s</option>
268
				<option value="Mb">Megabit/s</option>
269
				<option value="Gb">Gigabit/s</option>
270
				<option value=""></option>
271
			</select>
272
			<br> The bandwidth setting will define the speed of the interface for traffic shaping.
273
		  </td>
274
                </tr>                <tr>
275
                  <td width="22%" valign="top">&nbsp;</td>
276
                  <td width="78%">
277
                    <input name="index" type="hidden" value="<?=$index;?>">
278
				  <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
279
                  </td>
280
                </tr>
281
                <tr>
282
                  <td width="22%" valign="top">&nbsp;</td>
283
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
284
                    </strong></span>be sure to add firewall rules to permit traffic
285
                    through the interface. Firewall rules for an interface in
286
                    bridged mode have no effect on packets to hosts other than
287
                    m0n0wall itself, unless &quot;Enable filtering bridge&quot;
288
                    is checked on the <a href="system_advanced.php">System:
289
                    Advanced functions</a> page.</span></td>
290
                </tr>
291
              </table>
292
</form>
293
<script language="JavaScript">
294
<!--
295
enable_change(false);
296
//-->
297
</script>
298
<?php else: ?>
299
<p><strong>Optional <?=$index;?> has been disabled because there is no OPT<?=$index;?> interface.</strong></p>
300
<?php endif; ?>
301
<?php include("fend.inc"); ?>
302
</body>
303
</html>
(46-46/101)