Project

General

Profile

Download (16.5 KB) Statistics
| Branch: | Tag: | Revision:
1 5b74202b Scott Ullrich
<?php
2 09221bc3 Renato Botelho
/*
3 ac24dc24 Renato Botelho
 * config.console.inc
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 b8f91b7c Luiz Souza
 * Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
7 ac24dc24 Renato Botelho
 * All rights reserved.
8
 *
9
 * originally part of m0n0wall (http://m0n0.ch/wall)
10 c5d81585 Renato Botelho
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11 ac24dc24 Renato Botelho
 * All rights reserved.
12
 *
13 b12ea3fb Renato Botelho
 * 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 ac24dc24 Renato Botelho
 *
17 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
18 ac24dc24 Renato Botelho
 *
19 b12ea3fb Renato Botelho
 * 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 ac24dc24 Renato Botelho
 */
25 5b74202b Scott Ullrich
26 5eab8157 doktornotor
require_once("config.inc");
27
require_once("globals.inc");
28
require_once("interfaces.inc");
29
require_once("util.inc");
30
31 87d2f8cd Luiz Souza
/*
32
 * returns:
33
 * -2: error
34
 * -1: no interface found
35
 *  0: interface(s) assigned
36
 *  1: user quit
37
 */
38 5b74202b Scott Ullrich
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 493360f5 Phil Davis
	$physmem = $memory[0];
48
	$realmem = $memory[1];
49 5b74202b Scott Ullrich
50 1e0b1727 Phil Davis
	if ($physmem < $g['minimum_ram_warning']) {
51 5b74202b Scott Ullrich
		echo "\n\n\n";
52 814f9e64 Carlos Eduardo Ramos
		echo gettext("DANGER!  WARNING!  ACHTUNG!") . "\n\n";
53 1579e70f Phil Davis
		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 814f9e64 Carlos Eduardo Ramos
		echo "\n" . gettext("Press ENTER to continue.") . " ";
56 5b74202b Scott Ullrich
		fgets($fp);
57
		echo "\n";
58
	}
59
60
	$iflist = get_interface_list();
61
62 60f164f3 Renato Botelho
	/* Function flow is based on $key or the lack thereof */
63 5b74202b Scott Ullrich
	$key = null;
64
65
	echo <<<EOD
66
67
Valid interfaces are:
68
69
70
EOD;
71
72 1e0b1727 Phil Davis
	if (!is_array($iflist)) {
73 814f9e64 Carlos Eduardo Ramos
		echo gettext("No interfaces found!") . "\n";
74 78347c9b Luiz Souza
		return (-1);
75 5b74202b Scott Ullrich
	} else {
76 fd020a2d Phil Davis
		// ifsmallist is kept with spaces at the beginning and end to assist with str_replace() operations
77
		$ifsmallist = " ";
78 5b74202b Scott Ullrich
		foreach ($iflist as $iface => $ifa) {
79 16feb55d Luiz Otavio O Souza
			$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 fd020a2d Phil Davis
			$ifsmallist = $ifsmallist . $iface. " ";
86 a5c7f533 Luiz Souza
			echo sprintf("%-7s %s %s %s\n", $iface, $ifa['mac'],
87 b54a3743 nagyrobi
				$status, substr($ifa['dmesg'], 0, 46));
88 5b74202b Scott Ullrich
		}
89
	}
90
91 530e4707 NOYB
	echo "\n" . gettext("Do VLANs need to be set up first?");
92 0b3799f1 Phil Davis
	echo "\n" .
93
		gettext(
94 530e4707 NOYB
			"If VLANs will not be used, or only for optional interfaces, it is typical to\n" .
95 0b3799f1 Phil Davis
			"say no here and use the webConfigurator to configure VLANs later, if required.") .
96
		"\n";
97 34ee6639 NOYB
	echo "\n" . gettext("Should VLANs be set up now [y|n]?") . " ";
98 5b74202b Scott Ullrich
99 60f164f3 Renato Botelho
	$key = chop(fgets($fp));
100 5b74202b Scott Ullrich
101 60f164f3 Renato Botelho
	//Manually assign interfaces
102
	if (in_array($key, array('y', 'Y'))) {
103
		vlan_setup();
104
	}
105 5b74202b Scott Ullrich
106 60f164f3 Renato Botelho
	if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
