DNS forwarder validator

DNS forwarder's value can consist of IP address and a port.

The syntax is '<IP ADDRESS> port <PORT>'. A new validator was created for this purpose. It is based on IP address validator.

https://fedorahosted.org/freeipa/ticket/2490
This commit is contained in:
Petr Vobornik 2012-03-07 14:42:59 +01:00
parent 1b0ede0776
commit 661d82ad75
3 changed files with 36 additions and 3 deletions

View File

@ -49,7 +49,7 @@ IPA.dns.config_entity = function(spec) {
{
type: 'multivalued',
name: 'idnsforwarders',
validators: [IPA.ip_address_validator()]
validators: [IPA.dnsforwarder_validator()]
},
{
type: 'checkboxes',
@ -167,7 +167,7 @@ IPA.dns.zone_entity = function(spec) {
{
type: 'multivalued',
name: 'idnsforwarders',
validators: [IPA.ip_address_validator()]
validators: [IPA.dnsforwarder_validator()]
},
{
type: 'checkboxes',
@ -2170,7 +2170,6 @@ IPA.dns.ptr_redirection_dialog = function(spec) {
return that;
};
IPA.ip_address_validator = function(spec) {
spec = spec || {};
@ -2202,6 +2201,8 @@ IPA.ip_address_validator = function(spec) {
(that.address_type === 'IPv6' && net_type === 'v6'));
};
that.ip_address_validate = that.validate;
return that;
};
@ -2221,6 +2222,36 @@ IPA.ip_v6_address_validator = function(spec) {
return IPA.ip_address_validator(spec);
};
IPA.dnsforwarder_validator = function(spec) {
spec = spec || {};
var that = IPA.ip_address_validator(spec);
that.validate = function(value) {
var address_part = value;
if (value.indexOf(' ') > - 1) {
var parts = value.split(' ');
if (parts.length !== 3 || parts[1] !== 'port') return that.false_result();
address_part = parts[0];
var port = parts[2];
if (!port.match(/^[1-9]\d*$|^0$/) || port < 0 || port > 65535) {
var message = IPA.messages.widget.validation.port;
message = message.replace('${port}', port);
return that.false_result(message);
}
}
return that.ip_address_validate(address_part);
};
return that;
};
IPA.network_validator = function(spec) {
spec = spec || {};

View File

@ -452,6 +452,7 @@
"max_value": "Maximum value is ${value}",
"min_value": "Minimum value is ${value}",
"net_address": "Not a valid network address",
"port": "'${port}' is not a valid port",
"required": "Required field",
"unsupported": "Unsupported value"
}

View File

@ -591,6 +591,7 @@ class i18n_messages(Command):
"max_value": _("Maximum value is ${value}"),
"min_value": _("Minimum value is ${value}"),
"net_address": _("Not a valid network address"),
"port": _("'${port}' is not a valid port"),
"required": _("Required field"),
"unsupported": _("Unsupported value"),
},