Permalink
Browse files

Better logs for wifi authentication

Quiet room becomes Edison Room
Better calculation event duration for wifi portal
  • Loading branch information...
1 parent 4ec3aed commit cfaa915b169b730c1a92eae96c1c3e6fc9e5bc4a @Cealtea Cealtea committed Mar 8, 2017
Showing with 63 additions and 32 deletions.
  1. +41 −24 main.py
  2. +1 −1 models.py
  3. +2 −2 templates/wifi_login.html
  4. +19 −5 tests/test_main.py
View
65 main.py
@@ -1386,7 +1386,9 @@ def get(self):
"""
base_grant_url = self.request.get('base_grant_url', None)
user_continue_url = self.request.get('user_continue_url', None)
+ client_mac = self.request.get('client_mac', None)
+ logger.info('Start Connection to HD-Events - Client with MAC %s' % client_mac)
if not base_grant_url or not user_continue_url:
logger.error("access refused, missing parameters")
data = {
@@ -1403,9 +1405,12 @@ def post(self):
Handler that validates the password entered on the login and grant access to the wifi.
"""
+ client_mac = self.request.get('client_mac', None)
base_grant_url = self.request.get('base_grant_url', None)
user_continue_url = self.request.get('user_continue_url', None)
+ logger.info("Starting Authentication for client with MAC -- %s" % client_mac)
+
if base_grant_url and user_continue_url:
base_grant_url = cgi.escape(base_grant_url)
user_continue_url = cgi.escape(user_continue_url)
@@ -1418,13 +1423,13 @@ def post(self):
self.response.write(template.render('templates/wifi_login_error.html', data))
return
- logger.debug("Grant url received is: %s" % base_grant_url)
- logger.debug("Continue url received is: %s" % user_continue_url)
+ logger.info("Grant url received is: %s" % base_grant_url)
+ logger.info("Continue url received is: %s" % user_continue_url)
password = self.request.get('wifi', None)
if password:
password = cgi.escape(password)
- logger.debug("password typed is: %s" % password)
+ logger.info("password typed is: %s" % password)
else:
logger.error("access try again, missing password")
data = {'error': "The password is missing. Please try again!"}
@@ -1433,19 +1438,24 @@ def post(self):
return
events_list = Event.get_by_wifi_password(password)
- logger.debug(events_list)
if events_list:
now = local_now()
- logger.debug(now)
for event in events_list:
- logger.debug(event.name)
- start_time = event.start_time - timedelta(minutes=15)
- end_time = event.end_time + timedelta(minutes=15)
- logger.debug(start_time)
- logger.debug(end_time)
- if start_time <= now <= end_time:
- # user can access wifi for x hours
- logger.debug("access granted")
+ logger.info("Event is %s" % event.name)
+ start_time = event.start_time - timedelta(minutes=10) - timedelta(minutes=event.setup)
+ end_time = event.end_time + timedelta(minutes=10) + timedelta(minutes=event.teardown)
+ logger.info("Authorized login from %s to %s" % (start_time, end_time))
+
+ if start_time <= now < end_time:
+ # event started
+ session_duration = end_time - now
+ session_duration = int(session_duration.total_seconds())
+ logger.info("Time remaining in session: %s seconds" % session_duration)
+
+ # user can access wifi for 2 hours and then need to login again
+ # append grant url with duration
+ grant_url = "%s&duration=%s" % (grant_url, 7200)
+ logger.info("Access granted to %s for 2 hours" % client_mac)
self.response.write(template.render('templates/wifi_login_auth.html', locals()))
return
else:
@@ -1475,14 +1485,13 @@ class CheckWifiHandler(webapp2.RequestHandler):
"""
"""
-
def post(self):
"""
handler that check if the given password is valid and return the duration of the event
:return:
"""
given_password = self.request.get('event', None)
- event_validation = {'valid': False, 'duration_session': 0, 'start_time': 0}
+ event_validation = {'valid': False}
if not given_password:
self.response.set_status(401)
@@ -1495,17 +1504,25 @@ def post(self):
now_time = local_now()
for event in events_list:
logging.info("Found event %s with correct password" % event.name)
- start_time = event.start_time - timedelta(minutes=30)
- end_time = event.end_time + timedelta(minutes=30)
- duration = (end_time - now_time).total_seconds()
-
- if start_time <= now_time <= end_time:
- logging.info("Valid event started at %s, session allowed for %s sec" % (event.start_time, duration))
+ start_time = event.start_time - timedelta(minutes=10) - timedelta(minutes=event.setup)
+ end_time = event.end_time + timedelta(minutes=10) + timedelta(minutes=event.teardown)
+ session_duration = end_time - now_time
+ session_duration = int(session_duration.total_seconds())
+ logger.info("Time remaining in session: %s seconds" % session_duration)
+ if session_duration >= 21600:
+ logger.warning("Event duration is more than 6 hours")
+
+ if start_time <= now_time < end_time:
+ logging.info("Valid event started at %s, session allowed for %s sec" % (event.start_time, session_duration))
event_validation['valid'] = True
- event_validation['start_time'] = str(event.start_time)
- event_validation['duration_session'] = duration
+ event_validation['event_start_time'] = str(event.start_time)
+ event_validation['event_end_time'] = str(event.end_time)
+ event_validation['session_start_time'] = str(start_time)
+ event_validation['session_end_time'] = str(end_time)
+ event_validation['duration_session'] = session_duration
else:
logging.info("Event not valid")
+
logging.info(event_validation)
self.response.write(json.dumps(event_validation))
return
@@ -1535,5 +1552,5 @@ def post(self):
('/bulk_action', BulkActionHandler),
('/bulk_action_check', BulkActionCheckHandler),
('/wifilogin', WifiLoginHandler),
- ('/check/wifi', CheckWifiHandler)
+ ('/check/event', CheckWifiHandler)
], debug=True)
View
@@ -14,7 +14,7 @@
ROOM_OPTIONS = (
('Maker Space', 10),
('Classroom', 40),
- ('Quiet Room', 8),
+ ('Edison Room', 8),
# ('Flex Room', 10),
('Large Event Room', 80),
('Main Space', 100),
@@ -22,8 +22,8 @@
If you are a member, please disconnect from this SSID and choose HD-Members.
<form method="post">
<div class="row column" style="margin-top: 20px">
- <label>Please enter the event wifi password
- <input type="text" placeholder="Event wifi password" name="wifi" onkeyup="enableSubmit(this)">
+ <label>Please enter the event password
+ <input type="text" placeholder="Event password" name="wifi" onkeyup="enableSubmit(this)">
</label>
<p><button type="submit" id="submitpassword" class="button expanded" disabled>Login</button></p>
</div>
View
@@ -155,30 +155,44 @@ def test_get(self):
test get not allowed
:return:
"""
- response = self.test_app.get("/check/wifi", expect_errors=True)
+ response = self.test_app.get("/check/event", expect_errors=True)
self.assertEqual(405, response.status_int)
+ def test_get_wifilogin(self):
+ """
+ test get wifilogin
+ :return:
+ """
+ response = self.test_app.get("/wifilogin", expect_errors=True)
+ self.assertEqual(401, response.status_int)
+
+ def test_get_wifilogin_params(self):
+ """
+ test get wifilogin
+ :return:
+ """
+ response = self.test_app.get("/wifilogin?user_continue_url=ewj&base_grant_url=shaj", expect_errors=False)
+ self.assertEqual(200, response.status_int)
+
def test_post(self):
"""
test get not allowed
:return:
"""
- response = self.test_app.post("/check/wifi", params={"event": "euwi"})
+ response = self.test_app.post("/check/event", params={"event": "euwi"})
self.assertEqual(200, response.status_int)
def test_post_no_param(self):
"""
test post without params not allowed
:return:
"""
- response = self.test_app.post("/check/wifi", params={}, expect_errors=True)
+ response = self.test_app.post("/check/event", params={}, expect_errors=True)
self.assertEqual(401, response.status_int)
""" Tests that the new event handler works properly. """
-
-
class NewHandlerTest(BaseTest):
""" Tests that it gives us a page that seems correct. """

0 comments on commit cfaa915

Please sign in to comment.