diff --git a/install/ui/dns.js b/install/ui/dns.js index 546835860..33b21e4cf 100644 --- a/install/ui/dns.js +++ b/install/ui/dns.js @@ -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 || {}; diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json index 36a3388d9..8aa476082 100644 --- a/install/ui/test/data/ipa_init.json +++ b/install/ui/test/data/ipa_init.json @@ -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" } diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py index 541d85cfb..23b52372f 100644 --- a/ipalib/plugins/internal.py +++ b/ipalib/plugins/internal.py @@ -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"), },