Commit 39689a70 authored by Franco Fichtner's avatar Franco Fichtner

config: make WAN optional as well; #5

parent c8bc87f6
...@@ -113,6 +113,10 @@ EOD; ...@@ -113,6 +113,10 @@ EOD;
echo $wanif . PHP_EOL; echo $wanif . PHP_EOL;
} }
if ($wanif == '') {
break;
}
if ($wanif == 'a') { if ($wanif == 'a') {
$wanif = autodetect_interface('WAN', $fp); $wanif = autodetect_interface('WAN', $fp);
} }
...@@ -147,6 +151,15 @@ EOD; ...@@ -147,6 +151,15 @@ EOD;
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $lanif, "\n"); printf(gettext("%sInvalid interface name '%s'%s"), "\n", $lanif, "\n");
unset($lanif); unset($lanif);
} }
if ($wanif && $lanif == $wanif) {
unset($lanif);
echo <<<EOD
Error: you cannot assign the same interface name twice!
EOD;
}
} while (!$lanif); } while (!$lanif);
while ($lanif != '') { while ($lanif != '') {
...@@ -193,13 +206,12 @@ EOD; ...@@ -193,13 +206,12 @@ EOD;
for ($i = 0; $i < (count($ifarr)-1); $i++) { for ($i = 0; $i < (count($ifarr)-1); $i++) {
for ($j = ($i+1); $j < count($ifarr); $j++) { for ($j = ($i+1); $j < count($ifarr); $j++) {
if ($ifarr[$i] == $ifarr[$j]) { if ($ifarr[$i] == $ifarr[$j]) {
$again = true;
echo <<<EOD echo <<<EOD
Error: you cannot assign the same interface name twice! Error: you cannot assign the same interface name twice!
EOD; EOD;
$again = true;
} }
} }
} }
...@@ -210,9 +222,12 @@ EOD; ...@@ -210,9 +222,12 @@ EOD;
echo "\n" . gettext("The interfaces will be assigned as follows:") . "\n\n"; echo "\n" . gettext("The interfaces will be assigned as follows:") . "\n\n";
if ($wanif != '') {
echo "WAN -> " . $wanif . "\n"; echo "WAN -> " . $wanif . "\n";
if ($lanif != "") }
if ($lanif != '') {
echo "LAN -> " . $lanif . "\n"; echo "LAN -> " . $lanif . "\n";
}
for ($i = 0; $i < count($optif); $i++) { for ($i = 0; $i < count($optif); $i++) {
echo "OPT" . ($i+1) . " -> " . $optif[$i] . "\n"; echo "OPT" . ($i+1) . " -> " . $optif[$i] . "\n";
} }
...@@ -239,6 +254,16 @@ EOD; ...@@ -239,6 +254,16 @@ EOD;
} }
$config['interfaces']['lan']['if'] = $lanif; $config['interfaces']['lan']['if'] = $lanif;
$config['interfaces']['lan']['enable'] = true; $config['interfaces']['lan']['enable'] = true;
if (match_wireless_interface($lanif)) {
if (is_array($config['interfaces']['lan']) &&
(!is_array($config['interfaces']['lan']['wireless']))) {
$config['interfaces']['lan']['wireless'] = array();
}
} else {
if (isset($config['interfaces']['lan'])) {
unset($config['interfaces']['lan']['wireless']);
}
}
} else { } else {
if(isset($config['interfaces']['lan']['if'])) if(isset($config['interfaces']['lan']['if']))
mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete"); mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
...@@ -254,23 +279,14 @@ EOD; ...@@ -254,23 +279,14 @@ EOD;
unset($config['nat']); unset($config['nat']);
} }
if (match_wireless_interface($lanif)) { if ($wanif) {
if (is_array($config['interfaces']['lan']) &&
(!is_array($config['interfaces']['lan']['wireless']))) {
$config['interfaces']['lan']['wireless'] = array();
}
} else {
if (isset($config['interfaces']['lan'])) {
unset($config['interfaces']['lan']['wireless']);
}
}
if (!is_array($config['interfaces']['wan'])) { if (!is_array($config['interfaces']['wan'])) {
$config['interfaces']['wan'] = array(); $config['interfaces']['wan'] = array();
} }
$config['interfaces']['wan']['if'] = $wanif; $config['interfaces']['wan']['if'] = $wanif;
$config['interfaces']['wan']['enable'] = true; $config['interfaces']['wan']['enable'] = true;
$config['interfaces']['wan']['ipaddr'] = 'dhcp';
$config['interfaces']['wan']['ipaddrv6'] = 'dhcpv6';
if (match_wireless_interface($wanif)) { if (match_wireless_interface($wanif)) {
if (is_array($config['interfaces']['wan']) && if (is_array($config['interfaces']['wan']) &&
...@@ -282,6 +298,10 @@ EOD; ...@@ -282,6 +298,10 @@ EOD;
unset($config['interfaces']['wan']['wireless']); unset($config['interfaces']['wan']['wireless']);
} }
} }
} else {
if (isset($config['interfaces']['wan']))
unset($config['interfaces']['wan']);
}
for ($i = 0; $i < count($optif); $i++) { for ($i = 0; $i < count($optif); $i++) {
if (!is_array($config['interfaces']['opt' . ($i+1)])) if (!is_array($config['interfaces']['opt' . ($i+1)]))
...@@ -303,8 +323,9 @@ EOD; ...@@ -303,8 +323,9 @@ EOD;
} }
/* remove all other (old) optional interfaces */ /* remove all other (old) optional interfaces */
for (; isset($config['interfaces']['opt' . ($i+1)]); $i++) for (; isset($config['interfaces']['opt' . ($i+1)]); $i++) {
unset($config['interfaces']['opt' . ($i+1)]); unset($config['interfaces']['opt' . ($i+1)]);
}
printf(gettext("%sWriting configuration..."), "\n"); printf(gettext("%sWriting configuration..."), "\n");
write_config("Console assignment of interfaces"); write_config("Console assignment of interfaces");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment