Project

General

Profile

Download (22.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * config.console.inc
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2020 Rubicon Communications, LLC (Netgate)
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
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

    
26
require_once("config.inc");
27
require_once("globals.inc");
28
require_once("interfaces.inc");
29
require_once("util.inc");
30

    
31
/*
32
 * returns:
33
 * -2: error
34
 * -1: no interface found
35
 *  0: interface(s) assigned
36
 *  1: user quit
37
 */
38
function set_networking_interfaces_ports() {
39
	global $noreboot;
40
	global $config;
41
	global $g;
42
	global $fp;
43

    
44
	$fp = fopen('php://stdin', 'r');
45

    
46
	$memory = get_memory();
47
	$physmem = $memory[0];
48
	$realmem = $memory[1];
49

    
50
	if ($physmem < $g['minimum_ram_warning']) {
51
		echo "\n\n\n";
52
		echo gettext("DANGER!  WARNING!  ACHTUNG!") . "\n\n";
53
		printf(gettext('%1$s requires *AT LEAST* %2$s RAM to function correctly.%3$s'), $g['product_name'], $g['minimum_ram_warning_text'], "\n");
54
		printf(gettext('Only (%1$s) MB RAM has been detected, with (%2$s) available to %3$s.%4$s'), $realmem, $physmem, $g['product_name'], "\n");
55
		echo "\n" . gettext("Press ENTER to continue.") . " ";
56
		fgets($fp);
57
		echo "\n";
58
	}
59

    
60
	$iflist = get_interface_list();
61

    
62
	/* Function flow is based on $key or the lack thereof */
63
	$key = null;
64

    
65
	echo <<<EOD
66

    
67
Valid interfaces are:
68

    
69

    
70
EOD;
71

    
72
	if (!is_array($iflist)) {
73
		echo gettext("No interfaces found!") . "\n";
74
		return (-1);
75
	} else {
76
		// ifsmallist is kept with spaces at the beginning and end to assist with str_replace() operations
77
		$ifsmallist = " ";
78
		foreach ($iflist as $iface => $ifa) {
79
			$friendly = convert_real_interface_to_friendly_interface_name($iface);
80
			$ifstatus = pfSense_get_interface_addresses($config['interfaces'][$friendly]['if']);
81
			if (is_array($ifstatus) && $ifstatus['linkstateup'])
82
				$status = "  (up)";
83
			else
84
				$status = "(down)";
85
			$ifsmallist = $ifsmallist . $iface. " ";
86
			echo sprintf("%-7s %s %s %s\n", $iface, $ifa['mac'],
87
				$status, substr($ifa['dmesg'], 0, 46));
88
		}
89
	}
90

    
91
	echo "\n" . gettext("Do VLANs need to be set up first?");
92
	echo "\n" .
93
		gettext(
94
			"If VLANs will not be used, or only for optional interfaces, it is typical to\n" .
95
			"say no here and use the webConfigurator to configure VLANs later, if required.") .
96
		"\n";
97
	echo "\n" . gettext("Should VLANs be set up now [y|n]?") . " ";
98

    
99
	$key = chop(fgets($fp));
100

    
101
	//Manually assign interfaces
102
	if (in_array($key, array('y', 'Y'))) {
103
		vlan_setup();
104
	}
105

    
106
	if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
107

    
108
		echo "\n\n" . gettext("VLAN interfaces:") . "\n\n";
109
		foreach ($config['vlans']['vlan'] as $vlan) {
110

    
111
			echo sprintf("% -16s%s\n", vlan_interface($vlan),
112
				"VLAN tag {$vlan['tag']}, parent interface {$vlan['if']}");
113

    
114
			$iflist[vlan_interface($vlan)] = array();
115
			$ifsmallist = $ifsmallist . vlan_interface($vlan) . " ";
116
		}
117
	}
118

    
119
	echo <<<EOD
120

    
121
If the names of the interfaces are not known, auto-detection can
122
be used instead. To use auto-detection, please disconnect all
123
interfaces before pressing 'a' to begin the process.
124

    
125
EOD;
126

    
127
	do {
128
		echo "\n" . gettext("Enter the WAN interface name or 'a' for auto-detection") . " ";
129
		printf(gettext('%1$s(%2$s or a): '), "\n", trim($ifsmallist));
130
		$wanif = chop(fgets($fp));
131
		if ($wanif === "") {
132
			return (1);
133
		}
134
		if ($wanif === "a") {
135
			$wanif = autodetect_interface("WAN", $fp);
136
		} else if (!array_key_exists($wanif, $iflist)) {
137
			printf(gettext('%1$sInvalid interface name \'%2$s\'%3$s'), "\n", $wanif, "\n");
138
			unset($wanif);
139
			continue;
140
		}
141
		$ifsmallist = str_replace(" " . $wanif . " ", " ", $ifsmallist);
142
	} while (!$wanif);
143

    
144
	do {
145
		printf(gettext('%1$sEnter the LAN interface name or \'a\' for auto-detection %2$s' .
146
			'NOTE: this enables full Firewalling/NAT mode.%3$s' .
147
			'(%4$s a or nothing if finished):%5$s'), "\n", "\n", "\n", trim($ifsmallist), " ");
148

    
149
		$lanif = chop(fgets($fp));
150

    
151
		if ($lanif == "exit") {
152
			exit;
153
		}
154

    
155
		if ($lanif == "") {
156
			/* It is OK to have just a WAN, without a LAN so break if the user does not want LAN. */
157
			break;
158
		}
159

    
160
		if ($lanif === "a") {
161
			$lanif = autodetect_interface("LAN", $fp);
162
		} else if (!array_key_exists($lanif, $iflist)) {
163
			printf(gettext('%1$sInvalid interface name \'%2$s\'%3$s'), "\n", $lanif, "\n");
164
			unset($lanif);
165
			continue;
166
		}
167
		$ifsmallist = str_replace(" " . $lanif . " ", " ", $ifsmallist);
168
	} while (!$lanif);
169

    
170
	/* optional interfaces */
171
	$i = 0;
172
	$optif = array();
173

    
174
	if ($lanif <> "") {
175
		while (strlen(trim($ifsmallist)) > 0) {
176
			if (!empty($optif[$i])) {
177
				$i++;
178
			}
179
			$io = $i + 1;
180

    
181
			if ($config['interfaces']['opt' . $io]['descr']) {
182
				printf(gettext('%1$sOptional interface %2$s description found: %3$s'), "\n", $io, $config['interfaces']['opt' . $io]['descr']);
183
			}
184

    
185
			printf(gettext('%1$sEnter the Optional %2$s interface name or \'a\' for auto-detection%3$s' .
186
				'(%4$s a or nothing if finished):%5$s'), "\n", $io, "\n", trim($ifsmallist), " ");
187

    
188
			$optif[$i] = chop(fgets($fp));
189

    
190
			if ($optif[$i]) {
191
				if ($optif[$i] === "a") {
192
					$ad = autodetect_interface(gettext("Optional") . " " . $io, $fp);
193
					if ($ad) {
194
						$optif[$i] = $ad;
195
					} else {
196
						unset($optif[$i]);
197
					}
198
				} else if (!array_key_exists($optif[$i], $iflist)) {
199
					printf(gettext('%1$sInvalid interface name \'%2$s\'%3$s'), "\n", $optif[$i], "\n");
200
					unset($optif[$i]);
201
					continue;
202
				}
203
				$ifsmallist = str_replace(" " . $optif[$i] . " ", " ", $ifsmallist);
204
			} else {
205
				unset($optif[$i]);
206
				break;
207
			}
208
		}
209
	}
210

    
211
	/* check for double assignments */
212
	$ifarr = array_merge(array($lanif, $wanif), $optif);
213

    
214
	for ($i = 0; $i < (count($ifarr)-1); $i++) {
215
		for ($j = ($i+1); $j < count($ifarr); $j++) {
216
			if ($ifarr[$i] == $ifarr[$j]) {
217
				echo <<<EOD
218

    
219
Error: The same interface name cannot be assigned twice!
220

    
221
EOD;
222
				fclose($fp);
223
				return (-2);
224
			}
225
		}
226
	}
227

    
228
	echo "\n" . gettext("The interfaces will be assigned as follows:") . "\n\n";
229

    
230
	echo "WAN  -> " . $wanif . "\n";
231
	if ($lanif != "") {
232
		echo "LAN  -> " . $lanif . "\n";
233
	}
234
	for ($i = 0; $i < count($optif); $i++) {
235
		echo "OPT" . ($i+1) . " -> " . $optif[$i] . "\n";
236
	}
237

    
238
	echo "\n" . gettext("Do you want to proceed [y|n]?") . " ";
239
	$key = chop(fgets($fp));
240

    
241
	if (in_array($key, array('y', 'Y'))) {
242
		if ($lanif) {
243
			if (is_array($config['interfaces']['lan'])) {
244
				$upints = pfSense_interface_listget(IFF_UP);
245
				if (in_array($config['interfaces']['lan']['if'], $upints))
246
					interface_bring_down('lan', true);
247
			}
248
			if (!is_array($config['interfaces']['lan'])) {
249
				$config['interfaces']['lan'] = array();
250
			}
251
			$config['interfaces']['lan']['if'] = $lanif;
252
			$config['interfaces']['lan']['enable'] = true;
253
		} elseif (!platform_booting()) {
254

    
255
			echo "\n" . gettext("You have chosen to remove the LAN interface.") . "\n";
256
			echo "\n" . gettext("Would you like to remove the LAN IP address and \nunload the interface now [y|n]?") . " ";
257

    
258
			if (strcasecmp(chop(fgets($fp)), "y") == 0) {
259
				if (isset($config['interfaces']['lan']) && $config['interfaces']['lan']['if']) {
260
					mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
261
				}
262
			}
263
			if (isset($config['interfaces']['lan'])) {
264
				unset($config['interfaces']['lan']);
265
			}
266
			if (isset($config['dhcpd']['lan'])) {
267
				unset($config['dhcpd']['lan']);
268
			}
269
			if (isset($config['dhcpdv6']['lan'])) {
270
				unset($config['dhcpdv6']['lan']);
271
			}
272
			if (isset($config['interfaces']['lan']['if'])) {
273
				unset($config['interfaces']['lan']['if']);
274
			}
275
			if (isset($config['interfaces']['wan']['blockpriv'])) {
276
				unset($config['interfaces']['wan']['blockpriv']);
277
			}
278
			if (isset($config['shaper'])) {
279
				unset($config['shaper']);
280
			}
281
			if (isset($config['ezshaper'])) {
282
				unset($config['ezshaper']);
283
			}
284
			if (isset($config['nat'])) {
285
				unset($config['nat']);
286
			}
287
		} else {
288
			if (isset($config['interfaces']['lan']['if'])) {
289
				mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
290
			}
291
			if (isset($config['interfaces']['lan'])) {
292
				unset($config['interfaces']['lan']);
293
			}
294
			if (isset($config['dhcpd']['lan'])) {
295
				unset($config['dhcpd']['lan']);
296
			}
297
			if (isset($config['dhcpdv6']['lan'])) {
298
				unset($config['dhcpdv6']['lan']);
299
			}
300
			if (isset($config['interfaces']['lan']['if'])) {
301
				unset($config['interfaces']['lan']['if']);
302
			}
303
			if (isset($config['interfaces']['wan']['blockpriv'])) {
304
				unset($config['interfaces']['wan']['blockpriv']);
305
			}
306
			if (isset($config['shaper'])) {
307
				unset($config['shaper']);
308
			}
309
			if (isset($config['ezshaper'])) {
310
				unset($config['ezshaper']);
311
			}
312
			if (isset($config['nat'])) {
313
				unset($config['nat']);
314
			}
315
		}
316
		if (preg_match($g['wireless_regex'], $lanif)) {
317
			if (is_array($config['interfaces']['lan']) &&
318
			    !is_array($config['interfaces']['lan']['wireless'])) {
319
				$config['interfaces']['lan']['wireless'] = array();
320
			}
321
		} else {
322
			if (isset($config['interfaces']['lan'])) {
323
				unset($config['interfaces']['lan']['wireless']);
324
			}
325
		}
326

    
327
		if (is_array($config['interfaces']['wan'])) {
328
			$upints = pfSense_interface_listget(IFF_UP);
329
			if (in_array($config['interfaces']['wan']['if'], $upints))
330
				interface_bring_down('wan', true);
331
		}
332
		if (!is_array($config['interfaces']['wan'])) {
333
			$config['interfaces']['wan'] = array();
334
		}
335
		$config['interfaces']['wan']['if'] = $wanif;
336
		$config['interfaces']['wan']['enable'] = true;
337
		if (preg_match($g['wireless_regex'], $wanif)) {
338
			if (is_array($config['interfaces']['wan']) &&
339
			    !is_array($config['interfaces']['wan']['wireless'])) {
340
				$config['interfaces']['wan']['wireless'] = array();
341
			}
342
		} else {
343
			if (isset($config['interfaces']['wan'])) {
344
				unset($config['interfaces']['wan']['wireless']);
345
			}
346
		}
347

    
348
		for ($i = 0; $i < count($optif); $i++) {
349
			if (is_array($config['interfaces']['opt' . ($i+1)])) {
350
				$upints = pfSense_interface_listget(IFF_UP);
351
				if (in_array($config['interfaces']['opt' . ($i+1)]['if'], $upints))
352
					interface_bring_down('opt' . ($i+1), true);
353
			}
354
			if (!is_array($config['interfaces']['opt' . ($i+1)])) {
355
				$config['interfaces']['opt' . ($i+1)] = array();
356
			}
357

    
358
			$config['interfaces']['opt' . ($i+1)]['if'] = $optif[$i];
359

    
360
			/* wireless interface? */
361
			if (preg_match($g['wireless_regex'], $optif[$i])) {
362
				if (!is_array($config['interfaces']['opt' . ($i+1)]['wireless'])) {
363
					$config['interfaces']['opt' . ($i+1)]['wireless'] = array();
364
				}
365
			} else {
366
				unset($config['interfaces']['opt' . ($i+1)]['wireless']);
367
			}
368

    
369
			if (empty($config['interfaces']['opt' . ($i+1)]['descr'])) {
370
				$config['interfaces']['opt' . ($i+1)]['descr'] = "OPT" . ($i+1);
371
				unset($config['interfaces']['opt' . ($i+1)]['enable']);
372
			}
373
		}
374

    
375
		/* remove all other (old) optional interfaces */
376
		for (; isset($config['interfaces']['opt' . ($i+1)]); $i++) {
377
			unset($config['interfaces']['opt' . ($i+1)]);
378
		}
379

    
380
		printf(gettext("%sWriting configuration..."), "\n");
381
		write_config(gettext("Console assignment of interfaces"));
382
		printf(gettext("done.%s"), "\n");
383

    
384
		fclose($fp);
385

    
386
		echo gettext("One moment while the settings are reloading...");
387
		touch("{$g['tmp_path']}/assign_complete");
388

    
389
		if (file_exists("{$g['conf_path']}/trigger_initial_wizard")) {
390
			// Let the system know that the interface assign part of initial setup has been done.
391
			touch("{$g['conf_path']}/assign_complete");
392
		}
393

    
394
		echo gettext(" done!") . "\n";
395

    
396
		return (0);
397
	}
398
}
399

    
400
function autodetect_interface($ifname, $fp) {
401
	$iflist_prev = get_interface_list("media");
402
	echo <<<EOD
403

    
404
Connect the {$ifname} interface now and make sure that the link is up.
405
Then press ENTER to continue.
406

    
407
EOD;
408
	fgets($fp);
409
	$iflist = get_interface_list("media");
410

    
411
	foreach ($iflist_prev as $ifn => $ifa) {
412
		if (!$ifa['up'] && $iflist[$ifn]['up']) {
413
			printf(gettext('Detected link-up on interface %1$s.%2$s'), $ifn, "\n");
414
			return $ifn;
415
		}
416
	}
417

    
418
	printf(gettext("No link-up detected.%s"), "\n");
419

    
420
	return null;
421
}
422

    
423
function interfaces_setup() {
424
	global $iflist, $config, $g, $fp;
425

    
426
	$iflist = get_interface_list();
427
}
428

    
429
function vlan_setup() {
430
	global $iflist, $config, $g, $fp;
431

    
432
	$iflist = get_interface_list();
433

    
434
	if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
435
		echo "\n" . gettext("WARNING: all existing VLANs will be cleared if you proceed!") . "\n";
436
		echo "\n" . gettext("Do you want to proceed [y|n]?") . " ";
437

    
438
		if (strcasecmp(chop(fgets($fp)), "y") != 0) {
439
			return;
440
		}
441
	}
