Permalink
Browse files

Merge branch 'master' of github.com:hackerdojo/hd-captiveportal

  • Loading branch information...
2 parents ffa2cf5 + 738d091 commit d8a756b964974b511df69f4a8f69e8c08d528095 @progrium progrium committed Mar 26, 2011
View
@@ -9,3 +9,9 @@ indexes:
# manually, move them above the marker line. The index.yaml file is
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.
+
+- kind: MacAddressMapping
+ properties:
+ - name: username
+ - name: created
+ direction: desc
View
44 main.py
@@ -9,6 +9,7 @@
import base64
import urllib
import time
+import string
DOMAIN = 'hackerdojo.com'
MEMBER_DOWNLOAD = 0
@@ -56,6 +57,14 @@ def get_stat(name, resolution=60):
else:
return 0
+class Login(db.Model):
+ """ A non log of logins. """
+
+ address = db.StringProperty()
+ username = db.StringProperty()
+ created = db.DateTimeProperty(auto_now_add=True)
+
+
class MacAddressMapping(db.Model):
""" Member MAC address mapping
@@ -68,11 +77,32 @@ class MacAddressMapping(db.Model):
username = db.StringProperty()
created = db.DateTimeProperty(auto_now_add=True)
+ @classmethod
+ def register_new_device(cls, address, username):
+ total_devices = 2
+ devices = cls.all().filter('username =', username).order("-created").fetch(100)
+ for d in devices[total_devices-1:]:
+ d.delete()
+ m = cls(address=address, username=username)
+ m.put()
+ return m
+
+
@classmethod
def get_by_mac(cls, address):
return cls.all().filter('address =', address).get()
+class LogHandler(webapp.RequestHandler):
+ """ Show log """
+
+ def get(self):
+ log = Login.all()
+ self.response.out.write(template.render('templates/log.html', {
+ 'log': log
+ }))
+
+
class EntryHandler(webapp.RequestHandler):
""" Entry point for the wifi app
@@ -99,17 +129,18 @@ class MemberHandler(webapp.RequestHandler):
def post(self):
client = AppsService(domain=DOMAIN)
- username = self.request.get('username')
+ username = string.split(self.request.get('username'),"@")[0].strip()
mac = self.request.get('mac')
redirect = self.request.get('redirect')
try:
- client.ClientLogin('%s@%s' % (username, DOMAIN), self.request.get('password'))
+ client.ClientLogin('%s@%s' % (username, DOMAIN), self.request.get('password').strip())
+ login = Login(username=username, address = mac)
+ login.put()
existing = MacAddressMapping.get_by_mac(mac)
if existing and not is_suspended(username):
self.redirect(redirect or DEFAULT_REDIRECT)
elif not is_suspended(username):
- m = MacAddressMapping(address=mac, username=username)
- m.put()
+ MacAddressMapping.register_new_device(mac,username)
self.redirect(redirect or DEFAULT_REDIRECT)
else:
raise Exception("Invalid account")
@@ -119,7 +150,7 @@ def post(self):
class GuestHandler(webapp.RequestHandler):
""" Form handler when connecting as a guest """
- def post(self):
+ def get(self):
memcache.set(self.request.get('mac'), GUEST_NAME, time=GUEST_TIMEOUT)
self.redirect(self.request.get('redirect') or DEFAULT_REDIRECT)
@@ -139,7 +170,7 @@ def post(self):
class DonateHandler(webapp.RequestHandler):
""" Form handler when donating for a day pass """
- def post(self):
+ def get(self):
mac = self.request.get('mac')
redirect = self.request.get('redirect') or DEFAULT_REDIRECT
callback = "%s/donate/%s" % (self.request.host_url, base64.b64encode(','.join([mac, redirect])))
@@ -215,6 +246,7 @@ def post(self):
def main():
application = webapp.WSGIApplication([
('/dev', DevHandler),
+ ('/log', LogHandler),
('/api/mac/(.+)', MacHandler),
('/api/stat/(.+)', StatHandler),
('/guest', GuestHandler),
View
@@ -0,0 +1,3 @@
+*.pyc
+*/*.pyc
+*/*/.pyc
Oops, something went wrong.

0 comments on commit d8a756b

Please sign in to comment.