Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added a donate/daypass option, and a simple dev entrypoint

  • Loading branch information...
commit 9bc8c0bd50a7176b7654332bb4264b8cdb2dce18 1 parent 667d62d
@progrium progrium authored
View
54 main.py
@@ -16,7 +16,9 @@
GUEST_TIMEOUT = 43200 # 12 hours
#GUEST_TIMEOUT = 60
GUEST_NAME = 'internet-guest*'
+DAYPASS_NAME = 'internet-daypass*'
DEFAULT_REDIRECT = 'http://hackerdojo.com'
+DONATE_BUTTON = '6JB7VARJDVHAG'
def dojo(path, force=False):
""" Hacker Dojo Domain API helper with caching """
@@ -120,7 +122,39 @@ class GuestHandler(webapp.RequestHandler):
def post(self):
memcache.set(self.request.get('mac'), GUEST_NAME, time=GUEST_TIMEOUT)
self.redirect(self.request.get('redirect') or DEFAULT_REDIRECT)
-
+
+class DonateHandler(webapp.RequestHandler):
+ """ Form handler when donating for a day pass """
+
+ def post(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])))
+ memcache.set(mac, GUEST_NAME, time=GUEST_TIMEOUT)
+ self.redirect("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=%s&notify_url=%s&return=%s" %
+ (DONATE_BUTTON, callback, callback))
+
+class DonateCallbackHandler(webapp.RequestHandler):
+ """ Callback handler for PayPal IPN (POST) and return from PayPal (GET) """
+
+ def post(self, data):
+ data = urllib.unquote(data)
+ mac, redirect = base64.b64decode(data).split(',')
+ if self._validate_ipn() and self.request.get('payment_status').lower() == 'completed':
+ memcache.set(mac, DAYPASS_NAME, time=GUEST_TIMEOUT)
+ self.get(data)
+
+ def _validate_ipn(self):
+ resp = urlfetch.fetch('https://www.paypal.com/cgi-bin/webscr', method="POST",
+ payload="cmd=_notify-validate&%s" % self.request.body)
+ return "VERIFIED" in resp.content
+
+ def get(self, data):
+ data = urllib.unquote(data)
+ mac, redirect = base64.b64decode(data).split(',')
+ if not redirect.startswith('http'):
+ redirect = DEFAULT_REDIRECT
+ self.response.out.write(template.render('templates/daypass.html', {'hours': GUEST_TIMEOUT/3600, 'redirect': redirect}))
class MacHandler(webapp.RequestHandler):
""" Endpoint used by RADIUS bridge """
@@ -128,7 +162,10 @@ class MacHandler(webapp.RequestHandler):
def get(self, mac):
guest = memcache.get(mac)
if guest:
- self.response.out.write("%s,," % guest)
+ if guest == DAYPASS_NAME:
+ self.response.out.write("%s,%s,%s" % (guest, MEMBER_DOWNLOAD, MEMBER_UPLOAD))
+ else:
+ self.response.out.write("%s,," % guest)
touch_stat('guests')
else:
mapping = MacAddressMapping.get_by_mac(mac)
@@ -151,12 +188,25 @@ 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),
('/api/mac/(.+)', MacHandler),
('/api/stat/(.+)', StatHandler),
('/guest', GuestHandler),
+ ('/donate/(.+)', DonateCallbackHandler),
+ ('/donate', DonateHandler),
('/member', MemberHandler),
('/(.+)', EntryHandler),] ,debug=True)
util.run_wsgi_app(application)
View
19 templates/base.html
@@ -0,0 +1,19 @@
+<html>
+ <head>
+ <title>Hacker Dojo Internet Access</title>
+ <link href="/static/style.css" type="text/css" rel="stylesheet" />
+ {% block header %}{% endblock %}
+ </head>
+ <body>
+ <div id="wrapper">
+ <div id="header">
+ <img src="/static/dojo_icon.png" style="float: left; " />
+ <h1>Hacker Dojo</h1>
+ <h2>Internet Access</h2>
+ </div>
+ <div id="content">
+ {% block content %}{% endblock %}
+ </div>
+ </div>
+ </body>
+</html>
View
13 templates/daypass.html
@@ -0,0 +1,13 @@
+{% extends 'base.html' %}
+{% block header %}
+ <meta http-equiv="refresh" content="5;url={{redirect}}" />
+{% endblock %}
+{% block content %}
+
+ <div>
+ <h2>Thanks for donating!</h2>
+ <p>You now have member quality internet for the next {{hours}} hours. Enjoy! :)</p>
+ <p>Redirecting to <a href="{{redirect}}">{{redirect}}</a> in the next five seconds...</p>
+ </div>
+
+{% endblock %}
View
5 templates/dev.html
@@ -0,0 +1,5 @@
+<form method="post">
+ MAC: <input type="text" name="mac" /><br />
+ Redirect: <input type="text" name="redirect" /><br />
+ <input type="submit" />
+</form>
View
29 templates/main.html
@@ -1,17 +1,5 @@
-<html>
- <head>
- <title>Hacker Dojo Internet Access</title>
- <link href="/static/style.css" type="text/css" rel="stylesheet" />
- </head>
- <body>
- <div id="wrapper">
- <div id="header">
- <img src="/static/dojo_icon.png" style="float: left; " />
- <h1>Hacker Dojo</h1>
- <h2>Internet Access</h2>
- </div>
- <div id="content">
-
+{% extends 'base.html' %}
+{% block content %}
<div id="member">
<h3>Member Access</h3>
{% if error %}<span style="color: red; font-size: smaller;">{{error}}</span>{% endif %}
@@ -31,15 +19,18 @@
<div id="guest">
<h2>Welcome to Hacker Dojo!</h2>
- <p class="notice">You're using <strong>HackerDojo-gwifi</strong>, which is currently running a beta of our new captive portal that will be on our new fiber connection coming in early 2011. It will allow us to easily provide unlimited access to members, throttled access to guests, and perhaps even eliminate the sign-in kiosk.<br /><br />
+ <p class="notice">You're using <strong>HackerDojo-gwifi</strong>, which is currently running a beta of our new captive portal that will be on our new fiber connection coming in early 2011. It will allow us to easily provide unlimited access to members, throttle access to guests, and perhaps even eliminate the sign-in kiosk.<br /><br />
Email <a href="mailto:internet@hackerdojo.com">internet@hackerdojo.com</a> for questions or feedback.</p>
<form method="post" action="/guest" style="text-align: center;">
<input type="hidden" name="redirect" value="{{redirect}}" />
<input type="hidden" name="mac" value="{{mac}}" />
<input name="accept" type="submit" value="Continue as Guest &rarr;" />
</form>
+ <form method="post" action="/donate" style="text-align: center;">
+ <input type="hidden" name="redirect" value="{{redirect}}" />
+ <input type="hidden" name="mac" value="{{mac}}" />
+ <input name="accept" type="submit" value="Donate $10 for Day Pass &rarr;" />
+ </form>
</div>
- </div>
- </div>
- </body>
-</html>
+
+{% endblock %}
Please sign in to comment.
Something went wrong with that request. Please try again.