442

    
443
	init_config_arr(array('vlans', 'vlan'));
444
	echo "\n";
445

    
446
	$vlanif = 0;
447

    
448
	while (1) {
449
		$vlan = array();
450

    
451
		echo "\n\n" . gettext("VLAN Capable interfaces:") . "\n\n";
452
		if (!is_array($iflist)) {
453
			echo gettext("No interfaces found!") . "\n";
454
		} else {
455
			$vlan_capable = 0;
456
			foreach ($iflist as $iface => $ifa) {
457
				if (is_jumbo_capable($iface)) {
458
					echo sprintf("% -8s%s%s\n", $iface, $ifa['mac'],
459
						$ifa['up'] ? "   (up)" : "");
460
					$vlan_capable++;
461
				}
462
			}
463
		}
464

    
465
		if ($vlan_capable == 0) {
466
			echo gettext("No VLAN capable interfaces detected.") . "\n";
467
			return;
468
		}
469

    
470
		echo "\n" . gettext("Enter the parent interface name for the new VLAN (or nothing if finished):") . " ";
471
		$vlan['if'] = chop(fgets($fp));
472

    
473
		if ($vlan['if']) {
474
			if (!array_key_exists($vlan['if'], $iflist) ||
475
			    !is_jumbo_capable($vlan['if'])) {
476
				printf(gettext('%1$sInvalid interface name \'%2$s\'%3$s'), "\n", $vlan['if'], "\n");
477
				continue;
478
			}
479
		} else {
480
			break;
481
		}
482

    
483
		echo gettext("Enter the VLAN tag (1-4094):") . " ";
484
		$vlan['tag'] = chop(fgets($fp));
485
		$vlan['vlanif'] = vlan_interface($vlan);
486
		if (!is_numericint($vlan['tag']) || ($vlan['tag'] < 1) || ($vlan['tag'] > 4094)) {
487
			printf(gettext('%1$sInvalid VLAN tag \'%2$s\'%3$s'), "\n", $vlan['tag'], "\n");
488
			continue;
489
		}
490

    
491
		if (is_array($config['vlans']['vlan'])) {
492
			foreach ($config['vlans']['vlan'] as $existingvlan) {
493
				if ($vlan['if'] == $existingvlan['if'] && $vlan['tag'] == $existingvlan['tag']) {
494
					printf("\n\n" . gettext("This parent interface and VLAN already created."));
495
					continue 2;
496
				}
497
			}
498
		}
499
		$config['vlans']['vlan'][] = $vlan;
500
		$vlanif++;
501
	}
