1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Screens.InputBox import InputBox
4 from Screens.Standby import *
5 from Screens.VirtualKeyBoard import VirtualKeyBoard
6 from Screens.HelpMenu import HelpableScreen
7 from Components.Network import iNetwork
8 from Screens.NetworkSetup import NameserverSetup
9 from Components.Sources.StaticText import StaticText
10 from Components.Sources.Boolean import Boolean
11 from Components.Sources.List import List
12 from Components.Label import Label,MultiColorLabel
13 from Components.Pixmap import Pixmap,MultiPixmap
14 from Components.MenuList import MenuList
15 from Components.config import config, ConfigYesNo, ConfigIP, NoSave, ConfigText, ConfigPassword, ConfigSelection, getConfigListEntry, ConfigNothing
16 from Components.config import ConfigInteger, ConfigSubsection
17 from Components.ConfigList import ConfigListScreen
18 from Components.PluginComponent import plugins
19 from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest
20 from Components.ActionMap import ActionMap, NumberActionMap, HelpableActionMap
21 from Components.Console import Console
22 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_CURRENT_SKIN
23 from Tools.LoadPixmap import LoadPixmap
24 from Plugins.Plugin import PluginDescriptor
25 from enigma import eTimer, ePoint, eSize, RT_HALIGN_LEFT, eListboxPythonMultiContent, gFont
26 from os import path as os_path, system as os_system, unlink, listdir, access, R_OK, popen
27 from re import compile as re_compile, search as re_search
28 from Tools.Directories import fileExists
30 from pythonwifi.iwlibs import Wireless
31 from pythonwifi import flags as wifi_flags
33 class WlanSelection(Screen,HelpableScreen):
35 <screen position="center,center" size="510,400" title="Wireless Network Adapter Selection..." >
36 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
37 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
39 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
40 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
42 <widget source="key_red" render="Label" position="10,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
43 <widget source="key_green" render="Label" position="360,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
45 <widget name="menulist" position="20,20" size="230,260" transparent="1" backgroundColor="#371e1c1a" zPosition="10" scrollbarMode="showOnDemand" />
46 <widget source="description" render="Label" position="305,10" size="195,300" font="Regular;19" halign="center" valign="center" />
49 def __init__(self, session):
50 Screen.__init__(self,session)
51 HelpableScreen.__init__(self)
52 self.mainmenu = self.getWlandevice()
53 self["menulist"] = MenuList(self.mainmenu)
54 self["key_red"] = StaticText(_("Close"))
55 self["key_green"] = StaticText(_("Select"))
56 self["description"] = StaticText()
57 self["description"].setText(_("Select Wireless Lan module. \n" ))
58 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
60 "ok": (self.ok, _("select interface")),
61 "cancel": (self.close, _("exit network interface list")),
64 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
66 "green": (self.ok, _("select interface")),
67 "red": (self.close, _("exit network interface list")),
69 self.updateInterfaces()
70 self.onClose.append(self.cleanup)
72 def updateInterfaces(self):
73 iNetwork.config_ready = False
75 iNetwork.getInterfaces()
77 def checkIfaceMode(self, iface = None):
80 if obj.getMode() == 'Master':
88 # print len(self["menulist"].list)
89 if len(self["menulist"].list) == 0:
90 self.session.open(MessageBox, (_("Can not find any WirelessLan Module\n")),MessageBox.TYPE_ERROR,5 )
92 iface=self["menulist"].getCurrent()[1]
95 elif iNetwork.getAdapterAttribute(iface, "up") == True:
96 ret = self.checkIfaceMode(iface)
98 self.session.open(MessageBox, (_("Invalid WirelessLan Module.\n")),MessageBox.TYPE_ERROR,5 )
101 self.session.open(MessageBox, (_("Can not setup WirelessLan Module in 'AP Mode'\n")),MessageBox.TYPE_ERROR,5 )
103 self.session.open(WlanSetup, iface)
105 def getWlandevice(self):
107 for x in iNetwork.getInstalledAdapters():
108 if x.startswith('eth') or x.startswith('br') or x.startswith('mon'):
110 description=self.getAdapterDescription(x)
111 if description == "Unknown network adapter":
112 list.append((description,x))
114 list.append((description + " (%s)"%x,x))
117 def getAdapterDescription(self, iface):
118 classdir = "/sys/class/net/" + iface + "/device/"
119 driverdir = "/sys/class/net/" + iface + "/device/driver/"
120 if os_path.exists(classdir):
121 files = listdir(classdir)
122 if 'driver' in files:
123 if os_path.realpath(driverdir).endswith('rtw_usb_drv'):
124 return _("Realtek")+ " " + _("WLAN adapter.")
125 elif os_path.realpath(driverdir).endswith('ath_pci'):
126 return _("Atheros")+ " " + _("WLAN adapter.")
127 elif os_path.realpath(driverdir).endswith('zd1211b'):
128 return _("Zydas")+ " " + _("WLAN adapter.")
129 elif os_path.realpath(driverdir).endswith('rt73'):
130 return _("Ralink")+ " " + _("WLAN adapter.")
131 elif os_path.realpath(driverdir).endswith('rt73usb'):
132 return _("Ralink")+ " " + _("WLAN adapter.")
133 elif self.isRalinkModule(iface):
134 return _("Ralink")+ " " + _("WLAN adapter.")
136 return str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter")
138 return _("Unknown network adapter")
139 elif os_path.exists("/tmp/bcm/%s"%iface):
140 return _("BroadCom WLAN adapter")
142 return _("Unknown network adapter")
144 def isRalinkModule(self, iface):
145 # check vendor ID for lagacy driver
146 vendorID = "148f" # ralink vendor ID
147 idVendorPath = "/sys/class/net/%s/device/idVendor" % iface
148 if access(idVendorPath, R_OK):
149 fd = open(idVendorPath, "r")
150 data = fd.read().strip()
153 # print "Vendor ID : %s" % data
158 # check sys driver path for kernel driver
159 ralinkKmod = "rt2800usb" # ralink kernel driver name
160 driverPath = "/sys/class/net/%s/device/driver/" % iface
161 if os_path.exists(driverPath):
162 driverName = os_path.basename(os_path.realpath(driverPath))
164 # print "driverName : %s" % driverName
166 if driverName == ralinkKmod:
172 iNetwork.stopGetInterfacesConsole()
174 class WlanSetup(Screen,HelpableScreen):
176 <screen position="center,center" size="510,400" title="Wireless Network Setup Menu..." >
177 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
178 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
180 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
181 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
183 <widget source="key_red" render="Label" position="10,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
184 <widget source="key_green" render="Label" position="360,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
186 <widget name="menulist" position="20,20" size="230,260" transparent="1" backgroundColor="#371e1c1a" zPosition="10" scrollbarMode="showOnDemand" />
187 <widget source="description" render="Label" position="305,10" size="195,300" font="Regular;19" halign="center" valign="center" />
190 def __init__(self, session, ifaces):
191 Screen.__init__(self, session)
192 HelpableScreen.__init__(self)
193 self.session = session
195 self.restartLanRef = None
196 self.LinkState = None
197 self.mainmenu = self.MakeMenu()
198 self["menulist"] = MenuList(self.mainmenu)
199 self["key_red"] = StaticText(_("Close"))
200 self["key_green"] = StaticText(_("Select"))
201 self["description"] = StaticText()
202 self["IFtext"] = StaticText()
203 self["IF"] = StaticText()
204 self.onLayoutFinish.append(self.loadDescription)
206 self.oktext = _("Press OK on your remote control to continue.")
208 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
210 "up": (self.up, _("move up to previous entry")),
211 "down": (self.down, _("move down to next entry")),
212 "left": (self.left, _("move up to first entry")),
213 "right": (self.right, _("move down to last entry")),
216 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
218 "cancel": (self.close, _("exit networkadapter setup menu")),
219 "ok": (self.ok, _("select menu entry")),
222 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
224 "red": (self.close, _("exit networkadapter setup menu")),
225 "green": (self.ok, _("select menu entry")),
228 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
238 self.onClose.append(self.cleanup)
240 def loadDescription(self):
241 if self["menulist"].getCurrent()[1] == 'setting':
242 self["description"].setText(_("Edit the network configuration of your STB.\n" ) + self.oktext )
243 if self["menulist"].getCurrent()[1] == 'scanap':
244 self["description"].setText(_("Scan your network for wireless access points and connect to them using your selected wireless device.\n" ) + self.oktext )
245 if self["menulist"].getCurrent()[1] == 'dns':
246 self["description"].setText(_("Edit the Nameserver configuration of your STB.\n" ) + self.oktext )
247 if self["menulist"].getCurrent()[1] == 'status':
248 self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
249 if self["menulist"].getCurrent()[1] == 'test':
250 self["description"].setText(_("Test the network configuration of your STB.\n" ) + self.oktext )
251 if self["menulist"].getCurrent()[1] == 'restart':
252 self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
255 self["menulist"].up()
256 self.loadDescription()
259 self["menulist"].down()
260 self.loadDescription()
263 self["menulist"].pageUp()
264 self.loadDescription()
267 self["menulist"].pageDown()
268 self.loadDescription()
272 if self["menulist"].getCurrent()[1] == 'setting':
273 self.session.openWithCallback(self.checklist, WlanConfig, self.iface)
274 elif self["menulist"].getCurrent()[1] == 'scanap':
275 self.session.openWithCallback(self.WlanScanApCallback, WlanScanAp, self.iface)
276 elif self["menulist"].getCurrent()[1] == 'dns':
277 self.session.open(NameserverSetup)
278 elif self["menulist"].getCurrent()[1] == 'status':
279 self.session.open(Wlanstatus, self.iface)
280 elif self["menulist"].getCurrent()[1] == 'test':
281 self.session.openWithCallback(self.checklist,NetworkAdapterTest,self.iface)
282 elif self["menulist"].getCurrent()[1] == 'restart':
283 self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
286 self["menulist"].setList(self.MakeMenu())
290 menu.append((_("Adapter settings"), "setting"))
291 menu.append((_("Scan Wireless AP"), "scanap"))
292 # menu.append((_("Nameserver settings"), "dns"))
293 if iNetwork.getAdapterAttribute(self.iface, "up"):
294 menu.append((_("Show WLAN Status"), "status"))
295 menu.append((_("Network test"), "test"))
296 menu.append((_("Restart network"), "restart"))
300 def WlanScanApCallback(self, essid = None):
301 if essid is not None:
302 self.session.openWithCallback(self.checklist, WlanConfig, self.iface)
304 def restartLan(self, ret = False):
306 iNetwork.restartNetwork(self.restartLanDataAvail)
307 self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while your network is restarting..."), type = MessageBox.TYPE_INFO, enable_input = False)
309 def restartLanDataAvail(self, data):
311 iNetwork.getInterfaces(self.getInterfacesDataAvail)
313 def getInterfacesDataAvail(self, data):
315 self.restartLanRef.close(True)
317 def restartfinishedCB(self,data):
319 self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 5, default = False)
322 iNetwork.stopRestartConsole()
323 iNetwork.stopGetInterfacesConsole()
325 ESSID_SELECTED_IN_APLIST = None
326 CHECK_NETWORK_SHARE = False
328 class WlanConfig(Screen, ConfigListScreen, HelpableScreen):
330 <screen position="center,center" size="510,400" title="Wireless Network Configuration..." >
331 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
332 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
334 <widget source="key_red" render="Label" position="10,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
335 <widget source="key_green" render="Label" position="360,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
337 <widget name="config" position="10,10" backgroundColor="#371e1c1a" transparent="1" size="480,195" scrollbarMode="showOnDemand" />
338 <ePixmap pixmap="skin_default/div-h.png" position="0,210" zPosition="1" size="560,2" />
339 <widget source="ipaddresstext" render="Label" position="100,220" zPosition="1" size="190,21" font="Regular;19" halign="Left" valign="center" />
340 <widget source="ipaddress" render="Label" position="300,220" zPosition="1" size="150,26" font="Regular;20" halign="Left" valign="center" />
341 <widget source="netmasktext" render="Label" position="100,245" zPosition="1" size="190,21" font="Regular;19" halign="Left" valign="center" />
342 <widget source="netmask" render="Label" position="300,245" zPosition="1" size="150,26" font="Regular;20" halign="Left" valign="center" />
343 <widget source="gatewaytext" render="Label" position="100,270" zPosition="1" size="190,21" font="Regular;19" halign="Left" valign="center" />
344 <widget source="gateway" render="Label" position="300,270" zPosition="1" size="150,26" font="Regular;20" halign="Left" valign="center" />
345 <widget source="DNS1text" render="Label" position="100,295" zPosition="1" size="190,21" font="Regular;19" halign="Left" valign="center" />
346 <widget source="DNS1" render="Label" position="300,295" zPosition="1" size="150,26" font="Regular;20" halign="Left" valign="center" />
347 <widget source="DNS2text" render="Label" position="100,320" zPosition="1" size="190,21" font="Regular;19" halign="Left" valign="center" />
348 <widget source="DNS2" render="Label" position="300,320" zPosition="1" size="150,26" font="Regular;20" halign="Left" valign="center" />
349 <widget name="VKeyIcon" pixmap="skin_default/buttons/key_text.png" position="460,230" zPosition="10" size="35,25" transparent="1" alphatest="on" />
350 <widget name="HelpWindow" pixmap="skin_default/buttons/key_text.png" position="383,420" zPosition="1" size="1,1" transparent="1" alphatest="on" />
353 def __init__(self, session, iface):
354 Screen.__init__(self,session)
355 self.session = session
356 self["key_red"] = StaticText(_("Close"))
357 self["key_green"] = StaticText(_("Ok"))
358 self["ipaddresstext"] = StaticText(_("IP Address"))
359 self["ipaddress"] = StaticText(_("[ N/A ]"))
360 self["netmasktext"] = StaticText(_("NetMask"))
361 self["netmask"] = StaticText(_("[ N/A ]"))
362 self["gatewaytext"] = StaticText(_("Gateway"))
363 self["gateway"] = StaticText(_("[ N/A ]"))
364 self["DNS1text"] = StaticText(_("Primary DNS"))
365 self["DNS1"] = StaticText(_("[ N/A ]"))
366 self["DNS2text"] = StaticText(_("Secondary DNS"))
367 self["DNS2"] = StaticText(_("[ N/A ]"))
368 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
370 "ok": self.saveWlanConfig,
371 "green": self.saveWlanConfig,
372 "cancel": self.keyCancel,
373 "red": self.keyCancel,
375 self["HelpWindow"] = Pixmap()
376 self["HelpWindow"].hide()
377 self["VKeyIcon"] = Pixmap()
378 self["VKeyIcon"].hide()
382 ConfigListScreen.__init__(self, self.list, session = self.session)
383 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
385 self.updateInterfaces(self.updateInterfaceCB)
386 self.onClose.append(self.cleanup)
388 self.useWlCommand = os_path.exists("/tmp/bcm/%s"%iface)
390 def updateInterfaces(self,callback = None):
391 iNetwork.config_ready = False
392 iNetwork.msgPlugins()
393 iNetwork.getInterfaces(callback)
395 def updateInterfaceCB(self, ret=None):
397 print "getInterfaces Fail... "
402 def getWlConfName(self, iface):
403 return "/etc/wl.conf.%s" % iface
405 def readWlConf(self):
407 wsconf["ssid"] = "Vuplus AP"
408 wsconf["hidden_ssid"] = False # not used
409 wsconf["encrypt_mothod"] = "wpa2"
410 wsconf["wep_keytype"] = "ascii" # not used
411 wsconf["key"] = "XXXXXXXX"
413 wlConfName = self.getWlConfName(self.iface)
415 if fileExists(wlConfName):
416 fd = open(wlConfName, "r")
417 lines = fd.readlines()
422 (key, value) = line.strip().split('=',1)
427 wsconf["ssid"] = value.strip()
429 wsconf["encrypt_mothod"] = value.strip()
431 wsconf["key"] = value.strip()
436 for (k,v) in wsconf.items():
437 print "[wsconf][%s] %s" % (k , v)
441 def getWpaSupplicantName(self, iface):
442 return "/etc/wpa_supplicant.conf.%s" % iface
444 def readWpaSupplicantConf(self):
445 wpaSupplicantName = self.getWpaSupplicantName(self.iface)
448 if fileExists(wpaSupplicantName):
449 wpafd = open(wpaSupplicantName, "r")
450 lines = wpafd.readlines()
455 (key, value) = line.strip().split('=',1)
459 # if key not in ('ssid', 'ap_scan', 'scan_ssid', 'key_mgmt', 'proto', 'wep_key0', 'psk', '#psk'):
460 if key not in ('ssid', 'scan_ssid', 'key_mgmt', 'proto', 'wep_key0', 'psk', '#psk'):
464 data[key] = value.strip('"')
467 data[key] = value.strip()
469 wsconf["ssid"] = data.get("ssid", "INPUTSSID")
470 wsconf["hidden_ssid"] = data.get("scan_ssid") == '1' and True or False
472 key_mgmt = data.get("key_mgmt")
473 if key_mgmt == "NONE":
474 wep_key = data.get("wep_key0")
477 wsconf["encrypt_mothod"] = "None"
479 wsconf["encrypt_mothod"] = "wep"
481 if wep_key.startswith('"') and wep_key.endswith('"'):
482 wsconf["wep_keytype"] = "ascii"
483 wsconf["key"] = wep_key.strip('"')
485 wsconf["wep_keytype"] = "hex"
486 wsconf["key"] = wep_key
488 elif key_mgmt == "WPA-PSK":
489 proto = data.get("proto")
492 wsconf["encrypt_mothod"] = "wpa"
495 wsconf["encrypt_mothod"] = "wpa2"
497 elif proto in ( "WPA RSN", "WPA WPA2"):
498 wsconf["encrypt_mothod"] = "wpa/wpa2"
501 wsconf["encrypt_mothod"] = "wpa2"
503 psk = data.get("#psk")
505 wsconf["key"] = psk.strip('"')
507 wsconf["key"] = data.get("psk")
509 wsconf["encrypt_mothod"] = "wpa2"
513 if wsconf.get("ssid") is None:
514 wsconf["ssid"] = "INPUTSSID"
515 if wsconf.get("hidden_ssid") is None:
516 wsconf["hidden_ssid"] = False
517 if wsconf.get("encrypt_mothod") is None:
518 wsconf["encrypt_mothod"] = "wpa2"
519 if wsconf.get("wep_keytype") is None:
520 wsconf["wep_keytype"] = "ascii"
521 if wsconf.get("key") is None:
522 wsconf["key"] = "XXXXXXXX"
525 # for (k,v) in wsconf.items():
526 # print "[wsconf][%s] %s" % (k , v)
530 def displayIP(self, domain, entry):
531 text = entry.getText()
532 if text is not None and text != "0.0.0.0":
533 self[domain].setText(entry.getText())
535 self[domain].setText(_("N/A"))
537 def createConfig(self):
538 # activate Interface setup
539 self.activateInterfaceEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "up") or False))
541 self.usedhcpConfigEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "dhcp") or False))
544 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
545 usegatewayDefault=True
547 usegatewayDefault=False
548 self.usegatewayConfigEntry = NoSave(ConfigYesNo(default=usegatewayDefault))
550 self.gatewayConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0]))
553 self.IPConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip") or [0,0,0,0]))
554 self.netmaskConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0]))
557 if iNetwork.getAdapterAttribute(self.iface, "dns-nameservers"):
561 self.useDNSConfigEntry = NoSave(ConfigYesNo(default=dnsDefault or False))
563 nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
564 self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
565 self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
567 self.displayIP("ipaddress", self.IPConfigEntry)
568 self.displayIP("netmask", self.netmaskConfigEntry)
569 self.displayIP("gateway", self.gatewayConfigEntry)
570 self.displayIP("DNS1", self.primaryDNS)
571 self.displayIP("DNS2", self.secondaryDNS)
573 # read old configuration
574 if self.useWlCommand:
575 wsconf = self.readWlConf()
577 wsconf = self.readWpaSupplicantConf()
580 encryptionChoices = [("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")), ("None", _("No Encrypt")) ]
581 if not self.useWlCommand:
582 encryptionChoices.append( ("wpa/wpa2", _("WPA/WPA2")) )
583 self.methodConfigEntry = NoSave(ConfigSelection(default = wsconf["encrypt_mothod"], choices = encryptionChoices))
586 keytypeChoices = [("ascii", _("ASCII")), ("hex", _("HEX"))]
587 self.keytypeConfigEntry = NoSave(ConfigSelection(default = wsconf["wep_keytype"], choices = keytypeChoices))
590 self.keyConfigEntry = NoSave(ConfigPassword(default = wsconf["key"], visible_width = 50, fixed_size = False))
593 self.hiddenssidConfigEntry = NoSave(ConfigYesNo(default = wsconf["hidden_ssid"]))
597 global ESSID_SELECTED_IN_APLIST
598 if ESSID_SELECTED_IN_APLIST:
599 essidDefault = ESSID_SELECTED_IN_APLIST
601 essidDefault = wsconf["ssid"]
603 self.ssidConfigEntry = NoSave(ConfigText(default = essidDefault, visible_width = 50, fixed_size = False))
605 def createSetup(self):
607 self.usedeviceEntry = getConfigListEntry(_("Use Device"), self.activateInterfaceEntry)
608 self.usedhcpEntry = getConfigListEntry(_("Use DHCP"), self.usedhcpConfigEntry)
609 self.essidEntry = getConfigListEntry(_("SSID"), self.ssidConfigEntry)
610 if not self.useWlCommand:
611 self.hiddenessidEntry = getConfigListEntry(_("Hidden Network"), self.hiddenssidConfigEntry)
612 self.methodEntry = getConfigListEntry(_("Encrypt Method"), self.methodConfigEntry)
613 if not self.useWlCommand:
614 self.keytypeEntry = getConfigListEntry(_("Key Type"), self.keytypeConfigEntry)
615 self.keyEntry = getConfigListEntry(_("KEY"), self.keyConfigEntry)
617 self.ipEntry = getConfigListEntry(_("IP"), self.IPConfigEntry)
618 self.netmaskEntry = getConfigListEntry(_("NetMask"), self.netmaskConfigEntry)
620 self.usegatewayEntry = getConfigListEntry(_("Use Gateway"), self.usegatewayConfigEntry)
621 self.gatewayEntry = getConfigListEntry(_("Gateway"), self.gatewayConfigEntry)
623 manualNameservers = (iNetwork.getInterfacesNameserverList(self.iface) + [[0,0,0,0]] * 2)[0:2]
624 self.manualPrimaryDNS = NoSave(ConfigIP(default=manualNameservers[0]))
625 self.manualSecondaryDNS = NoSave(ConfigIP(default=manualNameservers[1]))
627 self.usednsEntry = getConfigListEntry(_("Use Manual dns-nameserver"), self.useDNSConfigEntry)
628 self.primaryDNSConfigEntry = getConfigListEntry(_('Primary DNS'), self.manualPrimaryDNS)
629 self.secondaryDNSConfigEntry = getConfigListEntry(_('Secondary DNS'), self.manualSecondaryDNS)
631 self.configList.append( self.usedeviceEntry )
632 if self.activateInterfaceEntry.value is True:
633 self.configList.append( self.usedhcpEntry )
635 if self.usedhcpConfigEntry.value is True:
636 self.configList.append(self.usednsEntry)
638 self.configList.append(self.ipEntry)
639 self.configList.append(self.netmaskEntry)
640 self.configList.append(self.usegatewayEntry)
642 if self.usegatewayConfigEntry.value is True:
643 self.configList.append(self.gatewayEntry)
645 if self.useDNSConfigEntry.value is True or self.usedhcpConfigEntry.value is False:
646 self.configList.append(self.primaryDNSConfigEntry)
647 self.configList.append(self.secondaryDNSConfigEntry)
649 if not self.useWlCommand:
650 self.configList.append( self.hiddenessidEntry )
652 self.configList.append( self.essidEntry )
653 self.configList.append( self.methodEntry )
655 if self.methodConfigEntry.value =="wep":
656 if not self.useWlCommand:
657 self.configList.append( self.keytypeEntry )
659 if self.methodConfigEntry.value != "None":
660 self.configList.append( self.keyEntry )
662 self["config"].list = self.configList
663 self["config"].l.setList(self.configList)
664 if not self.showTextIcon in self["config"].onSelectionChanged:
665 self["config"].onSelectionChanged.append(self.showTextIcon)
667 def showTextIcon(self):
668 if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
669 self["VKeyIcon"].show()
671 self["VKeyIcon"].hide()
673 def onSelectHelpWindow(self, ret = False):
674 if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
675 self["config"].getCurrent()[1].onSelect(self.session)
677 def onDeselectHelpWindow(self, ret = False):
678 if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
679 self["config"].getCurrent()[1].onDeselect(self.session)
682 ConfigListScreen.keyLeft(self)
686 ConfigListScreen.keyRight(self)
690 if self["config"].getCurrent() == self.usedeviceEntry or self["config"].getCurrent() == self.usedhcpEntry \
691 or self["config"].getCurrent() == self.usegatewayEntry or self["config"].getCurrent() == self.methodEntry \
692 or self["config"].getCurrent() == self.methodEntry or self["config"].getCurrent() == self.usednsEntry:
695 def saveWlanConfig(self):
697 self.onDeselectHelpWindow()
699 if self["config"].isChanged():
700 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Are you sure you want to restart your network interfaces?\n") ) )
702 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Network configuration is not changed....\n\nAre you sure you want to restart your network interfaces?\n") ) )
706 def checkNetworkConfig(self, ret = False):
708 self.onSelectHelpWindow()
710 elif len(self.ssidConfigEntry.value) == 0:
711 self.session.open(MessageBox, ("PLEASE INPUT SSID"), type = MessageBox.TYPE_ERROR, timeout = 10)
713 elif len(self.keyConfigEntry.value) == 0:
714 self.session.open(MessageBox, ("PLEASE INPUT ENCRYPT KEY"), type = MessageBox.TYPE_ERROR, timeout = 10)
717 global CHECK_NETWORK_SHARE
718 if CHECK_NETWORK_SHARE:
719 self.checkNetworkShares(self.confirmAnotherIfaces)
721 self.confirmAnotherIfaces()
723 def checkNetworkShares(self, callback):
724 cmd = "cat /proc/mounts"
725 data = popen(cmd).readlines()
726 networks = ['nfs','smbfs','ncp','coda']
728 split = line.strip().split(' ',3)
729 if split[2] in networks:
730 self.session.openWithCallback(self.onSelectHelpWindow, MessageBox, ("NOT deconfiguring network interfaces :\n network shares still mounted\n"), type = MessageBox.TYPE_ERROR, timeout = 10)
734 def confirmAnotherIfaces(self):
735 num_configured_if = len(iNetwork.getConfiguredAdapters())
736 if num_configured_if >= 1:
737 if num_configured_if == 1 and self.iface in iNetwork.getConfiguredAdapters():
738 self.confirmAnotherIfacesCB(False)
740 self.session.openWithCallback(self.confirmAnotherIfacesCB, MessageBox, _("A second configured interface has been found.\n\nDo you want to disable the second network interface?"), default = True)
742 self.confirmAnotherIfacesCB(False)
744 def isWPAMethod(self, method):
745 if method in ("wep", "None"):
750 def confirmAnotherIfacesCB(self, ret):
752 configuredInterfaces = iNetwork.getConfiguredAdapters()
753 for interface in configuredInterfaces:
754 if interface == self.iface:
756 iNetwork.setAdapterAttribute(interface, "up", False)
757 iNetwork.deactivateInterface(interface)
762 if self.isWPAMethod(self.methodConfigEntry.value) and (not self.useWlCommand):
763 (psk, plainpwd) = self.getWpaPhrase()
766 if self.useWlCommand:
767 res = self.writeWlConf()
769 res = self.writeWpasupplicantConf(psk, plainpwd)
772 self.writeNetConfig()
774 def writeWlConf(self):
776 wsconf["ssid"] = "Vuplus AP"
777 wsconf["hidden_ssid"] = False # not used
778 wsconf["encrypt_mothod"] = "None"
779 wsconf["wep_keytype"] = "ascii" # not used
780 wsconf["key"] = "XXXXXXXX"
782 wlConfName = self.getWlConfName(self.iface)
785 fd = open(wlConfName, "w")
787 self.session.open(MessageBox, _("%s open error." % wlConfName ), type = MessageBox.TYPE_ERROR, timeout = 10)
791 contents += "ssid="+self.ssidConfigEntry.value+"\n"
792 contents += "method="+self.methodConfigEntry.value+"\n"
793 contents += "key="+self.keyConfigEntry.value+"\n"
795 print "content = \n"+contents
801 def getWpaPhrase(self):
802 cmd = "wpa_passphrase '%s' '%s'" % (self.ssidConfigEntry.value, self.keyConfigEntry.value)
804 data = popen(cmd).readlines()
810 (key, value) = line.strip().split('=',1)
819 return (psk, plainpwd)
821 def writeWpasupplicantConf(self, passphrasekey=None, plainpwd=None):
822 wpaSupplicantName = self.getWpaSupplicantName(self.iface)
824 wpafd = open(wpaSupplicantName, "w")
826 self.session.open(MessageBox, _("%s open error." % wpaSupplicantName ), type = MessageBox.TYPE_ERROR, timeout = 10)
829 contents = "#WPA Supplicant Configuration by STB\n"
830 contents += "ctrl_interface=/var/run/wpa_supplicant\n"
831 contents += "eapol_version=1\n"
832 contents += "fast_reauth=1\n"
833 contents += "ap_scan=1\n"
834 contents += "network={\n"
836 contents += "\tssid=\""+self.ssidConfigEntry.value+"\"\n"
838 if self.hiddenssidConfigEntry.value is True:
839 contents += "\tscan_ssid=1\n"
841 contents += "\tscan_ssid=0\n"
843 if self.methodConfigEntry.value == "None":
844 contents += "\tkey_mgmt=NONE\n"
846 elif self.methodConfigEntry.value == "wep":
847 contents += "\tkey_mgmt=NONE\n"
848 contents += "\twep_key0="
849 if self.keytypeConfigEntry.value == "ascii":
850 contents += "\""+self.keyConfigEntry.value+"\"\n"
852 contents += self.keyConfigEntry.value+"\n"
855 if self.methodConfigEntry.value == "wpa":
856 contents += "\tkey_mgmt=WPA-PSK\n"
857 contents += "\tproto=WPA\n"
858 contents += "\tpairwise=CCMP TKIP\n"
859 contents += "\tgroup=CCMP TKIP\n"
860 elif self.methodConfigEntry.value == "wpa2":
861 contents += "\tkey_mgmt=WPA-PSK\n"
862 contents += "\tproto=RSN\n"
863 contents += "\tpairwise=CCMP TKIP\n"
864 contents += "\tgroup=CCMP TKIP\n"
866 contents += "\tkey_mgmt=WPA-PSK\n"
867 contents += "\tproto=WPA RSN\n"
868 contents += "\tpairwise=CCMP TKIP\n"
869 contents += "\tgroup=CCMP TKIP\n"
871 # print "plainpwd : ",plainpwd
872 # print "passphrasekey : ",passphrasekey
873 if plainpwd is not None and passphrasekey is not None:
875 contents += passphrasekey
877 contents += "\tpsk=%s\n" % self.keyConfigEntry.value
880 # print "content = \n"+contents
881 wpafd.write(contents)
886 def writeNetConfig(self):
887 if self.activateInterfaceEntry.value is True:
888 iNetwork.setAdapterAttribute(self.iface, "up", True)
889 if self.usedhcpConfigEntry.value is True:
890 iNetwork.setAdapterAttribute(self.iface, "dhcp", True)
892 iNetwork.setAdapterAttribute(self.iface, "dhcp", False)
893 iNetwork.setAdapterAttribute(self.iface, "ip", self.IPConfigEntry.value)
894 iNetwork.setAdapterAttribute(self.iface, "netmask", self.netmaskConfigEntry.value)
895 if self.usegatewayConfigEntry.value is True:
896 iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value)
897 if self.useDNSConfigEntry.value is True or self.usedhcpConfigEntry.value is False:
898 interfacesDnsLines = self.makeLineDnsNameservers([self.manualPrimaryDNS.value, self.manualSecondaryDNS.value])
899 if interfacesDnsLines == "" :
900 interfacesDnsLines = False
901 iNetwork.setAdapterAttribute(self.iface, "dns-nameservers", interfacesDnsLines)
903 iNetwork.setAdapterAttribute(self.iface, "dns-nameservers", False)
905 iNetwork.setAdapterAttribute(self.iface, "up", False)
906 iNetwork.deactivateInterface(self.iface)
908 if self.useWlCommand:
909 contents = '\tpre-up wl-config.sh -m %s -k %s -s "%s" \n' % (self.methodConfigEntry.value, self.keyConfigEntry.value, self.ssidConfigEntry.value)
910 contents += '\tpost-down wl-down.sh\n'
912 wpaSupplicantName = self.getWpaSupplicantName(self.iface)
913 contents = "\tpre-up wpa_supplicant -i"+self.iface+" -c%s -B -D" % (wpaSupplicantName) +iNetwork.detectWlanModule(self.iface)+"\n"
914 contents += "\tpost-down wpa_cli terminate\n"
915 iNetwork.setAdapterAttribute(self.iface, "configStrings", contents)
916 iNetwork.writeNetworkConfig()
917 iNetwork.restartNetwork(self.updateCurrentInterfaces)
918 self.configurationmsg = None
919 self.configurationmsg = self.session.openWithCallback(self.configFinished, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
921 def makeLineDnsNameservers(self, nameservers = []):
923 entry = ' '.join([("%d.%d.%d.%d" % tuple(x)) for x in nameservers if x != [0, 0, 0, 0] ])
925 line+="\tdns-nameservers %s\n" % entry
928 def updateCurrentInterfaces(self, ret):
930 iNetwork.getInterfaces(self.configurationMsgClose)
931 elif self.configurationmsg is not None:
932 self.configurationmsg.close(False)
934 def configurationMsgClose(self,ret):
935 if self.configurationmsg is not None:
937 self.configurationmsg.close(True)
939 self.configurationmsg.close(False)
941 def configFinished(self,data):
943 self.session.openWithCallback(self.configFinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
944 global ESSID_SELECTED_IN_APLIST
945 ESSID_SELECTED_IN_APLIST = None
947 self.session.openWithCallback(self.configFinishedCB, MessageBox, _("Network configuration is failed."), type = MessageBox.TYPE_INFO, timeout = 10)
949 def configFinishedCB(self, data):
953 def keyCancelConfirm(self, result):
955 self.onSelectHelpWindow()
958 if self.oldInterfaceState is False:
959 iNetwork.deactivateInterface(self.iface, self.keyCancelCB)
963 def keyCancel(self,yesno = True):
964 if self["config"].isChanged():
965 self.onDeselectHelpWindow()
966 self.session.openWithCallback(self.keyCancelConfirm, MessageBox, _("Really close without saving settings?"))
970 def keyCancelCB(self,data):
975 iNetwork.stopRestartConsole()
976 iNetwork.stopGetInterfacesConsole()
977 iNetwork.stopDeactivateInterfaceConsole()
979 SHOW_HIDDEN_NETWORK = False
980 class WlanScanAp(Screen,HelpableScreen):
982 <screen position="center,center" size="510,400" title="Wireless Network AP Scan..." >
983 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
984 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
986 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
987 <ePixmap pixmap="skin_default/buttons/green.png" position="185,360" size="140,40" alphatest="on" />
988 <ePixmap pixmap="skin_default/buttons/blue.png" position="360,360" size="140,40" alphatest="on" />
990 <widget source="key_red" render="Label" position="10,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
991 <widget source="key_green" render="Label" position="185,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
992 <widget source="key_blue" render="Label" position="360,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" foregroundColor="#ffffff" transparent="1" />
994 <widget name="aplist" position="20,20" size="230,275" backgroundColor="#371e1c1a" transparent="1" zPosition="10" scrollbarMode="showOnDemand" />
996 <widget source="ESSID" render="Label" position="265,70" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
997 <widget source="Address" render="Label" position="265,100" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
998 <widget source="Protocol" render="Label" position="265,130" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
999 <widget source="Frequency" render="Label" position="265,160" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
1000 <widget source="Channel" render="Label" position="265,190" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
1001 <widget source="Encryption key" render="Label" position="265,220" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
1002 <widget source="BitRate" render="Label" position="265,250" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
1003 <widget source="Status" render="Label" position="115,310" zPosition="1" size="300,30" font="Regular;18" halign="center" valign="center" />
1007 def __init__(self, session, iface):
1008 Screen.__init__(self,session)
1009 HelpableScreen.__init__(self)
1010 self.session = session
1012 self.wlanscanap = None
1016 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
1018 "up": (self.up, _("move up to previous entry")),
1019 "down": (self.down, _("move down to next entry")),
1020 "left": (self.left, _("move up to first entry")),
1021 "right": (self.right, _("move down to last entry")),
1024 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
1026 "cancel": (self.close, _("exit")),
1027 "ok": (self.ok, "select AP"),
1030 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
1032 "red": (self.close, _("exit")),
1033 "green": (self.ok, "select AP"),
1034 "blue": (self.startWlanConfig, "Edit Wireless settings"),
1037 self["aplist"] = MenuList(self.setApList)
1038 self["key_red"] = StaticText(_("Close"))
1039 self["key_green"] = StaticText(_("Select"))
1040 self["key_blue"] = StaticText(_("EditSetting"))
1041 self["Status"] = StaticText(_(" "))
1042 self["ESSID"] = StaticText(" ")
1043 self["Address"] = StaticText(" ")
1044 self["Protocol"] = StaticText(" ")
1045 self["Frequency"] = StaticText(" ")
1046 self["Channel"] = StaticText(" ")
1047 self["Encryption key"] = StaticText(" ")
1048 self["BitRate"] = StaticText(" ")
1049 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
1051 self.startupTimer = eTimer()
1052 self.startupTimer.callback.append(self.startup)
1054 self.activateIfaceTimer = eTimer()
1055 self.activateIfaceTimer.callback.append(self.activateIface)
1057 self.updateStatusTimer = eTimer()
1058 self.updateStatusTimer.callback.append(self.updateStatus)
1060 self.scanAplistTimer = eTimer()
1061 self.scanAplistTimer.callback.append(self.scanApList)
1064 self.onClose.append(self.__onClose)
1065 self.onShown.append(lambda: self.startupTimer.start(10, True))
1067 self.useWlCommand = os_path.exists("/tmp/bcm/%s"%iface)
1070 if self.oldInterfaceState is not True:
1071 self["Status"].setText(("Please wait for activating interface..."))
1072 self.activateIfaceTimer.start(10, True)
1074 self.updateStatusTimer.start(10, True)
1076 def activateIface(self):
1077 os_system("ifconfig "+self.iface+" up")
1078 iNetwork.setAdapterAttribute(self.iface, "up", True)
1080 if self.useWlCommand:
1083 self.updateStatusTimer.start(10, True)
1086 def updateStatus(self):
1087 self["Status"].setText(("Please wait for scanning AP..."))
1088 self.scanAplistTimer.stop()
1089 self.scanAplistTimer.start(10, True)
1091 def updateAPList(self):
1092 self.updateStatusTimer.stop()
1093 self.updateStatusTimer.start(5000, True)
1096 self["aplist"].pageUp()
1097 self.displayApInfo()
1100 self["aplist"].pageDown()
1101 self.displayApInfo()
1105 self.displayApInfo()
1108 self["aplist"].down()
1109 self.displayApInfo()
1112 global ESSID_SELECTED_IN_APLIST
1113 if self["aplist"].getCurrent() is not None:
1114 ESSID_SELECTED_IN_APLIST = self["aplist"].getCurrent()[0]
1117 def startWlanConfig(self): # key blue
1118 global ESSID_SELECTED_IN_APLIST
1119 if self["aplist"].getCurrent() is not None:
1120 ESSID_SELECTED_IN_APLIST = self["aplist"].getCurrent()[0]
1123 def getScanResult(self, wirelessObj):
1126 Iwscanresult = wirelessObj.scan()
1128 print "%s Interface doesn't support scanning.."%self.iface
1131 def scanApList(self):
1135 wirelessObj = Wireless(self.iface)
1136 Iwscanresult=self.getScanResult(wirelessObj)
1138 if Iwscanresult is None or len(Iwscanresult.aplist) == 0:
1139 self["Status"].setText(("NO AP detected"))
1144 (num_channels, frequencies) = wirelessObj.getChannelInfo()
1149 for ap in Iwscanresult:
1150 self.apList[index] = {}
1151 self.apList[index]["Address"] = ap.bssid
1152 if len(ap.essid) == 0:
1153 self.apList[index]["ESSID"] = None
1155 self.apList[index]["ESSID"] = ap.essid
1157 self.apList[index]["Protocol"] = ap.protocol
1158 self.apList[index]["Frequency"] = wirelessObj._formatFrequency(ap.frequency.getFrequency())
1160 self.apList[index]["Channel"] = frequencies.index(self.apList[index]["Frequency"]) + 1
1162 self.apList[index]["Channel"] = "Unknown"
1164 self.apList[index]["Quality"] = "%s/%s" % \
1165 ( ap.quality.quality, wirelessObj.getQualityMax().quality )
1166 self.apList[index]["Signal Level"] = "%s/%s" % \
1167 ( ap.quality.getSignallevel(), "100" )
1168 self.apList[index]["Noise Level"] = "%s/%s" % \
1169 ( ap.quality.getNoiselevel(), "100" )
1171 # get encryption key on/off
1172 key_status = "Unknown"
1173 if (ap.encode.flags & wifi_flags.IW_ENCODE_DISABLED):
1175 elif (ap.encode.flags & wifi_flags.IW_ENCODE_NOKEY):
1176 if (ap.encode.length <= 0):
1178 self.apList[index]["Encryption key"] = key_status
1181 if len(ap.rate) > 0:
1182 if len(ap.rate[0]) > 0:
1183 self.apList[index]["BitRate"] = wirelessObj._formatBitrate(ap.rate[0][0])
1185 self.apList[index]["BitRate"] = ""
1192 for (ap_index, ap_info) in self.apList.items():
1193 essid = ap_info.get("ESSID", None)
1195 global SHOW_HIDDEN_NETWORK
1196 if SHOW_HIDDEN_NETWORK:
1197 essid = "# Hidden Network"
1200 self.setApList.append( (essid, int(ap_index)) )
1202 self["aplist"].setList(self.setApList)
1203 # print "menu aplist : ", self.setApList
1204 self["Status"].setText(("%d AP detected" % len(self.setApList)))
1205 self.displayApInfo()
1209 def displayApInfo(self):
1210 if self["aplist"].getCurrent() is not None:
1211 index = self["aplist"].getCurrent()[1]
1212 for key in ["Address", "ESSID", "Protocol", "Frequency", "Encryption key", "BitRate", "Channel"]:
1213 if self.apList[index].has_key(key) and self.apList[index][key] is not None:
1214 value = str(self.apList[index][key])
1217 self[key].setText(( "%s: %s" % (key, value) ))
1219 def __onClose(self):
1220 if self.oldInterfaceState is not True:
1221 os_system("ifconfig "+self.iface+" down")
1222 iNetwork.setAdapterAttribute(self.iface, "up", False)
1224 if self.useWlCommand:
1225 os_system("wl down")
1227 class NetworkAdapterTest(Screen):
1228 def __init__(self, session,iface):
1229 Screen.__init__(self, session)
1231 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
1233 self.onClose.append(self.cleanup)
1234 self.onHide.append(self.cleanup)
1236 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
1240 "up": lambda: self.updownhandler('up'),
1241 "down": lambda: self.updownhandler('down'),
1245 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1248 "back": self.cancel,
1250 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1252 "red": self.closeInfo,
1253 "back": self.closeInfo,
1255 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
1257 "green": self.KeyGreen,
1259 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
1261 "green": self.KeyGreenRestart,
1263 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
1265 "yellow": self.KeyYellow,
1268 self["shortcutsgreen_restart"].setEnabled(False)
1269 self["updown_actions"].setEnabled(False)
1270 self["infoshortcuts"].setEnabled(False)
1271 self.onClose.append(self.delTimer)
1272 self.onLayoutFinish.append(self.layoutFinished)
1273 self.steptimer = False
1275 self.activebutton = 0
1276 self.nextStepTimer = eTimer()
1277 self.nextStepTimer.callback.append(self.nextStepTimerFire)
1280 if self.oldInterfaceState is False:
1281 iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
1282 iNetwork.deactivateInterface(self.iface)
1285 def closeInfo(self):
1286 self["shortcuts"].setEnabled(True)
1287 self["infoshortcuts"].setEnabled(False)
1288 self["InfoText"].hide()
1289 self["InfoTextBorder"].hide()
1290 self["key_red"].setText(_("Close"))
1294 del self.nextStepTimer
1296 def nextStepTimerFire(self):
1297 self.nextStepTimer.stop()
1298 self.steptimer = False
1301 def updownhandler(self,direction):
1302 if direction == 'up':
1303 if self.activebutton >=2:
1304 self.activebutton -= 1
1306 self.activebutton = 6
1307 self.setActiveButton(self.activebutton)
1308 if direction == 'down':
1309 if self.activebutton <=5:
1310 self.activebutton += 1
1312 self.activebutton = 1
1313 self.setActiveButton(self.activebutton)
1315 def setActiveButton(self,button):
1317 self["EditSettingsButton"].setPixmapNum(0)
1318 self["EditSettings_Text"].setForegroundColorNum(0)
1319 self["NetworkInfo"].setPixmapNum(0)
1320 self["NetworkInfo_Text"].setForegroundColorNum(1)
1321 self["AdapterInfo"].setPixmapNum(1) # active
1322 self["AdapterInfo_Text"].setForegroundColorNum(2) # active
1324 self["AdapterInfo_Text"].setForegroundColorNum(1)
1325 self["AdapterInfo"].setPixmapNum(0)
1326 self["DhcpInfo"].setPixmapNum(0)
1327 self["DhcpInfo_Text"].setForegroundColorNum(1)
1328 self["NetworkInfo"].setPixmapNum(1) # active
1329 self["NetworkInfo_Text"].setForegroundColorNum(2) # active
1331 self["NetworkInfo"].setPixmapNum(0)
1332 self["NetworkInfo_Text"].setForegroundColorNum(1)
1333 self["IPInfo"].setPixmapNum(0)
1334 self["IPInfo_Text"].setForegroundColorNum(1)
1335 self["DhcpInfo"].setPixmapNum(1) # active
1336 self["DhcpInfo_Text"].setForegroundColorNum(2) # active
1338 self["DhcpInfo"].setPixmapNum(0)
1339 self["DhcpInfo_Text"].setForegroundColorNum(1)
1340 self["DNSInfo"].setPixmapNum(0)
1341 self["DNSInfo_Text"].setForegroundColorNum(1)
1342 self["IPInfo"].setPixmapNum(1) # active
1343 self["IPInfo_Text"].setForegroundColorNum(2) # active
1345 self["IPInfo"].setPixmapNum(0)
1346 self["IPInfo_Text"].setForegroundColorNum(1)
1347 self["EditSettingsButton"].setPixmapNum(0)
1348 self["EditSettings_Text"].setForegroundColorNum(0)
1349 self["DNSInfo"].setPixmapNum(1) # active
1350 self["DNSInfo_Text"].setForegroundColorNum(2) # active
1352 self["DNSInfo"].setPixmapNum(0)
1353 self["DNSInfo_Text"].setForegroundColorNum(1)
1354 self["EditSettingsButton"].setPixmapNum(1) # active
1355 self["EditSettings_Text"].setForegroundColorNum(2) # active
1356 self["AdapterInfo"].setPixmapNum(0)
1357 self["AdapterInfo_Text"].setForegroundColorNum(1)
1360 next = self.nextstep
1376 self.steptimer = True
1377 self.nextStepTimer.start(3000)
1378 self["key_yellow"].setText(_("Stop test"))
1381 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
1382 self["Adapter"].setForegroundColorNum(2)
1383 self["Adaptertext"].setForegroundColorNum(1)
1384 self["AdapterInfo_Text"].setForegroundColorNum(1)
1385 self["AdapterInfo_OK"].show()
1386 self.steptimer = True
1387 self.nextStepTimer.start(3000)
1390 self["Networktext"].setForegroundColorNum(1)
1391 self["Network"].setText(_("Please wait..."))
1392 self.AccessPointInfo(self.iface)
1393 self["NetworkInfo_Text"].setForegroundColorNum(1)
1394 self.steptimer = True
1395 self.nextStepTimer.start(3000)
1398 self["Dhcptext"].setForegroundColorNum(1)
1399 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
1400 self["Dhcp"].setForegroundColorNum(2)
1401 self["Dhcp"].setText(_("enabled"))
1402 self["DhcpInfo_Check"].setPixmapNum(0)
1404 self["Dhcp"].setForegroundColorNum(1)
1405 self["Dhcp"].setText(_("disabled"))
1406 self["DhcpInfo_Check"].setPixmapNum(1)
1407 self["DhcpInfo_Check"].show()
1408 self["DhcpInfo_Text"].setForegroundColorNum(1)
1409 self.steptimer = True
1410 self.nextStepTimer.start(3000)
1413 self["IPtext"].setForegroundColorNum(1)
1414 self["IP"].setText(_("Please wait..."))
1415 iNetwork.checkNetworkState(self.NetworkStatedataAvail)
1418 self.steptimer = False
1419 self.nextStepTimer.stop()
1420 self["DNStext"].setForegroundColorNum(1)
1421 self["DNS"].setText(_("Please wait..."))
1422 iNetwork.checkDNSLookup(self.DNSLookupdataAvail)
1425 self["shortcutsgreen"].setEnabled(False)
1426 self["shortcutsyellow"].setEnabled(True)
1427 self["updown_actions"].setEnabled(False)
1428 self["key_yellow"].setText("")
1429 self["key_green"].setText("")
1430 self.steptimer = True
1431 self.nextStepTimer.start(1000)
1433 def KeyGreenRestart(self):
1435 self.layoutFinished()
1436 self["Adapter"].setText((""))
1437 self["Network"].setText((""))
1438 self["Dhcp"].setText((""))
1439 self["IP"].setText((""))
1440 self["DNS"].setText((""))
1441 self["AdapterInfo_Text"].setForegroundColorNum(0)
1442 self["NetworkInfo_Text"].setForegroundColorNum(0)
1443 self["DhcpInfo_Text"].setForegroundColorNum(0)
1444 self["IPInfo_Text"].setForegroundColorNum(0)
1445 self["DNSInfo_Text"].setForegroundColorNum(0)
1446 self["shortcutsgreen_restart"].setEnabled(False)
1447 self["shortcutsgreen"].setEnabled(False)
1448 self["shortcutsyellow"].setEnabled(True)
1449 self["updown_actions"].setEnabled(False)
1450 self["key_yellow"].setText("")
1451 self["key_green"].setText("")
1452 self.steptimer = True
1453 self.nextStepTimer.start(1000)
1456 self["infoshortcuts"].setEnabled(True)
1457 self["shortcuts"].setEnabled(False)
1458 if self.activebutton == 1: # Adapter Check
1459 self["InfoText"].setText(_("This test detects your configured Wireless LAN-Adapter."))
1460 self["InfoTextBorder"].show()
1461 self["InfoText"].show()
1462 self["key_red"].setText(_("Back"))
1463 if self.activebutton == 2: #LAN Check
1464 self["InfoText"].setText(_("This test checks whether a network cable is connected to your Wireless LAN-Adapter."))
1465 self["InfoTextBorder"].show()
1466 self["InfoText"].show()
1467 self["key_red"].setText(_("Back"))
1468 if self.activebutton == 3: #DHCP Check
1469 self["InfoText"].setText(_("This test checks whether your Wireless LAN Adapter is set up for automatic IP Address configuration with DHCP.\nIf you get a \"disabled\" message:\n - then your Wireless 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."))
1470 self["InfoTextBorder"].show()
1471 self["InfoText"].show()
1472 self["key_red"].setText(_("Back"))
1473 if self.activebutton == 4: # IP Check
1474 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"))
1475 self["InfoTextBorder"].show()
1476 self["InfoText"].show()
1477 self["key_red"].setText(_("Back"))
1478 if self.activebutton == 5: # DNS Check
1479 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"))
1480 self["InfoTextBorder"].show()
1481 self["InfoText"].show()
1482 self["key_red"].setText(_("Back"))
1483 if self.activebutton == 6: # Edit Settings
1485 self.session.open(WlanConfig, self.iface)
1486 self["shortcuts"].setEnabled(True)
1487 self["infoshortcuts"].setEnabled(False)
1489 def KeyYellow(self):
1491 self["shortcutsgreen_restart"].setEnabled(True)
1492 self["shortcutsgreen"].setEnabled(False)
1493 self["shortcutsyellow"].setEnabled(False)
1494 self["key_green"].setText(_("Restart test"))
1495 self["key_yellow"].setText("")
1496 self.steptimer = False
1497 self.nextStepTimer.stop()
1499 def layoutFinished(self):
1500 self.setTitle(_("Network test: ") + iNetwork.getFriendlyAdapterName(self.iface) )
1501 self["shortcutsyellow"].setEnabled(False)
1502 self["AdapterInfo_OK"].hide()
1503 self["NetworkInfo_Check"].hide()
1504 self["DhcpInfo_Check"].hide()
1505 self["IPInfo_Check"].hide()
1506 self["DNSInfo_Check"].hide()
1507 self["EditSettings_Text"].hide()
1508 self["EditSettingsButton"].hide()
1509 self["InfoText"].hide()
1510 self["InfoTextBorder"].hide()
1511 self["key_yellow"].setText("")
1513 def setLabels(self):
1514 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1515 self["Adapter"] = MultiColorLabel()
1516 self["AdapterInfo"] = MultiPixmap()
1517 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1518 self["AdapterInfo_OK"] = Pixmap()
1520 if self.iface in iNetwork.wlan_interfaces:
1521 self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1523 self["Networktext"] = MultiColorLabel(_("Local Network"))
1525 self["Network"] = MultiColorLabel()
1526 self["NetworkInfo"] = MultiPixmap()
1527 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1528 self["NetworkInfo_Check"] = MultiPixmap()
1530 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1531 self["Dhcp"] = MultiColorLabel()
1532 self["DhcpInfo"] = MultiPixmap()
1533 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1534 self["DhcpInfo_Check"] = MultiPixmap()
1536 self["IPtext"] = MultiColorLabel(_("IP Address"))
1537 self["IP"] = MultiColorLabel()
1538 self["IPInfo"] = MultiPixmap()
1539 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1540 self["IPInfo_Check"] = MultiPixmap()
1542 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1543 self["DNS"] = MultiColorLabel()
1544 self["DNSInfo"] = MultiPixmap()
1545 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1546 self["DNSInfo_Check"] = MultiPixmap()
1548 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1549 self["EditSettingsButton"] = MultiPixmap()
1551 self["key_red"] = StaticText(_("Close"))
1552 self["key_green"] = StaticText(_("Start test"))
1553 self["key_yellow"] = StaticText(_("Stop test"))
1555 self["InfoTextBorder"] = Pixmap()
1556 self["InfoText"] = Label()
1558 def NetworkStatedataAvail(self,data):
1560 self["IP"].setForegroundColorNum(2)
1561 self["IP"].setText(_("confirmed"))
1562 self["IPInfo_Check"].setPixmapNum(0)
1564 self["IP"].setForegroundColorNum(1)
1565 self["IP"].setText(_("unconfirmed"))
1566 self["IPInfo_Check"].setPixmapNum(1)
1567 self["IPInfo_Check"].show()
1568 self["IPInfo_Text"].setForegroundColorNum(1)
1569 self.steptimer = True
1570 self.nextStepTimer.start(3000)
1572 def DNSLookupdataAvail(self,data):
1574 self["DNS"].setForegroundColorNum(2)
1575 self["DNS"].setText(_("confirmed"))
1576 self["DNSInfo_Check"].setPixmapNum(0)
1578 self["DNS"].setForegroundColorNum(1)
1579 self["DNS"].setText(_("unconfirmed"))
1580 self["DNSInfo_Check"].setPixmapNum(1)
1581 self["DNSInfo_Check"].show()
1582 self["DNSInfo_Text"].setForegroundColorNum(1)
1583 self["EditSettings_Text"].show()
1584 self["EditSettingsButton"].setPixmapNum(1)
1585 self["EditSettings_Text"].setForegroundColorNum(2) # active
1586 self["EditSettingsButton"].show()
1587 self["key_yellow"].setText("")
1588 self["key_green"].setText(_("Restart test"))
1589 self["shortcutsgreen"].setEnabled(False)
1590 self["shortcutsgreen_restart"].setEnabled(True)
1591 self["shortcutsyellow"].setEnabled(False)
1592 self["updown_actions"].setEnabled(True)
1593 self.activebutton = 6
1595 def getInfoCB(self,status):
1596 if status is not None:
1597 if status.startswith("No Connection") or status.startswith("Not-Associated") or status == False:
1598 self["Network"].setForegroundColorNum(1)
1599 self["Network"].setText(_("disconnected"))
1600 self["NetworkInfo_Check"].setPixmapNum(1)
1601 self["NetworkInfo_Check"].show()
1603 self["Network"].setForegroundColorNum(2)
1604 self["Network"].setText(_("connected"))
1605 self["NetworkInfo_Check"].setPixmapNum(0)
1606 self["NetworkInfo_Check"].show()
1609 iNetwork.stopLinkStateConsole()
1610 iNetwork.stopPingConsole()
1611 iNetwork.stopDNSConsole()
1613 def AccessPointInfo(self,iface):
1614 cmd = "iwconfig %s"%iface
1615 self.iwconfigConsole = Console()
1616 self.iwconfigConsole.ePopen(cmd,self.readAP,self.getInfoCB)
1618 def readAP(self,result,retval,extra_args):
1619 (callback) = extra_args
1621 if self.iwconfigConsole is not None:
1623 self.iwconfigConsole = None
1624 for content in result.splitlines():
1625 if 'Access Point' in content:
1626 self.apState = content.strip().split('Access Point: ')[1]
1627 callback(self.apState)
1629 callback(self.apState)
1631 class Wlanstatus(Screen):
1633 <screen position="center,center" size="510,400" title="Wireless Network Status..." >
1634 <widget source="status" render="Label" position="5,15" size="500,350" font="Regular;18" zPosition="1" />
1636 <ePixmap pixmap="skin_default/buttons/red.png" position="185,360" size="140,40" alphatest="on" />
1637 <widget source="key_red" render="Label" position="185,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
1640 def __init__(self, session,iface):
1641 Screen.__init__(self,session)
1642 self.session = session
1644 self["status"] = StaticText(_("Wait a moment..."))
1645 self["key_red"] = StaticText(_("Close"))
1646 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
1649 "cancel": self.close,
1653 self.onClose.append(self.cleanup)
1655 def readstatus(self):
1656 self.wlanstatus = Console()
1657 cmd1 = "iwconfig "+self.iface
1658 self.wlanstatus.ePopen(cmd1, self.iwconfigfinnished,self.statusdisplay)
1660 def iwconfigfinnished(self, result, retval,extra_args):
1662 (statecallback) = extra_args
1663 if self.wlanstatus is not None:
1665 statecallback(result)
1672 def statusdisplay(self,data):
1674 self["status"].setText(_("No information..."))
1676 self["status"].setText(data)
1682 self.stopWlanStatusConsole()
1684 def stopWlanStatusConsole(self):
1685 if self.wlanstatus is not None:
1686 if len(self.wlanstatus.appContainers):
1687 for name in self.wlanstatus.appContainers.keys():
1688 self.wlanstatus.kill(name)
1690 def openconfig(session, **kwargs):
1691 session.open(WlanSelection)
1693 def selSetup(menuid, **kwargs):
1695 if menuid != "system":
1698 for x in iNetwork.getInstalledAdapters():
1699 if x.startswith('eth'):
1703 return [(_("Wireless LAN Setup"), openconfig, "wlansetup_config", 80)]
1708 def Plugins(**kwargs):
1709 return PluginDescriptor(name=_("Wireless LAN Setup"), description="Wireless LAN Setup", where = PluginDescriptor.WHERE_MENU, fnc=selSetup)