107 5b74202b Scott Ullrich
108 60f164f3 Renato Botelho
		echo "\n\n" . gettext("VLAN interfaces:") . "\n\n";
109
		foreach ($config['vlans']['vlan'] as $vlan) {
110 5b74202b Scott Ullrich
111 12bcf7e9 Luiz Souza
			echo sprintf("% -16s%s\n", vlan_interface($vlan),
112 60f164f3 Renato Botelho
				"VLAN tag {$vlan['tag']}, parent interface {$vlan['if']}");
113 5b74202b Scott Ullrich
114 12bcf7e9 Luiz Souza
			$iflist[vlan_interface($vlan)] = array();
115
			$ifsmallist = $ifsmallist . vlan_interface($vlan) . " ";
116 60f164f3 Renato Botelho
		}
117
	}
118 5b74202b Scott Ullrich
119 60f164f3 Renato Botelho
	echo <<<EOD
120 5b74202b Scott Ullrich
121 60f164f3 Renato Botelho
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 5b74202b Scott Ullrich
125
EOD;
126
127 60f164f3 Renato Botelho
	do {
128
		echo "\n" . gettext("Enter the WAN interface name or 'a' for auto-detection") . " ";
129 1579e70f Phil Davis
		printf(gettext('%1$s(%2$s or a): '), "\n", trim($ifsmallist));
130 60f164f3 Renato Botelho
		$wanif = chop(fgets($fp));
131
		if ($wanif === "") {
132 87d2f8cd Luiz Souza
			return (1);
133 1e0b1727 Phil Davis
		}
134 60f164f3 Renato Botelho
		if ($wanif === "a") {
135
			$wanif = autodetect_interface("WAN", $fp);
136
		} else if (!array_key_exists($wanif, $iflist)) {
137 1579e70f Phil Davis
			printf(gettext('%1$sInvalid interface name \'%2$s\'%3$s'), "\n", $wanif, "\n");
138 60f164f3 Renato Botelho
			unset($wanif);
139
			continue;
140
		}
141
		$ifsmallist = str_replace(" " . $wanif . " ", " ", $ifsmallist);
142
	} while (!$wanif);
143 1e0b1727 Phil Davis
144 60f164f3 Renato Botelho
	do {
145 1579e70f Phil Davis
		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 1e0b1727 Phil Davis
149 60f164f3 Renato Botelho
		$lanif = chop(fgets($fp));
150 1e0b1727 Phil Davis
151 60f164f3 Renato Botelho
		if ($lanif == "exit") {
152
			exit;
153 5b74202b Scott Ullrich
		}
154 1e0b1727 Phil Davis
155 60f164f3 Renato Botelho
		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 1e0b1727 Phil Davis
160 60f164f3 Renato Botelho
		if ($lanif === "a") {
161
			$lanif = autodetect_interface("LAN", $fp);
162
		} else if (!array_key_exists($lanif, $iflist)) {
163 1579e70f Phil Davis
			printf(gettext('%1$sInvalid interface name \'%2$s\'%3$s'), "\n", $lanif, "\n");
164 60f164f3 Renato Botelho
			unset($lanif);
165
			continue;
166
		}
167
		$ifsmallist = str_replace(" " . $lanif . " ", " ", $ifsmallist);
168
	} while (!$lanif);
169 1e0b1727 Phil Davis
170 60f164f3 Renato Botelho
	/* optional interfaces */
171
	$i = 0;
172
	$optif = array();
173 1e0b1727 Phil Davis
174 60f164f3 Renato Botelho
	if ($lanif <> "") {
175 d326425e Luiz Souza
		while (strlen(trim($ifsmallist)) > 0) {
176
			if (!empty($optif[$i])) {
177 60f164f3 Renato Botelho
				$i++;
178 5b74202b Scott Ullrich
			}
179 60f164f3 Renato Botelho
			$io = $i + 1;
180 1e0b1727 Phil Davis
181 60f164f3 Renato Botelho
			if ($config['interfaces']['opt' . $io]['descr']) {
182 1579e70f Phil Davis
				printf(gettext('%1$sOptional interface %2$s description found: %3$s'), "\n", $io, $config['interfaces']['opt' . $io]['descr']);
183 5b74202b Scott Ullrich
			}
184 1e0b1727 Phil Davis
185 1579e70f Phil Davis
			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 1e0b1727 Phil Davis
188 60f164f3 Renato Botelho
			$optif[$i] = chop(fgets($fp));
189 1e0b1727 Phil Davis
190 60f164f3 Renato Botelho
			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 5b74202b Scott Ullrich
						unset($optif[$i]);
197
					}
198 60f164f3 Renato Botelho
				} else if (!array_key_exists($optif[$i], $iflist)) {
199 1579e70f Phil Davis
					printf(gettext('%1$sInvalid interface name \'%2$s\'%3$s'), "\n", $optif[$i], "\n");
200 5b74202b Scott Ullrich
					unset($optif[$i]);
201 60f164f3 Renato Botelho
					continue;
202 5b74202b Scott Ullrich
				}
