This file is indexed.

/usr/share/opennebula/ozones/ozones-server.rb is in opennebula 3.4.1-4.1ubuntu1.

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

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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#!/usr/bin/env ruby

# -------------------------------------------------------------------------- #
# 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.                                             #
#--------------------------------------------------------------------------- #

ONE_LOCATION=ENV["ONE_LOCATION"]

if !ONE_LOCATION
    LOG_LOCATION = "/var/log/one"
    VAR_LOCATION = "/var/lib/one"
    ETC_LOCATION = "/etc/one"
    LIB_LOCATION = "/usr/lib/one"
    RUBY_LIB_LOCATION = "/usr/lib/one/ruby"
else
    VAR_LOCATION = ONE_LOCATION + "/var"
    LOG_LOCATION = ONE_LOCATION + "/var"
    ETC_LOCATION = ONE_LOCATION + "/etc"
    LIB_LOCATION = ONE_LOCATION+"/lib"
    RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby"
end

OZONES_LOG         = LOG_LOCATION + "/ozones-server.log"
CONFIGURATION_FILE = ETC_LOCATION + "/ozones-server.conf"

OZONES_ROOT_DIR = File.dirname(__FILE__)
$: << RUBY_LIB_LOCATION
$: << RUBY_LIB_LOCATION+'/cloud'
$: << OZONES_ROOT_DIR+'/models'
$: << OZONES_ROOT_DIR+'/lib'
$: << RUBY_LIB_LOCATION+"/cli"


##############################################################################
# Required libraries
##############################################################################
require 'rubygems'
require 'sinatra'

require 'yaml'
require 'rubygems'
require 'data_mapper'
require 'digest/sha1'
require 'OzonesServer'

##############################################################################
# Read configuration
##############################################################################
begin
    config=YAML::load_file(CONFIGURATION_FILE)
rescue Exception => e
    warn "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}"
    exit 1
end

config[:debug_level] ||= 3

CloudServer.print_configuration(config)

db_type = config[:databasetype]

case db_type
    when "sqlite" then
        db_url = db_type + "://" + VAR_LOCATION + "/ozones.db"
    when "mysql","postgres" then
        if config[:databaseserver].nil?
            warn "DB server needed for this type of DB backend"
            exit -1
        end

        db_url = db_type + "://" + config[:databaseserver] + "/ozones"
    else 
        warn "DB type #{db_type} not recognized"
        exit -1
end

##############################################################################
# Sinatra Configuration
##############################################################################
set :config, config
set :bind, config[:host]
set :port, config[:port]

use Rack::Session::Pool, :key => 'ozones'

#Enable logger
include CloudLogger
enable_logging OZONES_LOG, settings.config[:debug_level].to_i

##############################################################################
# DB bootstrapping
##############################################################################
if config[:dbdebug]
    DataMapper::Logger.new($stdout, :debug)
end

DataMapper.setup(:default, db_url)

require 'OZones'
require 'Auth'

DataMapper.finalize
DataMapper.auto_upgrade!

if Auth.all.size == 0
    if ENV['OZONES_AUTH'] && File.exist?(ENV['OZONES_AUTH'])
        credentials = IO.read(ENV['OZONES_AUTH']).strip.split(':')

        if credentials.length < 2
            settings.logger.error {"Authorization data malformed"}
            exit -1
        end
        credentials[1] = Digest::SHA1.hexdigest(credentials[1])
        @auth=Auth.create({:name => credentials[0],
                           :password => credentials[1]})
        @auth.save
    else
        error_m = "oZones admin credentials not set, missing OZONES_AUTH file."
        settings.logger.error { error_m }
        exit -1
    end
else
    @auth=Auth.all.first
end

ADMIN_NAME = @auth.name
ADMIN_PASS = @auth.password

begin
    OZones::ProxyRules.new("apache",config[:htaccess])
rescue Exception => e
    settings.logger {e.message}
    exit -1
end

##############################################################################
# Helpers
##############################################################################
helpers do

    def authorized?
        session[:ip] && session[:ip]==request.ip ? true : false
    end

    def build_session
        auth = Rack::Auth::Basic::Request.new(request.env)

        if auth.provided? && auth.basic? && auth.credentials
            
            user      = auth.credentials[0]
            pass      = auth.credentials[1]
            sha1_pass = Digest::SHA1.hexdigest(pass)

            if user == ADMIN_NAME && sha1_pass == ADMIN_PASS
                session[:user] = user
                session[:ip]   = request.ip
                session[:key]  = Digest::SHA1.hexdigest("#{user}:#{pass}")

                session[:remember] = params[:remember]

                if params[:remember]
                    env['rack.session.options'][:expire_after] = 30*60*60*24
                end

                return [204, ""]
            else
                logger.info {"User not authorized login attempt"}
                return [401, ""]
            end
        end
        logger.error {"Authentication settings wrong or not provided"}
        return [401, ""]
    end

    def destroy_session
        session.clear
        return [204, ""]
    end
end

before do
    unless request.path=='/login' || request.path=='/'

        unless authorized?
            rc , msg = build_session

            if rc == 401
               halt 401 
            end
        end

        @OzonesServer = OzonesServer.new(session[:key],
                                         settings.config,
                                         settings.logger)
        @pr           = OZones::ProxyRules.new("apache",config[:htaccess])
    end
end

after do
    unless request.path=='/login' || request.path=='/'
        unless session[:remember]
            if params[:timeout] == true
                env['rack.session.options'][:defer] = true
            else
                env['rack.session.options'][:expire_after] = 60*10
            end
        end
    end
end

##############################################################################
# HTML Requests
##############################################################################
get '/' do
    return  File.read(File.dirname(__FILE__)+
                      '/templates/login.html') unless authorized?

    time = Time.now + 60*10
    response.set_cookie("ozones-user",
                        :value=>"#{session[:user]}",
                        :expires=>time)

    File.read(File.dirname(__FILE__)+'/templates/index.html')
end

get '/login' do
    File.read(File.dirname(__FILE__)+'/templates/login.html')
end

##############################################################################
# Login
##############################################################################
post '/login' do
    build_session
end

post '/logout' do
    destroy_session
end

##############################################################################
# Config and Logs
##############################################################################
get '/config' do
    config
end

##############################################################################
# GET information
##############################################################################
get '/vdc' do
    @OzonesServer.get_vdcs
end

get '/vdc/:id' do
    @OzonesServer.get_vdc(params[:id])
end

get '/zone' do
    @OzonesServer.get_zones
end

get %r{/zone/([\d]+)/([\w]+)} do
    @OzonesServer.get_zone_pool(params[:captures][0], params[:captures][1])
end

get %r{/zone/([\d]+)} do
    @OzonesServer.get_zone(params[:captures].first)
end

get %r{/zone/([\w]+)} do
    @OzonesServer.get_zones_pool(params[:captures].first)
end

##############################################################################
# POSTs information
##############################################################################

post '/vdc' do
    @OzonesServer.create_vdc(request.body.read, @pr)
end

post '/zone' do
    @OzonesServer.create_zone(request.body.read, @pr)
end

##############################################################################
# Update Resource
##############################################################################
put '/vdc/:id' do
    @OzonesServer.update_vdc(params[:id], request.body.read)
end

##############################################################################
# Delete Resource
##############################################################################
delete '/vdc/:id' do
    @OzonesServer.delete_vdc(params[:id], @pr)
end

delete '/zone/:id' do
    @OzonesServer.delete_zone(params[:id], @pr)
end