1 |
5b74202b
|
Scott Ullrich
|
<?php
|
2 |
|
|
/****h* pfSense/config
|
3 |
|
|
* NAME
|
4 |
|
|
* config.inc - Functions to manipulate config.xml
|
5 |
|
|
* DESCRIPTION
|
6 |
|
|
* This include contains various config.xml specific functions.
|
7 |
|
|
* HISTORY
|
8 |
|
|
* $Id$
|
9 |
|
|
******
|
10 |
|
|
|
11 |
|
|
config.console.inc
|
12 |
|
|
Copyright (C) 2004-2010 Scott Ullrich
|
13 |
|
|
All rights reserved.
|
14 |
|
|
|
15 |
|
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
16 |
|
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
17 |
|
|
All rights reserved.
|
18 |
|
|
|
19 |
|
|
Redistribution and use in source and binary forms, with or without
|
20 |
|
|
modification, are permitted provided that the following conditions are met:
|
21 |
|
|
|
22 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
23 |
|
|
this list of conditions and the following disclaimer.
|
24 |
|
|
|
25 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
26 |
|
|
notice, this list of conditions and the following disclaimer in the
|
27 |
|
|
documentation and/or other materials provided with the distribution.
|
28 |
|
|
|
29 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
30 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
31 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
32 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
33 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
34 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
35 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
36 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
37 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
38 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
39 |
|
|
|
40 |
|
|
|
41 |
971de1f9
|
Renato Botelho
|
pfSense_BUILDER_BINARIES: /sbin/mount /sbin/umount /sbin/halt /sbin/fsck
|
42 |
5b74202b
|
Scott Ullrich
|
pfSense_MODULE: config
|
43 |
|
|
*/
|
44 |
|
|
|
45 |
|
|
function set_networking_interfaces_ports() {
|
46 |
|
|
global $noreboot;
|
47 |
|
|
global $config;
|
48 |
|
|
global $g;
|
49 |
|
|
global $fp;
|
50 |
|
|
|
51 |
|
|
$fp = fopen('php://stdin', 'r');
|
52 |
|
|
|
53 |
|
|
$memory = get_memory();
|
54 |
493360f5
|
Phil Davis
|
$physmem = $memory[0];
|
55 |
|
|
$realmem = $memory[1];
|
56 |
5b74202b
|
Scott Ullrich
|
|
57 |
1e0b1727
|
Phil Davis
|
if ($physmem < $g['minimum_ram_warning']) {
|
58 |
5b74202b
|
Scott Ullrich
|
echo "\n\n\n";
|
59 |
814f9e64
|
Carlos Eduardo Ramos
|
echo gettext("DANGER! WARNING! ACHTUNG!") . "\n\n";
|
60 |
|
|
printf(gettext("%s requires *AT LEAST* %s RAM to function correctly.%s"), $g['product_name'], $g['minimum_ram_warning_text'], "\n");
|
61 |
493360f5
|
Phil Davis
|
printf(gettext("Only (%s) MB RAM has been detected, with (%s) available to %s.%s"), $realmem, $physmem, $g['product_name'], "\n");
|
62 |
814f9e64
|
Carlos Eduardo Ramos
|
echo "\n" . gettext("Press ENTER to continue.") . " ";
|
63 |
5b74202b
|
Scott Ullrich
|
fgets($fp);
|
64 |
|
|
echo "\n";
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
$iflist = get_interface_list();
|
68 |
|
|
|
69 |
1e0b1727
|
Phil Davis
|
/* Function flow is based on $key and $auto_assign or the lack thereof */
|
70 |
5b74202b
|
Scott Ullrich
|
$key = null;
|
71 |
|
|
|
72 |
1e0b1727
|
Phil Davis
|
/* Only present auto interface option if running from LiveCD and interface mismatch*/
|
73 |
|
|
if ((preg_match("/cdrom/", $g['platform'])) && is_interface_mismatch()) {
|
74 |
5b74202b
|
Scott Ullrich
|
$auto_assign = false;
|
75 |
1e0b1727
|
Phil Davis
|
}
|
76 |
5b74202b
|
Scott Ullrich
|
|
77 |
|
|
echo <<<EOD
|
78 |
|
|
|
79 |
|
|
Valid interfaces are:
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
EOD;
|
83 |
|
|
|
84 |
1e0b1727
|
Phil Davis
|
if (!is_array($iflist)) {
|
85 |
814f9e64
|
Carlos Eduardo Ramos
|
echo gettext("No interfaces found!") . "\n";
|
86 |
5b74202b
|
Scott Ullrich
|
$iflist = array();
|
87 |
|
|
} else {
|
88 |
|
|
foreach ($iflist as $iface => $ifa) {
|
89 |
f049d544
|
Renato Botelho
|
echo sprintf("% -7s%s %s %s\n", $iface, $ifa['mac'],
|
90 |
ca90133b
|
jim-p
|
$ifa['up'] ? " (up)" : "(down)", $ifa['dmesg']);
|
91 |
5b74202b
|
Scott Ullrich
|
}
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
if ($auto_assign) {
|
95 |
|
|
echo <<<EOD
|
96 |
1e0b1727
|
Phil Davis
|
|
97 |
5b74202b
|
Scott Ullrich
|
!!! LiveCD Detected: Auto Interface Option !!!!
|
98 |
|
|
BEGIN MANUAL CONFIGURATION OR WE WILL PROCEED WITH AUTO CONFIGURATION.
|
99 |
|
|
|
100 |
|
|
EOD;
|
101 |
1e0b1727
|
Phil Davis
|
}
|
102 |
|
|
|
103 |
5b74202b
|
Scott Ullrich
|
echo <<<EOD
|
104 |
|
|
|
105 |
|
|
Do you want to set up VLANs first?
|
106 |
|
|
|
107 |
|
|
If you are not going to use VLANs, or only for optional interfaces, you should
|
108 |
|
|
say no here and use the webConfigurator to configure VLANs later, if required.
|
109 |
|
|
|
110 |
|
|
Do you want to set up VLANs now [y|n]?
|
111 |
|
|
EOD;
|
112 |
|
|
|
113 |
|
|
if ($auto_assign) {
|
114 |
|
|
$key = timeout();
|
115 |
1e0b1727
|
Phil Davis
|
} else {
|
116 |
5b74202b
|
Scott Ullrich
|
$key = chop(fgets($fp));
|
117 |
1e0b1727
|
Phil Davis
|
}
|
118 |
5b74202b
|
Scott Ullrich
|
|
119 |
|
|
if (!isset($key) and $auto_assign) { // Auto Assign Interfaces
|
120 |
|
|
do {
|
121 |
|
|
echo <<<EOD
|
122 |
|
|
|
123 |
|
|
!!! Auto Assigning Interfaces !!!
|
124 |
|
|
|
125 |
|
|
For installation purposes, you must plug in at least one NIC
|
126 |
|
|
for the LAN connection. If you plug in a second NIC it will be
|
127 |
|
|
assigned to WAN. Otherwise, we'll temporarily assign WAN to the
|
128 |
|
|
next available NIC found regardless of activity. You should
|
129 |
|
|
assign and configure the WAN interface according to your requirements
|
130 |
|
|
|
131 |
|
|
If you haven't plugged in any network cables yet,
|
132 |
|
|
now is the time to do so.
|
133 |
|
|
We'll keep trying until you do.
|
134 |
|
|
|
135 |
|
|
Searching for active interfaces...
|
136 |
1e0b1727
|
Phil Davis
|
|
137 |
5b74202b
|
Scott Ullrich
|
EOD;
|
138 |
|
|
unset($wanif, $lanif);
|
139 |
|
|
|
140 |
|
|
$media_iflist = $plugged_in = array();
|
141 |
|
|
$media_iflist = get_interface_list("media");
|
142 |
|
|
foreach ($media_iflist as $iface => $ifa) {
|
143 |
1e0b1727
|
Phil Davis
|
if ($ifa['up']) {
|
144 |
5b74202b
|
Scott Ullrich
|
$plugged_in[] = $iface;
|
145 |
1e0b1727
|
Phil Davis
|
}
|
146 |
5b74202b
|
Scott Ullrich
|
}
|
147 |
|
|
|
148 |
|
|
$lanif = array_shift($plugged_in);
|
149 |
|
|
$wanif = array_shift($plugged_in);
|
150 |
|
|
|
151 |
1e0b1727
|
Phil Davis
|
if (isset($lanif) && !isset($wanif)) {
|
152 |
5b74202b
|
Scott Ullrich
|
foreach ($iflist as $iface => $ifa) {
|
153 |
|
|
if ($iface != $lanif) {
|
154 |
|
|
$wanif = $iface;
|
155 |
|
|
break;
|
156 |
|
|
}
|
157 |
|
|
}
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
echo <<<EOD
|
161 |
|
|
|
162 |
1e0b1727
|
Phil Davis
|
Assigned WAN to : $wanif
|
163 |
5b74202b
|
Scott Ullrich
|
Assigned LAN to : $lanif
|
164 |
|
|
|
165 |
|
|
If you don't like this assignment,
|
166 |
1e0b1727
|
Phil Davis
|
press any key to go back to manual configuration.
|
167 |
5b74202b
|
Scott Ullrich
|
|
168 |
|
|
EOD;
|
169 |
|
|
$key = timeout(20);
|
170 |
1e0b1727
|
Phil Davis
|
if (isset($key)) {
|
171 |
5b74202b
|
Scott Ullrich
|
return;
|
172 |
1e0b1727
|
Phil Davis
|
}
|
173 |
5b74202b
|
Scott Ullrich
|
} while (!isset($wanif));
|
174 |
|
|
|
175 |
1e0b1727
|
Phil Davis
|
$config['system']['enablesshd'] = 'enabled';
|
176 |
5b74202b
|
Scott Ullrich
|
$key = 'y';
|
177 |
|
|
|
178 |
1e0b1727
|
Phil Davis
|
} else { //Manually assign interfaces
|
179 |
|
|
if (in_array($key, array('y', 'Y'))) {
|
180 |
5b74202b
|
Scott Ullrich
|
vlan_setup();
|
181 |
1e0b1727
|
Phil Davis
|
}
|
182 |
|
|
|
183 |
5b74202b
|
Scott Ullrich
|
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
|
184 |
1e0b1727
|
Phil Davis
|
|
185 |
814f9e64
|
Carlos Eduardo Ramos
|
echo "\n\n" . gettext("VLAN interfaces:") . "\n\n";
|
186 |
5b74202b
|
Scott Ullrich
|
foreach ($config['vlans']['vlan'] as $vlan) {
|
187 |
1e0b1727
|
Phil Davis
|
|
188 |
5b74202b
|
Scott Ullrich
|
echo sprintf("% -16s%s\n", "{$vlan['if']}_vlan{$vlan['tag']}",
|
189 |
|
|
"VLAN tag {$vlan['tag']}, parent interface {$vlan['if']}");
|
190 |
1e0b1727
|
Phil Davis
|
|
191 |
5b74202b
|
Scott Ullrich
|
$iflist[$vlan['if'] . '_vlan' . $vlan['tag']] = array();
|
192 |
|
|
}
|
193 |
|
|
}
|
194 |
1e0b1727
|
Phil Davis
|
|
195 |
5b74202b
|
Scott Ullrich
|
echo <<<EOD
|
196 |
1e0b1727
|
Phil Davis
|
|
197 |
5b74202b
|
Scott Ullrich
|
If you do not know the names of your interfaces, you may choose to use
|
198 |
|
|
auto-detection. In that case, disconnect all interfaces now before
|
199 |
|
|
hitting 'a' to initiate auto detection.
|
200 |
1e0b1727
|
Phil Davis
|
|
201 |
5b74202b
|
Scott Ullrich
|
EOD;
|
202 |
1e0b1727
|
Phil Davis
|
|
203 |
5b74202b
|
Scott Ullrich
|
do {
|
204 |
814f9e64
|
Carlos Eduardo Ramos
|
echo "\n" . gettext("Enter the WAN interface name or 'a' for auto-detection:") . " ";
|
205 |
5b74202b
|
Scott Ullrich
|
$wanif = chop(fgets($fp));
|
206 |
|
|
if ($wanif === "") {
|
207 |
|
|
return;
|
208 |
|
|
}
|
209 |
1e0b1727
|
Phil Davis
|
if ($wanif === "a") {
|
210 |
5b74202b
|
Scott Ullrich
|
$wanif = autodetect_interface("WAN", $fp);
|
211 |
1e0b1727
|
Phil Davis
|
} else if (!array_key_exists($wanif, $iflist)) {
|
212 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $wanif, "\n");
|
213 |
5b74202b
|
Scott Ullrich
|
unset($wanif);
|
214 |
|
|
continue;
|
215 |
|
|
}
|
216 |
|
|
} while (!$wanif);
|
217 |
1e0b1727
|
Phil Davis
|
|
218 |
5b74202b
|
Scott Ullrich
|
do {
|
219 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("%sEnter the LAN interface name or 'a' for auto-detection %s" .
|
220 |
1e0b1727
|
Phil Davis
|
"NOTE: this enables full Firewalling/NAT mode.%s" .
|
221 |
814f9e64
|
Carlos Eduardo Ramos
|
"(or nothing if finished):%s"), "\n", "\n", "\n", " ");
|
222 |
1e0b1727
|
Phil Davis
|
|
223 |
5b74202b
|
Scott Ullrich
|
$lanif = chop(fgets($fp));
|
224 |
1e0b1727
|
Phil Davis
|
|
225 |
|
|
if ($lanif == "exit") {
|
226 |
5b74202b
|
Scott Ullrich
|
exit;
|
227 |
|
|
}
|
228 |
1e0b1727
|
Phil Davis
|
|
229 |
|
|
if ($lanif == "") {
|
230 |
5d49ceac
|
Phil Davis
|
/* It is OK to have just a WAN, without a LAN so break if the user does not want LAN. */
|
231 |
|
|
break;
|
232 |
5b74202b
|
Scott Ullrich
|
}
|
233 |
1e0b1727
|
Phil Davis
|
|
234 |
|
|
if ($lanif === "a") {
|
235 |
5b74202b
|
Scott Ullrich
|
$lanif = autodetect_interface("LAN", $fp);
|
236 |
1e0b1727
|
Phil Davis
|
} else if (!array_key_exists($lanif, $iflist)) {
|
237 |
589e9633
|
jim-p
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $lanif, "\n");
|
238 |
5b74202b
|
Scott Ullrich
|
unset($lanif);
|
239 |
|
|
continue;
|
240 |
|
|
}
|
241 |
|
|
} while (!$lanif);
|
242 |
1e0b1727
|
Phil Davis
|
|
243 |
5b74202b
|
Scott Ullrich
|
/* optional interfaces */
|
244 |
|
|
$i = 0;
|
245 |
|
|
$optif = array();
|
246 |
1e0b1727
|
Phil Davis
|
|
247 |
|
|
if ($lanif <> "") {
|
248 |
5b74202b
|
Scott Ullrich
|
while (1) {
|
249 |
1e0b1727
|
Phil Davis
|
if ($optif[$i]) {
|
250 |
5b74202b
|
Scott Ullrich
|
$i++;
|
251 |
1e0b1727
|
Phil Davis
|
}
|
252 |
870952cf
|
Ermal
|
$io = $i + 1;
|
253 |
db0d446f
|
Darren Embry
|
|
254 |
1e0b1727
|
Phil Davis
|
if ($config['interfaces']['opt' . $io]['descr']) {
|
255 |
870952cf
|
Ermal
|
printf(gettext("%sOptional interface %s description found: %s"), "\n", $io, $config['interfaces']['opt' . $io]['descr']);
|
256 |
1e0b1727
|
Phil Davis
|
}
|
257 |
|
|
|
258 |
db0d446f
|
Darren Embry
|
printf(gettext("%sEnter the Optional %s interface name or 'a' for auto-detection%s" .
|
259 |
df0e1f2d
|
Ermal
|
"(or nothing if finished):%s"), "\n", $io, "\n", " ");
|
260 |
1e0b1727
|
Phil Davis
|
|
261 |
5b74202b
|
Scott Ullrich
|
$optif[$i] = chop(fgets($fp));
|
262 |
1e0b1727
|
Phil Davis
|
|
263 |
5b74202b
|
Scott Ullrich
|
if ($optif[$i]) {
|
264 |
|
|
if ($optif[$i] === "a") {
|
265 |
870952cf
|
Ermal
|
$ad = autodetect_interface(gettext("Optional") . " " . $io, $fp);
|
266 |
1e0b1727
|
Phil Davis
|
if ($ad) {
|
267 |
5b74202b
|
Scott Ullrich
|
$optif[$i] = $ad;
|
268 |
1e0b1727
|
Phil Davis
|
} else {
|
269 |
5b74202b
|
Scott Ullrich
|
unset($optif[$i]);
|
270 |
1e0b1727
|
Phil Davis
|
}
|
271 |
5b74202b
|
Scott Ullrich
|
} else if (!array_key_exists($optif[$i], $iflist)) {
|
272 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $optif[$i], "\n");
|
273 |
5b74202b
|
Scott Ullrich
|
unset($optif[$i]);
|
274 |
|
|
continue;
|
275 |
|
|
}
|
276 |
|
|
} else {
|
277 |
|
|
unset($optif[$i]);
|
278 |
|
|
break;
|
279 |
|
|
}
|
280 |
|
|
}
|
281 |
|
|
}
|
282 |
1e0b1727
|
Phil Davis
|
|
283 |
5b74202b
|
Scott Ullrich
|
/* check for double assignments */
|
284 |
|
|
$ifarr = array_merge(array($lanif, $wanif), $optif);
|
285 |
1e0b1727
|
Phil Davis
|
|
286 |
5b74202b
|
Scott Ullrich
|
for ($i = 0; $i < (count($ifarr)-1); $i++) {
|
287 |
|
|
for ($j = ($i+1); $j < count($ifarr); $j++) {
|
288 |
|
|
if ($ifarr[$i] == $ifarr[$j]) {
|
289 |
|
|
echo <<<EOD
|
290 |
1e0b1727
|
Phil Davis
|
|
291 |
5b74202b
|
Scott Ullrich
|
Error: you cannot assign the same interface name twice!
|
292 |
1e0b1727
|
Phil Davis
|
|
293 |
5b74202b
|
Scott Ullrich
|
EOD;
|
294 |
|
|
fclose($fp);
|
295 |
|
|
return;
|
296 |
|
|
}
|
297 |
|
|
}
|
298 |
|
|
}
|
299 |
1e0b1727
|
Phil Davis
|
|
300 |
8e1fd4fe
|
Renato Botelho
|
echo "\n" . gettext("The interfaces will be assigned as follows:") . "\n\n";
|
301 |
1e0b1727
|
Phil Davis
|
|
302 |
95524508
|
Ermal
|
echo "WAN -> " . $wanif . "\n";
|
303 |
1e0b1727
|
Phil Davis
|
if ($lanif != "") {
|
304 |
5b74202b
|
Scott Ullrich
|
echo "LAN -> " . $lanif . "\n";
|
305 |
1e0b1727
|
Phil Davis
|
}
|
306 |
5b74202b
|
Scott Ullrich
|
for ($i = 0; $i < count($optif); $i++) {
|
307 |
|
|
echo "OPT" . ($i+1) . " -> " . $optif[$i] . "\n";
|
308 |
|
|
}
|
309 |
1e0b1727
|
Phil Davis
|
|
310 |
5b74202b
|
Scott Ullrich
|
echo <<<EOD
|
311 |
1e0b1727
|
Phil Davis
|
|
312 |
5b74202b
|
Scott Ullrich
|
Do you want to proceed [y|n]?
|
313 |
|
|
EOD;
|
314 |
1e0b1727
|
Phil Davis
|
$key = chop(fgets($fp));
|
315 |
5b74202b
|
Scott Ullrich
|
}
|
316 |
|
|
|
317 |
|
|
if (in_array($key, array('y', 'Y'))) {
|
318 |
1e0b1727
|
Phil Davis
|
if ($lanif) {
|
319 |
|
|
if (!is_array($config['interfaces']['lan'])) {
|
320 |
e503c44a
|
Ermal
|
$config['interfaces']['lan'] = array();
|
321 |
1e0b1727
|
Phil Davis
|
}
|
322 |
5b74202b
|
Scott Ullrich
|
$config['interfaces']['lan']['if'] = $lanif;
|
323 |
|
|
$config['interfaces']['lan']['enable'] = true;
|
324 |
285ef132
|
Ermal LUÇI
|
} elseif (!platform_booting() && !$auto_assign) {
|
325 |
5b74202b
|
Scott Ullrich
|
|
326 |
|
|
echo <<<EODD
|
327 |
|
|
|
328 |
|
|
You have chosen to remove the LAN interface.
|
329 |
|
|
|
330 |
|
|
Would you like to remove the LAN IP address and
|
331 |
|
|
unload the interface now? [y|n]?
|
332 |
|
|
EODD;
|
333 |
|
|
|
334 |
1e0b1727
|
Phil Davis
|
if (strcasecmp(chop(fgets($fp)), "y") == 0) {
|
335 |
|
|
if (isset($config['interfaces']['lan']) && $config['interfaces']['lan']['if']) {
|
336 |
|
|
mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
|
337 |
5b74202b
|
Scott Ullrich
|
}
|
338 |
1e0b1727
|
Phil Davis
|
}
|
339 |
|
|
if (isset($config['interfaces']['lan'])) {
|
340 |
|
|
unset($config['interfaces']['lan']);
|
341 |
|
|
}
|
342 |
|
|
if (isset($config['dhcpd']['lan'])) {
|
343 |
|
|
unset($config['dhcpd']['lan']);
|
344 |
|
|
}
|
345 |
|
|
if (isset($config['interfaces']['lan']['if'])) {
|
346 |
|
|
unset($config['interfaces']['lan']['if']);
|
347 |
|
|
}
|
348 |
|
|
if (isset($config['interfaces']['wan']['blockpriv'])) {
|
349 |
|
|
unset($config['interfaces']['wan']['blockpriv']);
|
350 |
|
|
}
|
351 |
|
|
if (isset($config['shaper'])) {
|
352 |
|
|
unset($config['shaper']);
|
353 |
|
|
}
|
354 |
|
|
if (isset($config['ezshaper'])) {
|
355 |
|
|
unset($config['ezshaper']);
|
356 |
|
|
}
|
357 |
|
|
if (isset($config['nat'])) {
|
358 |
|
|
unset($config['nat']);
|
359 |
|
|
}
|
360 |
5b74202b
|
Scott Ullrich
|
} else {
|
361 |
1e0b1727
|
Phil Davis
|
if (isset($config['interfaces']['lan']['if'])) {
|
362 |
5b74202b
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
|
363 |
1e0b1727
|
Phil Davis
|
}
|
364 |
|
|
if (isset($config['interfaces']['lan'])) {
|
365 |
5b74202b
|
Scott Ullrich
|
unset($config['interfaces']['lan']);
|
366 |
1e0b1727
|
Phil Davis
|
}
|
367 |
|
|
if (isset($config['dhcpd']['lan'])) {
|
368 |
5b74202b
|
Scott Ullrich
|
unset($config['dhcpd']['lan']);
|
369 |
1e0b1727
|
Phil Davis
|
}
|
370 |
|
|
if (isset($config['interfaces']['lan']['if'])) {
|
371 |
5b74202b
|
Scott Ullrich
|
unset($config['interfaces']['lan']['if']);
|
372 |
1e0b1727
|
Phil Davis
|
}
|
373 |
|
|
if (isset($config['interfaces']['wan']['blockpriv'])) {
|
374 |
5b74202b
|
Scott Ullrich
|
unset($config['interfaces']['wan']['blockpriv']);
|
375 |
1e0b1727
|
Phil Davis
|
}
|
376 |
|
|
if (isset($config['shaper'])) {
|
377 |
5b74202b
|
Scott Ullrich
|
unset($config['shaper']);
|
378 |
1e0b1727
|
Phil Davis
|
}
|
379 |
|
|
if (isset($config['ezshaper'])) {
|
380 |
5b74202b
|
Scott Ullrich
|
unset($config['ezshaper']);
|
381 |
1e0b1727
|
Phil Davis
|
}
|
382 |
|
|
if (isset($config['nat'])) {
|
383 |
|
|
unset($config['nat']);
|
384 |
|
|
}
|
385 |
5b74202b
|
Scott Ullrich
|
}
|
386 |
|
|
if (preg_match($g['wireless_regex'], $lanif)) {
|
387 |
|
|
if (is_array($config['interfaces']['lan']) &&
|
388 |
ae52d165
|
Renato Botelho
|
!is_array($config['interfaces']['lan']['wireless'])) {
|
389 |
5b74202b
|
Scott Ullrich
|
$config['interfaces']['lan']['wireless'] = array();
|
390 |
1e0b1727
|
Phil Davis
|
}
|
391 |
5b74202b
|
Scott Ullrich
|
} else {
|
392 |
1e0b1727
|
Phil Davis
|
if (isset($config['interfaces']['lan'])) {
|
393 |
e503c44a
|
Ermal
|
unset($config['interfaces']['lan']['wireless']);
|
394 |
1e0b1727
|
Phil Davis
|
}
|
395 |
5b74202b
|
Scott Ullrich
|
}
|
396 |
|
|
|
397 |
1e0b1727
|
Phil Davis
|
if (!is_array($config['interfaces']['wan'])) {
|
398 |
e503c44a
|
Ermal
|
$config['interfaces']['wan'] = array();
|
399 |
1e0b1727
|
Phil Davis
|
}
|
400 |
5b74202b
|
Scott Ullrich
|
$config['interfaces']['wan']['if'] = $wanif;
|
401 |
|
|
$config['interfaces']['wan']['enable'] = true;
|
402 |
|
|
if (preg_match($g['wireless_regex'], $wanif)) {
|
403 |
|
|
if (is_array($config['interfaces']['wan']) &&
|
404 |
ae52d165
|
Renato Botelho
|
!is_array($config['interfaces']['wan']['wireless'])) {
|
405 |
5b74202b
|
Scott Ullrich
|
$config['interfaces']['wan']['wireless'] = array();
|
406 |
1e0b1727
|
Phil Davis
|
}
|
407 |
5b74202b
|
Scott Ullrich
|
} else {
|
408 |
1e0b1727
|
Phil Davis
|
if (isset($config['interfaces']['wan'])) {
|
409 |
e503c44a
|
Ermal
|
unset($config['interfaces']['wan']['wireless']);
|
410 |
1e0b1727
|
Phil Davis
|
}
|
411 |
5b74202b
|
Scott Ullrich
|
}
|
412 |
|
|
|
413 |
|
|
for ($i = 0; $i < count($optif); $i++) {
|
414 |
1e0b1727
|
Phil Davis
|
if (!is_array($config['interfaces']['opt' . ($i+1)])) {
|
415 |
5b74202b
|
Scott Ullrich
|
$config['interfaces']['opt' . ($i+1)] = array();
|
416 |
1e0b1727
|
Phil Davis
|
}
|
417 |
5b74202b
|
Scott Ullrich
|
|
418 |
|
|
$config['interfaces']['opt' . ($i+1)]['if'] = $optif[$i];
|
419 |
|
|
|
420 |
|
|
/* wireless interface? */
|
421 |
|
|
if (preg_match($g['wireless_regex'], $optif[$i])) {
|
422 |
1e0b1727
|
Phil Davis
|
if (!is_array($config['interfaces']['opt' . ($i+1)]['wireless'])) {
|
423 |
5b74202b
|
Scott Ullrich
|
$config['interfaces']['opt' . ($i+1)]['wireless'] = array();
|
424 |
1e0b1727
|
Phil Davis
|
}
|
425 |
5b74202b
|
Scott Ullrich
|
} else {
|
426 |
|
|
unset($config['interfaces']['opt' . ($i+1)]['wireless']);
|
427 |
|
|
}
|
428 |
|
|
|
429 |
62784b05
|
Ermal
|
if (empty($config['interfaces']['opt' . ($i+1)]['descr'])) {
|
430 |
|
|
$config['interfaces']['opt' . ($i+1)]['descr'] = "OPT" . ($i+1);
|
431 |
|
|
unset($config['interfaces']['opt' . ($i+1)]['enable']);
|
432 |
|
|
}
|
433 |
5b74202b
|
Scott Ullrich
|
}
|
434 |
|
|
|
435 |
|
|
/* remove all other (old) optional interfaces */
|
436 |
1e0b1727
|
Phil Davis
|
for (; isset($config['interfaces']['opt' . ($i+1)]); $i++) {
|
437 |
5b74202b
|
Scott Ullrich
|
unset($config['interfaces']['opt' . ($i+1)]);
|
438 |
1e0b1727
|
Phil Davis
|
}
|
439 |
5b74202b
|
Scott Ullrich
|
|
440 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("%sWriting configuration..."), "\n");
|
441 |
62784b05
|
Ermal
|
write_config("Console assignment of interfaces");
|
442 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("done.%s"), "\n");
|
443 |
5b74202b
|
Scott Ullrich
|
|
444 |
|
|
fclose($fp);
|
445 |
c9fa8254
|
Scott Ullrich
|
|
446 |
1e0b1727
|
Phil Davis
|
if (platform_booting()) {
|
447 |
5b74202b
|
Scott Ullrich
|
return;
|
448 |
1e0b1727
|
Phil Davis
|
}
|
449 |
5b74202b
|
Scott Ullrich
|
|
450 |
814f9e64
|
Carlos Eduardo Ramos
|
echo gettext("One moment while we reload the settings...");
|
451 |
9d3d8d00
|
Vinicius Coque
|
echo gettext(" done!") . "\n";
|
452 |
5b74202b
|
Scott Ullrich
|
|
453 |
|
|
touch("{$g['tmp_path']}/assign_complete");
|
454 |
|
|
|
455 |
|
|
}
|
456 |
|
|
}
|
457 |
|
|
|
458 |
|
|
function autodetect_interface($ifname, $fp) {
|
459 |
|
|
$iflist_prev = get_interface_list("media");
|
460 |
|
|
echo <<<EOD
|
461 |
|
|
|
462 |
|
|
Connect the {$ifname} interface now and make sure that the link is up.
|
463 |
|
|
Then press ENTER to continue.
|
464 |
|
|
|
465 |
|
|
EOD;
|
466 |
|
|
fgets($fp);
|
467 |
|
|
$iflist = get_interface_list("media");
|
468 |
|
|
|
469 |
|
|
foreach ($iflist_prev as $ifn => $ifa) {
|
470 |
|
|
if (!$ifa['up'] && $iflist[$ifn]['up']) {
|
471 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("Detected link-up on interface %s.%s"), $ifn, "\n");
|
472 |
5b74202b
|
Scott Ullrich
|
return $ifn;
|
473 |
|
|
}
|
474 |
|
|
}
|
475 |
|
|
|
476 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("No link-up detected.%s"), "\n");
|
477 |
5b74202b
|
Scott Ullrich
|
|
478 |
|
|
return null;
|
479 |
|
|
}
|
480 |
|
|
|
481 |
c9fa8254
|
Scott Ullrich
|
function interfaces_setup() {
|
482 |
|
|
global $iflist, $config, $g, $fp;
|
483 |
|
|
|
484 |
|
|
$iflist = get_interface_list();
|
485 |
|
|
}
|
486 |
|
|
|
487 |
5b74202b
|
Scott Ullrich
|
function vlan_setup() {
|
488 |
|
|
global $iflist, $config, $g, $fp;
|
489 |
|
|
|
490 |
|
|
$iflist = get_interface_list();
|
491 |
|
|
|
492 |
|
|
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
|
493 |
|
|
|
494 |
1e0b1727
|
Phil Davis
|
echo <<<EOD
|
495 |
5b74202b
|
Scott Ullrich
|
|
496 |
|
|
WARNING: all existing VLANs will be cleared if you proceed!
|
497 |
|
|
|
498 |
|
|
Do you want to proceed [y|n]?
|
499 |
|
|
EOD;
|
500 |
|
|
|
501 |
1e0b1727
|
Phil Davis
|
if (strcasecmp(chop(fgets($fp)), "y") != 0) {
|
502 |
|
|
return;
|
503 |
|
|
}
|
504 |
5b74202b
|
Scott Ullrich
|
}
|
505 |
|
|
|
506 |
|
|
$config['vlans']['vlan'] = array();
|
507 |
|
|
echo "\n";
|
508 |
|
|
|
509 |
|
|
$vlanif = 0;
|
510 |
|
|
|
511 |
|
|
while (1) {
|
512 |
|
|
$vlan = array();
|
513 |
|
|
|
514 |
814f9e64
|
Carlos Eduardo Ramos
|
echo "\n\n" . gettext("VLAN Capable interfaces:") . "\n\n";
|
515 |
1e0b1727
|
Phil Davis
|
if (!is_array($iflist)) {
|
516 |
814f9e64
|
Carlos Eduardo Ramos
|
echo gettext("No interfaces found!") . "\n";
|
517 |
5b74202b
|
Scott Ullrich
|
} else {
|
518 |
|
|
$vlan_capable=0;
|
519 |
|
|
foreach ($iflist as $iface => $ifa) {
|
520 |
|
|
if (is_jumbo_capable($iface)) {
|
521 |
|
|
echo sprintf("% -8s%s%s\n", $iface, $ifa['mac'],
|
522 |
|
|
$ifa['up'] ? " (up)" : "");
|
523 |
|
|
$vlan_capable++;
|
524 |
|
|
}
|
525 |
|
|
}
|
526 |
|
|
}
|
527 |
|
|
|
528 |
1e0b1727
|
Phil Davis
|
if ($vlan_capable == 0) {
|
529 |
814f9e64
|
Carlos Eduardo Ramos
|
echo gettext("No VLAN capable interfaces detected.") . "\n";
|
530 |
5b74202b
|
Scott Ullrich
|
return;
|
531 |
|
|
}
|
532 |
|
|
|
533 |
814f9e64
|
Carlos Eduardo Ramos
|
echo "\n" . gettext("Enter the parent interface name for the new VLAN (or nothing if finished):") . " ";
|
534 |
5b74202b
|
Scott Ullrich
|
$vlan['if'] = chop(fgets($fp));
|
535 |
|
|
|
536 |
|
|
if ($vlan['if']) {
|
537 |
|
|
if (!array_key_exists($vlan['if'], $iflist) or
|
538 |
ae52d165
|
Renato Botelho
|
!is_jumbo_capable($vlan['if'])) {
|
539 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $vlan['if'], "\n");
|
540 |
5b74202b
|
Scott Ullrich
|
continue;
|
541 |
|
|
}
|
542 |
|
|
} else {
|
543 |
|
|
break;
|
544 |
|
|
}
|
545 |
|
|
|
546 |
814f9e64
|
Carlos Eduardo Ramos
|
echo gettext("Enter the VLAN tag (1-4094):") . " ";
|
547 |
5b74202b
|
Scott Ullrich
|
$vlan['tag'] = chop(fgets($fp));
|
548 |
|
|
$vlan['vlanif'] = "{$vlan['if']}_vlan{$vlan['tag']}";
|
549 |
|
|
if (!is_numericint($vlan['tag']) || ($vlan['tag'] < 1) || ($vlan['tag'] > 4094)) {
|
550 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("%sInvalid VLAN tag '%s'%s"), "\n", $vlan['tag'], "\n");
|
551 |
5b74202b
|
Scott Ullrich
|
continue;
|
552 |
|
|
}
|
553 |
1e0b1727
|
Phil Davis
|
|
554 |
5b74202b
|
Scott Ullrich
|
$config['vlans']['vlan'][] = $vlan;
|
555 |
|
|
$vlanif++;
|
556 |
|
|
}
|
557 |
|
|
}
|
558 |
|
|
|
559 |
814f9e64
|
Carlos Eduardo Ramos
|
?>
|