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
$pconfig['ipaddr'] = $lancfg['ipaddr'];
37
$pconfig['subnet'] = $lancfg['subnet'];
38
$pconfig['bridge'] = $optcfg['bridge'];
39
$pconfig['bandwidth'] = $lancfg['bandwidth'];
40
$pconfig['bandwidthtype'] = $lancfg['bandwidthtype'];
41

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

    
48
if ($_POST) {
49

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

    
75
		unset($input_errors);
76
		$pconfig = $_POST;
77
		$changedesc = "LAN Interface: ";
78
	
79
		/* input validation */
80
		$reqdfields = explode(" ", "ipaddr subnet");
81
		$reqdfieldsn = explode(",", "IP address,Subnet bit count");
82
	
83
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
84
	
85
		if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
86
			$input_errors[] = "A valid IP address must be specified.";
87
		}
88
		if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
89
			$input_errors[] = "A valid subnet bit count must be specified.";
90
		}
91
	
92
		/* Wireless interface? */
93
		if (isset($lancfg['wireless'])) {
94
			$wi_input_errors = wireless_config_post();
95
			if ($wi_input_errors) {
96
				$input_errors = array_merge($input_errors, $wi_input_errors);
97
			}
98
		}
99
	
100
		if (!$input_errors) {
101
			$optcfg['bridge'] = $_POST['bridge'];
102
			if (($lancfg['ipaddr'] != $_POST['ipaddr']) || ($lancfg['subnet'] != $_POST['subnet'])) {
103
				update_if_changed("IP Address", &$lancfg['ipaddr'], $_POST['ipaddr']);
104
				update_if_changed("subnet", &$lancfg['subnet'], $_POST['subnet']);
105
	
106
				/* We'll need to reboot after this */
107
				touch($d_sysrebootreqd_path);
108
			}
109
	
110
			if($_POST['bandwidth'] <> "" and $_POST['bandwidthtype'] <> "") {
111
				update_if_changed("bandwidth", &$lancfg['bandwidth'], $_POST['bandwidth']);
112
				update_if_changed("bandwidth type", &$lancfg['bandwidthtype'], $_POST['bandwidthtype']);
113
			} else {
114
				unset($lancfg['bandwidth']);
115
				unset($lancfg['bandwidthtype']);
116
			}
117
	
118
			$dhcpd_was_enabled = 0;
119
			if (isset($config['dhcpd']['enable'])) {
120
				unset($config['dhcpd']['enable']);
121
				$dhcpd_was_enabled = 1;
122
				$changedesc .= " DHCP disabled";
123
			}
124
	
125
			write_config($changedesc);
126
	
127
					
128
			if ($dhcpd_was_enabled)
129
				$savemsg .= "<br>Note that the DHCP server has been disabled.<br>Please review its configuration " .
130
					"and enable it again prior to rebooting.";
131
			else
132
				$savemsg = "The changes have been applied.  You may need to correct the web browsers ip address.";
133
		}
134
	}
135
}
136

    
137

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

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

    
145
<script language="JavaScript">
146
<!--
147
function ipaddr_change() {
148
	document.iform.subnet.value = gen_bits_lan(document.iform.ipaddr.value);
149
}
150
function enable_change(enable_over) {
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
<?php include("fbegin.inc"); ?>
162
<p class="pgtitle"><?=$pgtitle?></p>
163
<?php if ($input_errors) print_input_errors($input_errors); ?>
164
<?php if ($savemsg) print_info_box($savemsg); ?>
165
            <form action="interfaces_lan.php" method="post" name="iform" id="iform">
166
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
167
		<tr>
168
                  <td colspan="2" valign="top" class="listtopic">IP configuration</td>
169
		</tr>	      
170
		<tr>
171
                  <td width="22%" valign="top" class="vncellreq">Bridge with</td>
172
                  <td width="78%" class="vtable">
173
			<select name="bridge" class="formfld" id="bridge" onChange="enable_change(false)">
174
				  	<option <?php if (!$pconfig['bridge']) echo "selected";?> value="">none</option>
175
                      <?php $opts = array('lan' => "LAN", 'wan' => "WAN");
176
					  	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
177
							if ($i != $index)
178
								$opts['opt' . $i] = "Optional " . $i . " (" .
179
									$config['interfaces']['opt' . $i]['descr'] . ")";
180
						}
181
					foreach ($opts as $opt => $optname): ?>
182
                      <option <?php if ($opt == $pconfig['bridge']) echo "selected";?> value="<?=htmlspecialchars($opt);?>">
183
                      <?=htmlspecialchars($optname);?>
184
                      </option>
185
                      <?php endforeach; ?>
186
                    </select> </td>
187
		</tr>	      
188
                <tr>
189
                  <td width="22%" valign="top" class="vncellreq">IP address</td>
190
                  <td width="78%" class="vtable">
191
                    <input name="ipaddr" type="text" class="formfld" id="hostname" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>" onchange="ipaddr_change()">
192
                    /
193
                    <select name="subnet" class="formfld" id="subnet">
194
					<?php
195
					for ($i = 32; $i > 0; $i--) {
196
						if($i <> 31) {
197
							echo "<option value=\"{$i}\" ";
198
							if ($i == $pconfig['subnet']) echo "selected";
199
							echo ">" . $i . "</option>";
200
						}
201
					}
202
					?>
203
                    </select></td>
204
                </tr>
205
				<?php /* Wireless interface? */
206
				if (isset($lancfg['wireless']))
207
					wireless_config_print();
208
				?>
209

    
210
                <tr>
211
                  <td colspan="2" valign="top" height="16"></td>
212
                </tr>
213

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

    
263
<?php
264

    
265
if ($_POST) {
266

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

    
272
	/* set up LAN interface */
273
	interfaces_lan_configure();
274

    
275
	interfaces_vlan_configure();
276
	
277
	/* setup carp interfaces */
278
	interfaces_carp_configure();
279

    
280
	/* bring up carp interfaces */
281
	interfaces_carp_bringup();	
282
	
283
}
284

    
285
?>
(58-58/137)