diff options
Diffstat (limited to 'packages/torouter-web/src/tui/utils')
-rw-r--r-- | packages/torouter-web/src/tui/utils/configuration.py | 41 | ||||
-rw-r--r-- | packages/torouter-web/src/tui/utils/fileio.py | 4 | ||||
-rw-r--r-- | packages/torouter-web/src/tui/utils/parsing.py | 38 |
3 files changed, 66 insertions, 17 deletions
diff --git a/packages/torouter-web/src/tui/utils/configuration.py b/packages/torouter-web/src/tui/utils/configuration.py index 7133443..336aa54 100644 --- a/packages/torouter-web/src/tui/utils/configuration.py +++ b/packages/torouter-web/src/tui/utils/configuration.py @@ -1,15 +1,32 @@ import web +import re +from tui.utils import parsing from tui import config def get(name): conf = {} - # XXX The content of these functions are just - # skeletons + itfc = parsing.interfaces(config.interfaces_file) + itfc.parse() + if name == "wireless": - conf['essid'] = "Torouter" - conf['encryption'] = "WPA2" - conf['mac'] = "00:66:66:66:66:66" - conf['key'] = "ljdasjkbcuBH12389Ba" + conf['essid'] = "tor" + conf['mac'] = "00:11:22:33:44:55" + for entry in itfc.wifi['post-up']: + if re.search("sys_cfg_ssid", entry): + conf['essid'] = entry.split(" ")[2].split("\"")[1] + + if type(itfc.wifi['pre-up']) is str: + conf['mac'] = itfc.wifi['pre-up'].split(" ")[4] + else: + for entry in itfc.wifi['pre-up']: + if re.search("ether", entry): + print "hahah" + conf['mac'] = entry.split(" ")[4] + + conf['netmask'] = itfc.wifi['netmask'] + conf['address'] = itfc.wifi['address'] + conf['encryption'] = "open" + conf['key'] = "" return conf elif name == "firewall": conf['el1'] = "Element 1" @@ -43,13 +60,17 @@ def get_form(name): c = get(name) return web.form.Form( web.form.Textbox(name='essid', - description='Wireless ESSID', value=c['essid']), + description='ESSID', value=c['essid']), web.form.Textbox(name='mac', - description='Wireless MAC address', value=c['mac']), + description='MAC address', value=c['mac']), + web.form.Textbox(name='address', + description='IP address', value=c['address']), + web.form.Textbox(name='netmask', + description='Netmask address', value=c['netmask']), web.form.Dropdown(name='enctype', args=['WPA2', 'WPA', 'WEP (not reccomended)', 'open'], - description='Wireless encryption scheme', value=c['encryption']), + description='Encryption scheme', value=c['encryption']), web.form.Password(name='key', - description='key', value=c['key']), + description='Key', value=c['key']), web.form.Button('save') ) elif name == "firewall": diff --git a/packages/torouter-web/src/tui/utils/fileio.py b/packages/torouter-web/src/tui/utils/fileio.py index 0675f3f..5b88504 100644 --- a/packages/torouter-web/src/tui/utils/fileio.py +++ b/packages/torouter-web/src/tui/utils/fileio.py @@ -15,8 +15,8 @@ def write(files): f.close() # rename all the file. This operation is atomic - for file in tmpfiles: - os.rename(file[0], file[1]) + #for file in tmpfiles: + # os.rename(file[0], file[1]) # for testing #files = [('/tmp/file1','blablbal'),('/tmp/file2','The content'),('/tmp/file3','The content 3')] diff --git a/packages/torouter-web/src/tui/utils/parsing.py b/packages/torouter-web/src/tui/utils/parsing.py index daf4436..d6aaf2b 100644 --- a/packages/torouter-web/src/tui/utils/parsing.py +++ b/packages/torouter-web/src/tui/utils/parsing.py @@ -1,15 +1,29 @@ # These functions are for parsing /etc/network/interface # files, they will be used inside torouter to visualize # and edit configuration -import os +import os, re class interfaces: def __init__(self,filename): + self.filename = filename self.fp = open(filename, "r") self.wifi = {} self.eth1 = {} self.eth0 = {} - + + def exclude_output(self, iexclude): + iface = None + output = "" + self.fp = open(self.filename, "r") + for line in self.fp.readlines(): + if line.lstrip().startswith("iface"): + iface = line.split(" ")[1] + if iface == iexclude: + continue + else: + output += line + return output + def parse_line(self, line, iface): name = line.split(" ")[0] values = " ".join(line.split(" ")[1:]).rstrip() @@ -65,14 +79,28 @@ class interfaces: return output def output(self, data): - print "iface %s" % data['iface'] + output = "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) + output += item[0] + " " + i + "\n" else: - print "%s %s" % (item[0],item[1]) + output += item[0] + " " + item[1] + "\n" + return output + + def set_ssid(self, essid): + i = 0 + for entry in self.wifi['post-up']: + if re.search("sys_cfg_ssid", entry): + print essid + self.wifi['post-up'][i] = 'post-up /usr/bin/uaputl sys_cfg_ssid "' + essid + '"' + i += 1 + + # XXX currently works for one pre-up entry, must make it work also for arrays + def set_mac(self, mac): + self.wifi['pre-up'] = 'ifconfig uap0 hw ether ' + mac + class torrc: def __init__(self,filename): |