Revision 15002c60 src/sunstone/sunstone-server.rb

View differences:

src/sunstone/sunstone-server.rb
36 36
##############################################################################
37 37
helpers do
38 38
    def authorized?
39
        session["ip"] && session["ip"]==request.ip ? true : false
39
        session[:ip] && session[:ip]==request.ip ? true : false
40 40
    end
41 41

  
42 42
    def build_session
......
47 47

  
48 48
            rc = SunstoneServer.authorize(user, sha1_pass)
49 49
            if rc[1]
50
                session["user"]       = user
51
                session["user_id"]    = rc[1]
52
                session["password"]   = sha1_pass
53
                session["ip"]         = request.ip
54
                session["user_agent"] = request.user_agent
55
                session["remember"]   = params[:remember]
50
                session[:user]     = user
51
                session[:user_id]  = rc[1]
52
                session[:password] = sha1_pass
53
                session[:ip]       = request.ip
54
                session[:remember] = params[:remember]
56 55

  
57 56
                if params[:remember]
58 57
                    env['rack.session.options'][:expire_after] = 30*60*60*24
......
77 76
    unless request.path=='/login' || request.path=='/'
78 77
        halt 401 unless authorized?
79 78

  
80
        @SunstoneServer = SunstoneServer.new(session["user"], session["password"])
79
        @SunstoneServer = SunstoneServer.new(session[:user], session[:password])
81 80
    end
82 81
end
83 82

  
84 83
after do
85 84
    unless request.path=='/login' || request.path=='/'
86
        unless session['remember']
87
            if params[:timeout] === true
85
        unless session[:remember]
86
            if params[:timeout] == true
88 87
                env['rack.session.options'][:defer] = true
89 88
            else
90 89
                env['rack.session.options'][:expire_after] = 60*10
......
98 97
##############################################################################
99 98
get '/' do
100 99
    redirect '/login' unless authorized?
100

  
101 101
    time = Time.now + 60
102
    response.set_cookie("one-user", :value=>"#{session['user']}", :expires=>time)
103
    response.set_cookie("one-user_id", :value=>"#{session['user_id']}", :expires=>time)
102
    response.set_cookie("one-user",
103
                        :value=>"#{session[:user]}",
104
                        :expires=>time)
105
    response.set_cookie("one-user_id",
106
                        :value=>"#{session[:user_id]}",
107
                        :expires=>time)
108

  
104 109
    File.read(File.dirname(__FILE__)+'/templates/index.html')
105 110
end
106 111

  
......
120 125
end
121 126

  
122 127
##############################################################################
128
# Config and Logs
129
##############################################################################
130
get '/config' do
131
    @SunstoneServer.get_configuration(session[:user_id])
132
end
133

  
134
get '/vm/:id/log' do
135
    @SunstoneServer.get_vm_log(params[:id])
136
end
137

  
138
##############################################################################
123 139
# GET Pool information
124 140
##############################################################################
125 141
get '/:pool' do
......
154 170
    @SunstoneServer.perform_action(params[:resource], params[:id], request.body.read)
155 171
end
156 172

  
157
##############################################################################
158
# Config and Logs
159
##############################################################################
160
get '/config' do
161
    @SunstoneServer.get_configuration(session["user_id"])
162
end
163

  
164
get '/vm/:id/log' do
165
    @SunstoneServer.get_vm_log(params[:id])
166
end

Also available in: Unified diff