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)
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)
77 iNetwork.getInterfaces()
80 num_configured_if = len(iNetwork.configuredInterfaces)
81 print "num_configured_if :",num_configured_if
82 if num_configured_if < 2 and os_path.exists("/etc/default_gw"):
83 unlink("/etc/default_gw")
85 if os_path.exists("/etc/default_gw"):
86 fp = file('/etc/default_gw', 'r')
91 if len(self.adapters) == 0: # no interface available => display only eth0
92 self.list.append(InterfaceEntryComponent("eth0",iNetwork.getFriendlyAdapterName('eth0'),True,True ))
94 for x in self.adapters:
95 if x[1] == default_gw:
99 if iNetwork.getAdapterAttribute(x[1], 'up') is True:
103 self.list.append(InterfaceEntryComponent(index = x[1],name = _(x[0]),default=default_int,active=active_int ))
104 self["list"].l.setList(self.list)
106 def setDefaultInterface(self):
107 selection = self["list"].getCurrent()
108 num_if = len(self.list)
109 old_default_gw = None
110 if os_path.exists("/etc/default_gw"):
111 fp = open('/etc/default_gw', 'r')
112 old_default_gw = fp.read()
114 if num_if > 1 and (not old_default_gw or old_default_gw != selection[0]):
115 fp = open('/etc/default_gw', 'w+')
116 fp.write(selection[0])
118 iNetwork.restartNetwork()
120 elif old_default_gw and num_if < 2:
121 unlink("/etc/default_gw")
122 iNetwork.restartNetwork()
125 def okbuttonClick(self):
126 selection = self["list"].getCurrent()
127 print "selection",selection
128 if selection is not None:
129 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, selection[0])
131 def AdapterSetupClosed(self, *ret):
132 if len(self.adapters) == 1:
137 def NetworkFallback(self):
138 if iNetwork.configuredInterfaces.has_key('wlan0') is True:
139 self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.wlan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
140 if iNetwork.configuredInterfaces.has_key('ath0') is True:
141 self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.wlan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
143 self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.lan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
145 def ErrorMessageClosed(self, *ret):
146 if iNetwork.configuredInterfaces.has_key('wlan0') is True:
147 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'wlan0')
148 elif iNetwork.configuredInterfaces.has_key('ath0') is True:
149 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'ath0')
151 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'eth0')
153 class NameserverSetup(Screen, ConfigListScreen):
154 def __init__(self, session):
155 Screen.__init__(self, session)
156 iNetwork.getInterfaces()
157 self.backupNameserverList = iNetwork.getNameserverList()[:]
158 print "backup-list:", self.backupNameserverList
160 self["ButtonGreentext"] = Label(_("Add"))
161 self["ButtonYellowtext"] = Label(_("Delete"))
162 self["ButtonRedtext"] = Label(_("Close"))
163 self["introduction"] = Label(_("Press OK to activate the settings."))
166 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
169 "cancel": self.cancel,
172 "yellow": self.remove
176 ConfigListScreen.__init__(self, self.list)
179 def createConfig(self):
180 self.nameservers = iNetwork.getNameserverList()
181 self.nameserverEntries = []
183 for nameserver in self.nameservers:
184 self.nameserverEntries.append(NoSave(ConfigIP(default=nameserver)))
186 def createSetup(self):
189 for i in range(len(self.nameserverEntries)):
190 self.list.append(getConfigListEntry(_("Nameserver %d") % (i + 1), self.nameserverEntries[i]))
192 self["config"].list = self.list
193 self["config"].l.setList(self.list)
196 iNetwork.clearNameservers()
197 for nameserver in self.nameserverEntries:
198 iNetwork.addNameserver(nameserver.value)
199 iNetwork.writeNameserverConfig()
206 iNetwork.clearNameservers()
207 print "backup-list:", self.backupNameserverList
208 for nameserver in self.backupNameserverList:
209 iNetwork.addNameserver(nameserver)
213 iNetwork.addNameserver([0,0,0,0])
218 print "currentIndex:", self["config"].getCurrentIndex()
220 index = self["config"].getCurrentIndex()
221 if index < len(self.nameservers):
222 iNetwork.removeNameserver(self.nameservers[index])
226 class AdapterSetup(Screen, ConfigListScreen):
227 def __init__(self, session, iface,essid=None, aplist=None):
228 Screen.__init__(self, session)
229 self.session = session
234 iNetwork.getInterfaces()
236 if self.iface == "wlan0" or self.iface == "ath0" :
237 from Plugins.SystemPlugins.WirelessLan.Wlan import wpaSupplicant,Wlan
238 self.ws = wpaSupplicant()
240 list.append(_("WEP"))
241 list.append(_("WPA"))
242 list.append(_("WPA2"))
243 if self.aplist is not None:
244 self.nwlist = self.aplist
245 self.nwlist.sort(key = lambda x: x[0])
251 self.w = Wlan(self.iface)
252 self.aps = self.w.getNetworkList()
253 if self.aps is not None:
254 print "[Wlan.py] got Accespoints!"
259 a['essid'] = a['bssid']
260 self.nwlist.append( a['essid'])
261 self.nwlist.sort(key = lambda x: x[0])
263 self.nwlist.append("No Networks found")
265 wsconfig = self.ws.loadConfig()
266 default = self.essid or wsconfig['ssid']
267 if default not in self.nwlist:
268 self.nwlist.append(default)
269 config.plugins.wlan.essid = NoSave(ConfigSelection(self.nwlist, default = default ))
270 config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = wsconfig['encryption'] ))
271 config.plugins.wlan.encryption.type = NoSave(ConfigSelection(list, default = wsconfig['encryption_type'] ))
272 config.plugins.wlan.encryption.psk = NoSave(ConfigText(default = wsconfig['key'], fixed_size = False,visible_width = 30))
274 self.activateInterfaceEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "up") or False))
275 self.dhcpConfigEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "dhcp") or False))
276 self.ipConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0])
277 self.netmaskConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0]))
278 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
279 self.dhcpdefault=True
281 self.dhcpdefault=False
282 self.hasGatewayConfigEntry = NoSave(ConfigYesNo(default=self.dhcpdefault or False))
283 self.gatewayConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0]))
284 nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
285 self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
286 self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
288 self["actions"] = ActionMap(["SetupActions","ShortcutActions"],
291 "cancel": self.cancel,
293 "blue": self.KeyBlue,
297 ConfigListScreen.__init__(self, self.list)
299 self.onLayoutFinish.append(self.layoutFinished)
301 self["DNS1text"] = Label(_("Primary DNS"))
302 self["DNS2text"] = Label(_("Secondary DNS"))
303 self["DNS1"] = Label()
304 self["DNS2"] = Label()
306 self["introduction"] = Label(_("Current settings:"))
308 self["IPtext"] = Label(_("IP Address"))
309 self["Netmasktext"] = Label(_("Netmask"))
310 self["Gatewaytext"] = Label(_("Gateway"))
313 self["Mask"] = Label()
314 self["Gateway"] = Label()
316 self["BottomBG"] = Pixmap()
317 self["Adaptertext"] = Label(_("Network:"))
318 self["Adapter"] = Label()
319 self["introduction2"] = Label(_("Press OK to activate the settings."))
320 self["ButtonRed"] = Pixmap()
321 self["ButtonRedtext"] = Label(_("Close"))
322 self["ButtonBlue"] = Pixmap()
323 self["ButtonBluetext"] = Label(_("Edit DNS"))
325 def layoutFinished(self):
326 self["DNS1"].setText(self.primaryDNS.getText())
327 self["DNS2"].setText(self.secondaryDNS.getText())
328 if self.ipConfigEntry.getText() is not None:
329 self["IP"].setText(self.ipConfigEntry.getText())
331 self["IP"].setText([0,0,0,0])
332 self["Mask"].setText(self.netmaskConfigEntry.getText())
333 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
334 self["Gateway"].setText(self.gatewayConfigEntry.getText())
336 self["Gateway"].hide()
337 self["Gatewaytext"].hide()
338 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
341 def createSetup(self):
343 self.InterfaceEntry = getConfigListEntry(_("Use Interface"), self.activateInterfaceEntry)
344 self.list.append(self.InterfaceEntry)
345 if self.activateInterfaceEntry.value:
346 self.dhcpEntry = getConfigListEntry(_("Use DHCP"), self.dhcpConfigEntry)
347 self.list.append(self.dhcpEntry)
348 if not self.dhcpConfigEntry.value:
349 self.list.append(getConfigListEntry(_('IP Address'), self.ipConfigEntry))
350 self.list.append(getConfigListEntry(_('Netmask'), self.netmaskConfigEntry))
351 self.list.append(getConfigListEntry(_('Use a gateway'), self.hasGatewayConfigEntry))
352 if self.hasGatewayConfigEntry.value:
353 self.list.append(getConfigListEntry(_('Gateway'), self.gatewayConfigEntry))
355 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
356 callFnc = p.__call__["ifaceSupported"](self.iface)
357 if callFnc is not None:
358 self.extended = callFnc
359 if p.__call__.has_key("configStrings"):
360 self.configStrings = p.__call__["configStrings"]
362 self.configStrings = None
364 self.list.append(getConfigListEntry(_("Network SSID"), config.plugins.wlan.essid))
365 self.encryptionEnabled = getConfigListEntry(_("Encryption"), config.plugins.wlan.encryption.enabled)
366 self.list.append(self.encryptionEnabled)
368 if config.plugins.wlan.encryption.enabled.value:
369 self.list.append(getConfigListEntry(_("Encryption Type"), config.plugins.wlan.encryption.type))
370 self.list.append(getConfigListEntry(_("Encryption Key"), config.plugins.wlan.encryption.psk))
372 self["config"].list = self.list
373 self["config"].l.setList(self.list)
376 self.session.openWithCallback(self.NameserverSetupClosed, NameserverSetup)
379 print self["config"].getCurrent()
380 if self["config"].getCurrent() == self.dhcpEntry:
384 ConfigListScreen.keyLeft(self)
388 ConfigListScreen.keyRight(self)
392 iNetwork.setAdapterAttribute(self.iface, "up", self.activateInterfaceEntry.value)
393 if self.activateInterfaceEntry.value is True:
394 iNetwork.setAdapterAttribute(self.iface, "dhcp", self.dhcpConfigEntry.value)
395 iNetwork.setAdapterAttribute(self.iface, "ip", self.ipConfigEntry.value)
396 iNetwork.setAdapterAttribute(self.iface, "netmask", self.netmaskConfigEntry.value)
397 if self.hasGatewayConfigEntry.value:
398 iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value)
400 iNetwork.removeAdapterAttribute(self.iface, "gateway")
401 if self.extended is not None and self.configStrings is not None:
402 iNetwork.setAdapterAttribute(self.iface, "configStrings", self.configStrings(self.iface))
403 self.ws.writeConfig()
405 iNetwork.removeAdapterAttribute(self.iface, "ip")
406 iNetwork.removeAdapterAttribute(self.iface, "netmask")
407 iNetwork.removeAdapterAttribute(self.iface, "gateway")
408 iNetwork.deactivateInterface(self.iface)
410 iNetwork.deactivateNetworkConfig()
411 iNetwork.writeNetworkConfig()
412 iNetwork.activateNetworkConfig()
416 if self.activateInterfaceEntry.value is False:
417 iNetwork.deactivateInterface(self.iface)
418 iNetwork.getInterfaces()
424 def NameserverSetupClosed(self, *ret):
425 iNetwork.loadNameserverConfig()
426 nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
427 self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
428 self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
430 self.layoutFinished()
433 class AdapterSetupConfiguration(Screen):
434 def __init__(self, session,iface):
435 Screen.__init__(self, session)
436 self.session = session
438 self.mainmenu = self.genMainMenu()
439 self["menulist"] = MenuList(self.mainmenu)
440 self["description"] = Label()
441 self["IFtext"] = Label()
443 self["BottomBG"] = Label()
444 self["Statustext"] = Label()
445 self["statuspic"] = MultiPixmap()
446 self["statuspic"].hide()
447 self["BottomBG"] = Pixmap()
448 self["ButtonRed"] = Pixmap()
449 self["ButtonRedtext"] = Label(_("Close"))
451 self.oktext = _("Press OK on your remote control to continue.")
452 self.reboottext = _("Your Dreambox will restart after pressing OK on your remote control.")
453 self.errortext = _("No working wireless interface found.\n Please verify that you have attached a compatible WLAN device or enable you local network interface.")
455 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
466 iNetwork.getInterfaces()
467 self.onLayoutFinish.append(self.layoutFinished)
468 self.updateStatusbar()
471 print "SELF.iFACE im OK Klick",self.iface
472 print "self.menulist.getCurrent()[1]",self["menulist"].getCurrent()[1]
473 if self["menulist"].getCurrent()[1] == 'edit':
474 if self.iface == 'wlan0' or self.iface == 'ath0':
476 from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
477 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
479 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
481 ifobj = Wireless(self.iface) # a Wireless NIC Object
482 self.wlanresponse = ifobj.getStatistics()
483 if self.wlanresponse[0] != 19: # Wlan Interface found.
484 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
486 # Display Wlan not available Message
487 self.showErrorMessage()
489 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
490 if self["menulist"].getCurrent()[1] == 'test':
491 self.session.open(NetworkAdapterTest,self.iface)
492 if self["menulist"].getCurrent()[1] == 'dns':
493 self.session.open(NameserverSetup)
494 if self["menulist"].getCurrent()[1] == 'scanwlan':
496 from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
497 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
499 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
501 ifobj = Wireless(self.iface) # a Wireless NIC Object
502 self.wlanresponse = ifobj.getStatistics()
503 if self.wlanresponse[0] != 19:
504 self.session.openWithCallback(self.WlanScanClosed, WlanScan, self.iface)
506 # Display Wlan not available Message
507 self.showErrorMessage()
508 if self["menulist"].getCurrent()[1] == 'wlanstatus':
510 from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
511 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
513 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
515 ifobj = Wireless(self.iface) # a Wireless NIC Object
516 self.wlanresponse = ifobj.getStatistics()
517 if self.wlanresponse[0] != 19:
518 self.session.open(WlanStatus,self.iface)
520 # Display Wlan not available Message
521 self.showErrorMessage()
522 if self["menulist"].getCurrent()[1] == 'lanrestart':
523 self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
524 if self["menulist"].getCurrent()[1] == 'openwizard':
525 from Plugins.SystemPlugins.NetworkWizard.NetworkWizard import NetworkWizard
526 self.session.openWithCallback(self.AdapterSetupClosed, NetworkWizard)
529 self["menulist"].up()
530 self.loadDescription()
533 self["menulist"].down()
534 self.loadDescription()
537 self["menulist"].pageUp()
538 self.loadDescription()
541 self["menulist"].pageDown()
542 self.loadDescription()
544 def layoutFinished(self):
546 self["menulist"].moveToIndex(idx)
547 self.loadDescription()
549 def loadDescription(self):
550 if self["menulist"].getCurrent()[1] == 'edit':
551 self["description"].setText(_("Edit the network configuration of your Dreambox.\n" ) + self.oktext )
552 if self["menulist"].getCurrent()[1] == 'test':
553 self["description"].setText(_("Test the network configuration of your Dreambox.\n" ) + self.oktext )
554 if self["menulist"].getCurrent()[1] == 'dns':
555 self["description"].setText(_("Edit the Nameserver configuration of your Dreambox.\n" ) + self.oktext )
556 if self["menulist"].getCurrent()[1] == 'scanwlan':
557 self["description"].setText(_("Scan your network for wireless Access Points and connect to them using your WLAN USB Stick\n" ) + self.oktext )
558 if self["menulist"].getCurrent()[1] == 'wlanstatus':
559 self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
560 if self["menulist"].getCurrent()[1] == 'lanrestart':
561 self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
562 if self["menulist"].getCurrent()[1] == 'openwizard':
563 self["description"].setText(_("Use the Networkwizard to configure your Network\n" ) + self.oktext )
565 def updateStatusbar(self):
566 self["IFtext"].setText(_("Network:"))
567 self["IF"].setText(iNetwork.getFriendlyAdapterName(self.iface))
568 self["Statustext"].setText(_("Link:"))
570 if self.iface == 'wlan0' or self.iface == 'ath0':
572 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
574 stats = w.getStatus()
575 if stats['BSSID'] == "00:00:00:00:00:00":
576 self["statuspic"].setPixmapNum(1)
578 self["statuspic"].setPixmapNum(0)
579 self["statuspic"].show()
581 self["statuspic"].setPixmapNum(1)
582 self["statuspic"].show()
584 self.getLinkState(self.iface)
589 def genMainMenu(self):
591 menu.append((_("Adapter settings"), "edit"))
592 menu.append((_("Nameserver settings"), "dns"))
593 menu.append((_("Network test"), "test"))
594 menu.append((_("Restart network"), "lanrestart"))
596 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
597 callFnc = p.__call__["ifaceSupported"](self.iface)
598 if callFnc is not None:
599 menu.append((_("Scan Wireless Networks"), "scanwlan"))
600 if iNetwork.getAdapterAttribute(self.iface, "up"):
601 menu.append((_("Show WLAN Status"), "wlanstatus"))
603 if os_path.exists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkWizard/networkwizard.xml")):
604 menu.append((_("NetworkWizard"), "openwizard"));
607 def AdapterSetupClosed(self, *ret):
608 self.mainmenu = self.genMainMenu()
609 self["menulist"].l.setList(self.mainmenu)
610 iNetwork.getInterfaces()
611 self.updateStatusbar()
613 def WlanScanClosed(self,*ret):
614 if ret[0] is not None:
615 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,ret[0],ret[1])
617 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,None,ret[0])
620 def restartLan(self, ret = False):
622 iNetwork.restartNetwork()
624 def getLinkState(self,iface):
625 iNetwork.getLinkState(iface,self.dataAvail)
627 def dataAvail(self,data):
628 self.output = data.strip()
629 result = self.output.split('\n')
630 pattern = re_compile("Link detected: yes")
632 if re_search(pattern, item):
633 self["statuspic"].setPixmapNum(0)
635 self["statuspic"].setPixmapNum(1)
636 self["statuspic"].show()
638 def showErrorMessage(self):
639 self.session.open(MessageBox, self.errortext, type = MessageBox.TYPE_INFO,timeout = 10 )
642 class NetworkAdapterTest(Screen):
643 def __init__(self, session,iface):
644 Screen.__init__(self, session)
646 iNetwork.getInterfaces()
649 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
653 "up": lambda: self.updownhandler('up'),
654 "down": lambda: self.updownhandler('down'),
658 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
663 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
665 "red": self.closeInfo,
666 "back": self.closeInfo,
668 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
670 "green": self.KeyGreen,
672 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
674 "green": self.KeyGreenRestart,
676 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
678 "yellow": self.KeyYellow,
681 self["shortcutsgreen_restart"].setEnabled(False)
682 self["updown_actions"].setEnabled(False)
683 self["infoshortcuts"].setEnabled(False)
684 self.onClose.append(self.delTimer)
685 self.onLayoutFinish.append(self.layoutFinished)
686 self.steptimer = False
688 self.activebutton = 0
689 self.nextStepTimer = eTimer()
690 self.nextStepTimer.callback.append(self.nextStepTimerFire)
693 self["shortcuts"].setEnabled(True)
694 self["infoshortcuts"].setEnabled(False)
695 self["InfoText"].hide()
696 self["InfoTextBorder"].hide()
697 self["ButtonRedtext"].setText(_("Close"))
701 del self.nextStepTimer
703 def nextStepTimerFire(self):
704 self.nextStepTimer.stop()
705 self.steptimer = False
708 def updownhandler(self,direction):
709 if direction == 'up':
710 if self.activebutton >=2:
711 self.activebutton -= 1
713 self.activebutton = 6
714 self.setActiveButton(self.activebutton)
715 if direction == 'down':
716 if self.activebutton <=5:
717 self.activebutton += 1
719 self.activebutton = 1
720 self.setActiveButton(self.activebutton)
722 def setActiveButton(self,button):
724 self["EditSettingsButton"].setPixmapNum(0)
725 self["EditSettings_Text"].setForegroundColorNum(0)
726 self["NetworkInfo"].setPixmapNum(0)
727 self["NetworkInfo_Text"].setForegroundColorNum(1)
728 self["AdapterInfo"].setPixmapNum(1) # active
729 self["AdapterInfo_Text"].setForegroundColorNum(2) # active
731 self["AdapterInfo_Text"].setForegroundColorNum(1)
732 self["AdapterInfo"].setPixmapNum(0)
733 self["DhcpInfo"].setPixmapNum(0)
734 self["DhcpInfo_Text"].setForegroundColorNum(1)
735 self["NetworkInfo"].setPixmapNum(1) # active
736 self["NetworkInfo_Text"].setForegroundColorNum(2) # active
738 self["NetworkInfo"].setPixmapNum(0)
739 self["NetworkInfo_Text"].setForegroundColorNum(1)
740 self["IPInfo"].setPixmapNum(0)
741 self["IPInfo_Text"].setForegroundColorNum(1)
742 self["DhcpInfo"].setPixmapNum(1) # active
743 self["DhcpInfo_Text"].setForegroundColorNum(2) # active
745 self["DhcpInfo"].setPixmapNum(0)
746 self["DhcpInfo_Text"].setForegroundColorNum(1)
747 self["DNSInfo"].setPixmapNum(0)
748 self["DNSInfo_Text"].setForegroundColorNum(1)
749 self["IPInfo"].setPixmapNum(1) # active
750 self["IPInfo_Text"].setForegroundColorNum(2) # active
752 self["IPInfo"].setPixmapNum(0)
753 self["IPInfo_Text"].setForegroundColorNum(1)
754 self["EditSettingsButton"].setPixmapNum(0)
755 self["EditSettings_Text"].setForegroundColorNum(0)
756 self["DNSInfo"].setPixmapNum(1) # active
757 self["DNSInfo_Text"].setForegroundColorNum(2) # active
759 self["DNSInfo"].setPixmapNum(0)
760 self["DNSInfo_Text"].setForegroundColorNum(1)
761 self["EditSettingsButton"].setPixmapNum(1) # active
762 self["EditSettings_Text"].setForegroundColorNum(2) # active
763 self["AdapterInfo"].setPixmapNum(0)
764 self["AdapterInfo_Text"].setForegroundColorNum(1)
783 self.steptimer = True
784 self.nextStepTimer.start(3000)
787 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
788 self["Adapter"].setForegroundColorNum(2)
789 self["Adaptertext"].setForegroundColorNum(1)
790 self["AdapterInfo_Text"].setForegroundColorNum(1)
791 self["AdapterInfo_OK"].show()
792 self.steptimer = True
793 self.nextStepTimer.start(3000)
796 self["Networktext"].setForegroundColorNum(1)
797 self.getLinkState(self.iface)
798 self["NetworkInfo_Text"].setForegroundColorNum(1)
799 self.steptimer = True
800 self.nextStepTimer.start(3000)
803 self["Dhcptext"].setForegroundColorNum(1)
804 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
805 self["Dhcp"].setForegroundColorNum(2)
806 self["Dhcp"].setText(_("enabled"))
807 self["DhcpInfo_Check"].setPixmapNum(0)
809 self["Dhcp"].setForegroundColorNum(1)
810 self["Dhcp"].setText(_("disabled"))
811 self["DhcpInfo_Check"].setPixmapNum(1)
812 self["DhcpInfo_Check"].show()
813 self["DhcpInfo_Text"].setForegroundColorNum(1)
814 self.steptimer = True
815 self.nextStepTimer.start(3000)
818 self["IPtext"].setForegroundColorNum(1)
819 ret = iNetwork.checkNetworkState()
821 self["IP"].setForegroundColorNum(2)
822 self["IP"].setText(_("confirmed"))
823 self["IPInfo_Check"].setPixmapNum(0)
825 self["IP"].setForegroundColorNum(1)
826 self["IP"].setText(_("unconfirmed"))
827 self["IPInfo_Check"].setPixmapNum(1)
828 self["IPInfo_Check"].show()
829 self["IPInfo_Text"].setForegroundColorNum(1)
830 self.steptimer = True
831 self.nextStepTimer.start(3000)
834 self.steptimer = False
835 self.nextStepTimer.stop()
836 self["DNStext"].setForegroundColorNum(1)
837 ret = iNetwork.checkDNSLookup()
839 self["DNS"].setForegroundColorNum(2)
840 self["DNS"].setText(_("confirmed"))
841 self["DNSInfo_Check"].setPixmapNum(0)
843 self["DNS"].setForegroundColorNum(1)
844 self["DNS"].setText(_("unconfirmed"))
845 self["DNSInfo_Check"].setPixmapNum(1)
846 self["DNSInfo_Check"].show()
847 self["DNSInfo_Text"].setForegroundColorNum(1)
849 self["EditSettings_Text"].show()
850 self["EditSettingsButton"].setPixmapNum(1)
851 self["EditSettings_Text"].setForegroundColorNum(2) # active
852 self["EditSettingsButton"].show()
853 self["ButtonYellow_Check"].setPixmapNum(1)
854 self["ButtonGreentext"].setText(_("Restart test"))
855 self["ButtonGreen_Check"].setPixmapNum(0)
856 self["shortcutsgreen"].setEnabled(False)
857 self["shortcutsgreen_restart"].setEnabled(True)
858 self["shortcutsyellow"].setEnabled(False)
859 self["updown_actions"].setEnabled(True)
860 self.activebutton = 6
863 self["shortcutsgreen"].setEnabled(False)
864 self["shortcutsyellow"].setEnabled(True)
865 self["updown_actions"].setEnabled(False)
866 self["ButtonYellow_Check"].setPixmapNum(0)
867 self["ButtonGreen_Check"].setPixmapNum(1)
868 self.steptimer = True
869 self.nextStepTimer.start(1000)
871 def KeyGreenRestart(self):
873 self.layoutFinished()
874 self["Adapter"].setText((""))
875 self["Network"].setText((""))
876 self["Dhcp"].setText((""))
877 self["IP"].setText((""))
878 self["DNS"].setText((""))
879 self["AdapterInfo_Text"].setForegroundColorNum(0)
880 self["NetworkInfo_Text"].setForegroundColorNum(0)
881 self["DhcpInfo_Text"].setForegroundColorNum(0)
882 self["IPInfo_Text"].setForegroundColorNum(0)
883 self["DNSInfo_Text"].setForegroundColorNum(0)
884 self["shortcutsgreen_restart"].setEnabled(False)
885 self["shortcutsgreen"].setEnabled(False)
886 self["shortcutsyellow"].setEnabled(True)
887 self["updown_actions"].setEnabled(False)
888 self["ButtonYellow_Check"].setPixmapNum(0)
889 self["ButtonGreen_Check"].setPixmapNum(1)
890 self.steptimer = True
891 self.nextStepTimer.start(1000)
894 self["infoshortcuts"].setEnabled(True)
895 self["shortcuts"].setEnabled(False)
896 if self.activebutton == 1: # Adapter Check
897 self["InfoText"].setText(_("This test detects your configured LAN-Adapter."))
898 self["InfoTextBorder"].show()
899 self["InfoText"].show()
900 self["ButtonRedtext"].setText(_("Back"))
901 if self.activebutton == 2: #LAN Check
902 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"))
903 self["InfoTextBorder"].show()
904 self["InfoText"].show()
905 self["ButtonRedtext"].setText(_("Back"))
906 if self.activebutton == 3: #DHCP Check
907 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."))
908 self["InfoTextBorder"].show()
909 self["InfoText"].show()
910 self["ButtonRedtext"].setText(_("Back"))
911 if self.activebutton == 4: # IP Check
912 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"))
913 self["InfoTextBorder"].show()
914 self["InfoText"].show()
915 self["ButtonRedtext"].setText(_("Back"))
916 if self.activebutton == 5: # DNS Check
917 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"))
918 self["InfoTextBorder"].show()
919 self["InfoText"].show()
920 self["ButtonRedtext"].setText(_("Back"))
921 if self.activebutton == 6: # Edit Settings
922 self.session.open(AdapterSetup,self.iface)
926 self["shortcutsgreen_restart"].setEnabled(True)
927 self["shortcutsgreen"].setEnabled(False)
928 self["shortcutsyellow"].setEnabled(False)
929 self["ButtonGreentext"].setText(_("Restart test"))
930 self["ButtonYellow_Check"].setPixmapNum(1)
931 self["ButtonGreen_Check"].setPixmapNum(0)
932 self.steptimer = False
933 self.nextStepTimer.stop()
935 def layoutFinished(self):
936 self["shortcutsyellow"].setEnabled(False)
937 self["AdapterInfo_OK"].hide()
938 self["NetworkInfo_Check"].hide()
939 self["DhcpInfo_Check"].hide()
940 self["IPInfo_Check"].hide()
941 self["DNSInfo_Check"].hide()
942 self["EditSettings_Text"].hide()
943 self["EditSettingsButton"].hide()
944 self["InfoText"].hide()
945 self["InfoTextBorder"].hide()
948 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
949 self["Adapter"] = MultiColorLabel()
950 self["AdapterInfo"] = MultiPixmap()
951 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
952 self["AdapterInfo_OK"] = Pixmap()
954 if self.iface == 'wlan0' or self.iface == 'ath0':
955 self["Networktext"] = MultiColorLabel(_("Wireless Network"))
957 self["Networktext"] = MultiColorLabel(_("Local Network"))
959 self["Network"] = MultiColorLabel()
960 self["NetworkInfo"] = MultiPixmap()
961 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
962 self["NetworkInfo_Check"] = MultiPixmap()
964 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
965 self["Dhcp"] = MultiColorLabel()
966 self["DhcpInfo"] = MultiPixmap()
967 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
968 self["DhcpInfo_Check"] = MultiPixmap()
970 self["IPtext"] = MultiColorLabel(_("IP Address"))
971 self["IP"] = MultiColorLabel()
972 self["IPInfo"] = MultiPixmap()
973 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
974 self["IPInfo_Check"] = MultiPixmap()
976 self["DNStext"] = MultiColorLabel(_("Nameserver"))
977 self["DNS"] = MultiColorLabel()
978 self["DNSInfo"] = MultiPixmap()
979 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
980 self["DNSInfo_Check"] = MultiPixmap()
982 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
983 self["EditSettingsButton"] = MultiPixmap()
985 self["ButtonRedtext"] = Label(_("Close"))
986 self["ButtonRed"] = Pixmap()
988 self["ButtonGreentext"] = Label(_("Start test"))
989 self["ButtonGreen_Check"] = MultiPixmap()
991 self["ButtonYellowtext"] = Label(_("Stop test"))
992 self["ButtonYellow_Check"] = MultiPixmap()
994 self["InfoTextBorder"] = Pixmap()
995 self["InfoText"] = Label()
997 def getLinkState(self,iface):
998 if iface == 'wlan0' or iface == 'ath0':
1000 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
1002 stats = w.getStatus()
1003 if stats['BSSID'] == "00:00:00:00:00:00":
1004 self["Network"].setForegroundColorNum(1)
1005 self["Network"].setText(_("disconnected"))
1006 self["NetworkInfo_Check"].setPixmapNum(1)
1007 self["NetworkInfo_Check"].show()
1009 self["Network"].setForegroundColorNum(2)
1010 self["Network"].setText(_("connected"))
1011 self["NetworkInfo_Check"].setPixmapNum(0)
1012 self["NetworkInfo_Check"].show()
1014 self["Network"].setForegroundColorNum(1)
1015 self["Network"].setText(_("disconnected"))
1016 self["NetworkInfo_Check"].setPixmapNum(1)
1017 self["NetworkInfo_Check"].show()
1019 iNetwork.getLinkState(iface,self.dataAvail)
1021 def dataAvail(self,data):
1022 self.output = data.strip()
1023 result = self.output.split('\n')
1024 pattern = re_compile("Link detected: yes")
1026 if re_search(pattern, item):
1027 self["Network"].setForegroundColorNum(2)
1028 self["Network"].setText(_("connected"))
1029 self["NetworkInfo_Check"].setPixmapNum(0)
1031 self["Network"].setForegroundColorNum(1)
1032 self["Network"].setText(_("disconnected"))
1033 self["NetworkInfo_Check"].setPixmapNum(1)
1034 self["NetworkInfo_Check"].show()