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")
140 return _("Unknown network adapter")
142 def isRalinkModule(self, iface):
143 # check vendor ID for lagacy driver
144 vendorID = "148f" # ralink vendor ID
145 idVendorPath = "/sys/class/net/%s/device/idVendor" % iface
146 if access(idVendorPath, R_OK):
147 fd = open(idVendorPath, "r")
148 data = fd.read().strip()
151 # print "Vendor ID : %s" % data
156 # check sys driver path for kernel driver
157 ralinkKmod = "rt2800usb" # ralink kernel driver name
158 driverPath = "/sys/class/net/%s/device/driver/" % iface
159 if os_path.exists(driverPath):
160 driverName = os_path.basename(os_path.realpath(driverPath))
162 # print "driverName : %s" % driverName
164 if driverName == ralinkKmod:
170 iNetwork.stopGetInterfacesConsole()
172 class WlanSetup(Screen,HelpableScreen):
174 <screen position="center,center" size="510,400" title="Wireless Network Setup Menu..." >
175 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
176 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
178 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
179 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
181 <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" />
182 <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" />
184 <widget name="menulist" position="20,20" size="230,260" transparent="1" backgroundColor="#371e1c1a" zPosition="10" scrollbarMode="showOnDemand" />
185 <widget source="description" render="Label" position="305,10" size="195,300" font="Regular;19" halign="center" valign="center" />
188 def __init__(self, session, ifaces):
189 Screen.__init__(self, session)
190 HelpableScreen.__init__(self)
191 self.session = session
193 self.restartLanRef = None
194 self.LinkState = None
195 self.mainmenu = self.MakeMenu()
196 self["menulist"] = MenuList(self.mainmenu)
197 self["key_red"] = StaticText(_("Close"))
198 self["key_green"] = StaticText(_("Select"))
199 self["description"] = StaticText()
200 self["IFtext"] = StaticText()
201 self["IF"] = StaticText()
202 self.onLayoutFinish.append(self.loadDescription)
204 self.oktext = _("Press OK on your remote control to continue.")
206 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
208 "up": (self.up, _("move up to previous entry")),
209 "down": (self.down, _("move down to next entry")),
210 "left": (self.left, _("move up to first entry")),
211 "right": (self.right, _("move down to last entry")),
214 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
216 "cancel": (self.close, _("exit networkadapter setup menu")),
217 "ok": (self.ok, _("select menu entry")),
220 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
222 "red": (self.close, _("exit networkadapter setup menu")),
223 "green": (self.ok, _("select menu entry")),
226 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
236 self.onClose.append(self.cleanup)
238 def loadDescription(self):
239 if self["menulist"].getCurrent()[1] == 'setting':
240 self["description"].setText(_("Edit the network configuration of your STB.\n" ) + self.oktext )
241 if self["menulist"].getCurrent()[1] == 'scanap':
242 self["description"].setText(_("Scan your network for wireless access points and connect to them using your selected wireless device.\n" ) + self.oktext )
243 if self["menulist"].getCurrent()[1] == 'dns':
244 self["description"].setText(_("Edit the Nameserver configuration of your STB.\n" ) + self.oktext )
245 if self["menulist"].getCurrent()[1] == 'status':
246 self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
247 if self["menulist"].getCurrent()[1] == 'test':
248 self["description"].setText(_("Test the network configuration of your STB.\n" ) + self.oktext )
249 if self["menulist"].getCurrent()[1] == 'restart':
250 self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
253 self["menulist"].up()
254 self.loadDescription()
257 self["menulist"].down()
258 self.loadDescription()
261 self["menulist"].pageUp()
262 self.loadDescription()
265 self["menulist"].pageDown()
266 self.loadDescription()
270 if self["menulist"].getCurrent()[1] == 'setting':
271 self.session.openWithCallback(self.checklist, WlanConfig, self.iface)
272 elif self["menulist"].getCurrent()[1] == 'scanap':
273 self.session.openWithCallback(self.WlanScanApCallback, WlanScanAp, self.iface)
274 elif self["menulist"].getCurrent()[1] == 'dns':
275 self.session.open(NameserverSetup)
276 elif self["menulist"].getCurrent()[1] == 'status':
277 self.session.open(Wlanstatus, self.iface)
278 elif self["menulist"].getCurrent()[1] == 'test':
279 self.session.openWithCallback(self.checklist,NetworkAdapterTest,self.iface)
280 elif self["menulist"].getCurrent()[1] == 'restart':
281 self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
284 self["menulist"].setList(self.MakeMenu())
288 menu.append((_("Adapter settings"), "setting"))
289 menu.append((_("Scan Wireless AP"), "scanap"))
290 # menu.append((_("Nameserver settings"), "dns"))
291 if iNetwork.getAdapterAttribute(self.iface, "up"):
292 menu.append((_("Show WLAN Status"), "status"))
293 menu.append((_("Network test"), "test"))
294 menu.append((_("Restart network"), "restart"))
298 def WlanScanApCallback(self, essid = None):
299 if essid is not None:
300 self.session.openWithCallback(self.checklist, WlanConfig, self.iface)
302 def restartLan(self, ret = False):
304 iNetwork.restartNetwork(self.restartLanDataAvail)
305 self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while your network is restarting..."), type = MessageBox.TYPE_INFO, enable_input = False)
307 def restartLanDataAvail(self, data):
309 iNetwork.getInterfaces(self.getInterfacesDataAvail)
311 def getInterfacesDataAvail(self, data):
313 self.restartLanRef.close(True)
315 def restartfinishedCB(self,data):
317 self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 5, default = False)
320 iNetwork.stopRestartConsole()
321 iNetwork.stopGetInterfacesConsole()
323 ESSID_SELECTED_IN_APLIST = None
324 CHECK_NETWORK_SHARE = False
326 class WlanConfig(Screen, ConfigListScreen, HelpableScreen):
328 <screen position="center,center" size="510,400" title="Wireless Network Configuration..." >
329 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
330 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
332 <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" />
333 <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" />
335 <widget name="config" position="10,10" backgroundColor="#371e1c1a" transparent="1" size="480,195" scrollbarMode="showOnDemand" />
336 <ePixmap pixmap="skin_default/div-h.png" position="0,210" zPosition="1" size="560,2" />
337 <widget source="ipaddresstext" render="Label" position="100,220" zPosition="1" size="190,21" font="Regular;19" halign="Left" valign="center" />
338 <widget source="ipaddress" render="Label" position="300,220" zPosition="1" size="150,26" font="Regular;20" halign="Left" valign="center" />
339 <widget source="netmasktext" render="Label" position="100,245" zPosition="1" size="190,21" font="Regular;19" halign="Left" valign="center" />
340 <widget source="netmask" render="Label" position="300,245" zPosition="1" size="150,26" font="Regular;20" halign="Left" valign="center" />
341 <widget source="gatewaytext" render="Label" position="100,270" zPosition="1" size="190,21" font="Regular;19" halign="Left" valign="center" />
342 <widget source="gateway" render="Label" position="300,270" zPosition="1" size="150,26" font="Regular;20" halign="Left" valign="center" />
343 <widget source="DNS1text" render="Label" position="100,295" zPosition="1" size="190,21" font="Regular;19" halign="Left" valign="center" />
344 <widget source="DNS1" render="Label" position="300,295" zPosition="1" size="150,26" font="Regular;20" halign="Left" valign="center" />
345 <widget source="DNS2text" render="Label" position="100,320" zPosition="1" size="190,21" font="Regular;19" halign="Left" valign="center" />
346 <widget source="DNS2" render="Label" position="300,320" zPosition="1" size="150,26" font="Regular;20" halign="Left" valign="center" />
347 <widget name="VKeyIcon" pixmap="skin_default/buttons/key_text.png" position="460,230" zPosition="10" size="35,25" transparent="1" alphatest="on" />
348 <widget name="HelpWindow" pixmap="skin_default/buttons/key_text.png" position="383,420" zPosition="1" size="1,1" transparent="1" alphatest="on" />
351 def __init__(self, session, iface):
352 Screen.__init__(self,session)
353 self.session = session
354 self["key_red"] = StaticText(_("Close"))
355 self["key_green"] = StaticText(_("Ok"))
356 self["ipaddresstext"] = StaticText(_("IP Address"))
357 self["ipaddress"] = StaticText(_("[ N/A ]"))
358 self["netmasktext"] = StaticText(_("NetMask"))
359 self["netmask"] = StaticText(_("[ N/A ]"))
360 self["gatewaytext"] = StaticText(_("Gateway"))
361 self["gateway"] = StaticText(_("[ N/A ]"))
362 self["DNS1text"] = StaticText(_("Primary DNS"))
363 self["DNS1"] = StaticText(_("[ N/A ]"))
364 self["DNS2text"] = StaticText(_("Secondary DNS"))
365 self["DNS2"] = StaticText(_("[ N/A ]"))
366 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
368 "ok": self.saveWlanConfig,
369 "green": self.saveWlanConfig,
370 "cancel": self.keyCancel,
371 "red": self.keyCancel,
373 self["HelpWindow"] = Pixmap()
374 self["HelpWindow"].hide()
375 self["VKeyIcon"] = Pixmap()
376 self["VKeyIcon"].hide()
380 ConfigListScreen.__init__(self, self.list, session = self.session)
381 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
383 self.updateInterfaces(self.updateInterfaceCB)
384 self.onClose.append(self.cleanup)
386 def updateInterfaces(self,callback = None):
387 iNetwork.config_ready = False
388 iNetwork.msgPlugins()
389 iNetwork.getInterfaces(callback)
391 def updateInterfaceCB(self, ret=None):
393 print "getInterfaces Fail... "
398 def getWpaSupplicantName(self, iface):
399 return "/etc/wpa_supplicant.conf.%s" % iface
401 def readWpaSupplicantConf(self):
402 wpaSupplicantName = self.getWpaSupplicantName(self.iface)
405 if fileExists(wpaSupplicantName):
406 wpafd = open(wpaSupplicantName, "r")
407 lines = wpafd.readlines()
412 (key, value) = line.strip().split('=',1)
416 # if key not in ('ssid', 'ap_scan', 'scan_ssid', 'key_mgmt', 'proto', 'wep_key0', 'psk', '#psk'):
417 if key not in ('ssid', 'scan_ssid', 'key_mgmt', 'proto', 'wep_key0', 'psk', '#psk'):
421 data[key] = value.strip('"')
424 data[key] = value.strip()
426 wsconf["ssid"] = data.get("ssid", "INPUTSSID")
427 wsconf["hidden_ssid"] = data.get("scan_ssid") == '1' and True or False
429 key_mgmt = data.get("key_mgmt")
430 if key_mgmt == "NONE":
431 wep_key = data.get("wep_key0")
434 wsconf["encrypt_mothod"] = "None"
436 wsconf["encrypt_mothod"] = "wep"
438 if wep_key.startswith('"') and wep_key.endswith('"'):
439 wsconf["wep_keytype"] = "ascii"
440 wsconf["key"] = wep_key.strip('"')
442 wsconf["wep_keytype"] = "hex"
443 wsconf["key"] = wep_key
445 elif key_mgmt == "WPA-PSK":
446 proto = data.get("proto")
449 wsconf["encrypt_mothod"] = "wpa"
452 wsconf["encrypt_mothod"] = "wpa2"
454 elif proto in ( "WPA RSN", "WPA WPA2"):
455 wsconf["encrypt_mothod"] = "wpa/wpa2"
458 wsconf["encrypt_mothod"] = "wpa2"
460 psk = data.get("#psk")
462 wsconf["key"] = psk.strip('"')
464 wsconf["key"] = data.get("psk")
466 wsconf["encrypt_mothod"] = "wpa2"
470 if wsconf.get("ssid") is None:
471 wsconf["ssid"] = "INPUTSSID"
472 if wsconf.get("hidden_ssid") is None:
473 wsconf["hidden_ssid"] = False
474 if wsconf.get("encrypt_mothod") is None:
475 wsconf["encrypt_mothod"] = "wpa2"
476 if wsconf.get("wep_keytype") is None:
477 wsconf["wep_keytype"] = "ascii"
478 if wsconf.get("key") is None:
479 wsconf["key"] = "XXXXXXXX"
482 # for (k,v) in wsconf.items():
483 # print "[wsconf][%s] %s" % (k , v)
487 def displayIP(self, domain, entry):
488 text = entry.getText()
489 if text is not None and text != "0.0.0.0":
490 self[domain].setText(entry.getText())
492 self[domain].setText(_("N/A"))
494 def createConfig(self):
495 # activate Interface setup
496 self.activateInterfaceEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "up") or False))
498 self.usedhcpConfigEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "dhcp") or False))
501 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
502 usegatewayDefault=True
504 usegatewayDefault=False
505 self.usegatewayConfigEntry = NoSave(ConfigYesNo(default=usegatewayDefault))
507 self.gatewayConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0]))
510 self.IPConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip") or [0,0,0,0]))
511 self.netmaskConfigEntry = NoSave(ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0]))
514 if iNetwork.getAdapterAttribute(self.iface, "dns-nameservers"):
518 self.useDNSConfigEntry = NoSave(ConfigYesNo(default=dnsDefault or False))
520 nameserver = (iNetwork.getNameserverList() + [[0,0,0,0]] * 2)[0:2]
521 self.primaryDNS = NoSave(ConfigIP(default=nameserver[0]))
522 self.secondaryDNS = NoSave(ConfigIP(default=nameserver[1]))
524 self.displayIP("ipaddress", self.IPConfigEntry)
525 self.displayIP("netmask", self.netmaskConfigEntry)
526 self.displayIP("gateway", self.gatewayConfigEntry)
527 self.displayIP("DNS1", self.primaryDNS)
528 self.displayIP("DNS2", self.secondaryDNS)
530 # readWPASupplicantConf
531 wsconf = self.readWpaSupplicantConf()
534 encryptionChoices = [("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")), ("wpa/wpa2", _("WPA/WPA2")), ("None", _("No Encrypt")) ]
535 self.methodConfigEntry = NoSave(ConfigSelection(default = wsconf["encrypt_mothod"], choices = encryptionChoices))
538 keytypeChoices = [("ascii", _("ASCII")), ("hex", _("HEX"))]
539 self.keytypeConfigEntry = NoSave(ConfigSelection(default = wsconf["wep_keytype"], choices = keytypeChoices))
542 self.keyConfigEntry = NoSave(ConfigPassword(default = wsconf["key"], visible_width = 50, fixed_size = False))
545 self.hiddenssidConfigEntry = NoSave(ConfigYesNo(default = wsconf["hidden_ssid"]))
549 global ESSID_SELECTED_IN_APLIST
550 if ESSID_SELECTED_IN_APLIST:
551 essidDefault = ESSID_SELECTED_IN_APLIST
553 essidDefault = wsconf["ssid"]
555 self.ssidConfigEntry = NoSave(ConfigText(default = essidDefault, visible_width = 50, fixed_size = False))
557 def createSetup(self):
559 self.usedeviceEntry = getConfigListEntry(_("Use Device"), self.activateInterfaceEntry)
560 self.usedhcpEntry = getConfigListEntry(_("Use DHCP"), self.usedhcpConfigEntry)
561 self.essidEntry = getConfigListEntry(_("SSID"), self.ssidConfigEntry)
562 self.hiddenessidEntry = getConfigListEntry(_("Hidden Network"), self.hiddenssidConfigEntry)
563 self.methodEntry = getConfigListEntry(_("Encrypt Method"), self.methodConfigEntry)
564 self.keytypeEntry = getConfigListEntry(_("Key Type"), self.keytypeConfigEntry)
565 self.keyEntry = getConfigListEntry(_("KEY"), self.keyConfigEntry)
567 self.ipEntry = getConfigListEntry(_("IP"), self.IPConfigEntry)
568 self.netmaskEntry = getConfigListEntry(_("NetMask"), self.netmaskConfigEntry)
570 self.usegatewayEntry = getConfigListEntry(_("Use Gateway"), self.usegatewayConfigEntry)
571 self.gatewayEntry = getConfigListEntry(_("Gateway"), self.gatewayConfigEntry)
573 manualNameservers = (iNetwork.getInterfacesNameserverList(self.iface) + [[0,0,0,0]] * 2)[0:2]
574 self.manualPrimaryDNS = NoSave(ConfigIP(default=manualNameservers[0]))
575 self.manualSecondaryDNS = NoSave(ConfigIP(default=manualNameservers[1]))
577 self.usednsEntry = getConfigListEntry(_("Use Manual dns-nameserver"), self.useDNSConfigEntry)
578 self.primaryDNSConfigEntry = getConfigListEntry(_('Primary DNS'), self.manualPrimaryDNS)
579 self.secondaryDNSConfigEntry = getConfigListEntry(_('Secondary DNS'), self.manualSecondaryDNS)
581 self.configList.append( self.usedeviceEntry )
582 if self.activateInterfaceEntry.value is True:
583 self.configList.append( self.usedhcpEntry )
585 if self.usedhcpConfigEntry.value is True:
586 self.configList.append(self.usednsEntry)
588 self.configList.append(self.ipEntry)
589 self.configList.append(self.netmaskEntry)
590 self.configList.append(self.usegatewayEntry)
592 if self.usegatewayConfigEntry.value is True:
593 self.configList.append(self.gatewayEntry)
595 if self.useDNSConfigEntry.value is True or self.usedhcpConfigEntry.value is False:
596 self.configList.append(self.primaryDNSConfigEntry)
597 self.configList.append(self.secondaryDNSConfigEntry)
599 self.configList.append( self.hiddenessidEntry )
600 self.configList.append( self.essidEntry )
601 self.configList.append( self.methodEntry )
603 if self.methodConfigEntry.value =="wep":
604 self.configList.append( self.keytypeEntry )
605 if self.methodConfigEntry.value != "None":
606 self.configList.append( self.keyEntry )
608 self["config"].list = self.configList
609 self["config"].l.setList(self.configList)
610 if not self.showTextIcon in self["config"].onSelectionChanged:
611 self["config"].onSelectionChanged.append(self.showTextIcon)
613 def showTextIcon(self):
614 if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
615 self["VKeyIcon"].show()
617 self["VKeyIcon"].hide()
619 def onSelectHelpWindow(self, ret = False):
620 if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
621 self["config"].getCurrent()[1].onSelect(self.session)
623 def onDeselectHelpWindow(self, ret = False):
624 if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
625 self["config"].getCurrent()[1].onDeselect(self.session)
628 ConfigListScreen.keyLeft(self)
632 ConfigListScreen.keyRight(self)
636 if self["config"].getCurrent() == self.usedeviceEntry or self["config"].getCurrent() == self.usedhcpEntry \
637 or self["config"].getCurrent() == self.usegatewayEntry or self["config"].getCurrent() == self.methodEntry \
638 or self["config"].getCurrent() == self.methodEntry or self["config"].getCurrent() == self.usednsEntry:
641 def saveWlanConfig(self):
643 self.onDeselectHelpWindow()
645 if self["config"].isChanged():
646 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Are you sure you want to restart your network interfaces?\n") ) )
648 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Network configuration is not changed....\n\nAre you sure you want to restart your network interfaces?\n") ) )
652 def checkNetworkConfig(self, ret = False):
654 self.onSelectHelpWindow()
656 elif len(self.ssidConfigEntry.value) == 0:
657 self.session.open(MessageBox, ("PLEASE INPUT SSID"), type = MessageBox.TYPE_ERROR, timeout = 10)
659 elif len(self.keyConfigEntry.value) == 0:
660 self.session.open(MessageBox, ("PLEASE INPUT ENCRYPT KEY"), type = MessageBox.TYPE_ERROR, timeout = 10)
663 global CHECK_NETWORK_SHARE
664 if CHECK_NETWORK_SHARE:
665 self.checkNetworkShares(self.confirmAnotherIfaces)
667 self.confirmAnotherIfaces()
669 def checkNetworkShares(self, callback):
670 cmd = "cat /proc/mounts"
671 data = popen(cmd).readlines()
672 networks = ['nfs','smbfs','ncp','coda']
674 split = line.strip().split(' ',3)
675 if split[2] in networks:
676 self.session.openWithCallback(self.onSelectHelpWindow, MessageBox, ("NOT deconfiguring network interfaces :\n network shares still mounted\n"), type = MessageBox.TYPE_ERROR, timeout = 10)
680 def confirmAnotherIfaces(self):
681 num_configured_if = len(iNetwork.getConfiguredAdapters())
682 if num_configured_if >= 1:
683 if num_configured_if == 1 and self.iface in iNetwork.getConfiguredAdapters():
684 self.confirmAnotherIfacesCB(False)
686 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)
688 self.confirmAnotherIfacesCB(False)
690 def isWPAMethod(self, method):
691 if method in ("wep", "None"):
696 def confirmAnotherIfacesCB(self, ret):
698 configuredInterfaces = iNetwork.getConfiguredAdapters()
699 for interface in configuredInterfaces:
700 if interface == self.iface:
702 iNetwork.setAdapterAttribute(interface, "up", False)
703 iNetwork.deactivateInterface(interface)
705 if not self.isWPAMethod(self.methodConfigEntry.value):
706 self.writeWpasupplicantConf()
710 def getWpaPhrase(self):
711 cmd = "wpa_passphrase '%s' %s" % (self.ssidConfigEntry.value, self.keyConfigEntry.value)
713 data = popen(cmd).readlines()
719 (key, value) = line.strip().split('=',1)
727 self.writeWpasupplicantConf(psk, plainpwd)
729 def writeWpasupplicantConf(self, passphrasekey=None, plainpwd=None):
730 wpaSupplicantName = self.getWpaSupplicantName(self.iface)
732 wpafd = open(wpaSupplicantName, "w")
734 self.session.open(MessageBox, _("%s open error." % wpaSupplicantName ), type = MessageBox.TYPE_ERROR, timeout = 10)
737 contents = "#WPA Supplicant Configuration by STB\n"
738 contents += "ctrl_interface=/var/run/wpa_supplicant\n"
739 contents += "eapol_version=1\n"
740 contents += "fast_reauth=1\n"
741 contents += "ap_scan=1\n"
742 contents += "network={\n"
744 contents += "\tssid=\""+self.ssidConfigEntry.value+"\"\n"
746 if self.hiddenssidConfigEntry.value is True:
747 contents += "\tscan_ssid=1\n"
749 contents += "\tscan_ssid=0\n"
751 if self.methodConfigEntry.value == "None":
752 contents += "\tkey_mgmt=NONE\n"
754 elif self.methodConfigEntry.value == "wep":
755 contents += "\tkey_mgmt=NONE\n"
756 contents += "\twep_key0="
757 if self.keytypeConfigEntry.value == "ascii":
758 contents += "\""+self.keyConfigEntry.value+"\"\n"
760 contents += self.keyConfigEntry.value+"\n"
763 if self.methodConfigEntry.value == "wpa":
764 contents += "\tkey_mgmt=WPA-PSK\n"
765 contents += "\tproto=WPA\n"
766 contents += "\tpairwise=CCMP TKIP\n"
767 contents += "\tgroup=CCMP TKIP\n"
768 elif self.methodConfigEntry.value == "wpa2":
769 contents += "\tkey_mgmt=WPA-PSK\n"
770 contents += "\tproto=RSN\n"
771 contents += "\tpairwise=CCMP TKIP\n"
772 contents += "\tgroup=CCMP TKIP\n"
774 contents += "\tkey_mgmt=WPA-PSK\n"
775 contents += "\tproto=WPA RSN\n"
776 contents += "\tpairwise=CCMP TKIP\n"
777 contents += "\tgroup=CCMP TKIP\n"
779 # print "plainpwd : ",plainpwd
780 # print "passphrasekey : ",passphrasekey
781 if plainpwd is not None and passphrasekey is not None:
783 contents += passphrasekey
785 contents += "\tpsk=%s\n" % self.keyConfigEntry.value
788 # print "content = \n"+contents
789 wpafd.write(contents)
791 self.writeNetConfig()
793 def writeNetConfig(self):
794 if self.activateInterfaceEntry.value is True:
795 iNetwork.setAdapterAttribute(self.iface, "up", True)
796 if self.usedhcpConfigEntry.value is True:
797 iNetwork.setAdapterAttribute(self.iface, "dhcp", True)
799 iNetwork.setAdapterAttribute(self.iface, "dhcp", False)
800 iNetwork.setAdapterAttribute(self.iface, "ip", self.IPConfigEntry.value)
801 iNetwork.setAdapterAttribute(self.iface, "netmask", self.netmaskConfigEntry.value)
802 if self.usegatewayConfigEntry.value is True:
803 iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value)
804 if self.useDNSConfigEntry.value is True or self.usedhcpConfigEntry.value is False:
805 interfacesDnsLines = self.makeLineDnsNameservers([self.manualPrimaryDNS.value, self.manualSecondaryDNS.value])
806 if interfacesDnsLines == "" :
807 interfacesDnsLines = False
808 iNetwork.setAdapterAttribute(self.iface, "dns-nameservers", interfacesDnsLines)
810 iNetwork.setAdapterAttribute(self.iface, "dns-nameservers", False)
812 iNetwork.setAdapterAttribute(self.iface, "up", False)
813 iNetwork.deactivateInterface(self.iface)
815 wpaSupplicantName = self.getWpaSupplicantName(self.iface)
816 contents = "\tpre-up wpa_supplicant -i"+self.iface+" -c%s -B -D" % (wpaSupplicantName) +iNetwork.detectWlanModule(self.iface)+"\n"
817 contents += "\tpost-down wpa_cli terminate\n"
818 iNetwork.setAdapterAttribute(self.iface, "configStrings", contents)
819 iNetwork.writeNetworkConfig()
820 iNetwork.restartNetwork(self.updateCurrentInterfaces)
821 self.configurationmsg = None
822 self.configurationmsg = self.session.openWithCallback(self.configFinished, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
824 def makeLineDnsNameservers(self, nameservers = []):
826 entry = ' '.join([("%d.%d.%d.%d" % tuple(x)) for x in nameservers if x != [0, 0, 0, 0] ])
828 line+="\tdns-nameservers %s\n" % entry
831 def updateCurrentInterfaces(self, ret):
833 iNetwork.getInterfaces(self.configurationMsgClose)
834 elif self.configurationmsg is not None:
835 self.configurationmsg.close(False)
837 def configurationMsgClose(self,ret):
838 if self.configurationmsg is not None:
840 self.configurationmsg.close(True)
842 self.configurationmsg.close(False)
844 def configFinished(self,data):
846 self.session.openWithCallback(self.configFinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
847 global ESSID_SELECTED_IN_APLIST
848 ESSID_SELECTED_IN_APLIST = None
850 self.session.openWithCallback(self.configFinishedCB, MessageBox, _("Network configuration is failed."), type = MessageBox.TYPE_INFO, timeout = 10)
852 def configFinishedCB(self, data):
856 def keyCancelConfirm(self, result):
858 self.onSelectHelpWindow()
861 if self.oldInterfaceState is False:
862 iNetwork.deactivateInterface(self.iface, self.keyCancelCB)
866 def keyCancel(self,yesno = True):
867 if self["config"].isChanged():
868 self.onDeselectHelpWindow()
869 self.session.openWithCallback(self.keyCancelConfirm, MessageBox, _("Really close without saving settings?"))
873 def keyCancelCB(self,data):
878 iNetwork.stopRestartConsole()
879 iNetwork.stopGetInterfacesConsole()
880 iNetwork.stopDeactivateInterfaceConsole()
882 SHOW_HIDDEN_NETWORK = False
883 class WlanScanAp(Screen,HelpableScreen):
885 <screen position="center,center" size="510,400" title="Wireless Network AP Scan..." >
886 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
887 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
889 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
890 <ePixmap pixmap="skin_default/buttons/green.png" position="185,360" size="140,40" alphatest="on" />
891 <ePixmap pixmap="skin_default/buttons/blue.png" position="360,360" size="140,40" alphatest="on" />
893 <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" />
894 <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" />
895 <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" />
897 <widget name="aplist" position="20,20" size="230,275" backgroundColor="#371e1c1a" transparent="1" zPosition="10" scrollbarMode="showOnDemand" />
899 <widget source="ESSID" render="Label" position="265,70" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
900 <widget source="Address" render="Label" position="265,100" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
901 <widget source="Protocol" render="Label" position="265,130" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
902 <widget source="Frequency" render="Label" position="265,160" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
903 <widget source="Channel" render="Label" position="265,190" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
904 <widget source="Encryption key" render="Label" position="265,220" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
905 <widget source="BitRate" render="Label" position="265,250" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
906 <widget source="Status" render="Label" position="115,310" zPosition="1" size="300,30" font="Regular;18" halign="center" valign="center" />
910 def __init__(self, session, iface):
911 Screen.__init__(self,session)
912 HelpableScreen.__init__(self)
913 self.session = session
915 self.wlanscanap = None
919 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
921 "up": (self.up, _("move up to previous entry")),
922 "down": (self.down, _("move down to next entry")),
923 "left": (self.left, _("move up to first entry")),
924 "right": (self.right, _("move down to last entry")),
927 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
929 "cancel": (self.close, _("exit")),
930 "ok": (self.ok, "select AP"),
933 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
935 "red": (self.close, _("exit")),
936 "green": (self.ok, "select AP"),
937 "blue": (self.startWlanConfig, "Edit Wireless settings"),
940 self["aplist"] = MenuList(self.setApList)
941 self["key_red"] = StaticText(_("Close"))
942 self["key_green"] = StaticText(_("Select"))
943 self["key_blue"] = StaticText(_("EditSetting"))
944 self["Status"] = StaticText(_(" "))
945 self["ESSID"] = StaticText(" ")
946 self["Address"] = StaticText(" ")
947 self["Protocol"] = StaticText(" ")
948 self["Frequency"] = StaticText(" ")
949 self["Channel"] = StaticText(" ")
950 self["Encryption key"] = StaticText(" ")
951 self["BitRate"] = StaticText(" ")
952 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
954 self.startupTimer = eTimer()
955 self.startupTimer.callback.append(self.startup)
957 self.activateIfaceTimer = eTimer()
958 self.activateIfaceTimer.callback.append(self.activateIface)
960 self.updateStatusTimer = eTimer()
961 self.updateStatusTimer.callback.append(self.updateStatus)
963 self.scanAplistTimer = eTimer()
964 self.scanAplistTimer.callback.append(self.scanApList)
967 self.onClose.append(self.__onClose)
968 self.onShown.append(lambda: self.startupTimer.start(10, True))
971 if self.oldInterfaceState is not True:
972 self["Status"].setText(("Please wait for activating interface..."))
973 self.activateIfaceTimer.start(10, True)
975 self.updateStatusTimer.start(10, True)
977 def activateIface(self):
978 os_system("ifconfig "+self.iface+" up")
979 iNetwork.setAdapterAttribute(self.iface, "up", True)
980 self.updateStatusTimer.start(2000, True)
983 def updateStatus(self):
984 self["Status"].setText(("Please wait for scanning AP..."))
985 self.scanAplistTimer.stop()
986 self.scanAplistTimer.start(10, True)
988 def updateAPList(self):
989 self.updateStatusTimer.stop()
990 self.updateStatusTimer.start(8000, True)
993 self["aplist"].pageUp()
997 self["aplist"].pageDown()
1002 self.displayApInfo()
1005 self["aplist"].down()
1006 self.displayApInfo()
1009 global ESSID_SELECTED_IN_APLIST
1010 if self["aplist"].getCurrent() is not None:
1011 ESSID_SELECTED_IN_APLIST = self["aplist"].getCurrent()[0]
1014 def startWlanConfig(self): # key blue
1015 global ESSID_SELECTED_IN_APLIST
1016 if self["aplist"].getCurrent() is not None:
1017 ESSID_SELECTED_IN_APLIST = self["aplist"].getCurrent()[0]
1020 def getScanResult(self, wirelessObj):
1023 Iwscanresult = wirelessObj.scan()
1025 print "%s Interface doesn't support scanning.."%self.iface
1028 def scanApList(self):
1032 wirelessObj = Wireless(self.iface)
1033 Iwscanresult=self.getScanResult(wirelessObj)
1035 if Iwscanresult is None or len(Iwscanresult.aplist) == 0:
1036 self["Status"].setText(("NO AP detected"))
1040 (num_channels, frequencies) = wirelessObj.getChannelInfo()
1045 for ap in Iwscanresult:
1046 self.apList[index] = {}
1047 self.apList[index]["Address"] = ap.bssid
1048 if len(ap.essid) == 0:
1049 self.apList[index]["ESSID"] = None
1051 self.apList[index]["ESSID"] = ap.essid
1053 self.apList[index]["Protocol"] = ap.protocol
1054 self.apList[index]["Frequency"] = wirelessObj._formatFrequency(ap.frequency.getFrequency())
1056 self.apList[index]["Channel"] = frequencies.index(self.apList[index]["Frequency"]) + 1
1058 self.apList[index]["Channel"] = "Unknown"
1060 self.apList[index]["Quality"] = "%s/%s" % \
1061 ( ap.quality.quality, wirelessObj.getQualityMax().quality )
1062 self.apList[index]["Signal Level"] = "%s/%s" % \
1063 ( ap.quality.getSignallevel(), "100" )
1064 self.apList[index]["Noise Level"] = "%s/%s" % \
1065 ( ap.quality.getNoiselevel(), "100" )
1067 # get encryption key on/off
1068 key_status = "Unknown"
1069 if (ap.encode.flags & wifi_flags.IW_ENCODE_DISABLED):
1071 elif (ap.encode.flags & wifi_flags.IW_ENCODE_NOKEY):
1072 if (ap.encode.length <= 0):
1074 self.apList[index]["Encryption key"] = key_status
1077 if len(ap.rate) > 0:
1078 if len(ap.rate[0]) > 0:
1079 self.apList[index]["BitRate"] = wirelessObj._formatBitrate(ap.rate[0][0])
1081 self.apList[index]["BitRate"] = ""
1088 for (ap_index, ap_info) in self.apList.items():
1089 essid = ap_info.get("ESSID", None)
1091 global SHOW_HIDDEN_NETWORK
1092 if SHOW_HIDDEN_NETWORK:
1093 essid = "# Hidden Network"
1096 self.setApList.append( (essid, int(ap_index)) )
1098 self["aplist"].setList(self.setApList)
1099 # print "menu aplist : ", self.setApList
1100 self["Status"].setText(("%d AP detected" % len(self.setApList)))
1101 self.displayApInfo()
1105 def displayApInfo(self):
1106 if self["aplist"].getCurrent() is not None:
1107 index = self["aplist"].getCurrent()[1]
1108 for key in ["Address", "ESSID", "Protocol", "Frequency", "Encryption key", "BitRate", "Channel"]:
1109 if self.apList[index].has_key(key) and self.apList[index][key] is not None:
1110 value = str(self.apList[index][key])
1113 self[key].setText(( "%s: %s" % (key, value) ))
1115 def __onClose(self):
1116 if self.oldInterfaceState is not True:
1117 os_system("ifconfig "+self.iface+" down")
1118 iNetwork.setAdapterAttribute(self.iface, "up", False)
1120 class NetworkAdapterTest(Screen):
1121 def __init__(self, session,iface):
1122 Screen.__init__(self, session)
1124 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
1126 self.onClose.append(self.cleanup)
1127 self.onHide.append(self.cleanup)
1129 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
1133 "up": lambda: self.updownhandler('up'),
1134 "down": lambda: self.updownhandler('down'),
1138 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1141 "back": self.cancel,
1143 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1145 "red": self.closeInfo,
1146 "back": self.closeInfo,
1148 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
1150 "green": self.KeyGreen,
1152 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
1154 "green": self.KeyGreenRestart,
1156 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
1158 "yellow": self.KeyYellow,
1161 self["shortcutsgreen_restart"].setEnabled(False)
1162 self["updown_actions"].setEnabled(False)
1163 self["infoshortcuts"].setEnabled(False)
1164 self.onClose.append(self.delTimer)
1165 self.onLayoutFinish.append(self.layoutFinished)
1166 self.steptimer = False
1168 self.activebutton = 0
1169 self.nextStepTimer = eTimer()
1170 self.nextStepTimer.callback.append(self.nextStepTimerFire)
1173 if self.oldInterfaceState is False:
1174 iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
1175 iNetwork.deactivateInterface(self.iface)
1178 def closeInfo(self):
1179 self["shortcuts"].setEnabled(True)
1180 self["infoshortcuts"].setEnabled(False)
1181 self["InfoText"].hide()
1182 self["InfoTextBorder"].hide()
1183 self["key_red"].setText(_("Close"))
1187 del self.nextStepTimer
1189 def nextStepTimerFire(self):
1190 self.nextStepTimer.stop()
1191 self.steptimer = False
1194 def updownhandler(self,direction):
1195 if direction == 'up':
1196 if self.activebutton >=2:
1197 self.activebutton -= 1
1199 self.activebutton = 6
1200 self.setActiveButton(self.activebutton)
1201 if direction == 'down':
1202 if self.activebutton <=5:
1203 self.activebutton += 1
1205 self.activebutton = 1
1206 self.setActiveButton(self.activebutton)
1208 def setActiveButton(self,button):
1210 self["EditSettingsButton"].setPixmapNum(0)
1211 self["EditSettings_Text"].setForegroundColorNum(0)
1212 self["NetworkInfo"].setPixmapNum(0)
1213 self["NetworkInfo_Text"].setForegroundColorNum(1)
1214 self["AdapterInfo"].setPixmapNum(1) # active
1215 self["AdapterInfo_Text"].setForegroundColorNum(2) # active
1217 self["AdapterInfo_Text"].setForegroundColorNum(1)
1218 self["AdapterInfo"].setPixmapNum(0)
1219 self["DhcpInfo"].setPixmapNum(0)
1220 self["DhcpInfo_Text"].setForegroundColorNum(1)
1221 self["NetworkInfo"].setPixmapNum(1) # active
1222 self["NetworkInfo_Text"].setForegroundColorNum(2) # active
1224 self["NetworkInfo"].setPixmapNum(0)
1225 self["NetworkInfo_Text"].setForegroundColorNum(1)
1226 self["IPInfo"].setPixmapNum(0)
1227 self["IPInfo_Text"].setForegroundColorNum(1)
1228 self["DhcpInfo"].setPixmapNum(1) # active
1229 self["DhcpInfo_Text"].setForegroundColorNum(2) # active
1231 self["DhcpInfo"].setPixmapNum(0)
1232 self["DhcpInfo_Text"].setForegroundColorNum(1)
1233 self["DNSInfo"].setPixmapNum(0)
1234 self["DNSInfo_Text"].setForegroundColorNum(1)
1235 self["IPInfo"].setPixmapNum(1) # active
1236 self["IPInfo_Text"].setForegroundColorNum(2) # active
1238 self["IPInfo"].setPixmapNum(0)
1239 self["IPInfo_Text"].setForegroundColorNum(1)
1240 self["EditSettingsButton"].setPixmapNum(0)
1241 self["EditSettings_Text"].setForegroundColorNum(0)
1242 self["DNSInfo"].setPixmapNum(1) # active
1243 self["DNSInfo_Text"].setForegroundColorNum(2) # active
1245 self["DNSInfo"].setPixmapNum(0)
1246 self["DNSInfo_Text"].setForegroundColorNum(1)
1247 self["EditSettingsButton"].setPixmapNum(1) # active
1248 self["EditSettings_Text"].setForegroundColorNum(2) # active
1249 self["AdapterInfo"].setPixmapNum(0)
1250 self["AdapterInfo_Text"].setForegroundColorNum(1)
1253 next = self.nextstep
1269 self.steptimer = True
1270 self.nextStepTimer.start(3000)
1271 self["key_yellow"].setText(_("Stop test"))
1274 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
1275 self["Adapter"].setForegroundColorNum(2)
1276 self["Adaptertext"].setForegroundColorNum(1)
1277 self["AdapterInfo_Text"].setForegroundColorNum(1)
1278 self["AdapterInfo_OK"].show()
1279 self.steptimer = True
1280 self.nextStepTimer.start(3000)
1283 self["Networktext"].setForegroundColorNum(1)
1284 self["Network"].setText(_("Please wait..."))
1285 self.AccessPointInfo(self.iface)
1286 self["NetworkInfo_Text"].setForegroundColorNum(1)
1287 self.steptimer = True
1288 self.nextStepTimer.start(3000)
1291 self["Dhcptext"].setForegroundColorNum(1)
1292 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
1293 self["Dhcp"].setForegroundColorNum(2)
1294 self["Dhcp"].setText(_("enabled"))
1295 self["DhcpInfo_Check"].setPixmapNum(0)
1297 self["Dhcp"].setForegroundColorNum(1)
1298 self["Dhcp"].setText(_("disabled"))
1299 self["DhcpInfo_Check"].setPixmapNum(1)
1300 self["DhcpInfo_Check"].show()
1301 self["DhcpInfo_Text"].setForegroundColorNum(1)
1302 self.steptimer = True
1303 self.nextStepTimer.start(3000)
1306 self["IPtext"].setForegroundColorNum(1)
1307 self["IP"].setText(_("Please wait..."))
1308 iNetwork.checkNetworkState(self.NetworkStatedataAvail)
1311 self.steptimer = False
1312 self.nextStepTimer.stop()
1313 self["DNStext"].setForegroundColorNum(1)
1314 self["DNS"].setText(_("Please wait..."))
1315 iNetwork.checkDNSLookup(self.DNSLookupdataAvail)
1318 self["shortcutsgreen"].setEnabled(False)
1319 self["shortcutsyellow"].setEnabled(True)
1320 self["updown_actions"].setEnabled(False)
1321 self["key_yellow"].setText("")
1322 self["key_green"].setText("")
1323 self.steptimer = True
1324 self.nextStepTimer.start(1000)
1326 def KeyGreenRestart(self):
1328 self.layoutFinished()
1329 self["Adapter"].setText((""))
1330 self["Network"].setText((""))
1331 self["Dhcp"].setText((""))
1332 self["IP"].setText((""))
1333 self["DNS"].setText((""))
1334 self["AdapterInfo_Text"].setForegroundColorNum(0)
1335 self["NetworkInfo_Text"].setForegroundColorNum(0)
1336 self["DhcpInfo_Text"].setForegroundColorNum(0)
1337 self["IPInfo_Text"].setForegroundColorNum(0)
1338 self["DNSInfo_Text"].setForegroundColorNum(0)
1339 self["shortcutsgreen_restart"].setEnabled(False)
1340 self["shortcutsgreen"].setEnabled(False)
1341 self["shortcutsyellow"].setEnabled(True)
1342 self["updown_actions"].setEnabled(False)
1343 self["key_yellow"].setText("")
1344 self["key_green"].setText("")
1345 self.steptimer = True
1346 self.nextStepTimer.start(1000)
1349 self["infoshortcuts"].setEnabled(True)
1350 self["shortcuts"].setEnabled(False)
1351 if self.activebutton == 1: # Adapter Check
1352 self["InfoText"].setText(_("This test detects your configured Wireless LAN-Adapter."))
1353 self["InfoTextBorder"].show()
1354 self["InfoText"].show()
1355 self["key_red"].setText(_("Back"))
1356 if self.activebutton == 2: #LAN Check
1357 self["InfoText"].setText(_("This test checks whether a network cable is connected to your Wireless LAN-Adapter."))
1358 self["InfoTextBorder"].show()
1359 self["InfoText"].show()
1360 self["key_red"].setText(_("Back"))
1361 if self.activebutton == 3: #DHCP Check
1362 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."))
1363 self["InfoTextBorder"].show()
1364 self["InfoText"].show()
1365 self["key_red"].setText(_("Back"))
1366 if self.activebutton == 4: # IP Check
1367 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"))
1368 self["InfoTextBorder"].show()
1369 self["InfoText"].show()
1370 self["key_red"].setText(_("Back"))
1371 if self.activebutton == 5: # DNS Check
1372 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"))
1373 self["InfoTextBorder"].show()
1374 self["InfoText"].show()
1375 self["key_red"].setText(_("Back"))
1376 if self.activebutton == 6: # Edit Settings
1378 self.session.open(WlanConfig, self.iface)
1379 self["shortcuts"].setEnabled(True)
1380 self["infoshortcuts"].setEnabled(False)
1382 def KeyYellow(self):
1384 self["shortcutsgreen_restart"].setEnabled(True)
1385 self["shortcutsgreen"].setEnabled(False)
1386 self["shortcutsyellow"].setEnabled(False)
1387 self["key_green"].setText(_("Restart test"))
1388 self["key_yellow"].setText("")
1389 self.steptimer = False
1390 self.nextStepTimer.stop()
1392 def layoutFinished(self):
1393 self.setTitle(_("Network test: ") + iNetwork.getFriendlyAdapterName(self.iface) )
1394 self["shortcutsyellow"].setEnabled(False)
1395 self["AdapterInfo_OK"].hide()
1396 self["NetworkInfo_Check"].hide()
1397 self["DhcpInfo_Check"].hide()
1398 self["IPInfo_Check"].hide()
1399 self["DNSInfo_Check"].hide()
1400 self["EditSettings_Text"].hide()
1401 self["EditSettingsButton"].hide()
1402 self["InfoText"].hide()
1403 self["InfoTextBorder"].hide()
1404 self["key_yellow"].setText("")
1406 def setLabels(self):
1407 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1408 self["Adapter"] = MultiColorLabel()
1409 self["AdapterInfo"] = MultiPixmap()
1410 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1411 self["AdapterInfo_OK"] = Pixmap()
1413 if self.iface in iNetwork.wlan_interfaces:
1414 self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1416 self["Networktext"] = MultiColorLabel(_("Local Network"))
1418 self["Network"] = MultiColorLabel()
1419 self["NetworkInfo"] = MultiPixmap()
1420 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1421 self["NetworkInfo_Check"] = MultiPixmap()
1423 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1424 self["Dhcp"] = MultiColorLabel()
1425 self["DhcpInfo"] = MultiPixmap()
1426 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1427 self["DhcpInfo_Check"] = MultiPixmap()
1429 self["IPtext"] = MultiColorLabel(_("IP Address"))
1430 self["IP"] = MultiColorLabel()
1431 self["IPInfo"] = MultiPixmap()
1432 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1433 self["IPInfo_Check"] = MultiPixmap()
1435 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1436 self["DNS"] = MultiColorLabel()
1437 self["DNSInfo"] = MultiPixmap()
1438 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1439 self["DNSInfo_Check"] = MultiPixmap()
1441 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1442 self["EditSettingsButton"] = MultiPixmap()
1444 self["key_red"] = StaticText(_("Close"))
1445 self["key_green"] = StaticText(_("Start test"))
1446 self["key_yellow"] = StaticText(_("Stop test"))
1448 self["InfoTextBorder"] = Pixmap()
1449 self["InfoText"] = Label()
1451 def NetworkStatedataAvail(self,data):
1453 self["IP"].setForegroundColorNum(2)
1454 self["IP"].setText(_("confirmed"))
1455 self["IPInfo_Check"].setPixmapNum(0)
1457 self["IP"].setForegroundColorNum(1)
1458 self["IP"].setText(_("unconfirmed"))
1459 self["IPInfo_Check"].setPixmapNum(1)
1460 self["IPInfo_Check"].show()
1461 self["IPInfo_Text"].setForegroundColorNum(1)
1462 self.steptimer = True
1463 self.nextStepTimer.start(3000)
1465 def DNSLookupdataAvail(self,data):
1467 self["DNS"].setForegroundColorNum(2)
1468 self["DNS"].setText(_("confirmed"))
1469 self["DNSInfo_Check"].setPixmapNum(0)
1471 self["DNS"].setForegroundColorNum(1)
1472 self["DNS"].setText(_("unconfirmed"))
1473 self["DNSInfo_Check"].setPixmapNum(1)
1474 self["DNSInfo_Check"].show()
1475 self["DNSInfo_Text"].setForegroundColorNum(1)
1476 self["EditSettings_Text"].show()
1477 self["EditSettingsButton"].setPixmapNum(1)
1478 self["EditSettings_Text"].setForegroundColorNum(2) # active
1479 self["EditSettingsButton"].show()
1480 self["key_yellow"].setText("")
1481 self["key_green"].setText(_("Restart test"))
1482 self["shortcutsgreen"].setEnabled(False)
1483 self["shortcutsgreen_restart"].setEnabled(True)
1484 self["shortcutsyellow"].setEnabled(False)
1485 self["updown_actions"].setEnabled(True)
1486 self.activebutton = 6
1488 def getInfoCB(self,status):
1489 if status is not None:
1490 if status.startswith("No Connection") or status.startswith("Not-Associated") or status == False:
1491 self["Network"].setForegroundColorNum(1)
1492 self["Network"].setText(_("disconnected"))
1493 self["NetworkInfo_Check"].setPixmapNum(1)
1494 self["NetworkInfo_Check"].show()
1496 self["Network"].setForegroundColorNum(2)
1497 self["Network"].setText(_("connected"))
1498 self["NetworkInfo_Check"].setPixmapNum(0)
1499 self["NetworkInfo_Check"].show()
1502 iNetwork.stopLinkStateConsole()
1503 iNetwork.stopPingConsole()
1504 iNetwork.stopDNSConsole()
1506 def AccessPointInfo(self,iface):
1507 cmd = "iwconfig %s"%iface
1508 self.iwconfigConsole = Console()
1509 self.iwconfigConsole.ePopen(cmd,self.readAP,self.getInfoCB)
1511 def readAP(self,result,retval,extra_args):
1512 (callback) = extra_args
1514 if self.iwconfigConsole is not None:
1516 self.iwconfigConsole = None
1517 for content in result.splitlines():
1518 if 'Access Point' in content:
1519 self.apState = content.strip().split('Access Point: ')[1]
1520 callback(self.apState)
1522 callback(self.apState)
1524 class Wlanstatus(Screen):
1526 <screen position="center,center" size="510,400" title="Wireless Network Status..." >
1527 <widget source="status" render="Label" position="5,15" size="500,350" font="Regular;18" zPosition="1" />
1529 <ePixmap pixmap="skin_default/buttons/red.png" position="185,360" size="140,40" alphatest="on" />
1530 <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" />
1533 def __init__(self, session,iface):
1534 Screen.__init__(self,session)
1535 self.session = session
1537 self["status"] = StaticText(_("Wait a moment..."))
1538 self["key_red"] = StaticText(_("Close"))
1539 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
1542 "cancel": self.close,
1546 self.onClose.append(self.cleanup)
1548 def readstatus(self):
1549 self.wlanstatus = Console()
1550 cmd1 = "iwconfig "+self.iface
1551 self.wlanstatus.ePopen(cmd1, self.iwconfigfinnished,self.statusdisplay)
1553 def iwconfigfinnished(self, result, retval,extra_args):
1555 (statecallback) = extra_args
1556 if self.wlanstatus is not None:
1558 statecallback(result)
1565 def statusdisplay(self,data):
1567 self["status"].setText(_("No information..."))
1569 self["status"].setText(data)
1575 self.stopWlanStatusConsole()
1577 def stopWlanStatusConsole(self):
1578 if self.wlanstatus is not None:
1579 if len(self.wlanstatus.appContainers):
1580 for name in self.wlanstatus.appContainers.keys():
1581 self.wlanstatus.kill(name)
1583 def openconfig(session, **kwargs):
1584 session.open(WlanSelection)
1586 def selSetup(menuid, **kwargs):
1588 if menuid != "system":
1591 for x in iNetwork.getInstalledAdapters():
1592 if x.startswith('eth'):
1596 return [(_("Wireless LAN Setup"), openconfig, "wlansetup_config", 80)]
1601 def Plugins(**kwargs):
1602 return PluginDescriptor(name=_("Wireless LAN Setup"), description="Wireless LAN Setup", where = PluginDescriptor.WHERE_MENU, fnc=selSetup)