From d6fe8f27bb248a0850a657520f263835ca961e1f Mon Sep 17 00:00:00 2001 From: Arturo Filastò Date: Fri, 12 Aug 2011 20:50:12 +0200 Subject: Add dummy configuration update functions --- packages/torouter-web/tui/controllers/network.py | 18 +++++++++++++++++- packages/torouter-web/tui/controllers/tor.py | 4 ++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/torouter-web/tui/controllers/network.py b/packages/torouter-web/tui/controllers/network.py index 7022ca4..10b0c9d 100644 --- a/packages/torouter-web/tui/controllers/network.py +++ b/packages/torouter-web/tui/controllers/network.py @@ -28,6 +28,10 @@ def menu(n): 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)) @@ -36,6 +40,7 @@ class main: 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()) @@ -44,6 +49,10 @@ class main: 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.main(),menu(0)) @@ -52,6 +61,7 @@ class firewall: def POST(self): if session.is_logged() > 0: + self.update_config(web.input()) return render.base(render.firewall(),menu(1)) else: return render.base(render.login()) @@ -89,6 +99,7 @@ class wireless: return True + # XXX do all the backend stuff def update_config(self, data): return True @@ -101,7 +112,7 @@ class wireless: def POST(self): if session.is_logged() > 0: - self.update_config(None) + self.update_config(web.input()) print web.input() return render.base(render.saved(web.input()),menu(2)) else: @@ -111,6 +122,10 @@ class wireless: 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(),menu(3)) @@ -119,6 +134,7 @@ class wired: 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()) diff --git a/packages/torouter-web/tui/controllers/tor.py b/packages/torouter-web/tui/controllers/tor.py index ca96209..d07cb71 100644 --- a/packages/torouter-web/tui/controllers/tor.py +++ b/packages/torouter-web/tui/controllers/tor.py @@ -17,9 +17,13 @@ class status: Tor configuration page """ class config: + 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()) -- cgit v1.2.3 From 4f42f3bcd60505acfc712aae08c5726175978bb2 Mon Sep 17 00:00:00 2001 From: Arturo Filastò Date: Fri, 12 Aug 2011 21:24:19 +0200 Subject: Move the configuration read/write functions to separate class --- packages/torouter-web/tui/controllers/network.py | 36 ++-------- packages/torouter-web/tui/utils/configuration.py | 85 ++++++++++++++++++++++++ packages/torouter-web/tui/views/firewall.html | 8 ++- packages/torouter-web/tui/views/wired.html | 8 ++- 4 files changed, 103 insertions(+), 34 deletions(-) create mode 100644 packages/torouter-web/tui/utils/configuration.py (limited to 'packages') diff --git a/packages/torouter-web/tui/controllers/network.py b/packages/torouter-web/tui/controllers/network.py index 10b0c9d..4eb1991 100644 --- a/packages/torouter-web/tui/controllers/network.py +++ b/packages/torouter-web/tui/controllers/network.py @@ -1,7 +1,7 @@ import web import view, config from view import render -from tui.utils import session +from tui.utils import session,configuration """ This function is used to generate the network @@ -55,7 +55,7 @@ class firewall: def GET(self): if session.is_logged() > 0: - return render.base(render.main(),menu(0)) + return render.base(render.firewall(configuration.get_form("firewall")),menu(0)) else: return render.base(render.login()) @@ -72,41 +72,13 @@ class firewall: Wireless network configuration page """ class wireless: - def get_current_config(self): - conf = {'essid' : None, 'encryption' : None, 'key' : None} - - # XXX Dummy default config for testing purposes - # plugin here the actual code for config retreival - conf['essid'] = "Torouter" - conf['encryption'] = "WPA2" - conf['key'] = "ljdasjkbcuBH12389Ba" - - - return conf - - def build_form(self): - c = self.get_current_config() - ret_form = web.form.Form( - web.form.Textbox(name='essid', - description='Wireless ESSID', value=c['essid']), - web.form.Dropdown(name='enctype', args=['WPA2', 'WPA', 'WEP (not reccomended)', 'open'], - description='Wireless encryption scheme', value=c['encryption']), - web.form.Password(name='key', - description='key', value=c['key']), - web.form.Button('save') - ) - self.form = ret_form - - return True - # XXX do all the backend stuff def update_config(self, data): return True def GET(self): if session.is_logged() > 0: - if self.build_form(): - return render.base(render.wireless(self.form()),menu(2)) + return render.base(render.wireless(configuration.get_form("wireless")),menu(2)) else: return render.base(render.login()) @@ -128,7 +100,7 @@ class wired: def GET(self): if session.is_logged() > 0: - return render.base(render.wired(),menu(3)) + return render.base(render.wired(configuration.get_form("wired")),menu(3)) else: return render.base(render.login()) diff --git a/packages/torouter-web/tui/utils/configuration.py b/packages/torouter-web/tui/utils/configuration.py new file mode 100644 index 0000000..88bbc05 --- /dev/null +++ b/packages/torouter-web/tui/utils/configuration.py @@ -0,0 +1,85 @@ +import web +import config + +def get(name): + conf = {} + # XXX The content of these functions are just + # skeletons + if name == "wireless": + conf['essid'] = "Torouter" + conf['encryption'] = "WPA2" + conf['key'] = "ljdasjkbcuBH12389Ba" + return conf + elif name == "firewall": + conf['el1'] = "Element 1" + conf['el2'] = "Element 2" + conf['el3'] = "Element 3" + return conf + elif name == "wired": + conf['el1'] = "Element 1" + conf['el2'] = "Element 2" + conf['el3'] = "Element 3" + return conf + elif name == "tor": + conf['el1'] = "Element 1" + conf['el2'] = "Element 2" + conf['el3'] = "Element 3" + return conf + +def write(name, data): + if name == "wireless": + return True + elif name == "firewall": + return True + elif name == "wired": + return True + elif name == "tor": + return True + +def get_form(name): + # Also these are just skeletons + if name == "wireless": + c = get(name) + return web.form.Form( + web.form.Textbox(name='essid', + description='Wireless ESSID', value=c['essid']), + web.form.Dropdown(name='enctype', args=['WPA2', 'WPA', 'WEP (not reccomended)', 'open'], + description='Wireless encryption scheme', value=c['encryption']), + web.form.Password(name='key', + description='key', value=c['key']), + web.form.Button('save') + ) + elif name == "firewall": + c = get(name) + return web.form.Form( + web.form.Textbox(name='el1', + description='The first element', value=c['el2']), + web.form.Dropdown(name='el2', args=['WPA2', 'WPA', 'WEP (not reccomended)', 'open'], + description='The second selement', value=c['el2']), + web.form.Password(name='el3', + description='The third element', value=c['el3']), + web.form.Button('save') + ) + elif name == "wired": + c = get(name) + return web.form.Form( + web.form.Textbox(name='el1', + description='The first element', value=c['el2']), + web.form.Dropdown(name='el2', args=['WPA2', 'WPA', 'WEP (not reccomended)', 'open'], + description='The second selement', value=c['el2']), + web.form.Password(name='el3', + description='The third element', value=c['el3']), + web.form.Button('save') + ) + elif name == "tor": + c = get(name) + return web.form.Form( + web.form.Textbox(name='el1', + description='The first element', value=c['el2']), + web.form.Dropdown(name='el2', args=['WPA2', 'WPA', 'WEP (not reccomended)', 'open'], + description='The second selement', value=c['el2']), + web.form.Password(name='el3', + description='The third element', value=c['el3']), + web.form.Button('save') + ) + diff --git a/packages/torouter-web/tui/views/firewall.html b/packages/torouter-web/tui/views/firewall.html index c3a244d..30f5a9b 100644 --- a/packages/torouter-web/tui/views/firewall.html +++ b/packages/torouter-web/tui/views/firewall.html @@ -1 +1,7 @@ -the firewall page +$def with (form) + +

