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