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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
#
# network_text.py: text mode network configuration dialogs
#
# Copyright 2001 Red Hat, Inc.
#
# This software may be freely redistributed under the terms of the GNU
# library public license.
#
# You should have received a copy of the GNU Library Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
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, self.ns2, self.ns3:
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, network):
devices = network.available ()
if not devices:
return INSTALL_NOOP
if 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)
ask_ptp = None
if len(dev.info["DEVICE"]) >= 3 and dev.info["DEVICE"][:3] == "ctc":
ask_ptp = 1
secondg = Grid (2, 7)
else:
secondg = Grid (2, 6)
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)
secondg.setField (Label (_("Secondary nameserver:")), 0, 4, anchorLeft = 1)
secondg.setField (Label (_("Ternary nameserver:")), 0, 5, anchorLeft = 1)
if ask_ptp:
secondg.setField (Label (_("Point to Point (IP):")), 0, 6, 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 (network.gateway)
self.ns = Entry (16)
self.ns.set (network.primaryNS)
self.ns2 = Entry (16)
self.ns2.set (network.secondaryNS)
self.ns3 = Entry (16)
self.ns3.set (network.ternaryNS)
if ask_ptp:
self.ptp = Entry(16)
self.ptp.set (dev.get ("remip"))
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))
secondg.setField (self.ns2, 1, 4, (1, 0, 0, 0))
secondg.setField (self.ns3, 1, 5, (1, 0, 0, 0))
if ask_ptp:
secondg.setField (self.ptp, 1, 6, (1, 0, 0, 0))
bb = ButtonBar (screen, (TEXT_OK_BUTTON, TEXT_BACK_BUTTON))
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", "remip")
else:
try:
(net, bc) = 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", net), ("broadcast", bc))
if ask_ptp:
dev.set (("remip", self.ptp.value()))
network.gateway = self.gw.value ()
network.primaryNS = self.ns.value ()
network.secondaryNS = self.ns2.value()
network.ternaryNS = self.ns3.value()
screen.popWindow()
break
dev.set (("onboot", "yes"))
rc = bb.buttonPressed (result)
if rc == TEXT_BACK_CHECK:
return INSTALL_BACK
return INSTALL_OK
class HostnameWindow:
def __call__(self, screen, network):
devices = network.available ()
if not devices:
return INSTALL_NOOP
list = devices.keys ()
list.sort()
dev = devices[list[0]]
if dev.get ("bootproto") == "dhcp":
return INSTALL_NOOP
entry = Entry (24)
if network.hostname != "localhost.localdomain":
entry.set (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 = [ TEXT_OK_BUTTON, TEXT_BACK_BUTTON],
help = "hostname")
if rc == TEXT_BACK_CHECK:
return INSTALL_BACK
network.hostname = entry.value ()
return INSTALL_OK
|