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