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