aboutsummaryrefslogtreecommitdiffstats
path: root/packages/torouter-web/tui
diff options
context:
space:
mode:
authorArturo FilastoĢ€ <hellais@torproject.org>2011-08-11 18:18:34 +0200
committerArturo FilastoĢ€ <hellais@torproject.org>2011-08-11 18:18:34 +0200
commit30bf29091b7dd5531c5a096e09f3cdb6331b342f (patch)
tree91c5694da3ffae8130bd45ca5ece58a6093a6f22 /packages/torouter-web/tui
parent5f53648315b1ed94f263da7c13d1754073649e9c (diff)
downloadtorouter-30bf29091b7dd5531c5a096e09f3cdb6331b342f.tar.gz
torouter-30bf29091b7dd5531c5a096e09f3cdb6331b342f.zip
Implement rudimentary session and login management
Diffstat (limited to 'packages/torouter-web/tui')
-rw-r--r--packages/torouter-web/tui/__init__.pycbin142 -> 169 bytes
-rw-r--r--packages/torouter-web/tui/controllers/__init__.pycbin154 -> 181 bytes
-rw-r--r--packages/torouter-web/tui/controllers/main.py11
-rw-r--r--packages/torouter-web/tui/controllers/main.pycbin855 -> 1196 bytes
-rw-r--r--packages/torouter-web/tui/controllers/network.py49
-rw-r--r--packages/torouter-web/tui/controllers/network.pycbin5261 -> 6373 bytes
-rw-r--r--packages/torouter-web/tui/controllers/tor.py1
-rw-r--r--packages/torouter-web/tui/controllers/tor.pycbin1419 -> 1662 bytes
-rw-r--r--packages/torouter-web/tui/utils/__init__.py0
-rw-r--r--packages/torouter-web/tui/utils/__init__.pycbin0 -> 175 bytes
-rw-r--r--packages/torouter-web/tui/utils/session.py22
-rw-r--r--packages/torouter-web/tui/utils/session.pycbin0 -> 1207 bytes
-rw-r--r--packages/torouter-web/tui/views/login.html7
13 files changed, 77 insertions, 13 deletions
diff --git a/packages/torouter-web/tui/__init__.pyc b/packages/torouter-web/tui/__init__.pyc
index df02c3e..912a260 100644
--- a/packages/torouter-web/tui/__init__.pyc
+++ b/packages/torouter-web/tui/__init__.pyc
Binary files differ
diff --git a/packages/torouter-web/tui/controllers/__init__.pyc b/packages/torouter-web/tui/controllers/__init__.pyc
index 8568b24..47771bf 100644
--- a/packages/torouter-web/tui/controllers/__init__.pyc
+++ b/packages/torouter-web/tui/controllers/__init__.pyc
Binary files 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
--- a/packages/torouter-web/tui/controllers/main.pyc
+++ b/packages/torouter-web/tui/controllers/main.pyc
Binary files 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
--- a/packages/torouter-web/tui/controllers/network.pyc
+++ b/packages/torouter-web/tui/controllers/network.pyc
Binary files 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
--- a/packages/torouter-web/tui/controllers/tor.pyc
+++ b/packages/torouter-web/tui/controllers/tor.pyc
Binary files 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
--- /dev/null
+++ b/packages/torouter-web/tui/utils/__init__.py
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
--- /dev/null
+++ b/packages/torouter-web/tui/utils/__init__.pyc
Binary files 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
--- /dev/null
+++ b/packages/torouter-web/tui/utils/session.pyc
Binary files 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>
+