This file is indexed.

/usr/share/opennebula/sunstone/models/SunstonePlugins.rb is in opennebula-sunstone 3.4.1-3.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
# -------------------------------------------------------------------------- #
# Copyright 2002-2012, 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 'yaml'
require 'json'

class SunstonePlugins
    USER_PLUGIN_POLICY = false # or true to enable them by default

    attr_reader :plugins_conf

    def initialize
        load_conf
        check_plugins
    end

    def load_conf
        @plugins_conf = YAML.load_file(PLUGIN_CONFIGURATION_FILE)
    end

    def check_plugins
        base_path = SUNSTONE_ROOT_DIR+'/public/js/'

        @installed_plugins = Array.new

        # read user plugins
        modified = false
        Dir[base_path+'user-plugins/*.js'].each do |p_path|
            m = p_path.match(/^#{base_path}(.*)$/)
            if m and plugin = m[1]
                @installed_plugins << plugin
                if !plugins.include? plugin
                    @plugins_conf << {plugin=>{:ALL     => USER_PLUGIN_POLICY,
                                               :user    => nil,
                                               :group   => nil}}
                    modified = true
                end
            end
        end
        write_conf if modified

        # read base plugins
        Dir[base_path+'plugins/*.js'].each do |p_path|
            m = p_path.match(/^#{base_path}(.*)$/)
            if m and plugin = m[1]
                @installed_plugins << plugin
            end
        end
    end

    def plugins
        @plugins_conf.collect{|p| p.keys[0]}
    end

    def installed?(plugin)
        @installed_plugins.include? plugin
    end

    def authorized_plugins(user, group)
        auth_plugins = {"user-plugins"=>Array.new, "plugins"=>Array.new}

        @plugins_conf.each do |plugin_conf|
            plugin = plugin_conf.keys.first
            perms  = plugin_conf[plugin]

            if installed?(plugin)
                p_path, p_name = plugin.split('/')

                if perms[:user] and perms[:user].has_key? user
                    if perms[:user][user]
                        auth_plugins[p_path] << p_name
                    else
                        next
                    end
                elsif perms[:group] and perms[:group].has_key? group
                    if perms[:group][group]
                        auth_plugins[p_path] << p_name
                    else
                        next
                    end
                elsif perms[:ALL]
                    auth_plugins[p_path] << p_name
                end
            end
        end
        auth_plugins
    end

    def write_conf
        File.open(PLUGIN_CONFIGURATION_FILE,'w') do |f|
            f.write(@plugins_conf.to_yaml)
        end
    end

    def to_json
        @plugins_conf.to_json
    end
end