Project

General

Profile

Download (10.2 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	interfaces_lan.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
$lancfg = &$config['interfaces']['lan'];
36
$optcfg = &$config['interfaces']['lan'];
37

    
38
$pconfig['ipaddr'] = $lancfg['ipaddr'];
39
$pconfig['subnet'] = $lancfg['subnet'];
40
$pconfig['bridge'] = $lancfg['bridge'];
41
$pconfig['bandwidth'] = $lancfg['bandwidth'];
42
$pconfig['bandwidthtype'] = $lancfg['bandwidthtype'];
43

    
44
/* Wireless interface? */
45
if (isset($lancfg['wireless'])) {
46
	require("interfaces_wlan.inc");
47
	wireless_config_init();
48
}
49

    
50
if ($_POST) {
51

    
52
	if ($_POST['bridge']) {
53
		/* double bridging? */
54
		for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
55
			if ($i != $index) {
56
				if ($config['interfaces']['opt' . $i]['bridge'] == $_POST['bridge']) {
57
					//$input_errors[] = "Optional interface {$i} " .
58
					//	"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
59
					//	"the specified interface.";
60
				} else if ($config['interfaces']['opt' . $i]['bridge'] == "opt{$index}") {
61
					//$input_errors[] = "Optional interface {$i} " .
62
					//	"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
63
					//	"this interface.";
64
				}
65
			}
66
		}
67
		if ($config['interfaces'][$_POST['bridge']]['bridge']) {
68
			//$input_errors[] = "The specified interface is already bridged to " .
69
			//	"another interface.";
70
		}
71
		/* captive portal on? */
72
		if (isset($config['captiveportal']['enable'])) {
73
			//$input_errors[] = "Interfaces cannot be bridged while the captive portal is enabled.";
74
		}
75
	}
76

    
77
	unset($input_errors);
78
	$pconfig = $_POST;
79
	$changedesc = "LAN Interface: ";
80

    
81
	/* input validation */
82
	if (!$_POST['bridge']) {
83
		$reqdfields = explode(" ", "ipaddr subnet");
84
		$reqdfieldsn = explode(",", "IP address,Subnet bit count");
85
		
86
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
87
	}
88

    
89
	if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
90
		$input_errors[] = "A valid IP address must be specified.";
91
	}
92
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
93
		$input_errors[] = "A valid subnet bit count must be specified.";
94
	}
95
	if($_POST['bandwidth'] <> "" && !is_numeric($_POST['bandwidth'])) {
96
		$input_errors[] = "A valid bandwidth value is required 1-999999.";
97
	}
98

    
99
	/* Wireless interface? */
100
	if (isset($lancfg['wireless'])) {
101
		$wi_input_errors = wireless_config_post();
102
		if ($wi_input_errors) {
103
			$input_errors = array_merge($input_errors, $wi_input_errors);
104
		}
105
	}
106

    
107
	if (!$input_errors) {
108
		
109
		$lancfg['bridge'] = $_POST['bridge'];
110
		
111
		if (($lancfg['ipaddr'] != $_POST['ipaddr']) || ($lancfg['subnet'] != $_POST['subnet'])) {
112
			update_if_changed("IP Address", &$lancfg['ipaddr'], $_POST['ipaddr']);
113
			update_if_changed("subnet", &$lancfg['subnet'], $_POST['subnet']);
114
		}
115

    
116
		if($_POST['bandwidth'] <> "" and $_POST['bandwidthtype'] <> "") {
117
			update_if_changed("bandwidth", &$lancfg['bandwidth'], $_POST['bandwidth']);
118
			update_if_changed("bandwidth type", &$lancfg['bandwidthtype'], $_POST['bandwidthtype']);
119
		} else {
120
			unset($lancfg['bandwidth']);
121
			unset($lancfg['bandwidthtype']);
122
		}
123

    
124
		write_config($changedesc);
125

    
126
		touch($d_landirty_path);
127

    
128
		if ($_POST['apply'] <> "") {
129
			unlink($d_landirty_path);
130
			$savemsg = "The changes have been applied.  You may need to correct the web browsers ip address.";
131
		}
132

    
133
	}
134
}
135

    
136

    
137
$pgtitle = "Interfaces: LAN";
138
include("head.inc");
139

    
140
?>
141
<script type="text/javascript" language="javascript" src="ip_helper.js">
142
</script>
143

    
144
<script language="JavaScript">
145
<!--
146
function ipaddr_change() {
147
	document.iform.subnet.value = gen_bits_lan(document.iform.ipaddr.value);
148
}
149
function enable_change(enable_over) {
150
	return;
151
	var endis;
152
	endis = !((document.iform.bridge.selectedIndex == 0) || enable_over);
153
	document.iform.ipaddr.disabled = endis;
154
	document.iform.subnet.disabled = endis;
155
}
156
// -->
157
</script>
158

    
159

    
160
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
161
<form action="interfaces_lan.php" method="post" name="iform" id="iform">
162
<?php include("fbegin.inc"); ?>
163
<p class="pgtitle"><?=$pgtitle?></p>
164
<?php if ($input_errors) print_input_errors($input_errors); ?>
165
<?php if (file_exists($d_landirty_path)): ?><p>
166
<?php print_info_box_np("The LAN configuration has been changed.<p>You must apply the changes in order for them to take effect.<p>Don't forget to adjust the DHCP Server range if needed before applying.");?><br>
167
<?php endif; ?>
168
<?php if ($savemsg) print_info_box_np($savemsg); ?>
169
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
170
		<tr>
