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