Ver Fonte

Small improvements in the WEBUI

 * Require auth for all view!
 * Fix error in the main templates
 * initialize the Crypto instance before launching the webui.
oz123 há 10 anos atrás
pai
commit
3912266416
2 ficheiros alterados com 27 adições e 19 exclusões
  1. 1 4
      pwman/ui/templates/main.tpl
  2. 26 15
      scripts/webui.py

+ 1 - 4
pwman/ui/templates/main.tpl

@@ -11,12 +11,9 @@
 <table border="1">
 %for node in nodes:
 <tr>
-  %#for item in node:
-  %# <td><a href={{node._id}}><{{item}}</a></td>
   <td><a href=/node/{{node._id}}>{{node.username}}@{{node.url}}</a></td>
   <td>{{  ', '.join([t.strip() for t in filter(None, node.tags)]) }}</td>
-  <td><a href="/edit/{{node._id}}>edit</td>
-  %end
+  <td><a href=/edit/{{node._id}}>edit</a></td>
   </tr>
 %end
 </table>

+ 26 - 15
scripts/webui.py

@@ -32,7 +32,17 @@ TAGS = None
 DB = None
 
 
+def require_auth(fn):
+    def check_auth(**kwargs):
+        if AUTHENTICATED:
+            return fn(**kwargs)
+        else:
+            redirect("/auth")
+    return check_auth
+
+
 @route('/node/:no')
+@require_auth
 def view_node(no):
     global DB
     node = DB.getnodes([no])
@@ -47,6 +57,7 @@ def submit_node(id, request):
 
 @route('/new/', method=['GET', 'POST'])
 @route('/edit/:no', method=['GET', 'POST'])
+@require_auth
 def edit_node(no=None):
     global DB
 
@@ -76,7 +87,6 @@ def edit_node(no=None):
 
 @route('/auth', method=['GET', 'POST'])
 def is_authenticated():
-
     global AUTHENTICATED
     crypto = CryptoEngine.get()
 
@@ -90,22 +100,12 @@ def is_authenticated():
 
 
 @route('/', method=['GET', 'POST'])
-def listnodes():
+@require_auth
+def listnodes(apply=['require_login']):
 
     global AUTHENTICATED, TAGS, DB
 
     _filter = None
-    OSX = False
-    args = parser_options().parse_args()
-    xselpath, dbtype = get_conf_options(args, OSX)
-    dbver = 0.4
-    DB = pwman.data.factory.create(dbtype, dbver)
-    DB.open()
-
-    crypto = CryptoEngine.get()
-
-    if not AUTHENTICATED:
-        redirect('/auth')
 
     if 'POST' in request.method:
         _filter = request.POST.get('tag')
@@ -133,5 +133,16 @@ def listnodes():
                                                              'ui/templates')])
     return html_nodes
 
-debug(True)
-run(reloader=True)
+
+if __name__ == '__main__':
+    OSX = False
+    args = parser_options().parse_args()
+    xselpath, dbtype = get_conf_options(args, OSX)
+    dbver = 0.4
+    DB = pwman.data.factory.create(dbtype, dbver)
+    DB.open()
+
+    crypto = CryptoEngine.get()
+
+    debug(True)
+    run(reloader=True)