diff --git a/app.py b/app.py index cd87db3..abff37f 100644 --- a/app.py +++ b/app.py @@ -156,6 +156,8 @@ class App(object): d[uid]['start_time'] = self.online.get(uid, {}).get('test', {}).get('start_time','') d[uid]['password_defined'] = pw != '' d[uid]['grades'] = self.db.get_student_grades_from_test(uid, self.testfactory['ref']) + d[uid]['ip_address'] = self.online.get(uid, {}).get('student', {}).get('ip_address','') + d[uid]['user_agent'] = self.online.get(uid, {}).get('student', {}).get('user_agent','') return d # def get_this_students_grades(self): @@ -179,6 +181,12 @@ class App(object): self.db.reset_password(uid) logger.info('Student {}: password reset to ""'.format(uid)) + def set_user_agent(self, uid, user_agent=''): + self.online[uid]['student']['user_agent'] = user_agent + + def set_user_ip(self, uid, ipaddress=''): + self.online[uid]['student']['ip_address'] = ipaddress + # ============================================================================ ch = logging.StreamHandler() ch.setLevel(logging.INFO) diff --git a/serve.py b/serve.py index b2ebf75..0958879 100755 --- a/serve.py +++ b/serve.py @@ -133,7 +133,9 @@ class Root(object): if self.app.login(uid, pw): # ok cherrypy.session[SESSION_KEY] = cherrypy.request.login = uid - raise cherrypy.HTTPRedirect('/') # FIXME + self.app.set_user_agent(uid, cherrypy.request.headers.get('User-Agent', '')) + self.app.set_user_ip(uid, cherrypy.request.remote.ip) + raise cherrypy.HTTPRedirect('/') else: # denied return self.template['login'].render() diff --git a/static/js/admin.js b/static/js/admin.js index c5cc1ae..5778b5b 100644 --- a/static/js/admin.js +++ b/static/js/admin.js @@ -46,13 +46,20 @@ $(document).ready(function() { var rows = ""; $.each(students, function(i, r) { if (r[1]['start_time'] != '') { - active.push([r[0], r[1]['name'], r[1]['start_time']]); + active.push([r[0], r[1]['name'], r[1]['start_time'], r[1]['ip_address'], r[1]['user_agent']]); } }); + // sort by start time active.sort(function(a,b){return a[2] < b[2] ? -1 : (a[2] == b[2] ? 0 : 1);}); n = active.length; for(var i = 0; i < n; i++) { - rows += "