502
}
503

    
504
function check_for_alternate_interfaces() {
505
	global $config;
506

    
507
	// If the WAN and/or LAN devices in the factory default config do not exist,
508
	// then look for alternate devices.
509
	// This lets many systems boot a factory default config without being
510
	// forced to do interface assignment on the console.
511

    
512
	$specplatform = system_identify_specific_platform();
513
	$default_device = array();
514

    
515
	// If we recognise the platform, then specify the devices directly.
516
	switch ($specplatform['name']) {
517
		case 'alix':
518
			$default_device['wan'] = "vr1";
519
			$default_device['lan'] = "vr0";
520
			break;
521
		case 'APU':
522
			$default_device['wan'] = "re1";
523
			$default_device['lan'] = "re2";
524
			break;
525
		case 'Turbot Dual-E':
526
			$config['interfaces']['wan']['if'] = 'igb0';
527
			$config['interfaces']['lan']['if'] = 'igb1';
528
			break;
529
		case 'C2758':
530
			$config['interfaces']['wan']['if'] = 'igb0';
531
			$config['interfaces']['lan']['if'] = 'igb1';
532
			$config['interfaces']['opt1'] = array(
533
				'if' => 'igb2',
534
				'descr' => 'OPT1'
535
			);
536
			$config['interfaces']['opt2'] = array(
537
				'if' => 'igb3',
538
				'descr' => 'OPT2'
539
			);
540
			break;
541
		case 'RCC-VE':
542
		case 'SG-2220':
543
			/* SG-4860 or SG-8860 */
544
			if (does_interface_exist('igb4')) {
545
				$config['interfaces']['wan']['if'] = 'igb1';
546
				$config['interfaces']['lan']['if'] = 'igb0';
547
			} else {
548
				$config['interfaces']['wan']['if'] = 'igb0';
549
				$config['interfaces']['lan']['if'] = 'igb1';
550
			}
551
			/* It has 4 ports */
552
			if (does_interface_exist('igb3')) {
553
				$config['interfaces']['opt1'] = array(
554
					'if' => 'igb2',
555
					'descr' => 'OPT1'
556
				);
557
				$config['interfaces']['opt2'] = array(
558
					'if' => 'igb3',
559
					'descr' => 'OPT2'
560
				);
561
			}
562
			/* It has 6 ports */
563
			if (does_interface_exist('igb5')) {
564
				$config['interfaces']['opt3'] = array(
565
					'if' => 'igb4',
566
					'descr' => 'OPT3'
567
				);
568
				$config['interfaces']['opt4'] = array(
569
					'if' => 'igb5',
570
					'descr' => 'OPT4'
571
				);
572
			}
573
			break;
574
		case 'XG-1537':
575
			if (does_interface_exist('cxl0')) {
576
				/* It has 10G SFP+ addon */
577
				$config['interfaces']['wan']['if'] = 'cxl0';
578
				$config['interfaces']['lan']['if'] = 'cxl1';
579
				$config['interfaces']['opt1'] = array(
580
					'if' => 'igb0',
581
					'descr' => 'OPT1'
582
				);
583
				$config['interfaces']['opt2'] = array(
584
					'enable' => true,
585
					'if' => 'ix0',
586
					'descr' => 'OPT2'
587
				);
588
				$config['interfaces']['opt3'] = array(
589
					'if' => 'igb1',
590
					'descr' => 'OPT3'
591
				);
592
				$config['interfaces']['opt4'] = array(
593
					'enable' => true,
594
					'if' => 'ix1',
595
					'descr' => 'OPT4'
596
				);
597
			} elseif (does_interface_exist('igb4')) {
598
				/* It has 4 port ethernet addon */
599
				$config['interfaces']['wan']['if'] = 'igb4';
600
				$config['interfaces']['lan']['if'] = 'igb5';
601
				$config['interfaces']['opt1'] = array(
602
					'enable' => true,
603
					'if' => 'ix0',
604
					'descr' => 'OPT1'
605
				);
606
				$config['interfaces']['opt2'] = array(
607
					'enable' => true,
608
					'if' => 'ix1',
609
					'descr' => 'OPT2'
610
				);
611
				$config['interfaces']['opt3'] = array(
612
					'if' => 'igb3',
613
					'descr' => 'OPT3'
614
				);
615
				$config['interfaces']['opt4'] = array(
616
					'if' => 'igb2',
617
					'descr' => 'OPT4'
618
				);
619
				$config['interfaces']['opt5'] = array(
620
					'if' => 'igb1',
621
					'descr' => 'OPT5'
622
				);
623
				$config['interfaces']['opt6'] = array(
624
					'if' => 'igb0',
625
					'descr' => 'OPT6'
626
				);
627
			} else {
628
				$config['interfaces']['wan']['if'] = 'igb0';
629
				$config['interfaces']['lan']['if'] = 'igb1';
630
				$config['interfaces']['opt1'] = array(
631
					'enable' => true,
632
					'if' => 'ix0',
633
					'descr' => 'OPT1'
634
				);
635
				$config['interfaces']['opt2'] = array(
636
					'enable' => true,
637
					'if' => 'ix1',
638
					'descr' => 'OPT2'
639
				);
640
			}
641
			break;
642
		case 'XG-1540':
643
		case 'XG-1541':
644
			if (does_interface_exist('igb2')) {
645
				/* It has 4 port Intel 1Gb expansion card */
646
				$config['interfaces']['wan']['if'] = 'igb4';
647
				$config['interfaces']['lan']['if'] = 'igb5';
648
				$config['interfaces']['opt1'] = array(
649
					'enable' => true,
650
					'if' => 'ix0',
651
					'descr' => 'OPT1'
652
				);
653
				$config['interfaces']['opt2'] = array(
654
					'enable' => true,
655
					'if' => 'ix1',
656
					'descr' => 'OPT2'
657
				);
658
				$config['interfaces']['opt3'] = array(
659
					'if' => 'igb3',
660
					'descr' => 'OPT3'
661
				);
662
				$config['interfaces']['opt4'] = array(
663
					'if' => 'igb2',
664
					'descr' => 'OPT4'
665
				);
666
				$config['interfaces']['opt5'] = array(
667
					'if' => 'igb1',
668
					'descr' => 'OPT5'
669
				);
670
				$config['interfaces']['opt6'] = array(
671
					'if' => 'igb0',
672
					'descr' => 'OPT6'
673
				);
674
			} elseif (does_interface_exist('cxl0')) {
675
				/* It has 2 port Chelsio 10Gb expansion card */
676
				$config['interfaces']['wan']['if'] = 'cxl0';
677
				$config['interfaces']['lan']['if'] = 'cxl1';
678
				$config['interfaces']['opt1'] = array(
679
					'if' => 'igb0',
680
					'descr' => 'OPT1'
681
				);
682
				$config['interfaces']['opt2'] = array(
683
					'enable' => true,
684
					'if' => 'ix0',
685
					'descr' => 'OPT2'
686
				);
687
				$config['interfaces']['opt3'] = array(
688
					'if' => 'igb1',
689
					'descr' => 'OPT3'
690
				);
691
				$config['interfaces']['opt4'] = array(
692
					'enable' => true,
693
					'if' => 'ix1',
694
					'descr' => 'OPT4'
695
				);
696
			} else {
697
				$config['interfaces']['wan']['if'] = 'ix0';
698
				$config['interfaces']['lan']['if'] = 'ix1';
699
				$config['interfaces']['opt1'] = array(
700
					'if' => 'igb0',
701
					'descr' => 'OPT1'
702
				);
703
				$config['interfaces']['opt2'] = array(
704
					'if' => 'igb1',
705
					'descr' => 'OPT2'
706
				);
707
			}
708
			break;
709
		case 'RCC':
710
			if (does_interface_exist('igb7')) {
711
				// has quad port expansion card
712
				$config['interfaces']['opt5'] = array(
713
					'if' => 'igb0',
714
					'descr' => 'OPT5'
715
				);
716
				$config['interfaces']['opt6'] = array(
717
					'if' => 'igb1',
718
					'descr' => 'OPT6'
719
				);
720
				$config['interfaces']['opt7'] = array(
721
					'if' => 'igb2',
722
					'descr' => 'OPT7'
723
				);
724
				$config['interfaces']['opt8'] = array(
725
					'if' => 'igb3',
726
					'descr' => 'OPT8'
727
				);
728
				$config['interfaces']['wan']['if'] = 'igb4';
729
				$config['interfaces']['lan']['if'] = 'igb6';
730
				$config['interfaces']['opt1'] = array(
731
					'if' => 'igb5',
732
					'descr' => 'OPT1'
733
				);
734
				$config['interfaces']['opt2'] = array(
735
					'if' => 'igb7',
736
					'descr' => 'OPT2'
737
				);
738
			} else {
739
				$config['interfaces']['wan']['if'] = 'igb0';
740
				$config['interfaces']['lan']['if'] = 'igb2';
741
				$config['interfaces']['opt1'] = array(
742
					'if' => 'igb1',
743
					'descr' => 'OPT1'
744
				);
745
				$config['interfaces']['opt2'] = array(
746
					'if' => 'igb3',
747
					'descr' => 'OPT2'
748
				);
749
			}
750
			$config['interfaces']['opt3'] = array(
751
				'enable' => true,
752
				'if' => 'ix0',
753
				'descr' => 'OPT3'
754
			);
755
			$config['interfaces']['opt4'] = array(
756
				'enable' => true,
757
				'if' => 'ix1',
758
				'descr' => 'OPT4'
759
			);
760
			break;
761
		case 'SG-5100':
762
			$config['interfaces']['wan']['if'] = 'igb0';
763
			$config['interfaces']['lan']['if'] = 'igb1';
764
			$config['interfaces']['opt1'] = array(
765
				'enable' => true,
766
				'if' => 'ix0',
767
				'descr' => 'OPT1'
768
			);
769
			$config['interfaces']['opt2'] = array(
770
				'enable' => true,
771
				'if' => 'ix1',
772
				'descr' => 'OPT2'
773
			);
774
			$config['interfaces']['opt3'] = array(
775
				'enable' => true,
776
				'if' => 'ix2',
777
				'descr' => 'OPT3'
778
			);
779
			$config['interfaces']['opt4'] = array(
780
				'enable' => true,
781
				'if' => 'ix3',
782
				'descr' => 'OPT4'
783
			);
784
		default:
785
			$default_device['wan'] = "";
786
			$default_device['lan'] = "";
787
			break;
788
	}
789

    
790
	// Other common device names can be put here and will be looked for
791
	// if the system was not one of the known platforms.
792
	$other_devices_arr['wan'] = array("vr1", "re1", "igb0", "em0");
793
	$other_devices_arr['lan'] = array("vr0", "re2", "igb1", "em1");
794
	$interface_assignment_changed = false;
795

    
796
	foreach ($other_devices_arr as $ifname => $other_devices) {
797
		if (!does_interface_exist($config['interfaces'][$ifname]['if'])) {
798
			if (does_interface_exist($default_device[$ifname])) {
799
				$config['interfaces'][$ifname]['if'] = $default_device[$ifname];
800
				$interface_assignment_changed = true;
801
			} else {
802
				foreach ($other_devices as $other_device) {
803
					if (does_interface_exist($other_device)) {
804
						$config['interfaces'][$ifname]['if'] = $other_device;
805
						$interface_assignment_changed = true;
806
						break;
807
					}
808
				}
809
			}
810
		}
811
	}
812

    
813
	if ($interface_assignment_changed) {
814
		write_config("Factory default boot detected WAN " . $config['interfaces']['wan']['if'] . " and LAN " . $config['interfaces']['lan']['if']);
815
	}
816
}
817

    
818
?>
(8-8/60)