Description:
fix whitelisting bugs
fix report bug
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r784:73e8782d729d - - 5 files changed: 58 inserted, 54 deleted
@@ -7,7 +7,7 | |||
|
7 | 7 | |
|
8 | 8 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
9 | 9 | MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' |
|
10 |
- |
|
|
10 | + WHITELIST_IGNORE_CONF_KEY = 'right.whitelist_ignore' | |
|
11 | 11 | WHITELIST_IP_CONF_KEY = 'right.whitelist_ip' |
|
12 | 12 | |
|
13 | 13 | #report and redirect for unauthorized activities |
@@ -81,9 +81,9 | |||
|
81 | 81 | end |
|
82 | 82 | |
|
83 | 83 | # check if user ip is allowed |
|
84 |
- unless @current_user.admin? || |
|
|
84 | + unless @current_user.admin? || GraderConfiguration[WHITELIST_IGNORE_CONF_KEY] | |
|
85 | 85 | unless is_request_ip_allowed? |
|
86 | - unauthorized_redirect 'Your IP is not allowed' | |
|
86 | + unauthorized_redirect 'Your IP is not allowed to login at this time.' | |
|
87 | 87 | return false |
|
88 | 88 | end |
|
89 | 89 | end |
@@ -108,10 +108,8 | |||
|
108 | 108 | #this assume that we have already authenticate normally |
|
109 | 109 | unless GraderConfiguration[MULTIPLE_IP_LOGIN_CONF_KEY] |
|
110 | 110 | user = User.find(session[:user_id]) |
|
111 | - puts "User admin #{user.admin?}" | |
|
112 | 111 | if (!user.admin? && user.last_ip && user.last_ip != request.remote_ip) |
|
113 | 112 | flash[:notice] = "You cannot use the system from #{request.remote_ip}. Your last ip is #{user.last_ip}" |
|
114 | - puts "hahaha" | |
|
115 | 113 | redirect_to :controller => 'main', :action => 'login' |
|
116 | 114 | return false |
|
117 | 115 | end |
@@ -152,14 +150,17 | |||
|
152 | 150 | end |
|
153 | 151 | |
|
154 | 152 | def is_request_ip_allowed? |
|
155 |
- |
|
|
153 | + unless GraderConfiguration[WHITELIST_IGNORE_CONF_KEY] | |
|
156 | 154 | user_ip = IPAddr.new(request.remote_ip) |
|
157 | - GraderConfiguration[WHITELIST_IP_LIST_CONF_KEY].delete(' ').split(',').each do |ips| | |
|
155 | + | |
|
156 | + GraderConfiguration[WHITELIST_IP_CONF_KEY].delete(' ').split(',').each do |ips| | |
|
157 | + puts "ip is #{ips}, user ip is #{user_ip}" | |
|
158 | 158 | allow_ips = IPAddr.new(ips) |
|
159 |
- |
|
|
160 |
- return |
|
|
159 | + if allow_ips.include?(user_ip) | |
|
160 | + return true | |
|
161 | 161 | end |
|
162 | 162 | end |
|
163 | + return false | |
|
163 | 164 | end |
|
164 | 165 | return true |
|
165 | 166 | end |
@@ -465,7 +465,7 | |||
|
465 | 465 | protected |
|
466 | 466 | |
|
467 | 467 | def calculate_max_score(problems, users,since_id,until_id, get_last_score = false) |
|
468 | - #score[i] = user #i's user stat where i is the index (not id) | |
|
468 | + #scorearray[i] = user #i's user stat where i is the index (not id) | |
|
469 | 469 | scorearray = Array.new |
|
470 | 470 | users.each do |u| |
|
471 | 471 | ustat = Array.new |
@@ -12,9 +12,11 | |||
|
12 | 12 | %th.text-right Total |
|
13 | 13 | %th.text-right Passed |
|
14 | 14 | %tbody |
|
15 | - - sum = Array.new(@problems.count,0) | |
|
16 | - - nonzero = Array.new(@problems.count,0) | |
|
17 | - - full = Array.new(@problems.count,0) | |
|
15 | + - sum = Array.new(@problems.count+1,0) | |
|
16 | + - nonzero = Array.new(@problems.count+1,0) | |
|
17 | + - full = Array.new(@problems.count+1,0) | |
|
18 | + - puts @scorearray | |
|
19 | + - puts @problems.count | |
|
18 | 20 | - @scorearray.each do |sc| |
|
19 | 21 | %tr |
|
20 | 22 | - total,num_passed = 0,0 |
@@ -12,7 +12,7 | |||
|
12 | 12 | |
|
13 | 13 | ActiveRecord::Schema.define(version: 2018_06_12_102327) do |
|
14 | 14 | |
|
15 |
- create_table "announcements", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
15 | + create_table "announcements", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
16 | 16 | t.string "author" |
|
17 | 17 | t.text "body" |
|
18 | 18 | t.boolean "published" |
@@ -24,7 +24,7 | |||
|
24 | 24 | t.string "notes" |
|
25 | 25 | end |
|
26 | 26 | |
|
27 |
- create_table "contests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
27 | + create_table "contests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
28 | 28 | t.string "title" |
|
29 | 29 | t.boolean "enabled" |
|
30 | 30 | t.datetime "created_at" |
@@ -32,30 +32,30 | |||
|
32 | 32 | t.string "name" |
|
33 | 33 | end |
|
34 | 34 | |
|
35 |
- create_table "contests_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
35 | + create_table "contests_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
36 | 36 | t.integer "contest_id" |
|
37 | 37 | t.integer "problem_id" |
|
38 | 38 | end |
|
39 | 39 | |
|
40 |
- create_table "contests_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
40 | + create_table "contests_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
41 | 41 | t.integer "contest_id" |
|
42 | 42 | t.integer "user_id" |
|
43 | 43 | end |
|
44 | 44 | |
|
45 |
- create_table "countries", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
45 | + create_table "countries", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
46 | 46 | t.string "name" |
|
47 | 47 | t.datetime "created_at" |
|
48 | 48 | t.datetime "updated_at" |
|
49 | 49 | end |
|
50 | 50 | |
|
51 |
- create_table "descriptions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
51 | + create_table "descriptions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
52 | 52 | t.text "body" |
|
53 | 53 | t.boolean "markdowned" |
|
54 | 54 | t.datetime "created_at" |
|
55 | 55 | t.datetime "updated_at" |
|
56 | 56 | end |
|
57 | 57 | |
|
58 |
- create_table "grader_configurations", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
58 | + create_table "grader_configurations", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
59 | 59 | t.string "key" |
|
60 | 60 | t.string "value_type" |
|
61 | 61 | t.string "value" |
@@ -64,7 +64,7 | |||
|
64 | 64 | t.text "description" |
|
65 | 65 | end |
|
66 | 66 | |
|
67 |
- create_table "grader_processes", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
67 | + create_table "grader_processes", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
68 | 68 | t.string "host" |
|
69 | 69 | t.integer "pid" |
|
70 | 70 | t.string "mode" |
@@ -74,21 +74,21 | |||
|
74 | 74 | t.integer "task_id" |
|
75 | 75 | t.string "task_type" |
|
76 | 76 | t.boolean "terminated" |
|
77 |
- t.index ["host", "pid"], name: "index_grader_processes_on_ |
|
|
77 | + t.index ["host", "pid"], name: "index_grader_processes_on_host_and_pid" | |
|
78 | 78 | end |
|
79 | 79 | |
|
80 |
- create_table "groups", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
80 | + create_table "groups", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
81 | 81 | t.string "name" |
|
82 | 82 | t.string "description" |
|
83 | 83 | end |
|
84 | 84 | |
|
85 |
- create_table "groups_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
85 | + create_table "groups_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
86 | 86 | t.integer "problem_id", null: false |
|
87 | 87 | t.integer "group_id", null: false |
|
88 | 88 | t.index ["group_id", "problem_id"], name: "index_groups_problems_on_group_id_and_problem_id" |
|
89 | 89 | end |
|
90 | 90 | |
|
91 |
- create_table "groups_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
91 | + create_table "groups_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
92 | 92 | t.integer "group_id", null: false |
|
93 | 93 | t.integer "user_id", null: false |
|
94 | 94 | t.index ["user_id", "group_id"], name: "index_groups_users_on_user_id_and_group_id" |
@@ -97,13 +97,13 | |||
|
97 | 97 | create_table "heart_beats", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
98 | 98 | t.integer "user_id" |
|
99 | 99 | t.string "ip_address" |
|
100 |
- t.datetime "created_at" |
|
|
101 |
- t.datetime "updated_at" |
|
|
100 | + t.datetime "created_at" | |
|
101 | + t.datetime "updated_at" | |
|
102 | 102 | t.string "status" |
|
103 | 103 | t.index ["updated_at"], name: "index_heart_beats_on_updated_at" |
|
104 | 104 | end |
|
105 | 105 | |
|
106 |
- create_table "languages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
106 | + create_table "languages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
107 | 107 | t.string "name", limit: 10 |
|
108 | 108 | t.string "pretty_name" |
|
109 | 109 | t.string "ext", limit: 10 |
@@ -113,11 +113,11 | |||
|
113 | 113 | create_table "logins", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
114 | 114 | t.integer "user_id" |
|
115 | 115 | t.string "ip_address" |
|
116 |
- t.datetime "created_at" |
|
|
117 |
- t.datetime "updated_at" |
|
|
116 | + t.datetime "created_at" | |
|
117 | + t.datetime "updated_at" | |
|
118 | 118 | end |
|
119 | 119 | |
|
120 |
- create_table "messages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
120 | + create_table "messages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
121 | 121 | t.integer "sender_id" |
|
122 | 122 | t.integer "receiver_id" |
|
123 | 123 | t.integer "replying_message_id" |
@@ -127,7 +127,7 | |||
|
127 | 127 | t.datetime "updated_at" |
|
128 | 128 | end |
|
129 | 129 | |
|
130 |
- create_table "problems", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
130 | + create_table "problems", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
131 | 131 | t.string "name", limit: 30 |
|
132 | 132 | t.string "full_name" |
|
133 | 133 | t.integer "full_score" |
@@ -141,7 +141,7 | |||
|
141 | 141 | t.boolean "view_testcase" |
|
142 | 142 | end |
|
143 | 143 | |
|
144 |
- create_table "problems_tags", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
144 | + create_table "problems_tags", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
145 | 145 | t.integer "problem_id" |
|
146 | 146 | t.integer "tag_id" |
|
147 | 147 | t.index ["problem_id", "tag_id"], name: "index_problems_tags_on_problem_id_and_tag_id", unique: true |
@@ -149,29 +149,29 | |||
|
149 | 149 | t.index ["tag_id"], name: "index_problems_tags_on_tag_id" |
|
150 | 150 | end |
|
151 | 151 | |
|
152 |
- create_table "rights", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
152 | + create_table "rights", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
153 | 153 | t.string "name" |
|
154 | 154 | t.string "controller" |
|
155 | 155 | t.string "action" |
|
156 | 156 | end |
|
157 | 157 | |
|
158 |
- create_table "rights_roles", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
158 | + create_table "rights_roles", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
159 | 159 | t.integer "right_id" |
|
160 | 160 | t.integer "role_id" |
|
161 | 161 | t.index ["role_id"], name: "index_rights_roles_on_role_id" |
|
162 | 162 | end |
|
163 | 163 | |
|
164 |
- create_table "roles", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
164 | + create_table "roles", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
165 | 165 | t.string "name" |
|
166 | 166 | end |
|
167 | 167 | |
|
168 |
- create_table "roles_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
168 | + create_table "roles_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
169 | 169 | t.integer "role_id" |
|
170 | 170 | t.integer "user_id" |
|
171 | 171 | t.index ["user_id"], name: "index_roles_users_on_user_id" |
|
172 | 172 | end |
|
173 | 173 | |
|
174 |
- create_table "sessions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
174 | + create_table "sessions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
175 | 175 | t.string "session_id" |
|
176 | 176 | t.text "data" |
|
177 | 177 | t.datetime "updated_at" |
@@ -179,7 +179,7 | |||
|
179 | 179 | t.index ["updated_at"], name: "index_sessions_on_updated_at" |
|
180 | 180 | end |
|
181 | 181 | |
|
182 |
- create_table "sites", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
182 | + create_table "sites", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
183 | 183 | t.string "name" |
|
184 | 184 | t.boolean "started" |
|
185 | 185 | t.datetime "start_time" |
@@ -192,11 +192,11 | |||
|
192 | 192 | create_table "submission_view_logs", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
193 | 193 | t.integer "user_id" |
|
194 | 194 | t.integer "submission_id" |
|
195 |
- t.datetime "created_at" |
|
|
196 |
- t.datetime "updated_at" |
|
|
195 | + t.datetime "created_at" | |
|
196 | + t.datetime "updated_at" | |
|
197 | 197 | end |
|
198 | 198 | |
|
199 |
- create_table "submissions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
199 | + create_table "submissions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
200 | 200 | t.integer "user_id" |
|
201 | 201 | t.integer "problem_id" |
|
202 | 202 | t.integer "language_id" |
@@ -218,7 +218,7 | |||
|
218 | 218 | t.index ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id" |
|
219 | 219 | end |
|
220 | 220 | |
|
221 |
- create_table "tags", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
221 | + create_table "tags", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
222 | 222 | t.string "name", null: false |
|
223 | 223 | t.text "description" |
|
224 | 224 | t.boolean "public" |
@@ -226,7 +226,7 | |||
|
226 | 226 | t.datetime "updated_at", null: false |
|
227 | 227 | end |
|
228 | 228 | |
|
229 |
- create_table "tasks", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
229 | + create_table "tasks", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
230 | 230 | t.integer "submission_id" |
|
231 | 231 | t.datetime "created_at" |
|
232 | 232 | t.integer "status" |
@@ -234,7 +234,7 | |||
|
234 | 234 | t.index ["submission_id"], name: "index_tasks_on_submission_id" |
|
235 | 235 | end |
|
236 | 236 | |
|
237 |
- create_table "test_pairs", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
237 | + create_table "test_pairs", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
238 | 238 | t.integer "problem_id" |
|
239 | 239 | t.text "input", limit: 16777215 |
|
240 | 240 | t.text "solution", limit: 16777215 |
@@ -242,7 +242,7 | |||
|
242 | 242 | t.datetime "updated_at" |
|
243 | 243 | end |
|
244 | 244 | |
|
245 |
- create_table "test_requests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
245 | + create_table "test_requests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
246 | 246 | t.integer "user_id" |
|
247 | 247 | t.integer "problem_id" |
|
248 | 248 | t.integer "submission_id" |
@@ -263,7 +263,7 | |||
|
263 | 263 | t.index ["user_id", "problem_id"], name: "index_test_requests_on_user_id_and_problem_id" |
|
264 | 264 | end |
|
265 | 265 | |
|
266 |
- create_table "testcases", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
266 | + create_table "testcases", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
267 | 267 | t.integer "problem_id" |
|
268 | 268 | t.integer "num" |
|
269 | 269 | t.integer "group" |
@@ -275,14 +275,15 | |||
|
275 | 275 | t.index ["problem_id"], name: "index_testcases_on_problem_id" |
|
276 | 276 | end |
|
277 | 277 | |
|
278 |
- create_table "user_contest_stats", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
278 | + create_table "user_contest_stats", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
279 | 279 | t.integer "user_id" |
|
280 | 280 | t.datetime "started_at" |
|
281 | 281 | t.datetime "created_at" |
|
282 | 282 | t.datetime "updated_at" |
|
283 | + t.boolean "forced_logout" | |
|
283 | 284 | end |
|
284 | 285 | |
|
285 |
- create_table "users", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET= |
|
|
286 | + create_table "users", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
286 | 287 | t.string "login", limit: 50 |
|
287 | 288 | t.string "full_name" |
|
288 | 289 | t.string "hashed_password" |
@@ -100,7 +100,7 | |||
|
100 | 100 | :key => 'right.view_testcase', |
|
101 | 101 | :value_type => 'boolean', |
|
102 | 102 | :default_value => 'false', |
|
103 |
- :description => ' |
|
|
103 | + :description => 'If true, any user can view/download test data' | |
|
104 | 104 | }, |
|
105 | 105 | |
|
106 | 106 | { |
@@ -182,17 +182,17 | |||
|
182 | 182 | |
|
183 | 183 | |
|
184 | 184 | { |
|
185 |
- :key => 'right.whitelist_i |
|
|
185 | + :key => 'right.whitelist_ignore', | |
|
186 | 186 | :value_type => 'boolean', |
|
187 |
- :default_value => ' |
|
|
188 | - :description => "If true, non-admin user will be able to use the system only when their ip is in the 'whitelist_ip'." | |
|
187 | + :default_value => 'true', | |
|
188 | + :description => "If true, no IP check against whitelist_ip is perform. However, when false, non-admin user must have their ip in 'whitelist_ip' to be able to login." | |
|
189 | 189 | }, |
|
190 | 190 | |
|
191 | 191 | { |
|
192 | 192 | :key => 'right.whitelist_ip', |
|
193 | 193 | :value_type => 'string', |
|
194 | 194 | :default_value => '0.0.0.0/0', |
|
195 |
- :description => "list of whitelist ip, given in comma separated CIDR notation. For example '1 |
|
|
195 | + :description => "list of whitelist ip, given in comma separated CIDR notation. For example '192.168.90.0/23, 192.168.1.23/32'" | |
|
196 | 196 | }, |
|
197 | 197 | |
|
198 | 198 | ] |
You need to be logged in to leave comments.
Login now