From daa5462f64b417a036b3ecf17a2f19a3df1f7e3c Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Wed, 1 Jul 2015 21:23:59 +0200 Subject: [PATCH] config: clean up the code and horrible usage of temp files; #5 --- src/etc/inc/config.console.inc | 28 ++++++++++------------------ src/etc/inc/util.inc | 21 +++++---------------- src/etc/rc.bootup | 24 ++++++++++++------------ src/etc/rc.initial.setports | 3 ++- 4 files changed, 29 insertions(+), 47 deletions(-) diff --git a/src/etc/inc/config.console.inc b/src/etc/inc/config.console.inc index fbfeae746..9e171b910 100644 --- a/src/etc/inc/config.console.inc +++ b/src/etc/inc/config.console.inc @@ -1,8 +1,9 @@ . + Copyright (C) 2015 Franco Fichtner + Copyright (C) 2004-2010 Scott Ullrich + Copyright (C) 2003-2004 Manuel Kasper All rights reserved. Redistribution and use in source and binary forms, with or without @@ -29,9 +30,7 @@ function set_networking_interfaces_ports() { - global $noreboot; global $config; - global $fp; $fp = fopen('php://stdin', 'r'); $yes_no_prompt = '[y|n]? '; @@ -84,7 +83,7 @@ EOD; } if (in_array($key, array('y', 'Y'))) { - vlan_setup(); + vlan_setup($iflist, $fp); } if (isset($config['vlans']['vlan'])) { @@ -198,7 +197,7 @@ Error: you cannot assign the same interface name twice! EOD; fclose($fp); - return; + return false; } } } @@ -347,15 +346,10 @@ EODD; fclose($fp); - if(file_exists("/var/run/booting")) - return; - - echo gettext("One moment while we reload the settings..."); - - echo gettext(" done!") . "\n"; - - touch('/tmp/assign_complete'); + return true; } + + return false; } function autodetect_interface($ifname, $fp) @@ -382,14 +376,12 @@ EOD; return null; } -function vlan_setup() +function vlan_setup($iflist, $fp) { - global $iflist, $config, $fp; + global $config; $yes_no_prompt = '[y|n]? '; - $iflist = get_interface_list(); - if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) { echo << $ifcfg) { if (preg_match("/^enc|^cua|^tun|^tap|^l2tp|^pptp|^ppp|^ovpn|^gif|^gre|^lagg|^bridge|vlan|_wlan/i", $ifcfg['if'])) { - // Do not check these interfaces. + /* Do not check these interfaces */ $i++; continue; - } - else if (does_interface_exist($ifcfg['if']) == false) { - $missing_interfaces[] = $ifcfg['if']; + } elseif (does_interface_exist($ifcfg['if']) == false) { $do_assign = true; - } else + } else { $i++; + } } } - if (file_exists('/tmp/assign_complete')) { - $do_assign = false; - } - - if (!empty($missing_interfaces) && $do_assign) { - file_put_contents('/tmp/missing_interfaces', implode(' ', $missing_interfaces)); - } else { - @unlink('/tmp/missing_interfaces'); - } - return $do_assign; } diff --git a/src/etc/rc.bootup b/src/etc/rc.bootup index 1e3177cf9..ef4e48dd1 100755 --- a/src/etc/rc.bootup +++ b/src/etc/rc.bootup @@ -139,22 +139,22 @@ echo "done.\n"; * and ask the user to reassign interfaces. This will * avoid a reboot and thats a good thing. */ -while(is_interface_mismatch() == true) { - led_assigninterfaces(); - if (isset($config['revision'])) { - if (file_exists('/tmp/missing_interfaces')) { - echo "Warning: Configuration references interfaces that do not exist: " . file_get_contents('/tmp/missing_interfaces') . "\n"; - } - echo "\nNetwork interface mismatch -- Running interface assignment option.\n"; - } else - echo "\nDefault interfaces not found -- Running interface assignment option.\n"; +if (is_interface_mismatch()) { + echo PHP_EOL . gettext('Default interfaces not found -- Running interface assignment option.') . PHP_EOL; + $ifaces = get_interface_list(); if (is_array($ifaces)) { - foreach($ifaces as $iface => $ifdata) + foreach($ifaces as $iface => $ifdata) { interfaces_bring_up($iface); + } } - set_networking_interfaces_ports(); - led_kitt(); + + $done = false; + do { + led_assigninterfaces(); + $done = set_networking_interfaces_ports(); + led_kitt(); + } while (!$done); } /* convert config and clean backups */ diff --git a/src/etc/rc.initial.setports b/src/etc/rc.initial.setports index 545ab5982..aa64eac5d 100755 --- a/src/etc/rc.initial.setports +++ b/src/etc/rc.initial.setports @@ -37,6 +37,7 @@ require_once("vpn.inc"); require_once("captiveportal.inc"); require_once("rrd.inc"); -set_networking_interfaces_ports(); +/* configure until valid */ +while (!set_networking_interfaces_ports()); reload_interfaces_sync(); enable_rrd_graphing();