Commit daa5462f authored by Franco Fichtner's avatar Franco Fichtner

config: clean up the code and horrible usage of temp files; #5

parent 5ddbfd16
<?php <?php
/* /*
Copyright (C) 2004-2010 Scott Ullrich Copyright (C) 2015 Franco Fichtner <franco@opnsense.org>
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>. Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
...@@ -29,9 +30,7 @@ ...@@ -29,9 +30,7 @@
function set_networking_interfaces_ports() function set_networking_interfaces_ports()
{ {
global $noreboot;
global $config; global $config;
global $fp;
$fp = fopen('php://stdin', 'r'); $fp = fopen('php://stdin', 'r');
$yes_no_prompt = '[y|n]? '; $yes_no_prompt = '[y|n]? ';
...@@ -84,7 +83,7 @@ EOD; ...@@ -84,7 +83,7 @@ EOD;
} }
if (in_array($key, array('y', 'Y'))) { if (in_array($key, array('y', 'Y'))) {
vlan_setup(); vlan_setup($iflist, $fp);
} }
if (isset($config['vlans']['vlan'])) { if (isset($config['vlans']['vlan'])) {
...@@ -198,7 +197,7 @@ Error: you cannot assign the same interface name twice! ...@@ -198,7 +197,7 @@ Error: you cannot assign the same interface name twice!
EOD; EOD;
fclose($fp); fclose($fp);
return; return false;
} }
} }
} }
...@@ -347,15 +346,10 @@ EODD; ...@@ -347,15 +346,10 @@ EODD;
fclose($fp); fclose($fp);
if(file_exists("/var/run/booting")) return true;
return;
echo gettext("One moment while we reload the settings...");
echo gettext(" done!") . "\n";
touch('/tmp/assign_complete');
} }
return false;
} }
function autodetect_interface($ifname, $fp) function autodetect_interface($ifname, $fp)
...@@ -382,14 +376,12 @@ EOD; ...@@ -382,14 +376,12 @@ EOD;
return null; return null;
} }
function vlan_setup() function vlan_setup($iflist, $fp)
{ {
global $iflist, $config, $fp; global $config;
$yes_no_prompt = '[y|n]? '; $yes_no_prompt = '[y|n]? ';
$iflist = get_interface_list();
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) { if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
echo <<<EOD echo <<<EOD
......
...@@ -1409,30 +1409,19 @@ function is_interface_mismatch() ...@@ -1409,30 +1409,19 @@ function is_interface_mismatch()
$do_assign = false; $do_assign = false;
$i = 0; $i = 0;
$missing_interfaces = array();
if (is_array($config['interfaces'])) { if (is_array($config['interfaces'])) {
foreach ($config['interfaces'] as $ifname => $ifcfg) { foreach ($config['interfaces'] as $ifname => $ifcfg) {
if (preg_match("/^enc|^cua|^tun|^tap|^l2tp|^pptp|^ppp|^ovpn|^gif|^gre|^lagg|^bridge|vlan|_wlan/i", $ifcfg['if'])) { 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++; $i++;
continue; continue;
} } elseif (does_interface_exist($ifcfg['if']) == false) {
else if (does_interface_exist($ifcfg['if']) == false) {
$missing_interfaces[] = $ifcfg['if'];
$do_assign = true; $do_assign = true;
} else } else {
$i++; $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; return $do_assign;
......
...@@ -139,22 +139,22 @@ echo "done.\n"; ...@@ -139,22 +139,22 @@ echo "done.\n";
* and ask the user to reassign interfaces. This will * and ask the user to reassign interfaces. This will
* avoid a reboot and thats a good thing. * avoid a reboot and thats a good thing.
*/ */
while(is_interface_mismatch() == true) { if (is_interface_mismatch()) {
led_assigninterfaces(); echo PHP_EOL . gettext('Default interfaces not found -- Running interface assignment option.') . PHP_EOL;
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";
$ifaces = get_interface_list(); $ifaces = get_interface_list();
if (is_array($ifaces)) { if (is_array($ifaces)) {
foreach($ifaces as $iface => $ifdata) foreach($ifaces as $iface => $ifdata) {
interfaces_bring_up($iface); interfaces_bring_up($iface);
} }
set_networking_interfaces_ports(); }
$done = false;
do {
led_assigninterfaces();
$done = set_networking_interfaces_ports();
led_kitt(); led_kitt();
} while (!$done);
} }
/* convert config and clean backups */ /* convert config and clean backups */
......
...@@ -37,6 +37,7 @@ require_once("vpn.inc"); ...@@ -37,6 +37,7 @@ require_once("vpn.inc");
require_once("captiveportal.inc"); require_once("captiveportal.inc");
require_once("rrd.inc"); require_once("rrd.inc");
set_networking_interfaces_ports(); /* configure until valid */
while (!set_networking_interfaces_ports());
reload_interfaces_sync(); reload_interfaces_sync();
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