aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorJacob Appelbaum <jacob@appelbaum.net>2011-08-19 15:09:45 +0200
committerJacob Appelbaum <jacob@appelbaum.net>2011-08-19 15:09:45 +0200
commit254d2d3f6d1dfc01481ae4158302aae306bef793 (patch)
tree909f1798e9218eec51fe2689b61c5e397a16b588 /packages
parentd891a6dc8241809863eb53794d9028f75ac5362b (diff)
parent21472ffb02bb44782d232ce5efe79042c8cb27c6 (diff)
downloadtorouter-254d2d3f6d1dfc01481ae4158302aae306bef793.tar.gz
torouter-254d2d3f6d1dfc01481ae4158302aae306bef793.zip
Merge branch 'master' of ssh://git-rw.torproject.org/torouter
Diffstat (limited to 'packages')
-rw-r--r--packages/torouter-web/setup.py5
-rw-r--r--packages/torouter-web/src/config.py16
-rw-r--r--packages/torouter-web/src/runui.py2
-rw-r--r--packages/torouter-web/src/tui/controllers/main.py5
-rw-r--r--packages/torouter-web/src/tui/controllers/network.py5
-rw-r--r--packages/torouter-web/src/tui/controllers/tor.py21
-rw-r--r--packages/torouter-web/src/tui/models/router_config.py2
-rw-r--r--packages/torouter-web/src/tui/utils/configuration.py5
-rw-r--r--packages/torouter-web/src/tui/utils/fileio.py21
-rw-r--r--packages/torouter-web/src/tui/utils/parsing.py7
-rw-r--r--packages/torouter-web/src/tui/utils/session.py2
-rw-r--r--packages/torouter-web/src/tui/views/torconfig.html12
-rw-r--r--packages/torouter-web/src/tui/views/torstatus.html2
-rw-r--r--packages/torouter-web/src/view.py11
14 files changed, 73 insertions, 43 deletions
diff --git a/packages/torouter-web/setup.py b/packages/torouter-web/setup.py
index 7629b6b..2ff99fa 100644
--- a/packages/torouter-web/setup.py
+++ b/packages/torouter-web/setup.py
@@ -2,7 +2,8 @@
from distutils.core import setup
setup(name='torouter-tui',
- packages=['tui'],
+ packages=['tui', 'tui.controllers',
+ 'tui.models', 'tui.utils'],
package_dir = {'tui': 'src/tui/'},
package_data = {'tui': ['src/tui/']},
data_files = [('/usr/share/torouter-tui/static',
@@ -12,5 +13,5 @@ setup(name='torouter-tui',
author='Arturo Filasto',
author_email='hellais@torproject.org',
url='https://www.torproject.org/',
- scripts=['src/runui.py', 'src/view.py', 'src/config.py'])
+ scripts=['src/runui.py', 'src/tui/view.py', 'src/tui/config.py'])
diff --git a/packages/torouter-web/src/config.py b/packages/torouter-web/src/config.py
deleted file mode 100644
index 15057df..0000000
--- a/packages/torouter-web/src/config.py
+++ /dev/null
@@ -1,16 +0,0 @@
-# tui, Tor web UI
-# by Arturo Filasto' <hellais@torproject.org>
-#
-
-import web, os
-
-cache = False
-
-globals = {}
-
-# Add your own (username, password) pair
-authinfo = ("test", "test")
-
-interfaces_file = os.getcwd() + "/../torouter-prep/configs/interfaces"
-torrc_file = os.getcwd() + "/../torouter-prep/configs/torrc"
-
diff --git a/packages/torouter-web/src/runui.py b/packages/torouter-web/src/runui.py
index 4c9e199..43d8943 100644
--- a/packages/torouter-web/src/runui.py
+++ b/packages/torouter-web/src/runui.py
@@ -4,7 +4,7 @@
#
import web
-import config
+from tui import config
import tui.controllers
from tui.utils import session
diff --git a/packages/torouter-web/src/tui/controllers/main.py b/packages/torouter-web/src/tui/controllers/main.py
index 060caa6..fb925d3 100644
--- a/packages/torouter-web/src/tui/controllers/main.py
+++ b/packages/torouter-web/src/tui/controllers/main.py
@@ -1,6 +1,7 @@
import web
-import view, config
-from view import render
+from tui import config
+from tui import view
+from tui.view import render
from tui.utils import session
"""
diff --git a/packages/torouter-web/src/tui/controllers/network.py b/packages/torouter-web/src/tui/controllers/network.py
index cc46643..bf48f54 100644
--- a/packages/torouter-web/src/tui/controllers/network.py
+++ b/packages/torouter-web/src/tui/controllers/network.py
@@ -1,6 +1,7 @@
import web
-import view, config
-from view import render
+from tui import config
+from tui import view
+from tui.view import render
from tui.utils import session,configuration,parsing
"""
diff --git a/packages/torouter-web/src/tui/controllers/tor.py b/packages/torouter-web/src/tui/controllers/tor.py
index af8678c..bc66623 100644
--- a/packages/torouter-web/src/tui/controllers/tor.py
+++ b/packages/torouter-web/src/tui/controllers/tor.py
@@ -1,7 +1,8 @@
import web
-import view, config
-from view import render
-from tui.utils import session, parsing
+from tui import config
+from tui import view
+from tui.view import render
+from tui.utils import session, parsing, fileio
"""
The main Tor status page
@@ -24,12 +25,22 @@ Tor configuration page
"""
class torrc:
def update_config(self, data):
+ # Now it will just write to /tmp/torrc
+ files = [('/tmp/torrc',data.torrc)]
+ fileio.write(files)
+
return True
def GET(self):
- return render.base(render.torconfig())
+ trc = parsing.torrc(config.torrc_file)
+ output = trc.output()
+ return render.base(render.torconfig(output))
def POST(self):
self.update_config(web.input())
- return render.base(render.torconfig())
+ trc = parsing.torrc(config.torrc_file)
+ trc.parse()
+ output = trc.html_output()
+ return render.base(render.torstatus(output,config.torrc_file))
+
diff --git a/packages/torouter-web/src/tui/models/router_config.py b/packages/torouter-web/src/tui/models/router_config.py
index e83f9aa..a9bd975 100644
--- a/packages/torouter-web/src/tui/models/router_config.py
+++ b/packages/torouter-web/src/tui/models/router_config.py
@@ -1,5 +1,5 @@
import web
-from config import db
+from tui.config import db
def new_config(conf):
db.insert('router_config',
diff --git a/packages/torouter-web/src/tui/utils/configuration.py b/packages/torouter-web/src/tui/utils/configuration.py
index 88bbc05..7133443 100644
--- a/packages/torouter-web/src/tui/utils/configuration.py
+++ b/packages/torouter-web/src/tui/utils/configuration.py
@@ -1,5 +1,5 @@
import web
-import config
+from tui import config
def get(name):
conf = {}
@@ -8,6 +8,7 @@ def get(name):
if name == "wireless":
conf['essid'] = "Torouter"
conf['encryption'] = "WPA2"
+ conf['mac'] = "00:66:66:66:66:66"
conf['key'] = "ljdasjkbcuBH12389Ba"
return conf
elif name == "firewall":
@@ -43,6 +44,8 @@ def get_form(name):
return web.form.Form(
web.form.Textbox(name='essid',
description='Wireless ESSID', value=c['essid']),
+ web.form.Textbox(name='mac',
+ description='Wireless MAC address', value=c['mac']),
web.form.Dropdown(name='enctype', args=['WPA2', 'WPA', 'WEP (not reccomended)', 'open'],
description='Wireless encryption scheme', value=c['encryption']),
web.form.Password(name='key',
diff --git a/packages/torouter-web/src/tui/utils/fileio.py b/packages/torouter-web/src/tui/utils/fileio.py
new file mode 100644
index 0000000..3234f1e
--- /dev/null
+++ b/packages/torouter-web/src/tui/utils/fileio.py
@@ -0,0 +1,21 @@
+import os
+
+def write(files):
+ tmpfiles = []
+ for file in files:
+ tmpfile = "/tmp/" + file[0].split("/")[-1:][0] + ".tmp"
+ 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])
+
+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
index beb45d3..daf4436 100644
--- a/packages/torouter-web/src/tui/utils/parsing.py
+++ b/packages/torouter-web/src/tui/utils/parsing.py
@@ -87,6 +87,13 @@ class torrc:
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:
diff --git a/packages/torouter-web/src/tui/utils/session.py b/packages/torouter-web/src/tui/utils/session.py
index a554dad..4570196 100644
--- a/packages/torouter-web/src/tui/utils/session.py
+++ b/packages/torouter-web/src/tui/utils/session.py
@@ -1,5 +1,5 @@
import web
-import config
+from tui import config
# The main session class
diff --git a/packages/torouter-web/src/tui/views/torconfig.html b/packages/torouter-web/src/tui/views/torconfig.html
index 26bd228..223c339 100644
--- a/packages/torouter-web/src/tui/views/torconfig.html
+++ b/packages/torouter-web/src/tui/views/torconfig.html
@@ -1 +1,11 @@
-The main Tor config page
+$def with (content)
+
+<form method="POST" action="/tor/config" enctype="multipart/form-data">
+<ul>
+<li><textarea cols="100" rows="50" name="torrc">
+$:content
+</textarea></li>
+<li><input type="submit" name="save"></li>
+</ul>
+</form>
+
diff --git a/packages/torouter-web/src/tui/views/torstatus.html b/packages/torouter-web/src/tui/views/torstatus.html
index 27b2888..a2eeacf 100644
--- a/packages/torouter-web/src/tui/views/torstatus.html
+++ b/packages/torouter-web/src/tui/views/torstatus.html
@@ -1,3 +1,5 @@
$def with (content, torrc)
<h2>This is the content of $:torrc</h2>
$:content
+
+<a href="/tor/config">edit torrc</a>
diff --git a/packages/torouter-web/src/view.py b/packages/torouter-web/src/view.py
deleted file mode 100644
index f4c9b39..0000000
--- a/packages/torouter-web/src/view.py
+++ /dev/null
@@ -1,11 +0,0 @@
-import web
-import config
-
-t_globals = dict(
- datestr=web.datestr,
- )
-
-# create the render object
-render = web.template.render('tui/views', cache=config.cache, globals=t_globals)
-render._keywords['globals']['render'] = render
-