System: Gateways: Configuration - prevent removal when gateway is bound to an interface, closes https://github.com/opnsense/core/issues/7270

This commit is contained in:
Ad Schellevis 2024-02-25 20:08:07 +01:00
parent 042486e704
commit dd394645ac

View File

@ -194,6 +194,16 @@ class SettingsController extends ApiMutableModelControllerBase
if ($uuid != null) {
$gateway = $this->getModel()->getNodeByReference('gateway_item.' . $uuid);
$cfg = Config::getInstance()->object();
foreach ($cfg->interfaces->children() as $tag => $interface) {
if ((string)$interface->gateway == (string)$gateway->name) {
throw new UserException(sprintf(
gettext("Gateway %s cannot be deleted because it is in use on Interface '%s'"),
$gateway->name,
$interface->descr ?? $tag
));
}
}
$groups = [];
foreach ($cfg->gateways->children() as $tag => $gw_group) {
if ($tag == 'gateway_group' && !empty($gw_group)) {