203 60f164f3 Renato Botelho
				$ifsmallist = str_replace(" " . $optif[$i] . " ", " ", $ifsmallist);
204
			} else {
205
				unset($optif[$i]);
206
				break;
207 5b74202b Scott Ullrich
			}
208
		}
209 60f164f3 Renato Botelho
	}
210 1e0b1727 Phil Davis
211 60f164f3 Renato Botelho
	/* check for double assignments */
212
	$ifarr = array_merge(array($lanif, $wanif), $optif);
213 1e0b1727 Phil Davis
214 60f164f3 Renato Botelho
	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 1e0b1727 Phil Davis
219 530e4707 NOYB
Error: The same interface name cannot be assigned twice!
220 1e0b1727 Phil Davis
221 5b74202b Scott Ullrich
EOD;
222 60f164f3 Renato Botelho
				fclose($fp);
223 87d2f8cd Luiz Souza
				return (-2);
224 5b74202b Scott Ullrich
			}
225
		}
226 60f164f3 Renato Botelho
	}
227 1e0b1727 Phil Davis
228 60f164f3 Renato Botelho
	echo "\n" . gettext("The interfaces will be assigned as follows:") . "\n\n";
229 1e0b1727 Phil Davis
230 60f164f3 Renato Botelho
	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 5b74202b Scott Ullrich
	}
237
238 60f164f3 Renato Botelho
	echo "\n" . gettext("Do you want to proceed [y|n]?") . " ";
239
	$key = chop(fgets($fp));
240
241 5b74202b Scott Ullrich
	if (in_array($key, array('y', 'Y'))) {
242 1e0b1727 Phil Davis
		if ($lanif) {
243 86d1c9c2 Luiz Otavio O Souza
			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 1e0b1727 Phil Davis
			if (!is_array($config['interfaces']['lan'])) {
249 e503c44a Ermal
				$config['interfaces']['lan'] = array();
250 1e0b1727 Phil Davis
			}
251 5b74202b Scott Ullrich
			$config['interfaces']['lan']['if'] = $lanif;
252
			$config['interfaces']['lan']['enable'] = true;
253 60f164f3 Renato Botelho
		} elseif (!platform_booting()) {
254 5b74202b Scott Ullrich
255 0b3799f1 Phil Davis
			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 5b74202b Scott Ullrich
258 1e0b1727 Phil Davis
			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 5b74202b Scott Ullrich
				}
262 1e0b1727 Phil Davis
			}
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 bb213758 Chris Buechler
			if (isset($config['dhcpdv6']['lan'])) {
270
				unset($config['dhcpdv6']['lan']);
271
			}
272 1e0b1727 Phil Davis
			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 5b74202b Scott Ullrich
		} else {
288 1e0b1727 Phil Davis
			if (isset($config['interfaces']['lan']['if'])) {
289 5b74202b Scott Ullrich
				mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
290 1e0b1727 Phil Davis
			}
291
			if (isset($config['interfaces']['lan'])) {
292 5b74202b Scott Ullrich
				unset($config['interfaces']['lan']);
293 1e0b1727 Phil Davis
			}
294
			if (isset($config['dhcpd']['lan'])) {
295 5b74202b Scott Ullrich
				unset($config['dhcpd']['lan']);
296 1e0b1727 Phil Davis
			}
297
			if (isset($config['interfaces']['lan']['if'])) {
298 5b74202b Scott Ullrich
				unset($config['interfaces']['lan']['if']);
299 1e0b1727 Phil Davis
			}
300
			if (isset($config['interfaces']['wan']['blockpriv'])) {
301 5b74202b Scott Ullrich
				unset($config['interfaces']['wan']['blockpriv']);
302 1e0b1727 Phil Davis
			}
303
			if (isset($config['shaper'])) {
304 5b74202b Scott Ullrich
				unset($config['shaper']);
305 1e0b1727 Phil Davis
			}
306
			if (isset($config['ezshaper'])) {
307 5b74202b Scott Ullrich
				unset($config['ezshaper']);
308 1e0b1727 Phil Davis
			}
309
			if (isset($config['nat'])) {
310
				unset($config['nat']);
311
			}
312 5b74202b Scott Ullrich
		}
