aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/torouter-web/src/tui/controllers/network.py12
-rw-r--r--packages/torouter-web/src/tui/controllers/tor.py13
-rw-r--r--packages/torouter-web/src/tui/utils/configuration.py41
-rw-r--r--packages/torouter-web/src/tui/utils/fileio.py4
-rw-r--r--packages/torouter-web/src/tui/utils/parsing.py38
5 files changed, 85 insertions, 23 deletions
diff --git a/packages/torouter-web/src/tui/controllers/network.py b/packages/torouter-web/src/tui/controllers/network.py
index bf48f54..690dc3f 100644
--- a/packages/torouter-web/src/tui/controllers/network.py
+++ b/packages/torouter-web/src/tui/controllers/network.py
@@ -2,7 +2,7 @@ import web
from tui import config
from tui import view
from tui.view import render
-from tui.utils import session,configuration,parsing
+from tui.utils import session, configuration, parsing, fileio
"""
This function is used to generate the network
@@ -75,6 +75,16 @@ Wireless network configuration page
class wireless:
# XXX do all the backend stuff
def update_config(self, data):
+ itfc = parsing.interfaces(config.interfaces_file)
+ itfc.parse()
+ itfc.set_ssid(data.essid)
+ itfc.set_mac(data.mac)
+ itfc.wifi['netmask'] = data.netmask
+ itfc.wifi['address'] = data.address
+ filecontent = itfc.exclude_output("uap0") + itfc.output(itfc.wifi)
+ files = [('/etc/network/interfaces', filecontent)]
+ fileio.write(files)
+ #print itfc.output(itfc.wifi)
return True
def GET(self):
diff --git a/packages/torouter-web/src/tui/controllers/tor.py b/packages/torouter-web/src/tui/controllers/tor.py
index bc66623..491c6b7 100644
--- a/packages/torouter-web/src/tui/controllers/tor.py
+++ b/packages/torouter-web/src/tui/controllers/tor.py
@@ -37,10 +37,13 @@ class torrc:
return render.base(render.torconfig(output))
def POST(self):
- self.update_config(web.input())
- trc = parsing.torrc(config.torrc_file)
- trc.parse()
- output = trc.html_output()
- return render.base(render.torstatus(output,config.torrc_file))
+ if session.is_logged() > 0:
+ self.update_config(web.input())
+ trc = parsing.torrc(config.torrc_file)
+ trc.parse()
+ output = trc.html_output()
+ return render.base(render.torstatus(output,config.torrc_file))
+ else:
+ return render.base(render.login())
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):