Project

General

Profile

Download (10.1 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
$pconfig['enable'] = isset($optcfg['enable']);
49

    
50
/* Wireless interface? */
51
if (isset($optcfg['wireless'])) {
52
	require("interfaces_wlan.inc");
53
	wireless_config_init();
54
}
55

    
56
if ($_POST) {
57

    
58
	unset($input_errors);
59
	$pconfig = $_POST;
60

    
61
	/* input validation */
62
	if ($_POST['enable']) {
63
	
64
		/* description unique? */
65
		for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
66
			if ($i != $index) {
67
				if ($config['interfaces']['opt' . $i]['descr'] == $_POST['descr']) {
68
					$input_errors[] = "An interface with the specified description already exists.";
69
				}
70
			}
71
		}
72
		
73
		if ($_POST['bridge']) {
74
			/* double bridging? */
75
			for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
76
				if ($i != $index) {
77
					if ($config['interfaces']['opt' . $i]['bridge'] == $_POST['bridge']) {
78
						$input_errors[] = "Optional interface {$i} " . 
79
							"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
80
							"the specified interface.";
81
					} else if ($config['interfaces']['opt' . $i]['bridge'] == "opt{$index}") {
82
						$input_errors[] = "Optional interface {$i} " . 
83
							"({$config['interfaces']['opt' . $i]['descr']}) is already bridged to " .
84
							"this interface.";
85
					}
86
				}
87
			}
88
			if ($config['interfaces'][$_POST['bridge']]['bridge']) {
89
				$input_errors[] = "The specified interface is already bridged to " .
90
					"another interface.";
91
			}
92
			/* captive portal on? */
93
			if (isset($config['captiveportal']['enable'])) {
94
				$input_errors[] = "Interfaces cannot be bridged while the captive portal is enabled.";
95
			}
96
		} else {
97
			$reqdfields = explode(" ", "descr ipaddr subnet");
98
			$reqdfieldsn = explode(",", "Description,IP address,Subnet bit count");
99
		
100
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
101
		
102
			if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
103
				$input_errors[] = "A valid IP address must be specified.";
104
			}
105
			if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
106
				$input_errors[] = "A valid subnet bit count must be specified.";
107
			}
108
		}
109
	}
110
	
111
	/* Wireless interface? */
112
	if (isset($optcfg['wireless'])) {
113
		$wi_input_errors = wireless_config_post();
114
		if ($wi_input_errors) {
115
			$input_errors = array_merge($input_errors, $wi_input_errors);
116
		}
117
	}
118
	
119
	if (!$input_errors) {
120
		$optcfg['descr'] = $_POST['descr'];
121
		$optcfg['ipaddr'] = $_POST['ipaddr'];
122
		$optcfg['subnet'] = $_POST['subnet'];
123
		$optcfg['bridge'] = $_POST['bridge'];
124
		$optcfg['enable'] = $_POST['enable'] ? true : false;
125
			
126
		write_config();
127
		
128
		$retval = 0;
129
		if (!file_exists($d_sysrebootreqd_path)) {
130
			config_lock();
131
			$retval = interfaces_optional_configure();
132
			
133
			/* is this the captive portal interface? */
134
			if (isset($config['captiveportal']['enable']) && 
135
				($config['captiveportal']['interface'] == ('opt' . $index))) {
136
				captiveportal_configure();
137
			}
138
			config_unlock();
139
		}
140
		$savemsg = get_std_save_message($retval);
141
	}
142
}
143
?>
144
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
145
<html>
146
<head>
147
<title><?=gentitle("Interfaces: Optional $index (" . htmlspecialchars($optcfg['descr']) . ")");?></title>
148
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
149
<link href="gui.css" rel="stylesheet" type="text/css">
150
<script language="JavaScript">
151
<!--
152
function enable_change(enable_over) {
153
	if ((document.iform.bridge.selectedIndex == 0) || enable_over) {
154
		document.iform.ipaddr.disabled = 0;
155
		document.iform.subnet.disabled = 0;
156
	} else {
157
		document.iform.ipaddr.disabled = 1;
158
		document.iform.subnet.disabled = 1;
159
	}
160
}
161
function gen_bits(ipaddr) {
162
    if (ipaddr.search(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) != -1) {
163
        var adr = ipaddr.split(/\./);
164
        if (adr[0] > 255 || adr[1] > 255 || adr[2] > 255 || adr[3] > 255)
165
            return 0;
166
        if (adr[0] == 0 && adr[1] == 0 && adr[2] == 0 && adr[3] == 0)
167
            return 0;
168
		
169
		if (adr[0] <= 127)
170
			return 23;
171
		else if (adr[0] <= 191)
172
			return 15;
173
		else
174
			return 7;
175
    }
176
    else
177
        return 0;
178
}
179
function ipaddr_change() {
180
	document.iform.subnet.selectedIndex = gen_bits(document.iform.ipaddr.value);
181
}
182
//-->
183
</script>
184
</head>
185

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