313
		if (preg_match($g['wireless_regex'], $lanif)) {
314
			if (is_array($config['interfaces']['lan']) &&
315 ae52d165 Renato Botelho
			    !is_array($config['interfaces']['lan']['wireless'])) {
316 5b74202b Scott Ullrich
				$config['interfaces']['lan']['wireless'] = array();
317 1e0b1727 Phil Davis
			}
318 5b74202b Scott Ullrich
		} else {
319 1e0b1727 Phil Davis
			if (isset($config['interfaces']['lan'])) {
320 e503c44a Ermal
				unset($config['interfaces']['lan']['wireless']);
321 1e0b1727 Phil Davis
			}
322 5b74202b Scott Ullrich
		}
323
324 86d1c9c2 Luiz Otavio O Souza
		if (is_array($config['interfaces']['wan'])) {
325
			$upints = pfSense_interface_listget(IFF_UP);
326
			if (in_array($config['interfaces']['wan']['if'], $upints))
327
				interface_bring_down('wan', true);
328
		}
329 1e0b1727 Phil Davis
		if (!is_array($config['interfaces']['wan'])) {
330 e503c44a Ermal
			$config['interfaces']['wan'] = array();
331 1e0b1727 Phil Davis
		}
332 5b74202b Scott Ullrich
		$config['interfaces']['wan']['if'] = $wanif;
333
		$config['interfaces']['wan']['enable'] = true;
334
		if (preg_match($g['wireless_regex'], $wanif)) {
335
			if (is_array($config['interfaces']['wan']) &&
336 ae52d165 Renato Botelho
			    !is_array($config['interfaces']['wan']['wireless'])) {
337 5b74202b Scott Ullrich
				$config['interfaces']['wan']['wireless'] = array();
338 1e0b1727 Phil Davis
			}
339 5b74202b Scott Ullrich
		} else {
340 1e0b1727 Phil Davis
			if (isset($config['interfaces']['wan'])) {
341 e503c44a Ermal
				unset($config['interfaces']['wan']['wireless']);
342 1e0b1727 Phil Davis
			}
343 5b74202b Scott Ullrich
		}
344
345
		for ($i = 0; $i < count($optif); $i++) {
346 86d1c9c2 Luiz Otavio O Souza
			if (is_array($config['interfaces']['opt' . ($i+1)])) {
347
				$upints = pfSense_interface_listget(IFF_UP);
348
				if (in_array($config['interfaces']['opt' . ($i+1)]['if'], $upints))
349
					interface_bring_down('opt' . ($i+1), true);
350
			}
351 1e0b1727 Phil Davis
			if (!is_array($config['interfaces']['opt' . ($i+1)])) {
352 5b74202b Scott Ullrich
				$config['interfaces']['opt' . ($i+1)] = array();
353 1e0b1727 Phil Davis
			}
354 5b74202b Scott Ullrich
355
			$config['interfaces']['opt' . ($i+1)]['if'] = $optif[$i];
356
357
			/* wireless interface? */
358
			if (preg_match($g['wireless_regex'], $optif[$i])) {
359 1e0b1727 Phil Davis
				if (!is_array($config['interfaces']['opt' . ($i+1)]['wireless'])) {
360 5b74202b Scott Ullrich
					$config['interfaces']['opt' . ($i+1)]['wireless'] = array();
361 1e0b1727 Phil Davis
				}
362 5b74202b Scott Ullrich
			} else {
363
				unset($config['interfaces']['opt' . ($i+1)]['wireless']);
364
			}
365
366 62784b05 Ermal
			if (empty($config['interfaces']['opt' . ($i+1)]['descr'])) {
367
				$config['interfaces']['opt' . ($i+1)]['descr'] = "OPT" . ($i+1);
368
				unset($config['interfaces']['opt' . ($i+1)]['enable']);
369
			}
370 5b74202b Scott Ullrich
		}
