1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

Merge branch 'hector-847' into bug-847

Conflicts:
	src/sunstone/sunstone-server.rb
This commit is contained in:
Ruben S. Montero 2011-10-27 00:17:45 +02:00
commit ec9e027811
4 changed files with 188 additions and 16 deletions

View File

@ -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

View File

@ -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,

View File

@ -18,6 +18,7 @@
var dataTable_users;
var users_select="";
var $create_user_dialog;
var $update_pw_dialog;
var users_tab_content =
'<form id="user_form" action="" action="javascript:alert(\'js error!\');">\
@ -30,6 +31,7 @@ var users_tab_content =
<th>ID</th>\
<th>Name</th>\
<th>Group</th>\
<th>Authentication driver</th>\
</tr>\
</thead>\
<tbody id="tbodyusers">\
@ -45,6 +47,13 @@ var create_user_tmpl =
<input type="text" name="username" id="username" /><br />\
<label for="pass">Password:</label>\
<input type="password" name="pass" id="pass" />\
<label for="driver">Authentication:</label>\
<select name="driver" id="driver">\
<option value="core" selected="selected">Core</option>\
<option value="ssh" selected="selected">SSH</option>\
<option value="x509" selected="selected">x509</option>\
<option value="server" selected="selected">Server</option>\
</select>\
</div>\
</fieldset>\
<fieldset>\
@ -55,6 +64,23 @@ var create_user_tmpl =
</fieldset>\
</form>';
var update_pw_tmpl = '<form id="update_user_pw_form" action="">\
<fieldset>\
<div>\
<div>This will change the password for the selected users:</div>\
<label for="new_password">New password:</label>\
<input type="password" name="new_password" id="new_password" />\
</div>\
</fieldset>\
<fieldset>\
<div class="form_buttons">\
<button class="button" id="update_pw_submit" value="user/create">Change</button>\
<button class="button" type="reset" value="reset">Reset</button>\
</div>\
</fieldset>\
</form>';
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 '<option value="core" selected="selected">Core</option>\
<option value="ssh" selected="selected">SSH</option>\
<option value="x509" selected="selected">x509</option>\
<option value="server" selected="selected">Server</option>'
},
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){
'<input type="checkbox" id="user_'+user.ID+'" name="selected_items" value="'+user.ID+'"/>',
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('<div title="Change password" id="update_user_pw_dialog"></div>');
$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);

View File

@ -22,18 +22,19 @@ ONE_LOCATION = ENV["ONE_LOCATION"]
if !ONE_LOCATION
LOG_LOCATION = "/var/log/one"
VAR_LOCATION = "/var/lib/one"
ETC_LOCATION = "/etc/one"
RUBY_LIB_LOCATION = "/usr/lib/one/ruby"
CONFIGURATION_FILE = "/etc/one/sunstone-server.conf"
PLUGIN_CONFIGURATION_FILE = "/etc/one/sunstone-plugins.yaml"
else
VAR_LOCATION = ONE_LOCATION+"/var"
LOG_LOCATION = ONE_LOCATION+"/var"
VAR_LOCATION = ONE_LOCATION + "/var"
LOG_LOCATION = ONE_LOCATION + "/var"
ETC_LOCATION = ONE_LOCATION + "/etc"
RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby"
CONFIGURATION_FILE = ONE_LOCATION+"/etc/sunstone-server.conf"
PLUGIN_CONFIGURATION_FILE = ONE_LOCATION+"/etc/sunstone-plugins.yaml"
end
SUNSTONE_AUTH = VAR_LOCATION + "/sunstone_auth"
SUNSTONE_AUTH = VAR_LOCATION + "/sunstone_auth"
CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-server.conf"
PLUGIN_CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-plugins.yaml"
SUNSTONE_ROOT_DIR = File.dirname(__FILE__)
$: << RUBY_LIB_LOCATION