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
			/* We'll need to reboot after this */
116
			touch($d_sysrebootreqd_path);
117
		}
118

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

    
127
		$dhcpd_was_enabled = 0;
128
		if (isset($config['dhcpd']['enable'])) {
129
			unset($config['dhcpd']['enable']);
130
			$dhcpd_was_enabled = 1;
131
			$changedesc .= " DHCP disabled";
132
		}
133

    
134
		write_config($changedesc);
135

    
136
		$savemsg = get_std_save_message($retval);
137
				
138
		if ($dhcpd_was_enabled)
139
			$savemsg .= "<br>Note that the DHCP server has been disabled.<br>Please review its configuration " .
140
				"and enable it again prior to rebooting.";
141
		else
142
			$savemsg = "The changes have been applied.  You may need to correct the web browsers ip address.";
143
	}
144
}
145

    
146

    
147
$pgtitle = "Interfaces: LAN";
148
include("head.inc");
149

    
150
?>
151
<script type="text/javascript" language="javascript" src="ip_helper.js">
152
</script>
153

    
154
<script language="JavaScript">
155
<!--
156
function ipaddr_change() {
157
	document.iform.subnet.value = gen_bits_lan(document.iform.ipaddr.value);
158
}
159
function enable_change(enable_over) {
160
	return;
161
	var endis;
162
	endis = !((document.iform.bridge.selectedIndex == 0) || enable_over);
163
	document.iform.ipaddr.disabled = endis;
164
	document.iform.subnet.disabled = endis;
165
}
166
// -->
167
</script>
168

    
169

    
170
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
171
<?php include("fbegin.inc"); ?>
172
<p class="pgtitle"><?=$pgtitle?></p>
173
<?php if ($input_errors) print_input_errors($input_errors); ?>
174
<?php if ($savemsg) print_info_box($savemsg); ?>
175
            <form action="interfaces_lan.php" method="post" name="iform" id="iform">
176
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
177
		<tr>
178
                  <td colspan="2" valign="top" class="listtopic">IP configuration</td>
179
		</tr>	      
180
		<tr>
181
                  <td width="22%" valign="top" class="vncellreq">Bridge with</td>
182
                  <td width="78%" class="vtable">
183
			<select name="bridge" class="formfld" id="bridge" onChange="enable_change(false)">
184
				  	<option <?php if (!$pconfig['bridge']) echo "selected";?> value="">none</option>
185
                      <?php $opts = array('lan' => "LAN", 'wan' => "WAN");
186
					  	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
187
							if ($i != $index)
188
								$opts['opt' . $i] = "Optional " . $i . " (" .
189
									$config['interfaces']['opt' . $i]['descr'] . ")";
190
						}
191
					foreach ($opts as $opt => $optname): ?>
192
                      <option <?php if ($opt == $pconfig['bridge']) echo "selected";?> value="<?=htmlspecialchars($opt);?>">
193
                      <?=htmlspecialchars($optname);?>
194
                      </option>
195
                      <?php endforeach; ?>
196
                    </select> </td>
197
		</tr>	      
198
                <tr>
199
                  <td width="22%" valign="top" class="vncellreq">IP address</td>
200
                  <td width="78%" class="vtable">
201
                    <input name="ipaddr" type="text" class="formfld" id="hostname" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>" onchange="ipaddr_change()">
202
                    /
203
                    <select name="subnet" class="formfld" id="subnet">
204
					<?php
205
					for ($i = 32; $i > 0; $i--) {
206
						if($i <> 31) {
207
							echo "<option value=\"{$i}\" ";
208
							if ($i == $pconfig['subnet']) echo "selected";
209
							echo ">" . $i . "</option>";
210
						}
211
					}
212
					?>
213
                    </select></td>
214
                </tr>
215
				<?php /* Wireless interface? */
216
				if (isset($lancfg['wireless']))
217
					wireless_config_print();
218
				?>
219

    
220
                <tr>
221
                  <td colspan="2" valign="top" height="16"></td>
222
                </tr>
223

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

    
268
<?php
269

    
270
if ($_POST) {
271

    
272
	/*   Change these items late in the script
273
	 *   so the script will fully complete to
274
         *   the users web browser
275
	 */
276

    
277
	/* set up LAN interface */
278
	interfaces_lan_configure();
279

    
280
	interfaces_vlan_configure();
281
	
282
	/* setup carp interfaces */
283
	interfaces_carp_configure();
284

    
285
	/* bring up carp interfaces */
286
	interfaces_carp_bringup();	
287
	
288
}
289

    
290
?>
(59-59/144)