diff --git a/src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasContentField.php b/src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasContentField.php new file mode 100644 index 000000000..6529d432b --- /dev/null +++ b/src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasContentField.php @@ -0,0 +1,122 @@ +separatorchar, (string)$this); + foreach ($selectlist as $optKey) { + $result[$optKey] = array("value"=>$optKey, "selected" => 1); + } + return $result; + } + + /** + * Validate port alias options + * @param array $data to validate + * @return bool|Callback + */ + private function validatePort($data) + { + $message = array(); + foreach ($data as $key => $value){ + foreach (explode($this->separatorchar, $value) as $key => $value){ + if (!Util::isAlias($value) && !Util::isPort($value, true)){ + $message[] = $value; + } + } + } + if (!empty($message)) { + // When validation fails use a callback to return the message so we can add the failed items + return new Callback([ + "message" =>sprintf(gettext('Entry "%s" is not a valid port number.'), implode("|", $message)), + "callback" => function() {return false;}] + ); + } + return true; + } + + /** + * retrieve field validators for this field type + * @return array + */ + public function getValidators() + { + $validators = parent::getValidators(); + if ($this->internalValue != null) { + $alias_type = (string)$this->getParentNode()->type; + + switch ($alias_type) { + case "port": + $validators[] = new Callback(["callback" => function ($data) { + return $this->validatePort($data);} + ]); + break; + default: + break; + } + } + return $validators; + } +} diff --git a/src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasNameField.php b/src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasNameField.php index 4ff055806..9bf2ef3d4 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasNameField.php +++ b/src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasNameField.php @@ -34,7 +34,7 @@ use Phalcon\Validation\Validator\ExclusionIn; use Phalcon\Validation\Validator\Callback; /** - * Class AliasField + * Class AliasNameField * @package OPNsense\Base\FieldTypes */ class AliasNameField extends BaseField @@ -51,7 +51,7 @@ class AliasNameField extends BaseField /** * retrieve field validators for this field type - * @return array returns Text/regex validator + * @return array returns list of validators */ public function getValidators() {