Permalink
Browse files

Binding authentication to html views; fixing tor html controller.

  • Loading branch information...
1 parent 2107234 commit 64e04e1cab865ccc9fd00312faa1e726d44bbe1d @mmaker committed Aug 13, 2012
Showing with 20 additions and 4 deletions.
  1. +18 −3 apaf/panel/handlers/html.py
  2. +1 −1 apaf/panel/panel.py
  3. +1 −0 datadir/services/panel/templates/tor.html
View
21 apaf/panel/handlers/html.py
@@ -1,4 +1,5 @@
#-*- coding: UTF-8 -*-
+import urlparse
from txtorcon import torcontrolprotocol
from twisted.internet import defer
@@ -12,7 +13,7 @@
from base import PanelHandler
-def render(page, **args):
+def render(page, _authenticated=False, **args):
"""
Simple helper function for returning a PanelHandler page.
:param page: path for html page
@@ -23,7 +24,7 @@ def get(self):
self.render(page, **args)
return type('Handler_'+page, (PanelHandler,),
- {'get': get})
+ {'get': get if not _authenticated else web.authenticated(get)})
def render_with_controller(page, controller, *args, **kwargs):
"""
@@ -53,6 +54,7 @@ def parse_type(self, var):
else:
return 'text'
+ @web.authenticated
def get(self):
return self.render(
'config.html',
@@ -63,6 +65,7 @@ def get(self):
class ServiceHandler(PanelHandler):
controller = controllers.ServicesCtl()
+ @web.authenticated
def get(self):
service = self.get_argument('service', None)
return self.render('services.html' if not service else 'serviceinfo.html',
@@ -78,10 +81,22 @@ def get(self):
else: self.redirect(self.REDIRECT)
def post(self):
- request = dict(x.split('=', 1) for x in self.request.body.split('&'))
+ request, = urlparse.parse_qs(self.requestbody).get('passwd', ['', ])
if not self.auth_login(request['passwd']):
raise web.HTTPAuthenticationRequired
else:
return self.redirect(self.REDIRECT)
+
+class TorHandler(PanelHandler):
+ controller = controllers.TorCtl()
+
+ @web.authenticated
+ @defer.inlineCallbacks
+ def get(self):
+ bootstrap = yield self.controller.get('status/bootstrap-phase')
+ self.render('tor.html',
+ version=apaf.torctl.version,
+ bootstrap=bootstrap,
+ )
View
2 apaf/panel/panel.py
@@ -46,7 +46,7 @@ class PanelService(Service):
# Legacy html
(r'/index.html', handlers.html.render('index.html')),
(r'/services.html', handlers.html.ServiceHandler),
- (r'/tor.html', handlers.html.render('tor.html')),
+ (r'/tor.html', handlers.html.TorHandler),
(r'/config.html', handlers.html.ConfigHandler),
(r'/about.html', handlers.html.render('about.html')),
(r'/login.html', handlers.html.LoginHandler),
View
1 datadir/services/panel/templates/tor.html
@@ -15,6 +15,7 @@
<div class="row">
<div class="span8">
Tor version: <code>{{ version }}</code>
+ <br>
Bootstrap: <code>{{ bootstrap }}</code>
</div>
<button class="btn" href="http://check.torproject.org">

0 comments on commit 64e04e1

Please sign in to comment.