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-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally part of m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
require_once("config.inc");
29
require_once("globals.inc");
30
require_once("interfaces.inc");
31
require_once("util.inc");
32

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

    
46
	$fp = fopen('php://stdin', 'r');
47

    
48
	$memory = get_memory();
49
	$physmem = $memory[0];
50
	$realmem = $memory[1];
51

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

    
62
	$iflist = get_interface_list('active', 'physical', true);
63

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

    
67
	echo <<<EOD
68

    
69
Valid interfaces are:
70

    
71

    
72
EOD;
73

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

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

    
101
	$key = chop(fgets($fp));
102

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

    
108
	if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
109

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

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

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

    
121
	echo <<<EOD
122

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

    
127
EOD;
128

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

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

    
151
		$lanif = chop(fgets($fp));
152

    
153
		if ($lanif == "exit") {
154
			exit;
155
		}
156

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

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

    
172
	/* optional interfaces */
173
	$i = 0;
174
	$optif = array();
175

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

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

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

    
190
			$optif[$i] = chop(fgets($fp));
191

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

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

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

    
221
Error: The same interface name cannot be assigned twice!
222

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
386
		fclose($fp);
387

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

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

    
396
		echo gettext(" done!") . "\n";
397

    
398
		return (0);
399
	}
400
}
401

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

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

    
409
EOD;
410
	fgets($fp);
411
	$iflist = get_interface_list("media");
412

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

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

    
422
	return null;
423
}
424

    
425
function interfaces_setup() {
426
	global $iflist, $config, $g, $fp;
427

    
428
	$iflist = get_interface_list();
429
}
430

    
431
function vlan_setup() {
432
	global $iflist, $config, $g, $fp;
433

    
434
	$iflist = get_interface_list();
435

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

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

    
445
	init_config_arr(array('vlans', 'vlan'));
446
	echo "\n";
447

    
448
	$vlanif = 0;
449

    
450
	while (1) {
451
		$vlan = array();
452

    
453
		echo "\n\n" . gettext("VLAN Capable interfaces:") . "\n\n";
454
		if (!is_array($iflist)) {
455
			echo gettext("No interfaces found!") . "\n";
456
		} else {
457
			$vlan_capable = 0;
458
			foreach ($iflist as $iface => $ifa) {
459
				echo sprintf("% -8s%s%s\n", $iface, $ifa['mac'],
460
				    $ifa['up'] ? "   (up)" : "");
461
				$vlan_capable++;
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
				printf(gettext(
476
				    '%1$sInvalid interface name \'%2$s\'%3$s'),
477
				    "\n", $vlan['if'], "\n");
478
				continue;
479
			}
480
		} else {
481
			break;
482
		}
483

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

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

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

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

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

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

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

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

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

    
819
?>
(8-8/61)