Commit 4feaaba5dd05b4ba6bffd487c74dd939f3e2b4e7
1 parent
8584ceb0
Exists in
master
and in
1 other branch
- show ip address and user-agent of online students
Showing
4 changed files
with
21 additions
and
3 deletions
Show diff stats
app.py
... | ... | @@ -156,6 +156,8 @@ class App(object): |
156 | 156 | d[uid]['start_time'] = self.online.get(uid, {}).get('test', {}).get('start_time','') |
157 | 157 | d[uid]['password_defined'] = pw != '' |
158 | 158 | d[uid]['grades'] = self.db.get_student_grades_from_test(uid, self.testfactory['ref']) |
159 | + d[uid]['ip_address'] = self.online.get(uid, {}).get('student', {}).get('ip_address','') | |
160 | + d[uid]['user_agent'] = self.online.get(uid, {}).get('student', {}).get('user_agent','') | |
159 | 161 | return d |
160 | 162 | |
161 | 163 | # def get_this_students_grades(self): |
... | ... | @@ -179,6 +181,12 @@ class App(object): |
179 | 181 | self.db.reset_password(uid) |
180 | 182 | logger.info('Student {}: password reset to ""'.format(uid)) |
181 | 183 | |
184 | + def set_user_agent(self, uid, user_agent=''): | |
185 | + self.online[uid]['student']['user_agent'] = user_agent | |
186 | + | |
187 | + def set_user_ip(self, uid, ipaddress=''): | |
188 | + self.online[uid]['student']['ip_address'] = ipaddress | |
189 | + | |
182 | 190 | # ============================================================================ |
183 | 191 | ch = logging.StreamHandler() |
184 | 192 | ch.setLevel(logging.INFO) | ... | ... |
serve.py
... | ... | @@ -133,7 +133,9 @@ class Root(object): |
133 | 133 | |
134 | 134 | if self.app.login(uid, pw): # ok |
135 | 135 | cherrypy.session[SESSION_KEY] = cherrypy.request.login = uid |
136 | - raise cherrypy.HTTPRedirect('/') # FIXME | |
136 | + self.app.set_user_agent(uid, cherrypy.request.headers.get('User-Agent', '')) | |
137 | + self.app.set_user_ip(uid, cherrypy.request.remote.ip) | |
138 | + raise cherrypy.HTTPRedirect('/') | |
137 | 139 | else: # denied |
138 | 140 | return self.template['login'].render() |
139 | 141 | ... | ... |
static/js/admin.js
... | ... | @@ -46,13 +46,20 @@ $(document).ready(function() { |
46 | 46 | var rows = ""; |
47 | 47 | $.each(students, function(i, r) { |
48 | 48 | if (r[1]['start_time'] != '') { |
49 | - active.push([r[0], r[1]['name'], r[1]['start_time']]); | |
49 | + active.push([r[0], r[1]['name'], r[1]['start_time'], r[1]['ip_address'], r[1]['user_agent']]); | |
50 | 50 | } |
51 | 51 | }); |
52 | + // sort by start time | |
52 | 53 | active.sort(function(a,b){return a[2] < b[2] ? -1 : (a[2] == b[2] ? 0 : 1);}); |
53 | 54 | n = active.length; |
54 | 55 | for(var i = 0; i < n; i++) { |
55 | - rows += "<tr><td>" + active[i][0] + "</td><td>" + active[i][1] + "</td><td>" + active[i][2].slice(0,10) + "</td><td>" + active[i][2].slice(11,19) + "</td></tr>"; | |
56 | + rows += "<tr>\ | |
57 | + <td>" + active[i][0] + "</td>\ | |
58 | + <td>" + active[i][1] + "</td>\ | |
59 | + <td>" + active[i][2].slice(0,10) + "</td>\ | |
60 | + <td>" + active[i][2].slice(11,19) + '</td>\ | |
61 | + <td><div data-toggle="tooltip" data-placement="top" title="' + active[i][4] + '">' + active[i][3] + '</div></td>\ | |
62 | + </tr>'; | |
56 | 63 | } |
57 | 64 | $("#online_students").html(rows); |
58 | 65 | $("#online-header").html(n + " Activo(s)"); | ... | ... |