diff options
Diffstat (limited to 'install/ui/dns.js')
-rw-r--r-- | install/ui/dns.js | 60 |
1 files changed, 57 insertions, 3 deletions
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 <ayoung@redhat.com> @@ -21,7 +22,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* 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); |