From ef9c2b4df751b5f4c09067be44193e39cd78b391 Mon Sep 17 00:00:00 2001 From: Monviech <79600909+Monviech@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:14:20 +0200 Subject: [PATCH] Update VxLan.php - Add input validations to model (#6899) * Update VxLan.php - Add multiple input validations to model * Update VxLan.php - add isFieldChanged and gettext function --- .../app/models/OPNsense/Interfaces/VxLan.php | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/opnsense/mvc/app/models/OPNsense/Interfaces/VxLan.php b/src/opnsense/mvc/app/models/OPNsense/Interfaces/VxLan.php index f0c1e7d5a..df3f03dcc 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Interfaces/VxLan.php +++ b/src/opnsense/mvc/app/models/OPNsense/Interfaces/VxLan.php @@ -1,7 +1,7 @@ vxlan->iterateItems() as $vxlan) { + $vxlangroup = (string) $vxlan->vxlangroup; + $vxlanremote = (string) $vxlan->vxlanremote; + $vxlandev = (string) $vxlan->vxlandev; + + // Validate that values in Fields have been changed, prevents configuration save lockout when invalid data is present. + if ($validateFullModel || + $vxlan->vxlangroup->isFieldChanged() || + $vxlan->vxlanremote->isFieldChanged() || + $vxlan->vxlandev->isFieldChanged() + ) { + // Validation 1: At least one of vxlangroup and vxlanremote must be populated, but not both. + if ((!empty($vxlangroup) && !empty($vxlanremote)) || + (empty($vxlangroup) && empty($vxlanremote)) + ) { + $messages->appendMessage(new Message( + gettext("Remote address -or- Multicast group has to be specified"), + "vxlan.vxlanremote", + "GroupOrRemote" + )); + $messages->appendMessage(new Message( + gettext("Multicast group -or- Remote address has to be specified"), + "vxlan.vxlangroup", + "GroupOrRemote" + )); + } + + // Validation 2: If vxlanremote is populated, vxlandev must be an empty string. + if (!empty($vxlanremote) && !empty($vxlandev)) { + $messages->appendMessage(new Message( + gettext("Remote address is specified, Device must be None"), + "vxlan.vxlandev", + "DeviceRequirementForRemote" + )); + } + + // Validation 3: If vxlangroup is populated, vxlandev must not be an empty string. + if (!empty($vxlangroup) && empty($vxlandev)) { + $messages->appendMessage(new Message( + gettext("Multicast group is specified, a Device must also be specified"), + "vxlan.vxlandev", + "DeviceRequirementForGroup" + )); + } + } + } + + return $messages; + } }