aboutsummaryrefslogtreecommitdiffstats
path: root/packages/torouter-web/src/tui/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'packages/torouter-web/src/tui/controllers')
-rw-r--r--packages/torouter-web/src/tui/controllers/__init__.py0
-rw-r--r--packages/torouter-web/src/tui/controllers/main.py26
-rw-r--r--packages/torouter-web/src/tui/controllers/network.py129
-rw-r--r--packages/torouter-web/src/tui/controllers/old/main.py11
-rw-r--r--packages/torouter-web/src/tui/controllers/old/status.py9
-rw-r--r--packages/torouter-web/src/tui/controllers/old/wizard.py81
-rw-r--r--packages/torouter-web/src/tui/controllers/tor.py35
7 files changed, 291 insertions, 0 deletions
diff --git a/packages/torouter-web/src/tui/controllers/__init__.py b/packages/torouter-web/src/tui/controllers/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/packages/torouter-web/src/tui/controllers/__init__.py
diff --git a/packages/torouter-web/src/tui/controllers/main.py b/packages/torouter-web/src/tui/controllers/main.py
new file mode 100644
index 0000000..060caa6
--- /dev/null
+++ b/packages/torouter-web/src/tui/controllers/main.py
@@ -0,0 +1,26 @@
+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):
+ if session.is_logged() > 0:
+ return render.base(render.index())
+ else:
+ return render.base(render.login())
+
+ def POST(self):
+ if session.check_login(web.input()) == 0:
+ return render.base(render.index())
+ else:
+ return render.base(render.login())
+
+class logout:
+ def GET(self):
+ session.logout()
+ return render.base(render.logout())
+
diff --git a/packages/torouter-web/src/tui/controllers/network.py b/packages/torouter-web/src/tui/controllers/network.py
new file mode 100644
index 0000000..cc46643
--- /dev/null
+++ b/packages/torouter-web/src/tui/controllers/network.py
@@ -0,0 +1,129 @@
+import web
+import view, config
+from view import render
+from tui.utils import session,configuration,parsing
+
+"""
+This function is used to generate the network
+submenus.
+"""
+def menu(n):
+ a = []
+ for i in range(0,5):
+ if i == n:
+ a.append("sel")
+ else:
+ a.append("")
+ print a
+ return """<ul id="submenu">
+ <li><a href="/network" class="%s">Main</a></li>
+ <li><a href="/network/firewall" class="%s">Firewall</a></li>
+ <li><a href="/network/wireless" class="%s">Wireless</a></li>
+ <li><a href="/network/wired" class="%s">Wired</a></li>
+ <li><a href="/network/status" class="%s">Status</a></li>
+</ul>
+""" % tuple(a)
+
+"""
+The main page for network configuration
+"""
+class main:
+ # XXX do all the backend stuff
+ def update_config(self, data):
+ return True
+
+ def GET(self):
+ if session.is_logged() > 0:
+ return render.base(render.main(),menu(0))
+ else:
+ return render.base(render.login())
+
+ def POST(self):
+ if session.is_logged() > 0:
+ self.update_config(web.input())
+ return render.base(render.main(),menu(0))
+ else:
+ return render.base(render.login())
+
+"""
+The firewall configuration page
+"""
+class firewall:
+ # XXX do all the backend stuff
+ def update_config(self, data):
+ return True
+
+ def GET(self):
+ if session.is_logged() > 0:
+ return render.base(render.firewall(configuration.get_form("firewall")),menu(1))
+ else:
+ return render.base(render.login())
+
+ def POST(self):
+ if session.is_logged() > 0:
+ self.update_config(web.input())
+ return render.base(render.firewall(configuration.get_form("firewall")),menu(1))
+ else:
+ return render.base(render.login())
+
+
+
+"""
+Wireless network configuration page
+"""
+class wireless:
+ # XXX do all the backend stuff
+ def update_config(self, data):
+ return True
+
+ def GET(self):
+ if session.is_logged() > 0:
+ return render.base(render.wireless(configuration.get_form("wireless")),menu(2))
+ else:
+ return render.base(render.login())
+
+ def POST(self):
+ if session.is_logged() > 0:
+ self.update_config(web.input())
+ print web.input()
+ return render.base(render.saved(web.input()),menu(2))
+ else:
+ return render.base(render.login())
+
+"""
+Wired network configuration page
+"""
+class wired:
+ # XXX do all the backend stuff
+ def update_config(self, data):
+ return True
+
+ def GET(self):
+ if session.is_logged() > 0:
+ return render.base(render.wired(configuration.get_form("wired")),menu(3))
+ else:
+ return render.base(render.login())
+
+ def POST(self):
+ if session.is_logged() > 0:
+ self.update_config(web.input())
+ return render.base(render.wired(),menu(3))
+ else:
+ return render.base(render.login())
+
+"""
+General status page, displays a bit more detail than main
+"""
+class status:
+ def GET(self):
+ itfc = parsing.interfaces(config.interfaces_file)
+ itfc.parse()
+ network = itfc.html_output(itfc.wifi) + itfc.html_output(itfc.eth0) + itfc.html_output(itfc.eth1)
+ return render.base(render.status(network),menu(4))
+
+ def POST(self):
+ itfc = parsing.interfaces(config.interfaces_file)
+ itfc.parse()
+ network = itfc.html_output(itfc.wifi) + itfc.html_output(itfc.eth0) + itfc.html_output(itfc.eth1)
+ return render.base(render.status(),menu(4))
+
diff --git a/packages/torouter-web/src/tui/controllers/old/main.py b/packages/torouter-web/src/tui/controllers/old/main.py
new file mode 100644
index 0000000..9127e72
--- /dev/null
+++ b/packages/torouter-web/src/tui/controllers/old/main.py
@@ -0,0 +1,11 @@
+import web
+
+
+class index:
+ def GET(self):
+ return "index"
+
+class config:
+ def GET(self):
+ return "config"
+
diff --git a/packages/torouter-web/src/tui/controllers/old/status.py b/packages/torouter-web/src/tui/controllers/old/status.py
new file mode 100644
index 0000000..05f0bf8
--- /dev/null
+++ b/packages/torouter-web/src/tui/controllers/old/status.py
@@ -0,0 +1,9 @@
+import web
+import config
+
+from config import views
+from web import form
+
+class status:
+ def GET():
+ print "status"
diff --git a/packages/torouter-web/src/tui/controllers/old/wizard.py b/packages/torouter-web/src/tui/controllers/old/wizard.py
new file mode 100644
index 0000000..7b82df2
--- /dev/null
+++ b/packages/torouter-web/src/tui/controllers/old/wizard.py
@@ -0,0 +1,81 @@
+import web
+
+from web import form
+from config import view
+
+class step:
+ cur_step = 1
+ next_step = 2
+ wiztext = []
+ wizform = []
+
+ wiztext.append("Tor Configuration")
+ wizform.append(form.Form(
+ form.Textbox('Nickname',
+ form.notnull, description="Relay Nickname"),
+ form.Textbox('RelayBandwidthRate',
+ form.notnull, description="Relay Bandwidth Rate"),
+ form.Textbox('RelayBandwidthBurst',
+ form.notnull, description="Relay Bandwidth Burst"),
+ form.Textbox('ContactInfo',
+ form.notnull, description="Contact Info"),
+ form.Textbox('ExitPolicy',
+ form.notnull, description="Exit Policy"),
+ form.Button('Next Step')
+ ))
+
+ wiztext.append("Wireless setup")
+ wizform.append(form.Form(
+ form.Textbox('essid',
+ form.notnull, description="Wireless ESSID"),
+ form.Textbox('mac',
+ form.notnull, description="MAC address"),
+ form.Textbox('whatever',
+ form.notnull, description="Wireless ESSID"),
+ form.Button('Next Step')
+ ))
+
+ wiztext.append("")
+ wizform.append(form.Form(
+ form.Textbox('essid',
+ form.notnull, description="Wireless ESSID"),
+ form.Textbox('mac',
+ form.notnull, description="MAC address"),
+ form.Textbox('whatever',
+ form.notnull, description="Wireless ESSID"),
+ form.Button('Next Step')
+ ))
+
+ wiztext.append("")
+ wizform.append(form.Form(
+ form.Textbox('essid',
+ form.notnull, description="Wireless ESSID"),
+ form.Textbox('mac',
+ form.notnull, description="MAC address"),
+ form.Textbox('whatever',
+ form.notnull, description="Wireless ESSID"),
+ form.Button('Next Step')
+ ))
+
+ def GET(self, step):
+ if step:
+ self.cur_step = int(step)
+ self.next_step = int(step) + 1
+ else:
+ self.cur_step = 1
+ self.next_step = 2
+ if len(self.wizform) < int(self.cur_step):
+ return "Done!"
+ return view.wizard(self.wizform[self.cur_step-1], self.wiztext[self.cur_step-1], self.cur_step, self.next_step)
+
+ def POST(self, step):
+ x = web.input()
+ self.cur_step = int(step)
+ self.next_step = int(step) + 1
+ if len(self.wizform) < int(self.cur_step):
+ return "Done!"
+ return view.wizard(self.wizform[self.cur_step-1], self.wiztext[self.cur_step-1], self.cur_step, self.next_step)
+
+
+
+
diff --git a/packages/torouter-web/src/tui/controllers/tor.py b/packages/torouter-web/src/tui/controllers/tor.py
new file mode 100644
index 0000000..af8678c
--- /dev/null
+++ b/packages/torouter-web/src/tui/controllers/tor.py
@@ -0,0 +1,35 @@
+import web
+import view, config
+from view import render
+from tui.utils import session, parsing
+
+"""
+The main Tor status page
+"""
+class status:
+ def GET(self):
+ trc = parsing.torrc(config.torrc_file)
+ trc.parse()
+ output = trc.html_output()
+ return render.base(render.torstatus(output,config.torrc_file))
+
+ def POST(self):
+ trc = parsing.torrc(config.torrc_file)
+ trc.parse()
+ output = trc.html_output()
+ return render.base(render.torstatus(output,config.torrc_file))
+
+"""
+Tor configuration page
+"""
+class torrc:
+ def update_config(self, data):
+ return True
+
+ def GET(self):
+ return render.base(render.torconfig())
+
+ def POST(self):
+ self.update_config(web.input())
+ return render.base(render.torconfig())
+