From 1f3d8003f7ccb7793be6452942f62d10433e7f27 Mon Sep 17 00:00:00 2001 From: Petr Voborník Date: Thu, 19 Jan 2012 10:28:44 +0100 Subject: Modifying DNS UI to benefit from new DNS API DNS UI was modified to offer structured way of defining DNS records. https://fedorahosted.org/freeipa/ticket/2208 --- install/ui/dns.js | 1316 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 1109 insertions(+), 207 deletions(-) (limited to 'install/ui/dns.js') diff --git a/install/ui/dns.js b/install/ui/dns.js index d23eca3a..d30cc312 100644 --- a/install/ui/dns.js +++ b/install/ui/dns.js @@ -4,6 +4,7 @@ /* Authors: * Adam Young + * Petr Vobornik * * Copyright (C) 2010 Red Hat * see file 'COPYING' for use and warranty information @@ -439,6 +440,16 @@ IPA.dnszone_name_widget = function(spec) { IPA.widget_factories['dnszone_name'] = IPA.dnszone_name_widget; +IPA.force_dnszone_add_checkbox_widget = function(spec) { + var metadata = IPA.get_command_option('dnszone_add', spec.name); + spec.label = metadata.label; + spec.tooltip = metadata.doc; + return IPA.checkbox_widget(spec); +}; + +IPA.widget_factories['force_dnszone_add_checkbox'] = IPA.force_dnszone_add_checkbox_widget; +IPA.field_factories['force_dnszone_add_checkbox'] = IPA.checkbox_field; + IPA.dnszone_adder_dialog = function(spec) { spec = spec || {}; @@ -536,6 +547,334 @@ IPA.dns.record_search_facet = function(spec) { return that; }; +IPA.dns.record_metadata = null; +IPA.dns.get_record_metadata = function() { + + if (IPA.dns.record_metadata === null) { + + IPA.dns.record_metadata = [ + { + name: 'arecord', + attributes: [ + { + name: 'a_part_ip_address', + validators: [IPA.ip_v4_address_validator()] + } + ], + columns: ['a_part_ip_address'] + }, + { + name: 'aaaarecord', + attributes: [ + { + name:'aaaa_part_ip_address', + validators: [IPA.ip_v6_address_validator()] + } + ], + columns: ['aaaa_part_ip_address'] + }, + { + name: 'a6record', + attributes: [ + 'a6record' + ], + columns: ['a6record'] + }, + { + name: 'afsdbrecord', + attributes: [ + 'afsdb_part_subtype', + 'afsdb_part_hostname' + ], + columns: ['afsdb_part_subtype', 'afsdb_part_hostname'] + }, + { + name: 'certrecord', + attributes: [ + 'cert_part_type', + 'cert_part_key_tag', + 'cert_part_algorithm', + { + name: 'cert_part_certificate_or_crl', + type: 'textarea' + } + ], + columns: ['cert_part_type','cert_part_key_tag','cert_part_algorithm'] + }, + { + name: 'cnamerecord', + attributes: [ + 'cname_part_hostname' + ], + columns: ['cname_part_hostname'] + }, + { + name: 'dnamerecord', + attributes: [ + 'dname_part_target' + ], + columns: ['dname_part_target'] + }, + { + name: 'dsrecord', + attributes: [ + 'ds_part_key_tag', + 'ds_part_algorithm', + 'ds_part_digest_type', + { + name: 'ds_part_digest', + type: 'textarea' + } + ], + columns: ['ds_part_key_tag', 'ds_part_algorithm', + 'ds_part_digest_type'] + }, + { + name: 'keyrecord', + attributes: [ + 'key_part_flags', + 'key_part_protocol', + 'key_part_algorithm', + { + name: 'key_part_public_key', + type: 'textarea' + } + ], + columns: ['key_part_flags', 'key_part_protocol', + 'key_part_algorithm'] + }, + { + name: 'kxrecord', + attributes: [ + 'kx_part_preference', + 'kx_part_exchanger' + ], + columns: ['kx_part_preference', 'kx_part_exchanger'] + }, + { + name: 'locrecord', + attributes: [ + 'loc_part_lat_deg', + 'loc_part_lat_min', + 'loc_part_lat_sec', + { + name: 'loc_part_lat_dir', + options: IPA.create_options(['N','S']), + type: 'radio', + widget_opt: { + default_value: 'N' + } + }, + 'loc_part_lon_deg', + 'loc_part_lon_min', + 'loc_part_lon_sec', + { + name: 'loc_part_lon_dir', + options: IPA.create_options(['E','W']), + type: 'radio', + widget_opt: { + default_value: 'E' + } + }, + 'loc_part_altitude', + 'loc_part_size', + 'loc_part_h_precision', + 'loc_part_v_precision' + ], + columns: ['dnsdata'] + }, + { + name: 'mxrecord', + attributes: [ + 'mx_part_preference', + 'mx_part_exchanger' + ], + columns: ['mx_part_preference', 'mx_part_exchanger'] + }, + { + name: 'naptrrecord', + attributes: [ + 'naptr_part_order', + 'naptr_part_preference', + { + name: 'naptr_part_flags', + type: 'select', + options: IPA.create_options(['S', 'A', 'U', 'P']) + }, + 'naptr_part_service', + 'naptr_part_regexp', + 'naptr_part_replacement' + ], + adder_attributes: [], + columns: ['dnsdata'] + }, + { + name: 'nsrecord', + attributes: [ + 'ns_part_hostname' + ], + adder_attributes: [], + columns: ['ns_part_hostname'] + }, + { + name: 'nsecrecord', + attributes: [ + 'nsec_part_next', + 'nsec_part_types' +// TODO: nsec_part_types is multivalued attribute. New selector +// widget or at least new validator should be created. +// { +// name: 'nsec_part_types', +// options: IPA.create_options(['SOA', 'A', 'AAAA', 'A6', 'AFSDB', +// 'APL', 'CERT', 'CNAME', 'DHCID', 'DLV', 'DNAME', 'DNSKEY', +// 'DS', 'HIP', 'IPSECKEY', 'KEY', 'KX', 'LOC', 'MX', 'NAPTR', +// 'NS', 'NSEC','NSEC3', 'NSEC3PARAM', 'PTR', 'RRSIG', 'RP', +// 'SIG', 'SPF', 'SRV', 'SSHFP', 'TA', 'TKEY', 'TSIG', 'TXT']), +// type: 'select' +// } + ], + adder_attributes: [], + columns: [ 'nsec_part_next', 'nsec_part_types'] + }, + { + name: 'ptrrecord', + attributes: [ + 'ptr_part_hostname' + ], + adder_attributes: [], + columns: [ 'ptr_part_hostname'] + }, + { + name: 'rrsigrecord', + attributes: [ + { + name: 'rrsig_part_type_covered', + type: 'select', + options: IPA.create_options(['SOA', 'A', 'AAAA', 'A6', 'AFSDB', + 'APL', 'CERT', 'CNAME', 'DHCID', 'DLV', 'DNAME', + 'DNSKEY', 'DS', 'HIP', 'IPSECKEY', 'KEY', 'KX', + 'LOC', 'MX', 'NAPTR', 'NS', 'NSEC', 'NSEC3', + 'NSEC3PARAM', 'PTR', 'RRSIG', 'RP', 'SPF', 'SRV', + 'SSHFP', 'TA', 'TKEY', 'TSIG', 'TXT']) + }, + 'rrsig_part_algorithm', + 'rrsig_part_labels', + 'rrsig_part_original_ttl', + 'rrsig_part_signature_expiration', + 'rrsig_part_signature_inception', + 'rrsig_part_key_tag', + 'rrsig_part_signers_name', + { + name: 'rrsig_part_signature', + type: 'textarea' + } + ], + adder_attributes: [], + columns: ['dnsdata'] + }, + { + name: 'sigrecord', + attributes: [ + { + name: 'sig_part_type_covered', + type: 'select', + options: IPA.create_options(['SOA', 'A', 'AAAA', 'A6', 'AFSDB', + 'APL', 'CERT', 'CNAME', 'DHCID', 'DLV', 'DNAME', + 'DNSKEY', 'DS', 'HIP', 'IPSECKEY', 'KEY', 'KX', + 'LOC', 'MX', 'NAPTR', 'NS', 'NSEC', 'NSEC3', + 'NSEC3PARAM', 'PTR', 'RRSIG', 'RP', 'SPF', 'SRV', + 'SSHFP', 'TA', 'TKEY', 'TSIG', 'TXT']) + }, + 'sig_part_algorithm', + 'sig_part_labels', + 'sig_part_original_ttl', + 'sig_part_signature_expiration', + 'sig_part_signature_inception', + 'sig_part_key_tag', + 'sig_part_signers_name', + { + name: 'sig_part_signature', + type: 'textarea' + } + ], + adder_attributes: [], + columns: ['dnsdata'] + }, + { + name: 'srvrecord', + attributes: [ + 'srv_part_priority', + 'srv_part_weight', + 'srv_part_port', + 'srv_part_target' + ], + adder_attributes: [], + columns: ['srv_part_priority', 'srv_part_weight', 'srv_part_port', + 'srv_part_target'] + }, + { + name: 'sshfprecord', + attributes: [ + 'sshfp_part_algorithm', + 'sshfp_part_fp_type', + { + name: 'sshfp_part_fingerprint', + type: 'textarea' + } + ], + adder_attributes: [], + columns: ['sshfp_part_algorithm', 'sshfp_part_fp_type'] + }, + { + name: 'txtrecord', + attributes: [ + 'txt_part_data' + ], + adder_attributes: [], + columns: ['txt_part_data'] + } + ]; + + //set required flags for attributes based on 'dnsrecord_optional' flag + //in param metadata + + for (var i=0; i -1) { + IPA.dns.record_prepare_details_for_type(type, fields, standard_record_section); + } else { + IPA.dns.record_prepare_details_for_type(type, fields, other_record_section); + } + } + + IPA.dns.extend_spec(spec, fields, widgets); +}; + +IPA.dns.record_prepare_details_for_type = function(type, fields, container) { + + var index = type.name.search('record$'); + var dnstype = type.name.substring(0, index).toUpperCase(); + + var type_widget = { + name: type.name, + type: 'dnsrecord_type_table', + record_type: type.name, + value_attribute: 'dnsdata', + dnstype: dnstype, + columns: type.columns + }; + + container.widgets.push(type_widget); + + var field = { + name: type.name, + type: 'dnsrecord_type_table', + dnstype: dnstype, + label: dnstype, + widget: container.name+'.'+type.name + }; + + fields.push(field); +}; + +/* + * Widgets and policies + */ + + IPA.dnsrecord_host_link_field = function(spec) { var that = IPA.link_field(spec); that.other_pkeys = function() { @@ -829,22 +1200,75 @@ IPA.field_factories['dnsrecord_host_link'] = IPA.dnsrecord_host_link_field; IPA.widget_factories['dnsrecord_host_link'] = IPA.link_widget; IPA.dns_record_types = function() { - var attrs = IPA.metadata.objects.dnsrecord.default_attributes; + + //only supported + var attrs = ['A', 'AAAA', 'A6', 'AFSDB', 'CERT', 'CNAME', 'DNAME', + 'DS','KEY', 'KX', 'LOC', 'MX', 'NAPTR', 'NS', 'NSEC', + 'PTR', 'RRSIG', 'SRV', 'SIG', 'SSHFP', 'TXT']; var record_types = []; for (var i=0; i -1) { - var rec_type = { - label: attr.substring(0, index).toUpperCase(), - value: attr - }; - record_types.push(rec_type); - } + + var rec_type = { + label: attr, + value: attr.toLowerCase()+'record' + }; + record_types.push(rec_type); } return record_types; }; +IPA.dns.record_get_attr_label = function(part_name) { + + var metadata = IPA.get_entity_param('dnsrecord', part_name); + + if (!metadata) return null; + + var label = metadata.label; + + if (part_name.indexOf('_part_') > -1) { + + label = label.substring(label.indexOf(' ')); + } + + return label; +}; + + +IPA.dnsrecord_type_field = function(spec) { + + spec = spec || {}; + var that = IPA.field(spec); + + that.type_changed = IPA.observer(); + + that.get_type = function() { + + return that.widget.save()[0]; + }; + + that.on_type_change = function() { + + that.type_changed.notify([], that); + }; + + that.widgets_created = function() { + + that.field_widgets_created(); + that.widget.value_changed.attach(that.on_type_change); + }; + + that.reset = function() { + that.field_reset(); + that.on_type_change(); + }; + + return that; +}; + +IPA.field_factories['dnsrecord_type'] = IPA.dnsrecord_type_field; + + IPA.dnsrecord_type_widget = function(spec) { spec.options = IPA.dns_record_types(); @@ -854,62 +1278,539 @@ IPA.dnsrecord_type_widget = function(spec) { IPA.widget_factories['dnsrecord_type'] = IPA.dnsrecord_type_widget; -IPA.dnsrecord_field = function(spec) { + +IPA.dnsrecord_adder_dialog_type_policy = function(spec) { spec = spec || {}; - var that = IPA.field(spec); - that.type_widget_name = spec.type_widget || ''; + var that = IPA.facet_policy(spec); - that.normal_validators = []; - that.a_record_validators = [ - IPA.ip_v4_address_validator() - ]; - that.aaaa_record_validators = [ - IPA.ip_v6_address_validator() - ]; + that.type_field_name = spec.type_field; + + that.post_create = function() { + that.type_field = that.container.fields.get_field(that.type_field_name); + that.type_field.type_changed.attach(that.on_type_change); + that.on_type_change(); + }; that.on_type_change = function() { - var type = that.type_widget.save()[0]; + var type = that.type_field.get_type(); + + that.allow_fields_for_type(type); + that.show_widgets_for_type(type); + }; + + that.allow_fields_for_type = function(type) { + + type = type.substring(0, type.indexOf('record')); + + var fields = that.container.fields.get_fields(); + + for (var i=0; i -1) { + fieldtype = field.name.substring(0, index); + } else { + fieldtype = field.name.substring(0, field.name.indexOf('record')); + } + + + field.enabled = (field.name === 'idnsname' || + field.name === that.type_field_name || + fieldtype === type); + } + }; + + that.show_widgets_for_type = function(type) { + + var widgets = that.container.widgets.get_widgets(); + + for (var i=0; i', { + href: '#'+that.text, + text: that.text, + style: 'float: right;', + click: function() { + return that.link_handler(value); + } + }).appendTo(container); + }; + + return that; +}; IPA.ip_address_validator = function(spec) { @@ -963,5 +1864,6 @@ IPA.ip_v6_address_validator = function(spec) { return IPA.ip_address_validator(spec); }; + IPA.register('dnszone', IPA.dns.zone_entity); IPA.register('dnsrecord', IPA.dns.record_entity); -- cgit