/** * Global variables */ var userDatatable; var topPriority = 0; var tableId = 'usersTable'; /** * Get user access table * * @returns User access table */ function getUsersTable(){ return userDatatable; } /** * Set user access table * * @param table User access table */ function setUsersTable(table){ userDatatable = table; } /** * Load the user page */ function loadUserPage() { // Retrieve users from policy table $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'tabdump', tgt : '', args : 'policy', msg : '' }, success : loadUserTable }); } /** * Load user table * * @param data Data returned from HTTP request */ function loadUserTable(data){ var tabId = 'usersTab'; $('#' + tabId).empty(); // Set padding for page $('#' + tabId).css('padding', '20px 60px'); // Create info bar var info = $('#' + tabId).find('.ui-state-highlight'); // If there is no info bar if (!info.length) { var infoBar = createInfoBar('Configure access given to users.'); // Create users page var userPg = $('
'); $('#' + tabId).append(infoBar, userPg); } if (data.rsp) { // Create a datatable if one does not exist var table = new DataTable(tableId); var headers = new Array('Priority', 'Name', 'Host', 'Commands', 'Noderange', 'Parameters', 'Time', 'Rule', 'Comments', 'Disable'); // Add column for the checkbox headers.unshift(''); table.init(headers); headers.shift(); // Append datatable to panel $('#' + tabId).append(table.object()); topPriority = 0; // Add table rows // Start with the 2nd row (1st row is the headers) for (var i = 1; i < data.rsp.length; i++) { // Trim returned data data.rsp[i] = jQuery.trim(data.rsp[i]); // Split data into columns var cols = data.rsp[i].split(','); // Go through each column // Column names are: priority, name, host, commands, noderange, parameters, time, rule, comments, disable for (var j = 0; j < cols.length; j++) { // Replace quote cols[j] = cols[j].replace(/"/g, ''); } // Set the highest priority priority = cols[0]; if (priority > topPriority) topPriority = priority; // Add check box where name = user name cols.unshift(''); // Add row table.add(cols); } // Turn table into datatable var dTable = $('#' + tableId).dataTable({ 'iDisplayLength': 50, 'bLengthChange': false, "bScrollCollapse": true, "sScrollY": "400px", "sScrollX": "100%", "bAutoWidth": true, "oLanguage": { "oPaginate": { "sNext": "", "sPrevious": "" } } }); setUsersTable(dTable); // Cache user access table } // Create action bar var actionBar = $('
').css("width", "450px"); var createLnk = $('Create'); createLnk.click(function() { openCreateUserDialog(""); }); var editLnk = $('Edit'); editLnk.click(function() { // Should only allow 1 user to be edited at a time var users = getNodesChecked(tableId).split(',') for (var i in users) { openCreateUserDialog(users[i]); } }); var deleteLnk = $('Delete'); deleteLnk.click(function() { // Find the user name from datatable var usersList = ""; var users = $('#' + tableId + ' input[type=checkbox]:checked'); for (var i in users) { var user = users.eq(i).parents('tr').find('td:eq(2)').text(); if (user && user != "undefined") { usersList += user; if (i < users.length - 1) { usersList += ','; } } } if (usersList) { openDeleteUserDialog(usersList); } }); var refreshLnk = $('Refresh'); refreshLnk.click(function() { loadUserPage(); }); // Create an action menu var actionsMenu = createMenu([createLnk, editLnk, deleteLnk, refreshLnk]); actionsMenu.superfish(); actionsMenu.css('display', 'inline-block'); actionBar.append(actionsMenu); // Set correct theme for action menu actionsMenu.find('li').hover(function() { setMenu2Theme($(this)); }, function() { setMenu2Normal($(this)); }); // Create a division to hold actions menu var menuDiv = $(''); $('#' + tableId + '_wrapper').prepend(menuDiv); menuDiv.append(actionBar); $('#' + tableId + '_filter').appendTo(menuDiv); } /** * Open create user dialog * * @param data User data (only during edit) */ function openCreateUserDialog(data) { var dialogId = 'createUser'; // Generate the user priority var priority = parseFloat(topPriority) + 0.01; priority = priority.toPrecision(3); // Create form to create user var createUserForm = $('
'); // Create info bar var info = createInfoBar('Create a user and configure access to xCAT.'); var userFS = $('
'); var userLegend = $('User'); userFS.append(userLegend); var userAttr = $('
'); userFS.append($('
')); userFS.append(userAttr); var optionFS = $('
'); var optionLegend = $('Options'); optionFS.append(optionLegend); var optionAttr = $('
'); optionFS.append($('
')); optionFS.append(optionAttr); createUserForm.append(info, userFS, optionFS); userAttr.append($('
')); userAttr.append($('
')); userAttr.append($('
')); userAttr.append($('
')); optionAttr.append($('
')); optionAttr.append($('
')); optionAttr.append($('
')); optionAttr.append($('
')); optionAttr.append($('
')); var rootPrivilege = $('
'); var accessCheckbox = $(''); optionAttr.append(rootPrivilege); rootPrivilege.append(accessCheckbox); optionAttr.append($('
')); optionAttr.append($('
')); // Open dialog to add disk createUserForm.dialog({ title:'Configure user', modal: true, close: function(){ $(this).remove(); }, width: 600, buttons: { "Ok": function(){ // Remove any warning messages $(this).find('.ui-state-error').remove(); // Get inputs var priority = $(this).find('input[name=priority]').val(); var usrName = $(this).find('input[name=name]').val(); var password = $(this).find('input[name=password]').val(); var confirmPassword = $(this).find('input[name=confirm_password]').val(); var host = $(this).find('input[name=host]').val(); var commands = $(this).find('input[name=commands]').val(); var parameters = $(this).find('input[name=parameters]').val(); var nodeRange = $(this).find('input[name=nodeRange]').val(); var rule = $(this).find('select[name=rule]').val(); var comments = $(this).find('input[name=comments]').val(); var disable = $(this).find('select[name=disable]').val(); // Verify user name and passwords are supplied if (!usrName) { var warn = createWarnBar('Please provide a user name'); warn.prependTo($(this)); return; } // Verify passwords match if (password != confirmPassword) { var warn = createWarnBar('Passwords do not match'); warn.prependTo($(this)); return; } var args = ""; if (usrName) { args += ' policy.name=' + usrName; } if (host) { args += " policy.host='" + host + "'"; } if (commands) { args += " policy.commands='" + commands + "'"; } if (parameters) { args += " policy.parameters='" + parameters + "'"; } if (nodeRange) { args += " policy.noderange='" + nodeRange + "'"; } if (rule) { args += ' policy.rule=' + rule; } if (disable) { args += ' policy.disable=' + disable; } if (comments) { args += " policy.comments='" + comments + "'"; } // Trim any extra spaces args = jQuery.trim(args); // Change dialog buttons $(this).dialog('option', 'buttons', { 'Close': function() {$(this).dialog("close");} }); // Submit request to update policy and passwd tables $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'policy|' + priority + '|' + args, msg : dialogId }, success : updatePanel }); if (password) { $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'passwd|' + usrName + '|' + password, msg : dialogId }, success : updatePanel }); } // Update highest priority topPriority = priority; }, "Cancel": function() { $(this).dialog( "close" ); } } }); // Change comments if access checkbox is checked accessCheckbox.click( function(){ var comments = createUserForm.find('input[name=comments]').val(); var tag = "privilege:root"; comments = jQuery.trim(comments); // Append tag to comments if (accessCheckbox.is(':checked')) { if (comments && comments.charAt(comments.length - 1) != ";") { comments += ";"; } comments += tag; createUserForm.find('input[name=comments]').val(comments); } else { comments = comments.replace(tag, ""); comments = comments.replace(";;", ";"); createUserForm.find('input[name=comments]').val(comments); } // Strip off leading semi-colon if (comments.charAt(0) == ";") { comments = comments.substr(1, comments.length); createUserForm.find('input[name=comments]').val(comments); } }); // Set the user data (on edit) if (data) { var checkBox = $('#' + tableId + ' input[name="' + data + '"]'); var priority = data; var name = checkBox.parents('tr').find('td:eq(2)').text(); var host = checkBox.parents('tr').find('td:eq(3)').text(); var commands = checkBox.parents('tr').find('td:eq(4)').text(); var noderange = checkBox.parents('tr').find('td:eq(5)').text(); var parameters = checkBox.parents('tr').find('td:eq(6)').text(); var time = checkBox.parents('tr').find('td:eq(7)').text(); var rule = checkBox.parents('tr').find('td:eq(8)').text(); var comments = checkBox.parents('tr').find('td:eq(9)').text(); var disable = checkBox.parents('tr').find('td:eq(10)').text(); createUserForm.find('input[name=priority]').val(priority); createUserForm.find('input[name=name]').val(name); // Do not show password (security) createUserForm.find('input[name=password]').val(); createUserForm.find('input[name=confirm_password]').val(); createUserForm.find('input[name=host]').val(host); createUserForm.find('input[name=commands]').val(commands); createUserForm.find('input[name=parameters]').val(parameters); createUserForm.find('input[name=nodeRange]').val(noderange); createUserForm.find('select[name=rule]').val(rule); createUserForm.find('input[name=comments]').val(comments); createUserForm.find('select[name=disable]').val(disable); if (comments.indexOf("privilege:root") > -1) { accessCheckbox.attr("checked", true); } } } /** * Open dialog to confirm user delete * * @param users Users to delete */ function openDeleteUserDialog(users) { // Create form to delete disk to pool var dialogId = 'deleteUser'; var deleteForm = $('
'); // Create info bar var info = createInfoBar('Are you sure you want to delete ' + users.replace(new RegExp(',', 'g'), ', ') + '?'); deleteForm.append(info); // Open dialog to delete user deleteForm.dialog({ title:'Delete user', modal: true, width: 400, close: function(){ $(this).remove(); }, buttons: { "Ok": function(){ // Remove any warning messages $(this).find('.ui-state-error').remove(); // Change dialog buttons $(this).dialog('option', 'buttons', { 'Close': function() {$(this).dialog("close");} }); // Delete user $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'deleteuser|' + users, msg : dialogId }, success : updatePanel }); }, "Cancel": function() { $(this).dialog( "close" ); } } }); }