From a1f8c39f88dac7c0999175528d4c1e90a8dd1210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Voborn=C3=ADk?= Date: Thu, 9 Feb 2012 17:21:09 +0100 Subject: [PATCH] DNS Zone UI: added new attributes New attributes were added to DNS zone details facet. Attributes: idnsallowquery idnsallowtransfer idnsforwarders idnsforwardpolicy idnsallowsyncptr New network address validator created for idnsallowquery and idnsallowtransfer attributes. Network address validator also added to dnszone adder dialog - from_ip field. https://fedorahosted.org/freeipa/ticket/2351 --- install/ui/dns.js | 288 +++++++++++++++++-------- install/ui/field.js | 9 +- install/ui/test/data/dnszone_show.json | 20 ++ install/ui/test/data/ipa_init.json | 1 + install/ui/widget.js | 4 +- ipalib/plugins/internal.py | 1 + 6 files changed, 228 insertions(+), 95 deletions(-) diff --git a/install/ui/dns.js b/install/ui/dns.js index 5c6fc6c03..35c945b2f 100644 --- a/install/ui/dns.js +++ b/install/ui/dns.js @@ -57,12 +57,13 @@ IPA.dns.zone_entity = function(spec) { }). details_facet({ factory: IPA.dnszone_details_facet, + command_mode: 'info', sections: [{ name: 'identity', fields: [ 'idnsname', { - type: 'radio', + type: 'enable', name: 'idnszoneactive', label: IPA.messages.status.label, options: [ @@ -96,6 +97,43 @@ IPA.dns.zone_entity = function(spec) { { type: 'textarea', name: 'idnsupdatepolicy' + }, + { + type: 'netaddr', + name: 'idnsallowquery', + validators: [ + IPA.network_validator({ + specials: ['any', 'none', + 'localhost', 'localnets'], + allow_negation: true, + allow_host_address: true + })] + }, + { + type: 'netaddr', + name: 'idnsallowtransfer', + validators: [ + IPA.network_validator({ + specials: ['any', 'none', + 'localhost', 'localnets'], + allow_negation: true, + allow_host_address: true + })] + }, + { + type: 'multivalued', + name: 'idnsforwarders', + validators: [IPA.ip_address_validator()] + }, + { + type: 'checkboxes', + name: 'idnsforwardpolicy', + mutex: true, + options: IPA.create_options(['only', 'first']) + }, + { + type: 'checkbox', + name: 'idnsallowsyncptr' } ] }] @@ -142,7 +180,8 @@ IPA.dns.zone_entity = function(spec) { { type: 'dnszone_name', name: 'name_from_ip', - radio_name: 'dnszone_name_type' + radio_name: 'dnszone_name_type', + validators: [IPA.network_validator()] } ] }, @@ -177,97 +216,12 @@ IPA.dnszone_details_facet = function(spec) { var that = IPA.details_facet(spec); - that.update = function(on_success, on_error) { + that.update_on_success = function(data, text_status, xhr) { + that.refresh(); + }; - var args = that.get_primary_key(); - - var modify_operation = { - execute: false, - command: IPA.command({ - entity: that.entity.name, - method: 'mod', - args: args, - options: { all: true, rights: true } - }) - }; - - var enable_operation = { - execute: false, - command: IPA.command({ - entity: that.entity.name, - method: 'enable', - args: args, - options: { all: true, rights: true } - }) - }; - - var record = {}; - that.save(record); - - var fields = that.fields.get_fields(); - for (var i=0; i -1) { + return that.true_result(); + } + + var address_part, mask_part; + + if (value.indexOf('/') > -1) { + + var parts = value.split('/'); + + if (parts.length === 2) { + address_part = parts[0]; + mask_part = parts[1]; + + if (mask_part === '') return that.false_result(); + + } else { + return that.false_result(); + } + } else if (that.allow_host_address) { + address_part = value; + } else { + return that.false_result(); + } + + + if (that.allow_negation && address_part.indexOf('!') === 0) { + address_part = address_part.substring(1); + } + + var address = NET.ip_address(address_part); + if (!address.valid) return that.false_result(); + + if (mask_part) { + + var mask = parseInt(mask_part, 10); + + var mask_length = 32; + if (address.type === 'v6') mask_length = 128; + + if (isNaN(mask) || mask < 8 || mask > mask_length) { + return that.false_result(); + } + } + + return that.true_result(); + }; + + return that; +}; IPA.register('dnszone', IPA.dns.zone_entity); IPA.register('dnsrecord', IPA.dns.record_entity); diff --git a/install/ui/field.js b/install/ui/field.js index 46802be6c..2922ce0fb 100644 --- a/install/ui/field.js +++ b/install/ui/field.js @@ -550,11 +550,16 @@ IPA.multivalued_field = function(spec) { that.validate = function() { + var values = that.save(); + + return that.validate_core(values); + }; + + that.validate_core = function(values) { + that.hide_error(); that.valid = true; - var values = that.save(); - if (that.is_empty(values)) { return that.valid; } diff --git a/install/ui/test/data/dnszone_show.json b/install/ui/test/data/dnszone_show.json index b7d5b87b2..b113f7d4e 100644 --- a/install/ui/test/data/dnszone_show.json +++ b/install/ui/test/data/dnszone_show.json @@ -18,6 +18,11 @@ "dsrecord": "rscwo", "hinforecord": "rscwo", "idnsallowdynupdate": "rscwo", + "idnsallowquery": "rscwo", + "idnsallowsyncptr": "rscwo", + "idnsallowtransfer": "rscwo", + "idnsforwarders": "rscwo", + "idnsforwardpolicy": "rscwo", "idnsname": "rscwo", "idnssoaexpire": "rscwo", "idnssoaminimum": "rscwo", @@ -51,6 +56,21 @@ "idnsallowdynupdate": [ "FALSE" ], + "idnsallowquery": [ + "any" + ], + "idnsallowsyncptr": [ + "TRUE" + ], + "idnsallowtransfer": [ + "none" + ], + "idnsforwarders": [ + "2003:beef::24" + ], + "idnsforwardpolicy": [ + "only" + ], "idnsname": [ "example.com" ], diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json index 267ab5c9f..8e07dbc92 100644 --- a/install/ui/test/data/ipa_init.json +++ b/install/ui/test/data/ipa_init.json @@ -430,6 +430,7 @@ "ip_v6_address": "Not a valid IPv6 address", "max_value": "Maximum value is ${value}", "min_value": "Minimum value is ${value}", + "net_address": "Not a valid network address", "required": "Required field" } } diff --git a/install/ui/widget.js b/install/ui/widget.js index cc5f4f78e..5ce7261e8 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -533,10 +533,12 @@ IPA.multivalued_widget = function(spec) { that.test_dirty_row = function(row) { - if(row.deleted || row.is_new) return true; + if (row.deleted || row.is_new) return true; var values = row.widget.save(); + if (row.original_values.length !== values.length) return true; + for (var i=0; i