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
/*
Copyright (C) 2004-2010 Scott Ullrich
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
Copyright (C) 2015 Franco Fichtner <franco@opnsense.org>
Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>
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 <<<EOD
......
......@@ -1409,30 +1409,19 @@ function is_interface_mismatch()
$do_assign = false;
$i = 0;
$missing_interfaces = array();
if (is_array($config['interfaces'])) {
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'])) {
// 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;
......
......@@ -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();
}
$done = false;
do {
led_assigninterfaces();
$done = set_networking_interfaces_ports();
led_kitt();
} while (!$done);
}
/* convert config and clean backups */
......
......@@ -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();
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