add new network config
[enigma2.git] / lib / python / Screens / NetworkSetup.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap,NumberActionMap
3 from Screens.MessageBox import MessageBox
4 from Screens.Standby import *
5 from Components.ConfigList import ConfigListScreen
6 from Components.config import config, getConfigListEntry
7 from Components.Network import iNetwork
8 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE
9 from Components.Label import Label
10 from Components.Pixmap import Pixmap
11 from Tools.LoadPixmap import LoadPixmap
12 from Components.MenuList import MenuList
13 from Components.config import config, ConfigYesNo, ConfigIP, NoSave, ConfigNothing, ConfigSubsection, ConfigText, ConfigSelection, getConfigListEntry
14 from Components.PluginComponent import plugins
15 from Plugins.Plugin import PluginDescriptor
16 #from Plugins.SystemPlugins.WirelessLan.plugin import *
17 #from Plugins.SystemPlugins.WirelessLan.Wlan import *
18 from enigma import eTimer, eConsoleAppContainer,gRGB
19 import time, os, re
20
21
22 Black = "#000000"
23 Grey = "#8c8c93"
24 Green = "1cff1c"
25 nextstep = None
26 activebutton = None
27
28 def getColor(str):
29         return gRGB(int(str[1:], 0x10))
30
31 class NetworkAdapterSelection(Screen):
32         def __init__(self, session):
33                 Screen.__init__(self, session)
34
35                 self.adapters = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
36                 if len(self.adapters) == 0:
37                         #Reset Network to defaults if network broken
38                         iNetwork.resetNetworkConfig('lan')
39                         
40                 self["adapterlist"] = MenuList(self.adapters)
41                 self["actions"] = ActionMap(["OkCancelActions"],
42                 {
43                         "ok": self.okbuttonClick,
44                         "cancel": self.close
45                 })
46
47                 if len(self.adapters) == 1:
48                         self.onFirstExecBegin.append(self.okbuttonClick)
49
50         def okbuttonClick(self):
51                 selection = self["adapterlist"].getCurrent()
52                 if selection is not None:
53                         self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, selection[1])
54         def AdapterSetupClosed(self, *ret):
55                 if len(self.adapters) == 1: # just one network adapter.. close selection
56                         self.close()
57
58 class NameserverSetup(Screen, ConfigListScreen):
59
60         def __init__(self, session):
61                 Screen.__init__(self, session)
62                 self.backupNameserverList = iNetwork.getNameserverList()[:]
63                 print "backup-list:", self.backupNameserverList
64
65                 self["ButtonGreentext"] = Label(_("Add"))
66                 self["ButtonYellowtext"] = Label(_("Delete"))
67                 self["ButtonRedtext"] = Label(_("Close"))               
68                 self.createConfig()
69
70                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
71                 {
72                         "ok": self.ok,
73                         "cancel": self.cancel,
74                         "red": self.cancel,
75                         "green": self.add,
76                         "yellow": self.remove
77                 }, -2)
78
79                 self.list = []
80                 ConfigListScreen.__init__(self, self.list)
81                 self.createSetup()
82
83         def createConfig(self):
84                 self.nameservers = iNetwork.getNameserverList()
85                 self.nameserverEntries = []
86
87                 for nameserver in self.nameservers:
88                         self.nameserverEntries.append(NoSave(ConfigIP(default=nameserver)))
89
90         def createSetup(self):
91                 self.list = []
92
93                 for i in range(len(self.nameserverEntries)):
94                         self.list.append(getConfigListEntry(_("Nameserver %d") % (i + 1), self.nameserverEntries[i]))
95
96                 self["config"].list = self.list
97                 self["config"].l.setList(self.list)
98
99         def ok(self):
100                 iNetwork.clearNameservers()
101                 for nameserver in self.nameserverEntries:
102                         iNetwork.addNameserver(nameserver.value)
103                 iNetwork.writeNameserverConfig()
104                 self.close()
105
106         def cancel(self):
107                 iNetwork.clearNameservers()
108                 print "backup-list:", self.backupNameserverList
109                 for nameserver in self.backupNameserverList:
110                         iNetwork.addNameserver(nameserver)
111                 self.close()
112
113         def add(self):
114                 iNetwork.addNameserver([0,0,0,0])
115                 self.createConfig()
116                 self.createSetup()
117
118         def remove(self):
119                 print "currentIndex:", self["config"].getCurrentIndex()
120
121                 index = self["config"].getCurrentIndex()
122                 if index < len(self.nameservers):
123                         iNetwork.removeNameserver(self.nameservers[index])
124                         self.createConfig()
125                         self.createSetup()
126
127
128 class AdapterSetup(Screen, ConfigListScreen):
129         def __init__(self, session, iface):
130                 Screen.__init__(self, session)
131                 self.session = session
132                 ## FIXME , workaround against current wizzard not able to send arguments
133                 if iface == 0:
134                         self.iface = "eth0"
135                 elif iface == 1:
136                         self.iface = "wlan0"
137                 else:
138                         self.iface = iface
139
140                 if self.iface == 'wlan0':
141                         from Plugins.SystemPlugins.WirelessLan.Wlan import wpaSupplicant
142                         self.ws = wpaSupplicant()
143                         list = []
144                         list.append(_("WEP"))
145                         list.append(_("WPA"))
146                         list.append(_("WPA2"))
147
148                         config.plugins.wlan.essid = NoSave(ConfigText(default = "home", fixed_size = False))
149                         config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = False))
150                         config.plugins.wlan.encryption.type = NoSave(ConfigSelection(list, default = _("WPA")))
151                         config.plugins.wlan.encryption.psk = NoSave(ConfigText(default = "mysecurewlan", fixed_size = False))
152                         self.ws.loadConfig()
153
154                 self.dhcpConfigEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "dhcp") or False))
155                 self.hasGatewayConfigEntry = NoSave(ConfigYesNo(default=True))
156                 self.ipConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0])
157                 self.netmaskConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0]))
158                 self.gatewayConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0]))
159                 nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
160                 self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
161                 self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
162
163                 self["actions"] = ActionMap(["SetupActions","ShortcutActions"],
164                 {
165                         "ok": self.ok,
166                         "cancel": self.cancel,
167                         "red": self.cancel,
168                         "blue": self.KeyBlue,
169                 }, -2)
170
171                 self.list = []
172                 ConfigListScreen.__init__(self, self.list)
173                 self.createSetup()
174                 self.onLayoutFinish.append(self.layoutFinished)
175                 
176                 self["DNS1text"] = Label(_("Primary DNS"))
177                 self["DNS2text"] = Label(_("Secondary DNS"))
178                 self["DNS1"] = Label()
179                 self["DNS2"] = Label()
180                 
181                 self["introduction"] = Label(_("Current settings:"))
182                 
183                 self["IPtext"] = Label(_("IP Address"))
184                 self["Netmasktext"] = Label(_("Netmask"))
185                 self["Gatewaytext"] = Label(_("Gateway"))
186                 
187                 self["IP"] = Label()
188                 self["Mask"] = Label()
189                 self["Gateway"] = Label()
190                 
191                 self["BottomBG"] = Pixmap()
192                 self["Adaptertext"] = Label(_("Network:"))
193                 self["Adapter"] = Label()
194                 self["introduction2"] = Label(_("Press OK to activate the settings."))
195                 self["ButtonRed"] = Pixmap()
196                 self["ButtonRedtext"] = Label(_("Close"))
197                 self["ButtonBlue"] = Pixmap()
198                 self["ButtonBluetext"] = Label(_("Edit DNS"))
199
200         def layoutFinished(self):
201                 self["DNS1"].setText(self.primaryDNS.getText())
202                 self["DNS2"].setText(self.secondaryDNS.getText())
203                 self["IP"].setText(self.ipConfigEntry.getText())
204                 self["Mask"].setText(self.netmaskConfigEntry.getText())
205                 self["Gateway"].setText(self.gatewayConfigEntry.getText())              
206                 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
207                 
208         def createSetup(self):
209                 self.list = []
210
211                 self.dhcpEntry = getConfigListEntry(_("Use DHCP"), self.dhcpConfigEntry)
212                 self.list.append(self.dhcpEntry)
213                 if not self.dhcpConfigEntry.value:
214                         self.list.append(getConfigListEntry(_('IP Address'), self.ipConfigEntry))
215                         self.list.append(getConfigListEntry(_('Netmask'), self.netmaskConfigEntry))
216                         self.list.append(getConfigListEntry(_('Use a gateway'), self.hasGatewayConfigEntry))
217                         if self.hasGatewayConfigEntry.value:
218                                 self.list.append(getConfigListEntry(_('Gateway'), self.gatewayConfigEntry))
219
220                 self.extended = None
221                 self.extendedSetup = None
222                 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
223                         callFnc = p.__call__["ifaceSupported"](self.iface)
224                         if callFnc is not None:
225                                 self.extended = callFnc
226                                 print p.__call__
227                                 if p.__call__.has_key("configStrings"):
228                                         self.configStrings = p.__call__["configStrings"]
229                                 else:
230                                         self.configStrings = None
231
232                                 self.list.append(getConfigListEntry(_("Network SSID"), config.plugins.wlan.essid))
233                                 self.encryptionEnabled = getConfigListEntry(_("Encryption"), config.plugins.wlan.encryption.enabled)
234                                 self.list.append(self.encryptionEnabled)
235                 
236                                 if config.plugins.wlan.encryption.enabled.value:
237                                         self.list.append(getConfigListEntry(_("Encryption Type"), config.plugins.wlan.encryption.type))
238                                         self.list.append(getConfigListEntry(_("Encryption Key"), config.plugins.wlan.encryption.psk))
239
240
241                 self["config"].list = self.list
242                 self["config"].l.setList(self.list)
243
244         def KeyBlue(self):
245                 self.session.open(NameserverSetup)
246
247         def newConfig(self):
248                 print self["config"].getCurrent()
249                 if self["config"].getCurrent() == self.dhcpEntry:
250                         self.createSetup()
251
252         def keyLeft(self):
253                 ConfigListScreen.keyLeft(self)
254                 self.createSetup()
255
256         def keyRight(self):
257                 ConfigListScreen.keyRight(self)
258                 self.createSetup()
259
260         def ok(self):
261                 selection = self["config"].getCurrent()
262                 if selection == self.extendedSetup:
263                         self.extended(self.session, self.iface)
264                 else:
265                         iNetwork.setAdapterAttribute(self.iface, "dhcp", self.dhcpConfigEntry.value)
266                         iNetwork.setAdapterAttribute(self.iface, "ip", self.ipConfigEntry.value)
267                         iNetwork.setAdapterAttribute(self.iface, "netmask", self.netmaskConfigEntry.value)
268                         if self.hasGatewayConfigEntry.value:
269                                 iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value)
270                         else:
271                                 iNetwork.removeAdapterAttribute(self.iface, "gateway")
272
273                         if self.extended is not None and self.configStrings is not None:
274                                 iNetwork.setAdapterAttribute(self.iface, "configStrings", self.configStrings(self.iface))
275                                 self.ws.writeConfig()
276                         
277                         iNetwork.deactivateNetworkConfig()
278                         iNetwork.writeNetworkConfig()
279                         iNetwork.activateNetworkConfig()
280                         #if self.iface == 'wlan0':
281                         #       iNetwork.restartNetwork()
282                         self.close()
283
284         def cancel(self):
285                 iNetwork.getInterfaces()
286                 self.close()
287
288         def run(self):
289                 self.ok()
290
291
292 class AdapterSetupConfiguration(Screen):
293         
294         def __init__(self, session,iface):
295                 Screen.__init__(self, session)
296                 self.iface = iface
297                 self.session = session
298                 #self.ethtool_bin = "/usr/sbin/ethtool"
299                 #self.output = None
300                 #self.container = eConsoleAppContainer()
301                 self.mainmenu = self.genMainMenu()
302                 self["menulist"] = MenuList(self.mainmenu)
303                 self["description"] = Label()
304                 self["IFtext"] = Label()
305                 self["IF"] = Label()
306                 self["BottomBG"] = Label()
307                 self["Statustext"] = Label()
308                 self["statuspic_active"] = Pixmap()
309                 self["statuspic_active"].hide()
310                 self["statuspic_inactive"] = Pixmap()
311                 self["statuspic_inactive"].hide()
312                 self["BottomBG"] = Pixmap()
313                 self["ButtonRed"] = Pixmap()
314                 self["ButtonRedtext"] = Label(_("Close"))
315
316                 self.oktext = _("Press OK on your remote control to continue.")
317                 self.reboottext = _("Your Dreambox will restart after pressing OK on your remote control.")
318                 
319                 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
320                 {
321                         "ok": self.ok,
322                         "back": self.close,
323                         "up": self.up,
324                         "down": self.down,
325                         "red": self.close,
326                 }, -2)
327
328                 iNetwork.loadNetworkConfig()
329                 self.onLayoutFinish.append(self.layoutFinished)
330                 self.updateStatusbar()
331
332         def ok(self):
333                 if self["menulist"].getCurrent()[1] == 'edit':
334                         self.session.open(AdapterSetup,self.iface)
335                 if self["menulist"].getCurrent()[1] == 'test':
336                         self.session.open(NetworkAdapterTest,self.iface)
337                 if self["menulist"].getCurrent()[1] == 'dns':
338                         self.session.open(NameserverSetup)
339                 if self["menulist"].getCurrent()[1] == 'scanwlan':
340                         from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
341                         self.session.open(WlanScan,self.iface)
342                 if self["menulist"].getCurrent()[1] == 'wlanstatus':
343                         from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
344                         self.session.open(WlanStatus,self.iface)
345                 if self["menulist"].getCurrent()[1] == 'lanrestart':
346                         self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
347                 if self["menulist"].getCurrent()[1] == 'enablewlan':
348                         self.session.openWithCallback(self.enablewlan, MessageBox, (_("Are you sure you want to enable WLAN support?\nConnect your Wlan USB Stick to your Dreambox and press OK.\n\n") + self.reboottext ) )
349                 if self["menulist"].getCurrent()[1] == 'resetconfig':
350                         self.session.openWithCallback(self.resetconfig, MessageBox, (_("Are you sure you want to reset \nyour network configuration to defaults?\n\n") + self.reboottext ) )
351                 
352         def up(self):
353                 self["menulist"].up()
354                 self.loadDescription()
355
356         def down(self):
357                 self["menulist"].down()
358                 self.loadDescription()
359
360         def layoutFinished(self):
361                 idx = 0
362                 self["menulist"].moveToIndex(idx)
363                 self.loadDescription()
364
365         def loadDescription(self):
366                 if self["menulist"].getCurrent()[1] == 'edit':
367                         self["description"].setText(_("Edit the network configuration of your Dreambox.\n" ) + self.oktext )
368                 if self["menulist"].getCurrent()[1] == 'test':
369                         self["description"].setText(_("Test the network configuration of your Dreambox.\n" ) + self.oktext )
370                 if self["menulist"].getCurrent()[1] == 'resetconfig':
371                         self["description"].setText(_("Reset the network configuration of your Dreambox.\n\n" ) + self.reboottext )
372                 if self["menulist"].getCurrent()[1] == 'dns':
373                         self["description"].setText(_("Edit the Nameserver configuration of your Dreambox.\n" ) + self.oktext )
374                 if self["menulist"].getCurrent()[1] == 'scanwlan':
375                         self["description"].setText(_("Scan your network for wireless Access Points and connect to them using your WLAN USB Stick\n" ) + self.oktext )
376                 if self["menulist"].getCurrent()[1] == 'wlanstatus':
377                         self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
378                 if self["menulist"].getCurrent()[1] == 'lanrestart':
379                         self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
380                 if self["menulist"].getCurrent()[1] == 'enablewlan':
381                         self["description"].setText(_("Pressing OK enables the built in wireless LAN support of your Dreambox.\nWlan USB Sticks with Zydas ZD1211B and RAlink RT73 Chipset are supported.\nConnect your Wlan USB Stick to your Dreambox before pressing OK.\n\n" ) + self.reboottext )
382
383
384         def updateStatusbar(self):
385                 self["IFtext"].setText(_("Network:"))
386                 self["IF"].setText(iNetwork.getFriendlyAdapterName(self.iface))
387                 self["Statustext"].setText(_("Link:"))
388
389                 if self.iface == 'wlan0':
390                         from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan, WlanList, wpaSupplicant
391                         w = Wlan(self.iface)
392                         stats = w.getStatus()
393                         if stats['BSSID'] == "00:00:00:00:00:00":
394                                 self["statuspic_active"].hide()
395                                 self["statuspic_inactive"].show()
396                         else:
397                                 self["statuspic_active"].show()
398                                 self["statuspic_inactive"].hide()
399                 else:
400                         self.getLinkState(self.iface)
401                 
402         def doNothing(self):
403                 pass
404
405         def genMainMenu(self):
406                 menu = []
407                 menu.append((_("Adapter settings"), "edit"));
408                 menu.append((_("Nameserver settings"), "dns"));
409                 menu.append((_("Network test"), "test"));
410                 menu.append((_("Restart network"), "lanrestart"));
411                 menu.append((_("Reset configuration"), "resetconfig"));
412
413                 self.extended = None
414                 self.extendedSetup = None
415                 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
416                         callFnc = p.__call__["ifaceSupported"](self.iface)
417                         if callFnc is not None:
418                                 menu.append((_("Scan Wireless Networks"), "scanwlan"));
419                                 menu.append((_("Show WLAN Status"), "wlanstatus"));
420                         if callFnc is None and iNetwork.ifaces.has_key('wlan0') is False:
421                                 menu.append((_("Enable WLAN Support"), "enablewlan"));
422                 return menu
423
424         
425         def enablewlan(self, ret = False):
426                 if (ret == True):
427                         iNetwork.resetNetworkConfig('wlan')
428                         TryQuitMainloop(self.session,2)
429                 
430         def resetconfig(self, ret = False):
431                 if (ret == True):
432                         iNetwork.resetNetworkConfig('lan')
433                         TryQuitMainloop(self.session,2)
434
435         def restartLan(self, ret = False):
436                 if (ret == True):
437                         iNetwork.restartNetwork()
438
439         def getLinkState(self,iface):
440                 iNetwork.getLinkState(iface,self.dataAvail)
441
442         def dataAvail(self,data):
443                 self.output = data.strip()
444                 result = self.output.split('\n')
445                 pattern = re.compile("Link detected: yes")
446                 for item in result:
447                         if re.search(pattern, item):
448                                 self["statuspic_active"].show()
449                                 self["statuspic_inactive"].hide()
450                         else:
451                                 self["statuspic_active"].hide()
452                                 self["statuspic_inactive"].show()
453         
454
455 class NetworkAdapterTest(Screen):       
456
457         def __init__(self, session,iface):
458                 Screen.__init__(self, session)
459                 self.iface = iface
460
461                 self.setLabels()
462         
463                 self["updown_actions"] = NumberActionMap(["WizardActions"],
464                 {
465                         "ok": self.KeyOK,
466                         "up": lambda: self.updownhandler('up'),
467                         "down": lambda: self.updownhandler('down'),
468         
469                 }, -2)
470
471                 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
472                 {
473                         "red": self.close,
474                         "back": self.close,
475                 }, -2)
476                 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
477                 {
478                         "red": self.closeInfo,
479                         "back": self.closeInfo,
480                 }, -2)
481                 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
482                 {
483                         "green": self.KeyGreen,
484                 }, -2)
485                 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
486                 {
487                         "green": self.KeyGreenRestart,
488                 }, -2)
489                 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
490                 {
491                         "yellow": self.KeyYellow,
492                 }, -2)
493
494                 self["shortcutsgreen_restart"].setEnabled(False)
495                 self["updown_actions"].setEnabled(False)
496                 self["infoshortcuts"].setEnabled(False)
497                 self.onClose.append(self.delTimer)      
498                 self.onLayoutFinish.append(self.layoutFinished)
499                 self.steptimer = False
500                 global nextstep
501                 nextstep = 0
502                 global activebutton
503                 activebutton = 0                
504                 self.nextStepTimer = eTimer()
505                 self.nextStepTimer.callback.append(self.nextStepTimerFire)
506
507         def closeInfo(self):
508                 self["shortcuts"].setEnabled(True)              
509                 self["infoshortcuts"].setEnabled(False)
510                 self["InfoText"].hide()
511                 self["InfoTextBorder"].hide()
512                 self["ButtonRedtext"].setText(_("Close"))
513                 
514         def delTimer(self):
515                 del self.steptimer
516                 del self.nextStepTimer
517
518         def nextStepTimerFire(self):
519                 global nextstep
520                 self.nextstep= nextstep
521                 self.nextStepTimer.stop()
522                 self.steptimer = False
523                 self.runTest(self.nextstep)
524
525         def updownhandler(self,direction):
526                 global activebutton
527                 if direction == 'up':
528                         if activebutton >=2:
529                                 activebutton = activebutton -1
530                         self.setActiveButton(activebutton)
531                 if direction == 'down':
532                         if activebutton <=5:
533                                 activebutton = activebutton +1
534                         self.setActiveButton(activebutton)
535
536         def setActiveButton(self,button):
537                 if button == 1:
538                         self["NetworkInfo"].show()
539                         self["NetworkInfo_selected"].hide()
540                         self["AdapterInfo"].hide()
541                         self["AdapterInfo_selected"].show()
542                 if button == 2:
543                         self["AdapterInfo"].show()
544                         self["AdapterInfo_selected"].hide()
545                         self["DhcpInfo"].show()
546                         self["DhcpInfo_selected"].hide()
547                         self["NetworkInfo"].hide()
548                         self["NetworkInfo_selected"].show()             
549                 if button == 3:
550                         self["NetworkInfo"].show()
551                         self["NetworkInfo_selected"].hide()
552                         self["IPInfo"].show()
553                         self["IPInfo_selected"].hide()
554                         self["DhcpInfo"].hide()
555                         self["DhcpInfo_selected"].show()
556                 if button == 4:
557                         self["DhcpInfo"].show()
558                         self["DhcpInfo_selected"].hide()
559                         self["DNSInfo"].show()
560                         self["DNSInfo_selected"].hide()
561                         self["IPInfo"].hide()
562                         self["IPInfo_selected"].show()
563                 if button == 5:
564                         self["IPInfo"].show()
565                         self["IPInfo_selected"].hide()
566                         self["EditSettingsButton"].show()
567                         self["EditSettingsButton_selected"].hide()
568                         self["DNSInfo"].hide()
569                         self["DNSInfo_selected"].show()
570                 if button == 6:
571                         self["DNSInfo"].show()
572                         self["DNSInfo_selected"].hide()
573                         self["EditSettingsButton"].hide()
574                         self["EditSettingsButton_selected"].show()
575                         
576         def runTest(self,next):
577                 global nextstep
578                 if next == 0:
579                         nextstep = next + 1
580                         self.doStep1()
581                 if next == 1:
582                         nextstep = next + 1
583                         self.doStep2()          
584                 if next == 2:
585                         nextstep = next + 1
586                         self.doStep3()
587                 if next == 3:
588                         nextstep = next + 1
589                         self.doStep4()
590                 if next == 4:
591                         nextstep = next + 1
592                         self.doStep5()
593                 if next == 5:
594                         nextstep = next + 1
595                         self.doStep6()                  
596                 
597         def doStep1(self):
598                 self.steptimer = True
599                 self.nextStepTimer.start(3000)
600
601         def doStep2(self):
602                 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
603                 self["Adapter"].instance.setForegroundColor(getColor(Green))
604                 self["AdapterInfo_Text"].instance.setForegroundColor(getColor(Black))
605                 self["AdapterInfo_OK"].show()           
606                 self.steptimer = True
607                 self.nextStepTimer.start(3000)          
608
609         def doStep3(self):
610                 self.getLinkState(self.iface)
611                 self["NetworkInfo_Text"].instance.setForegroundColor(getColor(Black))
612                 self.steptimer = True
613                 self.nextStepTimer.start(3000)                  
614
615         def doStep4(self):
616                 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
617                         self["Dhcp"].instance.setForegroundColor(getColor(Green))
618                         self["Dhcp"].setText(_("enabled"))
619                         self["DhcpInfo_OK"].show()
620                         self["DhcpInfo_NOK"].hide()
621                 else:
622                         self["Dhcp"].instance.setForegroundColor(getColor(Grey))
623                         self["Dhcp"].setText(_("disabled"))             
624                         self["DhcpInfo_NOK"].show()
625                         self["DhcpInfo_OK"].hide()
626                 self["DhcpInfo_Text"].instance.setForegroundColor(getColor(Black))      
627                 self.steptimer = True
628                 self.nextStepTimer.start(3000)
629
630         def doStep5(self):
631                 if len(iNetwork.getAdapterAttribute(self.iface,'ip')) != 0:
632                         self["IP"].instance.setForegroundColor(getColor(Green))
633                         self["IP"].setText(_("confirmed"))
634                         self["IPInfo_OK"].show()
635                         self["IPInfo_NOK"].hide()
636                 else:
637                         self["IP"].instance.setForegroundColor(getColor(Grey))
638                         self["IP"].setText(_("unconfirmed"))                    
639                         self["IPInfo_NOK"].show()
640                         self["IPInfo_OK"].hide()
641                 self["IPInfo_Text"].instance.setForegroundColor(getColor(Black))        
642                 self.steptimer = True
643                 self.nextStepTimer.start(3000)
644
645         def doStep6(self):
646                 self.steptimer = False
647                 self.nextStepTimer.stop()
648                 if len (iNetwork.getNameserverList()) != 0:
649                         self["DNS"].instance.setForegroundColor(getColor(Green))
650                         self["DNS"].setText(_("confirmed"))
651                         self["DNSInfo_OK"].show()
652                         self["DNSInfo_NOK"].hide()
653                 else:
654                         self["DNS"].instance.setForegroundColor(getColor(Grey))
655                         self["DNS"].setText(_("unconfirmed"))
656                         self["DNSInfo_NOK"].show()
657                         self["DNSInfo_OK"].hide()
658                         
659                 self["DNSInfo_Text"].instance.setForegroundColor(getColor(Black))
660                 self["EditSettings_Text"].show()
661                 self["EditSettingsButton_selected"].show()
662                 self["ButtonYellow_off"].show()
663                 self["ButtonYellow"].hide()
664                 self["ButtonGreentext"].setText(_("Restart test"))
665                 self["ButtonGreen"].show()              
666                 self["ButtonGreen_off"].hide()
667                 self["shortcutsgreen"].setEnabled(False)
668                 self["shortcutsgreen_restart"].setEnabled(True)
669                 self["shortcutsyellow"].setEnabled(False)
670                 self["updown_actions"].setEnabled(True)
671                 global activebutton
672                 activebutton = 6
673                 
674         def KeyGreen(self):
675                 self["shortcutsgreen"].setEnabled(False)
676                 self["shortcutsyellow"].setEnabled(True)
677                 self["updown_actions"].setEnabled(False)
678                 self["ButtonYellow_off"].hide()
679                 self["ButtonYellow"].show()
680                 self["ButtonGreen"].hide()              
681                 self["ButtonGreen_off"].show()
682                 self.steptimer = True
683                 self.nextStepTimer.start(1000)
684
685         def KeyGreenRestart(self):
686                 global nextstep
687                 nextstep = 0            
688                 self.layoutFinished()
689                 self["Adapter"].setText((""))
690                 self["Network"].setText((""))
691                 self["Dhcp"].setText((""))
692                 self["IP"].setText((""))
693                 self["DNS"].setText((""))
694                 self["AdapterInfo_Text"].instance.setForegroundColor(getColor(Grey))
695                 self["NetworkInfo_Text"].instance.setForegroundColor(getColor(Grey))
696                 self["DhcpInfo_Text"].instance.setForegroundColor(getColor(Grey))
697                 self["IPInfo_Text"].instance.setForegroundColor(getColor(Grey))
698                 self["DNSInfo_Text"].instance.setForegroundColor(getColor(Grey))
699                 self["shortcutsgreen_restart"].setEnabled(False)
700                 self["shortcutsgreen"].setEnabled(False)
701                 self["shortcutsyellow"].setEnabled(True)
702                 self["updown_actions"].setEnabled(False)
703                 self["ButtonYellow_off"].hide()
704                 self["ButtonYellow"].show()
705                 self["ButtonGreen"].hide()              
706                 self["ButtonGreen_off"].show()
707                 self.steptimer = True
708                 self.nextStepTimer.start(1000)
709                 
710         def KeyOK(self):
711                 global activebutton
712                 self["infoshortcuts"].setEnabled(True)
713                 self["shortcuts"].setEnabled(False)
714                 if activebutton == 1: # Adapter Check
715                         self["InfoText"].setText(_("This test detects your configured LAN-Adapter."))
716                         self["InfoTextBorder"].show()
717                         self["InfoText"].show()
718                         self["ButtonRedtext"].setText(_("Back"))
719                 if activebutton == 2: #LAN Check
720                         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"))
721                         self["InfoTextBorder"].show()
722                         self["InfoText"].show()
723                         self["ButtonRedtext"].setText(_("Back"))
724                 if activebutton == 3: #DHCP Check
725                         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."))
726                         self["InfoTextBorder"].show()
727                         self["InfoText"].show()
728                         self["ButtonRedtext"].setText(_("Back"))
729                 if activebutton == 4: # IP Check
730                         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"))
731                         self["InfoTextBorder"].show()
732                         self["InfoText"].show()
733                         self["ButtonRedtext"].setText(_("Back"))
734                 if activebutton == 5: # DNS Check
735                         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"))
736                         self["InfoTextBorder"].show()
737                         self["InfoText"].show()
738                         self["ButtonRedtext"].setText(_("Back"))
739                 if activebutton == 6: # Edit Settings
740                         self.session.open(AdapterSetup,self.iface)
741
742         def KeyYellow(self):
743                 global nextstep
744                 nextstep = 0
745                 self["shortcutsgreen_restart"].setEnabled(True)
746                 self["shortcutsgreen"].setEnabled(False)
747                 self["shortcutsyellow"].setEnabled(False)
748                 self["ButtonGreentext"].setText(_("Restart test"))
749                 self["ButtonYellow_off"].show()
750                 self["ButtonYellow"].hide()
751                 self["ButtonGreen"].show()              
752                 self["ButtonGreen_off"].hide()
753                 self.steptimer = False
754                 self.nextStepTimer.stop()
755                 
756         def layoutFinished(self):
757                 self["shortcutsyellow"].setEnabled(False)
758                 self["AdapterInfo_selected"].hide()
759                 self["AdapterInfo_OK"].hide()
760                 
761                 self["NetworkInfo_selected"].hide()
762                 self["NetworkInfo_OK"].hide()
763                 self["NetworkInfo_NOK"].hide()
764                 
765                 self["DhcpInfo_selected"].hide()
766                 self["DhcpInfo_OK"].hide()
767                 self["DhcpInfo_NOK"].hide()
768                 
769                 self["IPInfo_selected"].hide()
770                 self["IPInfo_OK"].hide()
771                 self["IPInfo_NOK"].hide()
772                 
773                 self["DNSInfo_selected"].hide()
774                 self["DNSInfo_OK"].hide()
775                 self["DNSInfo_NOK"].hide()
776                 
777                 self["EditSettings_Text"].hide()
778                 self["EditSettingsButton"].hide()
779                 self["EditSettingsButton_selected"].hide()
780                 self["ButtonYellow"].hide()
781                 self["ButtonGreen_off"].hide()
782                 self["InfoText"].hide()
783                 self["InfoTextBorder"].hide()
784                 
785         def setLabels(self):
786                 self["Adaptertext"] = Label(_("LAN Adapter"))
787                 self["Adapter"] = Label()
788                 self["AdapterInfo"] = Pixmap()
789                 self["AdapterInfo_selected"] = Pixmap()
790                 self["AdapterInfo_Text"] = Label(_("Show Info"))
791                 self["AdapterInfo_OK"] = Pixmap()
792                 
793                 if self.iface == 'wlan0':
794                         self["Networktext"] = Label(_("Wireless Network"))
795                 else:
796                         self["Networktext"] = Label(_("Local Network"))
797                 
798                 self["Network"] = Label()
799                 self["NetworkInfo"] = Pixmap()
800                 self["NetworkInfo_selected"] = Pixmap()
801                 self["NetworkInfo_Text"] = Label(_("Show Info"))
802                 self["NetworkInfo_OK"] = Pixmap()
803                 self["NetworkInfo_NOK"] = Pixmap()
804                 
805                 self["Dhcptext"] = Label(_("DHCP"))
806                 self["Dhcp"] = Label()
807                 self["DhcpInfo"] = Pixmap()
808                 self["DhcpInfo_selected"] = Pixmap()
809                 self["DhcpInfo_Text"] = Label(_("Show Info"))
810                 self["DhcpInfo_OK"] = Pixmap()
811                 self["DhcpInfo_NOK"] = Pixmap()
812                 
813                 self["IPtext"] = Label(_("IP Address"))
814                 self["IP"] = Label()
815                 self["IPInfo"] = Pixmap()
816                 self["IPInfo_selected"] = Pixmap()
817                 self["IPInfo_Text"] = Label(_("Show Info"))
818                 self["IPInfo_OK"] = Pixmap()
819                 self["IPInfo_NOK"] = Pixmap()
820                 
821                 self["DNStext"] = Label(_("Nameserver"))
822                 self["DNS"] = Label()
823                 self["DNSInfo"] = Pixmap()
824                 self["DNSInfo_selected"] = Pixmap()
825                 self["DNSInfo_Text"] = Label(_("Show Info"))
826                 self["DNSInfo_OK"] = Pixmap()
827                 self["DNSInfo_NOK"] = Pixmap()
828                 
829                 self["EditSettings_Text"] = Label(_("Edit settings"))           
830                 self["EditSettingsButton"] = Pixmap()
831                 self["EditSettingsButton_selected"] = Pixmap()
832                 
833                 self["ButtonRedtext"] = Label(_("Close"))
834                 self["ButtonRed"] = Pixmap()
835                 self["ButtonGreentext"] = Label(_("Start test"))
836                 self["ButtonGreen"] = Pixmap()
837                 self["ButtonGreen_off"] = Pixmap()
838                 self["ButtonYellowtext"] = Label(_("Stop test"))
839                 self["ButtonYellow"] = Pixmap()         
840                 self["ButtonYellow_off"] = Pixmap()
841                 
842                 self["InfoTextBorder"] = Pixmap()
843                 self["InfoText"] = Label()
844
845         def getLinkState(self,iface):
846                 iNetwork.getLinkState(iface,self.dataAvail)
847
848         def dataAvail(self,data):
849                 self.output = data.strip()
850                 result = self.output.split('\n')
851                 pattern = re.compile("Link detected: yes")
852                 for item in result:
853                         if re.search(pattern, item):
854                                 self["Network"].instance.setForegroundColor(getColor(Green))
855                                 self["Network"].setText(_("connected"))
856                                 self["NetworkInfo_OK"].show()
857                                 self["NetworkInfo_NOK"].hide()
858                         else:
859                                 self["Network"].instance.setForegroundColor(getColor(Grey))
860                                 self["Network"].setText(_("disconnected"))
861                                 self["NetworkInfo_OK"].hide()
862                                 self["NetworkInfo_NOK"].show()
863
864