diff --git a/src/sunstone/models/OpenNebulaJSON.rb b/src/sunstone/models/OpenNebulaJSON.rb index 44685c68f9..0eb98bd37c 100644 --- a/src/sunstone/models/OpenNebulaJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON.rb @@ -26,6 +26,7 @@ require 'OpenNebulaJSON/PoolJSON' require 'OpenNebulaJSON/UserJSON' require 'OpenNebulaJSON/VirtualMachineJSON' require 'OpenNebulaJSON/VirtualNetworkJSON' +require 'OpenNebulaJSON/AclJSON' module OpenNebula class Error diff --git a/src/sunstone/models/OpenNebulaJSON/AclJSON.rb b/src/sunstone/models/OpenNebulaJSON/AclJSON.rb new file mode 100644 index 0000000000..0db8a68ac1 --- /dev/null +++ b/src/sunstone/models/OpenNebulaJSON/AclJSON.rb @@ -0,0 +1,51 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +require 'OpenNebulaJSON/JSONUtils' + +module OpenNebulaJSON + class AclJSON < OpenNebula::Acl + include JSONUtils + + def create(template_json) + acl_string = parse_json(template_json, 'acl') + acl_rule = Acl.parse_rule(acl_string) + if OpenNebula.is_error?(acl_rule) + return acl_rule + end + self.allocate(acl_rule[0],acl_rule[1],acl_rule[2]) + end + + def perform_action(template_json) + action_hash = parse_json(template_json, 'action') + if OpenNebula.is_error?(action_hash) + return action_hash + end + + error_msg = "#{action_hash['perform']} action not " << + " available for this resource" + OpenNebula::Error.new(error_msg) + + # rc = case action_hash['perform'] + # #no actions! + # else + # error_msg = "#{action_hash['perform']} action not " << + # " available for this resource" + # OpenNebula::Error.new(error_msg) + # end + end + end +end diff --git a/src/sunstone/models/OpenNebulaJSON/PoolJSON.rb b/src/sunstone/models/OpenNebulaJSON/PoolJSON.rb index 150956bdf6..a59db50c73 100644 --- a/src/sunstone/models/OpenNebulaJSON/PoolJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/PoolJSON.rb @@ -24,4 +24,5 @@ module OpenNebulaJSON class TemplatePoolJSON < OpenNebula::TemplatePool; include JSONUtils; end class GroupPoolJSON < OpenNebula::GroupPool; include JSONUtils; end class UserPoolJSON < OpenNebula::UserPool; include JSONUtils; end + class AclPoolJSON < OpenNebula::AclPool; include JSONUtils; end end diff --git a/src/sunstone/models/SunstoneServer.rb b/src/sunstone/models/SunstoneServer.rb index f1cec51f60..d387b77acc 100644 --- a/src/sunstone/models/SunstoneServer.rb +++ b/src/sunstone/models/SunstoneServer.rb @@ -65,13 +65,14 @@ class SunstoneServer when "vm" then VirtualMachinePoolJSON.new(@client) when "vnet" then VirtualNetworkPoolJSON.new(@client) when "user" then UserPoolJSON.new(@client) + when "acl" then AclPoolJSON.new(@client) else error = Error.new("Error: #{kind} resource not supported") return [404, error.to_json] end rc = case kind - when "group","host","user" then pool.info + when "group","host","user","acl" then pool.info else gid != "0" ? pool.info_group : pool.info_all end @@ -120,6 +121,7 @@ class SunstoneServer when "vm" then VirtualMachineJSON.new(VirtualMachine.build_xml,@client) when "vnet" then VirtualNetworkJSON.new(VirtualNetwork.build_xml, @client) when "user" then UserJSON.new(User.build_xml, @client) + when "acl" then AclJSON.new(Acl.build_xml, @client) else error = Error.new("Error: #{kind} resource not supported") return [404, error.to_json] @@ -339,6 +341,7 @@ class SunstoneServer when "vm" then VirtualMachineJSON.new_with_id(id, @client) when "vnet" then VirtualNetworkJSON.new_with_id(id, @client) when "user" then UserJSON.new_with_id(id, @client) + when "acl" then AclJSON.new_with_id(id, @client) else error = Error.new("Error: #{kind} resource not supported") return error diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index 769bffab40..222faa20ca 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -2589,5 +2589,95 @@ var OpenNebula = { "chgrp" : function(params){ OpenNebula.Helper.chgrp(params,OpenNebula.Template.resource,"template"); } + }, + + "Acl" : { + "resource" : "ACL", + "create" : function(params){ + var callback = params.success; + var callback_error = params.error; + var data = params.data; + var resource = OpenNebula.Acl.resource; + + var request = OpenNebula.Helper.request(resource,"create",data); + + $.ajax({ + url: "acl", + type: "POST", + dataType: "json", + data: JSON.stringify(data), + success: function(response) + { + if (callback) + { + callback(request, response); + } + }, + error: function(response) + { + if (callback_error) + { + callback_error(request, OpenNebula.Error(response)); + } + } + }); + }, + "list" : function(params){ + var callback = params.success; + var callback_error = params.error; + var timeout = params.timeout || false; + + var resource = OpenNebula.Acl.resource; + var request = OpenNebula.Helper.request(resource,"list"); + + $.ajax({ + url: "acl", + type: "GET", + dataType: "json", + data: {timeout: timeout}, + success: function(response) + { + if (callback) + { + var acl_pool = OpenNebula.Helper.pool(resource,response); + callback(request, acl_pool); + } + }, + error: function(response) + { + if (callback_error) + { + callback_error(request, OpenNebula.Error(response)); + } + } + }); + }, + "delete" : function(params){ + var callback = params.success; + var callback_error = params.error; + var id = params.data.id; + var resource = OpenNebula.Acl.resource; + + var request = OpenNebula.Helper.request(resource,"delete", id); + + $.ajax({ + url: "acl/" + id, + type: "DELETE", + success: function() + { + if (callback) + { + callback(request); + } + }, + error: function(response) + { + if (callback_error) + { + callback_error(request, OpenNebula.Error(response)); + } + } + }); + } } } diff --git a/src/sunstone/public/js/plugins/acls-tab.js b/src/sunstone/public/js/plugins/acls-tab.js new file mode 100644 index 0000000000..8f2a4ab7b0 --- /dev/null +++ b/src/sunstone/public/js/plugins/acls-tab.js @@ -0,0 +1,474 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +/*ACLs tab plugin*/ +var dataTable_acls; + +var acls_tab_content = +'
'; + +var create_acl_tmpl = +''; + +var acl_actions = { + "Acl.create" : { + type: "create", + call: OpenNebula.Acl.create, + callback: function(){ + Sunstone.runAction("Acl.list"); + }, + error: onError, + notify: true + }, + + "Acl.create_dialog" : { + type: "custom", + call: popUpCreateAclDialog + }, + + "Acl.list" : { + type: "list", + call: OpenNebula.Acl.list, + callback: updateAclsView, + error: onError + }, + + "Acl.refresh" : { + type: "custom", + call: function () { + waitingNodes(dataTable_acls); + Sunstone.runAction("Acl.list"); + }, + }, + + "Acl.autorefresh" : { + type: "custom", + call: function(){ + OpenNebula.Acl.list({ + timeout: true, + success: updateAclsView, + error: onError + }); + }, + condition: True, + notify: false + }, + + "Acl.delete" : { + type: "multiple", + call: OpenNebula.Acl.delete, + callback: deleteAclElement, + elements: function() { return getSelectedNodes(dataTable_acls); }, + error: onError, + notify: true + }, +} + +var acl_buttons = { + "Acl.refresh" : { + type: "image", + text: "Refresh list", + img: "images/Refresh-icon.png", + condition: True + }, + "Acl.create_dialog" : { + type: "create_dialog", + text: "+ New", + condition: True + }, + "Acl.delete" : { + type: "action", + text: "Delete", + condition: True + } +} + +var acls_tab = { + title: "ACLs", + content: acls_tab_content, + buttons: acl_buttons, + condition: True +} + +Sunstone.addActions(acl_actions); +Sunstone.addMainTab('acls_tab',acls_tab); + +function parseUserAcl(user){ + var user_str=""; + if (user[0] == '*'){ + user_str = "All"; + } else { + if (user[0] == '#'){ + user_str="User "; + user_str+= getUserName(user.substring(1)); + } + else if (user[0] == '@'){ + user_str="Group "; + user_str+= getGroupName(user.substring(1)); + }; + }; + return user_str; +} + +function parseResourceAcl(user){ + var user_str=""; + if (user[0] == '*'){ + user_str = "All"; + } else { + if (user[0] == '#'){ + user_str="ID "; + user_str+= user.substring(1); + } + else if (user[0] == '@'){ + user_str="Group "; + user_str+= getGroupName(user.substring(1)); + }; + }; + return user_str; +} + +//Parses the string, returns a legible array +function parseAclString(string) { + var space_split = string.split(' '); + var user = space_split[0]; + var resources = space_split[1]; + var rights = space_split[2]; + + //User + var user_str=parseUserAcl(user); + + + //Resources + var resources_str=""; + var resources_array = resources.split('/'); + var belonging_to = parseResourceAcl(resources_array[1]); + resources_array = resources_array[0].split('+'); + for (var i=0; i