diff --git a/src/sunstone/models/OpenNebulaJSON/UserJSON.rb b/src/sunstone/models/OpenNebulaJSON/UserJSON.rb index 89f9780b7a..0fe15fdcc5 100644 --- a/src/sunstone/models/OpenNebulaJSON/UserJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/UserJSON.rb @@ -27,7 +27,8 @@ module OpenNebulaJSON end password = Digest::SHA1.hexdigest(user_hash['password']) - self.allocate(user_hash['name'], password) + + self.allocate(user_hash['name'], password, user_hash['auth_driver']) end def perform_action(template_json) @@ -37,10 +38,12 @@ module OpenNebulaJSON end rc = case action_hash['perform'] - when "passwd" then self.passwd(action_hash['params']) + when "passwd" then self.passwd(action_hash['params']) when "chgrp" then self.chgrp(action_hash['params']) - when "addgroup" then self.addgroup(action_hash['params']) - when "delgroup" then self.delgroup(action_hash['params']) + when "chauth" then self.chauth(action_hash['params']) + when "update" then self.update(action_hash['params']) + when "addgroup" then self.addgroup(action_hash['params']) + when "delgroup" then self.delgroup(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << " available for this resource" @@ -57,6 +60,14 @@ module OpenNebulaJSON super(params['group_id'].to_i) end + def chauth(params=Hash.new) + super(params['auth_driver']) + end + + def update(params=Hash.new) + super(params['raw_template']) + end + def addgroup(params=Hash.new) super(params['group_id'].to_i) end diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index 8a7224d161..0269c92e8e 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -669,7 +669,22 @@ var OpenNebula = { var action_obj = {"group_id": params.data.extra_param }; OpenNebula.Action.simple_action(params,OpenNebula.User.resource, "chgrp",action_obj); - } + }, + "chauth" : function(params){ + var action_obj = {"auth_driver" : params.data.extra_param }; + OpenNebula.Action.simple_action(params,OpenNebula.User.resource, + "chauth",action_obj); + }, + "update": function(params){ + var action_obj = {"template_raw" : params.data.extra_param }; + OpenNebula.Action.simple_action(params, + OpenNebula.User.resource, + "update", + action_obj); + }, + "fetch_template" : function(params){ + OpenNebula.Action.show(params,OpenNebula.User.resource,"template"); + }, // "addgroup" : function(params){ // var action_obj = {"group_id": params.data.extra_param }; // OpenNebula.Action.simple_action(params,OpenNebula.User.resource, diff --git a/src/sunstone/public/js/plugins/users-tab.js b/src/sunstone/public/js/plugins/users-tab.js index 0c48249ef8..667bc29733 100644 --- a/src/sunstone/public/js/plugins/users-tab.js +++ b/src/sunstone/public/js/plugins/users-tab.js @@ -18,6 +18,7 @@ var dataTable_users; var users_select=""; var $create_user_dialog; +var $update_pw_dialog; var users_tab_content = '
\ @@ -30,6 +31,7 @@ var users_tab_content = ID\ Name\ Group\ + Authentication driver\ \ \ \ @@ -45,6 +47,13 @@ var create_user_tmpl =
\ \ \ + \ + \ \ \
\ @@ -55,6 +64,23 @@ var create_user_tmpl =
\
'; +var update_pw_tmpl = '
\ +
\ +
\ +
This will change the password for the selected users:
\ + \ + \ +
\ +
\ +
\ +
\ + \ + \ +
\ +
\ +
'; + + var user_actions = { "User.create" : { type: "create", @@ -95,6 +121,18 @@ var user_actions = { } }, + "User.update_password" : { + type: "custom", + call: popUpUpdatePasswordDialog + }, + + "User.passwd" : { + type: "multiple", + call: OpenNebula.User.passwd, + //nocallback + elements: userElements, + error: onError + }, "User.chgrp" : { type: "multiple", call: OpenNebula.User.chgrp, @@ -106,6 +144,17 @@ var user_actions = { notify: true }, + "User.chauth" : { + type: "multiple", + call: OpenNebula.User.chauth, + callback : function(req){ + Sunstone.runAction("User.show",req.request.data[0]); + }, + elements: userElements, + error: onError, + notify: true + }, + // "User.addgroup" : { // type: "multiple", // call: OpenNebula.User.addgroup, @@ -143,6 +192,39 @@ var user_actions = { error: onError, notify: true }, + + "User.fetch_template" : { + type: "single", + call: OpenNebula.User.fetch_template, + callback: function (request,response) { + $('#template_update_dialog #template_update_textarea').val(response.template); + }, + error: onError + }, + + "User.update_dialog" : { + type: "custom", + call: function() { + popUpTemplateUpdateDialog("User", + makeSelectOptions(dataTable_users, + 1,//id_col + 2,//name_col + [], + [] + ), + getSelectedNodes(dataTable_users)); + } + }, + + "User.update" : { + type: "single", + call: OpenNebula.User.update, + callback: function() { + notifyMessage("Template updated correctly"); + }, + error: onError + } + } var user_buttons = { @@ -155,12 +237,32 @@ var user_buttons = { type: "create_dialog", text: "+ New" }, + "User.update_dialog" : { + type: "action", + text: "Update a template", + alwaysActive: true + }, + "User.update_password" : { + type : "action", + text : "Change password", + }, "User.chgrp" : { type: "confirm_with_select", text: "Change group", select: groups_sel, tip: "This will change the main group of the selected users. Select the new group:" }, + "User.chauth" : { + type: "confirm_with_select", + text: "Change authentication", + select: function() { + return '\ + \ + \ + ' + }, + tip: "Please choose the new type of authentication for the selected users:" + }, // "User.addgroup" : { // type: "confirm_with_select", // text: "Add to group", @@ -203,7 +305,8 @@ function userElementArray(user_json){ '', user.ID, user.NAME, - user.GNAME + user.GNAME, + user.AUTH_DRIVER ] } @@ -268,6 +371,8 @@ function setupCreateUserDialog(){ $('#create_user_form',dialog).submit(function(){ var user_name=$('#username',this).val(); var user_password=$('#pass',this).val(); + var driver = $('#driver', this).val(); + if (!user_name.length || !user_password.length){ notifyError("User name and password must be filled in"); return false; @@ -275,7 +380,9 @@ function setupCreateUserDialog(){ var user_json = { "user" : { "name" : user_name, - "password" : user_password } + "password" : user_password, + "auth_driver" : driver + } }; Sunstone.runAction("User.create",user_json); $create_user_dialog.dialog('close'); @@ -283,10 +390,46 @@ function setupCreateUserDialog(){ }); } +function setupUpdatePasswordDialog(){ + dialogs_context.append('
'); + $update_pw_dialog = $('#update_user_pw_dialog',dialogs_context); + var dialog = $update_pw_dialog; + dialog.html(update_pw_tmpl); + + //Prepare jquery dialog + dialog.dialog({ + autoOpen: false, + modal:true, + width: 400 + }); + + $('button',dialog).button(); + + $('#update_user_pw_form',dialog).submit(function(){ + var pw=$('#new_password',this).val(); + + if (!pw.length){ + notifyError("Fill in a new password"); + return false; + } + + Sunstone.runAction("User.passwd",getSelectedNodes(dataTable_users),pw); + $update_pw_dialog.dialog('close'); + return false; + }); +}; + function popUpCreateUserDialog(){ $create_user_dialog.dialog('open'); } + +function popUpUpdatePasswordDialog(){ + $update_pw_dialog.dialog('open'); +} + + + // Prepare the autorefresh of the list function setUserAutorefresh(){ setInterval(function(){ @@ -309,17 +452,19 @@ $(document).ready(function(){ "aoColumnDefs": [ { "bSortable": false, "aTargets": ["check"] }, { "sWidth": "60px", "aTargets": [0] }, - { "sWidth": "35px", "aTargets": [1] } + { "sWidth": "35px", "aTargets": [1] }, + { "sWidth": "150px", "aTargets": [4] } ] }); dataTable_users.fnClearTable(); addElement([ spinner, - '','',''],dataTable_users); + '','','',''],dataTable_users); Sunstone.runAction("User.list"); setupCreateUserDialog(); + setupUpdatePasswordDialog(); setUserAutorefresh(); initCheckAllBoxes(dataTable_users); diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index 631c90fbb4..4cf1044149 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -25,14 +25,14 @@ if !ONE_LOCATION RUBY_LIB_LOCATION = "/usr/lib/one/ruby" CONFIGURATION_FILE = "/etc/one/sunstone-server.conf" PLUGIN_CONFIGURATION_FILE = "/etc/one/sunstone-plugins.yaml" - SUNSTONE_AUTH = "/etc/one/auth/sunstone_auth" + SUNSTONE_AUTH = "/var/one/sunstone_auth" else VAR_LOCATION = ONE_LOCATION+"/var" LOG_LOCATION = ONE_LOCATION+"/var" RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby" CONFIGURATION_FILE = ONE_LOCATION+"/etc/sunstone-server.conf" PLUGIN_CONFIGURATION_FILE = ONE_LOCATION+"/etc/sunstone-plugins.yaml" - SUNSTONE_AUTH = ONE_LOCATION + "/etc/auth/sunstone_auth" + SUNSTONE_AUTH = ONE_LOCATION + "/var/sunstone_auth" end SUNSTONE_ROOT_DIR = File.dirname(__FILE__)