Permalink
Browse files

put reset handler on / and keep your mac in a cookie

  • Loading branch information...
1 parent 9d14bb4 commit deea2d5ffcb46636cd384e930541ef85c77181be @progrium progrium committed Mar 27, 2011
Showing with 22 additions and 15 deletions.
  1. +9 −15 main.py
  2. +13 −0 pfsense/install.sh
  3. 0 templates/{dev.html → reset.html}
View
24 main.py
@@ -104,7 +104,7 @@ def get(self):
class EntryHandler(webapp.RequestHandler):
- """ Entry point for the wifi app
+ """ Entry point for the captive portal app
The pfSense Captive Portal page (as defined in pfsense/portal.php) will
redirect to this endpoint. It will encode the user's MAC address and
@@ -115,6 +115,7 @@ def get(self, data):
try:
data = urllib.unquote(data)
mac, redirect = base64.b64decode(data).split(',')
+ self.response.headers.add_header('Set-Cookie', 'mac=%s;' % mac)
self.response.out.write(template.render('templates/main.html', {
'redirect': redirect,
'mac': mac,
@@ -158,8 +159,12 @@ class ResetHandler(webapp.RequestHandler):
""" Resets guest MAC mapping so they see the captive portal again """
def get(self):
- # Reusing the dev handler template to capture the MAC address
- self.response.out.write(template.render('templates/dev.html', {}))
+ if self.request.cookies.has_key('mac'):
+ mac = self.request.cookies['mac']
+ memcache.delete(mac)
+ self.redirect('/%s' % base64.b64encode(','.join([mac, DEFAULT_REDIRECT])))
+ else:
+ self.response.out.write(template.render('templates/reset.html', {}))
def post(self):
memcache.delete(self.request.get('mac'))
@@ -232,25 +237,14 @@ def get(self, name=None):
stat = members+guests
self.response.out.write(str(stat))
-class DevHandler(webapp.RequestHandler):
- """ Convenience entry point for local development """
-
- def get(self):
- self.response.out.write(template.render('templates/dev.html', {}))
-
- def post(self):
- self.redirect('/%s' % base64.b64encode(','.join([
- self.request.get('mac'),
- self.request.get('redirect')])))
def main():
application = webapp.WSGIApplication([
- ('/dev', DevHandler),
+ ('/', ResetHandler),
('/log', LogHandler),
('/api/mac/(.+)', MacHandler),
('/api/stat/(.+)', StatHandler),
('/guest', GuestHandler),
- ('/reset', ResetHandler),
('/donate/(.+)', DonateCallbackHandler),
('/donate', DonateHandler),
('/member', MemberHandler),
View
13 pfsense/install.sh
@@ -0,0 +1,13 @@
+pkg_add -r python
+pkg_add -r py26-setuptools
+pkg_add -r screen
+rehash
+fetch http://pypi.python.org/packages/source/p/pyrad/pyrad-1.1.tar.gz
+tar -zxvf pyrad-1.1.tar.gz
+cd pyrad-1.1
+python setup.py install
+mkdir -p /home/captiveportal
+cd /home/captiveportal
+fetch https://github.com/progrium/hd-captiveportal/raw/master/pfsense/dictionary
+fetch https://github.com/progrium/hd-captiveportal/raw/master/pfsense/bridge.py
+screen python bridge.py
View
0 templates/dev.html → templates/reset.html
File renamed without changes.

0 comments on commit deea2d5

Please sign in to comment.