/* Authors: * Adam Young * Petr Vobornik * * Copyright (C) 2010 Red Hat * see file 'COPYING' for use and warranty information * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ define([ 'dojo/_base/declare', './ipa', './jquery', './net', './field', './navigation', './menu', './phases', './reg', './rpc', './util', './text', './details', './search', './association', './entity'], function(declare, IPA, $, NET, field_mod, navigation, menu, phases, reg, rpc, util, text) { var exp = IPA.dns = { zone_permission_name: 'Manage DNS zone ${dnszone}' }; var make_config_spec = function() { return { name: 'dnsconfig', defines_key: false, enable_test: function() { return IPA.dns_enabled; }, facets: [ { $type: 'details', title: '@mo:config.label', sections: [ { name: 'options', label: '@i18n:objects.dnsconfig.options', fields: [ { $type: 'checkbox', name: 'idnsallowsyncptr' }, { $type: 'multivalued', name: 'idnsforwarders', validators: [ 'dnsforwarder'] }, { $type: 'radio', name: 'idnsforwardpolicy', default_value: 'first', options: [ { value: 'first', label: '@i18n:objects.dnsconfig.forward_first' }, { value: 'only', label: '@i18n:objects.dnsconfig.forward_only' }, { value: 'none', label: '@i18n:objects.dnsconfig.forward_none' } ] } ] } ], needs_update: true } ] };}; var make_zone_spec = function() { return { name: 'dnszone', enable_test: function() { return IPA.dns_enabled; }, facet_groups: [ 'dnsrecord', 'settings' ], facets: [ { $type: 'search', row_enabled_attribute: 'idnszoneactive', title: '@mo:dnszone.label', columns: [ 'idnsname', { name: 'idnszoneactive', label: '@i18n:status.label', formatter: 'boolean_status' } ], actions: [ 'batch_disable', 'batch_enable' ], control_buttons: [ { name: 'disable', label: '@i18n:buttons.disable', icon: 'fa-minus' }, { name: 'enable', label: '@i18n:buttons.enable', icon: 'fa-check' } ] }, { $type: 'details', $factory: IPA.dnszone_details_facet, command_mode: 'info', sections: [ { name: 'identity', fields: [ 'idnsname', 'idnssoamname', 'idnssoarname', 'idnssoaserial', 'idnssoarefresh', 'idnssoaretry', 'idnssoaexpire', 'idnssoaminimum', 'dnsttl', { $type: 'combobox', name: 'dnsclass', options: [ 'IN', 'CS', 'CH', 'HS' ] }, { $type: 'radio', name: 'idnsallowdynupdate', options: [ { value: 'TRUE', label: '@i18n:true' }, { value: 'FALSE', label: '@i18n:false' } ] }, { $type: 'textarea', name: 'idnsupdatepolicy' }, { $type: 'netaddr', name: 'idnsallowquery', validators: [ { $type: 'network', specials: ['any', 'none', 'localhost', 'localnets'], allow_negation: true, allow_host_address: true }] }, { $type: 'netaddr', name: 'idnsallowtransfer', validators: [ { $type: 'network', specials: ['any', 'none', 'localhost', 'localnets'], allow_negation: true, allow_host_address: true }] }, { $type: 'multivalued', name: 'idnsforwarders', validators: [ 'dnsforwarder'] }, { $type: 'radio', name: 'idnsforwardpolicy', default_value: 'first', options: [ { value: 'first', label: '@i18n:objects.dnsconfig.forward_first' }, { value: 'only', label: '@i18n:objects.dnsconfig.forward_only' }, { value: 'none', label: '@i18n:objects.dnsconfig.forward_none' } ] }, { $type: 'checkbox', name: 'idnsallowsyncptr' }, { $type: 'checkbox', name: 'idnssecinlinesigning' }, 'nsec3paramrecord' ] }], actions: [ 'select', 'enable', 'disable', 'delete', 'dns_add_permission', 'dns_remove_permission' ], header_actions: ['enable', 'disable', 'delete', 'add_permission', 'remove_permission'], state: { evaluators: [ { $factory: IPA.enable_state_evaluator, field: 'idnszoneactive' }, { $factory: IPA.acl_state_evaluator, attribute: 'managedby' }, IPA.dns.zone_has_permission_evaluator ], summary_conditions: [ IPA.enabled_summary_cond, IPA.disabled_summary_cond ] } }, { $type: 'nested_search', $factory: IPA.dns.record_search_facet, facet_group: 'dnsrecord', nested_entity : 'dnsrecord', name: 'records', deleter_dialog: IPA.dns.record_search_deleter_dialog, title: '@mo:dnszone.label_singular', label: '@mo:dnsrecord.label', tab_label: '@mo:dnsrecord.label', columns: [ { name: 'idnsname', label: '@mo-param:dnsrecord:idnsname:label', primary_key: true }, { name: 'type', label: '@i18n:objects.dnsrecord.type' }, { name: 'data', label: '@i18n:objects.dnsrecord.data' } ] } ], standard_association_facets: true, adder_dialog: { $factory: IPA.dnszone_adder_dialog, height: 300, sections: [ { name: 'name', layout: IPA.dnszone_name_section_layout, fields: [ { $type: 'dnszone_name', name: 'idnsname', required: false, radio_name: 'dnszone_name_type' }, { $type: 'dnszone_name', name: 'name_from_ip', radio_name: 'dnszone_name_type', validators: ['network'] } ] }, { name: 'other', fields: [ 'idnssoamname', { name: 'ip_address', validators: [ 'ip_address' ], metadata: '@mc-opt:dnszone_add:ip_address' }, { name: 'idnssoarname', required: false }, { $type: 'force_dnszone_add_checkbox', name: 'force', metadata: '@mc-opt:dnszone_add:force' } ] } ], policies: [ IPA.add_dns_zone_name_policy ] } };}; var make_forwardzone_spec = function() { return { name: 'dnsforwardzone', enable_test: function() { return IPA.dns_enabled; }, facet_groups: [ 'dnsrecord', 'settings' ], facets: [ { $type: 'search', row_enabled_attribute: 'idnszoneactive', title: '@mo:dnszone.label', columns: [ 'idnsname', { name: 'idnszoneactive', label: '@i18n:status.label', formatter: 'boolean_status' }, 'idnsforwarders', 'idnsforwardpolicy' ], actions: [ 'batch_disable', 'batch_enable' ], control_buttons: [ { name: 'disable', label: '@i18n:buttons.disable', icon: 'fa-minus' }, { name: 'enable', label: '@i18n:buttons.enable', icon: 'fa-check' } ] }, { $type: 'details', $factory: IPA.dnszone_details_facet, command_mode: 'info', sections: [ { name: 'identity', fields: [ 'idnsname', { $type: 'multivalued', name: 'idnsforwarders', validators: ['dnsforwarder'] }, { $type: 'radio', name: 'idnsforwardpolicy', default_value: 'first', options: [ { value: 'first', label: '@i18n:objects.dnsconfig.forward_first' }, { value: 'only', label: '@i18n:objects.dnsconfig.forward_only' }, { value: 'none', label: '@i18n:objects.dnsconfig.forward_none' } ] } ] }], actions: [ 'enable', 'disable', 'delete', 'dns_add_permission', 'dns_remove_permission' ], header_actions: ['enable', 'disable', 'delete', 'add_permission', 'remove_permission'], state: { evaluators: [ { $factory: IPA.enable_state_evaluator, field: 'idnszoneactive' }, { $factory: IPA.acl_state_evaluator, attribute: 'managedby' }, IPA.dns.zone_has_permission_evaluator ], summary_conditions: [ IPA.enabled_summary_cond, IPA.disabled_summary_cond ] } } ], adder_dialog: { sections: [ { name: 'name', layout: IPA.dnszone_name_section_layout, fields: [ { $type: 'dnszone_name', name: 'idnsname', required: false, radio_name: 'dnszone_name_type' }, { $type: 'dnszone_name', name: 'name_from_ip', radio_name: 'dnszone_name_type', validators: ['network'] } ] }, { name: 'forwarders', fields: [ { $type: 'multivalued', name: 'idnsforwarders', required: true, validators: ['dnsforwarder'] }, { $type: 'radio', name: 'idnsforwardpolicy', default_value: 'first', options: [ { value: 'first', label: '@i18n:objects.dnsconfig.forward_first' }, { value: 'only', label: '@i18n:objects.dnsconfig.forward_only' }, { value: 'none', label: '@i18n:objects.dnsconfig.forward_none' } ] } ] } ], policies: [ IPA.add_dns_zone_name_policy ] } };}; IPA.dnszone_details_facet = function(spec, no_init) { spec = spec || {}; var that = IPA.details_facet(spec, true); that.permission_load = IPA.observer(); that.permission_status = 'unknown'; // [unknown, set, none] that.create_refresh_command = function() { var pkey = that.get_pkey(); var batch = rpc.batch_command({ name: this.entity.name + '_details_refresh' }); var dnszone_command = that.details_facet_create_refresh_command(); batch.add_command(dnszone_command); var permission_name = IPA.dns.zone_permission_name.replace('${dnszone}', pkey); var permission_command = rpc.command({ entity: 'permission', method: 'show', args: [permission_name], options: {}, retry: false }); permission_command.on_success = function(data, text_status, xhr) { that.permission_status = 'set'; that.permission_load.notify([that.permission_status], that); }; permission_command.on_error = function(xhr, text_status, error_thrown) { if (error_thrown && error_thrown.code === 4001) { //NotFound error that.permission_status = 'none'; } else { that.permission_status = 'unknown'; } that.permission_load.notify([that.permission_status], that); }; batch.add_command(permission_command); return batch; }; that.update_on_success = function(data, text_status, xhr) { that.refresh(); that.on_update.notify(); that.nofify_update_success(); }; that.update_on_error = function(xhr, text_status, error_thrown) { that.refresh(); }; if (!no_init) that.init_details_facet(); return that; }; IPA.dnszone_name_section_layout = function(spec) { var that = IPA.fluid_layout(spec); that.radio_names = spec.radio_names || 'idnsname_method'; that.create_label = function(widget) { var label_text = widget.label + that.get_measurement_unit_text(widget); var label_cont = $('
', { 'class': that.label_cls }); widget.create_radio(label_cont); $('