1 |
5b237745
|
Scott Ullrich
|
#!/usr/local/bin/php
|
2 |
|
|
<?php
|
3 |
|
|
/*
|
4 |
|
|
interfaces_assign.php
|
5 |
|
|
part of m0n0wall (http://m0n0.ch/wall)
|
6 |
|
|
Written by Jim McBeath based on existing m0n0wall files
|
7 |
|
|
|
8 |
94a77286
|
Scott Ullrich
|
Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
|
9 |
5b237745
|
Scott Ullrich
|
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 |
94a77286
|
Scott Ullrich
|
$pgtitle = array("Interfaces", "Assign network ports");
|
34 |
5b237745
|
Scott Ullrich
|
require("guiconfig.inc");
|
35 |
|
|
|
36 |
|
|
/*
|
37 |
|
|
In this file, "port" refers to the physical port name,
|
38 |
|
|
while "interface" refers to LAN, WAN, or OPTn.
|
39 |
|
|
*/
|
40 |
|
|
|
41 |
|
|
/* get list without VLAN interfaces */
|
42 |
|
|
$portlist = get_interface_list();
|
43 |
|
|
|
44 |
|
|
/* add VLAN interfaces */
|
45 |
|
|
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
|
46 |
|
|
$i = 0;
|
47 |
|
|
foreach ($config['vlans']['vlan'] as $vlan) {
|
48 |
|
|
$portlist['vlan' . $i] = $vlan;
|
49 |
|
|
$portlist['vlan' . $i]['isvlan'] = true;
|
50 |
|
|
$i++;
|
51 |
|
|
}
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
if ($_POST) {
|
55 |
|
|
|
56 |
|
|
unset($input_errors);
|
57 |
|
|
|
58 |
|
|
/* input validation */
|
59 |
|
|
|
60 |
|
|
/* Build a list of the port names so we can see how the interfaces map */
|
61 |
|
|
$portifmap = array();
|
62 |
|
|
foreach ($portlist as $portname => $portinfo)
|
63 |
|
|
$portifmap[$portname] = array();
|
64 |
|
|
|
65 |
|
|
/* Go through the list of ports selected by the user,
|
66 |
|
|
build a list of port-to-interface mappings in portifmap */
|
67 |
|
|
foreach ($_POST as $ifname => $ifport) {
|
68 |
|
|
if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
|
69 |
|
|
$portifmap[$ifport][] = strtoupper($ifname);
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
/* Deliver error message for any port with more than one assignment */
|
73 |
|
|
foreach ($portifmap as $portname => $ifnames) {
|
74 |
|
|
if (count($ifnames) > 1) {
|
75 |
|
|
$errstr = "Port " . $portname .
|
76 |
|
|
" was assigned to " . count($ifnames) .
|
77 |
|
|
" interfaces:";
|
78 |
|
|
|
79 |
|
|
foreach ($portifmap[$portname] as $ifn)
|
80 |
|
|
$errstr .= " " . $ifn;
|
81 |
|
|
|
82 |
|
|
$input_errors[] = $errstr;
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
if (!$input_errors) {
|
88 |
|
|
/* No errors detected, so update the config */
|
89 |
|
|
foreach ($_POST as $ifname => $ifport) {
|
90 |
|
|
|
91 |
|
|
if (($ifname == 'lan') || ($ifname == 'wan') ||
|
92 |
|
|
(substr($ifname, 0, 3) == 'opt')) {
|
93 |
|
|
|
94 |
|
|
if (!is_array($ifport)) {
|
95 |
|
|
$config['interfaces'][$ifname]['if'] = $ifport;
|
96 |
|
|
|
97 |
|
|
/* check for wireless interfaces, set or clear ['wireless'] */
|
98 |
94a77286
|
Scott Ullrich
|
if (preg_match($g['wireless_regex'], $ifport)) {
|
99 |
5b237745
|
Scott Ullrich
|
if (!is_array($config['interfaces'][$ifname]['wireless']))
|
100 |
|
|
$config['interfaces'][$ifname]['wireless'] = array();
|
101 |
|
|
} else {
|
102 |
|
|
unset($config['interfaces'][$ifname]['wireless']);
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
/* make sure there is a name for OPTn */
|
106 |
|
|
if (substr($ifname, 0, 3) == 'opt') {
|
107 |
|
|
if (!isset($config['interfaces'][$ifname]['descr']))
|
108 |
|
|
$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
|
109 |
|
|
}
|
110 |
|
|
}
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
|
114 |
2e506568
|
Scott Ullrich
|
$savemsg = get_std_save_message($retval);
|
115 |
|
|
|
116 |
5b237745
|
Scott Ullrich
|
write_config();
|
117 |
182c30de
|
Scott Ullrich
|
|
118 |
5b237745
|
Scott Ullrich
|
}
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
if ($_GET['act'] == "del") {
|
122 |
|
|
$id = $_GET['id'];
|
123 |
|
|
|
124 |
|
|
unset($config['interfaces'][$id]); /* delete the specified OPTn */
|
125 |
|
|
|
126 |
|
|
/* shift down other OPTn interfaces to get rid of holes */
|
127 |
|
|
$i = substr($id, 3); /* the number of the OPTn port being deleted */
|
128 |
|
|
$i++;
|
129 |
|
|
|
130 |
|
|
/* look at the following OPTn ports */
|
131 |
|
|
while (is_array($config['interfaces']['opt' . $i])) {
|
132 |
|
|
$config['interfaces']['opt' . ($i - 1)] =
|
133 |
|
|
$config['interfaces']['opt' . $i];
|
134 |
|
|
|
135 |
|
|
if ($config['interfaces']['opt' . ($i - 1)]['descr'] == "OPT" . $i)
|
136 |
|
|
$config['interfaces']['opt' . ($i - 1)]['descr'] = "OPT" . ($i - 1);
|
137 |
|
|
|
138 |
|
|
unset($config['interfaces']['opt' . $i]);
|
139 |
|
|
$i++;
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
write_config();
|
143 |
|
|
touch($d_sysrebootreqd_path);
|
144 |
|
|
header("Location: interfaces_assign.php");
|
145 |
|
|
exit;
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
if ($_GET['act'] == "add") {
|
149 |
|
|
/* find next free optional interface number */
|
150 |
|
|
$i = 1;
|
151 |
|
|
while (is_array($config['interfaces']['opt' . $i]))
|
152 |
|
|
$i++;
|
153 |
|
|
|
154 |
|
|
$newifname = 'opt' . $i;
|
155 |
|
|
$config['interfaces'][$newifname] = array();
|
156 |
|
|
$config['interfaces'][$newifname]['descr'] = "OPT" . $i;
|
157 |
|
|
|
158 |
|
|
/* Find an unused port for this interface */
|
159 |
|
|
foreach ($portlist as $portname => $portinfo) {
|
160 |
|
|
$portused = false;
|
161 |
|
|
foreach ($config['interfaces'] as $ifname => $ifdata) {
|
162 |
|
|
if ($ifdata['if'] == $portname) {
|
163 |
|
|
$portused = true;
|
164 |
|
|
break;
|
165 |
|
|
}
|
166 |
|
|
}
|
167 |
|
|
if (!$portused) {
|
168 |
|
|
$config['interfaces'][$newifname]['if'] = $portname;
|
169 |
94a77286
|
Scott Ullrich
|
if (preg_match($g['wireless_regex'], $portname))
|
170 |
5b237745
|
Scott Ullrich
|
$config['interfaces'][$newifname]['wireless'] = array();
|
171 |
|
|
break;
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
write_config();
|
176 |
093a01b0
|
Scott Ullrich
|
|
177 |
|
|
reload_interfaces();
|
178 |
|
|
|
179 |
5b237745
|
Scott Ullrich
|
header("Location: interfaces_assign.php");
|
180 |
|
|
exit;
|
181 |
|
|
}
|
182 |
|
|
|
183 |
7f43ca88
|
Scott Ullrich
|
|
184 |
|
|
$pgtitle = "Interfaces: Assign";
|
185 |
|
|
include("head.inc");
|
186 |
|
|
|
187 |
5b237745
|
Scott Ullrich
|
?>
|
188 |
6eb47218
|
Scott Ullrich
|
|
189 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
190 |
5b237745
|
Scott Ullrich
|
<?php include("fbegin.inc"); ?>
|
191 |
931066a8
|
Bill Marquette
|
<p class="pgtitle"><?=$pgtitle?></p>
|
192 |
5b237745
|
Scott Ullrich
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
193 |
2e506568
|
Scott Ullrich
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
194 |
5b237745
|
Scott Ullrich
|
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
|
195 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
196 |
94a77286
|
Scott Ullrich
|
<tr><td class="tabnavtbl">
|
197 |
c8b8ff69
|
Scott Ullrich
|
<?php
|
198 |
|
|
$tab_array = array();
|
199 |
931066a8
|
Bill Marquette
|
$tab_array[0] = array("Interface assignments", true, "interfaces_assign.php");
|
200 |
|
|
$tab_array[1] = array("VLANs", false, "interfaces_vlan.php");
|
201 |
c8b8ff69
|
Scott Ullrich
|
display_top_tabs($tab_array);
|
202 |
|
|
?>
|
203 |
5b237745
|
Scott Ullrich
|
</td></tr>
|
204 |
|
|
<tr>
|
205 |
d732f186
|
Bill Marquette
|
<td>
|
206 |
|
|
<div id="mainarea">
|
207 |
|
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
|
208 |
|
|
<tr>
|
209 |
5b237745
|
Scott Ullrich
|
<td class="listhdrr">Interface</td>
|
210 |
|
|
<td class="listhdr">Network port</td>
|
211 |
|
|
<td class="list"> </td>
|
212 |
|
|
</tr>
|
213 |
|
|
<?php foreach ($config['interfaces'] as $ifname => $iface):
|
214 |
|
|
if ($iface['descr'])
|
215 |
|
|
$ifdescr = $iface['descr'];
|
216 |
|
|
else
|
217 |
|
|
$ifdescr = strtoupper($ifname);
|
218 |
|
|
?>
|
219 |
|
|
<tr>
|
220 |
|
|
<td class="listlr" valign="middle"><strong><?=$ifdescr;?></strong></td>
|
221 |
|
|
<td valign="middle" class="listr">
|
222 |
|
|
<select name="<?=$ifname;?>" class="formfld" id="<?=$ifname;?>">
|
223 |
|
|
<?php foreach ($portlist as $portname => $portinfo): ?>
|
224 |
|
|
<option value="<?=$portname;?>" <?php if ($portname == $iface['if']) echo "selected";?>>
|
225 |
|
|
<?php if ($portinfo['isvlan']) {
|
226 |
|
|
$descr = "VLAN {$portinfo['tag']} on {$portinfo['if']}";
|
227 |
|
|
if ($portinfo['descr'])
|
228 |
|
|
$descr .= " (" . $portinfo['descr'] . ")";
|
229 |
|
|
echo htmlspecialchars($descr);
|
230 |
|
|
} else
|
231 |
|
|
echo htmlspecialchars($portname . " (" . $portinfo['mac'] . ")");
|
232 |
|
|
?>
|
233 |
|
|
</option>
|
234 |
|
|
<?php endforeach; ?>
|
235 |
|
|
</select>
|
236 |
|
|
</td>
|
237 |
|
|
<td valign="middle" class="list">
|
238 |
|
|
<?php if (($ifname != 'lan') && ($ifname != 'wan')): ?>
|
239 |
677c0869
|
Erik Kristensen
|
<a href="interfaces_assign.php?act=del&id=<?=$ifname;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="delete interface" width="17" height="17" border="0"></a>
|
240 |
5b237745
|
Scott Ullrich
|
<?php endif; ?>
|
241 |
|
|
</td>
|
242 |
|
|
</tr>
|
243 |
|
|
<?php endforeach; ?>
|
244 |
|
|
<?php if (count($config['interfaces']) < count($portlist)): ?>
|
245 |
|
|
<tr>
|
246 |
|
|
<td class="list" colspan="2"></td>
|
247 |
|
|
<td class="list" nowrap>
|
248 |
677c0869
|
Erik Kristensen
|
<a href="interfaces_assign.php?act=add"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add interface" width="17" height="17" border="0"></a>
|
249 |
5b237745
|
Scott Ullrich
|
</td>
|
250 |
|
|
</tr>
|
251 |
|
|
<?php else: ?>
|
252 |
|
|
<tr>
|
253 |
|
|
<td class="list" colspan="3" height="10"></td>
|
254 |
|
|
</tr>
|
255 |
|
|
<?php endif; ?>
|
256 |
|
|
</table>
|
257 |
d732f186
|
Bill Marquette
|
</div>
|
258 |
7f894be6
|
Scott Ullrich
|
<br>
|
259 |
|
|
<input name="Submit" type="submit" class="formbtn" value="Save"><br><br>
|
260 |
94a77286
|
Scott Ullrich
|
<p><span class="vexpl"><strong><span class="red">Warning:</span><br>
|
261 |
|
|
</strong>After you click "Save", you must reboot the firewall to make the changes take effect. You may also have to do one or more of the following steps before you can access your firewall again: </span></p>
|
262 |
|
|
<ul>
|
263 |
|
|
<li><span class="vexpl">change the IP address of your computer</span></li>
|
264 |
|
|
<li><span class="vexpl">renew its DHCP lease</span></li>
|
265 |
|
|
<li><span class="vexpl">access the webGUI with the new IP address</span></li>
|
266 |
|
|
</ul></td>
|
267 |
5b237745
|
Scott Ullrich
|
</tr>
|
268 |
|
|
</table>
|
269 |
|
|
</form>
|
270 |
|
|
<?php include("fend.inc"); ?>
|
271 |
c8b8ff69
|
Scott Ullrich
|
</body>
|
272 |
|
|
</html>
|
273 |
2e506568
|
Scott Ullrich
|
|
274 |
|
|
<?php
|
275 |
|
|
|
276 |
|
|
if($_POST) {
|
277 |
|
|
/* reload all interfaces configuration */
|
278 |
|
|
reload_interfaces();
|
279 |
|
|
}
|