Firewall configuration page

+ +
+$:form.render() +
diff --git a/packages/torouter-web/tui/views/wired.html b/packages/torouter-web/tui/views/wired.html index 3a517d1..3676f63 100644 --- a/packages/torouter-web/tui/views/wired.html +++ b/packages/torouter-web/tui/views/wired.html @@ -1 +1,7 @@ -the wired page +$def with (form) + +

Wired configuration page

+ +
+$:form.render() +
-- cgit v1.2.3 From f54fe96d36551fc61d746d875365e6722d56afd2 Mon Sep 17 00:00:00 2001 From: Arturo Filastò Date: Sat, 13 Aug 2011 03:19:24 +0200 Subject: Add parsing function to read and write /etc/network/interfaces files. --- packages/torouter-web/static/main.css | 10 +++- packages/torouter-web/tui/controllers/network.py | 2 +- packages/torouter-web/tui/utils/parsing.py | 66 ++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 packages/torouter-web/tui/utils/parsing.py (limited to 'packages') diff --git a/packages/torouter-web/static/main.css b/packages/torouter-web/static/main.css index 41cb47f..5626e92 100644 --- a/packages/torouter-web/static/main.css +++ b/packages/torouter-web/static/main.css @@ -3,13 +3,17 @@ body { margin: 0;border: 0;padding: 0; } div.wrapper { + min-height: 300px; width: 800px; margin: 0 auto; } div.footer { - background-color: #CCC; + text-align: center; + background-color: #333; color: white; + padding-top: 20px; + padding-bottom: 20px; } div.header { @@ -22,8 +26,12 @@ div.header ul { } div.header ul li { + font-size: 20px; float: left; padding: 5px 10px; } +div.header ul#submenu li { + font-size: 15px; +} diff --git a/packages/torouter-web/tui/controllers/network.py b/packages/torouter-web/tui/controllers/network.py index 4eb1991..b5da4e3 100644 --- a/packages/torouter-web/tui/controllers/network.py +++ b/packages/torouter-web/tui/controllers/network.py @@ -15,7 +15,7 @@ def menu(n): else: a.append("") print a - return """
    + return """