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