dhcp: interface description might not exist

This commit is contained in:
Stephan de Wit 2023-07-27 10:49:05 +02:00
parent b1d85fd398
commit a18406fade
2 changed files with 6 additions and 6 deletions

View File

@ -137,14 +137,14 @@ class LeasesController extends ApiControllerBase
$if = $config->interfaces->{$lease['if']};
if (!empty((string)$if->ipaddr)) {
$intf = $lease['if'];
$intf_descr = (string)$if->descr;
$intf_descr = (string)$if->descr ?: strtoupper($intf);
}
} else {
/* interface not known, check range */
foreach ($if_ranges as $if_name => $if_range) {
if (!empty($lease['address']) && Util::isIPInCIDR($lease['address'], $if_range)) {
$intf = $if_name;
$intf_descr = (string)$config->interfaces->$if_name->descr;
$intf_descr = (string)$config->interfaces->$if_name->descr ?: strtoupper($if_name);
break;
}
}
@ -153,7 +153,7 @@ class LeasesController extends ApiControllerBase
$leases[$idx]['if'] = $intf;
$leases[$idx]['if_descr'] = $intf_descr;
if (!empty($intf) && !array_key_exists($intf, $interfaces)) {
if (!empty($intf_descr) && !array_key_exists($intf, $interfaces)) {
$interfaces[$intf] = $intf_descr;
}
}

View File

@ -170,13 +170,13 @@ class LeasesController extends ApiControllerBase
$if = $config->interfaces->{$lease['if']};
if (!empty((string)$if->ipaddrv6) && Util::isIpAddress((string)$if->ipaddrv6)) {
$intf = $lease['if'];
$intf_descr = (string)$if->descr;
$intf_descr = (string)$if->descr ?: strtoupper($intf);
}
} else {
foreach ($if_ranges as $if_name => $if_range) {
if (!empty($lease['address']) && Util::isIPInCIDR($lease['address'], $if_range)) {
$intf = $if_name;
$intf_descr = (string)$config->interfaces->$if_name->descr;
$intf_descr = (string)$config->interfaces->$if_name->descr ?: strtoupper($if_name);
break;
}
}
@ -185,7 +185,7 @@ class LeasesController extends ApiControllerBase
$leases[$idx]['if'] = $intf;
$leases[$idx]['if_descr'] = $intf_descr;
if (!empty($intf) && !array_key_exists($intf, $interfaces)) {
if (!empty($intf_descr) && !array_key_exists($intf, $interfaces)) {
$interfaces[$intf] = $intf_descr;
}
}