Description:
update heartbeat
add try-to-login-from-other-ip loggin (by printing to stdout)
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r539:c49187a88c77 - - 2 files changed: 2 inserted, 1 deleted
@@ -48,48 +48,49 | |||
|
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 |
@@ -5,27 +5,27 | |||
|
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