aboutsummaryrefslogtreecommitdiffstats
path: root/packages/torouter-web/src
diff options
context:
space:
mode:
authorJacob Appelbaum <jacob@appelbaum.net>2011-08-19 17:25:35 +0200
committerJacob Appelbaum <jacob@appelbaum.net>2011-08-19 17:25:35 +0200
commit18ce925004eb3030b91c01beda43a58017607103 (patch)
tree8dc479f49f66125af86933f91309db4a9ed98d71 /packages/torouter-web/src
parentf76a57a4534722c7facb0432b4ee49e0030c7d1a (diff)
parentfe239d1d9e8a590798abc31cd7bf7cf11324cfd5 (diff)
downloadtorouter-18ce925004eb3030b91c01beda43a58017607103.tar.gz
torouter-18ce925004eb3030b91c01beda43a58017607103.zip
Merge branch 'master' of ssh://git-rw.torproject.org/torouter
Diffstat (limited to 'packages/torouter-web/src')
-rw-r--r--packages/torouter-web/src/tui/config.py5
-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.py8
-rw-r--r--packages/torouter-web/src/tui/utils/parsing.py38
6 files changed, 90 insertions, 27 deletions
diff --git a/packages/torouter-web/src/tui/config.py b/packages/torouter-web/src/tui/config.py
index f3f8dcc..73087f2 100644
--- a/packages/torouter-web/src/tui/config.py
+++ b/packages/torouter-web/src/tui/config.py
@@ -11,7 +11,8 @@ globals = {}
# Add your own (username, password) pair
authinfo = ("test", "test")
-interfaces_file = os.getcwd() + "/../../torouter-prep/configs/interfaces"
+#interfaces_file = os.getcwd() + "/../../torouter-prep/configs/interfaces"
#torrc_file = os.getcwd() + "/../../torouter-prep/configs/torrc"
-torrc_file = "/tmp/torrc"
+torrc_file = "/var/tmp/tor-tui/torrc"
+interfaces_file = "/var/tmp/tor-tui/interfaces"
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..c6574b7 100644
--- a/packages/torouter-web/src/tui/utils/fileio.py
+++ b/packages/torouter-web/src/tui/utils/fileio.py
@@ -1,12 +1,12 @@
import os
def write(files):
- tmp_dir = "/var/tmp/tor-tui"
+ tmp_dir = "/var/tmp/tor-tui/"
tmpfiles = []
for file in files:
if not os.path.exists(tmp_dir):
os.mkdir(tmp_dir)
- tmpfile = tmp_dir + file[0].split("/")[-1:][0] + ".tmp"
+ tmpfile = tmp_dir + file[0].split("/")[-1:][0]
tmpfiles.append((tmpfile,file[0]))
# open the tmp file for write
f = open(tmpfile, 'w')
@@ -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):