Commit 679b72f3 authored by Franco Fichtner's avatar Franco Fichtner

config: introduce non-interactive interface assignment; #5

Boy, this is a fun one!  :) Still some work to do, but seems really
good for headless installation or just being plain sloppy.  Needed
do adapt timeout() to return the actual input char, so that we can
do the `any key' prompt.
parent 6d3eded2
......@@ -33,14 +33,23 @@ function set_networking_interfaces_ports()
global $config;
global $fp;
$yes_no_prompt = '[y|n]? ';
$fp = fopen('php://stdin', 'r');
$yes_no_prompt = '[y|n]? ';
$interactive = true;
$key = null;
$iflist = get_interface_list();
/* Function flow is based on $key */
$key = null;
echo PHP_EOL . gettext('Press any key to start the manual interface assignment: ');
$key = timeout(7);
if (!isset($key)) {
$interactive = false;
}
if ($key != "\n") {
echo PHP_EOL;
}
echo <<<EOD
......@@ -48,7 +57,7 @@ Valid interfaces are:
EOD;
if(!is_array($iflist)) {
if (!is_array($iflist)) {
echo gettext("No interfaces found!") . "\n";
$iflist = array();
} else {
......@@ -58,29 +67,31 @@ EOD;
}
}
echo <<<EOD
$ifnames = array_keys($iflist);
Do you want to set up VLANs first?
echo <<<EOD
If you are not going to use VLANs, or only for optional interfaces, you should
say no here and use the webConfigurator to configure VLANs later, if required.
You now have the opportunity to configure VLANs. If you don't require VLANs
for initial connectivity, say no here and use the GUI to configure VLANs later.
Do you want to set up VLANs now ${yes_no_prompt}
EOD;
if ($interactive) {
$key = chop(fgets($fp));
} else {
$key = 'n';
echo $key . PHP_EOL;
}
if (in_array($key, array('y', 'Y')))
if (in_array($key, array('y', 'Y'))) {
vlan_setup();
}
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
if (isset($config['vlans']['vlan'])) {
echo "\n\n" . gettext("VLAN interfaces:") . "\n\n";
foreach ($config['vlans']['vlan'] as $vlan) {
echo sprintf("% -16s%s\n", "{$vlan['if']}_vlan{$vlan['tag']}",
"VLAN tag {$vlan['tag']}, parent interface {$vlan['if']}");
$iflist[$vlan['if'] . '_vlan' . $vlan['tag']] = array();
}
}
......@@ -95,13 +106,18 @@ EOD;
do {
echo "\n" . gettext("Enter the WAN interface name or 'a' for auto-detection:") . " ";
if ($interactive) {
$wanif = chop(fgets($fp));
if ($wanif === "") {
} else {
$wanif = $ifnames[0];
echo $wanif . PHP_EOL;
}
if ($wanif == '') {
return;
}
if ($wanif === "a")
$wanif = autodetect_interface("WAN", $fp);
else if (!array_key_exists($wanif, $iflist)) {
if ($wanif == 'a') {
$wanif = autodetect_interface('WAN', $fp);
} elseif (!array_key_exists($wanif, $iflist)) {
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $wanif, "\n");
unset($wanif);
continue;
......@@ -113,19 +129,19 @@ EOD;
"NOTE: this enables full Firewalling/NAT mode.%s" .
"(or nothing if finished):%s"), "\n", "\n", "\n", " ");
if ($interactive) {
$lanif = chop(fgets($fp));
if($lanif == "exit") {
exit;
} else {
$lanif = '';
echo $lanif . PHP_EOL;
}
if($lanif == "") {
if ($lanif == '') {
break;
}
if ($lanif === "a")
$lanif = autodetect_interface("LAN", $fp);
else if (!array_key_exists($lanif, $iflist)) {
if ($lanif == 'a') {
$lanif = autodetect_interface('LAN', $fp);
} elseif (!array_key_exists($lanif, $iflist)) {
printf(gettext("%sInvalid interface name '%s'%s"), "\n", $lanif, "\n");
unset($lanif);
continue;
......@@ -133,10 +149,10 @@ EOD;
} while (!$lanif);
/* optional interfaces */
$i = 0;
$optif = array();
$i = 0;
if($lanif <> "") {
if ($lanif != '') {
while (1) {
if ($optif[$i])
$i++;
......@@ -198,16 +214,27 @@ EOD;
Do you want to proceed ${yes_no_prompt}
EOD;
if ($interactive) {
$key = chop(fgets($fp));
} else {
$key = 'y';
echo $key . PHP_EOL;
}
}
if (!$interactive) {
$key = 'y';
}
if (in_array($key, array('y', 'Y'))) {
if($lanif) {
if (!is_array($config['interfaces']['lan']))
if ($lanif) {
if (!is_array($config['interfaces']['lan'])) {
$config['interfaces']['lan'] = array();
}
$config['interfaces']['lan']['if'] = $lanif;
$config['interfaces']['lan']['enable'] = true;
} elseif (!file_exists("/var/run/booting")) {
} elseif (!file_exists('/var/run/booting') &&
isset($config['interfaces']['lan'])) {
echo <<<EODD
......@@ -217,7 +244,13 @@ Would you like to remove the LAN IP address and
unload the interface now ${yes_no_prompt}
EODD;
if (strcasecmp(chop(fgets($fp)), "y") == 0) {
if ($interactive) {
$key = chop(fgets($fp));
} else {
$key = 'y';
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");
}
......@@ -320,7 +353,6 @@ EODD;
echo gettext(" done!") . "\n";
touch('/tmp/assign_complete');
}
}
......
......@@ -1458,19 +1458,22 @@ function isAjax() {
* RESULT
* returns 1 char of user input or null if no input.
******/
function timeout($timer = 9) {
while(!isset($key)) {
function timeout($timer = 9)
{
while (!isset($key)) {
if ($timer >= 9) { echo chr(8) . chr(8) . ($timer==9 ? chr(32) : null) . "{$timer}"; }
else { echo chr(8). "{$timer}"; }
`/bin/stty -icanon min 0 time 25`;
$key = trim(`KEY=\`dd count=1 2>/dev/null\`; echo \$KEY`);
`/bin/stty icanon`;
if ($key == '')
shell_exec('/bin/stty -icanon min 0 time 25');
$key = shell_exec('/bin/dd count=1 status=none');
shell_exec('/bin/stty icanon');
if ($key == '') {
unset($key);
}
$timer--;
if ($timer == 0)
if ($timer == 0) {
break;
}
}
return $key;
}
......
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