From c7ae0c20db86aeace6224425f3ccf7e4726d6b46 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Mon, 2 Jan 2012 16:55:51 +0100 Subject: Added client-side validation of A and AAAA DNS records https://fedorahosted.org/freeipa/ticket/1466 --- install/ui/dns.js | 60 ++++++++++++++++++++++++++++++++++++-- install/ui/index.html | 1 + install/ui/test/data/ipa_init.json | 3 ++ 3 files changed, 61 insertions(+), 3 deletions(-) (limited to 'install') diff --git a/install/ui/dns.js b/install/ui/dns.js index 4853a944..f4f93389 100644 --- a/install/ui/dns.js +++ b/install/ui/dns.js @@ -1,5 +1,6 @@ /*jsl:import ipa.js */ /*jsl:import search.js */ +/*jsl:import net.js */ /* Authors: * Adam Young @@ -21,7 +22,8 @@ * along with this program. If not, see . */ -/* REQUIRES: ipa.js, details.js, search.js, add.js, facet.js, entity.js, widget.js */ +/* REQUIRES: ipa.js, details.js, search.js, add.js, facet.js, entity.js, + * net.js, widget.js */ IPA.dns = {}; @@ -526,13 +528,15 @@ IPA.dns.record_entity = function(spec) { type: 'multivalued', name: 'arecord', metadata: { primary_key: false }, - label: 'A' + label: 'A', + validators: [ IPA.ip_v4_address_validator() ] }, { type: 'multivalued', name: 'aaaarecord', metadata: { primary_key: false }, - label: 'AAAA' + label: 'AAAA', + validators: [ IPA.ip_v6_address_validator() ] }, { type: 'multivalued', @@ -824,5 +828,55 @@ IPA.dnsrecord_get_delete_values = function() { return value_array; }; +IPA.ip_address_validator = function(spec) { + + var that = IPA.validator(spec); + + that.address_type = spec.address_type; + that.message = spec.message || IPA.messages.widget.validation.ip_address; + + that.validate = function(value) { + + var address = NET.ip_address(value); + + if (!address.valid || !that.is_type_match(address.type)) { + return { + valid: false, + message: that.message + }; + } + + return { valid: true }; + }; + + that.is_type_match = function(net_type) { + + return (!that.address_type || + + (that.address_type === 'IPv4' && + (net_type === 'v4-quads' || net_type === 'v4-int')) || + + (that.address_type === 'IPv6' && net_type === 'v6')); + }; + + return that; +}; + +IPA.ip_v4_address_validator = function(spec) { + + spec = spec || {}; + spec.address_type = 'IPv4'; + spec.message = IPA.messages.widget.validation.ip_v4_address; + return IPA.ip_address_validator(spec); +}; + +IPA.ip_v6_address_validator = function(spec) { + + spec = spec || {}; + spec.address_type = 'IPv6'; + spec.message = IPA.messages.widget.validation.ip_v6_address; + return IPA.ip_address_validator(spec); +}; + IPA.register('dnszone', IPA.dns.zone_entity); IPA.register('dnsrecord', IPA.dns.record_entity); diff --git a/install/ui/index.html b/install/ui/index.html index 5c0ebdbb..6239deba 100644 --- a/install/ui/index.html +++ b/install/ui/index.html @@ -10,6 +10,7 @@ + diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json index a5ef756e..77af2f8f 100644 --- a/install/ui/test/data/ipa_init.json +++ b/install/ui/test/data/ipa_init.json @@ -376,6 +376,9 @@ "validation": { "error": "Text does not match field pattern", "integer": "Must be an integer", + "ip_address": "Not a valid IP address", + "ip_v4_address": "Not a valid IPv4 address", + "ip_v6_address": "Not a valid IPv6 address", "max_value": "Maximum value is ${value}", "min_value": "Minimum value is ${value}", "required": "Required field" -- cgit