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
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 import pythonwifi.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()
78 # print len(self["menulist"].list)
79 if len(self["menulist"].list) == 0:
80 self.session.open(MessageBox, (_("Can not find any WirelessLan Module\n")),MessageBox.TYPE_ERROR,5 )
82 ifaces=self["menulist"].getCurrent()[1]
86 self.session.open(WlanSetup,ifaces)
88 def getWlandevice(self):
90 for x in iNetwork.getInstalledAdapters():
91 if x.startswith('eth'):
93 description=self.getAdapterDescription(x)
94 if description == "Unknown network adapter":
95 list.append((description,x))
97 list.append((description + " (%s)"%x,x))
100 def getAdapterDescription(self, iface):
101 classdir = "/sys/class/net/" + iface + "/device/"
102 driverdir = "/sys/class/net/" + iface + "/device/driver/"
103 if os_path.exists(classdir):
104 files = listdir(classdir)
105 if 'driver' in files:
106 if os_path.realpath(driverdir).endswith('rtw_usb_drv'):
107 return _("Realtek")+ " " + _("WLAN adapter.")
108 elif os_path.realpath(driverdir).endswith('ath_pci'):
109 return _("Atheros")+ " " + _("WLAN adapter.")
110 elif os_path.realpath(driverdir).endswith('zd1211b'):
111 return _("Zydas")+ " " + _("WLAN adapter.")
112 elif os_path.realpath(driverdir).endswith('rt73'):
113 return _("Ralink")+ " " + _("WLAN adapter.")
114 elif os_path.realpath(driverdir).endswith('rt73usb'):
115 return _("Ralink")+ " " + _("WLAN adapter.")
117 return str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter")
119 return _("Unknown network adapter")
121 return _("Unknown network adapter")
124 iNetwork.stopGetInterfacesConsole()
126 class WlanSetup(Screen,HelpableScreen):
128 <screen position="center,center" size="510,400" title="Wireless Network Setup Menu..." >
129 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
130 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
132 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
133 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
135 <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" />
136 <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" />
138 <widget name="menulist" position="20,20" size="230,260" transparent="1" backgroundColor="#371e1c1a" zPosition="10" scrollbarMode="showOnDemand" />
139 <widget source="description" render="Label" position="305,10" size="195,300" font="Regular;19" halign="center" valign="center" />
142 def __init__(self, session, ifaces):
143 Screen.__init__(self, session)
144 HelpableScreen.__init__(self)
145 self.session = session
147 self.restartLanRef = None
148 self.LinkState = None
149 self.mainmenu = self.MakeMenu()
150 self["menulist"] = MenuList(self.mainmenu)
151 self["key_red"] = StaticText(_("Close"))
152 self["key_green"] = StaticText(_("Select"))
153 self["description"] = StaticText()
154 self["IFtext"] = StaticText()
155 self["IF"] = StaticText()
156 self["Statustext"] = StaticText()
157 self["statuspic"] = MultiPixmap()
158 self["statuspic"].hide()
159 self.onLayoutFinish.append(self.loadDescription)
161 self.oktext = _("Press OK on your remote control to continue.")
163 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
165 "up": (self.up, _("move up to previous entry")),
166 "down": (self.down, _("move down to next entry")),
167 "left": (self.left, _("move up to first entry")),
168 "right": (self.right, _("move down to last entry")),
171 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
173 "cancel": (self.close, _("exit networkadapter setup menu")),
174 "ok": (self.ok, _("select menu entry")),
177 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
179 "red": (self.close, _("exit networkadapter setup menu")),
180 "green": (self.ok, _("select menu entry")),
183 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
193 self.onClose.append(self.cleanup)
195 def loadDescription(self):
196 if self["menulist"].getCurrent()[1] == 'setting':
197 self["description"].setText(_("Edit the network configuration of your STB.\n" ) + self.oktext )
198 if self["menulist"].getCurrent()[1] == 'scanap':
199 self["description"].setText(_("Scan your network for wireless access points and connect to them using your selected wireless device.\n" ) + self.oktext )
200 if self["menulist"].getCurrent()[1] == 'dns':
201 self["description"].setText(_("Edit the Nameserver configuration of your STB.\n" ) + self.oktext )
202 if self["menulist"].getCurrent()[1] == 'status':
203 self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
204 if self["menulist"].getCurrent()[1] == 'test':
205 self["description"].setText(_("Test the network configuration of your STB.\n" ) + self.oktext )
206 if self["menulist"].getCurrent()[1] == 'restart':
207 self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
210 self["menulist"].up()
211 self.loadDescription()
214 self["menulist"].down()
215 self.loadDescription()
218 self["menulist"].pageUp()
219 self.loadDescription()
222 self["menulist"].pageDown()
223 self.loadDescription()
227 if self["menulist"].getCurrent()[1] == 'setting':
228 self.session.openWithCallback(self.checklist, WlanConfig, self.iface)
229 elif self["menulist"].getCurrent()[1] == 'scanap':
230 self.session.openWithCallback(self.WlanScanApCallback, WlanScanAp, self.iface)
231 elif self["menulist"].getCurrent()[1] == 'dns':
232 self.session.open(NameserverSetup)
233 elif self["menulist"].getCurrent()[1] == 'status':
234 self.session.open(Wlanstatus, self.iface)
235 elif self["menulist"].getCurrent()[1] == 'test':
236 self.session.openWithCallback(self.checklist,NetworkAdapterTest,self.iface)
237 elif self["menulist"].getCurrent()[1] == 'restart':
238 self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
241 self["menulist"].setList(self.MakeMenu())
245 menu.append((_("Adapter settings"), "setting"))
246 menu.append((_("Scan Wireless AP"), "scanap"))
247 menu.append((_("Nameserver settings"), "dns"))
248 if iNetwork.getAdapterAttribute(self.iface, "up"):
249 menu.append((_("Show WLAN Status"), "status"))
250 menu.append((_("Network test"), "test"))
251 menu.append((_("Restart network"), "restart"))
255 def WlanScanApCallback(self, essid = None):
256 if essid is not None:
257 self.session.openWithCallback(self.checklist, WlanConfig, self.iface, essid)
259 def restartLan(self, ret = False):
261 iNetwork.restartNetwork(self.restartLanDataAvail)
262 self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while your network is restarting..."), type = MessageBox.TYPE_INFO, enable_input = False)
264 def restartLanDataAvail(self, data):
266 iNetwork.getInterfaces(self.getInterfacesDataAvail)
268 def getInterfacesDataAvail(self, data):
270 self.restartLanRef.close(True)
272 def restartfinishedCB(self,data):
274 self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 5, default = False)
277 iNetwork.stopRestartConsole()
278 iNetwork.stopGetInterfacesConsole()
280 wlanconfig = ConfigSubsection()
281 wlanconfig.usedevice = ConfigSelection(default = "off", choices = [
282 ("off", _("off")), ("on", _("on"))])
283 wlanconfig.usedhcp = ConfigSelection(default = "off", choices = [
284 ("off", _("no")), ("on", _("yes"))])
285 wlanconfig.essid = ConfigSelection(default = "none", choices = ["none"])
286 wlanconfig.encrypt = ConfigSelection(default = "off", choices = [
287 ("off", _("no")), ("on", _("yes"))])
288 wlanconfig.method = ConfigSelection(default = "wep", choices = [
289 ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
290 wlanconfig.keytype = ConfigSelection(default = "ascii", choices = [
291 ("ascii", _("ASCII")), ("hex", _("HEX"))])
292 wlanconfig.key = ConfigPassword(default = "XXXXXXXX", visible_width = 50, fixed_size = False)
293 wlanconfig.usegateway = ConfigSelection(default = "off", choices = [
294 ("off", _("no")), ("on", _("yes"))])
295 wlanconfig.ip = ConfigIP([0,0,0,0])
296 wlanconfig.netmask = ConfigIP([0,0,0,0])
297 wlanconfig.gateway = ConfigIP([0,0,0,0])
300 class WlanConfig(Screen, ConfigListScreen, HelpableScreen):
302 <screen position="center,center" size="510,400" title="Wireless Network Configuration..." >
303 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
304 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
306 <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" />
307 <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" />
309 <widget name="config" position="10,10" backgroundColor="#371e1c1a" transparent="1" size="480,210" scrollbarMode="showOnDemand" />
310 <ePixmap pixmap="skin_default/div-h.png" position="0,225" zPosition="1" size="550,2" />
311 <eLabel text="IP Address : " position="100,250" size="190,21" font="Regular;19" />
312 <widget source="ipaddress" render="Label" position="300,250" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" />
313 <eLabel text="NetMask : " position="100,275" size="190,21" font="Regular;19" />
314 <widget source="netmask" render="Label" position="300,275" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" />
315 <eLabel text="Gateway : " position="100,300" size="190,21" font="Regular;19" />
316 <widget source="gateway" render="Label" position="300,300" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" />
319 def __init__(self, session, iface, essidSelected = None):
320 Screen.__init__(self,session)
321 self.session = session
322 self["key_red"] = StaticText(_("Close"))
323 self["key_green"] = StaticText(_("Ok"))
324 self["ipaddress"] = StaticText(_("[ N/A ]"))
325 self["netmask"] = StaticText(_("[ N/A ]"))
326 self["gateway"] = StaticText(_("[ N/A ]"))
327 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
329 "ok": self.saveWlanConfig,
330 "green": self.saveWlanConfig,
331 "cancel": self.keyCancel,
332 "red": self.keyCancel,
335 self.essidSelected = essidSelected
338 self.scan_ssid = None
342 self.encryption_key = None
343 self.wlanscanap = None
344 self.wpaphraseconsole = None
346 ConfigListScreen.__init__(self, self.list,session = self.session)
347 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
348 self.readWpaSupplicantConf()
349 self.scanAplistTimer = eTimer()
350 self.scanAplistTimer.callback.append(self.scanApList)
351 self.emptyListMsgTimer = eTimer()
352 self.emptyListMsgTimer.callback.append(self.emptyListMsg)
353 self.Console = Console()
354 self.updateInterfaces(self.readWlanSettings)
355 self.onClose.append(self.cleanup)
357 def updateInterfaces(self,callback = None):
358 iNetwork.config_ready = False
359 iNetwork.msgPlugins()
360 iNetwork.getInterfaces(callback)
362 def readWlanSettings(self,ret=None):
364 print "getInterfaces Fail... "
365 if iNetwork.getAdapterAttribute(self.iface, "up") == True:
369 wlanconfig.usedevice = ConfigSelection(default=default_tmp, choices = [("off", _("off")), ("on", _("on"))])
371 if iNetwork.getAdapterAttribute(self.iface, "dhcp"):
375 wlanconfig.usedhcp = ConfigSelection(default=default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
377 wlanconfig.ip = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0]
379 wlanconfig.netmask = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0])
380 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
384 wlanconfig.usegateway = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
386 wlanconfig.gateway = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0])
388 self["ipaddress"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "ip"))))
389 self["netmask"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "netmask"))))
390 self["gateway"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "gateway"))))
392 if self.encryption_key is not None:
396 wlanconfig.encrypt = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
398 if self.key_mgmt=="NONE":
400 elif self.key_mgmt == "WPA-PSK":
401 if self.proto == "WPA":
403 elif self.proto == "RSN":
405 elif self.proto in ( "WPA RSN", "WPA WPA2"):
406 default_tmp = "wpa/wpa2"
412 wlanconfig.method = ConfigSelection(default = default_tmp, choices = [
413 ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
415 if self.key_type == 0:
418 default_tmp = "ascii"
419 wlanconfig.keytype = ConfigSelection(default = default_tmp, choices = [
420 ("ascii", _("ASCII")), ("hex", _("HEX"))])
421 default_tmp = self.encryption_key or "XXXXXXXX"
422 wlanconfig.key = ConfigPassword(default = default_tmp, visible_width = 50, fixed_size = False)
425 def readWpaSupplicantConf(self):
427 if fileExists("/etc/wpa_supplicant.conf"):
428 wpafd = open("/etc/wpa_supplicant.conf","r")
430 data = wpafd.readline()
432 # print "####readWpaSupplicantConf, data : ",data
435 data = wpafd.readline()
437 if data.startswith('ssid=') and len(data) > 6:
438 self.ssid = data[6:-2]
439 elif data.startswith('ap_scan=') :
440 self.ap_scan = data[8:]
441 # print "####readWpaSupplicantConf, ap_scan : ",self.ap_scan
442 elif data.startswith('scan_ssid=') and len(data) > 10:
443 self.scan_ssid = data[10:-1]
444 elif data.startswith('key_mgmt=') and len(data) > 9:
445 self.key_mgmt = data[9:-1]
446 elif data.startswith('proto=') and len(data) > 6:
447 self.proto = data[6:-1]
448 elif data.startswith('wep_key0="') and len(data) > 11:
449 self.key_type = 1 # ascii
450 self.encryption_key = data[10:-2]
451 elif data.startswith('wep_key0=') and len(data) > 9:
452 self.key_type = 0 # hex
453 self.encryption_key = data[9:-1]
454 elif data.startswith('psk="') and len(data) > 6:
455 self.key_type = 1 # ascii
456 self.encryption_key = data[5:-2]
457 elif data.startswith('#psk="') and len(data) > 6:
458 self.key_type = 0 # hex
459 self.encryption_key = data[6:-2]
460 elif not self.encryption_key and data.startswith('psk=') and len(data) > 4:
461 self.key_type = 0 # hex
462 self.encryption_key = data[4:-1]
463 data = wpafd.readline()
464 # print self.ssid,self.scan_ssid,self.key_mgmt,self.proto,self.key_type,self.encryption_key
471 print 'failed loading wpasupplicant.conf'
473 def createConfig(self):
475 self.usedeviceEntry = getConfigListEntry(_("Use Device"), wlanconfig.usedevice)
476 self.usedhcpEntry = getConfigListEntry(_("Use DHCP"), wlanconfig.usedhcp)
477 self.essidEntry = getConfigListEntry(_("ESSID"), wlanconfig.essid)
478 self.hiddenessidEntry = getConfigListEntry(_("Input Hidden ESSID"), wlanconfig.hiddenessid)
479 self.encryptEntry = getConfigListEntry(_("Encrypt"), wlanconfig.encrypt)
480 self.methodEntry = getConfigListEntry(_("Method"), wlanconfig.method)
481 self.keytypeEntry = getConfigListEntry(_("Key Type"), wlanconfig.keytype)
482 self.keyEntry = getConfigListEntry(_("KEY"), wlanconfig.key)
484 self.ipEntry = getConfigListEntry(_("IP"), wlanconfig.ip)
485 self.netmaskEntry = getConfigListEntry(_("NetMask"), wlanconfig.netmask)
487 self.usegatewayEntry = getConfigListEntry(_("Use Gateway"), wlanconfig.usegateway)
488 self.gatewayEntry = getConfigListEntry(_("Gateway"), wlanconfig.gateway)
490 self.configList.append( self.usedeviceEntry )
491 if wlanconfig.usedevice.value is "on":
492 self.configList.append( self.usedhcpEntry )
493 if wlanconfig.usedhcp.value is "off":
494 self.configList.append(self.ipEntry)
495 self.configList.append(self.netmaskEntry)
496 self.configList.append(self.usegatewayEntry)
497 if wlanconfig.usegateway.value is "on":
498 self.configList.append(self.gatewayEntry)
499 self.configList.append( self.essidEntry )
500 if wlanconfig.essid.value == 'Input hidden ESSID':
501 self.configList.append( self.hiddenessidEntry )
502 self.configList.append( self.encryptEntry )
503 if wlanconfig.encrypt.value is "on" :
504 self.configList.append( self.methodEntry )
505 if wlanconfig.method.value =="wep":
506 self.configList.append( self.keytypeEntry )
507 self.configList.append( self.keyEntry )
509 self["config"].list = self.configList
510 self["config"].l.setList(self.configList)
513 if self.essidSelected is None:
515 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
516 self.scanAplistTimer.start(100,True)
518 self.apList = [self.essidSelected]
519 wlanconfig.essid = ConfigSelection(choices = self.apList)
520 if self.ssid is not None:
521 wlanconfig.hiddenessid = ConfigText(default = self.ssid, visible_width = 50, fixed_size = False)
523 wlanconfig.hiddenessid = ConfigText(default = "<Input ESSID>", visible_width = 50, fixed_size = False)
526 def scanApList(self):
527 if self.oldInterfaceState is not True:
528 os_system("ifconfig "+self.iface+" up")
529 iNetwork.setAdapterAttribute(self.iface, "up", True)
531 wirelessObj = Wireless(self.iface)
533 Iwscanresult = wirelessObj.scan()
535 print "%s Interface doesn't support scanning.."%self.iface
536 # self.session.open(MessageBox, "%s Interface doesn't support scanning.."%self.iface, MessageBox.TYPE_ERROR,10)
537 self.configurationmsg.close(True)
538 if Iwscanresult is None:
539 self.emptyListMsgTimer.start(100,True)
541 for ap in Iwscanresult:
542 if ap.essid not in self.apList and len(ap.essid) > 0:
543 self.apList.append(ap.essid)
544 self.apList.append('Input hidden ESSID')
545 if selectap is not None and selectap in self.apList:
546 wlanconfig.essid = ConfigSelection(default=selectap,choices = self.apList)
547 elif self.scan_ssid is not None and self.scan_ssid.strip() == '1':
548 wlanconfig.essid = ConfigSelection(default='Input hidden ESSID',choices = self.apList)
549 elif self.ssid is not None and self.ssid in self.apList:
550 wlanconfig.essid = ConfigSelection(default=self.ssid, choices = self.apList)
553 wlanconfig.essid = ConfigSelection(defalut = self.apList[0], choices = self.apList)
555 wlanconfig.essid = ConfigSelection(choices = self.apList)
556 if self.ssid is not None:
557 wlanconfig.hiddenessid = ConfigText(default = self.ssid, visible_width = 50, fixed_size = False)
559 wlanconfig.hiddenessid = ConfigText(default = "<Input ESSID>", visible_width = 50, fixed_size = False)
562 def emptyListMsg(self):
563 self.session.open(MessageBox, _("No AP detected."), type = MessageBox.TYPE_INFO, timeout = 10)
566 ConfigListScreen.keyLeft(self)
570 ConfigListScreen.keyRight(self)
574 if self["config"].getCurrent() == self.usedeviceEntry or self["config"].getCurrent() == self.encryptEntry \
575 or self["config"].getCurrent() == self.usedhcpEntry or self["config"].getCurrent() == self.usegatewayEntry \
576 or self["config"].getCurrent() == self.essidEntry or self["config"].getCurrent() == self.methodEntry:
579 def saveWlanConfig(self):
581 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
582 self["config"].getCurrent()[1].onDeselect(self.session)
583 if self["config"].isChanged():
584 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Are you sure you want to restart your network interfaces?\n") ) )
586 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Network configuration is not changed....\n\nAre you sure you want to restart your network interfaces?\n") ) )
590 def checkNetworkConfig(self, ret = False):
592 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
593 self["config"].getCurrent()[1].onSelect(self.session)
595 if wlanconfig.essid.value == 'Input hidden ESSID':
596 if len(wlanconfig.hiddenessid.value) == 0:
597 self.session.open(MessageBox, ("PLEASE INPUT HIDDEN ESSID"), type = MessageBox.TYPE_ERROR, timeout = 10)
599 if len(wlanconfig.key.value) == 0:
600 self.session.open(MessageBox, ("PLEASE INPUT NETWORK KEY"), type = MessageBox.TYPE_ERROR, timeout = 10)
602 self.checkNetworkShares()
604 def checkNetworkShares(self):
606 self.Console = Console()
607 cmd = "cat /proc/mounts"
608 self.Console.ePopen(cmd, self.checkSharesFinished, self.confirmAnotherIfaces)
610 def checkSharesFinished(self, result, retval, extra_args):
611 callback = extra_args
612 # print "checkMountsFinished : result : \n",result
613 networks = ['nfs','smbfs','ncp','coda']
614 for line in result.splitlines():
615 split = line.strip().split(' ',3)
616 if split[2] in networks:
617 self.session.open(MessageBox, ("NOT deconfiguring network interfaces :\n network shares still mounted\n"), type = MessageBox.TYPE_ERROR, timeout = 10)
619 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
620 self["config"].getCurrent()[1].onSelect(self.session)
624 def confirmAnotherIfaces(self, ret = False):
628 num_configured_if = len(iNetwork.getConfiguredAdapters())
629 if num_configured_if >= 1:
630 if num_configured_if == 1 and self.iface in iNetwork.getConfiguredAdapters():
631 self.getWpaPhrase(False)
633 self.session.openWithCallback(self.getWpaPhrase, MessageBox, _("A second configured interface has been found.\n\nDo you want to disable the second network interface?"), default = True)
635 self.getWpaPhrase(False)
637 def getWpaPhrase(self,ret):
639 configuredInterfaces = iNetwork.getConfiguredAdapters()
640 for interface in configuredInterfaces:
641 if interface == self.iface:
643 iNetwork.setAdapterAttribute(interface, "up", False)
644 iNetwork.deactivateInterface(interface)
645 if wlanconfig.method.value =="wep":
646 self.writeWpasupplicantConf("wep") # passphrasekey is not None
648 if wlanconfig.essid.value == 'Input hidden ESSID':
649 cmd = "wpa_passphrase '%s' %s" % (wlanconfig.hiddenessid.value,wlanconfig.key.value)
651 cmd = "wpa_passphrase '%s' %s" % (wlanconfig.essid.value,wlanconfig.key.value)
653 self.wpaphraseconsole = Console()
654 self.wpaphraseconsole.ePopen(cmd, self.parseWpaPhrase, self.writeWpasupplicantConf)
656 def parseWpaPhrase(self, result, retval, extra_args):
657 (writewlanconfig) = extra_args
658 if self.wpaphraseconsole is not None:
660 self.wpaphraseconsole.killAll()
661 self.wpaphraseconsole = None
662 # print "parseWpaPhrase result : "
665 for line in result.splitlines():
666 if line.find('ssid') == -1 and line.find('#psk=') != -1:
668 elif line.find('psk=') != -1:
671 writewlanconfig(psk,plainpwd)
673 writewlanconfig(None)
675 writewlanconfig(None)
677 def writeWpasupplicantConf(self, passphrasekey=None,plainpwd=None):
679 wpafd = open("/etc/wpa_supplicant.conf","w")
681 contents = "#WPA Supplicant Configuration by STB\n"
682 contents += "ctrl_interface=/var/run/wpa_supplicant\n"
683 contents += "eapol_version=1\n"
684 contents += "fast_reauth=1\n"
685 contents += "ap_scan=1\n"
686 contents += "network={\n"
687 if wlanconfig.essid.value == 'Input hidden ESSID':
688 contents += "\tssid=\""+wlanconfig.hiddenessid.value+"\"\n"
689 contents += "\tscan_ssid=1\n"
691 contents += "\tssid=\""+wlanconfig.essid.value+"\"\n"
692 contents += "\tscan_ssid=0\n"
693 if wlanconfig.encrypt.value == "on":
694 if wlanconfig.method.value =="wep":
695 contents += "\tkey_mgmt=NONE\n"
696 contents += "\twep_key0="
697 if wlanconfig.keytype.value == "ascii":
698 contents += "\""+wlanconfig.key.value+"\"\n"
700 contents += wlanconfig.key.value+"\n"
702 # print "plainpwd : ",plainpwd
703 # print "passphrasekey : ",passphrasekey
704 if wlanconfig.method.value == "wpa":
705 contents += "\tkey_mgmt=WPA-PSK\n"
706 contents += "\tproto=WPA\n"
707 contents += "\tpairwise=CCMP TKIP\n"
708 contents += "\tgroup=CCMP TKIP\n"
709 elif wlanconfig.method.value == "wpa2":
710 contents += "\tkey_mgmt=WPA-PSK\n"
711 contents += "\tproto=RSN\n"
712 contents += "\tpairwise=CCMP TKIP\n"
713 contents += "\tgroup=CCMP TKIP\n"
715 contents += "\tkey_mgmt=WPA-PSK\n"
716 contents += "\tproto=WPA RSN\n"
717 contents += "\tpairwise=CCMP TKIP\n"
718 contents += "\tgroup=CCMP TKIP\n"
719 contents += plainpwd+"\n"
720 contents += passphrasekey+"\n"
722 contents += "\tkey_mgmt=NONE\n"
724 print "content = \n"+contents
725 wpafd.write(contents)
727 self.writeNetConfig(0)
729 self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
730 self.writeNetConfig(-1)
732 self.writeNetConfig(-2)
734 def writeNetConfig(self,ret = -1):
736 self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
739 self.session.open(MessageBox, _("Can NOT generate passphrase"), type = MessageBox.TYPE_ERROR, timeout = 10)
742 if wlanconfig.usedevice.value=="on":
743 iNetwork.setAdapterAttribute(self.iface, "up", True)
744 if wlanconfig.usedhcp.value =="on":
745 iNetwork.setAdapterAttribute(self.iface, "dhcp", True)
747 iNetwork.setAdapterAttribute(self.iface, "dhcp", False)
748 iNetwork.setAdapterAttribute(self.iface, "ip", wlanconfig.ip.value)
749 iNetwork.setAdapterAttribute(self.iface, "netmask", wlanconfig.netmask.value)
750 if wlanconfig.usegateway.value == "on":
751 iNetwork.setAdapterAttribute(self.iface, "gateway", wlanconfig.gateway.value)
753 iNetwork.setAdapterAttribute(self.iface, "up", False)
754 iNetwork.deactivateInterface(self.iface)
755 contents = "\tpre-up wpa_supplicant -i"+self.iface+" -c/etc/wpa_supplicant.conf -B -D"+iNetwork.detectWlanModule(self.iface)+"\n"
756 contents += "\tpost-down wpa_cli terminate\n\n"
757 iNetwork.setAdapterAttribute(self.iface, "configStrings", contents)
758 iNetwork.writeNetworkConfig()
759 iNetwork.restartNetwork(self.updateCurrentInterfaces)
760 self.configurationmsg = None
761 self.configurationmsg = self.session.openWithCallback(self.configFinished, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
764 def updateCurrentInterfaces(self,ret):
766 iNetwork.getInterfaces(self.configurationMsgClose)
768 def configurationMsgClose(self,ret):
769 if ret is True and self.configurationmsg is not None:
770 self.configurationmsg.close(True)
772 def configFinished(self,data):
775 self.session.openWithCallback(self.configFinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
776 selectap = wlanconfig.essid.value
778 def configFinishedCB(self,data):
783 def formatip(self, iplist):
786 # print "iplist : ",iplist
789 result = str(iplist[0])+"."+str(iplist[1])+"."+str(iplist[2])+"."+str(iplist[3])
792 # print "result : ",result
797 def keyCancelConfirm(self, result):
800 if self.oldInterfaceState is False:
801 iNetwork.setAdapterAttribute(self.iface, "up", False)
802 iNetwork.deactivateInterface(self.iface,self.keyCancelCB)
806 def keyCancel(self,yesno = True):
807 if self["config"].isChanged():
808 self.session.openWithCallback(self.keyCancelConfirm, MessageBox, _("Really close without saving settings?"))
810 self.keyCancelConfirm(True)
812 def keyCancelCB(self,data):
818 iNetwork.stopRestartConsole()
819 iNetwork.stopGetInterfacesConsole()
820 iNetwork.stopDeactivateInterfaceConsole()
821 self.stopwlanscanapConsole()
822 self.stopCheckNetworkSharesConsole()
823 self.stopWpaPhraseConsole()
825 def stopwlanscanapConsole(self):
826 if self.wlanscanap is not None:
827 if len(self.wlanscanap.appContainers):
828 for name in self.wlanscanap.appContainers.keys():
829 self.wlanscanap.kill(name)
831 def stopCheckNetworkSharesConsole(self):
832 if self.Console is not None:
833 if len(self.Console.appContainers):
834 for name in self.Console.appContainers.keys():
835 self.Console.kill(name)
837 def stopWpaPhraseConsole(self):
838 if self.wpaphraseconsole is not None:
839 if len(self.wpaphraseconsole.appContainers):
840 for name in self.wpaphraseconsole.appContainers.keys():
841 self.wpaphraseconsole.kill(name)
843 class WlanScanAp(Screen,HelpableScreen):
845 <screen position="center,center" size="510,400" title="Wireless Network AP Scan..." >
846 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
847 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
849 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
850 <ePixmap pixmap="skin_default/buttons/green.png" position="185,360" size="140,40" alphatest="on" />
851 <ePixmap pixmap="skin_default/buttons/blue.png" position="360,360" size="140,40" alphatest="on" />
853 <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" />
854 <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" />
855 <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" />
857 <widget name="menulist" position="20,20" size="230,260" backgroundColor="#371e1c1a" transparent="1" zPosition="10" scrollbarMode="showOnDemand" />
859 <widget source="Address" render="Label" position="265,70" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
860 <widget source="ESSID" render="Label" position="265,100" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
861 <widget source="Protocol" render="Label" position="265,130" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
862 <widget source="Frequency" render="Label" position="265,160" zPosition="1" size="240,40" font="Regular;18" halign="center" valign="center" />
863 <widget source="Encryption key" render="Label" position="265,200" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
864 <widget source="BitRate" render="Label" position="265,220" zPosition="1" size="240,60" font="Regular;18" halign="center" valign="center" />
867 def __init__(self, session, iface):
868 Screen.__init__(self,session)
869 HelpableScreen.__init__(self)
870 self.session = session
872 self.wlanscanap = None
876 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
878 "up": (self.up, _("move up to previous entry")),
879 "down": (self.down, _("move down to next entry")),
880 "left": (self.left, _("move up to first entry")),
881 "right": (self.right, _("move down to last entry")),
884 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
886 "cancel": (self.close, _("exit")),
887 "ok": (self.ok, "select AP"),
890 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
892 "red": (self.close, _("exit")),
893 "green": (self.ok, "select AP"),
894 "yellow": (self.restartScanAP, "restart scan AP"),
895 "blue": (self.startWlanConfig, "Edit Wireless settings"),
898 self["menulist"] = MenuList(self.setApList)
899 self["key_red"] = StaticText(_("Close"))
900 self["key_green"] = StaticText(_("Select"))
901 self["key_blue"] = StaticText(_("EditSetting"))
902 self["Address"] = StaticText(_("Scanning AP List.."))
903 self["ESSID"] = StaticText(_("Wait a moment"))
904 self["Protocol"] = StaticText(" ")
905 self["Frequency"] = StaticText(" ")
906 self["Encryption key"] = StaticText(" ")
907 self["BitRate"] = StaticText(" ")
908 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
909 self.getAplistTimer = eTimer()
910 self.getAplistTimer.callback.append(self.getApList)
911 self.scanAplistTimer = eTimer()
912 self.scanAplistTimer.callback.append(self.scanApList)
913 self.emptyListMsgTimer = eTimer()
914 self.emptyListMsgTimer.callback.append(self.emptyListMsg)
916 self.onClose.append(self.__onClose)
917 self.getAplistTimer.start(100,True)
920 self["menulist"].pageUp()
924 self["menulist"].pageDown()
928 self["menulist"].up()
932 self["menulist"].down()
937 selectAp=self["menulist"].getCurrent()[0]
941 def startWlanConfig(self):
942 selectAp=self["menulist"].getCurrent()[0]
948 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
949 self.scanAplistTimer.start(100,True)
951 def scanApList(self):
952 if self.oldInterfaceState is not True:
953 os_system("ifconfig "+self.iface+" up")
954 iNetwork.setAdapterAttribute(self.iface, "up", True)
956 wirelessObj = Wireless(self.iface)
958 Iwscanresult = wirelessObj.scan()
960 print "%s Interface doesn't support scanning.."%self.iface
961 # self.session.open(MessageBox, "%s Interface doesn't support scanning.."%self.iface, MessageBox.TYPE_ERROR,10)
962 self.configurationmsg.close(True)
963 if Iwscanresult is not None:
964 (num_channels, frequencies) = wirelessObj.getChannelInfo()
966 for ap in Iwscanresult:
967 self.apList[index] = {}
968 self.apList[index]["Address"] = ap.bssid
969 if len(ap.essid) == 0:
970 self.apList[index]["ESSID"] = "<hidden ESSID>"
972 self.apList[index]["ESSID"] = ap.essid
973 self.setApList.append( (self.apList[index]["ESSID"], index) )
974 self.apList[index]["Protocol"] = ap.protocol
975 self.apList[index]["Frequency"] = wirelessObj._formatFrequency(ap.frequency.getFrequency())
977 self.apList[index]["Channel"] = frequencies.index(self.apList[index]["Frequency"] + 1)
979 self.apList[index]["Channel"] = "Unknown"
981 self.apList[index]["Quality"] = "%s/%s" % \
982 ( ap.quality.quality, wirelessObj.getQualityMax().quality )
983 self.apList[index]["Signal Level"] = "%s/%s" % \
984 ( ap.quality.getSignallevel(), "100" )
985 self.apList[index]["Noise Level"] = "%s/%s" % \
986 ( ap.quality.getNoiselevel(), "100" )
988 # get encryption key on/off
989 key_status = "Unknown"
990 if (ap.encode.flags & pythonwifi.flags.IW_ENCODE_DISABLED):
992 elif (ap.encode.flags & pythonwifi.flags.IW_ENCODE_NOKEY):
993 if (ap.encode.length <= 0):
995 self.apList[index]["Encryption key"] = key_status
996 self.apList[index]["BitRate"] = wirelessObj._formatBitrate(ap.rate[-1][-1])
999 # print self.setApList
1000 self.displayApInfo()
1001 if len(self.apList) == 0:
1002 self.emptyListMsgTimer.start(100,True)
1004 def displayApInfo(self):
1005 if len(self.apList) >0:
1006 self["menulist"].setList(self.setApList)
1007 index = self["menulist"].getCurrent()[1]
1008 for key in ["Address", "ESSID", "Protocol", "Frequency", "Encryption key", "BitRate"]:
1009 if self.apList[index].has_key(key):
1010 self[key].setText((key+": "+self.apList[index][key]))
1012 self[key].setText((key+": None"))
1014 def emptyListMsg(self):
1015 self.session.open(MessageBox, _("No AP detected."), type = MessageBox.TYPE_INFO, timeout = 10)
1016 self["Address"].setText(_("No AP detected."))
1017 self["ESSID"].setText(_(""))
1019 def restartScanAP(self):
1020 self.getAplistTimer.start(100,True)
1022 def __onClose(self):
1023 if self.oldInterfaceState is False:
1024 iNetwork.setAdapterAttribute(self.iface, "up", False)
1025 iNetwork.deactivateInterface(self.iface)
1027 class NetworkAdapterTest(Screen):
1028 def __init__(self, session,iface):
1029 Screen.__init__(self, session)
1031 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
1033 self.onClose.append(self.cleanup)
1034 self.onHide.append(self.cleanup)
1036 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
1040 "up": lambda: self.updownhandler('up'),
1041 "down": lambda: self.updownhandler('down'),
1045 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1048 "back": self.cancel,
1050 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1052 "red": self.closeInfo,
1053 "back": self.closeInfo,
1055 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
1057 "green": self.KeyGreen,
1059 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
1061 "green": self.KeyGreenRestart,
1063 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
1065 "yellow": self.KeyYellow,
1068 self["shortcutsgreen_restart"].setEnabled(False)
1069 self["updown_actions"].setEnabled(False)
1070 self["infoshortcuts"].setEnabled(False)
1071 self.onClose.append(self.delTimer)
1072 self.onLayoutFinish.append(self.layoutFinished)
1073 self.steptimer = False
1075 self.activebutton = 0
1076 self.nextStepTimer = eTimer()
1077 self.nextStepTimer.callback.append(self.nextStepTimerFire)
1080 if self.oldInterfaceState is False:
1081 iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
1082 iNetwork.deactivateInterface(self.iface)
1085 def closeInfo(self):
1086 self["shortcuts"].setEnabled(True)
1087 self["infoshortcuts"].setEnabled(False)
1088 self["InfoText"].hide()
1089 self["InfoTextBorder"].hide()
1090 self["key_red"].setText(_("Close"))
1094 del self.nextStepTimer
1096 def nextStepTimerFire(self):
1097 self.nextStepTimer.stop()
1098 self.steptimer = False
1101 def updownhandler(self,direction):
1102 if direction == 'up':
1103 if self.activebutton >=2:
1104 self.activebutton -= 1
1106 self.activebutton = 6
1107 self.setActiveButton(self.activebutton)
1108 if direction == 'down':
1109 if self.activebutton <=5:
1110 self.activebutton += 1
1112 self.activebutton = 1
1113 self.setActiveButton(self.activebutton)
1115 def setActiveButton(self,button):
1117 self["EditSettingsButton"].setPixmapNum(0)
1118 self["EditSettings_Text"].setForegroundColorNum(0)
1119 self["NetworkInfo"].setPixmapNum(0)
1120 self["NetworkInfo_Text"].setForegroundColorNum(1)
1121 self["AdapterInfo"].setPixmapNum(1) # active
1122 self["AdapterInfo_Text"].setForegroundColorNum(2) # active
1124 self["AdapterInfo_Text"].setForegroundColorNum(1)
1125 self["AdapterInfo"].setPixmapNum(0)
1126 self["DhcpInfo"].setPixmapNum(0)
1127 self["DhcpInfo_Text"].setForegroundColorNum(1)
1128 self["NetworkInfo"].setPixmapNum(1) # active
1129 self["NetworkInfo_Text"].setForegroundColorNum(2) # active
1131 self["NetworkInfo"].setPixmapNum(0)
1132 self["NetworkInfo_Text"].setForegroundColorNum(1)
1133 self["IPInfo"].setPixmapNum(0)
1134 self["IPInfo_Text"].setForegroundColorNum(1)
1135 self["DhcpInfo"].setPixmapNum(1) # active
1136 self["DhcpInfo_Text"].setForegroundColorNum(2) # active
1138 self["DhcpInfo"].setPixmapNum(0)
1139 self["DhcpInfo_Text"].setForegroundColorNum(1)
1140 self["DNSInfo"].setPixmapNum(0)
1141 self["DNSInfo_Text"].setForegroundColorNum(1)
1142 self["IPInfo"].setPixmapNum(1) # active
1143 self["IPInfo_Text"].setForegroundColorNum(2) # active
1145 self["IPInfo"].setPixmapNum(0)
1146 self["IPInfo_Text"].setForegroundColorNum(1)
1147 self["EditSettingsButton"].setPixmapNum(0)
1148 self["EditSettings_Text"].setForegroundColorNum(0)
1149 self["DNSInfo"].setPixmapNum(1) # active
1150 self["DNSInfo_Text"].setForegroundColorNum(2) # active
1152 self["DNSInfo"].setPixmapNum(0)
1153 self["DNSInfo_Text"].setForegroundColorNum(1)
1154 self["EditSettingsButton"].setPixmapNum(1) # active
1155 self["EditSettings_Text"].setForegroundColorNum(2) # active
1156 self["AdapterInfo"].setPixmapNum(0)
1157 self["AdapterInfo_Text"].setForegroundColorNum(1)
1160 next = self.nextstep
1176 self.steptimer = True
1177 self.nextStepTimer.start(3000)
1178 self["key_yellow"].setText(_("Stop test"))
1181 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
1182 self["Adapter"].setForegroundColorNum(2)
1183 self["Adaptertext"].setForegroundColorNum(1)
1184 self["AdapterInfo_Text"].setForegroundColorNum(1)
1185 self["AdapterInfo_OK"].show()
1186 self.steptimer = True
1187 self.nextStepTimer.start(3000)
1190 self["Networktext"].setForegroundColorNum(1)
1191 self["Network"].setText(_("Please wait..."))
1192 self.AccessPointInfo(self.iface)
1193 self["NetworkInfo_Text"].setForegroundColorNum(1)
1194 self.steptimer = True
1195 self.nextStepTimer.start(3000)
1198 self["Dhcptext"].setForegroundColorNum(1)
1199 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
1200 self["Dhcp"].setForegroundColorNum(2)
1201 self["Dhcp"].setText(_("enabled"))
1202 self["DhcpInfo_Check"].setPixmapNum(0)
1204 self["Dhcp"].setForegroundColorNum(1)
1205 self["Dhcp"].setText(_("disabled"))
1206 self["DhcpInfo_Check"].setPixmapNum(1)
1207 self["DhcpInfo_Check"].show()
1208 self["DhcpInfo_Text"].setForegroundColorNum(1)
1209 self.steptimer = True
1210 self.nextStepTimer.start(3000)
1213 self["IPtext"].setForegroundColorNum(1)
1214 self["IP"].setText(_("Please wait..."))
1215 iNetwork.checkNetworkState(self.NetworkStatedataAvail)
1218 self.steptimer = False
1219 self.nextStepTimer.stop()
1220 self["DNStext"].setForegroundColorNum(1)
1221 self["DNS"].setText(_("Please wait..."))
1222 iNetwork.checkDNSLookup(self.DNSLookupdataAvail)
1225 self["shortcutsgreen"].setEnabled(False)
1226 self["shortcutsyellow"].setEnabled(True)
1227 self["updown_actions"].setEnabled(False)
1228 self["key_yellow"].setText("")
1229 self["key_green"].setText("")
1230 self.steptimer = True
1231 self.nextStepTimer.start(1000)
1233 def KeyGreenRestart(self):
1235 self.layoutFinished()
1236 self["Adapter"].setText((""))
1237 self["Network"].setText((""))
1238 self["Dhcp"].setText((""))
1239 self["IP"].setText((""))
1240 self["DNS"].setText((""))
1241 self["AdapterInfo_Text"].setForegroundColorNum(0)
1242 self["NetworkInfo_Text"].setForegroundColorNum(0)
1243 self["DhcpInfo_Text"].setForegroundColorNum(0)
1244 self["IPInfo_Text"].setForegroundColorNum(0)
1245 self["DNSInfo_Text"].setForegroundColorNum(0)
1246 self["shortcutsgreen_restart"].setEnabled(False)
1247 self["shortcutsgreen"].setEnabled(False)
1248 self["shortcutsyellow"].setEnabled(True)
1249 self["updown_actions"].setEnabled(False)
1250 self["key_yellow"].setText("")
1251 self["key_green"].setText("")
1252 self.steptimer = True
1253 self.nextStepTimer.start(1000)
1256 self["infoshortcuts"].setEnabled(True)
1257 self["shortcuts"].setEnabled(False)
1258 if self.activebutton == 1: # Adapter Check
1259 self["InfoText"].setText(_("This test detects your configured Wireless LAN-Adapter."))
1260 self["InfoTextBorder"].show()
1261 self["InfoText"].show()
1262 self["key_red"].setText(_("Back"))
1263 if self.activebutton == 2: #LAN Check
1264 self["InfoText"].setText(_("This test checks whether a network cable is connected to your Wireless LAN-Adapter."))
1265 self["InfoTextBorder"].show()
1266 self["InfoText"].show()
1267 self["key_red"].setText(_("Back"))
1268 if self.activebutton == 3: #DHCP Check
1269 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."))
1270 self["InfoTextBorder"].show()
1271 self["InfoText"].show()
1272 self["key_red"].setText(_("Back"))
1273 if self.activebutton == 4: # IP Check
1274 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"))
1275 self["InfoTextBorder"].show()
1276 self["InfoText"].show()
1277 self["key_red"].setText(_("Back"))
1278 if self.activebutton == 5: # DNS Check
1279 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"))
1280 self["InfoTextBorder"].show()
1281 self["InfoText"].show()
1282 self["key_red"].setText(_("Back"))
1283 if self.activebutton == 6: # Edit Settings
1285 self.session.open(WlanConfig,self.iface)
1286 self["shortcuts"].setEnabled(True)
1287 self["infoshortcuts"].setEnabled(False)
1289 def KeyYellow(self):
1291 self["shortcutsgreen_restart"].setEnabled(True)
1292 self["shortcutsgreen"].setEnabled(False)
1293 self["shortcutsyellow"].setEnabled(False)
1294 self["key_green"].setText(_("Restart test"))
1295 self["key_yellow"].setText("")
1296 self.steptimer = False
1297 self.nextStepTimer.stop()
1299 def layoutFinished(self):
1300 self.setTitle(_("Network test: ") + iNetwork.getFriendlyAdapterName(self.iface) )
1301 self["shortcutsyellow"].setEnabled(False)
1302 self["AdapterInfo_OK"].hide()
1303 self["NetworkInfo_Check"].hide()
1304 self["DhcpInfo_Check"].hide()
1305 self["IPInfo_Check"].hide()
1306 self["DNSInfo_Check"].hide()
1307 self["EditSettings_Text"].hide()
1308 self["EditSettingsButton"].hide()
1309 self["InfoText"].hide()
1310 self["InfoTextBorder"].hide()
1311 self["key_yellow"].setText("")
1313 def setLabels(self):
1314 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1315 self["Adapter"] = MultiColorLabel()
1316 self["AdapterInfo"] = MultiPixmap()
1317 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1318 self["AdapterInfo_OK"] = Pixmap()
1320 if self.iface in iNetwork.wlan_interfaces:
1321 self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1323 self["Networktext"] = MultiColorLabel(_("Local Network"))
1325 self["Network"] = MultiColorLabel()
1326 self["NetworkInfo"] = MultiPixmap()
1327 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1328 self["NetworkInfo_Check"] = MultiPixmap()
1330 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1331 self["Dhcp"] = MultiColorLabel()
1332 self["DhcpInfo"] = MultiPixmap()
1333 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1334 self["DhcpInfo_Check"] = MultiPixmap()
1336 self["IPtext"] = MultiColorLabel(_("IP Address"))
1337 self["IP"] = MultiColorLabel()
1338 self["IPInfo"] = MultiPixmap()
1339 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1340 self["IPInfo_Check"] = MultiPixmap()
1342 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1343 self["DNS"] = MultiColorLabel()
1344 self["DNSInfo"] = MultiPixmap()
1345 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1346 self["DNSInfo_Check"] = MultiPixmap()
1348 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1349 self["EditSettingsButton"] = MultiPixmap()
1351 self["key_red"] = StaticText(_("Close"))
1352 self["key_green"] = StaticText(_("Start test"))
1353 self["key_yellow"] = StaticText(_("Stop test"))
1355 self["InfoTextBorder"] = Pixmap()
1356 self["InfoText"] = Label()
1358 def NetworkStatedataAvail(self,data):
1360 self["IP"].setForegroundColorNum(2)
1361 self["IP"].setText(_("confirmed"))
1362 self["IPInfo_Check"].setPixmapNum(0)
1364 self["IP"].setForegroundColorNum(1)
1365 self["IP"].setText(_("unconfirmed"))
1366 self["IPInfo_Check"].setPixmapNum(1)
1367 self["IPInfo_Check"].show()
1368 self["IPInfo_Text"].setForegroundColorNum(1)
1369 self.steptimer = True
1370 self.nextStepTimer.start(3000)
1372 def DNSLookupdataAvail(self,data):
1374 self["DNS"].setForegroundColorNum(2)
1375 self["DNS"].setText(_("confirmed"))
1376 self["DNSInfo_Check"].setPixmapNum(0)
1378 self["DNS"].setForegroundColorNum(1)
1379 self["DNS"].setText(_("unconfirmed"))
1380 self["DNSInfo_Check"].setPixmapNum(1)
1381 self["DNSInfo_Check"].show()
1382 self["DNSInfo_Text"].setForegroundColorNum(1)
1383 self["EditSettings_Text"].show()
1384 self["EditSettingsButton"].setPixmapNum(1)
1385 self["EditSettings_Text"].setForegroundColorNum(2) # active
1386 self["EditSettingsButton"].show()
1387 self["key_yellow"].setText("")
1388 self["key_green"].setText(_("Restart test"))
1389 self["shortcutsgreen"].setEnabled(False)
1390 self["shortcutsgreen_restart"].setEnabled(True)
1391 self["shortcutsyellow"].setEnabled(False)
1392 self["updown_actions"].setEnabled(True)
1393 self.activebutton = 6
1395 def getInfoCB(self,status):
1396 if status is not None:
1397 if status.startswith("No Connection") or status.startswith("Not-Associated") or status == False:
1398 self["Network"].setForegroundColorNum(1)
1399 self["Network"].setText(_("disconnected"))
1400 self["NetworkInfo_Check"].setPixmapNum(1)
1401 self["NetworkInfo_Check"].show()
1403 self["Network"].setForegroundColorNum(2)
1404 self["Network"].setText(_("connected"))
1405 self["NetworkInfo_Check"].setPixmapNum(0)
1406 self["NetworkInfo_Check"].show()
1409 iNetwork.stopLinkStateConsole()
1410 iNetwork.stopPingConsole()
1411 iNetwork.stopDNSConsole()
1413 def AccessPointInfo(self,iface):
1414 cmd = "iwconfig %s"%iface
1415 self.iwconfigConsole = Console()
1416 self.iwconfigConsole.ePopen(cmd,self.readAP,self.getInfoCB)
1418 def readAP(self,result,retval,extra_args):
1419 (callback) = extra_args
1421 if self.iwconfigConsole is not None:
1423 self.iwconfigConsole = None
1424 for content in result.splitlines():
1425 if 'Access Point' in content:
1426 self.apState = content.strip().split('Access Point: ')[1]
1427 callback(self.apState)
1429 callback(self.apState)
1431 class Wlanstatus(Screen):
1433 <screen position="center,center" size="510,400" title="Wireless Network Status..." >
1434 <widget source="status" render="Label" position="5,15" size="500,350" font="Regular;18" zPosition="1" />
1436 <ePixmap pixmap="skin_default/buttons/red.png" position="185,360" size="140,40" alphatest="on" />
1437 <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" />
1440 def __init__(self, session,iface):
1441 Screen.__init__(self,session)
1442 self.session = session
1444 self["status"] = StaticText(_("Wait a moment..."))
1445 self["key_red"] = StaticText(_("Close"))
1446 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
1449 "cancel": self.close,
1453 self.onClose.append(self.cleanup)
1455 def readstatus(self):
1456 self.wlanstatus = Console()
1457 cmd1 = "iwconfig "+self.iface
1458 self.wlanstatus.ePopen(cmd1, self.iwconfigfinnished,self.statusdisplay)
1460 def iwconfigfinnished(self, result, retval,extra_args):
1462 (statecallback) = extra_args
1463 if self.wlanstatus is not None:
1465 statecallback(result)
1472 def statusdisplay(self,data):
1474 self["status"].setText(_("No information..."))
1476 self["status"].setText(data)
1482 self.stopWlanStatusConsole()
1484 def stopWlanStatusConsole(self):
1485 if self.wlanstatus is not None:
1486 if len(self.wlanstatus.appContainers):
1487 for name in self.wlanstatus.appContainers.keys():
1488 self.wlanstatus.kill(name)
1490 def openconfig(session, **kwargs):
1491 session.open(WlanSelection)
1493 def selSetup(menuid, **kwargs):
1495 if menuid != "system":
1498 for x in iNetwork.getInstalledAdapters():
1499 if x.startswith('eth'):
1503 return [(_("Wireless LAN Setup"), openconfig, "wlansetup_config", 80)]
1508 def Plugins(**kwargs):
1509 return PluginDescriptor(name=_("Wireless LAN Setup"), description="Wireless LAN Setup", where = PluginDescriptor.WHERE_MENU, fnc=selSetup)