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 LiveCD 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
|
$ifsmallist = trim($ifsmallist . " " . $iface);
|
102
|
echo sprintf("% -7s%s %s %s\n", $iface, $ifa['mac'],
|
103
|
$ifa['up'] ? " (up)" : "(down)", substr($ifa['dmesg'], 0, 48));
|
104
|
}
|
105
|
}
|
106
|
|
107
|
if ($auto_assign) {
|
108
|
echo <<<EOD
|
109
|
|
110
|
!!! LiveCD Detected: Auto Interface Option !!!!
|
111
|
BEGIN MANUAL CONFIGURATION OR WE WILL PROCEED WITH AUTO CONFIGURATION.
|
112
|
|
113
|
EOD;
|
114
|
}
|
115
|
|
116
|
echo "\n" . gettext("Do you want to set up VLANs first?");
|
117
|
echo "\n" .
|
118
|
gettext(
|
119
|
"If you are not going to use VLANs, or only for optional interfaces, you should\n" .
|
120
|
"say no here and use the webConfigurator to configure VLANs later, if required.") .
|
121
|
"\n";
|
122
|
echo "\n" . gettext("Do you want to set up VLANs now [y|n]?") . " ";
|
123
|
|
124
|
if ($auto_assign) {
|
125
|
$key = timeout();
|
126
|
} else {
|
127
|
$key = chop(fgets($fp));
|
128
|
}
|
129
|
|
130
|
if (!isset($key) and $auto_assign) { // Auto Assign Interfaces
|
131
|
do {
|
132
|
echo <<<EOD
|
133
|
|
134
|
!!! Auto Assigning Interfaces !!!
|
135
|
|
136
|
For installation purposes, you must plug in at least one NIC
|
137
|
for the LAN connection. If you plug in a second NIC it will be
|
138
|
assigned to WAN. Otherwise, we'll temporarily assign WAN to the
|
139
|
next available NIC found regardless of activity. You should
|
140
|
assign and configure the WAN interface according to your requirements
|
141
|
|
142
|
If you haven't plugged in any network cables yet,
|
143
|
now is the time to do so.
|
144
|
We'll keep trying until you do.
|
145
|
|
146
|
Searching for active interfaces...
|
147
|
|
148
|
EOD;
|
149
|
unset($wanif, $lanif);
|
150
|
|
151
|
$media_iflist = $plugged_in = array();
|
152
|
$media_iflist = get_interface_list("media");
|
153
|
foreach ($media_iflist as $iface => $ifa) {
|
154
|
if ($ifa['up']) {
|
155
|
$plugged_in[] = $iface;
|
156
|
}
|
157
|
}
|
158
|
|
159
|
$lanif = array_shift($plugged_in);
|
160
|
$wanif = array_shift($plugged_in);
|
161
|
|
162
|
if (isset($lanif) && !isset($wanif)) {
|
163
|
foreach ($iflist as $iface => $ifa) {
|
164
|
if ($iface != $lanif) {
|
165
|
$wanif = $iface;
|
166
|
break;
|
167
|
}
|
168
|
}
|
169
|
}
|
170
|
|
171
|
echo <<<EOD
|
172
|
|
173
|
Assigned WAN to : $wanif
|
174
|
Assigned LAN to : $lanif
|
175
|
|
176
|
If you don't like this assignment,
|
177
|
press any key to go back to manual configuration.
|
178
|
|
179
|
EOD;
|
180
|
$key = timeout(20);
|
181
|
if (isset($key)) {
|
182
|
return;
|
183
|
}
|
184
|
} while (!isset($wanif));
|
185
|
|
186
|
$config['system']['enablesshd'] = 'enabled';
|
187
|
$key = 'y';
|
188
|
|
189
|
} else {
|
190
|
//Manually assign interfaces
|
191
|
if (in_array($key, array('y', 'Y'))) {
|
192
|
vlan_setup();
|
193
|
}
|
194
|
|
195
|
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
|
196
|
|
197
|
echo "\n\n" . gettext("VLAN interfaces:") . "\n\n";
|
198
|
foreach ($config['vlans']['vlan'] as $vlan) {
|
199
|
|
200
|
echo sprintf("% -16s%s\n", "{$vlan['if']}_vlan{$vlan['tag']}",
|
201
|
"VLAN tag {$vlan['tag']}, parent interface {$vlan['if']}");
|
202
|
|
203
|
$iflist[$vlan['if'] . '_vlan' . $vlan['tag']] = array();
|
204
|
$ifsmallist = trim($ifsmallist . " " . $vlan['if'] . '_vlan' . $vlan['tag']);
|
205
|
}
|
206
|
}
|
207
|
|
208
|
echo <<<EOD
|
209
|
|
210
|
If you do not know the names of your interfaces, you may choose to use
|
211
|
auto-detection. In that case, disconnect all interfaces now before
|
212
|
hitting 'a' to initiate auto detection.
|
213
|
|
214
|
EOD;
|
215
|
|
216
|
do {
|
217
|
echo "\n" . gettext("Enter the WAN interface name or 'a' for auto-detection") . " ";
|
218
|
printf(gettext("%s(%s or a): "), "\n", $ifsmallist);
|
219
|
$wanif = chop(fgets($fp));
|
220
|
if ($wanif === "") {
|
221
|
return;
|
222
|
}
|
223
|
if ($wanif === "a") {
|
224
|
$wanif = autodetect_interface("WAN", $fp);
|
225
|
} else if (!array_key_exists($wanif, $iflist)) {
|
226
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $wanif, "\n");
|
227
|
unset($wanif);
|
228
|
continue;
|
229
|
}
|
230
|
$ifsmallist = trim(str_replace(" ", " ", str_replace($wanif, "", $ifsmallist)));
|
231
|
} while (!$wanif);
|
232
|
|
233
|
do {
|
234
|
printf(gettext("%sEnter the LAN interface name or 'a' for auto-detection %s" .
|
235
|
"NOTE: this enables full Firewalling/NAT mode.%s" .
|
236
|
"(%s a or nothing if finished):%s"), "\n", "\n", "\n", $ifsmallist, " ");
|
237
|
|
238
|
$lanif = chop(fgets($fp));
|
239
|
|
240
|
if ($lanif == "exit") {
|
241
|
exit;
|
242
|
}
|
243
|
|
244
|
if ($lanif == "") {
|
245
|
/* It is OK to have just a WAN, without a LAN so break if the user does not want LAN. */
|
246
|
break;
|
247
|
}
|
248
|
|
249
|
if ($lanif === "a") {
|
250
|
$lanif = autodetect_interface("LAN", $fp);
|
251
|
} else if (!array_key_exists($lanif, $iflist)) {
|
252
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $lanif, "\n");
|
253
|
unset($lanif);
|
254
|
continue;
|
255
|
}
|
256
|
$ifsmallist = trim(str_replace(" ", " ", str_replace($lanif, "", $ifsmallist)));
|
257
|
} while (!$lanif);
|
258
|
|
259
|
/* optional interfaces */
|
260
|
$i = 0;
|
261
|
$optif = array();
|
262
|
|
263
|
if ($lanif <> "") {
|
264
|
while (1) {
|
265
|
if ($optif[$i]) {
|
266
|
$i++;
|
267
|
}
|
268
|
$io = $i + 1;
|
269
|
|
270
|
if ($config['interfaces']['opt' . $io]['descr']) {
|
271
|
printf(gettext("%sOptional interface %s description found: %s"), "\n", $io, $config['interfaces']['opt' . $io]['descr']);
|
272
|
}
|
273
|
|
274
|
printf(gettext("%sEnter the Optional %s interface name or 'a' for auto-detection%s" .
|
275
|
"(%s a or nothing if finished):%s"), "\n", $io, "\n", $ifsmallist, " ");
|
276
|
|
277
|
$optif[$i] = chop(fgets($fp));
|
278
|
|
279
|
if ($optif[$i]) {
|
280
|
if ($optif[$i] === "a") {
|
281
|
$ad = autodetect_interface(gettext("Optional") . " " . $io, $fp);
|
282
|
if ($ad) {
|
283
|
$optif[$i] = $ad;
|
284
|
} else {
|
285
|
unset($optif[$i]);
|
286
|
}
|
287
|
} else if (!array_key_exists($optif[$i], $iflist)) {
|
288
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $optif[$i], "\n");
|
289
|
unset($optif[$i]);
|
290
|
continue;
|
291
|
}
|
292
|
$ifsmallist = trim(str_replace(" ", " ", str_replace($optif[$i], "", $ifsmallist)));
|
293
|
} else {
|
294
|
unset($optif[$i]);
|
295
|
break;
|
296
|
}
|
297
|
}
|
298
|
}
|
299
|
|
300
|
/* check for double assignments */
|
301
|
$ifarr = array_merge(array($lanif, $wanif), $optif);
|
302
|
|
303
|
for ($i = 0; $i < (count($ifarr)-1); $i++) {
|
304
|
for ($j = ($i+1); $j < count($ifarr); $j++) {
|
305
|
if ($ifarr[$i] == $ifarr[$j]) {
|
306
|
echo <<<EOD
|
307
|
|
308
|
Error: you cannot assign the same interface name twice!
|
309
|
|
310
|
EOD;
|
311
|
fclose($fp);
|
312
|
return;
|
313
|
}
|
314
|
}
|
315
|
}
|
316
|
|
317
|
echo "\n" . gettext("The interfaces will be assigned as follows:") . "\n\n";
|
318
|
|
319
|
echo "WAN -> " . $wanif . "\n";
|
320
|
if ($lanif != "") {
|
321
|
echo "LAN -> " . $lanif . "\n";
|
322
|
}
|
323
|
for ($i = 0; $i < count($optif); $i++) {
|
324
|
echo "OPT" . ($i+1) . " -> " . $optif[$i] . "\n";
|
325
|
}
|
326
|
|
327
|
echo "\n" . gettext("Do you want to proceed [y|n]?") . " ";
|
328
|
$key = chop(fgets($fp));
|
329
|
}
|
330
|
|
331
|
if (in_array($key, array('y', 'Y'))) {
|
332
|
if ($lanif) {
|
333
|
if (!is_array($config['interfaces']['lan'])) {
|
334
|
$config['interfaces']['lan'] = array();
|
335
|
}
|
336
|
$config['interfaces']['lan']['if'] = $lanif;
|
337
|
$config['interfaces']['lan']['enable'] = true;
|
338
|
} elseif (!platform_booting() && !$auto_assign) {
|
339
|
|
340
|
echo "\n" . gettext("You have chosen to remove the LAN interface.") . "\n";
|
341
|
echo "\n" . gettext("Would you like to remove the LAN IP address and \nunload the interface now [y|n]?") . " ";
|
342
|
|
343
|
if (strcasecmp(chop(fgets($fp)), "y") == 0) {
|
344
|
if (isset($config['interfaces']['lan']) && $config['interfaces']['lan']['if']) {
|
345
|
mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
|
346
|
}
|
347
|
}
|
348
|
if (isset($config['interfaces']['lan'])) {
|
349
|
unset($config['interfaces']['lan']);
|
350
|
}
|
351
|
if (isset($config['dhcpd']['lan'])) {
|
352
|
unset($config['dhcpd']['lan']);
|
353
|
}
|
354
|
if (isset($config['interfaces']['lan']['if'])) {
|
355
|
unset($config['interfaces']['lan']['if']);
|
356
|
}
|
357
|
if (isset($config['interfaces']['wan']['blockpriv'])) {
|
358
|
unset($config['interfaces']['wan']['blockpriv']);
|
359
|
}
|
360
|
if (isset($config['shaper'])) {
|
361
|
unset($config['shaper']);
|
362
|
}
|
363
|
if (isset($config['ezshaper'])) {
|
364
|
unset($config['ezshaper']);
|
365
|
}
|
366
|
if (isset($config['nat'])) {
|
367
|
unset($config['nat']);
|
368
|
}
|
369
|
} else {
|
370
|
if (isset($config['interfaces']['lan']['if'])) {
|
371
|
mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
|
372
|
}
|
373
|
if (isset($config['interfaces']['lan'])) {
|
374
|
unset($config['interfaces']['lan']);
|
375
|
}
|
376
|
if (isset($config['dhcpd']['lan'])) {
|
377
|
unset($config['dhcpd']['lan']);
|
378
|
}
|
379
|
if (isset($config['interfaces']['lan']['if'])) {
|
380
|
unset($config['interfaces']['lan']['if']);
|
381
|
}
|
382
|
if (isset($config['interfaces']['wan']['blockpriv'])) {
|
383
|
unset($config['interfaces']['wan']['blockpriv']);
|
384
|
}
|
385
|
if (isset($config['shaper'])) {
|
386
|
unset($config['shaper']);
|
387
|
}
|
388
|
if (isset($config['ezshaper'])) {
|
389
|
unset($config['ezshaper']);
|
390
|
}
|
391
|
if (isset($config['nat'])) {
|
392
|
unset($config['nat']);
|
393
|
}
|
394
|
}
|
395
|
if (preg_match($g['wireless_regex'], $lanif)) {
|
396
|
if (is_array($config['interfaces']['lan']) &&
|
397
|
!is_array($config['interfaces']['lan']['wireless'])) {
|
398
|
$config['interfaces']['lan']['wireless'] = array();
|
399
|
}
|
400
|
} else {
|
401
|
if (isset($config['interfaces']['lan'])) {
|
402
|
unset($config['interfaces']['lan']['wireless']);
|
403
|
}
|
404
|
}
|
405
|
|
406
|
if (!is_array($config['interfaces']['wan'])) {
|
407
|
$config['interfaces']['wan'] = array();
|
408
|
}
|
409
|
$config['interfaces']['wan']['if'] = $wanif;
|
410
|
$config['interfaces']['wan']['enable'] = true;
|
411
|
if (preg_match($g['wireless_regex'], $wanif)) {
|
412
|
if (is_array($config['interfaces']['wan']) &&
|
413
|
!is_array($config['interfaces']['wan']['wireless'])) {
|
414
|
$config['interfaces']['wan']['wireless'] = array();
|
415
|
}
|
416
|
} else {
|
417
|
if (isset($config['interfaces']['wan'])) {
|
418
|
unset($config['interfaces']['wan']['wireless']);
|
419
|
}
|
420
|
}
|
421
|
|
422
|
for ($i = 0; $i < count($optif); $i++) {
|
423
|
if (!is_array($config['interfaces']['opt' . ($i+1)])) {
|
424
|
$config['interfaces']['opt' . ($i+1)] = array();
|
425
|
}
|
426
|
|
427
|
$config['interfaces']['opt' . ($i+1)]['if'] = $optif[$i];
|
428
|
|
429
|
/* wireless interface? */
|
430
|
if (preg_match($g['wireless_regex'], $optif[$i])) {
|
431
|
if (!is_array($config['interfaces']['opt' . ($i+1)]['wireless'])) {
|
432
|
$config['interfaces']['opt' . ($i+1)]['wireless'] = array();
|
433
|
}
|
434
|
} else {
|
435
|
unset($config['interfaces']['opt' . ($i+1)]['wireless']);
|
436
|
}
|
437
|
|
438
|
if (empty($config['interfaces']['opt' . ($i+1)]['descr'])) {
|
439
|
$config['interfaces']['opt' . ($i+1)]['descr'] = "OPT" . ($i+1);
|
440
|
unset($config['interfaces']['opt' . ($i+1)]['enable']);
|
441
|
}
|
442
|
}
|
443
|
|
444
|
/* remove all other (old) optional interfaces */
|
445
|
for (; isset($config['interfaces']['opt' . ($i+1)]); $i++) {
|
446
|
unset($config['interfaces']['opt' . ($i+1)]);
|
447
|
}
|
448
|
|
449
|
printf(gettext("%sWriting configuration..."), "\n");
|
450
|
write_config("Console assignment of interfaces");
|
451
|
printf(gettext("done.%s"), "\n");
|
452
|
|
453
|
fclose($fp);
|
454
|
|
455
|
if (platform_booting()) {
|
456
|
return;
|
457
|
}
|
458
|
|
459
|
echo gettext("One moment while we reload the settings...");
|
460
|
echo gettext(" done!") . "\n";
|
461
|
|
462
|
touch("{$g['tmp_path']}/assign_complete");
|
463
|
|
464
|
}
|
465
|
}
|
466
|
|
467
|
function autodetect_interface($ifname, $fp) {
|
468
|
$iflist_prev = get_interface_list("media");
|
469
|
echo <<<EOD
|
470
|
|
471
|
Connect the {$ifname} interface now and make sure that the link is up.
|
472
|
Then press ENTER to continue.
|
473
|
|
474
|
EOD;
|
475
|
fgets($fp);
|
476
|
$iflist = get_interface_list("media");
|
477
|
|
478
|
foreach ($iflist_prev as $ifn => $ifa) {
|
479
|
if (!$ifa['up'] && $iflist[$ifn]['up']) {
|
480
|
printf(gettext("Detected link-up on interface %s.%s"), $ifn, "\n");
|
481
|
return $ifn;
|
482
|
}
|
483
|
}
|
484
|
|
485
|
printf(gettext("No link-up detected.%s"), "\n");
|
486
|
|
487
|
return null;
|
488
|
}
|
489
|
|
490
|
function interfaces_setup() {
|
491
|
global $iflist, $config, $g, $fp;
|
492
|
|
493
|
$iflist = get_interface_list();
|
494
|
}
|
495
|
|
496
|
function vlan_setup() {
|
497
|
global $iflist, $config, $g, $fp;
|
498
|
|
499
|
$iflist = get_interface_list();
|
500
|
|
501
|
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
|
502
|
echo "\n" . gettext("WARNING: all existing VLANs will be cleared if you proceed!") . "\n";
|
503
|
echo "\n" . gettext("Do you want to proceed [y|n]?") . " ";
|
504
|
|
505
|
if (strcasecmp(chop(fgets($fp)), "y") != 0) {
|
506
|
return;
|
507
|
}
|
508
|
}
|
509
|
|
510
|
$config['vlans']['vlan'] = array();
|
511
|
echo "\n";
|
512
|
|
513
|
$vlanif = 0;
|
514
|
|
515
|
while (1) {
|
516
|
$vlan = array();
|
517
|
|
518
|
echo "\n\n" . gettext("VLAN Capable interfaces:") . "\n\n";
|
519
|
if (!is_array($iflist)) {
|
520
|
echo gettext("No interfaces found!") . "\n";
|
521
|
} else {
|
522
|
$vlan_capable = 0;
|
523
|
foreach ($iflist as $iface => $ifa) {
|
524
|
if (is_jumbo_capable($iface)) {
|
525
|
echo sprintf("% -8s%s%s\n", $iface, $ifa['mac'],
|
526
|
$ifa['up'] ? " (up)" : "");
|
527
|
$vlan_capable++;
|
528
|
}
|
529
|
}
|
530
|
}
|
531
|
|
532
|
if ($vlan_capable == 0) {
|
533
|
echo gettext("No VLAN capable interfaces detected.") . "\n";
|
534
|
return;
|
535
|
}
|
536
|
|
537
|
echo "\n" . gettext("Enter the parent interface name for the new VLAN (or nothing if finished):") . " ";
|
538
|
$vlan['if'] = chop(fgets($fp));
|
539
|
|
540
|
if ($vlan['if']) {
|
541
|
if (!array_key_exists($vlan['if'], $iflist) or
|
542
|
!is_jumbo_capable($vlan['if'])) {
|
543
|
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $vlan['if'], "\n");
|
544
|
continue;
|
545
|
}
|
546
|
} else {
|
547
|
break;
|
548
|
}
|
549
|
|
550
|
echo gettext("Enter the VLAN tag (1-4094):") . " ";
|
551
|
$vlan['tag'] = chop(fgets($fp));
|
552
|
$vlan['vlanif'] = "{$vlan['if']}_vlan{$vlan['tag']}";
|
553
|
if (!is_numericint($vlan['tag']) || ($vlan['tag'] < 1) || ($vlan['tag'] > 4094)) {
|
554
|
printf(gettext("%sInvalid VLAN tag '%s'%s"), "\n", $vlan['tag'], "\n");
|
555
|
continue;
|
556
|
}
|
557
|
|
558
|
$config['vlans']['vlan'][] = $vlan;
|
559
|
$vlanif++;
|
560
|
}
|
561
|
}
|
562
|
|
563
|
function check_for_alternate_interfaces() {
|
564
|
global $config;
|
565
|
|
566
|
// If the WAN and/or LAN devices in the factory default config do not exist,
|
567
|
// then look for alternate devices.
|
568
|
// This lets many systems boot a factory default config without being
|
569
|
// forced to do interface assignment on the console.
|
570
|
|
571
|
$specplatform = system_identify_specific_platform();
|
572
|
$default_device = array();
|
573
|
|
574
|
// If we recognise the platform, then specify the devices directly.
|
575
|
switch ($specplatform['name']) {
|
576
|
case 'alix':
|
577
|
$default_device['wan'] = "vr1";
|
578
|
$default_device['lan'] = "vr0";
|
579
|
break;
|
580
|
case 'APU':
|
581
|
$default_device['wan'] = "re1";
|
582
|
$default_device['lan'] = "re2";
|
583
|
break;
|
584
|
case 'RCC-VE':
|
585
|
$default_device['wan'] = "igb0";
|
586
|
$default_device['lan'] = "igb1";
|
587
|
break;
|
588
|
default:
|
589
|
$default_device['wan'] = "";
|
590
|
$default_device['lan'] = "";
|
591
|
break;
|
592
|
}
|
593
|
|
594
|
// Other common device names can be put here and will be looked for
|
595
|
// if the system was not one of the known platforms.
|
596
|
$other_devices_arr['wan'] = array("vr1", "re1", "igb0", "em0");
|
597
|
$other_devices_arr['lan'] = array("vr0", "re2", "igb1", "em1");
|
598
|
$interface_assignment_changed = false;
|
599
|
|
600
|
foreach ($other_devices_arr as $ifname => $other_devices) {
|
601
|
if (!does_interface_exist($config['interfaces'][$ifname]['if'])) {
|
602
|
if (does_interface_exist($default_device[$ifname])) {
|
603
|
$config['interfaces'][$ifname]['if'] = $default_device[$ifname];
|
604
|
$interface_assignment_changed = true;
|
605
|
} else {
|
606
|
foreach ($other_devices as $other_device) {
|
607
|
if (does_interface_exist($other_device)) {
|
608
|
$config['interfaces'][$ifname]['if'] = $other_device;
|
609
|
$interface_assignment_changed = true;
|
610
|
break;
|
611
|
}
|
612
|
}
|
613
|
}
|
614
|
}
|
615
|
}
|
616
|
|
617
|
if ($interface_assignment_changed) {
|
618
|
write_config("Factory default boot detected WAN " . $config['interfaces']['wan']['if'] . " and LAN " . $config['interfaces']['lan']['if']);
|
619
|
}
|
620
|
}
|
621
|
|
622
|
?>
|