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)
409 if self.activateInterfaceEntry.value is False:
410 iNetwork.deactivateInterface(self.iface)
411 iNetwork.deactivateNetworkConfig()
412 iNetwork.writeNetworkConfig()
413 iNetwork.activateNetworkConfig()
417 if self.activateInterfaceEntry.value is False:
418 iNetwork.deactivateInterface(self.iface)
419 iNetwork.getInterfaces()
425 def NameserverSetupClosed(self, *ret):
426 iNetwork.loadNameserverConfig()
427 nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
428 self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
429 self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
431 self.layoutFinished()
434 class AdapterSetupConfiguration(Screen):
435 def __init__(self, session,iface):
436 Screen.__init__(self, session)
437 self.session = session
439 self.mainmenu = self.genMainMenu()
440 self["menulist"] = MenuList(self.mainmenu)
441 self["description"] = Label()
442 self["IFtext"] = Label()
444 self["BottomBG"] = Label()
445 self["Statustext"] = Label()
446 self["statuspic"] = MultiPixmap()
447 self["statuspic"].hide()
448 self["BottomBG"] = Pixmap()
449 self["ButtonRed"] = Pixmap()
450 self["ButtonRedtext"] = Label(_("Close"))
452 self.oktext = _("Press OK on your remote control to continue.")
453 self.reboottext = _("Your Dreambox will restart after pressing OK on your remote control.")
454 self.errortext = _("No working wireless interface found.\n Please verify that you have attached a compatible WLAN device or enable you local network interface.")
456 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
467 iNetwork.getInterfaces()
468 self.onLayoutFinish.append(self.layoutFinished)
469 self.updateStatusbar()
472 print "SELF.iFACE im OK Klick",self.iface
473 print "self.menulist.getCurrent()[1]",self["menulist"].getCurrent()[1]
474 if self["menulist"].getCurrent()[1] == 'edit':
475 if self.iface == 'wlan0' or self.iface == 'ath0':
477 from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
478 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
480 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
482 ifobj = Wireless(self.iface) # a Wireless NIC Object
483 self.wlanresponse = ifobj.getStatistics()
484 if self.wlanresponse[0] != 19: # Wlan Interface found.
485 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
487 # Display Wlan not available Message
488 self.showErrorMessage()
490 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
491 if self["menulist"].getCurrent()[1] == 'test':
492 self.session.open(NetworkAdapterTest,self.iface)
493 if self["menulist"].getCurrent()[1] == 'dns':
494 self.session.open(NameserverSetup)
495 if self["menulist"].getCurrent()[1] == 'scanwlan':
497 from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
498 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
500 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
502 ifobj = Wireless(self.iface) # a Wireless NIC Object
503 self.wlanresponse = ifobj.getStatistics()
504 if self.wlanresponse[0] != 19:
505 self.session.openWithCallback(self.WlanScanClosed, WlanScan, self.iface)
507 # Display Wlan not available Message
508 self.showErrorMessage()
509 if self["menulist"].getCurrent()[1] == 'wlanstatus':
511 from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
512 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
514 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
516 ifobj = Wireless(self.iface) # a Wireless NIC Object
517 self.wlanresponse = ifobj.getStatistics()
518 if self.wlanresponse[0] != 19:
519 self.session.open(WlanStatus,self.iface)
521 # Display Wlan not available Message
522 self.showErrorMessage()
523 if self["menulist"].getCurrent()[1] == 'lanrestart':
524 self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
525 if self["menulist"].getCurrent()[1] == 'openwizard':
526 from Plugins.SystemPlugins.NetworkWizard.NetworkWizard import NetworkWizard
527 self.session.openWithCallback(self.AdapterSetupClosed, NetworkWizard)
530 self["menulist"].up()
531 self.loadDescription()
534 self["menulist"].down()
535 self.loadDescription()
538 self["menulist"].pageUp()
539 self.loadDescription()
542 self["menulist"].pageDown()
543 self.loadDescription()
545 def layoutFinished(self):
547 self["menulist"].moveToIndex(idx)
548 self.loadDescription()
550 def loadDescription(self):
551 if self["menulist"].getCurrent()[1] == 'edit':
552 self["description"].setText(_("Edit the network configuration of your Dreambox.\n" ) + self.oktext )
553 if self["menulist"].getCurrent()[1] == 'test':
554 self["description"].setText(_("Test the network configuration of your Dreambox.\n" ) + self.oktext )
555 if self["menulist"].getCurrent()[1] == 'dns':
556 self["description"].setText(_("Edit the Nameserver configuration of your Dreambox.\n" ) + self.oktext )
557 if self["menulist"].getCurrent()[1] == 'scanwlan':
558 self["description"].setText(_("Scan your network for wireless Access Points and connect to them using your WLAN USB Stick\n" ) + self.oktext )
559 if self["menulist"].getCurrent()[1] == 'wlanstatus':
560 self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
561 if self["menulist"].getCurrent()[1] == 'lanrestart':
562 self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
563 if self["menulist"].getCurrent()[1] == 'openwizard':
564 self["description"].setText(_("Use the Networkwizard to configure your Network\n" ) + self.oktext )
566 def updateStatusbar(self):
567 self["IFtext"].setText(_("Network:"))
568 self["IF"].setText(iNetwork.getFriendlyAdapterName(self.iface))
569 self["Statustext"].setText(_("Link:"))
571 if self.iface == 'wlan0' or self.iface == 'ath0':
573 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
575 stats = w.getStatus()
576 if stats['BSSID'] == "00:00:00:00:00:00":
577 self["statuspic"].setPixmapNum(1)
579 self["statuspic"].setPixmapNum(0)
580 self["statuspic"].show()
582 self["statuspic"].setPixmapNum(1)
583 self["statuspic"].show()
585 self.getLinkState(self.iface)
590 def genMainMenu(self):
592 menu.append((_("Adapter settings"), "edit"))
593 menu.append((_("Nameserver settings"), "dns"))
594 menu.append((_("Network test"), "test"))
595 menu.append((_("Restart network"), "lanrestart"))
597 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
598 callFnc = p.__call__["ifaceSupported"](self.iface)
599 if callFnc is not None:
600 menu.append((_("Scan Wireless Networks"), "scanwlan"))
601 if iNetwork.getAdapterAttribute(self.iface, "up"):
602 menu.append((_("Show WLAN Status"), "wlanstatus"))
604 if os_path.exists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkWizard/networkwizard.xml")):
605 menu.append((_("NetworkWizard"), "openwizard"));
608 def AdapterSetupClosed(self, *ret):
609 self.mainmenu = self.genMainMenu()
610 self["menulist"].l.setList(self.mainmenu)
611 iNetwork.getInterfaces()
612 self.updateStatusbar()
614 def WlanScanClosed(self,*ret):
615 if ret[0] is not None:
616 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,ret[0],ret[1])
618 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,None,ret[0])
621 def restartLan(self, ret = False):
623 iNetwork.restartNetwork()
625 def getLinkState(self,iface):
626 iNetwork.getLinkState(iface,self.dataAvail)
628 def dataAvail(self,data):
629 self.output = data.strip()
630 result = self.output.split('\n')
631 pattern = re_compile("Link detected: yes")
633 if re_search(pattern, item):
634 self["statuspic"].setPixmapNum(0)
636 self["statuspic"].setPixmapNum(1)
637 self["statuspic"].show()
639 def showErrorMessage(self):
640 self.session.open(MessageBox, self.errortext, type = MessageBox.TYPE_INFO,timeout = 10 )
643 class NetworkAdapterTest(Screen):
644 def __init__(self, session,iface):
645 Screen.__init__(self, session)
647 iNetwork.getInterfaces()
650 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
654 "up": lambda: self.updownhandler('up'),
655 "down": lambda: self.updownhandler('down'),
659 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
664 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
666 "red": self.closeInfo,
667 "back": self.closeInfo,
669 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
671 "green": self.KeyGreen,
673 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
675 "green": self.KeyGreenRestart,
677 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
679 "yellow": self.KeyYellow,
682 self["shortcutsgreen_restart"].setEnabled(False)
683 self["updown_actions"].setEnabled(False)
684 self["infoshortcuts"].setEnabled(False)
685 self.onClose.append(self.delTimer)
686 self.onLayoutFinish.append(self.layoutFinished)
687 self.steptimer = False
689 self.activebutton = 0
690 self.nextStepTimer = eTimer()
691 self.nextStepTimer.callback.append(self.nextStepTimerFire)
694 self["shortcuts"].setEnabled(True)
695 self["infoshortcuts"].setEnabled(False)
696 self["InfoText"].hide()
697 self["InfoTextBorder"].hide()
698 self["ButtonRedtext"].setText(_("Close"))
702 del self.nextStepTimer
704 def nextStepTimerFire(self):
705 self.nextStepTimer.stop()
706 self.steptimer = False
709 def updownhandler(self,direction):
710 if direction == 'up':
711 if self.activebutton >=2:
712 self.activebutton -= 1
714 self.activebutton = 6
715 self.setActiveButton(self.activebutton)
716 if direction == 'down':
717 if self.activebutton <=5:
718 self.activebutton += 1
720 self.activebutton = 1
721 self.setActiveButton(self.activebutton)
723 def setActiveButton(self,button):
725 self["EditSettingsButton"].setPixmapNum(0)
726 self["EditSettings_Text"].setForegroundColorNum(0)
727 self["NetworkInfo"].setPixmapNum(0)
728 self["NetworkInfo_Text"].setForegroundColorNum(1)
729 self["AdapterInfo"].setPixmapNum(1) # active
730 self["AdapterInfo_Text"].setForegroundColorNum(2) # active
732 self["AdapterInfo_Text"].setForegroundColorNum(1)
733 self["AdapterInfo"].setPixmapNum(0)
734 self["DhcpInfo"].setPixmapNum(0)
735 self["DhcpInfo_Text"].setForegroundColorNum(1)
736 self["NetworkInfo"].setPixmapNum(1) # active
737 self["NetworkInfo_Text"].setForegroundColorNum(2) # active
739 self["NetworkInfo"].setPixmapNum(0)
740 self["NetworkInfo_Text"].setForegroundColorNum(1)
741 self["IPInfo"].setPixmapNum(0)
742 self["IPInfo_Text"].setForegroundColorNum(1)
743 self["DhcpInfo"].setPixmapNum(1) # active
744 self["DhcpInfo_Text"].setForegroundColorNum(2) # active
746 self["DhcpInfo"].setPixmapNum(0)
747 self["DhcpInfo_Text"].setForegroundColorNum(1)
748 self["DNSInfo"].setPixmapNum(0)
749 self["DNSInfo_Text"].setForegroundColorNum(1)
750 self["IPInfo"].setPixmapNum(1) # active
751 self["IPInfo_Text"].setForegroundColorNum(2) # active
753 self["IPInfo"].setPixmapNum(0)
754 self["IPInfo_Text"].setForegroundColorNum(1)
755 self["EditSettingsButton"].setPixmapNum(0)
756 self["EditSettings_Text"].setForegroundColorNum(0)
757 self["DNSInfo"].setPixmapNum(1) # active
758 self["DNSInfo_Text"].setForegroundColorNum(2) # active
760 self["DNSInfo"].setPixmapNum(0)
761 self["DNSInfo_Text"].setForegroundColorNum(1)
762 self["EditSettingsButton"].setPixmapNum(1) # active
763 self["EditSettings_Text"].setForegroundColorNum(2) # active
764 self["AdapterInfo"].setPixmapNum(0)
765 self["AdapterInfo_Text"].setForegroundColorNum(1)
784 self.steptimer = True
785 self.nextStepTimer.start(3000)
788 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
789 self["Adapter"].setForegroundColorNum(2)
790 self["Adaptertext"].setForegroundColorNum(1)
791 self["AdapterInfo_Text"].setForegroundColorNum(1)
792 self["AdapterInfo_OK"].show()
793 self.steptimer = True
794 self.nextStepTimer.start(3000)
797 self["Networktext"].setForegroundColorNum(1)
798 self.getLinkState(self.iface)
799 self["NetworkInfo_Text"].setForegroundColorNum(1)
800 self.steptimer = True
801 self.nextStepTimer.start(3000)
804 self["Dhcptext"].setForegroundColorNum(1)
805 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
806 self["Dhcp"].setForegroundColorNum(2)
807 self["Dhcp"].setText(_("enabled"))
808 self["DhcpInfo_Check"].setPixmapNum(0)
810 self["Dhcp"].setForegroundColorNum(1)
811 self["Dhcp"].setText(_("disabled"))
812 self["DhcpInfo_Check"].setPixmapNum(1)
813 self["DhcpInfo_Check"].show()
814 self["DhcpInfo_Text"].setForegroundColorNum(1)
815 self.steptimer = True
816 self.nextStepTimer.start(3000)
819 self["IPtext"].setForegroundColorNum(1)
820 ret = iNetwork.checkNetworkState()
822 self["IP"].setForegroundColorNum(2)
823 self["IP"].setText(_("confirmed"))
824 self["IPInfo_Check"].setPixmapNum(0)
826 self["IP"].setForegroundColorNum(1)
827 self["IP"].setText(_("unconfirmed"))
828 self["IPInfo_Check"].setPixmapNum(1)
829 self["IPInfo_Check"].show()
830 self["IPInfo_Text"].setForegroundColorNum(1)
831 self.steptimer = True
832 self.nextStepTimer.start(3000)
835 self.steptimer = False
836 self.nextStepTimer.stop()
837 self["DNStext"].setForegroundColorNum(1)
838 ret = iNetwork.checkDNSLookup()
840 self["DNS"].setForegroundColorNum(2)
841 self["DNS"].setText(_("confirmed"))
842 self["DNSInfo_Check"].setPixmapNum(0)
844 self["DNS"].setForegroundColorNum(1)
845 self["DNS"].setText(_("unconfirmed"))
846 self["DNSInfo_Check"].setPixmapNum(1)
847 self["DNSInfo_Check"].show()
848 self["DNSInfo_Text"].setForegroundColorNum(1)
850 self["EditSettings_Text"].show()
851 self["EditSettingsButton"].setPixmapNum(1)
852 self["EditSettings_Text"].setForegroundColorNum(2) # active
853 self["EditSettingsButton"].show()
854 self["ButtonYellow_Check"].setPixmapNum(1)
855 self["ButtonGreentext"].setText(_("Restart test"))
856 self["ButtonGreen_Check"].setPixmapNum(0)
857 self["shortcutsgreen"].setEnabled(False)
858 self["shortcutsgreen_restart"].setEnabled(True)
859 self["shortcutsyellow"].setEnabled(False)
860 self["updown_actions"].setEnabled(True)
861 self.activebutton = 6
864 self["shortcutsgreen"].setEnabled(False)
865 self["shortcutsyellow"].setEnabled(True)
866 self["updown_actions"].setEnabled(False)
867 self["ButtonYellow_Check"].setPixmapNum(0)
868 self["ButtonGreen_Check"].setPixmapNum(1)
869 self.steptimer = True
870 self.nextStepTimer.start(1000)
872 def KeyGreenRestart(self):
874 self.layoutFinished()
875 self["Adapter"].setText((""))
876 self["Network"].setText((""))
877 self["Dhcp"].setText((""))
878 self["IP"].setText((""))
879 self["DNS"].setText((""))
880 self["AdapterInfo_Text"].setForegroundColorNum(0)
881 self["NetworkInfo_Text"].setForegroundColorNum(0)
882 self["DhcpInfo_Text"].setForegroundColorNum(0)
883 self["IPInfo_Text"].setForegroundColorNum(0)
884 self["DNSInfo_Text"].setForegroundColorNum(0)
885 self["shortcutsgreen_restart"].setEnabled(False)
886 self["shortcutsgreen"].setEnabled(False)
887 self["shortcutsyellow"].setEnabled(True)
888 self["updown_actions"].setEnabled(False)
889 self["ButtonYellow_Check"].setPixmapNum(0)
890 self["ButtonGreen_Check"].setPixmapNum(1)
891 self.steptimer = True
892 self.nextStepTimer.start(1000)
895 self["infoshortcuts"].setEnabled(True)
896 self["shortcuts"].setEnabled(False)
897 if self.activebutton == 1: # Adapter Check
898 self["InfoText"].setText(_("This test detects your configured LAN-Adapter."))
899 self["InfoTextBorder"].show()
900 self["InfoText"].show()
901 self["ButtonRedtext"].setText(_("Back"))
902 if self.activebutton == 2: #LAN Check
903 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"))
904 self["InfoTextBorder"].show()
905 self["InfoText"].show()
906 self["ButtonRedtext"].setText(_("Back"))
907 if self.activebutton == 3: #DHCP Check
908 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."))
909 self["InfoTextBorder"].show()
910 self["InfoText"].show()
911 self["ButtonRedtext"].setText(_("Back"))
912 if self.activebutton == 4: # IP Check
913 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"))
914 self["InfoTextBorder"].show()
915 self["InfoText"].show()
916 self["ButtonRedtext"].setText(_("Back"))
917 if self.activebutton == 5: # DNS Check
918 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"))
919 self["InfoTextBorder"].show()
920 self["InfoText"].show()
921 self["ButtonRedtext"].setText(_("Back"))
922 if self.activebutton == 6: # Edit Settings
923 self.session.open(AdapterSetup,self.iface)
927 self["shortcutsgreen_restart"].setEnabled(True)
928 self["shortcutsgreen"].setEnabled(False)
929 self["shortcutsyellow"].setEnabled(False)
930 self["ButtonGreentext"].setText(_("Restart test"))
931 self["ButtonYellow_Check"].setPixmapNum(1)
932 self["ButtonGreen_Check"].setPixmapNum(0)
933 self.steptimer = False
934 self.nextStepTimer.stop()
936 def layoutFinished(self):
937 self["shortcutsyellow"].setEnabled(False)
938 self["AdapterInfo_OK"].hide()
939 self["NetworkInfo_Check"].hide()
940 self["DhcpInfo_Check"].hide()
941 self["IPInfo_Check"].hide()
942 self["DNSInfo_Check"].hide()
943 self["EditSettings_Text"].hide()
944 self["EditSettingsButton"].hide()
945 self["InfoText"].hide()
946 self["InfoTextBorder"].hide()
949 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
950 self["Adapter"] = MultiColorLabel()
951 self["AdapterInfo"] = MultiPixmap()
952 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
953 self["AdapterInfo_OK"] = Pixmap()
955 if self.iface == 'wlan0' or self.iface == 'ath0':
956 self["Networktext"] = MultiColorLabel(_("Wireless Network"))
958 self["Networktext"] = MultiColorLabel(_("Local Network"))
960 self["Network"] = MultiColorLabel()
961 self["NetworkInfo"] = MultiPixmap()
962 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
963 self["NetworkInfo_Check"] = MultiPixmap()
965 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
966 self["Dhcp"] = MultiColorLabel()
967 self["DhcpInfo"] = MultiPixmap()
968 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
969 self["DhcpInfo_Check"] = MultiPixmap()
971 self["IPtext"] = MultiColorLabel(_("IP Address"))
972 self["IP"] = MultiColorLabel()
973 self["IPInfo"] = MultiPixmap()
974 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
975 self["IPInfo_Check"] = MultiPixmap()
977 self["DNStext"] = MultiColorLabel(_("Nameserver"))
978 self["DNS"] = MultiColorLabel()
979 self["DNSInfo"] = MultiPixmap()
980 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
981 self["DNSInfo_Check"] = MultiPixmap()
983 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
984 self["EditSettingsButton"] = MultiPixmap()
986 self["ButtonRedtext"] = Label(_("Close"))
987 self["ButtonRed"] = Pixmap()
989 self["ButtonGreentext"] = Label(_("Start test"))
990 self["ButtonGreen_Check"] = MultiPixmap()
992 self["ButtonYellowtext"] = Label(_("Stop test"))
993 self["ButtonYellow_Check"] = MultiPixmap()
995 self["InfoTextBorder"] = Pixmap()
996 self["InfoText"] = Label()
998 def getLinkState(self,iface):
999 if iface == 'wlan0' or iface == 'ath0':
1001 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
1003 stats = w.getStatus()
1004 if stats['BSSID'] == "00:00:00:00:00:00":
1005 self["Network"].setForegroundColorNum(1)
1006 self["Network"].setText(_("disconnected"))
1007 self["NetworkInfo_Check"].setPixmapNum(1)
1008 self["NetworkInfo_Check"].show()
1010 self["Network"].setForegroundColorNum(2)
1011 self["Network"].setText(_("connected"))
1012 self["NetworkInfo_Check"].setPixmapNum(0)
1013 self["NetworkInfo_Check"].show()
1015 self["Network"].setForegroundColorNum(1)
1016 self["Network"].setText(_("disconnected"))
1017 self["NetworkInfo_Check"].setPixmapNum(1)
1018 self["NetworkInfo_Check"].show()
1020 iNetwork.getLinkState(iface,self.dataAvail)
1022 def dataAvail(self,data):
1023 self.output = data.strip()
1024 result = self.output.split('\n')
1025 pattern = re_compile("Link detected: yes")
1027 if re_search(pattern, item):
1028 self["Network"].setForegroundColorNum(2)
1029 self["Network"].setText(_("connected"))
1030 self["NetworkInfo_Check"].setPixmapNum(0)
1032 self["Network"].setForegroundColorNum(1)
1033 self["Network"].setText(_("disconnected"))
1034 self["NetworkInfo_Check"].setPixmapNum(1)
1035 self["NetworkInfo_Check"].show()