371
372
		/* remove all other (old) optional interfaces */
373 1e0b1727 Phil Davis
		for (; isset($config['interfaces']['opt' . ($i+1)]); $i++) {
374 5b74202b Scott Ullrich
			unset($config['interfaces']['opt' . ($i+1)]);
375 1e0b1727 Phil Davis
		}
376 5b74202b Scott Ullrich
377 814f9e64 Carlos Eduardo Ramos
		printf(gettext("%sWriting configuration..."), "\n");
378 d18f3f6e Phil Davis
		write_config(gettext("Console assignment of interfaces"));
379 814f9e64 Carlos Eduardo Ramos
		printf(gettext("done.%s"), "\n");
380 5b74202b Scott Ullrich
381
		fclose($fp);
382 c9fa8254 Scott Ullrich
383 1e0b1727 Phil Davis
		if (platform_booting()) {
384 87d2f8cd Luiz Souza
			return (0);
385 1e0b1727 Phil Davis
		}
386 5b74202b Scott Ullrich
387 34ee6639 NOYB
		echo gettext("One moment while the settings are reloading...");
388 5b74202b Scott Ullrich
		touch("{$g['tmp_path']}/assign_complete");
389
390 75a1149e Phil Davis
		if (file_exists("/conf/trigger_initial_wizard")) {
391
			// Let the system know that the interface assign part of initial setup has been done.
392
			touch("{$g['conf_path']}/assign_complete");
393
		}
394 87d2f8cd Luiz Souza
395
		echo gettext(" done!") . "\n";
396
397
		return (0);
398 5b74202b Scott Ullrich
	}
399
}
400
401
function autodetect_interface($ifname, $fp) {
402
	$iflist_prev = get_interface_list("media");
403
	echo <<<EOD
404
405
Connect the {$ifname} interface now and make sure that the link is up.
406
Then press ENTER to continue.
407
408
EOD;
409
	fgets($fp);
410
	$iflist = get_interface_list("media");
411
412
	foreach ($iflist_prev as $ifn => $ifa) {
413
		if (!$ifa['up'] && $iflist[$ifn]['up']) {
414 1579e70f Phil Davis
			printf(gettext('Detected link-up on interface %1$s.%2$s'), $ifn, "\n");
415 5b74202b Scott Ullrich
			return $ifn;
416
		}
417
	}
418
419 814f9e64 Carlos Eduardo Ramos
	printf(gettext("No link-up detected.%s"), "\n");
420 5b74202b Scott Ullrich
421
	return null;
422
}
423
424 c9fa8254 Scott Ullrich
function interfaces_setup() {
425
	global $iflist, $config, $g, $fp;
426
427
	$iflist = get_interface_list();
428
}
429
430 5b74202b Scott Ullrich
function vlan_setup() {
431
	global $iflist, $config, $g, $fp;
432
433
	$iflist = get_interface_list();
434
435
	if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
436 0b3799f1 Phil Davis
		echo "\n" . gettext("WARNING: all existing VLANs will be cleared if you proceed!") . "\n";
437
		echo "\n" . gettext("Do you want to proceed [y|n]?") . " ";
438 5b74202b Scott Ullrich
439 1e0b1727 Phil Davis
		if (strcasecmp(chop(fgets($fp)), "y") != 0) {
440
			return;
441
		}
442 5b74202b Scott Ullrich
	}
443
444
	$config['vlans']['vlan'] = array();
445
	echo "\n";
446
447
	$vlanif = 0;
