diff options
author | Arturo FilastoĢ <hellais@torproject.org> | 2011-08-17 19:38:47 +0200 |
---|---|---|
committer | Arturo FilastoĢ <hellais@torproject.org> | 2011-08-17 19:38:47 +0200 |
commit | e14cf93e2c93e94c00d55d51ffc8ca26e063377c (patch) | |
tree | 3566a2d7eda080fd376d88d274b2af5eb6f3006a /packages/torouter-web/src/tui/utils | |
parent | 4a55d3546be8f0444b12d634ccf01c5a107d46eb (diff) | |
parent | 57e54f969b840546925d16ceceb130a0f3927140 (diff) | |
download | torouter-e14cf93e2c93e94c00d55d51ffc8ca26e063377c.tar.gz torouter-e14cf93e2c93e94c00d55d51ffc8ca26e063377c.zip |
Merge branch 'master' of ssh://git-rw.torproject.org/torouter
Diffstat (limited to 'packages/torouter-web/src/tui/utils')
-rw-r--r-- | packages/torouter-web/src/tui/utils/__init__.py | 0 | ||||
-rw-r--r-- | packages/torouter-web/src/tui/utils/configuration.py | 85 | ||||
-rw-r--r-- | packages/torouter-web/src/tui/utils/parsing.py | 105 | ||||
-rw-r--r-- | packages/torouter-web/src/tui/utils/session.py | 26 |
4 files changed, 216 insertions, 0 deletions
diff --git a/packages/torouter-web/src/tui/utils/__init__.py b/packages/torouter-web/src/tui/utils/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/packages/torouter-web/src/tui/utils/__init__.py diff --git a/packages/torouter-web/src/tui/utils/configuration.py b/packages/torouter-web/src/tui/utils/configuration.py new file mode 100644 index 0000000..88bbc05 --- /dev/null +++ b/packages/torouter-web/src/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/src/tui/utils/parsing.py b/packages/torouter-web/src/tui/utils/parsing.py new file mode 100644 index 0000000..beb45d3 --- /dev/null +++ b/packages/torouter-web/src/tui/utils/parsing.py @@ -0,0 +1,105 @@ +# These functions are for parsing /etc/network/interface +# files, they will be used inside torouter to visualize +# and edit configuration +import os + +class interfaces: + def __init__(self,filename): + self.fp = open(filename, "r") + self.wifi = {} + self.eth1 = {} + self.eth0 = {} + + def parse_line(self, line, iface): + name = line.split(" ")[0] + values = " ".join(line.split(" ")[1:]).rstrip() + if iface == "uap0": + if self.wifi.has_key(name): + if type(self.wifi[name]) is list: + self.wifi[name].append(values) + else: + self.wifi[name] = [self.wifi[name],values] + else: + self.wifi.update({name : values}) + elif iface == "eth1": + if self.eth1.has_key(name): + if type(self.eth1[name]) is list: + self.eth1[name].append(values) + else: + self.eth1[name] = [self.eth1[name],values] + else: + self.eth1.update({name : values}) + elif iface == "eth0": + if self.eth0.has_key(name): + if type(self.eth0[name]) is list: + self.eth0[name].append(values) + else: + self.eth0[name] = [self.eth0[name],values] + else: + self.eth0.update({name : values}) + + def parse(self): + iface = None + for line in self.fp.readlines(): + line = line.lstrip() + if line.startswith("#") or line == "": + continue + if line.startswith("iface"): + iface = line.split(" ")[1] + if iface: + self.parse_line(line, iface) + + def html_output(self, data): + output = "<h3>Interface %s</h3>\n" % data['iface'].split(" ")[0] + output += "<table class=\"interface\" id=\"%s\">\n" % data['iface'].split(" ")[0] + + for item in data.items(): + if item[0] != "iface": + if type(item[1]) is list: + for i in item[1]: + output += "<tr><td>%s</td><td>%s</td></tr>\n" % (item[0], i) + else: + output += "<tr><td>%s</td><td>%s</td></tr>\n" % (item[0],item[1]) + output += "</table>" + print output + return output + + def output(self, data): + print "iface %s" % data['iface'] + for item in data.items(): + if item[0] != "iface": + if type(item[1]) is list: + for i in item[1]: + print "%s %s" % (item[0], i) + else: + print "%s %s" % (item[0],item[1]) + +class torrc: + def __init__(self,filename): + self.fp = open(filename, "r") + self.parsed = [] + + def parse(self): + for line in self.fp.readlines(): + line = line.lstrip() + if line.startswith("#") or line == "": + continue + else: + self.parsed.append(line) + + def html_output(self): + output = "<ul id=\"torrc\">" + for line in self.parsed: + if line != "\n": + output += "<li><em>%s</em> %s</li>" % (line.split(" ")[0], " ".join(line.split(" ")[1:])) + output += "</ul>" + print output + return output + +#interfaces_file = os.getcwd() + "/../../../torouter-prep/configs/interfaces" +#itfc = interfaces(interfaces_file) +#itfc.parse() +#itfc.html_output(itfc.wifi) +#itfc.html_output(itfc.eth1) +#itfc.html_output(itfc.eth0) + diff --git a/packages/torouter-web/src/tui/utils/session.py b/packages/torouter-web/src/tui/utils/session.py new file mode 100644 index 0000000..a554dad --- /dev/null +++ b/packages/torouter-web/src/tui/utils/session.py @@ -0,0 +1,26 @@ +import web +import config + +# 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 == config.authinfo[0]) and (data.password == config.authinfo[1]): + web.config._session.login = 1 + return 0 + return 1 + +def logout(): + web.config._session.kill() + |