Commit d082febd authored by Ad Schellevis's avatar Ad Schellevis

(legacy) refactor config->interface traversal

parent fd8c6d46
......@@ -41,7 +41,7 @@ function conv_log_interface_names()
$interface_names['enc0'] = gettext("IPsec");
if (!empty($config['interfaces'])) {
foreach ($config['interfaces'] as $intfkey => $interface) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $intfkey => $interface) {
$interface_names[$interface['if']] = !empty($interface['descr']) ? $interface['descr'] : $intfkey;
}
}
......
......@@ -1066,7 +1066,7 @@ function is_dhcpv6_server_enabled()
global $config;
if (is_array($config['interfaces'])) {
foreach ($config['interfaces'] as $ifcfg) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $ifcfg) {
if (isset($ifcfg['enable']) && !empty($ifcfg['track6-interface'])) {
return true;
}
......
......@@ -732,7 +732,7 @@ function get_configured_interface_list($only_opt = false, $withdisabled = false)
/* if list */
if (isset($config['interfaces'])) {
foreach($config['interfaces'] as $if => $ifdetail) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $if => $ifdetail) {
if ($only_opt && ($if == "wan" || $if == "lan")) {
continue;
}
......@@ -753,7 +753,7 @@ function get_configured_interface_list_by_realif ($only_opt = false, $withdisabl
$iflist = array();
/* if list */
if (isset($config['interfaces'])) {
foreach($config['interfaces'] as $if => $ifdetail) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $if => $ifdetail) {
if ($only_opt && ($if == "wan" || $if == "lan")) {
continue;
}
......@@ -776,17 +776,13 @@ function get_configured_interface_with_descr($only_opt = false, $withdisabled =
$iflist = array();
/* if list */
if (isset($config['interfaces'])) {
foreach($config['interfaces'] as $if => $ifdetail) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $if => $ifdetail) {
if ($only_opt && ($if == "wan" || $if == "lan")) {
continue;
}
if (isset($ifdetail['enable']) || $withdisabled == true) {
if (empty($ifdetail['descr'])) {
$iflist[$if] = strtoupper($if);
} else {
$iflist[$if] = strtoupper($ifdetail['descr']);
}
$iflist[$if] = strtoupper($ifdetail['descr']);
}
}
}
......@@ -925,7 +921,7 @@ function get_interface_list($only_active = false)
);
if (isset($config['interfaces'])) {
foreach($config['interfaces'] as $name => $int) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $name => $int) {
if ($int['if'] == $ifname) {
$toput['friendly'] = $name;
break;
......
......@@ -55,7 +55,7 @@ function is_interface_mismatch()
$i = 0;
if (isset($config['interfaces'])) {
foreach ($config['interfaces'] as $ifname => $ifcfg) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) 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 */
$i++;
......
......@@ -163,7 +163,7 @@ if (isset($config['interfaces'][$interface]['ipaddrv6'])) {
if(isset($config['gifs']['gif']) && is_array($config['gifs']['gif'])){
foreach($config['gifs']['gif'] as $gif) {
if($gif['if'] == $interface) {
foreach($config['interfaces'] as $ifname => $ifparent) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $ifname => $ifparent) {
if(($ifparent['if'] == $gif['gifif']) && (isset($ifparent['enable']))) {
$gif['gifif'] = interface_gif_configure($gif);
$confif = convert_real_interface_to_friendly_interface_name($gif['gifif']);
......
......@@ -38,8 +38,8 @@ require_once("filter.inc");
function formInterfaces() {
global $config;
$interfaces = array();
foreach ( get_configured_interface_with_descr(false, true) as $if => $ifdesc) {
$interfaces[$if] = $ifdesc;
foreach (legacy_config_get_interfaces() as $if => $ifdata) {
$interfaces[$if] = $ifdata['descr'];
}
if (isset($config['l2tp']['mode']) && $config['l2tp']['mode'] == "server") {
......
......@@ -39,8 +39,7 @@ if (!isset($config['bridges']['bridged']) || !is_array($config['bridges']['bridg
function bridge_inuse($bridge_if) {
global $config;
foreach ($config['interfaces'] as $if => $intf) {
foreach (legacy_config_get_interfaces() as $if => $intf) {
if ($intf['if'] == $bridge_if) {
return true;
}
......
......@@ -31,8 +31,7 @@ require_once("guiconfig.inc");
require_once("interfaces.inc");
function gif_inuse($gif_intf) {
global $config;
foreach ($config['interfaces'] as $if => $intf) {
foreach (legacy_config_get_interfaces() as $if => $intf) {
if ($intf['if'] == $gif_intf) {
return true;
}
......
......@@ -31,8 +31,7 @@ require_once("guiconfig.inc");
require_once("interfaces.inc");
function gre_inuse($gre_intf) {
global $config;
foreach ($config['interfaces'] as $if => $intf) {
foreach (legacy_config_get_interfaces() as $if => $intf) {
if ($intf['if'] == $gre_intf) {
return true;
}
......
......@@ -33,7 +33,7 @@ require_once("interfaces.inc");
function ppp_inuse($ppp_intf) {
global $config;
if (isset($config['ppps']['ppp']) && !is_array($config['ppps']['ppp'])) {
foreach ($config['interfaces'] as $intf) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $intf) {
if ($intf['if'] == $ppp_intf) {
return true;
}
......
......@@ -32,7 +32,7 @@ require_once("interfaces.inc");
function qinq_inuse($qinq_intf) {
global $config;
foreach ($config['interfaces'] as $if => $intf) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $if => $intf) {
if ($intf['if'] == $qinq_intf) {
return true;
}
......
......@@ -51,7 +51,7 @@ function dhcp_clean_leases()
/* Build list of static MACs */
$staticmacs = array();
foreach($config['interfaces'] as $ifname => $ifarr) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $ifname => $ifarr) {
if (isset($config['dhcpd'][$ifname]['staticmap'])) {
foreach($config['dhcpd'][$ifname]['staticmap'] as $static) {
$staticmacs[] = $static['mac'];
......@@ -145,7 +145,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
/* If no interface is provided, choose first one from interfaces */
if (!isset($if)) {
foreach ($config['interfaces'] as $if_id => $intf) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $if_id => $intf) {
if (!empty($intf['enable']) && is_ipaddrv4($intf['ipaddr'])) {
$if = $if_id;
break;
......@@ -675,7 +675,7 @@ include("head.inc");
<?php
/* active tabs */
$tab_array = array();
foreach ($config['interfaces'] as $if_id => $intf) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $if_id => $intf) {
if (isset($intf['enable']) && is_ipaddrv4($intf['ipaddr'])) {
$ifname = !empty($intf['descr']) ? htmlspecialchars($intf['descr']) : strtoupper($if_id);
if ($if_id == $if) {
......
......@@ -72,7 +72,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
"The DHCPv6 Server can only be enabled on interfaces configured with static " .
"IP addresses. Only interfaces configured with a static IP will be shown."
);
foreach ($config['interfaces'] as $if_id => $intf) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $if_id => $intf) {
if (!empty($intf['enable']) && isset($intf['ipaddrv6']) && is_ipaddrv6($intf['ipaddrv6']) && !is_linklocal($intf['ipaddrv6'])) {
$if = $if_id;
break;
......@@ -443,7 +443,7 @@ include("head.inc");
<?php
/* active tabs */
$tab_array_main = array();
foreach ($config['interfaces'] as $if_id => $intf) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $if_id => $intf) {
if (isset($intf['enable']) && isset($intf['ipaddrv6']) && is_ipaddrv6($intf['ipaddrv6'])) {
$ifname = !empty($intf['descr']) ? htmlspecialchars($intf['descr']) : strtoupper($if_id);
if ($if_id == $if) {
......
......@@ -38,7 +38,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
} else {
$savemsg = "<p><b>" . gettext("The DHCPv6 Server can only be enabled on interfaces configured with static IP addresses") . ".</b></p>" .
"<p><b>" . gettext("Only interfaces configured with a static IP will be shown") . ".</b></p>";
foreach ($config['interfaces'] as $if_id => $intf) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $if_id => $intf) {
if (!empty($intf['enable']) && is_ipaddrv6($intf['ipaddrv6']) && !is_linklocal($oc['ipaddrv6'])) {
$if = $if_id;
break;
......@@ -173,7 +173,7 @@ include("head.inc");
<?php
/* active tabs */
$tab_array_main = array();
foreach ($config['interfaces'] as $if_id => $intf) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $if_id => $intf) {
if (!empty($intf['enable']) && is_ipaddrv6($intf['ipaddrv6'])) {
$ifname = !empty($intf['descr']) ? htmlspecialchars($intf['descr']) : strtoupper($if_id);
if ($if_id == $if) {
......
......@@ -227,7 +227,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
asort($pools);
}
foreach($config['interfaces'] as $ifname => $ifarr) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $ifname => $ifarr) {
if (isset($config['dhcpd'][$ifname]['staticmap'])) {
foreach($config['dhcpd'][$ifname]['staticmap'] as $static) {
$slease = array();
......
......@@ -293,7 +293,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
asort($pools);
}
foreach($config['interfaces'] as $ifname => $ifarr) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $ifname => $ifarr) {
if (isset($config['dhcpdv6'][$ifname]['staticmap'])) {
foreach($config['dhcpdv6'][$ifname]['staticmap'] as $static) {
$slease = array();
......
......@@ -164,7 +164,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
if (is_array($config['interfaces'])) {
foreach ($config['interfaces'] as $if) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $if) {
if (is_ipaddrv4($pconfig['network'])
&& isset($if['ipaddr']) && isset($if['subnet'])
&& is_ipaddrv4($if['ipaddr']) && is_numeric($if['subnet'])
......
......@@ -33,7 +33,7 @@ function traffic_api()
$temp = gettimeofday();
$result['time'] = (double)$temp["sec"] + (double)$temp["usec"] / 1000000.0;
// collect user friendly interface names
foreach ($config['interfaces'] as $interfaceKey => $interfaceData) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $interfaceKey => $interfaceData) {
if (array_key_exists($interfaceData['if'], $result['interfaces'])) {
$result['interfaces'][$interfaceData['if']]['name'] = !empty($interfaceData['descr']) ? $interfaceData['descr'] : $interfaceKey;
}
......
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