1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
<?php
/*
interfaces_assign.php
part of m0n0wall (http://m0n0.ch/wall)
Written by Jim McBeath based on existing m0n0wall files
Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
$pgtitle = array("Interfaces", "Assign network ports");
require("guiconfig.inc");
/*
In this file, "port" refers to the physical port name,
while "interface" refers to LAN, WAN, or OPTn.
*/
/* get list without VLAN interfaces */
$portlist = get_interface_list();
/* add VLAN interfaces */
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
$i = 0;
foreach ($config['vlans']['vlan'] as $vlan) {
$portlist['vlan' . $i] = $vlan;
$portlist['vlan' . $i]['isvlan'] = true;
$i++;
}
}
if ($_POST) {
unset($input_errors);
/* input validation */
/* Build a list of the port names so we can see how the interfaces map */
$portifmap = array();
foreach ($portlist as $portname => $portinfo)
$portifmap[$portname] = array();
/* Go through the list of ports selected by the user,
build a list of port-to-interface mappings in portifmap */
foreach ($_POST as $ifname => $ifport) {
if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
$portifmap[$ifport][] = strtoupper($ifname);
}
/* Deliver error message for any port with more than one assignment */
foreach ($portifmap as $portname => $ifnames) {
if (count($ifnames) > 1) {
$errstr = "Port " . $portname .
" was assigned to " . count($ifnames) .
" interfaces:";
foreach ($portifmap[$portname] as $ifn)
$errstr .= " " . $ifn;
$input_errors[] = $errstr;
}
}
if (!$input_errors) {
/* No errors detected, so update the config */
foreach ($_POST as $ifname => $ifport) {
if (($ifname == 'lan') || ($ifname == 'wan') ||
(substr($ifname, 0, 3) == 'opt')) {
if (!is_array($ifport)) {
$config['interfaces'][$ifname]['if'] = $ifport;
/* check for wireless interfaces, set or clear ['wireless'] */
if (preg_match($g['wireless_regex'], $ifport)) {
if (!is_array($config['interfaces'][$ifname]['wireless']))
$config['interfaces'][$ifname]['wireless'] = array();
} else {
unset($config['interfaces'][$ifname]['wireless']);
}
/* make sure there is a name for OPTn */
if (substr($ifname, 0, 3) == 'opt') {
if (!isset($config['interfaces'][$ifname]['descr']))
$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
}
}
}
}
$savemsg = get_std_save_message($retval);
write_config();
}
}
if ($_GET['act'] == "del") {
$id = $_GET['id'];
$i = substr($id, 3); /* the number of the OPTn port being deleted */
unset($config['interfaces'][$id]['enable']);
interfaces_optional_configure_if($i); /* down the interface */
unset($config['interfaces'][$id]); /* delete the specified OPTn */
write_config();
/* move all the interfaces up. for example:
* opt1 --> opt1
* opt2 --> delete
* opt3 --> opt2
* opt4 --> opt3
*/
cleanup_opt_interfaces_after_removal($i);
parse_config(true);
$savemsg = "Interface has been deleted.";
}
if ($_GET['act'] == "add") {
/* find next free optional interface number */
$i = 1;
while (is_array($config['interfaces']['opt' . $i]))
$i++;
$newifname = 'opt' . $i;
$config['interfaces'][$newifname] = array();
$config['interfaces'][$newifname]['descr'] = "OPT" . $i;
/* Find an unused port for this interface */
foreach ($portlist as $portname => $portinfo) {
$portused = false;
foreach ($config['interfaces'] as $ifname => $ifdata) {
if ($ifdata['if'] == $portname) {
$portused = true;
break;
}
}
if (!$portused) {
$config['interfaces'][$newifname]['if'] = $portname;
if (preg_match($g['wireless_regex'], $portname))
$config['interfaces'][$newifname]['wireless'] = array();
break;
}
}
write_config();
$savemsg = "Interface has been added.";
}
$pgtitle = "Interfaces: Assign";
include("head.inc");
if(file_exists("/var/run/interface_mismatch_reboot_needed"))
if ($_POST)
$savemsg = "The firewall is now rebooting.";
else
$savemsg = "Interface mismatch deteceted. Please resolve the mismatch and click Save. The firewall will reboot afterwards.";
?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<p class="pgtitle"><?=$pgtitle?></p>
<?php if ($input_errors) print_input_errors($input_errors); ?>
<?php if ($savemsg) print_info_box($savemsg); ?>
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td class="tabnavtbl">
<?php
$tab_array = array();
$tab_array[0] = array("Interface assignments", true, "interfaces_assign.php");
$tab_array[1] = array("VLANs", false, "interfaces_vlan.php");
display_top_tabs($tab_array);
?>
</td></tr>
<tr>
<td>
<div id="mainarea">
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="listhdrr">Interface</td>
<td class="listhdr">Network port</td>
<td class="list"> </td>
</tr>
<?php foreach ($config['interfaces'] as $ifname => $iface):
if ($iface['descr'])
$ifdescr = $iface['descr'];
else
$ifdescr = strtoupper($ifname);
?>
<tr>
<td class="listlr" valign="middle"><strong><?=$ifdescr;?></strong></td>
<td valign="middle" class="listr">
<select name="<?=$ifname;?>" class="formfld" id="<?=$ifname;?>">
<?php foreach ($portlist as $portname => $portinfo): ?>
<option value="<?=$portname;?>" <?php if ($portname == $iface['if']) echo "selected";?>>
<?php if ($portinfo['isvlan']) {
$descr = "VLAN {$portinfo['tag']} on {$portinfo['if']}";
if ($portinfo['descr'])
$descr .= " (" . $portinfo['descr'] . ")";
echo htmlspecialchars($descr);
} else
echo htmlspecialchars($portname . " (" . $portinfo['mac'] . ")");
?>
</option>
<?php endforeach; ?>
</select>
</td>
<td valign="middle" class="list">
<?php if (($ifname != 'lan') && ($ifname != 'wan')): ?>
<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>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php if (count($config['interfaces']) < count($portlist)): ?>
<tr>
<td class="list" colspan="2"></td>
<td class="list" nowrap>
<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>
</td>
</tr>
<?php else: ?>
<tr>
<td class="list" colspan="3" height="10"></td>
</tr>
<?php endif; ?>
</table>
</div>
<br>
<input name="Submit" type="submit" class="formbtn" value="Save"><br><br>
<p>
</p>
<ul>
<li><span class="vexpl">change the IP address of your computer</span></li>
<li><span class="vexpl">renew its DHCP lease</span></li>
<li><span class="vexpl">access the webGUI with the new IP address</span></li>
</ul></td>
</tr>
</table>
</form>
<?php include("fend.inc"); ?>
</body>
</html>
<?php
if ($_POST) {
if (!$input_errors)
touch("/tmp/reload_interfaces");
if(file_exists("/var/run/interface_mismatch_reboot_needed"))
exec("/etc/rc.reboot");
}
?>
|