1
|
<?php
|
2
|
/*
|
3
|
config.console.inc
|
4
|
|
5
|
part of pfSense (https://www.pfsense.org)
|
6
|
Copyright (c) 2004-2016 Electric Sheep Fencing, LLC. All rights reserved.
|
7
|
|
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
|
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
|
*/
|
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
|
$physmem = $memory[0];
|
67
|
$realmem = $memory[1];
|
68
|
|
69
|
if ($physmem < $g['minimum_ram_warning']) {
|
70
|
echo "\n\n\n";
|
71
|
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
|
printf(gettext("Only (%s) MB RAM has been detected, with (%s) available to %s.%s"), $realmem, $physmem, $g['product_name'], "\n");
|
74
|
echo "\n" . gettext("Press ENTER to continue.") . " ";
|
75
|
fgets($fp);
|
76
|
echo "\n";
|
77
|
}
|
78
|
|
79
|
$iflist = get_interface_list();
|
80
|
|
81
|
/* Function flow is based on $key and $auto_assign or the lack thereof */
|
82
|
$key = null;
|
83
|
|
84
|
/* Only present auto interface option if running from the installer media and interface mismatch*/
|
85
|
if ((preg_match("/cdrom/", $g['platform'])) && is_interface_mismatch()) {
|
86
|
$auto_assign = false;
|
87
|
}
|
88
|
|
89
|
echo <<<EOD
|
90
|
|
91
|
Valid interfaces are:
|
92
|
|
93
|
|
94
|
EOD;
|
95
|
|
96
|
if (!is_array($iflist)) {
|
97
|
echo gettext("No interfaces found!") . "\n";
|
98
|
$iflist = array();
|
99
|
} else {
|
100
|
foreach ($iflist as $iface => $ifa) {
|
101
|
$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
|
$ifsmallist = trim($ifsmallist . " " . $iface);
|
108
|
echo sprintf("% -7s%s %s %s\n", $iface, $ifa['mac'],
|
109
|
$status, substr($ifa['dmesg'], 0, 48));
|
110
|
}
|
111
|
}
|
112
|
|
113
|
if ($auto_assign) {
|
114
|
echo <<<EOD
|
115
|
|
116
|
!!! Installation Media Detected: Auto Interface Option !!!!
|
117
|
BEGIN MANUAL CONFIGURATION OR THE SYSTEM WILL PROCEED WITH AUTO CONFIGURATION.
|
118
|
|
119
|
EOD;
|
120
|
}
|
121
|
|
122
|
echo "\n" . gettext("Do VLANs need to be set up first?");
|
123
|
echo "\n" .
|
124
|
gettext(
|
125
|
"If VLANs will not be used, or only for optional interfaces, it is typical to\n" .
|
126
|
"say no here and use the webConfigurator to configure VLANs later, if required.") .
|
127
|
"\n";
|
128
|
echo "\n" . gettext("Should VLANs be set up now [y|n]?") . " ";
|
129
|
|
130
|
if ($auto_assign) {
|
131
|
$key = timeout();
|
132
|
} else {
|
133
|
$key = chop(fgets($fp));
|
134
|
}
|
135
|
|
136
|
if (!isset($key) and $auto_assign) { // Auto Assign Interfaces
|
137
|
do {
|
138
|
echo <<<EOD
|
139
|
|
140
|
!!! Auto Assigning Interfaces !!!
|
141
|
|
142
|
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
|
|
148
|
Please make the pfSense NIC connections now.
|
149
|
The system will continue checking until they have been made.
|
150
|
|
151
|
Searching for active interfaces...
|
152
|
|
153
|
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
|
if ($ifa['up']) {
|
160
|
$plugged_in[] = $iface;
|
161
|
}
|
162
|
}
|
163
|
|
164
|
$lanif = array_shift($plugged_in);
|
165
|
$wanif = array_shift($plugged_in);
|
166
|
|
167
|
if (isset($lanif) && !isset($wanif)) {
|
168
|
foreach ($iflist as $iface => $ifa) {
|
169
|
if ($iface != $lanif) {
|
170
|
$wanif = $iface;
|
171
|
break;
|
172
|
}
|
173
|
}
|
174
|
}
|
175
|
|
176
|
echo <<<EOD
|
177
|
|
178
|
Assigned WAN to : $wanif
|
179
|
Assigned LAN to : $lanif
|
180
|
|
181
|
If these assignments are not suitable,
|
182
|
press any key to go back to manual configuration.
|
183
|
|
184
|
EOD;
|
185
|
$key = timeout(20);
|
186
|
if (isset($key)) {
|
187
|
return;
|
188
|
}
|
189
|
} while (!isset($wanif));
|
190
|
|
191
|
$config['system']['enablesshd'] = 'enabled';
|
192
|
$key = 'y';
|
193
|
|
194
|
} else {
|
195
|
//Manually assign interfaces
|
196
|
if (in_array($key, array('y', 'Y'))) {
|
197
|
vlan_setup();
|
198
|
}
|
199
|
|
200
|
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
|
201
|
|
202
|
echo "\n\n" . gettext("VLAN interfaces:") . "\n\n";
|
203
|
foreach ($config['vlans']['vlan'] as $vlan) {
|
204
|
|
205
|
echo sprintf("% -16s%s\n", "{$vlan['if']}_vlan{$vlan['tag']}",
|
206
|
"VLAN tag {$vlan['tag']}, parent interface {$vlan['if']}");
|
207
|
|
208
|
$iflist[$vlan['if'] . '_vlan' . $vlan['tag']] = array();
|
209
|
$ifsmallist = trim($ifsmallist . " " . $vlan['if'] . '_vlan' . $vlan['tag']);
|
210
|
}
|
211
|
}
|
212
|
|
213
|
echo <<<EOD
|
214
|
|
215
|
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
|
|
219
|
EOD;
|
220
|
|
221
|
do {
|
222
|
echo "\n" . gettext("Enter the WAN interface name or 'a' for auto-detection") . " ";
|
223
|
printf(gettext("%s(%s or a): "), "\n", $ifsmallist);
|
224
|
$wanif = chop(fgets($fp));
|
225
|
if ($wanif === "") {
|
226
|
return;
|
227
|
}
|
228
|
if ($wanif === "a") {
|
229
|
$wanif = autodetect_interface("WAN", $fp);
|
230
|
} else if (!array_key_exists($wanif, $iflist)) {
|
231
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $wanif, "\n");
|
232
|
unset($wanif);
|
233
|
continue;
|
234
|
}
|
235
|
$ifsmallist = trim(str_replace(" ", " ", str_replace($wanif, "", $ifsmallist)));
|
236
|
} while (!$wanif);
|
237
|
|
238
|
do {
|
239
|
printf(gettext("%sEnter the LAN interface name or 'a' for auto-detection %s" .
|
240
|
"NOTE: this enables full Firewalling/NAT mode.%s" .
|
241
|
"(%s a or nothing if finished):%s"), "\n", "\n", "\n", $ifsmallist, " ");
|
242
|
|
243
|
$lanif = chop(fgets($fp));
|
244
|
|
245
|
if ($lanif == "exit") {
|
246
|
exit;
|
247
|
}
|
248
|
|
249
|
if ($lanif == "") {
|
250
|
/* It is OK to have just a WAN, without a LAN so break if the user does not want LAN. */
|
251
|
break;
|
252
|
}
|
253
|
|
254
|
if ($lanif === "a") {
|
255
|
$lanif = autodetect_interface("LAN", $fp);
|
256
|
} else if (!array_key_exists($lanif, $iflist)) {
|
257
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $lanif, "\n");
|
258
|
unset($lanif);
|
259
|
continue;
|
260
|
}
|
261
|
$ifsmallist = trim(str_replace(" ", " ", str_replace($lanif, "", $ifsmallist)));
|
262
|
} while (!$lanif);
|
263
|
|
264
|
/* optional interfaces */
|
265
|
$i = 0;
|
266
|
$optif = array();
|
267
|
|
268
|
if ($lanif <> "") {
|
269
|
while (1) {
|
270
|
if ($optif[$i]) {
|
271
|
$i++;
|
272
|
}
|
273
|
$io = $i + 1;
|
274
|
|
275
|
if ($config['interfaces']['opt' . $io]['descr']) {
|
276
|
printf(gettext("%sOptional interface %s description found: %s"), "\n", $io, $config['interfaces']['opt' . $io]['descr']);
|
277
|
}
|
278
|
|
279
|
printf(gettext("%sEnter the Optional %s interface name or 'a' for auto-detection%s" .
|
280
|
"(%s a or nothing if finished):%s"), "\n", $io, "\n", $ifsmallist, " ");
|
281
|
|
282
|
$optif[$i] = chop(fgets($fp));
|
283
|
|
284
|
if ($optif[$i]) {
|
285
|
if ($optif[$i] === "a") {
|
286
|
$ad = autodetect_interface(gettext("Optional") . " " . $io, $fp);
|
287
|
if ($ad) {
|
288
|
$optif[$i] = $ad;
|
289
|
} else {
|
290
|
unset($optif[$i]);
|
291
|
}
|
292
|
} else if (!array_key_exists($optif[$i], $iflist)) {
|
293
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $optif[$i], "\n");
|
294
|
unset($optif[$i]);
|
295
|
continue;
|
296
|
}
|
297
|
$ifsmallist = trim(str_replace(" ", " ", str_replace($optif[$i], "", $ifsmallist)));
|
298
|
} else {
|
299
|
unset($optif[$i]);
|
300
|
break;
|
301
|
}
|
302
|
}
|
303
|
}
|
304
|
|
305
|
/* check for double assignments */
|
306
|
$ifarr = array_merge(array($lanif, $wanif), $optif);
|
307
|
|
308
|
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
|
|
313
|
Error: The same interface name cannot be assigned twice!
|
314
|
|
315
|
EOD;
|
316
|
fclose($fp);
|
317
|
return;
|
318
|
}
|
319
|
}
|
320
|
}
|
321
|
|
322
|
echo "\n" . gettext("The interfaces will be assigned as follows:") . "\n\n";
|
323
|
|
324
|
echo "WAN -> " . $wanif . "\n";
|
325
|
if ($lanif != "") {
|
326
|
echo "LAN -> " . $lanif . "\n";
|
327
|
}
|
328
|
for ($i = 0; $i < count($optif); $i++) {
|
329
|
echo "OPT" . ($i+1) . " -> " . $optif[$i] . "\n";
|
330
|
}
|
331
|
|
332
|
echo "\n" . gettext("Do you want to proceed [y|n]?") . " ";
|
333
|
$key = chop(fgets($fp));
|
334
|
}
|
335
|
|
336
|
if (in_array($key, array('y', 'Y'))) {
|
337
|
if ($lanif) {
|
338
|
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
|
if (!is_array($config['interfaces']['lan'])) {
|
344
|
$config['interfaces']['lan'] = array();
|
345
|
}
|
346
|
$config['interfaces']['lan']['if'] = $lanif;
|
347
|
$config['interfaces']['lan']['enable'] = true;
|
348
|
} elseif (!platform_booting() && !$auto_assign) {
|
349
|
|
350
|
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
|
|
353
|
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
|
}
|
357
|
}
|
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
|
if (isset($config['dhcpdv6']['lan'])) {
|
365
|
unset($config['dhcpdv6']['lan']);
|
366
|
}
|
367
|
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
|
} else {
|
383
|
if (isset($config['interfaces']['lan']['if'])) {
|
384
|
mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
|
385
|
}
|
386
|
if (isset($config['interfaces']['lan'])) {
|
387
|
unset($config['interfaces']['lan']);
|
388
|
}
|
389
|
if (isset($config['dhcpd']['lan'])) {
|
390
|
unset($config['dhcpd']['lan']);
|
391
|
}
|
392
|
if (isset($config['interfaces']['lan']['if'])) {
|
393
|
unset($config['interfaces']['lan']['if']);
|
394
|
}
|
395
|
if (isset($config['interfaces']['wan']['blockpriv'])) {
|
396
|
unset($config['interfaces']['wan']['blockpriv']);
|
397
|
}
|
398
|
if (isset($config['shaper'])) {
|
399
|
unset($config['shaper']);
|
400
|
}
|
401
|
if (isset($config['ezshaper'])) {
|
402
|
unset($config['ezshaper']);
|
403
|
}
|
404
|
if (isset($config['nat'])) {
|
405
|
unset($config['nat']);
|
406
|
}
|
407
|
}
|
408
|
if (preg_match($g['wireless_regex'], $lanif)) {
|
409
|
if (is_array($config['interfaces']['lan']) &&
|
410
|
!is_array($config['interfaces']['lan']['wireless'])) {
|
411
|
$config['interfaces']['lan']['wireless'] = array();
|
412
|
}
|
413
|
} else {
|
414
|
if (isset($config['interfaces']['lan'])) {
|
415
|
unset($config['interfaces']['lan']['wireless']);
|
416
|
}
|
417
|
}
|
418
|
|
419
|
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
|
if (!is_array($config['interfaces']['wan'])) {
|
425
|
$config['interfaces']['wan'] = array();
|
426
|
}
|
427
|
$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
|
!is_array($config['interfaces']['wan']['wireless'])) {
|
432
|
$config['interfaces']['wan']['wireless'] = array();
|
433
|
}
|
434
|
} else {
|
435
|
if (isset($config['interfaces']['wan'])) {
|
436
|
unset($config['interfaces']['wan']['wireless']);
|
437
|
}
|
438
|
}
|
439
|
|
440
|
for ($i = 0; $i < count($optif); $i++) {
|
441
|
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
|
if (!is_array($config['interfaces']['opt' . ($i+1)])) {
|
447
|
$config['interfaces']['opt' . ($i+1)] = array();
|
448
|
}
|
449
|
|
450
|
$config['interfaces']['opt' . ($i+1)]['if'] = $optif[$i];
|
451
|
|
452
|
/* wireless interface? */
|
453
|
if (preg_match($g['wireless_regex'], $optif[$i])) {
|
454
|
if (!is_array($config['interfaces']['opt' . ($i+1)]['wireless'])) {
|
455
|
$config['interfaces']['opt' . ($i+1)]['wireless'] = array();
|
456
|
}
|
457
|
} else {
|
458
|
unset($config['interfaces']['opt' . ($i+1)]['wireless']);
|
459
|
}
|
460
|
|
461
|
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
|
}
|
466
|
|
467
|
/* remove all other (old) optional interfaces */
|
468
|
for (; isset($config['interfaces']['opt' . ($i+1)]); $i++) {
|
469
|
unset($config['interfaces']['opt' . ($i+1)]);
|
470
|
}
|
471
|
|
472
|
printf(gettext("%sWriting configuration..."), "\n");
|
473
|
write_config(gettext("Console assignment of interfaces"));
|
474
|
printf(gettext("done.%s"), "\n");
|
475
|
|
476
|
fclose($fp);
|
477
|
|
478
|
if (platform_booting()) {
|
479
|
return;
|
480
|
}
|
481
|
|
482
|
echo gettext("One moment while the settings are reloading...");
|
483
|
echo gettext(" done!") . "\n";
|
484
|
|
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
|
printf(gettext("Detected link-up on interface %s.%s"), $ifn, "\n");
|
504
|
return $ifn;
|
505
|
}
|
506
|
}
|
507
|
|
508
|
printf(gettext("No link-up detected.%s"), "\n");
|
509
|
|
510
|
return null;
|
511
|
}
|
512
|
|
513
|
function interfaces_setup() {
|
514
|
global $iflist, $config, $g, $fp;
|
515
|
|
516
|
$iflist = get_interface_list();
|
517
|
}
|
518
|
|
519
|
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
|
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
|
|
528
|
if (strcasecmp(chop(fgets($fp)), "y") != 0) {
|
529
|
return;
|
530
|
}
|
531
|
}
|
532
|
|
533
|
$config['vlans']['vlan'] = array();
|
534
|
echo "\n";
|
535
|
|
536
|
$vlanif = 0;
|
537
|
|
538
|
while (1) {
|
539
|
$vlan = array();
|
540
|
|
541
|
echo "\n\n" . gettext("VLAN Capable interfaces:") . "\n\n";
|
542
|
if (!is_array($iflist)) {
|
543
|
echo gettext("No interfaces found!") . "\n";
|
544
|
} else {
|
545
|
$vlan_capable = 0;
|
546
|
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
|
if ($vlan_capable == 0) {
|
556
|
echo gettext("No VLAN capable interfaces detected.") . "\n";
|
557
|
return;
|
558
|
}
|
559
|
|
560
|
echo "\n" . gettext("Enter the parent interface name for the new VLAN (or nothing if finished):") . " ";
|
561
|
$vlan['if'] = chop(fgets($fp));
|
562
|
|
563
|
if ($vlan['if']) {
|
564
|
if (!array_key_exists($vlan['if'], $iflist) or
|
565
|
!is_jumbo_capable($vlan['if'])) {
|
566
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $vlan['if'], "\n");
|
567
|
continue;
|
568
|
}
|
569
|
} else {
|
570
|
break;
|
571
|
}
|
572
|
|
573
|
echo gettext("Enter the VLAN tag (1-4094):") . " ";
|
574
|
$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
|
printf(gettext("%sInvalid VLAN tag '%s'%s"), "\n", $vlan['tag'], "\n");
|
578
|
continue;
|
579
|
}
|
580
|
|
581
|
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
|
$config['vlans']['vlan'][] = $vlan;
|
590
|
$vlanif++;
|
591
|
}
|
592
|
}
|
593
|
|
594
|
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
|
?>
|