[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [torouter/master] Implement rudimentary session and login management



commit 30bf29091b7dd5531c5a096e09f3cdb6331b342f
Author: Arturo FilastoÌ? <hellais@xxxxxxxxxxxxxx>
Date:   Thu Aug 11 18:18:34 2011 +0200

    Implement rudimentary session and login management
---
 packages/torouter-web/config.py                    |    1 -
 packages/torouter-web/config.pyc                   |  Bin 228 -> 255 bytes
 packages/torouter-web/runui.py                     |    3 +
 packages/torouter-web/runui.pyc                    |  Bin 1271 -> 1390 bytes
 packages/torouter-web/tui/__init__.pyc             |  Bin 142 -> 169 bytes
 packages/torouter-web/tui/controllers/__init__.pyc |  Bin 154 -> 181 bytes
 packages/torouter-web/tui/controllers/main.py      |   11 ++++-
 packages/torouter-web/tui/controllers/main.pyc     |  Bin 855 -> 1196 bytes
 packages/torouter-web/tui/controllers/network.py   |   49 +++++++++++++++----
 packages/torouter-web/tui/controllers/network.pyc  |  Bin 5261 -> 6373 bytes
 packages/torouter-web/tui/controllers/tor.py       |    1 +
 packages/torouter-web/tui/controllers/tor.pyc      |  Bin 1419 -> 1662 bytes
 packages/torouter-web/tui/utils/__init__.pyc       |  Bin 0 -> 175 bytes
 packages/torouter-web/tui/utils/session.py         |   22 +++++++++
 packages/torouter-web/tui/utils/session.pyc        |  Bin 0 -> 1207 bytes
 packages/torouter-web/tui/views/login.html         |    7 +++
 packages/torouter-web/view.pyc                     |  Bin 384 -> 411 bytes
 17 files changed, 80 insertions(+), 14 deletions(-)

diff --git a/packages/torouter-web/config.py b/packages/torouter-web/config.py
index 9b8f7a7..9411bb7 100644
--- a/packages/torouter-web/config.py
+++ b/packages/torouter-web/config.py
@@ -9,4 +9,3 @@ cache = False
 globals = {}
 
 
-
diff --git a/packages/torouter-web/config.pyc b/packages/torouter-web/config.pyc
index 7eb9e48..23bf9e9 100644
Binary files a/packages/torouter-web/config.pyc and b/packages/torouter-web/config.pyc differ
diff --git a/packages/torouter-web/runui.py b/packages/torouter-web/runui.py
index 5f27e4f..9b33d7a 100644
--- a/packages/torouter-web/runui.py
+++ b/packages/torouter-web/runui.py
@@ -6,8 +6,10 @@ import web
 import config
 import tui.controllers
 
+from tui.utils import session
 from view import render
 
+
 urls = (
     '/', 'tui.controllers.main.index',
 #    '/config/(tor|router)', 'tui.controllers.main.config',
@@ -24,6 +26,7 @@ urls = (
 
 if __name__ == "__main__":
   app = web.application(urls, globals())
+  session.add_session_to_app(app)
   app.internalerror = web.debugerror
   app.run()
 
diff --git a/packages/torouter-web/runui.pyc b/packages/torouter-web/runui.pyc
index dc829b3..ce57e6c 100644
Binary files a/packages/torouter-web/runui.pyc and b/packages/torouter-web/runui.pyc differ
diff --git a/packages/torouter-web/tui/__init__.pyc b/packages/torouter-web/tui/__init__.pyc
index df02c3e..912a260 100644
Binary files a/packages/torouter-web/tui/__init__.pyc and b/packages/torouter-web/tui/__init__.pyc differ
diff --git a/packages/torouter-web/tui/controllers/__init__.pyc b/packages/torouter-web/tui/controllers/__init__.pyc
index 8568b24..47771bf 100644
Binary files a/packages/torouter-web/tui/controllers/__init__.pyc and b/packages/torouter-web/tui/controllers/__init__.pyc differ
diff --git a/packages/torouter-web/tui/controllers/main.py b/packages/torouter-web/tui/controllers/main.py
index 2806467..7e1df50 100644
--- a/packages/torouter-web/tui/controllers/main.py
+++ b/packages/torouter-web/tui/controllers/main.py
@@ -1,14 +1,21 @@
 import web
 import view, config
 from view import render
+from tui.utils import session 
 
 """
 The main page for network configuration
 """
 class index:
   def GET(self):
-    return render.base(render.index())
+    if session.is_logged() > 0:
+      return render.base(render.index())
+    else:
+      return render.base(render.login())
 
   def POST(self):
-    return render.base(render.index())
+    if session.check_login(web.input()) == 0:
+      return render.base(render.index())
+    else:
+      return render.base(render.login())
 
diff --git a/packages/torouter-web/tui/controllers/main.pyc b/packages/torouter-web/tui/controllers/main.pyc
index 8bd620b..6fb29f0 100644
Binary files a/packages/torouter-web/tui/controllers/main.pyc and b/packages/torouter-web/tui/controllers/main.pyc differ
diff --git a/packages/torouter-web/tui/controllers/network.py b/packages/torouter-web/tui/controllers/network.py
index 33e7f27..7022ca4 100644
--- a/packages/torouter-web/tui/controllers/network.py
+++ b/packages/torouter-web/tui/controllers/network.py
@@ -1,6 +1,7 @@
 import web
 import view, config
 from view import render
+from tui.utils import session
 
 """
 This function is used to generate the network
@@ -28,20 +29,34 @@ The main page for network configuration
 """
 class main:
   def GET(self):
-    return render.base(render.main(),menu(0))
+    if session.is_logged() > 0:
+      return render.base(render.main(),menu(0))
+    else:
+      return render.base(render.login())
 
   def POST(self):
-    return render.base(render.main(),menu(0))
+    if session.is_logged() > 0:
+      return render.base(render.main(),menu(0))
+    else:
+      return render.base(render.login())
 
 """
 The firewall configuration page
 """
 class firewall:
   def GET(self):
-    return render.base(render.firewall(),menu(1))
+    if session.is_logged() > 0:
+      return render.base(render.main(),menu(0))
+    else:
+      return render.base(render.login())
 
   def POST(self):
-    return render.base(render.firewall(),menu(1))
+    if session.is_logged() > 0:
+      return render.base(render.firewall(),menu(1))
+    else:
+      return render.base(render.login())
+  
+
 
 """
 Wireless network configuration page
@@ -78,23 +93,35 @@ class wireless:
     return True
 
   def GET(self):
-    if self.build_form():
-      return render.base(render.wireless(self.form()),menu(2))
+    if session.is_logged() > 0:
+      if self.build_form():
+        return render.base(render.wireless(self.form()),menu(2))
+    else:
+      return render.base(render.login())
 
   def POST(self):
-    self.update_config(None)
-    print web.input()
-    return render.base(render.saved(web.input()),menu(2))
+    if session.is_logged() > 0:
+      self.update_config(None)
+      print web.input()
+      return render.base(render.saved(web.input()),menu(2))
+    else:
+      return render.base(render.login())
 
 """
 Wired network configuration page
 """
 class wired:
   def GET(self):
-    return render.base(render.wired(),menu(3))
+    if session.is_logged() > 0:
+      return render.base(render.wired(),menu(3))
+    else:
+      return render.base(render.login())
 
   def POST(self):
-    return render.base(render.wired(),menu(3))
+    if session.is_logged() > 0:
+      return render.base(render.wired(),menu(3))
+    else:
+      return render.base(render.login())
 
 """
 General status page, displays a bit more detail than main
diff --git a/packages/torouter-web/tui/controllers/network.pyc b/packages/torouter-web/tui/controllers/network.pyc
index 0fa3453..ba6e816 100644
Binary files a/packages/torouter-web/tui/controllers/network.pyc and b/packages/torouter-web/tui/controllers/network.pyc differ
diff --git a/packages/torouter-web/tui/controllers/tor.py b/packages/torouter-web/tui/controllers/tor.py
index 3b6116f..ca96209 100644
--- a/packages/torouter-web/tui/controllers/tor.py
+++ b/packages/torouter-web/tui/controllers/tor.py
@@ -1,6 +1,7 @@
 import web
 import view, config
 from view import render
+from tui.utils import session
 
 """
 The main Tor status page
diff --git a/packages/torouter-web/tui/controllers/tor.pyc b/packages/torouter-web/tui/controllers/tor.pyc
index 21724c4..0c5e9f5 100644
Binary files a/packages/torouter-web/tui/controllers/tor.pyc and b/packages/torouter-web/tui/controllers/tor.pyc differ
diff --git a/packages/torouter-web/tui/utils/__init__.py b/packages/torouter-web/tui/utils/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/packages/torouter-web/tui/utils/__init__.pyc b/packages/torouter-web/tui/utils/__init__.pyc
new file mode 100644
index 0000000..3700fb7
Binary files /dev/null and b/packages/torouter-web/tui/utils/__init__.pyc differ
diff --git a/packages/torouter-web/tui/utils/session.py b/packages/torouter-web/tui/utils/session.py
new file mode 100644
index 0000000..375b6bc
--- /dev/null
+++ b/packages/torouter-web/tui/utils/session.py
@@ -0,0 +1,22 @@
+import web
+
+# The main session class
+  
+def add_session_to_app(app):
+
+  if web.config.get("_session") is None:
+    store = web.session.DiskStore('sessions')
+    session = web.session.Session(app, store, initializer={'login': 0, 'privilege': 0})
+    web.config._session = session
+  else:
+    session = web.config._session
+
+def is_logged():
+  return web.config._session.login
+
+def check_login(data):
+  if (data.user == "test") and (data.password == "test"):
+    web.config._session.login = 1
+    return 0
+  return 1
+
diff --git a/packages/torouter-web/tui/utils/session.pyc b/packages/torouter-web/tui/utils/session.pyc
new file mode 100644
index 0000000..2084493
Binary files /dev/null and b/packages/torouter-web/tui/utils/session.pyc differ
diff --git a/packages/torouter-web/tui/views/login.html b/packages/torouter-web/tui/views/login.html
new file mode 100644
index 0000000..1377078
--- /dev/null
+++ b/packages/torouter-web/tui/views/login.html
@@ -0,0 +1,7 @@
+Login is required
+<form method="POST" action="/">
+  Login: <input type="text" name="user">
+  Password: <input type="password" name="password">
+  <input type="submit" name="login">
+</form>
+
diff --git a/packages/torouter-web/view.pyc b/packages/torouter-web/view.pyc
index b8a529b..17728c0 100644
Binary files a/packages/torouter-web/view.pyc and b/packages/torouter-web/view.pyc differ

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits