From db822955c2b61b31ba96213ec88c14c2b8d827bc Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Tue, 7 Dec 2010 01:51:51 -0600 Subject: SUDO adjustments The SUDO rule details facet has been updated to support the latest UI spec. The facet consists of 5 sections: general, users, hosts, commands, and run-as. The general section contains the SUDO rule description and status. If the status is changed, the sudorule-enable/disable will be invoked. The other sections contain radio buttons for the association category and tables for the members. When a member is added or removed, the category will be adjusted appropriately. If the category is changed to 'all', 'allow', or 'deny', all members will be removed. The last section is currently not working because backend support is not yet available. The adder dialog boxes for users, groups, and hosts has been modified to accept external identities. The layout for the base adder dialog was updated. The base dialog class was updated to support templates. The SUDO dialog boxes were implemented using templates. New CSS classes were added to ipa.css. The HBAC rule details facet has been updated as well. --- install/static/sudorule.js | 806 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 762 insertions(+), 44 deletions(-) (limited to 'install/static/sudorule.js') diff --git a/install/static/sudorule.js b/install/static/sudorule.js index 101f8c41..61eef6bf 100755 --- a/install/static/sudorule.js +++ b/install/static/sudorule.js @@ -110,20 +110,35 @@ function ipa_sudorule_details_facet(spec) { that.init = function() { - var section = ipa_details_list_section({ - 'name': 'general', - 'label': 'General' - }); - that.add_section(section); - - section.create_field({'name': 'cn', 'read_only': true}); - section.create_field({'name': 'description'}); - section.create_field({'name': 'cmdcategory'}); + var section; + + if (IPA.layout) { + section = that.create_section({ + 'name': 'general', + 'label': 'General', + 'template': 'sudorule-details-general.html #contents' + }); + + } else { + section = ipa_sudorule_details_general_section({ + 'name': 'general', + 'label': 'General' + }); + that.add_section(section); + } + + section.create_text({ 'name': 'cn', 'read_only': true }); + section.create_textarea({ 'name': 'description' }); + section.create_radio({ 'name': 'ipaenabledflag' }); section = ipa_rule_details_section({ 'name': 'user', 'label': 'Who', - 'field_name': 'memberuser', + 'field_name': 'usercategory', + 'options': [ + { 'value': 'all', 'label': 'Anyone' }, + { 'value': '', 'label': 'Specified Users and Groups' } + ], 'tables': [ { 'field_name': 'memberuser_user' }, { 'field_name': 'memberuser_group' } @@ -131,21 +146,26 @@ function ipa_sudorule_details_facet(spec) { }); that.add_section(section); - section.add_field(ipa_association_table_widget({ + var category = section.create_radio({ name: 'usercategory', label: 'User category' }); + section.add_field(ipa_sudorule_association_table_widget({ 'id': that.entity_name+'-memberuser_user', - 'name': 'memberuser_user', 'label': 'Users', + 'name': 'memberuser_user', 'label': 'Users', 'category': category, 'other_entity': 'user', 'add_method': 'add_user', 'remove_method': 'remove_user' })); - section.add_field(ipa_association_table_widget({ + section.add_field(ipa_sudorule_association_table_widget({ 'id': that.entity_name+'-memberuser_group', - 'name': 'memberuser_group', 'label': 'Groups', + 'name': 'memberuser_group', 'label': 'Groups', 'category': category, 'other_entity': 'group', 'add_method': 'add_user', 'remove_method': 'remove_user' })); section = ipa_rule_details_section({ 'name': 'host', - 'label': 'Where', - 'field_name': 'memberhost', + 'label': 'Access this host', + 'field_name': 'hostcategory', + 'options': [ + { 'value': 'all', 'label': 'Any Host' }, + { 'value': '', 'label': 'Specified Hosts and Groups' } + ], 'tables': [ { 'field_name': 'memberhost_host' }, { 'field_name': 'memberhost_hostgroup' } @@ -153,62 +173,760 @@ function ipa_sudorule_details_facet(spec) { }); that.add_section(section); - section.add_field(ipa_association_table_widget({ + category = section.create_radio({ 'name': 'hostcategory', 'label': 'Host category' }); + section.add_field(ipa_sudorule_association_table_widget({ 'id': that.entity_name+'-memberhost_host', - 'name': 'memberhost_host', 'label': 'Host', + 'name': 'memberhost_host', 'label': 'Host', 'category': category, 'other_entity': 'host', 'add_method': 'add_host', 'remove_method': 'remove_host' })); - section.add_field(ipa_association_table_widget({ + section.add_field(ipa_sudorule_association_table_widget({ 'id': that.entity_name+'-memberhost_hostgroup', - 'name': 'memberhost_hostgroup', 'label': 'Groups', + 'name': 'memberhost_hostgroup', 'label': 'Groups', 'category': category, 'other_entity': 'hostgroup', 'add_method': 'add_host', 'remove_method': 'remove_host' })); - section = ipa_rule_details_section({ - 'name': 'allow', - 'label': 'Allow', - 'field_name': 'memberallowcmd', - 'tables': [ - { 'field_name': 'memberallowcmd_sudocmd' }, - { 'field_name': 'memberallowcmd_sudocmdgroup' } - ] + section = ipa_sudorule_details_command_section({ + 'name': 'command', + 'label': 'Run Commands' }); that.add_section(section); - section.add_field(ipa_association_table_widget({ + section = ipa_sudorule_details_runas_section({ + 'name': 'runas', + 'label': 'As Whom' + }); + that.add_section(section); + + that.details_facet_init(); + }; + + that.load = function(record) { + var category = record['cmdcategory']; + if (category && category[0] == 'all') { + record['cmdcategory'] = ['allow']; + + } else { + var memberallowcmd_sudocmd = record['memberallowcmd_sudocmd']; + var memberallowcmd_sudocmdgroup = record['memberallowcmd_sudocmdgroup']; + var memberdenycmd_sudocmd = record['memberdenycmd_sudocmd']; + var memberdenycmd_sudocmdgroup = record['memberdenycmd_sudocmdgroup']; + + if (!memberallowcmd_sudocmd && !memberallowcmd_sudocmdgroup + && !memberdenycmd_sudocmd && !memberdenycmd_sudocmdgroup) { + record['cmdcategory'] = ['deny']; + + } else { + record['cmdcategory'] = ['']; + } + } + + that.details_facet_load(record); + }; + + that.update = function() { + + var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; + + var modify_operation = { + 'execute': false, + 'command': ipa_command({ + 'method': that.entity_name+'_mod', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + }; + + var categories = { + 'usercategory': { + 'remove_values': false + }, + 'hostcategory': { + 'remove_values': false + }, + 'cmdcategory': { + 'remove_values': false + }, + 'runasusercategory': { + 'remove_values': false + }, + 'runasgroupcategory': { + 'remove_values': false + } + }; + + var member_operations = { + 'memberuser': { + 'category': 'usercategory', + 'has_values': false, + 'command': ipa_command({ + 'method': that.entity_name+'_remove_user', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + }, + 'memberhost': { + 'category': 'hostcategory', + 'has_values': false, + 'command': ipa_command({ + 'method': that.entity_name+'_remove_host', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + }, + 'memberallowcmd': { + 'category': 'cmdcategory', + 'has_values': false, + 'command': ipa_command({ + 'method': that.entity_name+'_remove_allow_command', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + }, + 'memberdenycmd': { + 'category': 'cmdcategory', + 'has_values': false, + 'command': ipa_command({ + 'method': that.entity_name+'_remove_deny_command', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + }, + 'runasuser': { + 'category': 'runasusercategory', + 'has_values': false, + 'command': ipa_command({ + 'method': that.entity_name+'_remove_runas_user', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + }, + 'runasgroup': { + 'category': 'runasgroupcategory', + 'has_values': false, + 'command': ipa_command({ + 'method': that.entity_name+'_remove_runas_group', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + } + }; + + var enable_operation = { + 'execute': false, + 'command': ipa_command({ + 'method': that.entity_name+'_enable', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + }; + + for (var i=0; i= 0) { + // prepare command to remove members if needed + var attribute = field.name.substring(0, p); + var other_entity = field.name.substring(p+1); + + if (values.length) { + member_operations[attribute].command.set_option(other_entity, values.join(',')); + member_operations[attribute].has_values = true; + } + continue; + } + + // skip unchanged field + if (!field.is_dirty(span)) continue; + + // check enable/disable + if (field.name == 'ipaenabledflag') { + if (values[0] == 'FALSE') enable_operation.command.method = that.entity_name+'_disable'; + enable_operation.execute = true; + continue; + } + + if (field.name == 'cmdcategory') { + var value = values[0]; + if (value == 'allow') { + values = ['all']; + categories[field.name].remove_values = true; + } else if (value == 'deny') { + values = []; + categories[field.name].remove_values = true; + } else { + values = []; + } + + } else if (categories[field.name]) { + if (values[0] == 'all') { + categories[field.name].remove_values = true; + } + } + + // use setattr/addattr if param_info not available + if (!param_info) { + for (var k=0; k', { + 'style': 'width: 100%;' + }).appendTo(container); + + var tr = $('').appendTo(table); + + var td = $('', { + 'style': 'width: 100px; text-align: right;', + 'html': 'Name:' + }).appendTo(tr); + + td = $('').appendTo(tr); + + var span = $('', { 'name': 'cn' }).appendTo(td); + + $('', { + 'type': 'text', + 'name': 'cn', + 'size': 30 + }).appendTo(span); + + span.append(' '); + + $('', { + 'name': 'undo', + 'class': 'ui-state-highlight ui-corner-all', + 'style': 'display: none;', + 'html': 'undo' + }).appendTo(span); + + tr = $('').appendTo(table); + + td = $('', { + 'style': 'text-align: right; vertical-align: top;', + 'html': 'Description:' + }).appendTo(tr); + + td = $('').appendTo(tr); + + span = $('', { 'name': 'description' }).appendTo(td); + + $('