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.Network import iNetwork
6 from Components.Label import Label,MultiColorLabel
7 from Components.Pixmap import Pixmap,MultiPixmap
8 from Components.MenuList import MenuList
9 from Components.config import config, ConfigYesNo, ConfigIP, NoSave, ConfigText, ConfigSelection, getConfigListEntry
10 from Components.ConfigList import ConfigListScreen
11 from Components.PluginComponent import plugins
12 from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest
13 from Plugins.Plugin import PluginDescriptor
14 from enigma import eTimer
15 from os import path as os_path, system as os_system, unlink
16 from re import compile as re_compile, search as re_search
17 from Tools.Directories import resolveFilename, SCOPE_PLUGINS
19 from Tools.Directories import SCOPE_SKIN_IMAGE,SCOPE_PLUGINS, resolveFilename
20 from Tools.LoadPixmap import LoadPixmap
21 from enigma import RT_HALIGN_LEFT, eListboxPythonMultiContent, gFont
23 class InterfaceList(MenuList):
24 def __init__(self, list, enableWrapAround=False):
25 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
26 self.l.setFont(0, gFont("Regular", 20))
27 self.l.setItemHeight(30)
29 def InterfaceEntryComponent(index,name,default,active ):
31 res.append(MultiContentEntryText(pos=(80, 5), size=(430, 25), font=0, text=name))
33 png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/buttons/button_blue.png"))
35 png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/buttons/button_blue_off.png"))
36 res.append(MultiContentEntryPixmapAlphaTest(pos=(10, 5), size=(25, 25), png = png))
38 png2 = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lock_on.png"))
40 png2 = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lock_error.png"))
41 res.append(MultiContentEntryPixmapAlphaTest(pos=(40, 1), size=(25, 25), png = png2))
45 class NetworkAdapterSelection(Screen):
46 def __init__(self, session):
47 Screen.__init__(self, session)
48 iNetwork.getInterfaces()
49 self.wlan_errortext = _("No working wireless networkadapter found.\nPlease verify that you have attached a compatible WLAN USB Stick and your Network is configured correctly.")
50 self.lan_errortext = _("No working local networkadapter found.\nPlease verify that you have attached a network cable and your Network is configured correctly.")
52 self["ButtonBluetext"] = Label(_("Set as default Interface"))
53 self["ButtonRedtext"] = Label(_("Close"))
54 self["introduction"] = Label(_("Press OK to edit the settings."))
56 self.adapters = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
58 if len(self.adapters) == 0:
59 self.onFirstExecBegin.append(self.NetworkFallback)
62 self["list"] = InterfaceList(self.list)
64 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
66 "ok": self.okbuttonClick,
68 "blue": self.setDefaultInterface,
72 if len(self.adapters) == 1:
73 self.onFirstExecBegin.append(self.okbuttonClick)
79 if os_path.exists("/etc/default_gw"):
80 fp = file('/etc/default_gw', 'r')
85 if len(self.adapters) == 0: # no interface available => display only eth0
86 self.list.append(InterfaceEntryComponent("eth0",iNetwork.getFriendlyAdapterName('eth0'),True,True ))
88 for x in self.adapters:
89 if x[1] == default_gw:
93 if iNetwork.getAdapterAttribute(x[1], 'up') is True:
97 self.list.append(InterfaceEntryComponent(index = x[1],name = _(x[0]),default=default_int,active=active_int ))
98 self["list"].l.setList(self.list)
100 def setDefaultInterface(self):
101 selection = self["list"].getCurrent()
102 num_if = len(self.list)
103 old_default_gw = None
104 if os_path.exists("/etc/default_gw"):
105 fp = open('/etc/default_gw', 'r')
106 old_default_gw = fp.read()
108 if num_if > 1 and (not old_default_gw or old_default_gw != selection[0]):
109 fp = open('/etc/default_gw', 'w+')
110 fp.write(selection[0])
112 iNetwork.restartNetwork()
114 elif old_default_gw and num_if < 2:
115 unlink("/etc/default_gw")
116 iNetwork.restartNetwork()
119 def okbuttonClick(self):
120 selection = self["list"].getCurrent()
121 print "selection",selection
122 if selection is not None:
123 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, selection[0])
125 def AdapterSetupClosed(self, *ret):
126 if len(self.adapters) == 1:
129 def NetworkFallback(self):
130 if iNetwork.configuredInterfaces.has_key('wlan0') is True:
131 self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.wlan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
132 if iNetwork.configuredInterfaces.has_key('ath0') is True:
133 self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.wlan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
135 self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.lan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
137 def ErrorMessageClosed(self, *ret):
138 if iNetwork.configuredInterfaces.has_key('wlan0') is True:
139 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'wlan0')
140 elif iNetwork.configuredInterfaces.has_key('ath0') is True:
141 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'ath0')
143 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'eth0')
145 class NameserverSetup(Screen, ConfigListScreen):
146 def __init__(self, session):
147 Screen.__init__(self, session)
148 iNetwork.getInterfaces()
149 self.backupNameserverList = iNetwork.getNameserverList()[:]
150 print "backup-list:", self.backupNameserverList
152 self["ButtonGreentext"] = Label(_("Add"))
153 self["ButtonYellowtext"] = Label(_("Delete"))
154 self["ButtonRedtext"] = Label(_("Close"))
155 self["introduction"] = Label(_("Press OK to activate the settings."))
158 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
161 "cancel": self.cancel,
164 "yellow": self.remove
168 ConfigListScreen.__init__(self, self.list)
171 def createConfig(self):
172 self.nameservers = iNetwork.getNameserverList()
173 self.nameserverEntries = []
175 for nameserver in self.nameservers:
176 self.nameserverEntries.append(NoSave(ConfigIP(default=nameserver)))
178 def createSetup(self):
181 for i in range(len(self.nameserverEntries)):
182 self.list.append(getConfigListEntry(_("Nameserver %d") % (i + 1), self.nameserverEntries[i]))
184 self["config"].list = self.list
185 self["config"].l.setList(self.list)
188 iNetwork.clearNameservers()
189 for nameserver in self.nameserverEntries:
190 iNetwork.addNameserver(nameserver.value)
191 iNetwork.writeNameserverConfig()
198 iNetwork.clearNameservers()
199 print "backup-list:", self.backupNameserverList
200 for nameserver in self.backupNameserverList:
201 iNetwork.addNameserver(nameserver)
205 iNetwork.addNameserver([0,0,0,0])
210 print "currentIndex:", self["config"].getCurrentIndex()
212 index = self["config"].getCurrentIndex()
213 if index < len(self.nameservers):
214 iNetwork.removeNameserver(self.nameservers[index])
218 class AdapterSetup(Screen, ConfigListScreen):
219 def __init__(self, session, iface,essid=None, aplist=None):
220 Screen.__init__(self, session)
221 self.session = session
226 iNetwork.getInterfaces()
228 if self.iface == "wlan0" or self.iface == "ath0" :
229 from Plugins.SystemPlugins.WirelessLan.Wlan import wpaSupplicant,Wlan
230 self.ws = wpaSupplicant()
232 list.append(_("WEP"))
233 list.append(_("WPA"))
234 list.append(_("WPA2"))
235 if self.aplist is not None:
236 self.nwlist = self.aplist
237 self.nwlist.sort(key = lambda x: x[0])
243 self.w = Wlan(self.iface)
244 self.aps = self.w.getNetworkList()
245 if self.aps is not None:
246 print "[Wlan.py] got Accespoints!"
251 a['essid'] = a['bssid']
252 self.nwlist.append( a['essid'])
253 self.nwlist.sort(key = lambda x: x[0])
255 self.nwlist.append("No Networks found")
257 wsconfig = self.ws.loadConfig()
258 default = self.essid or wsconfig['ssid']
259 if default not in self.nwlist:
260 self.nwlist.append(default)
261 config.plugins.wlan.essid = NoSave(ConfigSelection(self.nwlist, default = default ))
262 config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = wsconfig['encryption'] ))
263 config.plugins.wlan.encryption.type = NoSave(ConfigSelection(list, default = wsconfig['encryption_type'] ))
264 config.plugins.wlan.encryption.psk = NoSave(ConfigText(default = wsconfig['key'], fixed_size = False,visible_width = 30))
266 self.activateInterfaceEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "up") or False))
267 self.dhcpConfigEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "dhcp") or False))
268 self.ipConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0])
269 self.netmaskConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0]))
270 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
271 self.dhcpdefault=True
273 self.dhcpdefault=False
274 self.hasGatewayConfigEntry = NoSave(ConfigYesNo(default=self.dhcpdefault or False))
275 self.gatewayConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0]))
276 nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
277 self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
278 self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
280 self["actions"] = ActionMap(["SetupActions","ShortcutActions"],
283 "cancel": self.cancel,
285 "blue": self.KeyBlue,
289 ConfigListScreen.__init__(self, self.list)
291 self.onLayoutFinish.append(self.layoutFinished)
293 self["DNS1text"] = Label(_("Primary DNS"))
294 self["DNS2text"] = Label(_("Secondary DNS"))
295 self["DNS1"] = Label()
296 self["DNS2"] = Label()
298 self["introduction"] = Label(_("Current settings:"))
300 self["IPtext"] = Label(_("IP Address"))
301 self["Netmasktext"] = Label(_("Netmask"))
302 self["Gatewaytext"] = Label(_("Gateway"))
305 self["Mask"] = Label()
306 self["Gateway"] = Label()
308 self["BottomBG"] = Pixmap()
309 self["Adaptertext"] = Label(_("Network:"))
310 self["Adapter"] = Label()
311 self["introduction2"] = Label(_("Press OK to activate the settings."))
312 self["ButtonRed"] = Pixmap()
313 self["ButtonRedtext"] = Label(_("Close"))
314 self["ButtonBlue"] = Pixmap()
315 self["ButtonBluetext"] = Label(_("Edit DNS"))
317 def layoutFinished(self):
318 self["DNS1"].setText(self.primaryDNS.getText())
319 self["DNS2"].setText(self.secondaryDNS.getText())
320 if self.ipConfigEntry.getText() is not None:
321 self["IP"].setText(self.ipConfigEntry.getText())
323 self["IP"].setText([0,0,0,0])
324 self["Mask"].setText(self.netmaskConfigEntry.getText())
325 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
326 self["Gateway"].setText(self.gatewayConfigEntry.getText())
328 self["Gateway"].hide()
329 self["Gatewaytext"].hide()
330 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
333 def createSetup(self):
335 self.InterfaceEntry = getConfigListEntry(_("Use Interface"), self.activateInterfaceEntry)
336 self.list.append(self.InterfaceEntry)
337 if self.activateInterfaceEntry.value:
338 self.dhcpEntry = getConfigListEntry(_("Use DHCP"), self.dhcpConfigEntry)
339 self.list.append(self.dhcpEntry)
340 if not self.dhcpConfigEntry.value:
341 self.list.append(getConfigListEntry(_('IP Address'), self.ipConfigEntry))
342 self.list.append(getConfigListEntry(_('Netmask'), self.netmaskConfigEntry))
343 self.list.append(getConfigListEntry(_('Use a gateway'), self.hasGatewayConfigEntry))
344 if self.hasGatewayConfigEntry.value:
345 self.list.append(getConfigListEntry(_('Gateway'), self.gatewayConfigEntry))
347 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
348 callFnc = p.__call__["ifaceSupported"](self.iface)
349 if callFnc is not None:
350 self.extended = callFnc
351 if p.__call__.has_key("configStrings"):
352 self.configStrings = p.__call__["configStrings"]
354 self.configStrings = None
356 self.list.append(getConfigListEntry(_("Network SSID"), config.plugins.wlan.essid))
357 self.encryptionEnabled = getConfigListEntry(_("Encryption"), config.plugins.wlan.encryption.enabled)
358 self.list.append(self.encryptionEnabled)
360 if config.plugins.wlan.encryption.enabled.value:
361 self.list.append(getConfigListEntry(_("Encryption Type"), config.plugins.wlan.encryption.type))
362 self.list.append(getConfigListEntry(_("Encryption Key"), config.plugins.wlan.encryption.psk))
364 self["config"].list = self.list
365 self["config"].l.setList(self.list)
368 self.session.openWithCallback(self.NameserverSetupClosed, NameserverSetup)
371 print self["config"].getCurrent()
372 if self["config"].getCurrent() == self.dhcpEntry:
376 ConfigListScreen.keyLeft(self)
380 ConfigListScreen.keyRight(self)
384 iNetwork.setAdapterAttribute(self.iface, "up", self.activateInterfaceEntry.value)
385 if self.activateInterfaceEntry.value is True:
386 iNetwork.setAdapterAttribute(self.iface, "dhcp", self.dhcpConfigEntry.value)
387 iNetwork.setAdapterAttribute(self.iface, "ip", self.ipConfigEntry.value)
388 iNetwork.setAdapterAttribute(self.iface, "netmask", self.netmaskConfigEntry.value)
389 if self.hasGatewayConfigEntry.value:
390 iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value)
392 iNetwork.removeAdapterAttribute(self.iface, "gateway")
393 if self.extended is not None and self.configStrings is not None:
394 iNetwork.setAdapterAttribute(self.iface, "configStrings", self.configStrings(self.iface))
395 self.ws.writeConfig()
397 iNetwork.removeAdapterAttribute(self.iface, "ip")
398 iNetwork.removeAdapterAttribute(self.iface, "netmask")
399 iNetwork.removeAdapterAttribute(self.iface, "gateway")
400 iNetwork.deactivateInterface(self.iface)
402 iNetwork.deactivateNetworkConfig()
403 iNetwork.writeNetworkConfig()
404 iNetwork.activateNetworkConfig()
408 if self.activateInterfaceEntry.value is False:
409 iNetwork.deactivateInterface(self.iface)
410 iNetwork.getInterfaces()
416 def NameserverSetupClosed(self, *ret):
417 iNetwork.loadNameserverConfig()
418 nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
419 self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
420 self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
422 self.layoutFinished()
425 class AdapterSetupConfiguration(Screen):
426 def __init__(self, session,iface):
427 Screen.__init__(self, session)
428 self.session = session
430 self.mainmenu = self.genMainMenu()
431 self["menulist"] = MenuList(self.mainmenu)
432 self["description"] = Label()
433 self["IFtext"] = Label()
435 self["BottomBG"] = Label()
436 self["Statustext"] = Label()
437 self["statuspic"] = MultiPixmap()
438 self["statuspic"].hide()
439 self["BottomBG"] = Pixmap()
440 self["ButtonRed"] = Pixmap()
441 self["ButtonRedtext"] = Label(_("Close"))
443 self.oktext = _("Press OK on your remote control to continue.")
444 self.reboottext = _("Your Dreambox will restart after pressing OK on your remote control.")
445 self.errortext = _("No working wireless interface found.\n Please verify that you have attached a compatible WLAN device or enable you local network interface.")
447 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
458 iNetwork.getInterfaces()
459 self.onLayoutFinish.append(self.layoutFinished)
460 self.updateStatusbar()
463 print "SELF.iFACE im OK Klick",self.iface
464 print "self.menulist.getCurrent()[1]",self["menulist"].getCurrent()[1]
465 if self["menulist"].getCurrent()[1] == 'edit':
466 if self.iface == 'wlan0' or self.iface == 'ath0':
468 from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
469 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
471 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
473 ifobj = Wireless(self.iface) # a Wireless NIC Object
474 self.wlanresponse = ifobj.getStatistics()
475 if self.wlanresponse[0] != 19: # Wlan Interface found.
476 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
478 # Display Wlan not available Message
479 self.showErrorMessage()
481 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
482 if self["menulist"].getCurrent()[1] == 'test':
483 self.session.open(NetworkAdapterTest,self.iface)
484 if self["menulist"].getCurrent()[1] == 'dns':
485 self.session.open(NameserverSetup)
486 if self["menulist"].getCurrent()[1] == 'scanwlan':
488 from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
489 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
491 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
493 ifobj = Wireless(self.iface) # a Wireless NIC Object
494 self.wlanresponse = ifobj.getStatistics()
495 if self.wlanresponse[0] != 19:
496 self.session.openWithCallback(self.WlanScanClosed, WlanScan, self.iface)
498 # Display Wlan not available Message
499 self.showErrorMessage()
500 if self["menulist"].getCurrent()[1] == 'wlanstatus':
502 from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
503 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
505 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
507 ifobj = Wireless(self.iface) # a Wireless NIC Object
508 self.wlanresponse = ifobj.getStatistics()
509 if self.wlanresponse[0] != 19:
510 self.session.open(WlanStatus,self.iface)
512 # Display Wlan not available Message
513 self.showErrorMessage()
514 if self["menulist"].getCurrent()[1] == 'lanrestart':
515 self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
516 if self["menulist"].getCurrent()[1] == 'openwizard':
517 from Plugins.SystemPlugins.NetworkWizard.NetworkWizard import NetworkWizard
518 self.session.openWithCallback(self.AdapterSetupClosed, NetworkWizard)
521 self["menulist"].up()
522 self.loadDescription()
525 self["menulist"].down()
526 self.loadDescription()
529 self["menulist"].pageUp()
530 self.loadDescription()
533 self["menulist"].pageDown()
534 self.loadDescription()
536 def layoutFinished(self):
538 self["menulist"].moveToIndex(idx)
539 self.loadDescription()
541 def loadDescription(self):
542 if self["menulist"].getCurrent()[1] == 'edit':
543 self["description"].setText(_("Edit the network configuration of your Dreambox.\n" ) + self.oktext )
544 if self["menulist"].getCurrent()[1] == 'test':
545 self["description"].setText(_("Test the network configuration of your Dreambox.\n" ) + self.oktext )
546 if self["menulist"].getCurrent()[1] == 'dns':
547 self["description"].setText(_("Edit the Nameserver configuration of your Dreambox.\n" ) + self.oktext )
548 if self["menulist"].getCurrent()[1] == 'scanwlan':
549 self["description"].setText(_("Scan your network for wireless Access Points and connect to them using your WLAN USB Stick\n" ) + self.oktext )
550 if self["menulist"].getCurrent()[1] == 'wlanstatus':
551 self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
552 if self["menulist"].getCurrent()[1] == 'lanrestart':
553 self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
554 if self["menulist"].getCurrent()[1] == 'openwizard':
555 self["description"].setText(_("Use the Networkwizard to configure your Network\n" ) + self.oktext )
557 def updateStatusbar(self):
558 self["IFtext"].setText(_("Network:"))
559 self["IF"].setText(iNetwork.getFriendlyAdapterName(self.iface))
560 self["Statustext"].setText(_("Link:"))
562 if self.iface == 'wlan0' or self.iface == 'ath0':
564 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
566 stats = w.getStatus()
567 if stats['BSSID'] == "00:00:00:00:00:00":
568 self["statuspic"].setPixmapNum(1)
570 self["statuspic"].setPixmapNum(0)
571 self["statuspic"].show()
573 self["statuspic"].setPixmapNum(1)
574 self["statuspic"].show()
576 self.getLinkState(self.iface)
581 def genMainMenu(self):
583 menu.append((_("Adapter settings"), "edit"))
584 menu.append((_("Nameserver settings"), "dns"))
585 menu.append((_("Network test"), "test"))
586 menu.append((_("Restart network"), "lanrestart"))
588 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
589 callFnc = p.__call__["ifaceSupported"](self.iface)
590 if callFnc is not None:
591 menu.append((_("Scan Wireless Networks"), "scanwlan"))
592 if iNetwork.getAdapterAttribute(self.iface, "up"):
593 menu.append((_("Show WLAN Status"), "wlanstatus"))
595 if os_path.exists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkWizard/networkwizard.xml")):
596 menu.append((_("NetworkWizard"), "openwizard"));
599 def AdapterSetupClosed(self, *ret):
600 self.mainmenu = self.genMainMenu()
601 self["menulist"].l.setList(self.mainmenu)
602 iNetwork.getInterfaces()
603 self.updateStatusbar()
605 def WlanScanClosed(self,*ret):
606 if ret[0] is not None:
607 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,ret[0],ret[1])
609 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,None,ret[0])
612 def restartLan(self, ret = False):
614 iNetwork.restartNetwork()
616 def getLinkState(self,iface):
617 iNetwork.getLinkState(iface,self.dataAvail)
619 def dataAvail(self,data):
620 self.output = data.strip()
621 result = self.output.split('\n')
622 pattern = re_compile("Link detected: yes")
624 if re_search(pattern, item):
625 self["statuspic"].setPixmapNum(0)
627 self["statuspic"].setPixmapNum(1)
628 self["statuspic"].show()
630 def showErrorMessage(self):
631 self.session.open(MessageBox, self.errortext, type = MessageBox.TYPE_INFO,timeout = 10 )
634 class NetworkAdapterTest(Screen):
635 def __init__(self, session,iface):
636 Screen.__init__(self, session)
638 iNetwork.getInterfaces()
641 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
645 "up": lambda: self.updownhandler('up'),
646 "down": lambda: self.updownhandler('down'),
650 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
655 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
657 "red": self.closeInfo,
658 "back": self.closeInfo,
660 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
662 "green": self.KeyGreen,
664 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
666 "green": self.KeyGreenRestart,
668 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
670 "yellow": self.KeyYellow,
673 self["shortcutsgreen_restart"].setEnabled(False)
674 self["updown_actions"].setEnabled(False)
675 self["infoshortcuts"].setEnabled(False)
676 self.onClose.append(self.delTimer)
677 self.onLayoutFinish.append(self.layoutFinished)
678 self.steptimer = False
680 self.activebutton = 0
681 self.nextStepTimer = eTimer()
682 self.nextStepTimer.callback.append(self.nextStepTimerFire)
685 self["shortcuts"].setEnabled(True)
686 self["infoshortcuts"].setEnabled(False)
687 self["InfoText"].hide()
688 self["InfoTextBorder"].hide()
689 self["ButtonRedtext"].setText(_("Close"))
693 del self.nextStepTimer
695 def nextStepTimerFire(self):
696 self.nextStepTimer.stop()
697 self.steptimer = False
700 def updownhandler(self,direction):
701 if direction == 'up':
702 if self.activebutton >=2:
703 self.activebutton -= 1
705 self.activebutton = 6
706 self.setActiveButton(self.activebutton)
707 if direction == 'down':
708 if self.activebutton <=5:
709 self.activebutton += 1
711 self.activebutton = 1
712 self.setActiveButton(self.activebutton)
714 def setActiveButton(self,button):
716 self["EditSettingsButton"].setPixmapNum(0)
717 self["EditSettings_Text"].setForegroundColorNum(0)
718 self["NetworkInfo"].setPixmapNum(0)
719 self["NetworkInfo_Text"].setForegroundColorNum(1)
720 self["AdapterInfo"].setPixmapNum(1) # active
721 self["AdapterInfo_Text"].setForegroundColorNum(2) # active
723 self["AdapterInfo_Text"].setForegroundColorNum(1)
724 self["AdapterInfo"].setPixmapNum(0)
725 self["DhcpInfo"].setPixmapNum(0)
726 self["DhcpInfo_Text"].setForegroundColorNum(1)
727 self["NetworkInfo"].setPixmapNum(1) # active
728 self["NetworkInfo_Text"].setForegroundColorNum(2) # active
730 self["NetworkInfo"].setPixmapNum(0)
731 self["NetworkInfo_Text"].setForegroundColorNum(1)
732 self["IPInfo"].setPixmapNum(0)
733 self["IPInfo_Text"].setForegroundColorNum(1)
734 self["DhcpInfo"].setPixmapNum(1) # active
735 self["DhcpInfo_Text"].setForegroundColorNum(2) # active
737 self["DhcpInfo"].setPixmapNum(0)
738 self["DhcpInfo_Text"].setForegroundColorNum(1)
739 self["DNSInfo"].setPixmapNum(0)
740 self["DNSInfo_Text"].setForegroundColorNum(1)
741 self["IPInfo"].setPixmapNum(1) # active
742 self["IPInfo_Text"].setForegroundColorNum(2) # active
744 self["IPInfo"].setPixmapNum(0)
745 self["IPInfo_Text"].setForegroundColorNum(1)
746 self["EditSettingsButton"].setPixmapNum(0)
747 self["EditSettings_Text"].setForegroundColorNum(0)
748 self["DNSInfo"].setPixmapNum(1) # active
749 self["DNSInfo_Text"].setForegroundColorNum(2) # active
751 self["DNSInfo"].setPixmapNum(0)
752 self["DNSInfo_Text"].setForegroundColorNum(1)
753 self["EditSettingsButton"].setPixmapNum(1) # active
754 self["EditSettings_Text"].setForegroundColorNum(2) # active
755 self["AdapterInfo"].setPixmapNum(0)
756 self["AdapterInfo_Text"].setForegroundColorNum(1)
775 self.steptimer = True
776 self.nextStepTimer.start(3000)
779 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
780 self["Adapter"].setForegroundColorNum(2)
781 self["Adaptertext"].setForegroundColorNum(1)
782 self["AdapterInfo_Text"].setForegroundColorNum(1)
783 self["AdapterInfo_OK"].show()
784 self.steptimer = True
785 self.nextStepTimer.start(3000)
788 self["Networktext"].setForegroundColorNum(1)
789 self.getLinkState(self.iface)
790 self["NetworkInfo_Text"].setForegroundColorNum(1)
791 self.steptimer = True
792 self.nextStepTimer.start(3000)
795 self["Dhcptext"].setForegroundColorNum(1)
796 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
797 self["Dhcp"].setForegroundColorNum(2)
798 self["Dhcp"].setText(_("enabled"))
799 self["DhcpInfo_Check"].setPixmapNum(0)
801 self["Dhcp"].setForegroundColorNum(1)
802 self["Dhcp"].setText(_("disabled"))
803 self["DhcpInfo_Check"].setPixmapNum(1)
804 self["DhcpInfo_Check"].show()
805 self["DhcpInfo_Text"].setForegroundColorNum(1)
806 self.steptimer = True
807 self.nextStepTimer.start(3000)
810 self["IPtext"].setForegroundColorNum(1)
811 ret = iNetwork.checkNetworkState()
813 self["IP"].setForegroundColorNum(2)
814 self["IP"].setText(_("confirmed"))
815 self["IPInfo_Check"].setPixmapNum(0)
817 self["IP"].setForegroundColorNum(1)
818 self["IP"].setText(_("unconfirmed"))
819 self["IPInfo_Check"].setPixmapNum(1)
820 self["IPInfo_Check"].show()
821 self["IPInfo_Text"].setForegroundColorNum(1)
822 self.steptimer = True
823 self.nextStepTimer.start(3000)
826 self.steptimer = False
827 self.nextStepTimer.stop()
828 self["DNStext"].setForegroundColorNum(1)
829 ret = iNetwork.checkDNSLookup()
831 self["DNS"].setForegroundColorNum(2)
832 self["DNS"].setText(_("confirmed"))
833 self["DNSInfo_Check"].setPixmapNum(0)
835 self["DNS"].setForegroundColorNum(1)
836 self["DNS"].setText(_("unconfirmed"))
837 self["DNSInfo_Check"].setPixmapNum(1)
838 self["DNSInfo_Check"].show()
839 self["DNSInfo_Text"].setForegroundColorNum(1)
841 self["EditSettings_Text"].show()
842 self["EditSettingsButton"].setPixmapNum(1)
843 self["EditSettings_Text"].setForegroundColorNum(2) # active
844 self["EditSettingsButton"].show()
845 self["ButtonYellow_Check"].setPixmapNum(1)
846 self["ButtonGreentext"].setText(_("Restart test"))
847 self["ButtonGreen_Check"].setPixmapNum(0)
848 self["shortcutsgreen"].setEnabled(False)
849 self["shortcutsgreen_restart"].setEnabled(True)
850 self["shortcutsyellow"].setEnabled(False)
851 self["updown_actions"].setEnabled(True)
852 self.activebutton = 6
855 self["shortcutsgreen"].setEnabled(False)
856 self["shortcutsyellow"].setEnabled(True)
857 self["updown_actions"].setEnabled(False)
858 self["ButtonYellow_Check"].setPixmapNum(0)
859 self["ButtonGreen_Check"].setPixmapNum(1)
860 self.steptimer = True
861 self.nextStepTimer.start(1000)
863 def KeyGreenRestart(self):
865 self.layoutFinished()
866 self["Adapter"].setText((""))
867 self["Network"].setText((""))
868 self["Dhcp"].setText((""))
869 self["IP"].setText((""))
870 self["DNS"].setText((""))
871 self["AdapterInfo_Text"].setForegroundColorNum(0)
872 self["NetworkInfo_Text"].setForegroundColorNum(0)
873 self["DhcpInfo_Text"].setForegroundColorNum(0)
874 self["IPInfo_Text"].setForegroundColorNum(0)
875 self["DNSInfo_Text"].setForegroundColorNum(0)
876 self["shortcutsgreen_restart"].setEnabled(False)
877 self["shortcutsgreen"].setEnabled(False)
878 self["shortcutsyellow"].setEnabled(True)
879 self["updown_actions"].setEnabled(False)
880 self["ButtonYellow_Check"].setPixmapNum(0)
881 self["ButtonGreen_Check"].setPixmapNum(1)
882 self.steptimer = True
883 self.nextStepTimer.start(1000)
886 self["infoshortcuts"].setEnabled(True)
887 self["shortcuts"].setEnabled(False)
888 if self.activebutton == 1: # Adapter Check
889 self["InfoText"].setText(_("This test detects your configured LAN-Adapter."))
890 self["InfoTextBorder"].show()
891 self["InfoText"].show()
892 self["ButtonRedtext"].setText(_("Back"))
893 if self.activebutton == 2: #LAN Check
894 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"))
895 self["InfoTextBorder"].show()
896 self["InfoText"].show()
897 self["ButtonRedtext"].setText(_("Back"))
898 if self.activebutton == 3: #DHCP Check
899 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."))
900 self["InfoTextBorder"].show()
901 self["InfoText"].show()
902 self["ButtonRedtext"].setText(_("Back"))
903 if self.activebutton == 4: # IP Check
904 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"))
905 self["InfoTextBorder"].show()
906 self["InfoText"].show()
907 self["ButtonRedtext"].setText(_("Back"))
908 if self.activebutton == 5: # DNS Check
909 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"))
910 self["InfoTextBorder"].show()
911 self["InfoText"].show()
912 self["ButtonRedtext"].setText(_("Back"))
913 if self.activebutton == 6: # Edit Settings
914 self.session.open(AdapterSetup,self.iface)
918 self["shortcutsgreen_restart"].setEnabled(True)
919 self["shortcutsgreen"].setEnabled(False)
920 self["shortcutsyellow"].setEnabled(False)
921 self["ButtonGreentext"].setText(_("Restart test"))
922 self["ButtonYellow_Check"].setPixmapNum(1)
923 self["ButtonGreen_Check"].setPixmapNum(0)
924 self.steptimer = False
925 self.nextStepTimer.stop()
927 def layoutFinished(self):
928 self["shortcutsyellow"].setEnabled(False)
929 self["AdapterInfo_OK"].hide()
930 self["NetworkInfo_Check"].hide()
931 self["DhcpInfo_Check"].hide()
932 self["IPInfo_Check"].hide()
933 self["DNSInfo_Check"].hide()
934 self["EditSettings_Text"].hide()
935 self["EditSettingsButton"].hide()
936 self["InfoText"].hide()
937 self["InfoTextBorder"].hide()
940 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
941 self["Adapter"] = MultiColorLabel()
942 self["AdapterInfo"] = MultiPixmap()
943 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
944 self["AdapterInfo_OK"] = Pixmap()
946 if self.iface == 'wlan0' or self.iface == 'ath0':
947 self["Networktext"] = MultiColorLabel(_("Wireless Network"))
949 self["Networktext"] = MultiColorLabel(_("Local Network"))
951 self["Network"] = MultiColorLabel()
952 self["NetworkInfo"] = MultiPixmap()
953 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
954 self["NetworkInfo_Check"] = MultiPixmap()
956 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
957 self["Dhcp"] = MultiColorLabel()
958 self["DhcpInfo"] = MultiPixmap()
959 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
960 self["DhcpInfo_Check"] = MultiPixmap()
962 self["IPtext"] = MultiColorLabel(_("IP Address"))
963 self["IP"] = MultiColorLabel()
964 self["IPInfo"] = MultiPixmap()
965 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
966 self["IPInfo_Check"] = MultiPixmap()
968 self["DNStext"] = MultiColorLabel(_("Nameserver"))
969 self["DNS"] = MultiColorLabel()
970 self["DNSInfo"] = MultiPixmap()
971 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
972 self["DNSInfo_Check"] = MultiPixmap()
974 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
975 self["EditSettingsButton"] = MultiPixmap()
977 self["ButtonRedtext"] = Label(_("Close"))
978 self["ButtonRed"] = Pixmap()
980 self["ButtonGreentext"] = Label(_("Start test"))
981 self["ButtonGreen_Check"] = MultiPixmap()
983 self["ButtonYellowtext"] = Label(_("Stop test"))
984 self["ButtonYellow_Check"] = MultiPixmap()
986 self["InfoTextBorder"] = Pixmap()
987 self["InfoText"] = Label()
989 def getLinkState(self,iface):
990 if iface == 'wlan0' or iface == 'ath0':
992 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
994 stats = w.getStatus()
995 if stats['BSSID'] == "00:00:00:00:00:00":
996 self["Network"].setForegroundColorNum(1)
997 self["Network"].setText(_("disconnected"))
998 self["NetworkInfo_Check"].setPixmapNum(1)
999 self["NetworkInfo_Check"].show()
1001 self["Network"].setForegroundColorNum(2)
1002 self["Network"].setText(_("connected"))
1003 self["NetworkInfo_Check"].setPixmapNum(0)
1004 self["NetworkInfo_Check"].show()
1006 self["Network"].setForegroundColorNum(1)
1007 self["Network"].setText(_("disconnected"))
1008 self["NetworkInfo_Check"].setPixmapNum(1)
1009 self["NetworkInfo_Check"].show()
1011 iNetwork.getLinkState(iface,self.dataAvail)
1013 def dataAvail(self,data):
1014 self.output = data.strip()
1015 result = self.output.split('\n')
1016 pattern = re_compile("Link detected: yes")
1018 if re_search(pattern, item):
1019 self["Network"].setForegroundColorNum(2)
1020 self["Network"].setText(_("connected"))
1021 self["NetworkInfo_Check"].setPixmapNum(0)
1023 self["Network"].setForegroundColorNum(1)
1024 self["Network"].setText(_("disconnected"))
1025 self["NetworkInfo_Check"].setPixmapNum(1)
1026 self["NetworkInfo_Check"].show()