/*jsl:import ipa.js */ /* Authors: * Endi Sukma Dewata * * 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 . */ /* REQUIRES: ipa.js, details.js, search.js, add.js, facet.js, entity.js */ IPA.sudo = { //priority of commands in details facet remove_method_priority: IPA.config.default_priority - 1, enable_priority: IPA.config.default_priority + 1 }; IPA.sudo.rule_entity = function(spec) { var that = IPA.entity(spec); that.init = function(params) { params.builder.search_facet({ columns: [ 'cn', 'ipaenabledflag', 'description' ] }). details_facet({ factory: IPA.sudorule_details_facet, entity: that, command_mode: 'info' }). adder_dialog({ fields: [ 'cn' ] }); }; return that; }; IPA.sudo.command_entity = function(spec) { var that = IPA.entity(spec); that.init = function(params) { params.builder.search_facet({ columns: [ 'sudocmd', 'description' ] }). details_facet({ sections: [ { name: 'general', label: IPA.messages.details.general, fields: [ 'sudocmd', { type: 'textarea', name: 'description' } ] } ] }). association_facet({ name: 'memberof_sudocmdgroup', associator: IPA.serial_associator, columns:[ { name: 'cn', primary_key: true, link: true }, { name: 'description' } ], adder_columns: [ { name: 'cn', primary_key: true, width: '100px' }, { name: 'description', width: '100px' } ] }). standard_association_facets(). adder_dialog({ fields: [ 'sudocmd', { type: 'textarea', name: 'description' } ] }); }; return that; }; IPA.sudo.command_group_entity = function(spec) { var that = IPA.entity(spec); that.init = function(params) { params.builder.search_facet({ columns: [ 'cn', 'description' ] }). details_facet({ sections: [ { name: 'general', label: IPA.messages.details.general, fields: [ 'cn', { type: 'textarea', name: 'description' } ] } ] }). association_facet({ name: 'member_sudocmd', columns: [ { name: 'sudocmd', primary_key: true, link: true }, { name: 'description' } ], adder_columns: [ { name: 'sudocmd', primary_key: true, width: '100px' }, { name: 'description', width: '100px' } ] }). standard_association_facets(). adder_dialog({ fields: [ 'cn', { type: 'textarea', name: 'description' } ] }); }; return that; }; IPA.sudorule_details_facet = function(spec) { var entity_name = spec.entity.name; // // General // spec.fields = [ { name: 'cn', read_only: true, widget: 'general.cn' }, { type: 'textarea', name: 'description', widget: 'general.description' }, { type: 'enable', name: 'ipaenabledflag', priority: IPA.sudo.enable_priority, widget: 'general.ipaenabledflag' } ]; spec.widgets = [ { type: 'details_table_section', name: 'general', label: IPA.messages.details.general, widgets: [ { name: 'cn' }, { type: 'textarea', name: 'description' }, { type: 'enable', name: 'ipaenabledflag', options: [ { value: 'TRUE', label: IPA.get_message('true') }, { value: 'FALSE', label: IPA.get_message('false') } ] } ] } ]; // // Options // spec.fields.push.apply(spec.fields, [ { name: 'ipasudoopt', widget: 'options.ipasudoopt' } ]); spec.widgets.push.apply(spec.widgets, [ { factory: IPA.sudo.options_section, name: 'options', label: IPA.messages.objects.sudorule.options, facet: that } ]); /* function options_section(){ var section = IPA.sudo.options_section({ name: 'options', label: IPA.messages.objects.sudorule.options, entity: that.entity, facet: that }); return section; }*/ // // Users // spec.fields.push( { type: 'radio', name: 'usercategory', widget: 'user.rule.usercategory' }, { type: 'rule_association_table', name: 'memberuser_user', widget: 'user.rule.memberuser_user', priority: IPA.sudo.remove_method_priority }, { type: 'rule_association_table', name: 'memberuser_group', widget: 'user.rule.memberuser_group', priority: IPA.sudo.remove_method_priority } ); spec.widgets.push( { factory: IPA.collapsible_section, name: 'user', label: IPA.messages.objects.sudorule.user, widgets: [ { factory: IPA.rule_details_widget, name: 'rule', radio_name: 'usercategory', options: [ { value: 'all', label: IPA.messages.objects.sudorule.anyone }, { value: '', label: IPA.messages.objects.sudorule.specified_users } ], tables: [ { name: 'memberuser_user' }, { name: 'memberuser_group' } ], widgets: [ { type: 'rule_association_table', id: entity_name+'-memberuser_user', name: 'memberuser_user', add_method: 'add_user', remove_method: 'remove_user', external: 'externaluser', add_title: IPA.messages.association.add.member, remove_title: IPA.messages.association.remove.member }, { type: 'rule_association_table', id: entity_name+'-memberuser_group', name: 'memberuser_group', add_method: 'add_user', remove_method: 'remove_user', add_title: IPA.messages.association.add.member, remove_title: IPA.messages.association.remove.member } ] } ] } ); // // Hosts // spec.fields.push( { type: 'radio', name: 'hostcategory', widget: 'host.rule.hostcategory' }, { type: 'rule_association_table', name: 'memberhost_host', widget: 'host.rule.memberhost_host', priority: IPA.sudo.remove_method_priority }, { type: 'rule_association_table', name: 'memberhost_hostgroup', widget: 'host.rule.memberhost_hostgroup', priority: IPA.sudo.remove_method_priority } ); spec.widgets.push( { factory: IPA.collapsible_section, name: 'host', label: IPA.messages.objects.sudorule.host, widgets: [ { factory: IPA.rule_details_widget, name: 'rule', radio_name: 'hostcategory', options: [ { 'value': 'all', 'label': IPA.messages.objects.sudorule.any_host }, { 'value': '', 'label': IPA.messages.objects.sudorule.specified_hosts } ], tables: [ { 'name': 'memberhost_host' }, { 'name': 'memberhost_hostgroup' } ], widgets: [ { type: 'rule_association_table', id: entity_name+'-memberuser_user', name: 'memberhost_host', add_method: 'add_host', remove_method: 'remove_host', external: 'externalhost', add_title: IPA.messages.association.add.member, remove_title: IPA.messages.association.remove.member }, { type: 'rule_association_table', id: entity_name+'-memberuser_group', name: 'memberhost_hostgroup', add_method: 'add_host', remove_method: 'remove_host', add_title: IPA.messages.association.add.member, remove_title: IPA.messages.association.remove.member } ] } ] } ); // // Run Commands // spec.fields.push( { type: 'radio', name: 'cmdcategory', widget: 'command.rule.cmdcategory' }, { type: 'rule_association_table', name: 'memberallowcmd_sudocmd', widget: 'command.rule.memberallowcmd_sudocmd', priority: IPA.sudo.remove_method_priority }, { type: 'rule_association_table', name: 'memberallowcmd_sudocmdgroup', widget: 'command.rule.memberallowcmd_sudocmdgroup', priority: IPA.sudo.remove_method_priority }, { type: 'rule_association_table', name: 'memberdenycmd_sudocmd', widget: 'command.memberdenycmd_sudocmd', priority: IPA.sudo.remove_method_priority }, { type: 'rule_association_table', name: 'memberdenycmd_sudocmdgroup', widget: 'command.memberdenycmd_sudocmdgroup', priority: IPA.sudo.remove_method_priority } ); spec.widgets.push( { factory: IPA.collapsible_section, name: 'command', label: IPA.messages.objects.sudorule.command, widgets: [ { factory: IPA.header_widget, name: 'allow_header', text: IPA.messages.objects.sudorule.allow, description: IPA.messages.objects.sudorule.allow }, { factory: IPA.rule_details_widget, name: 'rule', radio_name: 'cmdcategory', options: [ { value: 'all', label: IPA.messages.objects.sudorule.anyone }, { value: '', label: IPA.messages.objects.sudorule.specified_users } ], tables: [ { name: 'memberallowcmd_sudocmd' }, { name: 'memberallowcmd_sudocmdgroup' } ], widgets: [ { type: 'rule_association_table', id: entity_name+'-memberallowcmd_sudocmd', name: 'memberallowcmd_sudocmd', add_method: 'add_allow_command', remove_method: 'remove_allow_command', add_title: IPA.messages.association.add.memberallowcmd, remove_title: IPA.messages.association.remove.memberallowcmd }, { type: 'rule_association_table', id: entity_name+'-memberallowcmd_sudocmdgroup', name: 'memberallowcmd_sudocmdgroup', add_method: 'add_allow_command', remove_method: 'remove_allow_command', add_title: IPA.messages.association.add.memberallowcmd, remove_title: IPA.messages.association.remove.memberallowcmd } ] }, { factory: IPA.header_widget, name: 'deny_header', text: IPA.messages.objects.sudorule.deny, description: IPA.messages.objects.sudorule.deny }, { type: 'rule_association_table', id: entity_name+'-memberdenycmd_sudocmd', name: 'memberdenycmd_sudocmd', add_method: 'add_deny_command', remove_method: 'remove_deny_command', add_title: IPA.messages.association.add.memberdenycmd, remove_title: IPA.messages.association.remove.memberdenycmd }, { type: 'rule_association_table', id: entity_name+'-memberdenycmd_sudocmdgroup', name: 'memberdenycmd_sudocmdgroup', add_method: 'add_deny_command', remove_method: 'remove_deny_command', add_title: IPA.messages.association.add.memberdenycmd, remove_title: IPA.messages.association.remove.memberdenycmd } ] } ); // // As whom // spec.fields.push( { type: 'radio', name: 'ipasudorunasusercategory', widget: 'runas.runas_users.ipasudorunasusercategory' }, { type: 'rule_association_table', name: 'ipasudorunas_user', widget: 'runas.runas_users.ipasudorunas_user', priority: IPA.sudo.remove_method_priority }, { type: 'rule_association_table', name: 'ipasudorunas_group', widget: 'runas.runas_users.ipasudorunas_group', priority: IPA.sudo.remove_method_priority }, { type: 'radio', name: 'ipasudorunasgroupcategory', widget: 'runas.runas_groups.ipasudorunasgroupcategory' }, { type: 'rule_association_table', name: 'ipasudorunasgroup_group', widget: 'runas.runas_groups.ipasudorunasgroup_group', priority: IPA.sudo.remove_method_priority } ); spec.widgets.push( { factory: IPA.collapsible_section, name: 'runas', label: IPA.messages.objects.sudorule.runas, widgets: [ { factory: IPA.rule_details_widget, name: 'runas_users', radio_name: 'ipasudorunasusercategory', options: [ { value: 'all', label: IPA.messages.objects.sudorule.anyone }, { value: '', label: IPA.messages.objects.sudorule.specified_users } ], tables: [ { name: 'ipasudorunas_user' }, { name: 'ipasudorunas_group' } ], widgets: [ { type: 'rule_association_table', id: entity_name+'-runasruser_user', name: 'ipasudorunas_user', external: 'ipasudorunasextuser', add_method: 'add_runasuser', remove_method: 'remove_runasuser', add_title: IPA.messages.association.add.ipasudorunas, remove_title: IPA.messages.association.remove.ipasudorunas }, { type: 'rule_association_table', id: entity_name+'-runasuser_group', name: 'ipasudorunas_group', add_method: 'add_runasuser', remove_method: 'remove_runasuser', add_title: IPA.messages.association.add.ipasudorunas, remove_title: IPA.messages.association.remove.ipasudorunas } ] }, { factory: IPA.rule_details_widget, name: 'runas_groups', radio_name: 'ipasudorunasgroupcategory', options: [ { value: 'all', label: IPA.messages.objects.sudorule.any_group }, { value: '', label: IPA.messages.objects.sudorule.specified_groups } ], tables: [ { name: 'ipasudorunasgroup_group' } ], widgets: [{ type: 'rule_association_table', id: entity_name+'-runasgroup_group', name: 'ipasudorunasgroup_group', external: 'ipasudorunasextgroup', add_method: 'add_runasgroup', remove_method: 'remove_runasgroup', add_title: IPA.messages.association.add.ipasudorunasgroup, remove_title: IPA.messages.association.remove.ipasudorunasgroup }] } ] } ); var that = IPA.details_facet(spec); var init = function() { var options = that.widgets.get_widget('options'); options.facet = that; }; that.on_update_success = function(data, text_status, xhr) { that.refresh(); }; that.on_update_error = function(xhr, text_status, error_thrown) { that.refresh(); }; init(); return that; }; IPA.sudo.options_section = function(spec) { spec = spec || {}; var that = IPA.collapsible_section(spec); function setup_table(){ that.table = IPA.table_widget({ name: 'ipasudoopt', show_buttons: true }); that.widgets.add_widget(that.table); that.table.create_column({ name: 'ipasudoopt', label: IPA.get_method_option('sudorule_add_option', 'ipasudoopt').label, entity_name:that.entity.name, primary_key: true }); that.table.create = function(container) { that.table.table_create(container); that.remove_button = IPA.action_button({ name: 'remove', label: IPA.messages.buttons.remove, icon: 'remove-icon', 'class': 'action-button-disabled', click: function() { if (!that.remove_button.hasClass('action-button-disabled')) { that.remove_handler(); } return false; } }).appendTo(that.table.buttons); that.add_button = IPA.action_button({ name: 'add', label: IPA.messages.buttons.add, icon: 'add-icon', click: function() { if (!that.add_button.hasClass('action-button-disabled')) { that.add_handler(); } return false; } }).appendTo(that.table.buttons); }; that.table.select_changed = function() { var values = that.table.get_selected_values(); if (that.remove_button) { if (values.length === 0) { that.remove_button.addClass('action-button-disabled'); } else { that.remove_button.removeClass('action-button-disabled'); } } }; that.table.update = function(values) { that.table.empty(); for (var i=0; i -1; i--) { result = data.result.results[i].result; if(result) break; } if(result) { that.table.load(result); } else { that.reload(); } dialog.close(); }, on_error: function(data) { that.reload(); dialog.close(); } }); for (var i=0; i