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
141
142
143
144
145
146
147
148
149
|
import iutil
import os
import isys
from snack import *
from constants_text import *
from translate import _
class NetworkWindow:
def setsensitive (self):
if self.cb.selected ():
sense = FLAGS_SET
else:
sense = FLAGS_RESET
for n in self.ip, self.nm, self.gw, self.ns:
n.setFlags (FLAG_DISABLED, sense)
def calcNM (self):
ip = self.ip.value ()
if ip and not self.nm.value ():
try:
mask = isys.inet_calcNetmask (ip)
except ValueError:
return
self.nm.set (mask)
def calcGW (self):
ip = self.ip.value ()
nm = self.nm.value ()
if ip and nm:
try:
(net, bcast) = isys.inet_calcNetBroad (ip, nm)
except ValueError:
return
if not self.gw.value ():
gw = isys.inet_calcGateway (bcast)
self.gw.set (gw)
if not self.ns.value ():
ns = isys.inet_calcNS (net)
self.ns.set (ns)
def __call__(self, screen, todo):
devices = todo.network.available ()
if not devices:
return INSTALL_NOOP
if todo.network.readData:
# XXX expert mode, allow changing network settings here
return INSTALL_NOOP
list = devices.keys ()
list.sort()
dev = devices[list[0]]
firstg = Grid (1, 1)
boot = dev.get ("bootproto")
if not boot:
boot = "dhcp"
self.cb = Checkbox (_("Use bootp/dhcp"),
isOn = (boot == "dhcp"))
firstg.setField (self.cb, 0, 0, anchorLeft = 1)
secondg = Grid (2, 4)
secondg.setField (Label (_("IP address:")), 0, 0, anchorLeft = 1)
secondg.setField (Label (_("Netmask:")), 0, 1, anchorLeft = 1)
secondg.setField (Label (_("Default gateway (IP):")), 0, 2, anchorLeft = 1)
secondg.setField (Label (_("Primary nameserver:")), 0, 3, anchorLeft = 1)
self.ip = Entry (16)
self.ip.set (dev.get ("ipaddr"))
self.nm = Entry (16)
self.nm.set (dev.get ("netmask"))
self.gw = Entry (16)
self.gw.set (todo.network.gateway)
self.ns = Entry (16)
self.ns.set (todo.network.primaryNS)
self.cb.setCallback (self.setsensitive)
self.ip.setCallback (self.calcNM)
self.nm.setCallback (self.calcGW)
secondg.setField (self.ip, 1, 0, (1, 0, 0, 0))
secondg.setField (self.nm, 1, 1, (1, 0, 0, 0))
secondg.setField (self.gw, 1, 2, (1, 0, 0, 0))
secondg.setField (self.ns, 1, 3, (1, 0, 0, 0))
bb = ButtonBar (screen, ((_("OK"), "ok"), (_("Back"), "back")))
toplevel = GridFormHelp (screen, _("Network Configuration"),
"network", 1, 3)
toplevel.add (firstg, 0, 0, (0, 0, 0, 1), anchorLeft = 1)
toplevel.add (secondg, 0, 1, (0, 0, 0, 1))
toplevel.add (bb, 0, 2, growx = 1)
self.setsensitive ()
while 1:
result = toplevel.run ()
if self.cb.selected ():
dev.set (("bootproto", "dhcp"))
dev.unset ("ipaddr", "netmask", "network", "broadcast")
else:
try:
(network, broadcast) = isys.inet_calcNetBroad (self.ip.value (), self.nm.value ())
except:
ButtonChoiceWindow(screen, _("Invalid information"),
_("You must enter valid IP information to continue"),
buttons = [ _("OK") ])
continue
dev.set (("bootproto", "static"))
dev.set (("ipaddr", self.ip.value ()), ("netmask", self.nm.value ()),
("network", network), ("broadcast", broadcast))
todo.network.gateway = self.gw.value ()
todo.network.primaryNS = self.ns.value ()
screen.popWindow()
break
dev.set (("onboot", "yes"))
rc = bb.buttonPressed (result)
if rc == "back":
return INSTALL_BACK
return INSTALL_OK
class HostnameWindow:
def __call__(self, screen, todo):
entry = Entry (24)
if todo.network.hostname != "localhost.localdomain":
entry.set (todo.network.hostname)
rc, values = EntryWindow(screen, _("Hostname Configuration"),
_("The hostname is the name of your computer. If your "
"computer is attached to a network, this may be "
"assigned by your network administrator."),
[(_("Hostname"), entry)], buttons = [ _("OK"), _("Back")],
help = "hostname")
if rc == string.lower (_("Back")):
return INSTALL_BACK
todo.network.hostname = entry.value ()
return INSTALL_OK
|