887e1674417e87d3e9f362ee7a59380ef77e39cc
[enigma2.git] / lib / python / Screens / NetworkSetup.py
1 from Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Screens.InputBox import InputBox
4 from Screens.Standby import *
5 from Screens.VirtualKeyBoard import VirtualKeyBoard
6 from Screens.HelpMenu import HelpableScreen
7 from Components.Network import iNetwork
8 from Components.Label import Label,MultiColorLabel
9 from Components.Pixmap import Pixmap,MultiPixmap
10 from Components.MenuList import MenuList
11 from Components.config import config, ConfigYesNo, ConfigIP, NoSave, ConfigText, ConfigPassword, ConfigSelection, getConfigListEntry, ConfigNothing
12 from Components.ConfigList import ConfigListScreen
13 from Components.PluginComponent import plugins
14 from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest
15 from Components.ActionMap import ActionMap, NumberActionMap, HelpableActionMap
16 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
17 from Tools.LoadPixmap import LoadPixmap
18 from Plugins.Plugin import PluginDescriptor
19 from enigma import eTimer, ePoint, eSize, RT_HALIGN_LEFT, eListboxPythonMultiContent, gFont
20 from os import path as os_path, system as os_system, unlink
21 from re import compile as re_compile, search as re_search
22
23
24 class InterfaceList(MenuList):
25         def __init__(self, list, enableWrapAround=False):
26                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
27                 self.l.setFont(0, gFont("Regular", 20))
28                 self.l.setItemHeight(30)
29
30 def InterfaceEntryComponent(index,name,default,active ):
31         res = [ (index) ]
32         res.append(MultiContentEntryText(pos=(80, 5), size=(430, 25), font=0, text=name))
33         num_configured_if = len(iNetwork.getConfiguredAdapters())
34         if num_configured_if >= 2:
35                 if default is True:
36                         png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/buttons/button_blue.png"))
37                 if default is False:
38                         png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/buttons/button_blue_off.png"))
39                 res.append(MultiContentEntryPixmapAlphaTest(pos=(10, 5), size=(25, 25), png = png))
40         if active is True:
41                 png2 = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lock_on.png"))
42         if active is False:
43                 png2 = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lock_error.png"))
44         res.append(MultiContentEntryPixmapAlphaTest(pos=(40, 1), size=(25, 25), png = png2))
45         return res
46
47
48 class NetworkAdapterSelection(Screen,HelpableScreen):
49         def __init__(self, session):
50                 Screen.__init__(self, session)
51                 HelpableScreen.__init__(self)
52                 
53                 self.wlan_errortext = _("No working wireless networkadapter found.\nPlease verify that you have attached a compatible WLAN USB Stick and your Network is configured correctly.")
54                 self.lan_errortext = _("No working local networkadapter found.\nPlease verify that you have attached a network cable and your Network is configured correctly.")
55                 self.oktext = _("Press OK on your remote control to continue.")
56                 self.restartLanRef = None
57                 
58                 self["ButtonBluetext"] = Label(_("Set as default Interface"))
59                 self["ButtonBlue"] = Pixmap()
60                 self["ButtonRedtext"] = Label(_("Close"))
61                 self["introduction"] = Label(_("Press OK to edit the settings."))
62                 
63                 self.adapters = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
64                 
65                 if len(self.adapters) == 0:
66                         self.onFirstExecBegin.append(self.NetworkFallback)
67                         
68                 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
69                         {
70                         "cancel": (self.close, _("exit networkinterface list")),
71                         "ok": (self.okbuttonClick, _("select interface")),
72                         })
73
74                 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
75                         {
76                         "red": (self.close, _("exit networkinterface list")),   
77                         })
78                 
79                 self["DefaultInterfaceAction"] = HelpableActionMap(self, "ColorActions",
80                         {
81                         "blue": (self.setDefaultInterface, [_("Set interface as default Interface"),_("* Only available if more then one interface is active.")] ),     
82                         })
83                 
84                 self.list = []
85                 self["list"] = InterfaceList(self.list)
86                 self.updateList()
87                 
88                 if len(self.adapters) == 1:
89                         self.onFirstExecBegin.append(self.okbuttonClick)
90                 self.onClose.append(self.cleanup)
91                 
92         def updateList(self):
93                 iNetwork.getInterfaces()
94                 self.list = []
95                 default_gw = None
96                 num_configured_if = len(iNetwork.getConfiguredAdapters())
97                 if num_configured_if >= 2:
98                         self["ButtonBlue"].show()
99                         self["ButtonBluetext"].show()
100                         self["DefaultInterfaceAction"].setEnabled(True)
101                 else:
102                         self["ButtonBlue"].hide()
103                         self["ButtonBluetext"].hide()
104                         self["DefaultInterfaceAction"].setEnabled(False)
105
106                 if num_configured_if < 2 and os_path.exists("/etc/default_gw"):
107                         unlink("/etc/default_gw")
108                         
109                 if os_path.exists("/etc/default_gw"):
110                         fp = file('/etc/default_gw', 'r')
111                         result = fp.read()
112                         fp.close()
113                         default_gw = result
114                                         
115                 if len(self.adapters) == 0: # no interface available => display only eth0
116                         self.list.append(InterfaceEntryComponent("eth0",iNetwork.getFriendlyAdapterName('eth0'),True,True ))
117                 else:
118                         for x in self.adapters:
119                                 if x[1] == default_gw:
120                                         default_int = True
121                                 else:
122                                         default_int = False
123                                 if iNetwork.getAdapterAttribute(x[1], 'up') is True:
124                                         active_int = True
125                                 else:
126                                         active_int = False
127                                 self.list.append(InterfaceEntryComponent(index = x[1],name = _(x[0]),default=default_int,active=active_int ))
128                 self["list"].l.setList(self.list)
129
130         def setDefaultInterface(self):
131                 selection = self["list"].getCurrent()
132                 num_if = len(self.list)
133                 old_default_gw = None
134                 num_configured_if = len(iNetwork.getConfiguredAdapters())
135                 if os_path.exists("/etc/default_gw"):
136                         fp = open('/etc/default_gw', 'r')
137                         old_default_gw = fp.read()
138                         fp.close()
139                 if num_configured_if > 1 and (not old_default_gw or old_default_gw != selection[0]):
140                         fp = open('/etc/default_gw', 'w+')
141                         fp.write(selection[0])
142                         fp.close()
143                         self.restartLan()
144                 elif old_default_gw and num_configured_if < 2:
145                         unlink("/etc/default_gw")
146                         self.restartLan()
147
148         def okbuttonClick(self):
149                 selection = self["list"].getCurrent()
150                 if selection is not None:
151                         self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, selection[0])
152
153         def AdapterSetupClosed(self, *ret):
154                 if len(self.adapters) == 1:
155                         self.close()
156                 else:
157                         self.updateList()
158
159         def NetworkFallback(self):
160                 if iNetwork.configuredNetworkAdapters.has_key('wlan0') is True:
161                         self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.wlan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
162                 if iNetwork.configuredNetworkAdapters.has_key('ath0') is True:
163                         self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.wlan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
164                 else:
165                         self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.lan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
166
167         def ErrorMessageClosed(self, *ret):
168                 if iNetwork.configuredNetworkAdapters.has_key('wlan0') is True:
169                         self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'wlan0')
170                 elif iNetwork.configuredNetworkAdapters.has_key('ath0') is True:
171                         self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'ath0')
172                 else:
173                         self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'eth0')
174
175         def cleanup(self):
176                 iNetwork.stopLinkStateConsole()
177                 iNetwork.stopRestartConsole()
178
179         def restartLan(self):
180                 iNetwork.restartNetwork(self.restartLanDataAvail)
181                 self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while we configure your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
182                         
183         def restartLanDataAvail(self, data):
184                 if data is True:
185                         iNetwork.getInterfaces(self.getInterfacesDataAvail)
186
187         def getInterfacesDataAvail(self, data):
188                 if data is True:
189                         self.restartLanRef.close(True)
190
191         def restartfinishedCB(self,data):
192                 if data is True:
193                         self.updateList()
194                         self.session.open(MessageBox, _("Finished configuring your network"), type = MessageBox.TYPE_INFO, timeout = 10, default = False)
195
196
197 class NameserverSetup(Screen, ConfigListScreen, HelpableScreen):
198         def __init__(self, session):
199                 Screen.__init__(self, session)
200                 HelpableScreen.__init__(self)
201                 self.backupNameserverList = iNetwork.getNameserverList()[:]
202                 print "backup-list:", self.backupNameserverList
203                 
204                 self["ButtonGreentext"] = Label(_("Add"))
205                 self["ButtonYellowtext"] = Label(_("Delete"))
206                 self["ButtonRedtext"] = Label(_("Close"))
207                 self["introduction"] = Label(_("Press OK to activate the settings."))
208                 self.createConfig()
209                 
210                 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
211                         {
212                         "cancel": (self.cancel, _("exit nameserver configuration")),
213                         "ok": (self.ok, _("activate current configuration")),
214                         })
215                 
216                 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
217                         {
218                         "red": (self.cancel, _("exit nameserver configuration")),
219                         "green": (self.add, _("add a nameserver entry")),
220                         "yellow": (self.remove, _("remove a nameserver entry")),
221                         })
222                 
223                 
224                 self.list = []
225                 ConfigListScreen.__init__(self, self.list)
226                 self.createSetup()
227
228         def createConfig(self):
229                 self.nameservers = iNetwork.getNameserverList()
230                 self.nameserverEntries = []
231                 
232                 for nameserver in self.nameservers:
233                         self.nameserverEntries.append(NoSave(ConfigIP(default=nameserver)))
234
235         def createSetup(self):
236                 self.list = []
237                 
238                 for i in range(len(self.nameserverEntries)):
239                         self.list.append(getConfigListEntry(_("Nameserver %d") % (i + 1), self.nameserverEntries[i]))
240                 
241                 self["config"].list = self.list
242                 self["config"].l.setList(self.list)
243
244         def ok(self):
245                 iNetwork.clearNameservers()
246                 for nameserver in self.nameserverEntries:
247                         iNetwork.addNameserver(nameserver.value)
248                 iNetwork.writeNameserverConfig()
249                 self.close()
250
251         def run(self):
252                 self.ok()
253
254         def cancel(self):
255                 iNetwork.clearNameservers()
256                 print "backup-list:", self.backupNameserverList
257                 for nameserver in self.backupNameserverList:
258                         iNetwork.addNameserver(nameserver)
259                 self.close()
260
261         def add(self):
262                 iNetwork.addNameserver([0,0,0,0])
263                 self.createConfig()
264                 self.createSetup()
265
266         def remove(self):
267                 print "currentIndex:", self["config"].getCurrentIndex()
268                 
269                 index = self["config"].getCurrentIndex()
270                 if index < len(self.nameservers):
271                         iNetwork.removeNameserver(self.nameservers[index])
272                         self.createConfig()
273                         self.createSetup()
274         
275 class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
276         def __init__(self, session, iface,essid=None, aplist=None):
277                 Screen.__init__(self, session)
278                 HelpableScreen.__init__(self)
279                 self.session = session
280                 self.iface = iface
281                 self.essid = essid
282                 self.aplist = aplist
283                 self.extended = None
284                 self.applyConfigRef = None
285                 self.finished_cb = None
286                 self.oktext = _("Press OK on your remote control to continue.")
287                 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
288                 
289                 self.createConfig()
290
291                 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
292                         {
293                         "cancel": (self.cancel, _("exit networkadapter setup menu")),
294                         "ok": (self.ok, _("select menu entry")),
295                         })
296
297                 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
298                         {
299                         "red": (self.cancel, _("exit networkadapter configuration")),
300                         "blue": (self.KeyBlue, _("open nameserver configuration")),
301                         })
302
303                 self["VirtualKB"] = HelpableActionMap(self, "ColorActions",
304                         {
305                         "green": (self.KeyGreen, [_("open virtual keyboard input help"),_("* Only available when entering hidden ssid or network key")] ),                                      
306                         })
307
308                 self["actions"] = NumberActionMap(["SetupActions"],
309                 {
310                         "ok": self.ok,
311                 }, -2)
312                 
313                 
314                 self.list = []
315                 ConfigListScreen.__init__(self, self.list,session = self.session)
316                 self.createSetup()
317                 self.onLayoutFinish.append(self.layoutFinished)
318                 self.onClose.append(self.cleanup)
319                 
320                 self["DNS1text"] = Label(_("Primary DNS"))
321                 self["DNS2text"] = Label(_("Secondary DNS"))
322                 self["DNS1"] = Label()
323                 self["DNS2"] = Label()
324                 
325                 self["introduction"] = Label(_("Current settings:"))
326                 
327                 self["IPtext"] = Label(_("IP Address"))
328                 self["Netmasktext"] = Label(_("Netmask"))
329                 self["Gatewaytext"] = Label(_("Gateway"))
330                 
331                 self["IP"] = Label()
332                 self["Mask"] = Label()
333                 self["Gateway"] = Label()
334                 
335                 self["BottomBG"] = Pixmap()
336                 self["Adaptertext"] = Label(_("Network:"))
337                 self["Adapter"] = Label()
338                 self["introduction2"] = Label(_("Press OK to activate the settings."))
339                 self["ButtonRed"] = Pixmap()
340                 self["ButtonRedtext"] = Label(_("Close"))
341                 self["ButtonBlue"] = Pixmap()
342                 self["ButtonBluetext"] = Label(_("Edit DNS"))
343                 self["ButtonGreen"] = Pixmap()
344                 self["VKeyIcon"] = Pixmap()
345                 self["HelpWindow"] = Pixmap()
346
347         def layoutFinished(self):
348                 self["DNS1"].setText(self.primaryDNS.getText())
349                 self["DNS2"].setText(self.secondaryDNS.getText())
350                 if self.ipConfigEntry.getText() is not None:
351                         if self.ipConfigEntry.getText() == "0.0.0.0":
352                                 self["IP"].setText(_("N/A"))
353                         else:   
354                                 self["IP"].setText(self.ipConfigEntry.getText())
355                 else:
356                         self["IP"].setText(_("N/A"))
357                 if self.netmaskConfigEntry.getText() is not None:
358                         if self.netmaskConfigEntry.getText() == "0.0.0.0":
359                                         self["Mask"].setText(_("N/A"))
360                         else:   
361                                 self["Mask"].setText(self.netmaskConfigEntry.getText())
362                 else:
363                         self["IP"].setText(_("N/A"))                    
364                 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
365                         if self.gatewayConfigEntry.getText() == "0.0.0.0":
366                                 self["Gateway"].setText(_("N/A"))
367                         else:
368                                 self["Gateway"].setText(self.gatewayConfigEntry.getText())
369                 else:
370                         self["Gateway"].hide()
371                         self["Gatewaytext"].hide()
372                 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
373                 self["ButtonGreen"].hide()
374                 self["VKeyIcon"].hide()
375                 self["VirtualKB"].setEnabled(False)
376                 self["HelpWindow"].hide()
377
378         def createConfig(self):
379                 self.InterfaceEntry = None
380                 self.dhcpEntry = None
381                 self.gatewayEntry = None
382                 self.hiddenSSID = None
383                 self.wlanSSID = None
384                 self.encryptionEnabled = None
385                 self.encryptionKey = None
386                 self.encryptionType = None
387                 self.nwlist = None
388                 self.encryptionlist = None
389                 self.weplist = None
390                 self.wsconfig = None
391                 self.default = None
392                 
393                 if self.iface == "wlan0" or self.iface == "ath0" :
394                         from Plugins.SystemPlugins.WirelessLan.Wlan import wpaSupplicant,Wlan
395                         self.w = Wlan(self.iface)
396                         self.ws = wpaSupplicant()
397                         self.encryptionlist = []
398                         self.encryptionlist.append(("WEP", _("WEP")))
399                         self.encryptionlist.append(("WPA", _("WPA")))
400                         self.encryptionlist.append(("WPA2", _("WPA2")))
401                         self.encryptionlist.append(("WPA/WPA2", _("WPA or WPA2")))
402                         self.weplist = []
403                         self.weplist.append("ASCII")
404                         self.weplist.append("HEX")
405                         if self.aplist is not None:
406                                 self.nwlist = self.aplist
407                                 self.nwlist.sort(key = lambda x: x[0])
408                         else:
409                                 self.nwlist = []
410                                 self.aps = None
411                                 try:
412                                         self.aps = self.w.getNetworkList()
413                                         if self.aps is not None:
414                                                 print "[NetworkSetup.py] got Accespoints!"
415                                                 for ap in self.aps:
416                                                         a = self.aps[ap]
417                                                         if a['active']:
418                                                                 if a['essid'] == "":
419                                                                         a['essid'] = a['bssid']
420                                                                 self.nwlist.append( a['essid'])
421                                         self.nwlist.sort(key = lambda x: x[0])
422                                 except:
423                                         self.nwlist.append("No Networks found")
424
425                         self.wsconfig = self.ws.loadConfig()
426                         if self.essid is not None: # ssid from wlan scan
427                                 self.default = self.essid
428                         else:
429                                 self.default = self.wsconfig['ssid']
430                                 
431                         if "hidden..." not in self.nwlist:
432                                 self.nwlist.append("hidden...")
433                         if self.default not in self.nwlist:
434                                 self.nwlist.append(self.default)
435
436                         config.plugins.wlan.essid = NoSave(ConfigSelection(self.nwlist, default = self.default ))
437                         config.plugins.wlan.hiddenessid = NoSave(ConfigText(default = self.wsconfig['hiddenessid'], visible_width = 50, fixed_size = False))
438
439                         config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = self.wsconfig['encryption'] ))
440                         config.plugins.wlan.encryption.type = NoSave(ConfigSelection(self.encryptionlist, default = self.wsconfig['encryption_type'] ))
441                         config.plugins.wlan.encryption.wepkeytype = NoSave(ConfigSelection(self.weplist, default = self.wsconfig['encryption_wepkeytype'] ))
442                         config.plugins.wlan.encryption.psk = NoSave(ConfigPassword(default = self.wsconfig['key'], visible_width = 50, fixed_size = False))
443                 
444                 self.activateInterfaceEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "up") or False))
445                 self.dhcpConfigEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "dhcp") or False))
446                 self.ipConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0])
447                 self.netmaskConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0]))
448                 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
449                         self.dhcpdefault=True
450                 else:
451                         self.dhcpdefault=False
452                 self.hasGatewayConfigEntry = NoSave(ConfigYesNo(default=self.dhcpdefault or False))
453                 self.gatewayConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0]))
454                 nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
455                 self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
456                 self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
457
458         def createSetup(self):
459                 self.list = []
460                 self.InterfaceEntry = getConfigListEntry(_("Use Interface"), self.activateInterfaceEntry)
461                 
462                 self.list.append(self.InterfaceEntry)
463                 if self.activateInterfaceEntry.value:
464                         self.dhcpEntry = getConfigListEntry(_("Use DHCP"), self.dhcpConfigEntry)
465                         self.list.append(self.dhcpEntry)
466                         if not self.dhcpConfigEntry.value:
467                                 self.list.append(getConfigListEntry(_('IP Address'), self.ipConfigEntry))
468                                 self.list.append(getConfigListEntry(_('Netmask'), self.netmaskConfigEntry))
469                                 self.gatewayEntry = getConfigListEntry(_('Use a gateway'), self.hasGatewayConfigEntry)
470                                 self.list.append(self.gatewayEntry)
471                                 if self.hasGatewayConfigEntry.value:
472                                         self.list.append(getConfigListEntry(_('Gateway'), self.gatewayConfigEntry))
473                         
474                         self.extended = None            
475                         for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
476                                 callFnc = p.__call__["ifaceSupported"](self.iface)
477                                 if callFnc is not None:
478                                         if p.__call__.has_key("WlanPluginEntry"): # internally used only for WLAN Plugin
479                                                 self.extended = callFnc
480                                                 if p.__call__.has_key("configStrings"):
481                                                         self.configStrings = p.__call__["configStrings"]
482                                                 else:
483                                                         self.configStrings = None
484                                                 if config.plugins.wlan.essid.value == 'hidden...':
485                                                         self.wlanSSID = getConfigListEntry(_("Network SSID"), config.plugins.wlan.essid)
486                                                         self.list.append(self.wlanSSID)
487                                                         self.hiddenSSID = getConfigListEntry(_("Hidden network SSID"), config.plugins.wlan.hiddenessid)
488                                                         self.list.append(self.hiddenSSID)
489                                                 else:
490                                                         self.wlanSSID = getConfigListEntry(_("Network SSID"), config.plugins.wlan.essid)
491                                                         self.list.append(self.wlanSSID)
492                                                 self.encryptionEnabled = getConfigListEntry(_("Encryption"), config.plugins.wlan.encryption.enabled)
493                                                 self.list.append(self.encryptionEnabled)
494                                                 
495                                                 if config.plugins.wlan.encryption.enabled.value:
496                                                         self.encryptionType = getConfigListEntry(_("Encryption Type"), config.plugins.wlan.encryption.type)
497                                                         self.list.append(self.encryptionType)
498                                                         if config.plugins.wlan.encryption.type.value == 'WEP':
499                                                                 self.list.append(getConfigListEntry(_("Encryption Keytype"), config.plugins.wlan.encryption.wepkeytype))
500                                                                 self.encryptionKey = getConfigListEntry(_("Encryption Key"), config.plugins.wlan.encryption.psk)                                                
501                                                                 self.list.append(self.encryptionKey)                                                    
502                                                         else:                                                           
503                                                                 self.encryptionKey = getConfigListEntry(_("Encryption Key"), config.plugins.wlan.encryption.psk)                                                
504                                                                 self.list.append(self.encryptionKey)
505         
506                 
507                 self["config"].list = self.list
508                 self["config"].l.setList(self.list)
509                 if not self.selectionChanged in self["config"].onSelectionChanged:
510                         self["config"].onSelectionChanged.append(self.selectionChanged)
511
512         def KeyBlue(self):
513                 self.session.openWithCallback(self.NameserverSetupClosed, NameserverSetup)
514
515         def KeyGreen(self):
516                 if self.iface == "wlan0" or self.iface == "ath0" :      
517                         if self["config"].getCurrent() == self.hiddenSSID:
518                                 if config.plugins.wlan.essid.value == 'hidden...':
519                                         self.session.openWithCallback(self.VirtualKeyBoardSSIDCallback, VirtualKeyBoard, title = (_("Enter WLAN networkname/SSID:")), text = config.plugins.wlan.essid.value)
520                         if self["config"].getCurrent() == self.encryptionKey:
521                                 self.session.openWithCallback(self.VirtualKeyBoardKeyCallback, VirtualKeyBoard, title = (_("Enter WLAN passphrase/key:")), text = config.plugins.wlan.encryption.psk.value)
522         
523         def VirtualKeyBoardSSIDCallback(self, callback = None):
524                 if callback is not None and len(callback):
525                         config.plugins.wlan.hiddenessid = NoSave(ConfigText(default = callback, visible_width = 50, fixed_size = False))
526                         self.createSetup()
527                         
528         def VirtualKeyBoardKeyCallback(self, callback = None):
529                 if callback is not None and len(callback):
530                         config.plugins.wlan.encryption.psk = NoSave(ConfigPassword(default = callback, visible_width = 50, fixed_size = False))
531                         self.createSetup()
532                         
533         def newConfig(self):
534                 if self["config"].getCurrent() == self.InterfaceEntry:
535                         self.createSetup()
536                 if self["config"].getCurrent() == self.dhcpEntry:
537                         self.createSetup()
538                 if self["config"].getCurrent() == self.gatewayEntry:
539                         self.createSetup()
540                 if self.iface == "wlan0" or self.iface == "ath0" :      
541                         if self["config"].getCurrent() == self.wlanSSID:
542                                 self.createSetup()
543                         if self["config"].getCurrent() == self.encryptionEnabled:
544                                 self.createSetup()
545                         if self["config"].getCurrent() == self.encryptionType:
546                                 self.createSetup()      
547         def keyLeft(self):
548                 ConfigListScreen.keyLeft(self)
549                 self.newConfig()
550
551         def keyRight(self):
552                 ConfigListScreen.keyRight(self)
553                 self.newConfig()
554
555         def selectionChanged(self):
556                 current = self["config"].getCurrent()
557                 if current == self.hiddenSSID and config.plugins.wlan.essid.value == 'hidden...':
558                         helpwindowpos = self["HelpWindow"].getPosition()
559                         if current[1].help_window.instance is not None:
560                                 current[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
561                                 self["ButtonGreen"].show()
562                                 self["VKeyIcon"].show()
563                                 self["VirtualKB"].setEnabled(True)                      
564                 elif current == self.encryptionKey and config.plugins.wlan.encryption.enabled.value:
565                         helpwindowpos = self["HelpWindow"].getPosition()
566                         if current[1].help_window.instance is not None:
567                                 current[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
568                                 self["ButtonGreen"].show()
569                                 self["VKeyIcon"].show()
570                                 self["VirtualKB"].setEnabled(True)                      
571                 else:   
572                         self["ButtonGreen"].hide()
573                         self["VKeyIcon"].hide()
574                         self["VirtualKB"].setEnabled(False)
575
576         def ok(self):
577                 current = self["config"].getCurrent()
578                 if current == self.hiddenSSID and config.plugins.wlan.essid.value == 'hidden...':
579                         if current[1].help_window.instance is not None:
580                                 current[1].help_window.instance.hide()
581                 elif current == self.encryptionKey and config.plugins.wlan.encryption.enabled.value:
582                         if current[1].help_window.instance is not None:
583                                 current[1].help_window.instance.hide()
584                 self.session.openWithCallback(self.applyConfig, MessageBox, (_("Are you sure you want to activate this network configuration?\n\n") + self.oktext ) )
585
586         def applyConfig(self, ret = False):
587                 if (ret == True):
588                         iNetwork.setAdapterAttribute(self.iface, "up", self.activateInterfaceEntry.value)
589                         iNetwork.setAdapterAttribute(self.iface, "dhcp", self.dhcpConfigEntry.value)
590                         iNetwork.setAdapterAttribute(self.iface, "ip", self.ipConfigEntry.value)
591                         iNetwork.setAdapterAttribute(self.iface, "netmask", self.netmaskConfigEntry.value)
592                         if self.hasGatewayConfigEntry.value:
593                                 iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value)
594                         else:
595                                 iNetwork.removeAdapterAttribute(self.iface, "gateway")
596                         if self.extended is not None and self.configStrings is not None:
597                                 iNetwork.setAdapterAttribute(self.iface, "configStrings", self.configStrings(self.iface))
598                                 self.ws.writeConfig()
599                         if self.activateInterfaceEntry.value is False:
600                                 iNetwork.deactivateInterface(self.iface)
601                         iNetwork.writeNetworkConfig()                   
602                         iNetwork.restartNetwork(self.applyConfigDataAvail)
603                         self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait while activating your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
604                 else:
605                         self.cancel()
606                         
607         def applyConfigDataAvail(self, data):
608                 if data is True:
609                         iNetwork.getInterfaces(self.getInterfacesDataAvail)
610
611         def getInterfacesDataAvail(self, data):
612                 if data is True:
613                         self.applyConfigRef.close(True)
614
615         def applyConfigfinishedCB(self,data):
616                 if data is True:
617                         num_configured_if = len(iNetwork.getConfiguredAdapters())
618                         if num_configured_if >= 2:
619                                 self.session.openWithCallback(self.secondIfaceFoundCB, MessageBox, _("Your network configuration has been activated.\nA second configured interface has been found.\n\nDo you want to disable the second networkinterface?"), default = True)
620                         else:
621                                 if self.finished_cb:
622                                         self.session.openWithCallback(self.finished_cb, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
623                                 else:
624                                         self.session.openWithCallback(self.ConfigfinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
625         
626         def secondIfaceFoundCB(self,data):
627                 if data is False:
628                         self.close('ok')
629                 else:
630                         configuredInterfaces = iNetwork.getConfiguredAdapters()
631                         for interface in configuredInterfaces:
632                                 if interface == self.iface:
633                                         continue
634                                 iNetwork.setAdapterAttribute(interface, "up", False)
635                                 iNetwork.deactivateInterface(interface)
636                                 self.applyConfig(True)
637                         
638         def ConfigfinishedCB(self,data):
639                 if data is not None:
640                         if data is True:
641                                 self.close('ok')
642
643         def cancel(self):
644                 if self.oldInterfaceState is False:
645                         iNetwork.deactivateInterface(self.iface,self.deactivateInterfaceCB)
646                 else:
647                         self.close('cancel')
648
649         def deactivateInterfaceCB(self,data):
650                 if data is not None:
651                         if data is True:
652                                 iNetwork.getInterfaces(self.cancelCB)
653         
654         def cancelCB(self,data):                        
655                 if data is not None:
656                         if data is True:
657                                 self.close('cancel')
658                                 
659         def runAsync(self, finished_cb):
660                 self.finished_cb = finished_cb
661                 self.ok()
662                 
663         def NameserverSetupClosed(self, *ret):
664                 iNetwork.loadNameserverConfig()
665                 nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
666                 self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
667                 self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
668                 self.createSetup()
669                 self.layoutFinished()
670                 
671         def cleanup(self):
672                 iNetwork.stopLinkStateConsole()
673                 iNetwork.stopDeactivateInterfaceConsole()
674                 
675
676 class AdapterSetupConfiguration(Screen, HelpableScreen):
677         def __init__(self, session,iface):
678                 Screen.__init__(self, session)
679                 HelpableScreen.__init__(self)
680                 self.session = session
681                 self.iface = iface
682                 self.restartLanRef = None
683                 self.mainmenu = self.genMainMenu()
684                 self["menulist"] = MenuList(self.mainmenu)
685                 self["description"] = Label()
686                 self["IFtext"] = Label()
687                 self["IF"] = Label()
688                 self["BottomBG"] = Label()
689                 self["Statustext"] = Label()
690                 self["statuspic"] = MultiPixmap()
691                 self["statuspic"].hide()
692                 self["BottomBG"] = Pixmap()
693                 self["ButtonRed"] = Pixmap()
694                 self["ButtonRedtext"] = Label(_("Close"))
695                 
696                 self.oktext = _("Press OK on your remote control to continue.")
697                 self.reboottext = _("Your Dreambox will restart after pressing OK on your remote control.")
698                 self.errortext = _("No working wireless interface found.\n Please verify that you have attached a compatible WLAN device or enable you local network interface.")       
699                 
700                 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
701                         {
702                         "up": (self.up, _("move up to previous entry")),
703                         "down": (self.down, _("move down to next entry")),
704                         "left": (self.left, _("move up to first entry")),
705                         "right": (self.right, _("move down to last entry")),
706                         })
707                 
708                 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
709                         {
710                         "cancel": (self.close, _("exit networkadapter setup menu")),
711                         "ok": (self.ok, _("select menu entry")),
712                         })
713
714                 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
715                         {
716                         "red": (self.close, _("exit networkadapter setup menu")),       
717                         })
718
719                 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
720                 {
721                         "ok": self.ok,
722                         "back": self.close,
723                         "up": self.up,
724                         "down": self.down,
725                         "red": self.close,
726                         "left": self.left,
727                         "right": self.right,
728                 }, -2)
729                 
730                 iNetwork.getInterfaces(self.updateStatusbar)
731                 self.onLayoutFinish.append(self.layoutFinished)
732                 self.onClose.append(self.cleanup)
733
734         def ok(self):
735                 if self["menulist"].getCurrent()[1] == 'edit':
736                         if self.iface == 'wlan0' or self.iface == 'ath0':
737                                 try:
738                                         from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
739                                         from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
740                                 except ImportError:
741                                         self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
742                                 else:
743                                         ifobj = Wireless(self.iface) # a Wireless NIC Object
744                                         self.wlanresponse = ifobj.getStatistics()
745                                         if self.wlanresponse[0] != 19: # Wlan Interface found.
746                                                 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
747                                         else:
748                                                 # Display Wlan not available Message
749                                                 self.showErrorMessage()
750                         else:
751                                 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
752                 if self["menulist"].getCurrent()[1] == 'test':
753                         self.session.open(NetworkAdapterTest,self.iface)
754                 if self["menulist"].getCurrent()[1] == 'dns':
755                         self.session.open(NameserverSetup)
756                 if self["menulist"].getCurrent()[1] == 'scanwlan':
757                         try:
758                                 from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
759                                 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
760                         except ImportError:
761                                 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
762                         else:
763                                 ifobj = Wireless(self.iface) # a Wireless NIC Object
764                                 self.wlanresponse = ifobj.getStatistics()
765                                 if self.wlanresponse[0] != 19:
766                                         self.session.openWithCallback(self.WlanScanClosed, WlanScan, self.iface)
767                                 else:
768                                         # Display Wlan not available Message
769                                         self.showErrorMessage()
770                 if self["menulist"].getCurrent()[1] == 'wlanstatus':
771                         try:
772                                 from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
773                                 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
774                         except ImportError:
775                                 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
776                         else:   
777                                 ifobj = Wireless(self.iface) # a Wireless NIC Object
778                                 self.wlanresponse = ifobj.getStatistics()
779                                 if self.wlanresponse[0] != 19:
780                                         self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
781                                 else:
782                                         # Display Wlan not available Message
783                                         self.showErrorMessage()
784                 if self["menulist"].getCurrent()[1] == 'lanrestart':
785                         self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
786                 if self["menulist"].getCurrent()[1] == 'openwizard':
787                         from Plugins.SystemPlugins.NetworkWizard.NetworkWizard import NetworkWizard
788                         self.session.openWithCallback(self.AdapterSetupClosed, NetworkWizard)
789                 if self["menulist"].getCurrent()[1][0] == 'extendedSetup':
790                         self.extended = self["menulist"].getCurrent()[1][2]
791                         self.extended(self.session, self.iface)
792         
793         def up(self):
794                 self["menulist"].up()
795                 self.loadDescription()
796
797         def down(self):
798                 self["menulist"].down()
799                 self.loadDescription()
800
801         def left(self):
802                 self["menulist"].pageUp()
803                 self.loadDescription()
804
805         def right(self):
806                 self["menulist"].pageDown()
807                 self.loadDescription()
808
809         def layoutFinished(self):
810                 idx = 0
811                 self["menulist"].moveToIndex(idx)
812                 self.loadDescription()
813
814         def loadDescription(self):
815                 print self["menulist"].getCurrent()[1]
816                 if self["menulist"].getCurrent()[1] == 'edit':
817                         self["description"].setText(_("Edit the network configuration of your Dreambox.\n" ) + self.oktext )
818                 if self["menulist"].getCurrent()[1] == 'test':
819                         self["description"].setText(_("Test the network configuration of your Dreambox.\n" ) + self.oktext )
820                 if self["menulist"].getCurrent()[1] == 'dns':
821                         self["description"].setText(_("Edit the Nameserver configuration of your Dreambox.\n" ) + self.oktext )
822                 if self["menulist"].getCurrent()[1] == 'scanwlan':
823                         self["description"].setText(_("Scan your network for wireless Access Points and connect to them using your WLAN USB Stick\n" ) + self.oktext )
824                 if self["menulist"].getCurrent()[1] == 'wlanstatus':
825                         self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
826                 if self["menulist"].getCurrent()[1] == 'lanrestart':
827                         self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
828                 if self["menulist"].getCurrent()[1] == 'openwizard':
829                         self["description"].setText(_("Use the Networkwizard to configure your Network\n" ) + self.oktext )
830                 if self["menulist"].getCurrent()[1][0] == 'extendedSetup':
831                         self["description"].setText(_(self["menulist"].getCurrent()[1][1]) + self.oktext )
832                 
833         def updateStatusbar(self, data = None):
834                 self["IFtext"].setText(_("Network:"))
835                 self["IF"].setText(iNetwork.getFriendlyAdapterName(self.iface))
836                 self["Statustext"].setText(_("Link:"))
837                 
838                 if self.iface == 'wlan0' or self.iface == 'ath0':
839                         try:
840                                 from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
841                         except:
842                                         self["statuspic"].setPixmapNum(1)
843                                         self["statuspic"].show()
844                         else:
845                                 iStatus.getDataForInterface(self.iface,self.getInfoCB)
846                 else:
847                         iNetwork.getLinkState(self.iface,self.dataAvail)
848
849         def doNothing(self):
850                 pass
851
852         def genMainMenu(self):
853                 menu = []
854                 menu.append((_("Adapter settings"), "edit"))
855                 menu.append((_("Nameserver settings"), "dns"))
856                 menu.append((_("Network test"), "test"))
857                 menu.append((_("Restart network"), "lanrestart"))
858
859                 self.extended = None
860                 self.extendedSetup = None               
861                 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
862                         callFnc = p.__call__["ifaceSupported"](self.iface)
863                         if callFnc is not None:
864                                 self.extended = callFnc
865                                 print p.__call__
866                                 if p.__call__.has_key("WlanPluginEntry"): # internally used only for WLAN Plugin
867                                         menu.append((_("Scan Wireless Networks"), "scanwlan"))
868                                         if iNetwork.getAdapterAttribute(self.iface, "up"):
869                                                 menu.append((_("Show WLAN Status"), "wlanstatus"))
870                                 else:
871                                         if p.__call__.has_key("menuEntryName"):
872                                                 menuEntryName = p.__call__["menuEntryName"](self.iface)
873                                         else:
874                                                 menuEntryName = _('Extended Setup...')
875                                         if p.__call__.has_key("menuEntryDescription"):
876                                                 menuEntryDescription = p.__call__["menuEntryDescription"](self.iface)
877                                         else:
878                                                 menuEntryDescription = _('Extended Networksetup Plugin...')
879                                         self.extendedSetup = ('extendedSetup',menuEntryDescription, self.extended)
880                                         menu.append((menuEntryName,self.extendedSetup))                                 
881                         
882                 if os_path.exists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkWizard/networkwizard.xml")):
883                         menu.append((_("NetworkWizard"), "openwizard"))
884
885                 return menu
886
887         def AdapterSetupClosed(self, *ret):
888                 if ret is not None and len(ret):
889                         if ret[0] == 'ok' and (self.iface == 'wlan0' or self.iface == 'ath0') and iNetwork.getAdapterAttribute(self.iface, "up") is True:
890                                 try:
891                                         from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
892                                         from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
893                                 except ImportError:
894                                         self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
895                                 else:   
896                                         ifobj = Wireless(self.iface) # a Wireless NIC Object
897                                         self.wlanresponse = ifobj.getStatistics()
898                                         if self.wlanresponse[0] != 19:
899                                                 self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
900                                         else:
901                                                 # Display Wlan not available Message
902                                                 self.showErrorMessage()
903                         else:
904                                 self.mainmenu = self.genMainMenu()
905                                 self["menulist"].l.setList(self.mainmenu)
906                                 iNetwork.getInterfaces(self.updateStatusbar)
907                 else:
908                         self.mainmenu = self.genMainMenu()
909                         self["menulist"].l.setList(self.mainmenu)
910                         iNetwork.getInterfaces(self.updateStatusbar)
911
912         def WlanStatusClosed(self, *ret):
913                 if ret is not None and len(ret):
914                         from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
915                         iStatus.stopWlanConsole()
916                         self.mainmenu = self.genMainMenu()
917                         self["menulist"].l.setList(self.mainmenu)
918                         iNetwork.getInterfaces(self.updateStatusbar)
919
920         def WlanScanClosed(self,*ret):
921                 if ret[0] is not None:
922                         self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,ret[0],ret[1])
923                 else:
924                         from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
925                         iStatus.stopWlanConsole()
926                         self.mainmenu = self.genMainMenu()
927                         self["menulist"].l.setList(self.mainmenu)
928                         iNetwork.getInterfaces(self.updateStatusbar)
929                         
930         def restartLan(self, ret = False):
931                 if (ret == True):
932                         iNetwork.restartNetwork(self.restartLanDataAvail)
933                         self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while your network is restarting..."), type = MessageBox.TYPE_INFO, enable_input = False)
934                         
935         def restartLanDataAvail(self, data):
936                 if data is True:
937                         iNetwork.getInterfaces(self.getInterfacesDataAvail)
938
939         def getInterfacesDataAvail(self, data):
940                 if data is True:
941                         self.restartLanRef.close(True)
942
943         def restartfinishedCB(self,data):
944                 if data is True:
945                         self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 10, default = False)
946
947         def dataAvail(self,data):
948                 self.output = data.strip()
949                 result = self.output.split('\n')
950                 pattern = re_compile("Link detected: yes")
951                 for item in result:
952                         if re_search(pattern, item):
953                                 self["statuspic"].setPixmapNum(1)
954                         else:
955                                 self["statuspic"].setPixmapNum(0)
956                 self["statuspic"].show()
957
958         def showErrorMessage(self):
959                 self.session.open(MessageBox, self.errortext, type = MessageBox.TYPE_INFO,timeout = 10 )
960                 
961         def cleanup(self):
962                 iNetwork.stopLinkStateConsole()
963                 iNetwork.stopDeactivateInterfaceConsole()
964                 try:
965                         from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
966                 except ImportError:
967                         pass
968                 else:
969                         iStatus.stopWlanConsole()
970
971         def getInfoCB(self,data,status):
972                 if data is not None:
973                         if data is True:
974                                 if status is not None:
975                                         if status[self.iface]["acesspoint"] == "No Connection" or status[self.iface]["acesspoint"] == "Not-Associated" or status[self.iface]["acesspoint"] == False:
976                                                 self["statuspic"].setPixmapNum(1)
977                                         else:
978                                                 self["statuspic"].setPixmapNum(0)
979                                         self["statuspic"].show()
980
981 class NetworkAdapterTest(Screen):       
982         def __init__(self, session,iface):
983                 Screen.__init__(self, session)
984                 self.iface = iface
985                 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
986                 iNetwork.getInterfaces()
987                 self.setLabels()
988                 self.onClose.append(self.cleanup)
989                 self.onHide.append(self.cleanup)
990                 
991                 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
992                 {
993                         "ok": self.KeyOK,
994                         "blue": self.KeyOK,
995                         "up": lambda: self.updownhandler('up'),
996                         "down": lambda: self.updownhandler('down'),
997                 
998                 }, -2)
999                 
1000                 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1001                 {
1002                         "red": self.cancel,
1003                         "back": self.cancel,
1004                 }, -2)
1005                 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1006                 {
1007                         "red": self.closeInfo,
1008                         "back": self.closeInfo,
1009                 }, -2)
1010                 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
1011                 {
1012                         "green": self.KeyGreen,
1013                 }, -2)
1014                 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
1015                 {
1016                         "green": self.KeyGreenRestart,
1017                 }, -2)
1018                 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
1019                 {
1020                         "yellow": self.KeyYellow,
1021                 }, -2)
1022                 
1023                 self["shortcutsgreen_restart"].setEnabled(False)
1024                 self["updown_actions"].setEnabled(False)
1025                 self["infoshortcuts"].setEnabled(False)
1026                 self.onClose.append(self.delTimer)      
1027                 self.onLayoutFinish.append(self.layoutFinished)
1028                 self.steptimer = False
1029                 self.nextstep = 0
1030                 self.activebutton = 0
1031                 self.nextStepTimer = eTimer()
1032                 self.nextStepTimer.callback.append(self.nextStepTimerFire)
1033
1034         def cancel(self):
1035                 if self.oldInterfaceState is False:
1036                         iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
1037                         iNetwork.deactivateInterface(self.iface)
1038                 self.close()
1039
1040         def closeInfo(self):
1041                 self["shortcuts"].setEnabled(True)              
1042                 self["infoshortcuts"].setEnabled(False)
1043                 self["InfoText"].hide()
1044                 self["InfoTextBorder"].hide()
1045                 self["ButtonRedtext"].setText(_("Close"))
1046
1047         def delTimer(self):
1048                 del self.steptimer
1049                 del self.nextStepTimer
1050
1051         def nextStepTimerFire(self):
1052                 self.nextStepTimer.stop()
1053                 self.steptimer = False
1054                 self.runTest()
1055
1056         def updownhandler(self,direction):
1057                 if direction == 'up':
1058                         if self.activebutton >=2:
1059                                 self.activebutton -= 1
1060                         else:
1061                                 self.activebutton = 6
1062                         self.setActiveButton(self.activebutton)
1063                 if direction == 'down':
1064                         if self.activebutton <=5:
1065                                 self.activebutton += 1
1066                         else:
1067                                 self.activebutton = 1
1068                         self.setActiveButton(self.activebutton)
1069
1070         def setActiveButton(self,button):
1071                 if button == 1:
1072                         self["EditSettingsButton"].setPixmapNum(0)
1073                         self["EditSettings_Text"].setForegroundColorNum(0)
1074                         self["NetworkInfo"].setPixmapNum(0)
1075                         self["NetworkInfo_Text"].setForegroundColorNum(1)
1076                         self["AdapterInfo"].setPixmapNum(1)               # active
1077                         self["AdapterInfo_Text"].setForegroundColorNum(2) # active
1078                 if button == 2:
1079                         self["AdapterInfo_Text"].setForegroundColorNum(1)
1080                         self["AdapterInfo"].setPixmapNum(0)
1081                         self["DhcpInfo"].setPixmapNum(0)
1082                         self["DhcpInfo_Text"].setForegroundColorNum(1)
1083                         self["NetworkInfo"].setPixmapNum(1)               # active
1084                         self["NetworkInfo_Text"].setForegroundColorNum(2) # active
1085                 if button == 3:
1086                         self["NetworkInfo"].setPixmapNum(0)
1087                         self["NetworkInfo_Text"].setForegroundColorNum(1)
1088                         self["IPInfo"].setPixmapNum(0)
1089                         self["IPInfo_Text"].setForegroundColorNum(1)
1090                         self["DhcpInfo"].setPixmapNum(1)                  # active
1091                         self["DhcpInfo_Text"].setForegroundColorNum(2)    # active
1092                 if button == 4:
1093                         self["DhcpInfo"].setPixmapNum(0)
1094                         self["DhcpInfo_Text"].setForegroundColorNum(1)
1095                         self["DNSInfo"].setPixmapNum(0)
1096                         self["DNSInfo_Text"].setForegroundColorNum(1)
1097                         self["IPInfo"].setPixmapNum(1)                  # active
1098                         self["IPInfo_Text"].setForegroundColorNum(2)    # active                
1099                 if button == 5:
1100                         self["IPInfo"].setPixmapNum(0)
1101                         self["IPInfo_Text"].setForegroundColorNum(1)
1102                         self["EditSettingsButton"].setPixmapNum(0)
1103                         self["EditSettings_Text"].setForegroundColorNum(0)
1104                         self["DNSInfo"].setPixmapNum(1)                 # active
1105                         self["DNSInfo_Text"].setForegroundColorNum(2)   # active
1106                 if button == 6:
1107                         self["DNSInfo"].setPixmapNum(0)
1108                         self["DNSInfo_Text"].setForegroundColorNum(1)
1109                         self["EditSettingsButton"].setPixmapNum(1)         # active
1110                         self["EditSettings_Text"].setForegroundColorNum(2) # active
1111                         self["AdapterInfo"].setPixmapNum(0)
1112                         self["AdapterInfo_Text"].setForegroundColorNum(1)
1113                         
1114         def runTest(self):
1115                 next = self.nextstep
1116                 if next == 0:
1117                         self.doStep1()
1118                 elif next == 1:
1119                         self.doStep2()
1120                 elif next == 2:
1121                         self.doStep3()
1122                 elif next == 3:
1123                         self.doStep4()
1124                 elif next == 4:
1125                         self.doStep5()
1126                 elif next == 5:
1127                         self.doStep6()
1128                 self.nextstep += 1
1129
1130         def doStep1(self):
1131                 self.steptimer = True
1132                 self.nextStepTimer.start(3000)
1133                 self["ButtonYellow_Check"].show()
1134                 self["ButtonYellowtext"].show()
1135
1136         def doStep2(self):
1137                 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
1138                 self["Adapter"].setForegroundColorNum(2)
1139                 self["Adaptertext"].setForegroundColorNum(1)
1140                 self["AdapterInfo_Text"].setForegroundColorNum(1)
1141                 self["AdapterInfo_OK"].show()
1142                 self.steptimer = True
1143                 self.nextStepTimer.start(3000)
1144
1145         def doStep3(self):
1146                 self["Networktext"].setForegroundColorNum(1)
1147                 self["Network"].setText(_("Please wait..."))
1148                 self.getLinkState(self.iface)
1149                 self["NetworkInfo_Text"].setForegroundColorNum(1)
1150                 self.steptimer = True
1151                 self.nextStepTimer.start(3000)
1152
1153         def doStep4(self):
1154                 self["Dhcptext"].setForegroundColorNum(1)
1155                 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
1156                         self["Dhcp"].setForegroundColorNum(2)
1157                         self["Dhcp"].setText(_("enabled"))
1158                         self["DhcpInfo_Check"].setPixmapNum(0)
1159                 else:
1160                         self["Dhcp"].setForegroundColorNum(1)
1161                         self["Dhcp"].setText(_("disabled"))
1162                         self["DhcpInfo_Check"].setPixmapNum(1)
1163                 self["DhcpInfo_Check"].show()
1164                 self["DhcpInfo_Text"].setForegroundColorNum(1)
1165                 self.steptimer = True
1166                 self.nextStepTimer.start(3000)
1167
1168         def doStep5(self):
1169                 self["IPtext"].setForegroundColorNum(1)
1170                 self["IP"].setText(_("Please wait..."))
1171                 iNetwork.checkNetworkState(self.NetworkStatedataAvail)
1172
1173         def doStep6(self):
1174                 self.steptimer = False
1175                 self.nextStepTimer.stop()
1176                 self["DNStext"].setForegroundColorNum(1)
1177                 self["DNS"].setText(_("Please wait..."))
1178                 iNetwork.checkDNSLookup(self.DNSLookupdataAvail)
1179
1180         def KeyGreen(self):
1181                 self["shortcutsgreen"].setEnabled(False)
1182                 self["shortcutsyellow"].setEnabled(True)
1183                 self["updown_actions"].setEnabled(False)
1184                 self["ButtonYellow_Check"].setPixmapNum(0)
1185                 self["ButtonGreen_Check"].setPixmapNum(1)
1186                 self.steptimer = True
1187                 self.nextStepTimer.start(1000)
1188
1189         def KeyGreenRestart(self):
1190                 self.nextstep = 0
1191                 self.layoutFinished()
1192                 self["Adapter"].setText((""))
1193                 self["Network"].setText((""))
1194                 self["Dhcp"].setText((""))
1195                 self["IP"].setText((""))
1196                 self["DNS"].setText((""))
1197                 self["AdapterInfo_Text"].setForegroundColorNum(0)
1198                 self["NetworkInfo_Text"].setForegroundColorNum(0)
1199                 self["DhcpInfo_Text"].setForegroundColorNum(0)
1200                 self["IPInfo_Text"].setForegroundColorNum(0)
1201                 self["DNSInfo_Text"].setForegroundColorNum(0)
1202                 self["shortcutsgreen_restart"].setEnabled(False)
1203                 self["shortcutsgreen"].setEnabled(False)
1204                 self["shortcutsyellow"].setEnabled(True)
1205                 self["updown_actions"].setEnabled(False)
1206                 self["ButtonYellow_Check"].setPixmapNum(0)
1207                 self["ButtonGreen_Check"].setPixmapNum(1)
1208                 self.steptimer = True
1209                 self.nextStepTimer.start(1000)
1210
1211         def KeyOK(self):
1212                 self["infoshortcuts"].setEnabled(True)
1213                 self["shortcuts"].setEnabled(False)
1214                 if self.activebutton == 1: # Adapter Check
1215                         self["InfoText"].setText(_("This test detects your configured LAN-Adapter."))
1216                         self["InfoTextBorder"].show()
1217                         self["InfoText"].show()
1218                         self["ButtonRedtext"].setText(_("Back"))
1219                 if self.activebutton == 2: #LAN Check
1220                         self["InfoText"].setText(_("This test checks whether a network cable is connected to your LAN-Adapter.\nIf you get a \"disconnected\" message:\n- verify that a network cable is attached\n- verify that the cable is not broken"))
1221                         self["InfoTextBorder"].show()
1222                         self["InfoText"].show()
1223                         self["ButtonRedtext"].setText(_("Back"))
1224                 if self.activebutton == 3: #DHCP Check
1225                         self["InfoText"].setText(_("This test checks whether your LAN Adapter is set up for automatic IP Address configuration with DHCP.\nIf you get a \"disabled\" message:\n - then your LAN Adapter is configured for manual IP Setup\n- verify thay you have entered correct IP informations in the AdapterSetup dialog.\nIf you get an \"enabeld\" message:\n-verify that you have a configured and working DHCP Server in your network."))
1226                         self["InfoTextBorder"].show()
1227                         self["InfoText"].show()
1228                         self["ButtonRedtext"].setText(_("Back"))
1229                 if self.activebutton == 4: # IP Check
1230                         self["InfoText"].setText(_("This test checks whether a valid IP Address is found for your LAN Adapter.\nIf you get a \"unconfirmed\" message:\n- no valid IP Address was found\n- please check your DHCP, cabling and adapter setup"))
1231                         self["InfoTextBorder"].show()
1232                         self["InfoText"].show()
1233                         self["ButtonRedtext"].setText(_("Back"))
1234                 if self.activebutton == 5: # DNS Check
1235                         self["InfoText"].setText(_("This test checks for configured Nameservers.\nIf you get a \"unconfirmed\" message:\n- please check your DHCP, cabling and Adapter setup\n- if you configured your Nameservers manually please verify your entries in the \"Nameserver\" Configuration"))
1236                         self["InfoTextBorder"].show()
1237                         self["InfoText"].show()
1238                         self["ButtonRedtext"].setText(_("Back"))
1239                 if self.activebutton == 6: # Edit Settings
1240                         self.session.open(AdapterSetup,self.iface)
1241
1242         def KeyYellow(self):
1243                 self.nextstep = 0
1244                 self["shortcutsgreen_restart"].setEnabled(True)
1245                 self["shortcutsgreen"].setEnabled(False)
1246                 self["shortcutsyellow"].setEnabled(False)
1247                 self["ButtonGreentext"].setText(_("Restart test"))
1248                 self["ButtonYellow_Check"].setPixmapNum(1)
1249                 self["ButtonGreen_Check"].setPixmapNum(0)
1250                 self.steptimer = False
1251                 self.nextStepTimer.stop()
1252
1253         def layoutFinished(self):
1254                 self["shortcutsyellow"].setEnabled(False)
1255                 self["AdapterInfo_OK"].hide()
1256                 self["NetworkInfo_Check"].hide()
1257                 self["DhcpInfo_Check"].hide()
1258                 self["IPInfo_Check"].hide()
1259                 self["DNSInfo_Check"].hide()
1260                 self["EditSettings_Text"].hide()
1261                 self["EditSettingsButton"].hide()
1262                 self["InfoText"].hide()
1263                 self["InfoTextBorder"].hide()
1264                 self["ButtonYellow_Check"].hide()
1265                 self["ButtonYellowtext"].hide()
1266
1267         def setLabels(self):
1268                 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1269                 self["Adapter"] = MultiColorLabel()
1270                 self["AdapterInfo"] = MultiPixmap()
1271                 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1272                 self["AdapterInfo_OK"] = Pixmap()
1273                 
1274                 if self.iface == 'wlan0' or self.iface == 'ath0':
1275                         self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1276                 else:
1277                         self["Networktext"] = MultiColorLabel(_("Local Network"))
1278                 
1279                 self["Network"] = MultiColorLabel()
1280                 self["NetworkInfo"] = MultiPixmap()
1281                 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1282                 self["NetworkInfo_Check"] = MultiPixmap()
1283                 
1284                 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1285                 self["Dhcp"] = MultiColorLabel()
1286                 self["DhcpInfo"] = MultiPixmap()
1287                 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1288                 self["DhcpInfo_Check"] = MultiPixmap()
1289                 
1290                 self["IPtext"] = MultiColorLabel(_("IP Address"))
1291                 self["IP"] = MultiColorLabel()
1292                 self["IPInfo"] = MultiPixmap()
1293                 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1294                 self["IPInfo_Check"] = MultiPixmap()
1295                 
1296                 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1297                 self["DNS"] = MultiColorLabel()
1298                 self["DNSInfo"] = MultiPixmap()
1299                 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1300                 self["DNSInfo_Check"] = MultiPixmap()
1301                 
1302                 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1303                 self["EditSettingsButton"] = MultiPixmap()
1304                 
1305                 self["ButtonRedtext"] = Label(_("Close"))
1306                 self["ButtonRed"] = Pixmap()
1307
1308                 self["ButtonGreentext"] = Label(_("Start test"))
1309                 self["ButtonGreen_Check"] = MultiPixmap()
1310                 
1311                 self["ButtonYellowtext"] = Label(_("Stop test"))
1312                 self["ButtonYellow_Check"] = MultiPixmap()
1313                 
1314                 self["InfoTextBorder"] = Pixmap()
1315                 self["InfoText"] = Label()
1316
1317         def getLinkState(self,iface):
1318                 if iface == 'wlan0' or iface == 'ath0':
1319                         try:
1320                                 from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
1321                         except:
1322                                         self["Network"].setForegroundColorNum(1)
1323                                         self["Network"].setText(_("disconnected"))
1324                                         self["NetworkInfo_Check"].setPixmapNum(1)
1325                                         self["NetworkInfo_Check"].show()
1326                         else:
1327                                 iStatus.getDataForInterface(self.iface,self.getInfoCB)
1328                 else:
1329                         iNetwork.getLinkState(iface,self.LinkStatedataAvail)
1330
1331         def LinkStatedataAvail(self,data):
1332                 self.output = data.strip()
1333                 result = self.output.split('\n')
1334                 pattern = re_compile("Link detected: yes")
1335                 for item in result:
1336                         if re_search(pattern, item):
1337                                 self["Network"].setForegroundColorNum(2)
1338                                 self["Network"].setText(_("connected"))
1339                                 self["NetworkInfo_Check"].setPixmapNum(0)
1340                         else:
1341                                 self["Network"].setForegroundColorNum(1)
1342                                 self["Network"].setText(_("disconnected"))
1343                                 self["NetworkInfo_Check"].setPixmapNum(1)
1344                 self["NetworkInfo_Check"].show()
1345
1346         def NetworkStatedataAvail(self,data):
1347                 if data <= 2:
1348                         self["IP"].setForegroundColorNum(2)
1349                         self["IP"].setText(_("confirmed"))
1350                         self["IPInfo_Check"].setPixmapNum(0)
1351                 else:
1352                         self["IP"].setForegroundColorNum(1)
1353                         self["IP"].setText(_("unconfirmed"))
1354                         self["IPInfo_Check"].setPixmapNum(1)
1355                 self["IPInfo_Check"].show()
1356                 self["IPInfo_Text"].setForegroundColorNum(1)            
1357                 self.steptimer = True
1358                 self.nextStepTimer.start(3000)          
1359                 
1360         def DNSLookupdataAvail(self,data):
1361                 if data <= 2:
1362                         self["DNS"].setForegroundColorNum(2)
1363                         self["DNS"].setText(_("confirmed"))
1364                         self["DNSInfo_Check"].setPixmapNum(0)
1365                 else:
1366                         self["DNS"].setForegroundColorNum(1)
1367                         self["DNS"].setText(_("unconfirmed"))
1368                         self["DNSInfo_Check"].setPixmapNum(1)
1369                 self["DNSInfo_Check"].show()
1370                 self["DNSInfo_Text"].setForegroundColorNum(1)
1371                 self["EditSettings_Text"].show()
1372                 self["EditSettingsButton"].setPixmapNum(1)
1373                 self["EditSettings_Text"].setForegroundColorNum(2) # active
1374                 self["EditSettingsButton"].show()
1375                 self["ButtonYellow_Check"].setPixmapNum(1)
1376                 self["ButtonGreentext"].setText(_("Restart test"))
1377                 self["ButtonGreen_Check"].setPixmapNum(0)
1378                 self["shortcutsgreen"].setEnabled(False)
1379                 self["shortcutsgreen_restart"].setEnabled(True)
1380                 self["shortcutsyellow"].setEnabled(False)
1381                 self["updown_actions"].setEnabled(True)
1382                 self.activebutton = 6
1383
1384         def getInfoCB(self,data,status):
1385                 if data is not None:
1386                         if data is True:
1387                                 if status is not None:
1388                                         if status[self.iface]["acesspoint"] == "No Connection" or status[self.iface]["acesspoint"] == "Not-Associated" or status[self.iface]["acesspoint"] == False:
1389                                                 self["Network"].setForegroundColorNum(1)
1390                                                 self["Network"].setText(_("disconnected"))
1391                                                 self["NetworkInfo_Check"].setPixmapNum(1)
1392                                                 self["NetworkInfo_Check"].show()
1393                                         else:
1394                                                 self["Network"].setForegroundColorNum(2)
1395                                                 self["Network"].setText(_("connected"))
1396                                                 self["NetworkInfo_Check"].setPixmapNum(0)
1397                                                 self["NetworkInfo_Check"].show()
1398                                                 
1399         def cleanup(self):
1400                 iNetwork.stopLinkStateConsole()
1401                 iNetwork.stopDNSConsole()
1402                 try:
1403                         from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
1404                 except ImportError:
1405                         pass
1406                 else:
1407                         iStatus.stopWlanConsole()