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,6 +156,8 @@ class App(object): | ||
156 | d[uid]['start_time'] = self.online.get(uid, {}).get('test', {}).get('start_time','') | 156 | d[uid]['start_time'] = self.online.get(uid, {}).get('test', {}).get('start_time','') |
157 | d[uid]['password_defined'] = pw != '' | 157 | d[uid]['password_defined'] = pw != '' |
158 | d[uid]['grades'] = self.db.get_student_grades_from_test(uid, self.testfactory['ref']) | 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 | return d | 161 | return d |
160 | 162 | ||
161 | # def get_this_students_grades(self): | 163 | # def get_this_students_grades(self): |
@@ -179,6 +181,12 @@ class App(object): | @@ -179,6 +181,12 @@ class App(object): | ||
179 | self.db.reset_password(uid) | 181 | self.db.reset_password(uid) |
180 | logger.info('Student {}: password reset to ""'.format(uid)) | 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 | ch = logging.StreamHandler() | 191 | ch = logging.StreamHandler() |
184 | ch.setLevel(logging.INFO) | 192 | ch.setLevel(logging.INFO) |
serve.py
@@ -133,7 +133,9 @@ class Root(object): | @@ -133,7 +133,9 @@ class Root(object): | ||
133 | 133 | ||
134 | if self.app.login(uid, pw): # ok | 134 | if self.app.login(uid, pw): # ok |
135 | cherrypy.session[SESSION_KEY] = cherrypy.request.login = uid | 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 | else: # denied | 139 | else: # denied |
138 | return self.template['login'].render() | 140 | return self.template['login'].render() |
139 | 141 |
static/js/admin.js
@@ -46,13 +46,20 @@ $(document).ready(function() { | @@ -46,13 +46,20 @@ $(document).ready(function() { | ||
46 | var rows = ""; | 46 | var rows = ""; |
47 | $.each(students, function(i, r) { | 47 | $.each(students, function(i, r) { |
48 | if (r[1]['start_time'] != '') { | 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 | active.sort(function(a,b){return a[2] < b[2] ? -1 : (a[2] == b[2] ? 0 : 1);}); | 53 | active.sort(function(a,b){return a[2] < b[2] ? -1 : (a[2] == b[2] ? 0 : 1);}); |
53 | n = active.length; | 54 | n = active.length; |
54 | for(var i = 0; i < n; i++) { | 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 | $("#online_students").html(rows); | 64 | $("#online_students").html(rows); |
58 | $("#online-header").html(n + " Activo(s)"); | 65 | $("#online-header").html(n + " Activo(s)"); |
templates/admin.html
@@ -92,6 +92,7 @@ | @@ -92,6 +92,7 @@ | ||
92 | <th>Nome</th> | 92 | <th>Nome</th> |
93 | <th>Data de início</th> | 93 | <th>Data de início</th> |
94 | <th>Hora de início</th> | 94 | <th>Hora de início</th> |
95 | + <th>IP</th> | ||
95 | </tr> | 96 | </tr> |
96 | </thead> | 97 | </thead> |
97 | <tbody id="online_students"> | 98 | <tbody id="online_students"> |