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(10, 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(5000, 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"))
1041 (num_channels, frequencies) = wirelessObj.getChannelInfo()
1046 for ap in Iwscanresult:
1047 self.apList[index] = {}
1048 self.apList[index]["Address"] = ap.bssid
1049 if len(ap.essid) == 0:
1050 self.apList[index]["ESSID"] = None
1052 self.apList[index]["ESSID"] = ap.essid
1054 self.apList[index]["Protocol"] = ap.protocol
1055 self.apList[index]["Frequency"] = wirelessObj._formatFrequency(ap.frequency.getFrequency())
1057 self.apList[index]["Channel"] = frequencies.index(self.apList[index]["Frequency"]) + 1
1059 self.apList[index]["Channel"] = "Unknown"
1061 self.apList[index]["Quality"] = "%s/%s" % \
1062 ( ap.quality.quality, wirelessObj.getQualityMax().quality )
1063 self.apList[index]["Signal Level"] = "%s/%s" % \
1064 ( ap.quality.getSignallevel(), "100" )
1065 self.apList[index]["Noise Level"] = "%s/%s" % \
1066 ( ap.quality.getNoiselevel(), "100" )
1068 # get encryption key on/off
1069 key_status = "Unknown"
1070 if (ap.encode.flags & wifi_flags.IW_ENCODE_DISABLED):
1072 elif (ap.encode.flags & wifi_flags.IW_ENCODE_NOKEY):
1073 if (ap.encode.length <= 0):
1075 self.apList[index]["Encryption key"] = key_status
1078 if len(ap.rate) > 0:
1079 if len(ap.rate[0]) > 0:
1080 self.apList[index]["BitRate"] = wirelessObj._formatBitrate(ap.rate[0][0])
1082 self.apList[index]["BitRate"] = ""
1089 for (ap_index, ap_info) in self.apList.items():
1090 essid = ap_info.get("ESSID", None)
1092 global SHOW_HIDDEN_NETWORK
1093 if SHOW_HIDDEN_NETWORK:
1094 essid = "# Hidden Network"
1097 self.setApList.append( (essid, int(ap_index)) )
1099 self["aplist"].setList(self.setApList)
1100 # print "menu aplist : ", self.setApList
1101 self["Status"].setText(("%d AP detected" % len(self.setApList)))
1102 self.displayApInfo()
1106 def displayApInfo(self):
1107 if self["aplist"].getCurrent() is not None:
1108 index = self["aplist"].getCurrent()[1]
1109 for key in ["Address", "ESSID", "Protocol", "Frequency", "Encryption key", "BitRate", "Channel"]:
1110 if self.apList[index].has_key(key) and self.apList[index][key] is not None:
1111 value = str(self.apList[index][key])
1114 self[key].setText(( "%s: %s" % (key, value) ))
1116 def __onClose(self):
1117 if self.oldInterfaceState is not True:
1118 os_system("ifconfig "+self.iface+" down")
1119 iNetwork.setAdapterAttribute(self.iface, "up", False)
1121 class NetworkAdapterTest(Screen):
1122 def __init__(self, session,iface):
1123 Screen.__init__(self, session)
1125 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
1127 self.onClose.append(self.cleanup)
1128 self.onHide.append(self.cleanup)
1130 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
1134 "up": lambda: self.updownhandler('up'),
1135 "down": lambda: self.updownhandler('down'),
1139 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1142 "back": self.cancel,
1144 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1146 "red": self.closeInfo,
1147 "back": self.closeInfo,
1149 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
1151 "green": self.KeyGreen,
1153 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
1155 "green": self.KeyGreenRestart,
1157 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
1159 "yellow": self.KeyYellow,
1162 self["shortcutsgreen_restart"].setEnabled(False)
1163 self["updown_actions"].setEnabled(False)
1164 self["infoshortcuts"].setEnabled(False)
1165 self.onClose.append(self.delTimer)
1166 self.onLayoutFinish.append(self.layoutFinished)
1167 self.steptimer = False
1169 self.activebutton = 0
1170 self.nextStepTimer = eTimer()
1171 self.nextStepTimer.callback.append(self.nextStepTimerFire)
1174 if self.oldInterfaceState is False:
1175 iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
1176 iNetwork.deactivateInterface(self.iface)
1179 def closeInfo(self):
1180 self["shortcuts"].setEnabled(True)
1181 self["infoshortcuts"].setEnabled(False)
1182 self["InfoText"].hide()
1183 self["InfoTextBorder"].hide()
1184 self["key_red"].setText(_("Close"))
1188 del self.nextStepTimer
1190 def nextStepTimerFire(self):
1191 self.nextStepTimer.stop()
1192 self.steptimer = False
1195 def updownhandler(self,direction):
1196 if direction == 'up':
1197 if self.activebutton >=2:
1198 self.activebutton -= 1
1200 self.activebutton = 6
1201 self.setActiveButton(self.activebutton)
1202 if direction == 'down':
1203 if self.activebutton <=5:
1204 self.activebutton += 1
1206 self.activebutton = 1
1207 self.setActiveButton(self.activebutton)
1209 def setActiveButton(self,button):
1211 self["EditSettingsButton"].setPixmapNum(0)
1212 self["EditSettings_Text"].setForegroundColorNum(0)
1213 self["NetworkInfo"].setPixmapNum(0)
1214 self["NetworkInfo_Text"].setForegroundColorNum(1)
1215 self["AdapterInfo"].setPixmapNum(1) # active
1216 self["AdapterInfo_Text"].setForegroundColorNum(2) # active
1218 self["AdapterInfo_Text"].setForegroundColorNum(1)
1219 self["AdapterInfo"].setPixmapNum(0)
1220 self["DhcpInfo"].setPixmapNum(0)
1221 self["DhcpInfo_Text"].setForegroundColorNum(1)
1222 self["NetworkInfo"].setPixmapNum(1) # active
1223 self["NetworkInfo_Text"].setForegroundColorNum(2) # active
1225 self["NetworkInfo"].setPixmapNum(0)
1226 self["NetworkInfo_Text"].setForegroundColorNum(1)
1227 self["IPInfo"].setPixmapNum(0)
1228 self["IPInfo_Text"].setForegroundColorNum(1)
1229 self["DhcpInfo"].setPixmapNum(1) # active
1230 self["DhcpInfo_Text"].setForegroundColorNum(2) # active
1232 self["DhcpInfo"].setPixmapNum(0)
1233 self["DhcpInfo_Text"].setForegroundColorNum(1)
1234 self["DNSInfo"].setPixmapNum(0)
1235 self["DNSInfo_Text"].setForegroundColorNum(1)
1236 self["IPInfo"].setPixmapNum(1) # active
1237 self["IPInfo_Text"].setForegroundColorNum(2) # active
1239 self["IPInfo"].setPixmapNum(0)
1240 self["IPInfo_Text"].setForegroundColorNum(1)
1241 self["EditSettingsButton"].setPixmapNum(0)
1242 self["EditSettings_Text"].setForegroundColorNum(0)
1243 self["DNSInfo"].setPixmapNum(1) # active
1244 self["DNSInfo_Text"].setForegroundColorNum(2) # active
1246 self["DNSInfo"].setPixmapNum(0)
1247 self["DNSInfo_Text"].setForegroundColorNum(1)
1248 self["EditSettingsButton"].setPixmapNum(1) # active
1249 self["EditSettings_Text"].setForegroundColorNum(2) # active
1250 self["AdapterInfo"].setPixmapNum(0)
1251 self["AdapterInfo_Text"].setForegroundColorNum(1)
1254 next = self.nextstep
1270 self.steptimer = True
1271 self.nextStepTimer.start(3000)
1272 self["key_yellow"].setText(_("Stop test"))
1275 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
1276 self["Adapter"].setForegroundColorNum(2)
1277 self["Adaptertext"].setForegroundColorNum(1)
1278 self["AdapterInfo_Text"].setForegroundColorNum(1)
1279 self["AdapterInfo_OK"].show()
1280 self.steptimer = True
1281 self.nextStepTimer.start(3000)
1284 self["Networktext"].setForegroundColorNum(1)
1285 self["Network"].setText(_("Please wait..."))
1286 self.AccessPointInfo(self.iface)
1287 self["NetworkInfo_Text"].setForegroundColorNum(1)
1288 self.steptimer = True
1289 self.nextStepTimer.start(3000)
1292 self["Dhcptext"].setForegroundColorNum(1)
1293 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
1294 self["Dhcp"].setForegroundColorNum(2)
1295 self["Dhcp"].setText(_("enabled"))
1296 self["DhcpInfo_Check"].setPixmapNum(0)
1298 self["Dhcp"].setForegroundColorNum(1)
1299 self["Dhcp"].setText(_("disabled"))
1300 self["DhcpInfo_Check"].setPixmapNum(1)
1301 self["DhcpInfo_Check"].show()
1302 self["DhcpInfo_Text"].setForegroundColorNum(1)
1303 self.steptimer = True
1304 self.nextStepTimer.start(3000)
1307 self["IPtext"].setForegroundColorNum(1)
1308 self["IP"].setText(_("Please wait..."))
1309 iNetwork.checkNetworkState(self.NetworkStatedataAvail)
1312 self.steptimer = False
1313 self.nextStepTimer.stop()
1314 self["DNStext"].setForegroundColorNum(1)
1315 self["DNS"].setText(_("Please wait..."))
1316 iNetwork.checkDNSLookup(self.DNSLookupdataAvail)
1319 self["shortcutsgreen"].setEnabled(False)
1320 self["shortcutsyellow"].setEnabled(True)
1321 self["updown_actions"].setEnabled(False)
1322 self["key_yellow"].setText("")
1323 self["key_green"].setText("")
1324 self.steptimer = True
1325 self.nextStepTimer.start(1000)
1327 def KeyGreenRestart(self):
1329 self.layoutFinished()
1330 self["Adapter"].setText((""))
1331 self["Network"].setText((""))
1332 self["Dhcp"].setText((""))
1333 self["IP"].setText((""))
1334 self["DNS"].setText((""))
1335 self["AdapterInfo_Text"].setForegroundColorNum(0)
1336 self["NetworkInfo_Text"].setForegroundColorNum(0)
1337 self["DhcpInfo_Text"].setForegroundColorNum(0)
1338 self["IPInfo_Text"].setForegroundColorNum(0)
1339 self["DNSInfo_Text"].setForegroundColorNum(0)
1340 self["shortcutsgreen_restart"].setEnabled(False)
1341 self["shortcutsgreen"].setEnabled(False)
1342 self["shortcutsyellow"].setEnabled(True)
1343 self["updown_actions"].setEnabled(False)
1344 self["key_yellow"].setText("")
1345 self["key_green"].setText("")
1346 self.steptimer = True
1347 self.nextStepTimer.start(1000)
1350 self["infoshortcuts"].setEnabled(True)
1351 self["shortcuts"].setEnabled(False)
1352 if self.activebutton == 1: # Adapter Check
1353 self["InfoText"].setText(_("This test detects your configured Wireless LAN-Adapter."))
1354 self["InfoTextBorder"].show()
1355 self["InfoText"].show()
1356 self["key_red"].setText(_("Back"))
1357 if self.activebutton == 2: #LAN Check
1358 self["InfoText"].setText(_("This test checks whether a network cable is connected to your Wireless LAN-Adapter."))
1359 self["InfoTextBorder"].show()
1360 self["InfoText"].show()
1361 self["key_red"].setText(_("Back"))
1362 if self.activebutton == 3: #DHCP Check
1363 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."))
1364 self["InfoTextBorder"].show()
1365 self["InfoText"].show()
1366 self["key_red"].setText(_("Back"))
1367 if self.activebutton == 4: # IP Check
1368 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"))
1369 self["InfoTextBorder"].show()
1370 self["InfoText"].show()
1371 self["key_red"].setText(_("Back"))
1372 if self.activebutton == 5: # DNS Check
1373 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"))
1374 self["InfoTextBorder"].show()
1375 self["InfoText"].show()
1376 self["key_red"].setText(_("Back"))
1377 if self.activebutton == 6: # Edit Settings
1379 self.session.open(WlanConfig, self.iface)
1380 self["shortcuts"].setEnabled(True)
1381 self["infoshortcuts"].setEnabled(False)
1383 def KeyYellow(self):
1385 self["shortcutsgreen_restart"].setEnabled(True)
1386 self["shortcutsgreen"].setEnabled(False)
1387 self["shortcutsyellow"].setEnabled(False)
1388 self["key_green"].setText(_("Restart test"))
1389 self["key_yellow"].setText("")
1390 self.steptimer = False
1391 self.nextStepTimer.stop()
1393 def layoutFinished(self):
1394 self.setTitle(_("Network test: ") + iNetwork.getFriendlyAdapterName(self.iface) )
1395 self["shortcutsyellow"].setEnabled(False)
1396 self["AdapterInfo_OK"].hide()
1397 self["NetworkInfo_Check"].hide()
1398 self["DhcpInfo_Check"].hide()
1399 self["IPInfo_Check"].hide()
1400 self["DNSInfo_Check"].hide()
1401 self["EditSettings_Text"].hide()
1402 self["EditSettingsButton"].hide()
1403 self["InfoText"].hide()
1404 self["InfoTextBorder"].hide()
1405 self["key_yellow"].setText("")
1407 def setLabels(self):
1408 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1409 self["Adapter"] = MultiColorLabel()
1410 self["AdapterInfo"] = MultiPixmap()
1411 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1412 self["AdapterInfo_OK"] = Pixmap()
1414 if self.iface in iNetwork.wlan_interfaces:
1415 self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1417 self["Networktext"] = MultiColorLabel(_("Local Network"))
1419 self["Network"] = MultiColorLabel()
1420 self["NetworkInfo"] = MultiPixmap()
1421 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1422 self["NetworkInfo_Check"] = MultiPixmap()
1424 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1425 self["Dhcp"] = MultiColorLabel()
1426 self["DhcpInfo"] = MultiPixmap()
1427 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1428 self["DhcpInfo_Check"] = MultiPixmap()
1430 self["IPtext"] = MultiColorLabel(_("IP Address"))
1431 self["IP"] = MultiColorLabel()
1432 self["IPInfo"] = MultiPixmap()
1433 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1434 self["IPInfo_Check"] = MultiPixmap()
1436 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1437 self["DNS"] = MultiColorLabel()
1438 self["DNSInfo"] = MultiPixmap()
1439 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1440 self["DNSInfo_Check"] = MultiPixmap()
1442 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1443 self["EditSettingsButton"] = MultiPixmap()
1445 self["key_red"] = StaticText(_("Close"))
1446 self["key_green"] = StaticText(_("Start test"))
1447 self["key_yellow"] = StaticText(_("Stop test"))
1449 self["InfoTextBorder"] = Pixmap()
1450 self["InfoText"] = Label()
1452 def NetworkStatedataAvail(self,data):
1454 self["IP"].setForegroundColorNum(2)
1455 self["IP"].setText(_("confirmed"))
1456 self["IPInfo_Check"].setPixmapNum(0)
1458 self["IP"].setForegroundColorNum(1)
1459 self["IP"].setText(_("unconfirmed"))
1460 self["IPInfo_Check"].setPixmapNum(1)
1461 self["IPInfo_Check"].show()
1462 self["IPInfo_Text"].setForegroundColorNum(1)
1463 self.steptimer = True
1464 self.nextStepTimer.start(3000)
1466 def DNSLookupdataAvail(self,data):
1468 self["DNS"].setForegroundColorNum(2)
1469 self["DNS"].setText(_("confirmed"))
1470 self["DNSInfo_Check"].setPixmapNum(0)
1472 self["DNS"].setForegroundColorNum(1)
1473 self["DNS"].setText(_("unconfirmed"))
1474 self["DNSInfo_Check"].setPixmapNum(1)
1475 self["DNSInfo_Check"].show()
1476 self["DNSInfo_Text"].setForegroundColorNum(1)
1477 self["EditSettings_Text"].show()
1478 self["EditSettingsButton"].setPixmapNum(1)
1479 self["EditSettings_Text"].setForegroundColorNum(2) # active
1480 self["EditSettingsButton"].show()
1481 self["key_yellow"].setText("")
1482 self["key_green"].setText(_("Restart test"))
1483 self["shortcutsgreen"].setEnabled(False)
1484 self["shortcutsgreen_restart"].setEnabled(True)
1485 self["shortcutsyellow"].setEnabled(False)
1486 self["updown_actions"].setEnabled(True)
1487 self.activebutton = 6
1489 def getInfoCB(self,status):
1490 if status is not None:
1491 if status.startswith("No Connection") or status.startswith("Not-Associated") or status == False:
1492 self["Network"].setForegroundColorNum(1)
1493 self["Network"].setText(_("disconnected"))
1494 self["NetworkInfo_Check"].setPixmapNum(1)
1495 self["NetworkInfo_Check"].show()
1497 self["Network"].setForegroundColorNum(2)
1498 self["Network"].setText(_("connected"))
1499 self["NetworkInfo_Check"].setPixmapNum(0)
1500 self["NetworkInfo_Check"].show()
1503 iNetwork.stopLinkStateConsole()
1504 iNetwork.stopPingConsole()
1505 iNetwork.stopDNSConsole()
1507 def AccessPointInfo(self,iface):
1508 cmd = "iwconfig %s"%iface
1509 self.iwconfigConsole = Console()
1510 self.iwconfigConsole.ePopen(cmd,self.readAP,self.getInfoCB)
1512 def readAP(self,result,retval,extra_args):
1513 (callback) = extra_args
1515 if self.iwconfigConsole is not None:
1517 self.iwconfigConsole = None
1518 for content in result.splitlines():
1519 if 'Access Point' in content:
1520 self.apState = content.strip().split('Access Point: ')[1]
1521 callback(self.apState)
1523 callback(self.apState)
1525 class Wlanstatus(Screen):
1527 <screen position="center,center" size="510,400" title="Wireless Network Status..." >
1528 <widget source="status" render="Label" position="5,15" size="500,350" font="Regular;18" zPosition="1" />
1530 <ePixmap pixmap="skin_default/buttons/red.png" position="185,360" size="140,40" alphatest="on" />
1531 <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" />
1534 def __init__(self, session,iface):
1535 Screen.__init__(self,session)
1536 self.session = session
1538 self["status"] = StaticText(_("Wait a moment..."))
1539 self["key_red"] = StaticText(_("Close"))
1540 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
1543 "cancel": self.close,
1547 self.onClose.append(self.cleanup)
1549 def readstatus(self):
1550 self.wlanstatus = Console()
1551 cmd1 = "iwconfig "+self.iface
1552 self.wlanstatus.ePopen(cmd1, self.iwconfigfinnished,self.statusdisplay)
1554 def iwconfigfinnished(self, result, retval,extra_args):
1556 (statecallback) = extra_args
1557 if self.wlanstatus is not None:
1559 statecallback(result)
1566 def statusdisplay(self,data):
1568 self["status"].setText(_("No information..."))
1570 self["status"].setText(data)
1576 self.stopWlanStatusConsole()
1578 def stopWlanStatusConsole(self):
1579 if self.wlanstatus is not None:
1580 if len(self.wlanstatus.appContainers):
1581 for name in self.wlanstatus.appContainers.keys():
1582 self.wlanstatus.kill(name)
1584 def openconfig(session, **kwargs):
1585 session.open(WlanSelection)
1587 def selSetup(menuid, **kwargs):
1589 if menuid != "system":
1592 for x in iNetwork.getInstalledAdapters():
1593 if x.startswith('eth'):
1597 return [(_("Wireless LAN Setup"), openconfig, "wlansetup_config", 80)]
1602 def Plugins(**kwargs):
1603 return PluginDescriptor(name=_("Wireless LAN Setup"), description="Wireless LAN Setup", where = PluginDescriptor.WHERE_MENU, fnc=selSetup)