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