From bf30d129ce191f96018824a58264b699bd0fa487 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Wed, 13 May 2020 14:34:09 +0200 Subject: [PATCH] Proxy/MVC: add "S" option for AllowDynamic in InterfaceField type to select only static dynamic ip's, so we can select lo0 in proxy. Although it's not perfect, this seems like the least destructive option at the moment. Eventually we might need to refactor some of the proxy/interface selection, since it doesn't support ipv6 either. --- .../Base/FieldTypes/InterfaceField.php | 18 ++++++++++++------ .../mvc/app/models/OPNsense/Proxy/Proxy.xml | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/InterfaceField.php b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/InterfaceField.php index 688292b21..79fc2f6ff 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/InterfaceField.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/InterfaceField.php @@ -60,7 +60,7 @@ class InterfaceField extends BaseListField /** * @var bool allow dynamic interfaces */ - private $internalAllowDynamic = false; + private $internalAllowDynamic = 0; /** * collect parents for lagg interfaces @@ -120,6 +120,10 @@ class InterfaceField extends BaseListField foreach ($configObj->interfaces->children() as $key => $value) { if (!$this->internalAllowDynamic && !empty($value->internal_dynamic)) { continue; + } elseif ($this->internalAllowDynamic == 2 && !empty($value->internal_dynamic)) { + if (empty($value->ipaddr) && empty($value->ipaddrv6)) { + continue; + } } $allInterfaces[$key] = $value; if (!empty($value->if)) { @@ -185,7 +189,7 @@ class InterfaceField extends BaseListField private function updateInternalCacheKey() { $tmp = serialize($this->internalFilters); - $tmp .= $this->internalAllowDynamic ? "Y" : "N"; + $tmp .= (string)$this->internalAllowDynamic; $tmp .= $this->internalAddParentDevices ? "Y" : "N"; $this->internalCacheKey = md5($tmp); } @@ -218,14 +222,16 @@ class InterfaceField extends BaseListField /** * select if dynamic (hotplug) interfaces maybe selectable - * @param $value boolean value 0/1 + * @param $value Y/N/S (Yes, No, Static) */ public function setAllowDynamic($value) { if (trim(strtoupper($value)) == "Y") { - $this->internalAllowDynamic = true; - } else { - $this->internalAllowDynamic = false; + $this->internalAllowDynamic = 1; + } elseif (trim(strtoupper($value)) == "S") { + $this->internalAllowDynamic = 2; + }else { + $this->internalAllowDynamic = 0; } $this->updateInternalCacheKey(); } diff --git a/src/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.xml b/src/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.xml index 008d99269..7eb274ac7 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.xml +++ b/src/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.xml @@ -239,6 +239,7 @@ N Y + S lan /^(?!0).*$/