448
449
	while (1) {
450
		$vlan = array();
451
452 814f9e64 Carlos Eduardo Ramos
		echo "\n\n" . gettext("VLAN Capable interfaces:") . "\n\n";
453 1e0b1727 Phil Davis
		if (!is_array($iflist)) {
454 814f9e64 Carlos Eduardo Ramos
			echo gettext("No interfaces found!") . "\n";
455 5b74202b Scott Ullrich
		} else {
456 6c07db48 Phil Davis
			$vlan_capable = 0;
457 5b74202b Scott Ullrich
			foreach ($iflist as $iface => $ifa) {
458
				if (is_jumbo_capable($iface)) {
459
					echo sprintf("% -8s%s%s\n", $iface, $ifa['mac'],
460
						$ifa['up'] ? "   (up)" : "");
461
					$vlan_capable++;
462
				}
463
			}
464
		}
465
466 1e0b1727 Phil Davis
		if ($vlan_capable == 0) {
467 814f9e64 Carlos Eduardo Ramos
			echo gettext("No VLAN capable interfaces detected.") . "\n";
468 5b74202b Scott Ullrich
			return;
469
		}
470
471 814f9e64 Carlos Eduardo Ramos
		echo "\n" . gettext("Enter the parent interface name for the new VLAN (or nothing if finished):") . " ";
472 5b74202b Scott Ullrich
		$vlan['if'] = chop(fgets($fp));
473
474
		if ($vlan['if']) {
475 013110a1 stilez
			if (!array_key_exists($vlan['if'], $iflist) || 
476 ae52d165 Renato Botelho
			    !is_jumbo_capable($vlan['if'])) {
477 1579e70f Phil Davis
				printf(gettext('%1$sInvalid interface name \'%2$s\'%3$s'), "\n", $vlan['if'], "\n");
478 5b74202b Scott Ullrich
				continue;
479
			}
480
		} else {
481
			break;
482
		}
483
484 814f9e64 Carlos Eduardo Ramos
		echo gettext("Enter the VLAN tag (1-4094):") . " ";
485 5b74202b Scott Ullrich
		$vlan['tag'] = chop(fgets($fp));
486 12bcf7e9 Luiz Souza
		$vlan['vlanif'] = vlan_interface($vlan);
487 5b74202b Scott Ullrich
		if (!is_numericint($vlan['tag']) || ($vlan['tag'] < 1) || ($vlan['tag'] > 4094)) {
488 1579e70f Phil Davis
			printf(gettext('%1$sInvalid VLAN tag \'%2$s\'%3$s'), "\n", $vlan['tag'], "\n");
489 5b74202b Scott Ullrich
			continue;
490
		}
491 1e0b1727 Phil Davis
492 ff4665f0 Chris Buechler
		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 5b74202b Scott Ullrich
		$config['vlans']['vlan'][] = $vlan;
501
		$vlanif++;
502
	}
503
}
504
505 b49e6c01 Phil Davis
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 'RCC-VE':
527 3c3f9397 Luiz Otavio O Souza
			/* SG-4860 or SG-8860 */
528
			if (does_interface_exist('igb4')) {
529
				$config['interfaces']['wan']['if'] = 'igb1';
530
				$config['interfaces']['lan']['if'] = 'igb0';
531
			} else {
532
				$config['interfaces']['wan']['if'] = 'igb0';
533
				$config['interfaces']['lan']['if'] = 'igb1';
534
			}
535 b49e6c01 Phil Davis
			break;
536 8b3345dc Renato Botelho
		case 'Turbot Dual-E':
537
			$config['interfaces']['wan']['if'] = 'igb0';
538
			$config['interfaces']['lan']['if'] = 'igb1';
539
			break;
540 b49e6c01 Phil Davis
		default:
541
			$default_device['wan'] = "";
542
			$default_device['lan'] = "";
543
			break;
544
	}
545
546
	// Other common device names can be put here and will be looked for
547
	// if the system was not one of the known platforms.
548
	$other_devices_arr['wan'] = array("vr1", "re1", "igb0", "em0");
549
	$other_devices_arr['lan'] = array("vr0", "re2", "igb1", "em1");
550
	$interface_assignment_changed = false;
551
552
	foreach ($other_devices_arr as $ifname => $other_devices) {
553
		if (!does_interface_exist($config['interfaces'][$ifname]['if'])) {
554
			if (does_interface_exist($default_device[$ifname])) {
555
				$config['interfaces'][$ifname]['if'] = $default_device[$ifname];
556
				$interface_assignment_changed = true;
557
			} else {
558
				foreach ($other_devices as $other_device) {
559
					if (does_interface_exist($other_device)) {
560
						$config['interfaces'][$ifname]['if'] = $other_device;
561
						$interface_assignment_changed = true;
562
						break;
563
					}
564
				}
565
			}
566
		}
567
	}
568
569
	if ($interface_assignment_changed) {
570
		write_config("Factory default boot detected WAN " . $config['interfaces']['wan']['if'] . " and LAN " . $config['interfaces']['lan']['if']);
571
	}
572
}
573
574 814f9e64 Carlos Eduardo Ramos
?>