171
                  <td colspan="2" valign="top" class="listtopic">IP configuration</td>
172
		</tr>	      
173
		<tr>
174
                  <td width="22%" valign="top" class="vncellreq">Bridge with</td>
175
                  <td width="78%" class="vtable">
176
			<select name="bridge" class="formfld" id="bridge" onChange="enable_change(false)">
177
				  	<option <?php if (!$pconfig['bridge']) echo "selected";?> value="">none</option>
178
                      <?php $opts = array('lan' => "LAN", 'wan' => "WAN");
179
					  	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
180
							if ($i != $index)
181
								$opts['opt' . $i] = "Optional " . $i . " (" .
182
									$config['interfaces']['opt' . $i]['descr'] . ")";
183
						}
184
					foreach ($opts as $opt => $optname): ?>
185
                      <option <?php if ($opt == $pconfig['bridge']) echo "selected";?> value="<?=htmlspecialchars($opt);?>">
186
                      <?=htmlspecialchars($optname);?>
187
                      </option>
188
                      <?php endforeach; ?>
189
                    </select> </td>
190
		</tr>	      
191
                <tr>
192
                  <td width="22%" valign="top" class="vncellreq">IP address</td>
193
                  <td width="78%" class="vtable">
194
                    <input name="ipaddr" type="text" class="formfld" id="hostname" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>" onchange="ipaddr_change()">
195
                    /
196
                    <select name="subnet" class="formfld" id="subnet">
197
					<?php
198
					for ($i = 32; $i > 0; $i--) {
199
						if($i <> 31) {
200
							echo "<option value=\"{$i}\" ";
201
							if ($i == $pconfig['subnet']) echo "selected";
202
							echo ">" . $i . "</option>";
203
						}
204
					}
205
					?>
206
                    </select></td>
207
                </tr>
208
				<?php /* Wireless interface? */
209
				if (isset($lancfg['wireless']))
210
					wireless_config_print();
211
				?>
212

    
213
                <tr>
214
                  <td colspan="2" valign="top" height="16"></td>
215
                </tr>
216

    
217
                <tr>
218
                  <td colspan="2" valign="top" class="vnsepcell">Bandwidth Management (Traffic Shaping)</td>
219
                </tr>
220
                <tr>
221
                  <td valign="top" class="vncell">Interface Bandwidth Speed</td>
222
                  <td class="vtable"> <input name="bandwidth" type="text" class="formfld" id="bandwidth" size="30" value="<?=htmlspecialchars($pconfig['bandwidth']);?>">
223
			<select name="bandwidthtype">
224
				<option value="<?=htmlspecialchars($pconfig['bandwidthtype']);?>"><?=htmlspecialchars($pconfig['bandwidthtype']);?></option>
225
				<option value="b">bit/s</option>
226
				<option value="Kb">Kilobit/s</option>
227
				<option value="Mb">Megabit/s</option>
228
				<option value="Gb">Gigabit/s</option>
229
				<option value=""></option>
230
			</select>
231
			<br> The bandwidth setting will define the speed of the interface for traffic shaping.  Do not enter your "Internet" bandwidth here, only the physical speed!
232
		  </td>
233
                </tr>
234
                <tr>
235
                  <td width="22%" valign="top">&nbsp;</td>
236
                  <td width="78%">
237
                    <input name="Submit" type="submit" class="formbtn" value="Save">
238
                  </td>
239
                </tr>
240
                <tr>
241
                  <td width="22%" valign="top">&nbsp;</td>
242
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Warning:<br>
243
                    </strong></span>after you click &quot;Save&quot;, you will need
244
                    to do one or more of the following steps before you can
245
                    access your firewall again:
246
                    <ul>
247
                      <li>change the IP address of your computer</li>
248
                      <li>renew its DHCP lease</li>
249
                      <li>access the webGUI with the new IP address</li>
250
		      <li>be sure to add <a href="firewall_rules.php">firewall rules</a> to permit traffic through the interface.</li>
251
		      <li>You also need firewall rules for an interface in bridged mode as the firewall acts as a filtering bridge.</li>
252
                    </ul>
253
                    </span></td>
254
                </tr>
255
              </table>
256
</form>
257
<?php include("fend.inc"); ?>
258
</body>
259
</html>
260

    
261
<?php
262

    
263
if ($_POST['apply'] <> "") {
264

    
265
	/*   Change these items late in the script
266
	 *   so the script will fully complete to
267
         *   the users web browser
268
	 */
269

    
270
	/* set up LAN interface */
271
	interfaces_lan_configure();
272

    
273
	interfaces_vlan_configure();
274
	
275
	/* setup carp interfaces */
276
	interfaces_carp_configure();
277

    
278
	/* bring up carp interfaces */
279
	interfaces_carp_bringup();
280
	
281
	unlink($d_landirty_path);
282
	
283
}
284

    
285
?>
(61-61/146)