Description:
update heartbeat add try-to-login-from-other-ip loggin (by printing to stdout)
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r539:c49187a88c77 - - 2 files changed: 2 inserted, 1 deleted

@@ -24,87 +24,88
24 24 return false
25 25 end
26 26 end
27 27
28 28 protected
29 29
30 30 def authenticate
31 31 unless session[:user_id]
32 32 flash[:notice] = 'You need to login'
33 33 if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY]
34 34 flash[:notice] = 'You need to login but you cannot log in at this time'
35 35 end
36 36 redirect_to :controller => 'main', :action => 'login'
37 37 return false
38 38 end
39 39
40 40 # check if run in single user mode
41 41 if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY]
42 42 user = User.find(session[:user_id])
43 43 if user==nil or (not user.admin?)
44 44 flash[:notice] = 'You cannot log in at this time'
45 45 redirect_to :controller => 'main', :action => 'login'
46 46 return false
47 47 end
48 48 return true
49 49 end
50 50
51 51 if GraderConfiguration.multicontests?
52 52 user = User.find(session[:user_id])
53 53 return true if user.admin?
54 54 begin
55 55 if user.contest_stat(true).forced_logout
56 56 flash[:notice] = 'You have been automatically logged out.'
57 57 redirect_to :controller => 'main', :action => 'index'
58 58 end
59 59 rescue
60 60 end
61 61 end
62 62 return true
63 63 end
64 64
65 65 def authenticate_by_ip_address
66 66 #this assume that we have already authenticate normally
67 67 unless GraderConfiguration[MULTIPLE_IP_LOGIN_CONF_KEY]
68 68 user = User.find(session[:user_id])
69 69 if (not user.admin? and user.last_ip and user.last_ip != request.remote_ip)
70 70 flash[:notice] = "You cannot use the system from #{request.remote_ip}. Your last ip is #{user.last_ip}"
71 71 redirect_to :controller => 'main', :action => 'login'
72 + puts "CHEAT: user #{user.login} tried to login from '#{request.remote_ip}' while last ip is '#{user.last_ip}' at #{Time.zone.now}"
72 73 return false
73 74 end
74 75 unless user.last_ip
75 76 user.last_ip = request.remote_ip
76 77 user.save
77 78 end
78 79 end
79 80 return true
80 81 end
81 82
82 83 def authorization
83 84 return false unless authenticate
84 85 user = User.find(session[:user_id])
85 86 unless user.roles.detect { |role|
86 87 role.rights.detect{ |right|
87 88 right.controller == self.class.controller_name and
88 89 (right.action == 'all' or right.action == action_name)
89 90 }
90 91 }
91 92 flash[:notice] = 'You are not authorized to view the page you requested'
92 93 #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login')
93 94 redirect_to :controller => 'main', :action => 'login'
94 95 return false
95 96 end
96 97 end
97 98
98 99 def verify_time_limit
99 100 return true if session[:user_id]==nil
100 101 user = User.find(session[:user_id], :include => :site)
101 102 return true if user==nil or user.site == nil
102 103 if user.contest_finished?
103 104 flash[:notice] = 'Error: the contest you are participating is over.'
104 105 redirect_to :back
105 106 return false
106 107 end
107 108 return true
108 109 end
109 110
110 111 end
@@ -1,31 +1,31
1 1 class HeartbeatController < ApplicationController
2 2 before_filter :admin_authorization, :only => ['index']
3 3
4 4 def edit
5 5 @user = User.find_by_login(params[:id])
6 6 unless @user
7 7 render text: "LOGIN_NOT_FOUND"
8 8 return
9 9 end
10 10
11 11 #hb = HeartBeat.where(user_id: @user.id, ip_address: request.remote_ip).first
12 12 #puts "status = #{params[:status]}"
13 13 #if hb
14 14 # if params[:status]
15 15 # hb.status = params[:status]
16 16 # hb.save
17 17 # end
18 18 # hb.touch
19 19 #else
20 20 # HeartBeat.creae(user_id: @user.id, ip_address: request.remote_ip)
21 21 #end
22 22 HeartBeat.create(user_id: @user.id, ip_address: request.remote_ip, status: params[:status])
23 23
24 24 render text: (GraderConfiguration['right.heartbeat_response'] || 'OK')
25 25 end
26 26
27 27 def index
28 28 @hb = HeartBeat.where("updated_at >= ?",Time.zone.now-2.hours).includes(:user).order(:user_id).all
29 - @num = HeartBeat.where("updated_at >= ?",Time.zone.now-5.minutes).count
29 + @num = HeartBeat.where("updated_at >= ?",Time.zone.now-5.minutes).count(:user_id,distinct: true)
30 30 end
31 31 end
You need to be logged in to leave comments. Login now