Firewall: Aliases - remove Phalcon component usage in model

for https://github.com/opnsense/core/issues/6389
This commit is contained in:
Ad Schellevis 2024-04-30 21:17:00 +02:00
parent 100aac2fb8
commit cd0e45edf6
2 changed files with 17 additions and 23 deletions

View File

@ -30,8 +30,6 @@ namespace OPNsense\Firewall\FieldTypes;
use OPNsense\Base\FieldTypes\BaseField;
use OPNsense\Base\Validators\CallbackValidator;
use Phalcon\Filter\Validation\Validator\Regex;
use Phalcon\Filter\Validation\Validator\ExclusionIn;
use OPNsense\Core\Config;
use OPNsense\Base\Messages\Message;
use OPNsense\Firewall\Util;

View File

@ -30,8 +30,6 @@ namespace OPNsense\Firewall\FieldTypes;
use OPNsense\Base\FieldTypes\BaseField;
use OPNsense\Base\Validators\CallbackValidator;
use Phalcon\Filter\Validation\Validator\Regex;
use Phalcon\Filter\Validation\Validator\ExclusionIn;
/**
* Class AliasNameField
@ -70,28 +68,26 @@ class AliasNameField extends BaseField
'upperlimit', 'urpf-failed', 'user'
);
if ($this->internalValue != null) {
// add validations to deny reserved keywords, service/protocol names and invalid characters
$validators[] = new ExclusionIn(array(
'message' => sprintf(
gettext('The name cannot be the internally reserved keyword "%s".'),
(string)$this
),
'domain' => $reservedwords));
$validators[] = new Regex([
'message' => gettext('The name must start with a letter or single underscore, be less than 32 characters and only consist of alphanumeric characters or underscores.'),
/* avoids single "_" and prefixes of "__" here too */
'pattern' => '/^([a-zA-Z]|(([_a-zA-Z][a-zA-Z0-9]|[a-zA-Z][_a-zA-Z0-9])[_a-zA-Z0-9]{0,29}))$/'
]);
$validators[] = new CallbackValidator(
[
"callback" => function ($value) {
if (
getservbyname($value, 'tcp') ||
getservbyname($value, 'udp') || getprotobyname($value)
) {
return array(gettext('Reserved protocol or service names may not be used'));
"callback" => function ($value) use ($reservedwords) {
$result = [];
/* avoids single "_" and prefixes of "__" here too */
if (!preg_match(
'/^([a-zA-Z]|(([_a-zA-Z][a-zA-Z0-9]|[a-zA-Z][_a-zA-Z0-9])[_a-zA-Z0-9]{0,29}))$/',
$value
)) {
$result[] = gettext('The name must start with a letter or single underscore, be less than 32 characters and only consist of alphanumeric characters or underscores.');
}
return array();
if (in_array($value, $reservedwords)) {
$result[] = gettext('The name cannot be the internally reserved keyword "%s".');
}
if (
getservbyname($value, 'tcp') || getservbyname($value, 'udp') || getprotobyname($value)
) {
$result[] = gettext('Reserved protocol or service names may not be used');
}
return $result;
}
]
);