1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
import web
from tui import config
from tui import view
from tui.view import render
from tui.utils import session, configuration, parsing, fileio
"""
This function is used to generate the network
submenus.
"""
def menu(n):
a = []
for i in range(0,5):
if i == n:
a.append("sel")
else:
a.append("")
print a
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>
<li><a href="/network/wired" class="%s">Wired</a></li>
<li><a href="/network/status" class="%s">Status</a></li>
</ul>
""" % tuple(a)
"""
The main page for network configuration
"""
class main:
# XXX do all the backend stuff
def update_config(self, data):
return True
def GET(self):
if session.is_logged() > 0:
return render.base(render.main(),menu(0))
else:
return render.base(render.login())
def POST(self):
if session.is_logged() > 0:
self.update_config(web.input())
return render.base(render.main(),menu(0))
else:
return render.base(render.login())
"""
The firewall configuration page
"""
class firewall:
# XXX do all the backend stuff
def update_config(self, data):
return True
def GET(self):
if session.is_logged() > 0:
return render.base(render.firewall(configuration.get_form("firewall")),menu(1))
else:
return render.base(render.login())
def POST(self):
if session.is_logged() > 0:
self.update_config(web.input())
return render.base(render.firewall(configuration.get_form("firewall")),menu(1))
else:
return render.base(render.login())
"""
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):
if session.is_logged() > 0:
return render.base(render.wireless(configuration.get_form("wireless")),menu(2))
else:
return render.base(render.login())
def POST(self):
if session.is_logged() > 0:
self.update_config(web.input())
print web.input()
return render.base(render.saved(web.input()),menu(2))
else:
return render.base(render.login())
"""
Wired network configuration page
"""
class wired:
# XXX do all the backend stuff
def update_config(self, data):
return True
def GET(self):
if session.is_logged() > 0:
return render.base(render.wired(configuration.get_form("wired")),menu(3))
else:
return render.base(render.login())
def POST(self):
if session.is_logged() > 0:
self.update_config(web.input())
return render.base(render.wired(),menu(3))
else:
return render.base(render.login())
"""
General status page, displays a bit more detail than main
"""
class status:
def GET(self):
itfc = parsing.interfaces(config.interfaces_file)
itfc.parse()
network = itfc.html_output(itfc.wifi) + itfc.html_output(itfc.eth0) + itfc.html_output(itfc.eth1)
return render.base(render.status(network),menu(4))
def POST(self):
itfc = parsing.interfaces(config.interfaces_file)
itfc.parse()
network = itfc.html_output(itfc.wifi) + itfc.html_output(itfc.eth0) + itfc.html_output(itfc.eth1)
return render.base(render.status(),menu(4))
|