Project

General

Profile

Download (10.1 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'] = $lancfg['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
	}
74

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

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

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

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

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

    
113
			/* We'll need to reboot after this */
114
			touch($d_sysrebootreqd_path);
115
		}
116

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

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

    
132
		write_config($changedesc);
133

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

    
144

    
145
$pgtitle = "Interfaces: LAN";
146
include("head.inc");
147

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

    
152
<script language="JavaScript">
153
<!--
154
function ipaddr_change() {
155
	document.iform.subnet.value = gen_bits_lan(document.iform.ipaddr.value);
156
}
157
function enable_change(enable_over) {
158
	return;
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
// -->
165
</script>
166

    
167

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

    
218
                <tr>
219
                  <td colspan="2" valign="top" height="16"></td>
220
                </tr>
221

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

    
266
<?php
267

    
268
if ($_POST) {
269

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

    
275
	/* set up LAN interface */
276
	interfaces_lan_configure();
277

    
278
	interfaces_vlan_configure();
279
	
280
	/* setup carp interfaces */
281
	interfaces_carp_configure();
282

    
283
	/* bring up carp interfaces */
284
	interfaces_carp_bringup();	
285
	
286
}
287

    
288
?>
(59-59/144)