From c5bfeb1ed0fc8a31fcfea475cccc98da37f7c17e Mon Sep 17 00:00:00 2001 From: Ana Krivokapic Date: Thu, 9 May 2013 18:47:12 +0200 Subject: Prompt for nameserver IP address in dnszone-add Prompt for nameserver IP address in interactive mode of dnszone-add. Add a corresponding field to dnszone creation dialog in the web UI. This parameter is required if and only if: * New zone is a forward zone * Nameserver is defined inside the new zone Add a new unit test to cover this functionality. https://fedorahosted.org/freeipa/ticket/3603 --- install/ui/src/freeipa/dns.js | 58 +++++++++++++++++++++++++++++ install/ui/src/freeipa/widget.js | 4 ++ install/ui/test/data/ipa_init_commands.json | 11 ++++++ 3 files changed, 73 insertions(+) (limited to 'install/ui') diff --git a/install/ui/src/freeipa/dns.js b/install/ui/src/freeipa/dns.js index 5024e8b7..52cbb81f 100644 --- a/install/ui/src/freeipa/dns.js +++ b/install/ui/src/freeipa/dns.js @@ -299,6 +299,11 @@ return { name: 'other', fields: [ 'idnssoamname', + { + name: 'ip_address', + validators: [ 'ip_address' ], + metadata: '@mc-opt:dnszone_add:ip_address' + }, { name: 'idnssoarname', required: false @@ -576,11 +581,64 @@ IPA.dnszone_adder_dialog = function(spec) { var that = IPA.entity_adder_dialog(spec); + function ends_with(str, suffix) { + return str.indexOf(suffix, str.length - suffix.length) !== -1; + } + + var init = function() { + var zone_w = that.fields.get_field('idnsname').widget; + var reverse_zone_w = that.fields.get_field('name_from_ip').widget; + var ns_w = that.fields.get_field('idnssoamname').widget; + + zone_w.value_changed.attach(that.check_ns_ip); + reverse_zone_w.value_changed.attach(that.check_ns_ip); + ns_w.value_changed.attach(that.check_ns_ip); + }; + + that.check_ns_ip = function() { + var ip_address_f = that.fields.get_field('ip_address'); + var zone_w = that.fields.get_field('idnsname').widget; + var ns_w = that.fields.get_field('idnssoamname').widget; + + var zone = zone_w.save()[0] || ''; + var ns = ns_w.save()[0] || ''; + + var zone_is_reverse = !zone_w.is_enabled() || + ends_with(zone, '.in-addr.arpa.') || + ends_with(zone, '.ip6.arpa.'); + var relative_ns = true; + var ns_in_zone = false; + + if (ns && ns[ns.length-1] === '.') { + relative_ns = false; + ns = ns.slice(0, -1); + } + + if (zone && zone[zone.length-1] === '.') { + zone = zone.slice(0, -1); + } + + if (ns && zone && ends_with(ns, '.' + zone)) { + ns_in_zone = true; + } + + if (!zone_is_reverse && (relative_ns || ns_in_zone)) { + ip_address_f.set_enabled(true); + ip_address_f.set_required(true); + } else { + ip_address_f.reset(); + ip_address_f.set_required(false); + ip_address_f.set_enabled(false); + } + }; + that.create = function() { that.entity_adder_dialog_create(); that.container.addClass('dnszone-adder-dialog'); }; + init(); + return that; }; diff --git a/install/ui/src/freeipa/widget.js b/install/ui/src/freeipa/widget.js index 8f1208e0..4570c903 100644 --- a/install/ui/src/freeipa/widget.js +++ b/install/ui/src/freeipa/widget.js @@ -303,6 +303,10 @@ IPA.text_widget = function(spec) { } }; + that.is_enabled = function(value) { + return !that.input.prop('disabled'); + }; + that.set_enabled = function(value) { that.input.prop('disabled', !value); diff --git a/install/ui/test/data/ipa_init_commands.json b/install/ui/test/data/ipa_init_commands.json index a7e00ba5..b66ae4dd 100644 --- a/install/ui/test/data/ipa_init_commands.json +++ b/install/ui/test/data/ipa_init_commands.json @@ -7651,6 +7651,17 @@ "required": true, "type": "unicode" }, + { + "attribute": true, + "class": "Str", + "doc": "Add forward record for nameserver located in the created zone", + "flags": [], + "label": "Nameserver IP address", + "name": "ip_address", + "noextrawhitespace": true, + "required": true, + "type": "unicode" + }, { "attribute": true, "class": "Str", -- cgit