1 from Screen import Screen
2 from Components.ActionMap import ActionMap,NumberActionMap
3 from Screens.MessageBox import MessageBox
4 from Screens.InputBox import InputBox
5 from Screens.Standby import *
6 from Components.Network import iNetwork
7 from Components.Label import Label,MultiColorLabel
8 from Components.Pixmap import Pixmap,MultiPixmap
9 from Components.MenuList import MenuList
10 from Components.config import config, ConfigYesNo, ConfigIP, NoSave, ConfigText, ConfigSelection, getConfigListEntry, ConfigNothing
11 from Components.ConfigList import ConfigListScreen
12 from Components.PluginComponent import plugins
13 from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest
14 from Plugins.Plugin import PluginDescriptor
15 from enigma import eTimer
16 from os import path as os_path, system as os_system, unlink
17 from re import compile as re_compile, search as re_search
18 from Tools.Directories import resolveFilename, SCOPE_PLUGINS
20 from Tools.Directories import SCOPE_SKIN_IMAGE,SCOPE_PLUGINS, resolveFilename
21 from Tools.LoadPixmap import LoadPixmap
22 from enigma import RT_HALIGN_LEFT, eListboxPythonMultiContent, gFont
24 class InterfaceList(MenuList):
25 def __init__(self, list, enableWrapAround=False):
26 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
27 self.l.setFont(0, gFont("Regular", 20))
28 self.l.setItemHeight(30)
30 def InterfaceEntryComponent(index,name,default,active ):
32 res.append(MultiContentEntryText(pos=(80, 5), size=(430, 25), font=0, text=name))
34 png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/buttons/button_blue.png"))
36 png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/buttons/button_blue_off.png"))
37 res.append(MultiContentEntryPixmapAlphaTest(pos=(10, 5), size=(25, 25), png = png))
39 png2 = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lock_on.png"))
41 png2 = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lock_error.png"))
42 res.append(MultiContentEntryPixmapAlphaTest(pos=(40, 1), size=(25, 25), png = png2))
46 class NetworkAdapterSelection(Screen):
47 def __init__(self, session):
48 Screen.__init__(self, session)
50 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.")
51 self.lan_errortext = _("No working local networkadapter found.\nPlease verify that you have attached a network cable and your Network is configured correctly.")
53 self["ButtonBluetext"] = Label(_("Set as default Interface"))
54 self["ButtonRedtext"] = Label(_("Close"))
55 self["introduction"] = Label(_("Press OK to edit the settings."))
57 self.adapters = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
59 if len(self.adapters) == 0:
60 self.onFirstExecBegin.append(self.NetworkFallback)
63 self["list"] = InterfaceList(self.list)
65 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
67 "ok": self.okbuttonClick,
69 "blue": self.setDefaultInterface,
73 if len(self.adapters) == 1:
74 self.onFirstExecBegin.append(self.okbuttonClick)
77 iNetwork.getInterfaces()
80 num_configured_if = len(iNetwork.configuredInterfaces)
81 if num_configured_if < 2 and os_path.exists("/etc/default_gw"):
82 unlink("/etc/default_gw")
84 if os_path.exists("/etc/default_gw"):
85 fp = file('/etc/default_gw', 'r')
90 if len(self.adapters) == 0: # no interface available => display only eth0
91 self.list.append(InterfaceEntryComponent("eth0",iNetwork.getFriendlyAdapterName('eth0'),True,True ))
93 for x in self.adapters:
94 if x[1] == default_gw:
98 if iNetwork.getAdapterAttribute(x[1], 'up') is True:
102 self.list.append(InterfaceEntryComponent(index = x[1],name = _(x[0]),default=default_int,active=active_int ))
103 self["list"].l.setList(self.list)
105 def setDefaultInterface(self):
106 selection = self["list"].getCurrent()
107 num_if = len(self.list)
108 old_default_gw = None
109 if os_path.exists("/etc/default_gw"):
110 fp = open('/etc/default_gw', 'r')
111 old_default_gw = fp.read()
113 if num_if > 1 and (not old_default_gw or old_default_gw != selection[0]):
114 fp = open('/etc/default_gw', 'w+')
115 fp.write(selection[0])
117 iNetwork.restartNetwork()
119 elif old_default_gw and num_if < 2:
120 unlink("/etc/default_gw")
121 iNetwork.restartNetwork()
124 def okbuttonClick(self):
125 selection = self["list"].getCurrent()
126 print "selection",selection
127 if selection is not None:
128 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, selection[0])
130 def AdapterSetupClosed(self, *ret):
131 if len(self.adapters) == 1:
136 def NetworkFallback(self):
137 if iNetwork.configuredInterfaces.has_key('wlan0') is True:
138 self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.wlan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
139 if iNetwork.configuredInterfaces.has_key('ath0') is True:
140 self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.wlan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
142 self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.lan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
144 def ErrorMessageClosed(self, *ret):
145 if iNetwork.configuredInterfaces.has_key('wlan0') is True:
146 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'wlan0')
147 elif iNetwork.configuredInterfaces.has_key('ath0') is True:
148 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'ath0')
150 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'eth0')
152 class NameserverSetup(Screen, ConfigListScreen):
153 def __init__(self, session):
154 Screen.__init__(self, session)
155 iNetwork.getInterfaces()
156 self.backupNameserverList = iNetwork.getNameserverList()[:]
157 print "backup-list:", self.backupNameserverList
159 self["ButtonGreentext"] = Label(_("Add"))
160 self["ButtonYellowtext"] = Label(_("Delete"))
161 self["ButtonRedtext"] = Label(_("Close"))
162 self["introduction"] = Label(_("Press OK to activate the settings."))
165 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
168 "cancel": self.cancel,
171 "yellow": self.remove
175 ConfigListScreen.__init__(self, self.list)
178 def createConfig(self):
179 self.nameservers = iNetwork.getNameserverList()
180 self.nameserverEntries = []
182 for nameserver in self.nameservers:
183 self.nameserverEntries.append(NoSave(ConfigIP(default=nameserver)))
185 def createSetup(self):
188 for i in range(len(self.nameserverEntries)):
189 self.list.append(getConfigListEntry(_("Nameserver %d") % (i + 1), self.nameserverEntries[i]))
191 self["config"].list = self.list
192 self["config"].l.setList(self.list)
195 iNetwork.clearNameservers()
196 for nameserver in self.nameserverEntries:
197 iNetwork.addNameserver(nameserver.value)
198 iNetwork.writeNameserverConfig()
205 iNetwork.clearNameservers()
206 print "backup-list:", self.backupNameserverList
207 for nameserver in self.backupNameserverList:
208 iNetwork.addNameserver(nameserver)
212 iNetwork.addNameserver([0,0,0,0])
217 print "currentIndex:", self["config"].getCurrentIndex()
219 index = self["config"].getCurrentIndex()
220 if index < len(self.nameservers):
221 iNetwork.removeNameserver(self.nameservers[index])
225 class AdapterSetup(Screen, ConfigListScreen):
226 def __init__(self, session, iface,essid=None, aplist=None):
227 Screen.__init__(self, session)
228 self.session = session
233 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
234 iNetwork.getInterfaces()
238 self["actions"] = NumberActionMap(["SetupActions", "ColorActions"],
241 "cancel": self.cancel,
243 "blue": self.KeyBlue,
247 ConfigListScreen.__init__(self, self.list,session = self.session)
249 self.onLayoutFinish.append(self.layoutFinished)
251 self["DNS1text"] = Label(_("Primary DNS"))
252 self["DNS2text"] = Label(_("Secondary DNS"))
253 self["DNS1"] = Label()
254 self["DNS2"] = Label()
256 self["introduction"] = Label(_("Current settings:"))
258 self["IPtext"] = Label(_("IP Address"))
259 self["Netmasktext"] = Label(_("Netmask"))
260 self["Gatewaytext"] = Label(_("Gateway"))
263 self["Mask"] = Label()
264 self["Gateway"] = Label()
266 self["BottomBG"] = Pixmap()
267 self["Adaptertext"] = Label(_("Network:"))
268 self["Adapter"] = Label()
269 self["introduction2"] = Label(_("Press OK to activate the settings."))
270 self["ButtonRed"] = Pixmap()
271 self["ButtonRedtext"] = Label(_("Close"))
272 self["ButtonBlue"] = Pixmap()
273 self["ButtonBluetext"] = Label(_("Edit DNS"))
275 def layoutFinished(self):
276 self["DNS1"].setText(self.primaryDNS.getText())
277 self["DNS2"].setText(self.secondaryDNS.getText())
278 if self.ipConfigEntry.getText() is not None:
279 self["IP"].setText(self.ipConfigEntry.getText())
281 self["IP"].setText([0,0,0,0])
282 self["Mask"].setText(self.netmaskConfigEntry.getText())
283 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
284 self["Gateway"].setText(self.gatewayConfigEntry.getText())
286 self["Gateway"].hide()
287 self["Gatewaytext"].hide()
288 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
290 def createConfig(self):
291 self.InterfaceEntry = None
292 self.dhcpEntry = None
293 self.gatewayEntry = None
296 self.manualwlanSSID = None
297 self.encryptionEnabled = None
298 self.encryptionKey = None
303 if self.iface == "wlan0" or self.iface == "ath0" :
304 from Plugins.SystemPlugins.WirelessLan.Wlan import wpaSupplicant,Wlan
305 self.ws = wpaSupplicant()
307 list.append(_("WEP"))
308 list.append(_("WPA"))
309 list.append(_("WPA2"))
310 if self.aplist is not None:
311 self.nwlist = self.aplist
312 self.nwlist.sort(key = lambda x: x[0])
318 self.w = Wlan(self.iface)
319 self.aps = self.w.getNetworkList()
320 if self.aps is not None:
321 print "[NetworkSetup.py] got Accespoints!"
326 a['essid'] = a['bssid']
327 self.nwlist.append( a['essid'])
328 self.nwlist.sort(key = lambda x: x[0])
330 self.nwlist.append("No Networks found")
332 self.wsconfig = self.ws.loadConfig()
333 self.default = self.essid or self.wsconfig['ssid']
334 if self.default not in self.nwlist:
335 self.nwlist.append(self.default)
336 config.plugins.wlan.essidscan = NoSave(ConfigYesNo(default = self.wsconfig['ssidscan']))
337 if self.wsconfig['ssidscan'] is True:
338 config.plugins.wlan.essid = NoSave(ConfigSelection(self.nwlist, default = self.default ))
340 config.plugins.wlan.essid = NoSave(ConfigText(default = self.default, visible_width = 50, fixed_size = False))
341 config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = self.wsconfig['encryption'] ))
342 config.plugins.wlan.encryption.type = NoSave(ConfigSelection(list, default = self.wsconfig['encryption_type'] ))
343 config.plugins.wlan.encryption.psk = NoSave(ConfigText(default = self.wsconfig['key'], visible_width = 50, fixed_size = False))
345 self.activateInterfaceEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "up") or False))
346 self.dhcpConfigEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "dhcp") or False))
347 self.ipConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0])
348 self.netmaskConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0]))
349 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
350 self.dhcpdefault=True
352 self.dhcpdefault=False
353 self.hasGatewayConfigEntry = NoSave(ConfigYesNo(default=self.dhcpdefault or False))
354 self.gatewayConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0]))
355 nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
356 self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
357 self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
359 def createSetup(self):
361 self.InterfaceEntry = getConfigListEntry(_("Use Interface"), self.activateInterfaceEntry)
363 self.list.append(self.InterfaceEntry)
364 if self.activateInterfaceEntry.value:
365 self.dhcpEntry = getConfigListEntry(_("Use DHCP"), self.dhcpConfigEntry)
366 self.list.append(self.dhcpEntry)
367 if not self.dhcpConfigEntry.value:
368 self.list.append(getConfigListEntry(_('IP Address'), self.ipConfigEntry))
369 self.list.append(getConfigListEntry(_('Netmask'), self.netmaskConfigEntry))
370 self.gatewayEntry = getConfigListEntry(_('Use a gateway'), self.hasGatewayConfigEntry)
371 self.list.append(self.gatewayEntry)
372 if self.hasGatewayConfigEntry.value:
373 self.list.append(getConfigListEntry(_('Gateway'), self.gatewayConfigEntry))
376 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
377 callFnc = p.__call__["ifaceSupported"](self.iface)
378 if callFnc is not None:
379 if p.__call__.has_key("WlanPluginEntry"): # internally used only for WLAN Plugin
380 self.extended = callFnc
381 if p.__call__.has_key("configStrings"):
382 self.configStrings = p.__call__["configStrings"]
384 self.configStrings = None
385 self.SSIDscan = getConfigListEntry(_("Automatic SSID lookup"), config.plugins.wlan.essidscan)
386 self.list.append(self.SSIDscan)
387 self.wlanSSID = getConfigListEntry(_("Network SSID"), config.plugins.wlan.essid)
388 self.list.append(self.wlanSSID)
389 self.encryptionEnabled = getConfigListEntry(_("Encryption"), config.plugins.wlan.encryption.enabled)
390 self.list.append(self.encryptionEnabled)
392 if config.plugins.wlan.encryption.enabled.value:
393 self.list.append(getConfigListEntry(_("Encryption Type"), config.plugins.wlan.encryption.type))
394 self.encryptionKey = getConfigListEntry(_("Encryption Key"), config.plugins.wlan.encryption.psk)
395 self.list.append(self.encryptionKey)
397 self["config"].list = self.list
398 self["config"].l.setList(self.list)
401 self.session.openWithCallback(self.NameserverSetupClosed, NameserverSetup)
404 print self["config"].getCurrent()
405 if self["config"].getCurrent() == self.InterfaceEntry:
407 if self["config"].getCurrent() == self.dhcpEntry:
409 if self["config"].getCurrent() == self.gatewayEntry:
411 if self.iface == "wlan0" or self.iface == "ath0" :
412 if self["config"].getCurrent() == self.SSIDscan:
413 if config.plugins.wlan.essidscan.value is True:
414 config.plugins.wlan.essid = NoSave(ConfigSelection(self.nwlist, default = self.default ))
416 config.plugins.wlan.essid = NoSave(ConfigText(default = self.default, visible_width = 50, fixed_size = False))
418 if self["config"].getCurrent() == self.encryptionEnabled:
422 ConfigListScreen.keyLeft(self)
426 ConfigListScreen.keyRight(self)
430 iNetwork.setAdapterAttribute(self.iface, "up", self.activateInterfaceEntry.value)
431 iNetwork.setAdapterAttribute(self.iface, "dhcp", self.dhcpConfigEntry.value)
432 iNetwork.setAdapterAttribute(self.iface, "ip", self.ipConfigEntry.value)
433 iNetwork.setAdapterAttribute(self.iface, "netmask", self.netmaskConfigEntry.value)
434 if self.hasGatewayConfigEntry.value:
435 iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value)
437 iNetwork.removeAdapterAttribute(self.iface, "gateway")
438 if self.extended is not None and self.configStrings is not None:
439 iNetwork.setAdapterAttribute(self.iface, "configStrings", self.configStrings(self.iface))
440 self.ws.writeConfig()
441 if self.activateInterfaceEntry.value is False:
442 iNetwork.deactivateInterface(self.iface)
443 iNetwork.writeNetworkConfig()
444 iNetwork.deactivateNetworkConfig()
445 iNetwork.activateNetworkConfig()
449 iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
450 self.activateInterfaceEntry.value = self.oldInterfaceState
451 if self.activateInterfaceEntry.value is False:
452 iNetwork.deactivateInterface(self.iface)
453 iNetwork.getInterfaces()
459 def NameserverSetupClosed(self, *ret):
460 iNetwork.loadNameserverConfig()
461 nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
462 self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
463 self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
465 self.layoutFinished()
468 class AdapterSetupConfiguration(Screen):
469 def __init__(self, session,iface):
470 Screen.__init__(self, session)
471 self.session = session
473 self.mainmenu = self.genMainMenu()
474 self["menulist"] = MenuList(self.mainmenu)
475 self["description"] = Label()
476 self["IFtext"] = Label()
478 self["BottomBG"] = Label()
479 self["Statustext"] = Label()
480 self["statuspic"] = MultiPixmap()
481 self["statuspic"].hide()
482 self["BottomBG"] = Pixmap()
483 self["ButtonRed"] = Pixmap()
484 self["ButtonRedtext"] = Label(_("Close"))
486 self.oktext = _("Press OK on your remote control to continue.")
487 self.reboottext = _("Your Dreambox will restart after pressing OK on your remote control.")
488 self.errortext = _("No working wireless interface found.\n Please verify that you have attached a compatible WLAN device or enable your local network interface.")
490 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
501 iNetwork.getInterfaces()
502 self.onLayoutFinish.append(self.layoutFinished)
503 self.updateStatusbar()
506 if self["menulist"].getCurrent()[1] == 'edit':
507 if self.iface == 'wlan0' or self.iface == 'ath0':
509 from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
510 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
512 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
514 ifobj = Wireless(self.iface) # a Wireless NIC Object
515 self.wlanresponse = ifobj.getStatistics()
516 if self.wlanresponse[0] != 19: # Wlan Interface found.
517 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
519 # Display Wlan not available Message
520 self.showErrorMessage()
522 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
523 if self["menulist"].getCurrent()[1] == 'test':
524 self.session.open(NetworkAdapterTest,self.iface)
525 if self["menulist"].getCurrent()[1] == 'dns':
526 self.session.open(NameserverSetup)
527 if self["menulist"].getCurrent()[1] == 'scanwlan':
529 from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
530 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
532 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
534 ifobj = Wireless(self.iface) # a Wireless NIC Object
535 self.wlanresponse = ifobj.getStatistics()
536 if self.wlanresponse[0] != 19:
537 self.session.openWithCallback(self.WlanScanClosed, WlanScan, self.iface)
539 # Display Wlan not available Message
540 self.showErrorMessage()
541 if self["menulist"].getCurrent()[1] == 'wlanstatus':
543 from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
544 from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
546 self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
548 ifobj = Wireless(self.iface) # a Wireless NIC Object
549 self.wlanresponse = ifobj.getStatistics()
550 if self.wlanresponse[0] != 19:
551 self.session.openWithCallback(self.AdapterSetupClosed, WlanStatus,self.iface)
552 #self.session.open(WlanStatus,self.iface)
554 # Display Wlan not available Message
555 self.showErrorMessage()
556 if self["menulist"].getCurrent()[1] == 'lanrestart':
557 self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
558 if self["menulist"].getCurrent()[1] == 'openwizard':
559 from Plugins.SystemPlugins.NetworkWizard.NetworkWizard import NetworkWizard
560 self.session.openWithCallback(self.AdapterSetupClosed, NetworkWizard)
561 if self["menulist"].getCurrent()[1][0] == 'extendedSetup':
562 self.extended = self["menulist"].getCurrent()[1][2]
563 self.extended(self.session, self.iface)
566 self["menulist"].up()
567 self.loadDescription()
570 self["menulist"].down()
571 self.loadDescription()
574 self["menulist"].pageUp()
575 self.loadDescription()
578 self["menulist"].pageDown()
579 self.loadDescription()
581 def layoutFinished(self):
583 self["menulist"].moveToIndex(idx)
584 self.loadDescription()
586 def loadDescription(self):
587 if self["menulist"].getCurrent()[1] == 'edit':
588 self["description"].setText(_("Edit the network configuration of your Dreambox.\n" ) + self.oktext )
589 if self["menulist"].getCurrent()[1] == 'test':
590 self["description"].setText(_("Test the network configuration of your Dreambox.\n" ) + self.oktext )
591 if self["menulist"].getCurrent()[1] == 'dns':
592 self["description"].setText(_("Edit the Nameserver configuration of your Dreambox.\n" ) + self.oktext )
593 if self["menulist"].getCurrent()[1] == 'scanwlan':
594 self["description"].setText(_("Scan your network for wireless Access Points and connect to them using your WLAN USB Stick\n" ) + self.oktext )
595 if self["menulist"].getCurrent()[1] == 'wlanstatus':
596 self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
597 if self["menulist"].getCurrent()[1] == 'lanrestart':
598 self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
599 if self["menulist"].getCurrent()[1] == 'openwizard':
600 self["description"].setText(_("Use the Networkwizard to configure your Network\n" ) + self.oktext )
601 if self["menulist"].getCurrent()[1][0] == 'extendedSetup':
602 self["description"].setText(_(self["menulist"].getCurrent()[1][1]) + self.oktext )
604 def updateStatusbar(self):
605 self["IFtext"].setText(_("Network:"))
606 self["IF"].setText(iNetwork.getFriendlyAdapterName(self.iface))
607 self["Statustext"].setText(_("Link:"))
609 if self.iface == 'wlan0' or self.iface == 'ath0':
611 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
613 stats = w.getStatus()
614 if stats['BSSID'] == "00:00:00:00:00:00":
615 self["statuspic"].setPixmapNum(1)
617 self["statuspic"].setPixmapNum(0)
618 self["statuspic"].show()
620 self["statuspic"].setPixmapNum(1)
621 self["statuspic"].show()
623 self.getLinkState(self.iface)
628 def genMainMenu(self):
630 menu.append((_("Adapter settings"), "edit"))
631 menu.append((_("Nameserver settings"), "dns"))
632 menu.append((_("Network test"), "test"))
633 menu.append((_("Restart network"), "lanrestart"))
636 self.extendedSetup = None
637 for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
638 callFnc = p.__call__["ifaceSupported"](self.iface)
639 if callFnc is not None:
640 self.extended = callFnc
642 if p.__call__.has_key("WlanPluginEntry"): # internally used only for WLAN Plugin
643 menu.append((_("Scan Wireless Networks"), "scanwlan"))
644 if iNetwork.getAdapterAttribute(self.iface, "up"):
645 menu.append((_("Show WLAN Status"), "wlanstatus"))
647 if p.__call__.has_key("menuEntryName"):
648 menuEntryName = p.__call__["menuEntryName"](self.iface)
650 menuEntryName = _('Extended Setup...')
651 if p.__call__.has_key("menuEntryDescription"):
652 menuEntryDescription = p.__call__["menuEntryDescription"](self.iface)
654 menuEntryDescription = _('Extended Networksetup Plugin...')
655 self.extendedSetup = ('extendedSetup',menuEntryDescription, self.extended)
656 menu.append((menuEntryName,self.extendedSetup))
658 if os_path.exists(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkWizard/networkwizard.xml")):
659 menu.append((_("NetworkWizard"), "openwizard"))
663 def AdapterSetupClosed(self, *ret):
664 self.mainmenu = self.genMainMenu()
665 self["menulist"].l.setList(self.mainmenu)
666 iNetwork.getInterfaces()
667 self.updateStatusbar()
669 def WlanScanClosed(self,*ret):
670 if ret[0] is not None:
671 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,ret[0],ret[1])
673 self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,None,ret[0])
676 def restartLan(self, ret = False):
678 iNetwork.restartNetwork()
680 def getLinkState(self,iface):
681 iNetwork.getLinkState(iface,self.dataAvail)
683 def dataAvail(self,data):
684 self.output = data.strip()
685 result = self.output.split('\n')
686 pattern = re_compile("Link detected: yes")
688 if re_search(pattern, item):
689 self["statuspic"].setPixmapNum(0)
691 self["statuspic"].setPixmapNum(1)
692 self["statuspic"].show()
694 def showErrorMessage(self):
695 self.session.open(MessageBox, self.errortext, type = MessageBox.TYPE_INFO,timeout = 10 )
698 class NetworkAdapterTest(Screen):
699 def __init__(self, session,iface):
700 Screen.__init__(self, session)
702 iNetwork.getInterfaces()
705 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
709 "up": lambda: self.updownhandler('up'),
710 "down": lambda: self.updownhandler('down'),
714 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
719 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
721 "red": self.closeInfo,
722 "back": self.closeInfo,
724 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
726 "green": self.KeyGreen,
728 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
730 "green": self.KeyGreenRestart,
732 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
734 "yellow": self.KeyYellow,
737 self["shortcutsgreen_restart"].setEnabled(False)
738 self["updown_actions"].setEnabled(False)
739 self["infoshortcuts"].setEnabled(False)
740 self.onClose.append(self.delTimer)
741 self.onLayoutFinish.append(self.layoutFinished)
742 self.steptimer = False
744 self.activebutton = 0
745 self.nextStepTimer = eTimer()
746 self.nextStepTimer.callback.append(self.nextStepTimerFire)
749 self["shortcuts"].setEnabled(True)
750 self["infoshortcuts"].setEnabled(False)
751 self["InfoText"].hide()
752 self["InfoTextBorder"].hide()
753 self["ButtonRedtext"].setText(_("Close"))
757 del self.nextStepTimer
759 def nextStepTimerFire(self):
760 self.nextStepTimer.stop()
761 self.steptimer = False
764 def updownhandler(self,direction):
765 if direction == 'up':
766 if self.activebutton >=2:
767 self.activebutton -= 1
769 self.activebutton = 6
770 self.setActiveButton(self.activebutton)
771 if direction == 'down':
772 if self.activebutton <=5:
773 self.activebutton += 1
775 self.activebutton = 1
776 self.setActiveButton(self.activebutton)
778 def setActiveButton(self,button):
780 self["EditSettingsButton"].setPixmapNum(0)
781 self["EditSettings_Text"].setForegroundColorNum(0)
782 self["NetworkInfo"].setPixmapNum(0)
783 self["NetworkInfo_Text"].setForegroundColorNum(1)
784 self["AdapterInfo"].setPixmapNum(1) # active
785 self["AdapterInfo_Text"].setForegroundColorNum(2) # active
787 self["AdapterInfo_Text"].setForegroundColorNum(1)
788 self["AdapterInfo"].setPixmapNum(0)
789 self["DhcpInfo"].setPixmapNum(0)
790 self["DhcpInfo_Text"].setForegroundColorNum(1)
791 self["NetworkInfo"].setPixmapNum(1) # active
792 self["NetworkInfo_Text"].setForegroundColorNum(2) # active
794 self["NetworkInfo"].setPixmapNum(0)
795 self["NetworkInfo_Text"].setForegroundColorNum(1)
796 self["IPInfo"].setPixmapNum(0)
797 self["IPInfo_Text"].setForegroundColorNum(1)
798 self["DhcpInfo"].setPixmapNum(1) # active
799 self["DhcpInfo_Text"].setForegroundColorNum(2) # active
801 self["DhcpInfo"].setPixmapNum(0)
802 self["DhcpInfo_Text"].setForegroundColorNum(1)
803 self["DNSInfo"].setPixmapNum(0)
804 self["DNSInfo_Text"].setForegroundColorNum(1)
805 self["IPInfo"].setPixmapNum(1) # active
806 self["IPInfo_Text"].setForegroundColorNum(2) # active
808 self["IPInfo"].setPixmapNum(0)
809 self["IPInfo_Text"].setForegroundColorNum(1)
810 self["EditSettingsButton"].setPixmapNum(0)
811 self["EditSettings_Text"].setForegroundColorNum(0)
812 self["DNSInfo"].setPixmapNum(1) # active
813 self["DNSInfo_Text"].setForegroundColorNum(2) # active
815 self["DNSInfo"].setPixmapNum(0)
816 self["DNSInfo_Text"].setForegroundColorNum(1)
817 self["EditSettingsButton"].setPixmapNum(1) # active
818 self["EditSettings_Text"].setForegroundColorNum(2) # active
819 self["AdapterInfo"].setPixmapNum(0)
820 self["AdapterInfo_Text"].setForegroundColorNum(1)
839 self.steptimer = True
840 self.nextStepTimer.start(3000)
841 self["ButtonYellow_Check"].show()
842 self["ButtonYellowtext"].show()
845 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
846 self["Adapter"].setForegroundColorNum(2)
847 self["Adaptertext"].setForegroundColorNum(1)
848 self["AdapterInfo_Text"].setForegroundColorNum(1)
849 self["AdapterInfo_OK"].show()
850 self.steptimer = True
851 self.nextStepTimer.start(3000)
854 self["Networktext"].setForegroundColorNum(1)
855 self.getLinkState(self.iface)
856 self["NetworkInfo_Text"].setForegroundColorNum(1)
857 self.steptimer = True
858 self.nextStepTimer.start(3000)
861 self["Dhcptext"].setForegroundColorNum(1)
862 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
863 self["Dhcp"].setForegroundColorNum(2)
864 self["Dhcp"].setText(_("enabled"))
865 self["DhcpInfo_Check"].setPixmapNum(0)
867 self["Dhcp"].setForegroundColorNum(1)
868 self["Dhcp"].setText(_("disabled"))
869 self["DhcpInfo_Check"].setPixmapNum(1)
870 self["DhcpInfo_Check"].show()
871 self["DhcpInfo_Text"].setForegroundColorNum(1)
872 self.steptimer = True
873 self.nextStepTimer.start(3000)
876 self["IPtext"].setForegroundColorNum(1)
877 ret = iNetwork.checkNetworkState()
879 self["IP"].setForegroundColorNum(2)
880 self["IP"].setText(_("confirmed"))
881 self["IPInfo_Check"].setPixmapNum(0)
883 self["IP"].setForegroundColorNum(1)
884 self["IP"].setText(_("unconfirmed"))
885 self["IPInfo_Check"].setPixmapNum(1)
886 self["IPInfo_Check"].show()
887 self["IPInfo_Text"].setForegroundColorNum(1)
888 self.steptimer = True
889 self.nextStepTimer.start(3000)
892 self.steptimer = False
893 self.nextStepTimer.stop()
894 self["DNStext"].setForegroundColorNum(1)
895 ret = iNetwork.checkDNSLookup()
897 self["DNS"].setForegroundColorNum(2)
898 self["DNS"].setText(_("confirmed"))
899 self["DNSInfo_Check"].setPixmapNum(0)
901 self["DNS"].setForegroundColorNum(1)
902 self["DNS"].setText(_("unconfirmed"))
903 self["DNSInfo_Check"].setPixmapNum(1)
904 self["DNSInfo_Check"].show()
905 self["DNSInfo_Text"].setForegroundColorNum(1)
907 self["EditSettings_Text"].show()
908 self["EditSettingsButton"].setPixmapNum(1)
909 self["EditSettings_Text"].setForegroundColorNum(2) # active
910 self["EditSettingsButton"].show()
911 self["ButtonYellow_Check"].setPixmapNum(1)
912 self["ButtonGreentext"].setText(_("Restart test"))
913 self["ButtonGreen_Check"].setPixmapNum(0)
914 self["shortcutsgreen"].setEnabled(False)
915 self["shortcutsgreen_restart"].setEnabled(True)
916 self["shortcutsyellow"].setEnabled(False)
917 self["updown_actions"].setEnabled(True)
918 self.activebutton = 6
921 self["shortcutsgreen"].setEnabled(False)
922 self["shortcutsyellow"].setEnabled(True)
923 self["updown_actions"].setEnabled(False)
924 self["ButtonYellow_Check"].setPixmapNum(0)
925 self["ButtonGreen_Check"].setPixmapNum(1)
926 self.steptimer = True
927 self.nextStepTimer.start(1000)
929 def KeyGreenRestart(self):
931 self.layoutFinished()
932 self["Adapter"].setText((""))
933 self["Network"].setText((""))
934 self["Dhcp"].setText((""))
935 self["IP"].setText((""))
936 self["DNS"].setText((""))
937 self["AdapterInfo_Text"].setForegroundColorNum(0)
938 self["NetworkInfo_Text"].setForegroundColorNum(0)
939 self["DhcpInfo_Text"].setForegroundColorNum(0)
940 self["IPInfo_Text"].setForegroundColorNum(0)
941 self["DNSInfo_Text"].setForegroundColorNum(0)
942 self["shortcutsgreen_restart"].setEnabled(False)
943 self["shortcutsgreen"].setEnabled(False)
944 self["shortcutsyellow"].setEnabled(True)
945 self["updown_actions"].setEnabled(False)
946 self["ButtonYellow_Check"].setPixmapNum(0)
947 self["ButtonGreen_Check"].setPixmapNum(1)
948 self.steptimer = True
949 self.nextStepTimer.start(1000)
952 self["infoshortcuts"].setEnabled(True)
953 self["shortcuts"].setEnabled(False)
954 if self.activebutton == 1: # Adapter Check
955 self["InfoText"].setText(_("This test detects your configured LAN-Adapter."))
956 self["InfoTextBorder"].show()
957 self["InfoText"].show()
958 self["ButtonRedtext"].setText(_("Back"))
959 if self.activebutton == 2: #LAN Check
960 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"))
961 self["InfoTextBorder"].show()
962 self["InfoText"].show()
963 self["ButtonRedtext"].setText(_("Back"))
964 if self.activebutton == 3: #DHCP Check
965 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."))
966 self["InfoTextBorder"].show()
967 self["InfoText"].show()
968 self["ButtonRedtext"].setText(_("Back"))
969 if self.activebutton == 4: # IP Check
970 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"))
971 self["InfoTextBorder"].show()
972 self["InfoText"].show()
973 self["ButtonRedtext"].setText(_("Back"))
974 if self.activebutton == 5: # DNS Check
975 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"))
976 self["InfoTextBorder"].show()
977 self["InfoText"].show()
978 self["ButtonRedtext"].setText(_("Back"))
979 if self.activebutton == 6: # Edit Settings
980 self.session.open(AdapterSetup,self.iface)
984 self["shortcutsgreen_restart"].setEnabled(True)
985 self["shortcutsgreen"].setEnabled(False)
986 self["shortcutsyellow"].setEnabled(False)
987 self["ButtonGreentext"].setText(_("Restart test"))
988 self["ButtonYellow_Check"].setPixmapNum(1)
989 self["ButtonGreen_Check"].setPixmapNum(0)
990 self.steptimer = False
991 self.nextStepTimer.stop()
993 def layoutFinished(self):
994 self["shortcutsyellow"].setEnabled(False)
995 self["AdapterInfo_OK"].hide()
996 self["NetworkInfo_Check"].hide()
997 self["DhcpInfo_Check"].hide()
998 self["IPInfo_Check"].hide()
999 self["DNSInfo_Check"].hide()
1000 self["EditSettings_Text"].hide()
1001 self["EditSettingsButton"].hide()
1002 self["InfoText"].hide()
1003 self["InfoTextBorder"].hide()
1004 self["ButtonYellow_Check"].hide()
1005 self["ButtonYellowtext"].hide()
1007 def setLabels(self):
1008 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1009 self["Adapter"] = MultiColorLabel()
1010 self["AdapterInfo"] = MultiPixmap()
1011 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1012 self["AdapterInfo_OK"] = Pixmap()
1014 if self.iface == 'wlan0' or self.iface == 'ath0':
1015 self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1017 self["Networktext"] = MultiColorLabel(_("Local Network"))
1019 self["Network"] = MultiColorLabel()
1020 self["NetworkInfo"] = MultiPixmap()
1021 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1022 self["NetworkInfo_Check"] = MultiPixmap()
1024 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1025 self["Dhcp"] = MultiColorLabel()
1026 self["DhcpInfo"] = MultiPixmap()
1027 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1028 self["DhcpInfo_Check"] = MultiPixmap()
1030 self["IPtext"] = MultiColorLabel(_("IP Address"))
1031 self["IP"] = MultiColorLabel()
1032 self["IPInfo"] = MultiPixmap()
1033 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1034 self["IPInfo_Check"] = MultiPixmap()
1036 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1037 self["DNS"] = MultiColorLabel()
1038 self["DNSInfo"] = MultiPixmap()
1039 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1040 self["DNSInfo_Check"] = MultiPixmap()
1042 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1043 self["EditSettingsButton"] = MultiPixmap()
1045 self["ButtonRedtext"] = Label(_("Close"))
1046 self["ButtonRed"] = Pixmap()
1048 self["ButtonGreentext"] = Label(_("Start test"))
1049 self["ButtonGreen_Check"] = MultiPixmap()
1051 self["ButtonYellowtext"] = Label(_("Stop test"))
1052 self["ButtonYellow_Check"] = MultiPixmap()
1054 self["InfoTextBorder"] = Pixmap()
1055 self["InfoText"] = Label()
1057 def getLinkState(self,iface):
1058 if iface == 'wlan0' or iface == 'ath0':
1060 from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan
1062 stats = w.getStatus()
1063 if stats['BSSID'] == "00:00:00:00:00:00":
1064 self["Network"].setForegroundColorNum(1)
1065 self["Network"].setText(_("disconnected"))
1066 self["NetworkInfo_Check"].setPixmapNum(1)
1067 self["NetworkInfo_Check"].show()
1069 self["Network"].setForegroundColorNum(2)
1070 self["Network"].setText(_("connected"))
1071 self["NetworkInfo_Check"].setPixmapNum(0)
1072 self["NetworkInfo_Check"].show()
1074 self["Network"].setForegroundColorNum(1)
1075 self["Network"].setText(_("disconnected"))
1076 self["NetworkInfo_Check"].setPixmapNum(1)
1077 self["NetworkInfo_Check"].show()
1079 iNetwork.getLinkState(iface,self.dataAvail)
1081 def dataAvail(self,data):
1082 self.output = data.strip()
1083 result = self.output.split('\n')
1084 pattern = re_compile("Link detected: yes")
1086 if re_search(pattern, item):
1087 self["Network"].setForegroundColorNum(2)
1088 self["Network"].setText(_("connected"))
1089 self["NetworkInfo_Check"].setPixmapNum(0)
1091 self["Network"].setForegroundColorNum(1)
1092 self["Network"].setText(_("disconnected"))
1093 self["NetworkInfo_Check"].setPixmapNum(1)
1094 self["NetworkInfo_Check"].show()