Commit cca7eda6 authored by Franco Fichtner's avatar Franco Fichtner

config: clean up more code paths, whew; #5

Always unload LAN if previously set.  Otherwise no code changes.
parent daa5462f
...@@ -149,11 +149,11 @@ EOD; ...@@ -149,11 +149,11 @@ EOD;
} }
} while (!$lanif); } while (!$lanif);
/* optional interfaces */ while ($lanif != '') {
$optif = array(); /* optional interfaces */
$i = 0; $optif = array();
$i = 0;
if ($lanif != '') {
while (1) { while (1) {
if ($optif[$i]) if ($optif[$i])
$i++; $i++;
...@@ -188,6 +188,8 @@ EOD; ...@@ -188,6 +188,8 @@ EOD;
/* check for double assignments */ /* check for double assignments */
$ifarr = array_merge(array($lanif, $wanif), $optif); $ifarr = array_merge(array($lanif, $wanif), $optif);
$again = false;
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]) {
...@@ -196,12 +198,16 @@ EOD; ...@@ -196,12 +198,16 @@ EOD;
Error: you cannot assign the same interface name twice! Error: you cannot assign the same interface name twice!
EOD; EOD;
fclose($fp);
return false; $again = true;
} }
} }
} }
if ($again) {
continue;
}
echo "\n" . gettext("The interfaces will be assigned as follows:") . "\n\n"; echo "\n" . gettext("The interfaces will be assigned as follows:") . "\n\n";
echo "WAN -> " . $wanif . "\n"; echo "WAN -> " . $wanif . "\n";
...@@ -221,135 +227,90 @@ EOD; ...@@ -221,135 +227,90 @@ EOD;
$key = 'y'; $key = 'y';
echo $key . PHP_EOL; echo $key . PHP_EOL;
} }
}
if (!$interactive) { if (in_array($key, array('y', 'Y'))) {
$key = 'y'; break;
}
} }
if (in_array($key, array('y', 'Y'))) { if ($lanif) {
if ($lanif) { if (!is_array($config['interfaces']['lan'])) {
if (!is_array($config['interfaces']['lan'])) { $config['interfaces']['lan'] = array();
$config['interfaces']['lan'] = array(); }
} $config['interfaces']['lan']['if'] = $lanif;
$config['interfaces']['lan']['if'] = $lanif; $config['interfaces']['lan']['enable'] = true;
$config['interfaces']['lan']['enable'] = true; } else {
} elseif (!file_exists('/var/run/booting') && if(isset($config['interfaces']['lan']['if']))
isset($config['interfaces']['lan'])) { mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
if(isset($config['interfaces']['lan']))
unset($config['interfaces']['lan']);
if(isset($config['dhcpd']['lan']))
unset($config['dhcpd']['lan']);
if(isset($config['interfaces']['lan']['if']))
unset($config['interfaces']['lan']['if']);
if(isset($config['interfaces']['wan']['blockpriv']))
unset($config['interfaces']['wan']['blockpriv']);
if(isset($config['nat']))
unset($config['nat']);
}
echo <<<EODD 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']);
}
}
You have chosen to remove the LAN interface. if (!is_array($config['interfaces']['wan'])) {
$config['interfaces']['wan'] = array();
}
Would you like to remove the LAN IP address and $config['interfaces']['wan']['if'] = $wanif;
unload the interface now ${yes_no_prompt} $config['interfaces']['wan']['enable'] = true;
EODD;
if ($interactive) { if (match_wireless_interface($wanif)) {
$key = chop(fgets($fp)); if (is_array($config['interfaces']['wan']) &&
} else { (!is_array($config['interfaces']['wan']['wireless']))) {
$key = 'y'; $config['interfaces']['wan']['wireless'] = array();
echo $key . PHP_EOL;
}
if (strcasecmp($key, 'y') == 0) {
if(isset($config['interfaces']['lan']) && $config['interfaces']['lan']['if'])
mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
}
if(isset($config['interfaces']['lan']))
unset($config['interfaces']['lan']);
if(isset($config['dhcpd']['lan']))
unset($config['dhcpd']['lan']);
if(isset($config['interfaces']['lan']['if']))
unset($config['interfaces']['lan']['if']);
if(isset($config['interfaces']['wan']['blockpriv']))
unset($config['interfaces']['wan']['blockpriv']);
if(isset($config['shaper']))
unset($config['shaper']);
if(isset($config['ezshaper']))
unset($config['ezshaper']);
if(isset($config['nat']))
unset($config['nat']);
} else {
if(isset($config['interfaces']['lan']['if']))
mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
if(isset($config['interfaces']['lan']))
unset($config['interfaces']['lan']);
if(isset($config['dhcpd']['lan']))
unset($config['dhcpd']['lan']);
if(isset($config['interfaces']['lan']['if']))
unset($config['interfaces']['lan']['if']);
if(isset($config['interfaces']['wan']['blockpriv']))
unset($config['interfaces']['wan']['blockpriv']);
if(isset($config['shaper']))
unset($config['shaper']);
if(isset($config['ezshaper']))
unset($config['ezshaper']);
if(isset($config['nat']))
unset($config['nat']);
} }
} else {
if (match_wireless_interface($lanif)) { if (isset($config['interfaces']['wan'])) {
if (is_array($config['interfaces']['lan']) && unset($config['interfaces']['wan']['wireless']);
(!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'])) { for ($i = 0; $i < count($optif); $i++) {
$config['interfaces']['wan'] = array(); if (!is_array($config['interfaces']['opt' . ($i+1)]))
} $config['interfaces']['opt' . ($i+1)] = array();
$config['interfaces']['wan']['if'] = $wanif; $config['interfaces']['opt' . ($i+1)]['if'] = $optif[$i];
$config['interfaces']['wan']['enable'] = true;
if (match_wireless_interface($wanif)) { if (match_wireless_interface($optif[$i])) {
if (is_array($config['interfaces']['wan']) && if (!is_array($config['interfaces']['opt' . ($i+1)]['wireless']))
(!is_array($config['interfaces']['wan']['wireless']))) { $config['interfaces']['opt' . ($i+1)]['wireless'] = array();
$config['interfaces']['wan']['wireless'] = array();
}
} else { } else {
if (isset($config['interfaces']['wan'])) { unset($config['interfaces']['opt' . ($i+1)]['wireless']);
unset($config['interfaces']['wan']['wireless']);
}
} }
for ($i = 0; $i < count($optif); $i++) { if (empty($config['interfaces']['opt' . ($i+1)]['descr'])) {
if (!is_array($config['interfaces']['opt' . ($i+1)])) $config['interfaces']['opt' . ($i+1)]['descr'] = "OPT" . ($i+1);
$config['interfaces']['opt' . ($i+1)] = array(); unset($config['interfaces']['opt' . ($i+1)]['enable']);
$config['interfaces']['opt' . ($i+1)]['if'] = $optif[$i];
if (match_wireless_interface($optif[$i])) {
if (!is_array($config['interfaces']['opt' . ($i+1)]['wireless']))
$config['interfaces']['opt' . ($i+1)]['wireless'] = array();
} else {
unset($config['interfaces']['opt' . ($i+1)]['wireless']);
}
if (empty($config['interfaces']['opt' . ($i+1)]['descr'])) {
$config['interfaces']['opt' . ($i+1)]['descr'] = "OPT" . ($i+1);
unset($config['interfaces']['opt' . ($i+1)]['enable']);
}
} }
}
/* 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");
write_config("Console assignment of interfaces");
printf(gettext("done.%s"), "\n");
fclose($fp);
return true; printf(gettext("%sWriting configuration..."), "\n");
} write_config("Console assignment of interfaces");
printf(gettext("done.%s"), "\n");
return false; fclose($fp);
} }
function autodetect_interface($ifname, $fp) function autodetect_interface($ifname, $fp)
......
...@@ -149,12 +149,9 @@ if (is_interface_mismatch()) { ...@@ -149,12 +149,9 @@ if (is_interface_mismatch()) {
} }
} }
$done = false; led_assigninterfaces();
do { set_networking_interfaces_ports();
led_assigninterfaces(); led_kitt();
$done = set_networking_interfaces_ports();
led_kitt();
} while (!$done);
} }
/* convert config and clean backups */ /* convert config and clean backups */
......
...@@ -37,7 +37,8 @@ require_once("vpn.inc"); ...@@ -37,7 +37,8 @@ require_once("vpn.inc");
require_once("captiveportal.inc"); require_once("captiveportal.inc");
require_once("rrd.inc"); require_once("rrd.inc");
/* configure until valid */ set_networking_interfaces_ports();
while (!set_networking_interfaces_ports()); echo "Reloading interfaces...";
reload_interfaces_sync(); reload_interfaces_sync();
echo "done.\n";
enable_rrd_graphing(); enable_rrd_graphing();
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