aboutsummaryrefslogtreecommitdiffstats
path: root/packages/torouter-web/src/tui/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/torouter-web/src/tui/utils')
-rw-r--r--packages/torouter-web/src/tui/utils/__init__.py0
-rw-r--r--packages/torouter-web/src/tui/utils/configuration.py109
-rw-r--r--packages/torouter-web/src/tui/utils/fileio.py24
-rw-r--r--packages/torouter-web/src/tui/utils/parsing.py145
-rw-r--r--packages/torouter-web/src/tui/utils/session.py26
5 files changed, 0 insertions, 304 deletions
diff --git a/packages/torouter-web/src/tui/utils/__init__.py b/packages/torouter-web/src/tui/utils/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/packages/torouter-web/src/tui/utils/__init__.py
+++ /dev/null
diff --git a/packages/torouter-web/src/tui/utils/configuration.py b/packages/torouter-web/src/tui/utils/configuration.py
deleted file mode 100644
index 336aa54..0000000
--- a/packages/torouter-web/src/tui/utils/configuration.py
+++ /dev/null
@@ -1,109 +0,0 @@
-import web
-import re
-from tui.utils import parsing
-from tui import config
-
-def get(name):
- conf = {}
- itfc = parsing.interfaces(config.interfaces_file)
- itfc.parse()
-
- if name == "wireless":
- 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"
- 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='ESSID', value=c['essid']),
- web.form.Textbox(name='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='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/fileio.py b/packages/torouter-web/src/tui/utils/fileio.py
deleted file mode 100644
index c6574b7..0000000
--- a/packages/torouter-web/src/tui/utils/fileio.py
+++ /dev/null
@@ -1,24 +0,0 @@
-import os
-
-def write(files):
- 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]
- tmpfiles.append((tmpfile,file[0]))
- # open the tmp file for write
- f = open(tmpfile, 'w')
- # write the data (file[1]) to the temp file
- f.write(file[1])
- f.close()
-
- # rename all the file. This operation is atomic
- #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')]
-#write(files)
-
diff --git a/packages/torouter-web/src/tui/utils/parsing.py b/packages/torouter-web/src/tui/utils/parsing.py
deleted file mode 100644
index 310ea5c..0000000
--- a/packages/torouter-web/src/tui/utils/parsing.py
+++ /dev/null
@@ -1,145 +0,0 @@
-# These functions are for parsing /etc/network/interface
-# files, they will be used inside torouter to visualize
-# and edit configuration
-import os, re
-from tui import config
-
-class interfaces:
- def __init__(self,filename):
- self.filename = filename
- try:
- self.fp = open(filename, "r")
- except:
- # this will happen on our first run or at reboot
- self.fp = open("/etc/tor/torrc", "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()
- if iface == config.network_interfaces[0]:
- 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 == config.network_interfaces[2]:
- 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 == config.network_interfaces[1]:
- 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):
- output = "iface %s\n" % data['iface']
- for item in data.items():
- if item[0] != "iface":
- if type(item[1]) is list:
- for i in item[1]:
- output += item[0] + " " + i + "\n"
- else:
- 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] = '/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 ' + config.network_interfaces[0] + ' hw ether ' + mac
-
-
-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 output(self):
- output = ""
- for line in self.fp.readlines():
- print line
- output += line
- return output
-
- 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
deleted file mode 100644
index 4570196..0000000
--- a/packages/torouter-web/src/tui/utils/session.py
+++ /dev/null
@@ -1,26 +0,0 @@
-import web
-from tui 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()
-