aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArturo FilastoĢ€ <hellais@torproject.org>2011-08-13 03:19:24 +0200
committerArturo FilastoĢ€ <hellais@torproject.org>2011-08-13 03:19:24 +0200
commitf54fe96d36551fc61d746d875365e6722d56afd2 (patch)
tree00fb5314bb3d9771829ba69e75ae3053cba965b7
parent4f42f3bcd60505acfc712aae08c5726175978bb2 (diff)
downloadtorouter-f54fe96d36551fc61d746d875365e6722d56afd2.tar.gz
torouter-f54fe96d36551fc61d746d875365e6722d56afd2.zip
Add parsing function to read and write /etc/network/interfaces files.
-rw-r--r--packages/torouter-web/static/main.css10
-rw-r--r--packages/torouter-web/tui/controllers/network.py2
-rw-r--r--packages/torouter-web/tui/utils/parsing.py66
3 files changed, 76 insertions, 2 deletions
diff --git a/packages/torouter-web/static/main.css b/packages/torouter-web/static/main.css
index 41cb47f..5626e92 100644
--- a/packages/torouter-web/static/main.css
+++ b/packages/torouter-web/static/main.css
@@ -3,13 +3,17 @@
body { margin: 0;border: 0;padding: 0; }
div.wrapper {
+ min-height: 300px;
width: 800px;
margin: 0 auto;
}
div.footer {
- background-color: #CCC;
+ text-align: center;
+ background-color: #333;
color: white;
+ padding-top: 20px;
+ padding-bottom: 20px;
}
div.header {
@@ -22,8 +26,12 @@ div.header ul {
}
div.header ul li {
+ font-size: 20px;
float: left;
padding: 5px 10px;
}
+div.header ul#submenu li {
+ font-size: 15px;
+}
diff --git a/packages/torouter-web/tui/controllers/network.py b/packages/torouter-web/tui/controllers/network.py
index 4eb1991..b5da4e3 100644
--- a/packages/torouter-web/tui/controllers/network.py
+++ b/packages/torouter-web/tui/controllers/network.py
@@ -15,7 +15,7 @@ def menu(n):
else:
a.append("")
print a
- return """<ul>
+ return """<ul id="submenu">
<li><a href="/network" class="%s">Main</a></li>
<li><a href="/network/firewall" class="%s">Firewall</a></li>
<li><a href="/network/wireless" class="%s">Wireless</a></li>
diff --git a/packages/torouter-web/tui/utils/parsing.py b/packages/torouter-web/tui/utils/parsing.py
new file mode 100644
index 0000000..c6ebe02
--- /dev/null
+++ b/packages/torouter-web/tui/utils/parsing.py
@@ -0,0 +1,66 @@
+# These functions are for parsing /etc/network/interface
+# files, they will be used inside torouter to visualize
+# and edit configuration
+class interfaces:
+ def __init__(self,filename):
+ self.fp = open(filename, "r")
+ self.wifi = {}
+ self.eth1 = {}
+ self.eth0 = {}
+
+ def parse_line(self, line, iface):
+ name = line.split(" ")[0]
+ values = " ".join(line.split(" ")[1:]).rstrip()
+ if iface == "uap0":
+ 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 == "eth1":
+ 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 == "eth0":
+ 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 output(self, data):
+ print "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)
+ else:
+ print "%s %s" % (item[0],item[1])
+
+itfc = interfaces("/tmp/interfaces")
+itfc.parse()
+itfc.output(itfc.wifi)
+itfc.output(itfc.eth1)
+itfc.output(itfc.eth0)
+