1 |
5b74202b
|
Scott Ullrich
|
<?php
|
2 |
09221bc3
|
Renato Botelho
|
/*
|
3 |
5b74202b
|
Scott Ullrich
|
config.console.inc
|
4 |
09221bc3
|
Renato Botelho
|
|
5 |
|
|
part of pfSense (https://www.pfsense.org)
|
6 |
|
|
Copyright (c) 2004-2016 Electric Sheep Fencing, LLC. All rights reserved.
|
7 |
5b74202b
|
Scott Ullrich
|
|
8 |
|
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
9 |
|
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
10 |
|
|
All rights reserved.
|
11 |
|
|
|
12 |
|
|
Redistribution and use in source and binary forms, with or without
|
13 |
|
|
modification, are permitted provided that the following conditions are met:
|
14 |
|
|
|
15 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
16 |
|
|
this list of conditions and the following disclaimer.
|
17 |
|
|
|
18 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
19 |
09221bc3
|
Renato Botelho
|
notice, this list of conditions and the following disclaimer in
|
20 |
|
|
the documentation and/or other materials provided with the
|
21 |
|
|
distribution.
|
22 |
|
|
|
23 |
|
|
3. All advertising materials mentioning features or use of this software
|
24 |
|
|
must display the following acknowledgment:
|
25 |
|
|
"This product includes software developed by the pfSense Project
|
26 |
|
|
for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
27 |
|
|
|
28 |
|
|
4. The names "pfSense" and "pfSense Project" must not be used to
|
29 |
|
|
endorse or promote products derived from this software without
|
30 |
|
|
prior written permission. For written permission, please contact
|
31 |
|
|
coreteam@pfsense.org.
|
32 |
|
|
|
33 |
|
|
5. Products derived from this software may not be called "pfSense"
|
34 |
|
|
nor may "pfSense" appear in their names without prior written
|
35 |
|
|
permission of the Electric Sheep Fencing, LLC.
|
36 |
|
|
|
37 |
|
|
6. Redistributions of any form whatsoever must retain the following
|
38 |
|
|
acknowledgment:
|
39 |
|
|
|
40 |
|
|
"This product includes software developed by the pfSense Project
|
41 |
|
|
for use in the pfSense software distribution (http://www.pfsense.org/).
|
42 |
|
|
|
43 |
|
|
THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
44 |
|
|
EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
45 |
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
46 |
|
|
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
47 |
|
|
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
48 |
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
49 |
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
50 |
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
51 |
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
52 |
|
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
53 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
54 |
|
|
OF THE POSSIBILITY OF SUCH DAMAGE.
|
55 |
5b74202b
|
Scott Ullrich
|
*/
|
56 |
|
|
|
57 |
|
|
function set_networking_interfaces_ports() {
|
58 |
|
|
global $noreboot;
|
59 |
|
|
global $config;
|
60 |
|
|
global $g;
|
61 |
|
|
global $fp;
|
62 |
|
|
|
63 |
|
|
$fp = fopen('php://stdin', 'r');
|
64 |
|
|
|
65 |
|
|
$memory = get_memory();
|
66 |
493360f5
|
Phil Davis
|
$physmem = $memory[0];
|
67 |
|
|
$realmem = $memory[1];
|
68 |
5b74202b
|
Scott Ullrich
|
|
69 |
1e0b1727
|
Phil Davis
|
if ($physmem < $g['minimum_ram_warning']) {
|
70 |
5b74202b
|
Scott Ullrich
|
echo "\n\n\n";
|
71 |
814f9e64
|
Carlos Eduardo Ramos
|
echo gettext("DANGER! WARNING! ACHTUNG!") . "\n\n";
|
72 |
|
|
printf(gettext("%s requires *AT LEAST* %s RAM to function correctly.%s"), $g['product_name'], $g['minimum_ram_warning_text'], "\n");
|
73 |
493360f5
|
Phil Davis
|
printf(gettext("Only (%s) MB RAM has been detected, with (%s) available to %s.%s"), $realmem, $physmem, $g['product_name'], "\n");
|
74 |
814f9e64
|
Carlos Eduardo Ramos
|
echo "\n" . gettext("Press ENTER to continue.") . " ";
|
75 |
5b74202b
|
Scott Ullrich
|
fgets($fp);
|
76 |
|
|
echo "\n";
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
$iflist = get_interface_list();
|
80 |
|
|
|
81 |
1e0b1727
|
Phil Davis
|
/* Function flow is based on $key and $auto_assign or the lack thereof */
|
82 |
5b74202b
|
Scott Ullrich
|
$key = null;
|
83 |
|
|
|
84 |
987712e8
|
jim-p
|
/* Only present auto interface option if running from the installer media and interface mismatch*/
|
85 |
1e0b1727
|
Phil Davis
|
if ((preg_match("/cdrom/", $g['platform'])) && is_interface_mismatch()) {
|
86 |
5b74202b
|
Scott Ullrich
|
$auto_assign = false;
|
87 |
1e0b1727
|
Phil Davis
|
}
|
88 |
5b74202b
|
Scott Ullrich
|
|
89 |
|
|
echo <<<EOD
|
90 |
|
|
|
91 |
|
|
Valid interfaces are:
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
EOD;
|
95 |
|
|
|
96 |
1e0b1727
|
Phil Davis
|
if (!is_array($iflist)) {
|
97 |
814f9e64
|
Carlos Eduardo Ramos
|
echo gettext("No interfaces found!") . "\n";
|
98 |
5b74202b
|
Scott Ullrich
|
$iflist = array();
|
99 |
|
|
} else {
|
100 |
|
|
foreach ($iflist as $iface => $ifa) {
|
101 |
16feb55d
|
Luiz Otavio O Souza
|
$friendly = convert_real_interface_to_friendly_interface_name($iface);
|
102 |
|
|
$ifstatus = pfSense_get_interface_addresses($config['interfaces'][$friendly]['if']);
|
103 |
|
|
if (is_array($ifstatus) && $ifstatus['linkstateup'])
|
104 |
|
|
$status = " (up)";
|
105 |
|
|
else
|
106 |
|
|
$status = "(down)";
|
107 |
fcaca8ef
|
doktornotor
|
$ifsmallist = trim($ifsmallist . " " . $iface);
|
108 |
f049d544
|
Renato Botelho
|
echo sprintf("% -7s%s %s %s\n", $iface, $ifa['mac'],
|
109 |
16feb55d
|
Luiz Otavio O Souza
|
$status, substr($ifa['dmesg'], 0, 48));
|
110 |
5b74202b
|
Scott Ullrich
|
}
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
if ($auto_assign) {
|
114 |
|
|
echo <<<EOD
|
115 |
1e0b1727
|
Phil Davis
|
|
116 |
987712e8
|
jim-p
|
!!! Installation Media Detected: Auto Interface Option !!!!
|
117 |
adb56dbd
|
Phil Davis
|
BEGIN MANUAL CONFIGURATION OR THE SYSTEM WILL PROCEED WITH AUTO CONFIGURATION.
|
118 |
5b74202b
|
Scott Ullrich
|
|
119 |
|
|
EOD;
|
120 |
1e0b1727
|
Phil Davis
|
}
|
121 |
|
|
|
122 |
530e4707
|
NOYB
|
echo "\n" . gettext("Do VLANs need to be set up first?");
|
123 |
0b3799f1
|
Phil Davis
|
echo "\n" .
|
124 |
|
|
gettext(
|
125 |
530e4707
|
NOYB
|
"If VLANs will not be used, or only for optional interfaces, it is typical to\n" .
|
126 |
0b3799f1
|
Phil Davis
|
"say no here and use the webConfigurator to configure VLANs later, if required.") .
|
127 |
|
|
"\n";
|
128 |
34ee6639
|
NOYB
|
echo "\n" . gettext("Should VLANs be set up now [y|n]?") . " ";
|
129 |
5b74202b
|
Scott Ullrich
|
|
130 |
|
|
if ($auto_assign) {
|
131 |
|
|
$key = timeout();
|
132 |
1e0b1727
|
Phil Davis
|
} else {
|
133 |
5b74202b
|
Scott Ullrich
|
$key = chop(fgets($fp));
|
134 |
1e0b1727
|
Phil Davis
|
}
|
135 |
5b74202b
|
Scott Ullrich
|
|
136 |
|
|
if (!isset($key) and $auto_assign) { // Auto Assign Interfaces
|
137 |
|
|
do {
|
138 |
|
|
echo <<<EOD
|
139 |
|
|
|
140 |
|
|
!!! Auto Assigning Interfaces !!!
|
141 |
|
|
|
142 |
34ee6639
|
NOYB
|
For setup purposes, there must be at least one NIC connected for
|
143 |
|
|
the LAN. If a second NIC is connected, it will be assigned to the
|
144 |
|
|
WAN. Otherwise, WAN will be temporarily assigned to the next
|
145 |
|
|
available NIC found regardless of activity. The WAN interface
|
146 |
|
|
should then be assigned and configured as required.
|
147 |
5b74202b
|
Scott Ullrich
|
|
148 |
34ee6639
|
NOYB
|
Please make the pfSense NIC connections now.
|
149 |
|
|
The system will continue checking until they have been made.
|
150 |
5b74202b
|
Scott Ullrich
|
|
151 |
|
|
Searching for active interfaces...
|
152 |
1e0b1727
|
Phil Davis
|
|
153 |
5b74202b
|
Scott Ullrich
|
EOD;
|
154 |
|
|
unset($wanif, $lanif);
|
155 |
|
|
|
156 |
|
|
$media_iflist = $plugged_in = array();
|
157 |
|
|
$media_iflist = get_interface_list("media");
|
158 |
|
|
foreach ($media_iflist as $iface => $ifa) {
|
159 |
1e0b1727
|
Phil Davis
|
if ($ifa['up']) {
|
160 |
5b74202b
|
Scott Ullrich
|
$plugged_in[] = $iface;
|
161 |
1e0b1727
|
Phil Davis
|
}
|
162 |
5b74202b
|
Scott Ullrich
|
}
|
163 |
|
|
|
164 |
|
|
$lanif = array_shift($plugged_in);
|
165 |
|
|
$wanif = array_shift($plugged_in);
|
166 |
|
|
|
167 |
1e0b1727
|
Phil Davis
|
if (isset($lanif) && !isset($wanif)) {
|
168 |
5b74202b
|
Scott Ullrich
|
foreach ($iflist as $iface => $ifa) {
|
169 |
|
|
if ($iface != $lanif) {
|
170 |
|
|
$wanif = $iface;
|
171 |
|
|
break;
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
|
|
}
|
175 |
|
|
|
176 |
|
|
echo <<<EOD
|
177 |
|
|
|
178 |
1e0b1727
|
Phil Davis
|
Assigned WAN to : $wanif
|
179 |
5b74202b
|
Scott Ullrich
|
Assigned LAN to : $lanif
|
180 |
|
|
|
181 |
530e4707
|
NOYB
|
If these assignments are not suitable,
|
182 |
1e0b1727
|
Phil Davis
|
press any key to go back to manual configuration.
|
183 |
5b74202b
|
Scott Ullrich
|
|
184 |
|
|
EOD;
|
185 |
|
|
$key = timeout(20);
|
186 |
1e0b1727
|
Phil Davis
|
if (isset($key)) {
|
187 |
5b74202b
|
Scott Ullrich
|
return;
|
188 |
1e0b1727
|
Phil Davis
|
}
|
189 |
5b74202b
|
Scott Ullrich
|
} while (!isset($wanif));
|
190 |
|
|
|
191 |
1e0b1727
|
Phil Davis
|
$config['system']['enablesshd'] = 'enabled';
|
192 |
5b74202b
|
Scott Ullrich
|
$key = 'y';
|
193 |
|
|
|
194 |
6c07db48
|
Phil Davis
|
} else {
|
195 |
|
|
//Manually assign interfaces
|
196 |
1e0b1727
|
Phil Davis
|
if (in_array($key, array('y', 'Y'))) {
|
197 |
5b74202b
|
Scott Ullrich
|
vlan_setup();
|
198 |
1e0b1727
|
Phil Davis
|
}
|
199 |
|
|
|
200 |
5b74202b
|
Scott Ullrich
|
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
|
201 |
1e0b1727
|
Phil Davis
|
|
202 |
814f9e64
|
Carlos Eduardo Ramos
|
echo "\n\n" . gettext("VLAN interfaces:") . "\n\n";
|
203 |
5b74202b
|
Scott Ullrich
|
foreach ($config['vlans']['vlan'] as $vlan) {
|
204 |
1e0b1727
|
Phil Davis
|
|
205 |
5b74202b
|
Scott Ullrich
|
echo sprintf("% -16s%s\n", "{$vlan['if']}_vlan{$vlan['tag']}",
|
206 |
|
|
"VLAN tag {$vlan['tag']}, parent interface {$vlan['if']}");
|
207 |
1e0b1727
|
Phil Davis
|
|
208 |
5b74202b
|
Scott Ullrich
|
$iflist[$vlan['if'] . '_vlan' . $vlan['tag']] = array();
|
209 |
fcaca8ef
|
doktornotor
|
$ifsmallist = trim($ifsmallist . " " . $vlan['if'] . '_vlan' . $vlan['tag']);
|
210 |
5b74202b
|
Scott Ullrich
|
}
|
211 |
|
|
}
|
212 |
1e0b1727
|
Phil Davis
|
|
213 |
5b74202b
|
Scott Ullrich
|
echo <<<EOD
|
214 |
1e0b1727
|
Phil Davis
|
|
215 |
34ee6639
|
NOYB
|
If the names of the interfaces are not known, auto-detection can
|
216 |
|
|
be used instead. To use auto-detection, please disconnect all
|
217 |
|
|
interfaces before pressing 'a' to begin the process.
|
218 |
1e0b1727
|
Phil Davis
|
|
219 |
5b74202b
|
Scott Ullrich
|
EOD;
|
220 |
1e0b1727
|
Phil Davis
|
|
221 |
5b74202b
|
Scott Ullrich
|
do {
|
222 |
fcaca8ef
|
doktornotor
|
echo "\n" . gettext("Enter the WAN interface name or 'a' for auto-detection") . " ";
|
223 |
|
|
printf(gettext("%s(%s or a): "), "\n", $ifsmallist);
|
224 |
5b74202b
|
Scott Ullrich
|
$wanif = chop(fgets($fp));
|
225 |
|
|
if ($wanif === "") {
|
226 |
|
|
return;
|
227 |
|
|
}
|
228 |
1e0b1727
|
Phil Davis
|
if ($wanif === "a") {
|
229 |
5b74202b
|
Scott Ullrich
|
$wanif = autodetect_interface("WAN", $fp);
|
230 |
1e0b1727
|
Phil Davis
|
} else if (!array_key_exists($wanif, $iflist)) {
|
231 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $wanif, "\n");
|
232 |
5b74202b
|
Scott Ullrich
|
unset($wanif);
|
233 |
|
|
continue;
|
234 |
|
|
}
|
235 |
fcaca8ef
|
doktornotor
|
$ifsmallist = trim(str_replace(" ", " ", str_replace($wanif, "", $ifsmallist)));
|
236 |
5b74202b
|
Scott Ullrich
|
} while (!$wanif);
|
237 |
1e0b1727
|
Phil Davis
|
|
238 |
5b74202b
|
Scott Ullrich
|
do {
|
239 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("%sEnter the LAN interface name or 'a' for auto-detection %s" .
|
240 |
1e0b1727
|
Phil Davis
|
"NOTE: this enables full Firewalling/NAT mode.%s" .
|
241 |
fcaca8ef
|
doktornotor
|
"(%s a or nothing if finished):%s"), "\n", "\n", "\n", $ifsmallist, " ");
|
242 |
1e0b1727
|
Phil Davis
|
|
243 |
5b74202b
|
Scott Ullrich
|
$lanif = chop(fgets($fp));
|
244 |
1e0b1727
|
Phil Davis
|
|
245 |
|
|
if ($lanif == "exit") {
|
246 |
5b74202b
|
Scott Ullrich
|
exit;
|
247 |
|
|
}
|
248 |
1e0b1727
|
Phil Davis
|
|
249 |
|
|
if ($lanif == "") {
|
250 |
5d49ceac
|
Phil Davis
|
/* It is OK to have just a WAN, without a LAN so break if the user does not want LAN. */
|
251 |
|
|
break;
|
252 |
5b74202b
|
Scott Ullrich
|
}
|
253 |
1e0b1727
|
Phil Davis
|
|
254 |
|
|
if ($lanif === "a") {
|
255 |
5b74202b
|
Scott Ullrich
|
$lanif = autodetect_interface("LAN", $fp);
|
256 |
1e0b1727
|
Phil Davis
|
} else if (!array_key_exists($lanif, $iflist)) {
|
257 |
589e9633
|
jim-p
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $lanif, "\n");
|
258 |
5b74202b
|
Scott Ullrich
|
unset($lanif);
|
259 |
|
|
continue;
|
260 |
|
|
}
|
261 |
fcaca8ef
|
doktornotor
|
$ifsmallist = trim(str_replace(" ", " ", str_replace($lanif, "", $ifsmallist)));
|
262 |
5b74202b
|
Scott Ullrich
|
} while (!$lanif);
|
263 |
1e0b1727
|
Phil Davis
|
|
264 |
5b74202b
|
Scott Ullrich
|
/* optional interfaces */
|
265 |
|
|
$i = 0;
|
266 |
|
|
$optif = array();
|
267 |
1e0b1727
|
Phil Davis
|
|
268 |
|
|
if ($lanif <> "") {
|
269 |
5b74202b
|
Scott Ullrich
|
while (1) {
|
270 |
1e0b1727
|
Phil Davis
|
if ($optif[$i]) {
|
271 |
5b74202b
|
Scott Ullrich
|
$i++;
|
272 |
1e0b1727
|
Phil Davis
|
}
|
273 |
870952cf
|
Ermal
|
$io = $i + 1;
|
274 |
db0d446f
|
Darren Embry
|
|
275 |
1e0b1727
|
Phil Davis
|
if ($config['interfaces']['opt' . $io]['descr']) {
|
276 |
870952cf
|
Ermal
|
printf(gettext("%sOptional interface %s description found: %s"), "\n", $io, $config['interfaces']['opt' . $io]['descr']);
|
277 |
1e0b1727
|
Phil Davis
|
}
|
278 |
|
|
|
279 |
db0d446f
|
Darren Embry
|
printf(gettext("%sEnter the Optional %s interface name or 'a' for auto-detection%s" .
|
280 |
fcaca8ef
|
doktornotor
|
"(%s a or nothing if finished):%s"), "\n", $io, "\n", $ifsmallist, " ");
|
281 |
1e0b1727
|
Phil Davis
|
|
282 |
5b74202b
|
Scott Ullrich
|
$optif[$i] = chop(fgets($fp));
|
283 |
1e0b1727
|
Phil Davis
|
|
284 |
5b74202b
|
Scott Ullrich
|
if ($optif[$i]) {
|
285 |
|
|
if ($optif[$i] === "a") {
|
286 |
870952cf
|
Ermal
|
$ad = autodetect_interface(gettext("Optional") . " " . $io, $fp);
|
287 |
1e0b1727
|
Phil Davis
|
if ($ad) {
|
288 |
5b74202b
|
Scott Ullrich
|
$optif[$i] = $ad;
|
289 |
1e0b1727
|
Phil Davis
|
} else {
|
290 |
5b74202b
|
Scott Ullrich
|
unset($optif[$i]);
|
291 |
1e0b1727
|
Phil Davis
|
}
|
292 |
5b74202b
|
Scott Ullrich
|
} else if (!array_key_exists($optif[$i], $iflist)) {
|
293 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $optif[$i], "\n");
|
294 |
5b74202b
|
Scott Ullrich
|
unset($optif[$i]);
|
295 |
|
|
continue;
|
296 |
|
|
}
|
297 |
fcaca8ef
|
doktornotor
|
$ifsmallist = trim(str_replace(" ", " ", str_replace($optif[$i], "", $ifsmallist)));
|
298 |
5b74202b
|
Scott Ullrich
|
} else {
|
299 |
|
|
unset($optif[$i]);
|
300 |
|
|
break;
|
301 |
|
|
}
|
302 |
|
|
}
|
303 |
|
|
}
|
304 |
1e0b1727
|
Phil Davis
|
|
305 |
5b74202b
|
Scott Ullrich
|
/* check for double assignments */
|
306 |
|
|
$ifarr = array_merge(array($lanif, $wanif), $optif);
|
307 |
1e0b1727
|
Phil Davis
|
|
308 |
5b74202b
|
Scott Ullrich
|
for ($i = 0; $i < (count($ifarr)-1); $i++) {
|
309 |
|
|
for ($j = ($i+1); $j < count($ifarr); $j++) {
|
310 |
|
|
if ($ifarr[$i] == $ifarr[$j]) {
|
311 |
|
|
echo <<<EOD
|
312 |
1e0b1727
|
Phil Davis
|
|
313 |
530e4707
|
NOYB
|
Error: The same interface name cannot be assigned twice!
|
314 |
1e0b1727
|
Phil Davis
|
|
315 |
5b74202b
|
Scott Ullrich
|
EOD;
|
316 |
|
|
fclose($fp);
|
317 |
|
|
return;
|
318 |
|
|
}
|
319 |
|
|
}
|
320 |
|
|
}
|
321 |
1e0b1727
|
Phil Davis
|
|
322 |
8e1fd4fe
|
Renato Botelho
|
echo "\n" . gettext("The interfaces will be assigned as follows:") . "\n\n";
|
323 |
1e0b1727
|
Phil Davis
|
|
324 |
95524508
|
Ermal
|
echo "WAN -> " . $wanif . "\n";
|
325 |
1e0b1727
|
Phil Davis
|
if ($lanif != "") {
|
326 |
5b74202b
|
Scott Ullrich
|
echo "LAN -> " . $lanif . "\n";
|
327 |
1e0b1727
|
Phil Davis
|
}
|
328 |
5b74202b
|
Scott Ullrich
|
for ($i = 0; $i < count($optif); $i++) {
|
329 |
|
|
echo "OPT" . ($i+1) . " -> " . $optif[$i] . "\n";
|
330 |
|
|
}
|
331 |
1e0b1727
|
Phil Davis
|
|
332 |
0b3799f1
|
Phil Davis
|
echo "\n" . gettext("Do you want to proceed [y|n]?") . " ";
|
333 |
1e0b1727
|
Phil Davis
|
$key = chop(fgets($fp));
|
334 |
5b74202b
|
Scott Ullrich
|
}
|
335 |
|
|
|
336 |
|
|
if (in_array($key, array('y', 'Y'))) {
|
337 |
1e0b1727
|
Phil Davis
|
if ($lanif) {
|
338 |
86d1c9c2
|
Luiz Otavio O Souza
|
if (is_array($config['interfaces']['lan'])) {
|
339 |
|
|
$upints = pfSense_interface_listget(IFF_UP);
|
340 |
|
|
if (in_array($config['interfaces']['lan']['if'], $upints))
|
341 |
|
|
interface_bring_down('lan', true);
|
342 |
|
|
}
|
343 |
1e0b1727
|
Phil Davis
|
if (!is_array($config['interfaces']['lan'])) {
|
344 |
e503c44a
|
Ermal
|
$config['interfaces']['lan'] = array();
|
345 |
1e0b1727
|
Phil Davis
|
}
|
346 |
5b74202b
|
Scott Ullrich
|
$config['interfaces']['lan']['if'] = $lanif;
|
347 |
|
|
$config['interfaces']['lan']['enable'] = true;
|
348 |
285ef132
|
Ermal LUÇI
|
} elseif (!platform_booting() && !$auto_assign) {
|
349 |
5b74202b
|
Scott Ullrich
|
|
350 |
0b3799f1
|
Phil Davis
|
echo "\n" . gettext("You have chosen to remove the LAN interface.") . "\n";
|
351 |
|
|
echo "\n" . gettext("Would you like to remove the LAN IP address and \nunload the interface now [y|n]?") . " ";
|
352 |
5b74202b
|
Scott Ullrich
|
|
353 |
1e0b1727
|
Phil Davis
|
if (strcasecmp(chop(fgets($fp)), "y") == 0) {
|
354 |
|
|
if (isset($config['interfaces']['lan']) && $config['interfaces']['lan']['if']) {
|
355 |
|
|
mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
|
356 |
5b74202b
|
Scott Ullrich
|
}
|
357 |
1e0b1727
|
Phil Davis
|
}
|
358 |
|
|
if (isset($config['interfaces']['lan'])) {
|
359 |
|
|
unset($config['interfaces']['lan']);
|
360 |
|
|
}
|
361 |
|
|
if (isset($config['dhcpd']['lan'])) {
|
362 |
|
|
unset($config['dhcpd']['lan']);
|
363 |
|
|
}
|
364 |
bb213758
|
Chris Buechler
|
if (isset($config['dhcpdv6']['lan'])) {
|
365 |
|
|
unset($config['dhcpdv6']['lan']);
|
366 |
|
|
}
|
367 |
1e0b1727
|
Phil Davis
|
if (isset($config['interfaces']['lan']['if'])) {
|
368 |
|
|
unset($config['interfaces']['lan']['if']);
|
369 |
|
|
}
|
370 |
|
|
if (isset($config['interfaces']['wan']['blockpriv'])) {
|
371 |
|
|
unset($config['interfaces']['wan']['blockpriv']);
|
372 |
|
|
}
|
373 |
|
|
if (isset($config['shaper'])) {
|
374 |
|
|
unset($config['shaper']);
|
375 |
|
|
}
|
376 |
|
|
if (isset($config['ezshaper'])) {
|
377 |
|
|
unset($config['ezshaper']);
|
378 |
|
|
}
|
379 |
|
|
if (isset($config['nat'])) {
|
380 |
|
|
unset($config['nat']);
|
381 |
|
|
}
|
382 |
5b74202b
|
Scott Ullrich
|
} else {
|
383 |
1e0b1727
|
Phil Davis
|
if (isset($config['interfaces']['lan']['if'])) {
|
384 |
5b74202b
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
|
385 |
1e0b1727
|
Phil Davis
|
}
|
386 |
|
|
if (isset($config['interfaces']['lan'])) {
|
387 |
5b74202b
|
Scott Ullrich
|
unset($config['interfaces']['lan']);
|
388 |
1e0b1727
|
Phil Davis
|
}
|
389 |
|
|
if (isset($config['dhcpd']['lan'])) {
|
390 |
5b74202b
|
Scott Ullrich
|
unset($config['dhcpd']['lan']);
|
391 |
1e0b1727
|
Phil Davis
|
}
|
392 |
|
|
if (isset($config['interfaces']['lan']['if'])) {
|
393 |
5b74202b
|
Scott Ullrich
|
unset($config['interfaces']['lan']['if']);
|
394 |
1e0b1727
|
Phil Davis
|
}
|
395 |
|
|
if (isset($config['interfaces']['wan']['blockpriv'])) {
|
396 |
5b74202b
|
Scott Ullrich
|
unset($config['interfaces']['wan']['blockpriv']);
|
397 |
1e0b1727
|
Phil Davis
|
}
|
398 |
|
|
if (isset($config['shaper'])) {
|
399 |
5b74202b
|
Scott Ullrich
|
unset($config['shaper']);
|
400 |
1e0b1727
|
Phil Davis
|
}
|
401 |
|
|
if (isset($config['ezshaper'])) {
|
402 |
5b74202b
|
Scott Ullrich
|
unset($config['ezshaper']);
|
403 |
1e0b1727
|
Phil Davis
|
}
|
404 |
|
|
if (isset($config['nat'])) {
|
405 |
|
|
unset($config['nat']);
|
406 |
|
|
}
|
407 |
5b74202b
|
Scott Ullrich
|
}
|
408 |
|
|
if (preg_match($g['wireless_regex'], $lanif)) {
|
409 |
|
|
if (is_array($config['interfaces']['lan']) &&
|
410 |
ae52d165
|
Renato Botelho
|
!is_array($config['interfaces']['lan']['wireless'])) {
|
411 |
5b74202b
|
Scott Ullrich
|
$config['interfaces']['lan']['wireless'] = array();
|
412 |
1e0b1727
|
Phil Davis
|
}
|
413 |
5b74202b
|
Scott Ullrich
|
} else {
|
414 |
1e0b1727
|
Phil Davis
|
if (isset($config['interfaces']['lan'])) {
|
415 |
e503c44a
|
Ermal
|
unset($config['interfaces']['lan']['wireless']);
|
416 |
1e0b1727
|
Phil Davis
|
}
|
417 |
5b74202b
|
Scott Ullrich
|
}
|
418 |
|
|
|
419 |
86d1c9c2
|
Luiz Otavio O Souza
|
if (is_array($config['interfaces']['wan'])) {
|
420 |
|
|
$upints = pfSense_interface_listget(IFF_UP);
|
421 |
|
|
if (in_array($config['interfaces']['wan']['if'], $upints))
|
422 |
|
|
interface_bring_down('wan', true);
|
423 |
|
|
}
|
424 |
1e0b1727
|
Phil Davis
|
if (!is_array($config['interfaces']['wan'])) {
|
425 |
e503c44a
|
Ermal
|
$config['interfaces']['wan'] = array();
|
426 |
1e0b1727
|
Phil Davis
|
}
|
427 |
5b74202b
|
Scott Ullrich
|
$config['interfaces']['wan']['if'] = $wanif;
|
428 |
|
|
$config['interfaces']['wan']['enable'] = true;
|
429 |
|
|
if (preg_match($g['wireless_regex'], $wanif)) {
|
430 |
|
|
if (is_array($config['interfaces']['wan']) &&
|
431 |
ae52d165
|
Renato Botelho
|
!is_array($config['interfaces']['wan']['wireless'])) {
|
432 |
5b74202b
|
Scott Ullrich
|
$config['interfaces']['wan']['wireless'] = array();
|
433 |
1e0b1727
|
Phil Davis
|
}
|
434 |
5b74202b
|
Scott Ullrich
|
} else {
|
435 |
1e0b1727
|
Phil Davis
|
if (isset($config['interfaces']['wan'])) {
|
436 |
e503c44a
|
Ermal
|
unset($config['interfaces']['wan']['wireless']);
|
437 |
1e0b1727
|
Phil Davis
|
}
|
438 |
5b74202b
|
Scott Ullrich
|
}
|
439 |
|
|
|
440 |
|
|
for ($i = 0; $i < count($optif); $i++) {
|
441 |
86d1c9c2
|
Luiz Otavio O Souza
|
if (is_array($config['interfaces']['opt' . ($i+1)])) {
|
442 |
|
|
$upints = pfSense_interface_listget(IFF_UP);
|
443 |
|
|
if (in_array($config['interfaces']['opt' . ($i+1)]['if'], $upints))
|
444 |
|
|
interface_bring_down('opt' . ($i+1), true);
|
445 |
|
|
}
|
446 |
1e0b1727
|
Phil Davis
|
if (!is_array($config['interfaces']['opt' . ($i+1)])) {
|
447 |
5b74202b
|
Scott Ullrich
|
$config['interfaces']['opt' . ($i+1)] = array();
|
448 |
1e0b1727
|
Phil Davis
|
}
|
449 |
5b74202b
|
Scott Ullrich
|
|
450 |
|
|
$config['interfaces']['opt' . ($i+1)]['if'] = $optif[$i];
|
451 |
|
|
|
452 |
|
|
/* wireless interface? */
|
453 |
|
|
if (preg_match($g['wireless_regex'], $optif[$i])) {
|
454 |
1e0b1727
|
Phil Davis
|
if (!is_array($config['interfaces']['opt' . ($i+1)]['wireless'])) {
|
455 |
5b74202b
|
Scott Ullrich
|
$config['interfaces']['opt' . ($i+1)]['wireless'] = array();
|
456 |
1e0b1727
|
Phil Davis
|
}
|
457 |
5b74202b
|
Scott Ullrich
|
} else {
|
458 |
|
|
unset($config['interfaces']['opt' . ($i+1)]['wireless']);
|
459 |
|
|
}
|
460 |
|
|
|
461 |
62784b05
|
Ermal
|
if (empty($config['interfaces']['opt' . ($i+1)]['descr'])) {
|
462 |
|
|
$config['interfaces']['opt' . ($i+1)]['descr'] = "OPT" . ($i+1);
|
463 |
|
|
unset($config['interfaces']['opt' . ($i+1)]['enable']);
|
464 |
|
|
}
|
465 |
5b74202b
|
Scott Ullrich
|
}
|
466 |
|
|
|
467 |
|
|
/* remove all other (old) optional interfaces */
|
468 |
1e0b1727
|
Phil Davis
|
for (; isset($config['interfaces']['opt' . ($i+1)]); $i++) {
|
469 |
5b74202b
|
Scott Ullrich
|
unset($config['interfaces']['opt' . ($i+1)]);
|
470 |
1e0b1727
|
Phil Davis
|
}
|
471 |
5b74202b
|
Scott Ullrich
|
|
472 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("%sWriting configuration..."), "\n");
|
473 |
d18f3f6e
|
Phil Davis
|
write_config(gettext("Console assignment of interfaces"));
|
474 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("done.%s"), "\n");
|
475 |
5b74202b
|
Scott Ullrich
|
|
476 |
|
|
fclose($fp);
|
477 |
c9fa8254
|
Scott Ullrich
|
|
478 |
1e0b1727
|
Phil Davis
|
if (platform_booting()) {
|
479 |
5b74202b
|
Scott Ullrich
|
return;
|
480 |
1e0b1727
|
Phil Davis
|
}
|
481 |
5b74202b
|
Scott Ullrich
|
|
482 |
34ee6639
|
NOYB
|
echo gettext("One moment while the settings are reloading...");
|
483 |
9d3d8d00
|
Vinicius Coque
|
echo gettext(" done!") . "\n";
|
484 |
5b74202b
|
Scott Ullrich
|
|
485 |
|
|
touch("{$g['tmp_path']}/assign_complete");
|
486 |
|
|
|
487 |
|
|
}
|
488 |
|
|
}
|
489 |
|
|
|
490 |
|
|
function autodetect_interface($ifname, $fp) {
|
491 |
|
|
$iflist_prev = get_interface_list("media");
|
492 |
|
|
echo <<<EOD
|
493 |
|
|
|
494 |
|
|
Connect the {$ifname} interface now and make sure that the link is up.
|
495 |
|
|
Then press ENTER to continue.
|
496 |
|
|
|
497 |
|
|
EOD;
|
498 |
|
|
fgets($fp);
|
499 |
|
|
$iflist = get_interface_list("media");
|
500 |
|
|
|
501 |
|
|
foreach ($iflist_prev as $ifn => $ifa) {
|
502 |
|
|
if (!$ifa['up'] && $iflist[$ifn]['up']) {
|
503 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("Detected link-up on interface %s.%s"), $ifn, "\n");
|
504 |
5b74202b
|
Scott Ullrich
|
return $ifn;
|
505 |
|
|
}
|
506 |
|
|
}
|
507 |
|
|
|
508 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("No link-up detected.%s"), "\n");
|
509 |
5b74202b
|
Scott Ullrich
|
|
510 |
|
|
return null;
|
511 |
|
|
}
|
512 |
|
|
|
513 |
c9fa8254
|
Scott Ullrich
|
function interfaces_setup() {
|
514 |
|
|
global $iflist, $config, $g, $fp;
|
515 |
|
|
|
516 |
|
|
$iflist = get_interface_list();
|
517 |
|
|
}
|
518 |
|
|
|
519 |
5b74202b
|
Scott Ullrich
|
function vlan_setup() {
|
520 |
|
|
global $iflist, $config, $g, $fp;
|
521 |
|
|
|
522 |
|
|
$iflist = get_interface_list();
|
523 |
|
|
|
524 |
|
|
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
|
525 |
0b3799f1
|
Phil Davis
|
echo "\n" . gettext("WARNING: all existing VLANs will be cleared if you proceed!") . "\n";
|
526 |
|
|
echo "\n" . gettext("Do you want to proceed [y|n]?") . " ";
|
527 |
5b74202b
|
Scott Ullrich
|
|
528 |
1e0b1727
|
Phil Davis
|
if (strcasecmp(chop(fgets($fp)), "y") != 0) {
|
529 |
|
|
return;
|
530 |
|
|
}
|
531 |
5b74202b
|
Scott Ullrich
|
}
|
532 |
|
|
|
533 |
|
|
$config['vlans']['vlan'] = array();
|
534 |
|
|
echo "\n";
|
535 |
|
|
|
536 |
|
|
$vlanif = 0;
|
537 |
|
|
|
538 |
|
|
while (1) {
|
539 |
|
|
$vlan = array();
|
540 |
|
|
|
541 |
814f9e64
|
Carlos Eduardo Ramos
|
echo "\n\n" . gettext("VLAN Capable interfaces:") . "\n\n";
|
542 |
1e0b1727
|
Phil Davis
|
if (!is_array($iflist)) {
|
543 |
814f9e64
|
Carlos Eduardo Ramos
|
echo gettext("No interfaces found!") . "\n";
|
544 |
5b74202b
|
Scott Ullrich
|
} else {
|
545 |
6c07db48
|
Phil Davis
|
$vlan_capable = 0;
|
546 |
5b74202b
|
Scott Ullrich
|
foreach ($iflist as $iface => $ifa) {
|
547 |
|
|
if (is_jumbo_capable($iface)) {
|
548 |
|
|
echo sprintf("% -8s%s%s\n", $iface, $ifa['mac'],
|
549 |
|
|
$ifa['up'] ? " (up)" : "");
|
550 |
|
|
$vlan_capable++;
|
551 |
|
|
}
|
552 |
|
|
}
|
553 |
|
|
}
|
554 |
|
|
|
555 |
1e0b1727
|
Phil Davis
|
if ($vlan_capable == 0) {
|
556 |
814f9e64
|
Carlos Eduardo Ramos
|
echo gettext("No VLAN capable interfaces detected.") . "\n";
|
557 |
5b74202b
|
Scott Ullrich
|
return;
|
558 |
|
|
}
|
559 |
|
|
|
560 |
814f9e64
|
Carlos Eduardo Ramos
|
echo "\n" . gettext("Enter the parent interface name for the new VLAN (or nothing if finished):") . " ";
|
561 |
5b74202b
|
Scott Ullrich
|
$vlan['if'] = chop(fgets($fp));
|
562 |
|
|
|
563 |
|
|
if ($vlan['if']) {
|
564 |
|
|
if (!array_key_exists($vlan['if'], $iflist) or
|
565 |
ae52d165
|
Renato Botelho
|
!is_jumbo_capable($vlan['if'])) {
|
566 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $vlan['if'], "\n");
|
567 |
5b74202b
|
Scott Ullrich
|
continue;
|
568 |
|
|
}
|
569 |
|
|
} else {
|
570 |
|
|
break;
|
571 |
|
|
}
|
572 |
|
|
|
573 |
814f9e64
|
Carlos Eduardo Ramos
|
echo gettext("Enter the VLAN tag (1-4094):") . " ";
|
574 |
5b74202b
|
Scott Ullrich
|
$vlan['tag'] = chop(fgets($fp));
|
575 |
|
|
$vlan['vlanif'] = "{$vlan['if']}_vlan{$vlan['tag']}";
|
576 |
|
|
if (!is_numericint($vlan['tag']) || ($vlan['tag'] < 1) || ($vlan['tag'] > 4094)) {
|
577 |
814f9e64
|
Carlos Eduardo Ramos
|
printf(gettext("%sInvalid VLAN tag '%s'%s"), "\n", $vlan['tag'], "\n");
|
578 |
5b74202b
|
Scott Ullrich
|
continue;
|
579 |
|
|
}
|
580 |
1e0b1727
|
Phil Davis
|
|
581 |
ff4665f0
|
Chris Buechler
|
if (is_array($config['vlans']['vlan'])) {
|
582 |
|
|
foreach ($config['vlans']['vlan'] as $existingvlan) {
|
583 |
|
|
if ($vlan['if'] == $existingvlan['if'] && $vlan['tag'] == $existingvlan['tag']) {
|
584 |
|
|
printf("\n\n" . gettext("This parent interface and VLAN already created."));
|
585 |
|
|
continue 2;
|
586 |
|
|
}
|
587 |
|
|
}
|
588 |
|
|
}
|
589 |
5b74202b
|
Scott Ullrich
|
$config['vlans']['vlan'][] = $vlan;
|
590 |
|
|
$vlanif++;
|
591 |
|
|
}
|
592 |
|
|
}
|
593 |
|
|
|
594 |
b49e6c01
|
Phil Davis
|
function check_for_alternate_interfaces() {
|
595 |
|
|
global $config;
|
596 |
|
|
|
597 |
|
|
// If the WAN and/or LAN devices in the factory default config do not exist,
|
598 |
|
|
// then look for alternate devices.
|
599 |
|
|
// This lets many systems boot a factory default config without being
|
600 |
|
|
// forced to do interface assignment on the console.
|
601 |
|
|
|
602 |
|
|
$specplatform = system_identify_specific_platform();
|
603 |
|
|
$default_device = array();
|
604 |
|
|
|
605 |
|
|
// If we recognise the platform, then specify the devices directly.
|
606 |
|
|
switch ($specplatform['name']) {
|
607 |
|
|
case 'alix':
|
608 |
|
|
$default_device['wan'] = "vr1";
|
609 |
|
|
$default_device['lan'] = "vr0";
|
610 |
|
|
break;
|
611 |
|
|
case 'APU':
|
612 |
|
|
$default_device['wan'] = "re1";
|
613 |
|
|
$default_device['lan'] = "re2";
|
614 |
|
|
break;
|
615 |
|
|
case 'RCC-VE':
|
616 |
|
|
$default_device['wan'] = "igb0";
|
617 |
|
|
$default_device['lan'] = "igb1";
|
618 |
|
|
break;
|
619 |
|
|
default:
|
620 |
|
|
$default_device['wan'] = "";
|
621 |
|
|
$default_device['lan'] = "";
|
622 |
|
|
break;
|
623 |
|
|
}
|
624 |
|
|
|
625 |
|
|
// Other common device names can be put here and will be looked for
|
626 |
|
|
// if the system was not one of the known platforms.
|
627 |
|
|
$other_devices_arr['wan'] = array("vr1", "re1", "igb0", "em0");
|
628 |
|
|
$other_devices_arr['lan'] = array("vr0", "re2", "igb1", "em1");
|
629 |
|
|
$interface_assignment_changed = false;
|
630 |
|
|
|
631 |
|
|
foreach ($other_devices_arr as $ifname => $other_devices) {
|
632 |
|
|
if (!does_interface_exist($config['interfaces'][$ifname]['if'])) {
|
633 |
|
|
if (does_interface_exist($default_device[$ifname])) {
|
634 |
|
|
$config['interfaces'][$ifname]['if'] = $default_device[$ifname];
|
635 |
|
|
$interface_assignment_changed = true;
|
636 |
|
|
} else {
|
637 |
|
|
foreach ($other_devices as $other_device) {
|
638 |
|
|
if (does_interface_exist($other_device)) {
|
639 |
|
|
$config['interfaces'][$ifname]['if'] = $other_device;
|
640 |
|
|
$interface_assignment_changed = true;
|
641 |
|
|
break;
|
642 |
|
|
}
|
643 |
|
|
}
|
644 |
|
|
}
|
645 |
|
|
}
|
646 |
|
|
}
|
647 |
|
|
|
648 |
|
|
if ($interface_assignment_changed) {
|
649 |
|
|
write_config("Factory default boot detected WAN " . $config['interfaces']['wan']['if'] . " and LAN " . $config['interfaces']['lan']['if']);
|
650 |
|
|
}
|
651 |
|
|
}
|
652 |
|
|
|
653 |
814f9e64
|
Carlos Eduardo Ramos
|
?>
|