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()
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]
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.")
134 return str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter")
136 return _("Unknown network adapter")
138 return _("Unknown network adapter")
141 iNetwork.stopGetInterfacesConsole()
143 class WlanSetup(Screen,HelpableScreen):
145 <screen position="center,center" size="510,400" title="Wireless Network Setup Menu..." >
146 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
147 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
149 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
150 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
152 <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" />
153 <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" />
155 <widget name="menulist" position="20,20" size="230,260" transparent="1" backgroundColor="#371e1c1a" zPosition="10" scrollbarMode="showOnDemand" />
156 <widget source="description" render="Label" position="305,10" size="195,300" font="Regular;19" halign="center" valign="center" />
159 def __init__(self, session, ifaces):
160 Screen.__init__(self, session)
161 HelpableScreen.__init__(self)
162 self.session = session
164 self.restartLanRef = None
165 self.LinkState = None
166 self.mainmenu = self.MakeMenu()
167 self["menulist"] = MenuList(self.mainmenu)
168 self["key_red"] = StaticText(_("Close"))
169 self["key_green"] = StaticText(_("Select"))
170 self["description"] = StaticText()
171 self["IFtext"] = StaticText()
172 self["IF"] = StaticText()
173 self["Statustext"] = StaticText()
174 self["statuspic"] = MultiPixmap()
175 self["statuspic"].hide()
176 self.onLayoutFinish.append(self.loadDescription)
178 self.oktext = _("Press OK on your remote control to continue.")
180 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
182 "up": (self.up, _("move up to previous entry")),
183 "down": (self.down, _("move down to next entry")),
184 "left": (self.left, _("move up to first entry")),
185 "right": (self.right, _("move down to last entry")),
188 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
190 "cancel": (self.close, _("exit networkadapter setup menu")),
191 "ok": (self.ok, _("select menu entry")),
194 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
196 "red": (self.close, _("exit networkadapter setup menu")),
197 "green": (self.ok, _("select menu entry")),
200 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
210 self.onClose.append(self.cleanup)
212 def loadDescription(self):
213 if self["menulist"].getCurrent()[1] == 'setting':
214 self["description"].setText(_("Edit the network configuration of your STB.\n" ) + self.oktext )
215 if self["menulist"].getCurrent()[1] == 'scanap':
216 self["description"].setText(_("Scan your network for wireless access points and connect to them using your selected wireless device.\n" ) + self.oktext )
217 if self["menulist"].getCurrent()[1] == 'dns':
218 self["description"].setText(_("Edit the Nameserver configuration of your STB.\n" ) + self.oktext )
219 if self["menulist"].getCurrent()[1] == 'status':
220 self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
221 if self["menulist"].getCurrent()[1] == 'test':
222 self["description"].setText(_("Test the network configuration of your STB.\n" ) + self.oktext )
223 if self["menulist"].getCurrent()[1] == 'restart':
224 self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
227 self["menulist"].up()
228 self.loadDescription()
231 self["menulist"].down()
232 self.loadDescription()
235 self["menulist"].pageUp()
236 self.loadDescription()
239 self["menulist"].pageDown()
240 self.loadDescription()
244 if self["menulist"].getCurrent()[1] == 'setting':
245 self.session.openWithCallback(self.checklist, WlanConfig, self.iface)
246 elif self["menulist"].getCurrent()[1] == 'scanap':
247 self.session.openWithCallback(self.WlanScanApCallback, WlanScanAp, self.iface)
248 elif self["menulist"].getCurrent()[1] == 'dns':
249 self.session.open(NameserverSetup)
250 elif self["menulist"].getCurrent()[1] == 'status':
251 self.session.open(Wlanstatus, self.iface)
252 elif self["menulist"].getCurrent()[1] == 'test':
253 self.session.openWithCallback(self.checklist,NetworkAdapterTest,self.iface)
254 elif self["menulist"].getCurrent()[1] == 'restart':
255 self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
258 self["menulist"].setList(self.MakeMenu())
262 menu.append((_("Adapter settings"), "setting"))
263 menu.append((_("Scan Wireless AP"), "scanap"))
264 menu.append((_("Nameserver settings"), "dns"))
265 if iNetwork.getAdapterAttribute(self.iface, "up"):
266 menu.append((_("Show WLAN Status"), "status"))
267 menu.append((_("Network test"), "test"))
268 menu.append((_("Restart network"), "restart"))
272 def WlanScanApCallback(self, essid = None):
273 if essid is not None:
274 self.session.openWithCallback(self.checklist, WlanConfig, self.iface, essid)
276 def restartLan(self, ret = False):
278 iNetwork.restartNetwork(self.restartLanDataAvail)
279 self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while your network is restarting..."), type = MessageBox.TYPE_INFO, enable_input = False)
281 def restartLanDataAvail(self, data):
283 iNetwork.getInterfaces(self.getInterfacesDataAvail)
285 def getInterfacesDataAvail(self, data):
287 self.restartLanRef.close(True)
289 def restartfinishedCB(self,data):
291 self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 5, default = False)
294 iNetwork.stopRestartConsole()
295 iNetwork.stopGetInterfacesConsole()
297 wlanconfig = ConfigSubsection()
298 wlanconfig.usedevice = ConfigSelection(default = "off", choices = [
299 ("off", _("off")), ("on", _("on"))])
300 wlanconfig.usedhcp = ConfigSelection(default = "off", choices = [
301 ("off", _("no")), ("on", _("yes"))])
302 wlanconfig.essid = ConfigSelection(default = "none", choices = ["none"])
303 wlanconfig.encrypt = ConfigSelection(default = "off", choices = [
304 ("off", _("no")), ("on", _("yes"))])
305 wlanconfig.method = ConfigSelection(default = "wep", choices = [
306 ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
307 wlanconfig.keytype = ConfigSelection(default = "ascii", choices = [
308 ("ascii", _("ASCII")), ("hex", _("HEX"))])
309 wlanconfig.key = ConfigPassword(default = "XXXXXXXX", visible_width = 50, fixed_size = False)
310 wlanconfig.usegateway = ConfigSelection(default = "off", choices = [
311 ("off", _("no")), ("on", _("yes"))])
312 wlanconfig.ip = ConfigIP([0,0,0,0])
313 wlanconfig.netmask = ConfigIP([0,0,0,0])
314 wlanconfig.gateway = ConfigIP([0,0,0,0])
317 class WlanConfig(Screen, ConfigListScreen, HelpableScreen):
319 <screen position="center,center" size="510,400" title="Wireless Network Configuration..." >
320 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
321 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
323 <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" />
324 <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" />
326 <widget name="config" position="10,10" backgroundColor="#371e1c1a" transparent="1" size="480,210" scrollbarMode="showOnDemand" />
327 <ePixmap pixmap="skin_default/div-h.png" position="0,225" zPosition="1" size="550,2" />
328 <eLabel text="IP Address : " position="100,250" size="190,21" font="Regular;19" />
329 <widget source="ipaddress" render="Label" position="300,250" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" />
330 <eLabel text="NetMask : " position="100,275" size="190,21" font="Regular;19" />
331 <widget source="netmask" render="Label" position="300,275" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" />
332 <eLabel text="Gateway : " position="100,300" size="190,21" font="Regular;19" />
333 <widget source="gateway" render="Label" position="300,300" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" />
334 <widget name="VKeyIcon" pixmap="skin_default/buttons/key_text.png" position="460,230" zPosition="10" size="35,25" transparent="1" alphatest="on" />
335 <widget name="HelpWindow" pixmap="skin_default/buttons/key_text.png" position="383,420" zPosition="1" size="1,1" transparent="1" alphatest="on" />
338 def __init__(self, session, iface, essidSelected = None):
339 Screen.__init__(self,session)
340 self.session = session
341 self["key_red"] = StaticText(_("Close"))
342 self["key_green"] = StaticText(_("Ok"))
343 self["ipaddress"] = StaticText(_("[ N/A ]"))
344 self["netmask"] = StaticText(_("[ N/A ]"))
345 self["gateway"] = StaticText(_("[ N/A ]"))
346 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
348 "ok": self.saveWlanConfig,
349 "green": self.saveWlanConfig,
350 "cancel": self.keyCancel,
351 "red": self.keyCancel,
353 self["HelpWindow"] = Pixmap()
354 self["HelpWindow"].hide()
355 self["VKeyIcon"] = Pixmap()
356 self["VKeyIcon"].hide()
358 self.essidSelected = essidSelected
361 self.scan_ssid = None
365 self.encryption_key = None
366 self.wlanscanap = None
367 self.wpaphraseconsole = None
369 ConfigListScreen.__init__(self, self.list,session = self.session)
370 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
371 self.readWpaSupplicantConf()
372 self.scanAplistTimer = eTimer()
373 self.scanAplistTimer.callback.append(self.scanApList)
374 self.emptyListMsgTimer = eTimer()
375 self.emptyListMsgTimer.callback.append(self.emptyListMsg)
376 self.Console = Console()
377 self.updateInterfaces(self.readWlanSettings)
378 self.onClose.append(self.cleanup)
380 def updateInterfaces(self,callback = None):
381 iNetwork.config_ready = False
382 iNetwork.msgPlugins()
383 iNetwork.getInterfaces(callback)
385 def readWlanSettings(self,ret=None):
387 print "getInterfaces Fail... "
388 if iNetwork.getAdapterAttribute(self.iface, "up") == True:
392 wlanconfig.usedevice = ConfigSelection(default=default_tmp, choices = [("off", _("off")), ("on", _("on"))])
394 if iNetwork.getAdapterAttribute(self.iface, "dhcp"):
398 wlanconfig.usedhcp = ConfigSelection(default=default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
400 wlanconfig.ip = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0]
402 wlanconfig.netmask = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0])
403 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
407 wlanconfig.usegateway = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
409 wlanconfig.gateway = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0])
411 self["ipaddress"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "ip"))))
412 self["netmask"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "netmask"))))
413 self["gateway"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "gateway"))))
415 if self.encryption_key is not None:
419 wlanconfig.encrypt = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
421 if self.key_mgmt=="NONE":
423 elif self.key_mgmt == "WPA-PSK":
424 if self.proto == "WPA":
426 elif self.proto == "RSN":
428 elif self.proto in ( "WPA RSN", "WPA WPA2"):
429 default_tmp = "wpa/wpa2"
435 wlanconfig.method = ConfigSelection(default = default_tmp, choices = [
436 ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
438 if self.key_type == 0:
441 default_tmp = "ascii"
442 wlanconfig.keytype = ConfigSelection(default = default_tmp, choices = [
443 ("ascii", _("ASCII")), ("hex", _("HEX"))])
444 default_tmp = self.encryption_key or "XXXXXXXX"
445 wlanconfig.key = ConfigPassword(default = default_tmp, visible_width = 50, fixed_size = False)
448 def readWpaSupplicantConf(self):
450 if fileExists("/etc/wpa_supplicant.conf"):
451 wpafd = open("/etc/wpa_supplicant.conf","r")
453 data = wpafd.readline()
455 # print "####readWpaSupplicantConf, data : ",data
458 data = wpafd.readline()
460 if data.startswith('ssid=') and len(data) > 6:
461 self.ssid = data[6:-2]
462 elif data.startswith('ap_scan=') :
463 self.ap_scan = data[8:]
464 # print "####readWpaSupplicantConf, ap_scan : ",self.ap_scan
465 elif data.startswith('scan_ssid=') and len(data) > 10:
466 self.scan_ssid = data[10:-1]
467 elif data.startswith('key_mgmt=') and len(data) > 9:
468 self.key_mgmt = data[9:-1]
469 elif data.startswith('proto=') and len(data) > 6:
470 self.proto = data[6:-1]
471 elif data.startswith('wep_key0="') and len(data) > 11:
472 self.key_type = 1 # ascii
473 self.encryption_key = data[10:-2]
474 elif data.startswith('wep_key0=') and len(data) > 9:
475 self.key_type = 0 # hex
476 self.encryption_key = data[9:-1]
477 elif data.startswith('psk="') and len(data) > 6:
478 self.key_type = 1 # ascii
479 self.encryption_key = data[5:-2]
480 elif data.startswith('#psk="') and len(data) > 6:
481 self.key_type = 0 # hex
482 self.encryption_key = data[6:-2]
483 elif not self.encryption_key and data.startswith('psk=') and len(data) > 4:
484 self.key_type = 0 # hex
485 self.encryption_key = data[4:-1]
486 data = wpafd.readline()
487 # print self.ssid,self.scan_ssid,self.key_mgmt,self.proto,self.key_type,self.encryption_key
494 print 'failed loading wpasupplicant.conf'
496 def createConfig(self):
498 self.usedeviceEntry = getConfigListEntry(_("Use Device"), wlanconfig.usedevice)
499 self.usedhcpEntry = getConfigListEntry(_("Use DHCP"), wlanconfig.usedhcp)
500 self.essidEntry = getConfigListEntry(_("ESSID"), wlanconfig.essid)
501 self.hiddenessidEntry = getConfigListEntry(_("Input Hidden ESSID"), wlanconfig.hiddenessid)
502 self.encryptEntry = getConfigListEntry(_("Encrypt"), wlanconfig.encrypt)
503 self.methodEntry = getConfigListEntry(_("Method"), wlanconfig.method)
504 self.keytypeEntry = getConfigListEntry(_("Key Type"), wlanconfig.keytype)
505 self.keyEntry = getConfigListEntry(_("KEY"), wlanconfig.key)
507 self.ipEntry = getConfigListEntry(_("IP"), wlanconfig.ip)
508 self.netmaskEntry = getConfigListEntry(_("NetMask"), wlanconfig.netmask)
510 self.usegatewayEntry = getConfigListEntry(_("Use Gateway"), wlanconfig.usegateway)
511 self.gatewayEntry = getConfigListEntry(_("Gateway"), wlanconfig.gateway)
513 self.configList.append( self.usedeviceEntry )
514 if wlanconfig.usedevice.value is "on":
515 self.configList.append( self.usedhcpEntry )
516 if wlanconfig.usedhcp.value is "off":
517 self.configList.append(self.ipEntry)
518 self.configList.append(self.netmaskEntry)
519 self.configList.append(self.usegatewayEntry)
520 if wlanconfig.usegateway.value is "on":
521 self.configList.append(self.gatewayEntry)
522 self.configList.append( self.essidEntry )
523 if wlanconfig.essid.value == 'Input hidden ESSID':
524 self.configList.append( self.hiddenessidEntry )
525 self.configList.append( self.encryptEntry )
526 if wlanconfig.encrypt.value is "on" :
527 self.configList.append( self.methodEntry )
528 if wlanconfig.method.value =="wep":
529 self.configList.append( self.keytypeEntry )
530 self.configList.append( self.keyEntry )
532 self["config"].list = self.configList
533 self["config"].l.setList(self.configList)
534 if not self.showTextIcon in self["config"].onSelectionChanged:
535 self["config"].onSelectionChanged.append(self.showTextIcon)
537 def showTextIcon(self):
538 if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
539 self["VKeyIcon"].show()
541 self["VKeyIcon"].hide()
544 if self.essidSelected is None:
546 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
547 self.scanAplistTimer.start(100,True)
549 self.apList = [self.essidSelected]
550 wlanconfig.essid = ConfigSelection(choices = self.apList)
551 if self.ssid is not None:
552 wlanconfig.hiddenessid = ConfigText(default = self.ssid, visible_width = 50, fixed_size = False)
554 wlanconfig.hiddenessid = ConfigText(default = "<Input ESSID>", visible_width = 50, fixed_size = False)
557 def scanApList(self):
558 if self.oldInterfaceState is not True:
559 os_system("ifconfig "+self.iface+" up")
560 iNetwork.setAdapterAttribute(self.iface, "up", True)
562 wirelessObj = Wireless(self.iface)
564 Iwscanresult = wirelessObj.scan()
566 print "%s Interface doesn't support scanning.."%self.iface
567 # self.session.open(MessageBox, "%s Interface doesn't support scanning.."%self.iface, MessageBox.TYPE_ERROR,10)
568 self.configurationmsg.close(True)
569 if Iwscanresult is None:
570 self.emptyListMsgTimer.start(100,True)
572 for ap in Iwscanresult:
573 if ap.essid not in self.apList and len(ap.essid) > 0:
574 self.apList.append(ap.essid)
575 self.apList.append('Input hidden ESSID')
576 if selectap is not None and selectap in self.apList:
577 wlanconfig.essid = ConfigSelection(default=selectap,choices = self.apList)
578 elif self.scan_ssid is not None and self.scan_ssid.strip() == '1':
579 wlanconfig.essid = ConfigSelection(default='Input hidden ESSID',choices = self.apList)
580 elif self.ssid is not None and self.ssid in self.apList:
581 wlanconfig.essid = ConfigSelection(default=self.ssid, choices = self.apList)
584 wlanconfig.essid = ConfigSelection(defalut = self.apList[0], choices = self.apList)
586 wlanconfig.essid = ConfigSelection(choices = self.apList)
587 if self.ssid is not None:
588 wlanconfig.hiddenessid = ConfigText(default = self.ssid, visible_width = 50, fixed_size = False)
590 wlanconfig.hiddenessid = ConfigText(default = "<Input ESSID>", visible_width = 50, fixed_size = False)
593 def emptyListMsg(self):
594 self.session.open(MessageBox, _("No AP detected."), type = MessageBox.TYPE_INFO, timeout = 10)
597 ConfigListScreen.keyLeft(self)
601 ConfigListScreen.keyRight(self)
605 if self["config"].getCurrent() == self.usedeviceEntry or self["config"].getCurrent() == self.encryptEntry \
606 or self["config"].getCurrent() == self.usedhcpEntry or self["config"].getCurrent() == self.usegatewayEntry \
607 or self["config"].getCurrent() == self.essidEntry or self["config"].getCurrent() == self.methodEntry:
610 def saveWlanConfig(self):
612 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
613 self["config"].getCurrent()[1].onDeselect(self.session)
614 if self["config"].isChanged():
615 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Are you sure you want to restart your network interfaces?\n") ) )
617 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Network configuration is not changed....\n\nAre you sure you want to restart your network interfaces?\n") ) )
621 def checkNetworkConfig(self, ret = False):
623 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
624 self["config"].getCurrent()[1].onSelect(self.session)
626 if wlanconfig.essid.value == 'Input hidden ESSID':
627 if len(wlanconfig.hiddenessid.value) == 0:
628 self.session.open(MessageBox, ("PLEASE INPUT HIDDEN ESSID"), type = MessageBox.TYPE_ERROR, timeout = 10)
630 if len(wlanconfig.key.value) == 0:
631 self.session.open(MessageBox, ("PLEASE INPUT NETWORK KEY"), type = MessageBox.TYPE_ERROR, timeout = 10)
633 self.checkNetworkShares()
635 def checkNetworkShares(self):
637 self.Console = Console()
638 cmd = "cat /proc/mounts"
639 self.Console.ePopen(cmd, self.checkSharesFinished, self.confirmAnotherIfaces)
641 def checkSharesFinished(self, result, retval, extra_args):
642 callback = extra_args
643 # print "checkMountsFinished : result : \n",result
644 networks = ['nfs','smbfs','ncp','coda']
645 for line in result.splitlines():
646 split = line.strip().split(' ',3)
647 if split[2] in networks:
648 self.session.open(MessageBox, ("NOT deconfiguring network interfaces :\n network shares still mounted\n"), type = MessageBox.TYPE_ERROR, timeout = 10)
650 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
651 self["config"].getCurrent()[1].onSelect(self.session)
655 def confirmAnotherIfaces(self, ret = False):
659 num_configured_if = len(iNetwork.getConfiguredAdapters())
660 if num_configured_if >= 1:
661 if num_configured_if == 1 and self.iface in iNetwork.getConfiguredAdapters():
662 self.getWpaPhrase(False)
664 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)
666 self.getWpaPhrase(False)
668 def getWpaPhrase(self,ret):
670 configuredInterfaces = iNetwork.getConfiguredAdapters()
671 for interface in configuredInterfaces:
672 if interface == self.iface:
674 iNetwork.setAdapterAttribute(interface, "up", False)
675 iNetwork.deactivateInterface(interface)
676 if wlanconfig.method.value =="wep":
677 self.writeWpasupplicantConf("wep") # passphrasekey is not None
679 if wlanconfig.essid.value == 'Input hidden ESSID':
680 cmd = "wpa_passphrase '%s' %s" % (wlanconfig.hiddenessid.value,wlanconfig.key.value)
682 cmd = "wpa_passphrase '%s' %s" % (wlanconfig.essid.value,wlanconfig.key.value)
684 self.wpaphraseconsole = Console()
685 self.wpaphraseconsole.ePopen(cmd, self.parseWpaPhrase, self.writeWpasupplicantConf)
687 def parseWpaPhrase(self, result, retval, extra_args):
688 (writewlanconfig) = extra_args
689 if self.wpaphraseconsole is not None:
691 self.wpaphraseconsole.killAll()
692 self.wpaphraseconsole = None
693 # print "parseWpaPhrase result : "
696 for line in result.splitlines():
697 if line.find('ssid') == -1 and line.find('#psk=') != -1:
699 elif line.find('psk=') != -1:
702 writewlanconfig(psk,plainpwd)
704 writewlanconfig(None)
706 writewlanconfig(None)
708 def writeWpasupplicantConf(self, passphrasekey=None,plainpwd=None):
710 wpafd = open("/etc/wpa_supplicant.conf","w")
712 contents = "#WPA Supplicant Configuration by STB\n"
713 contents += "ctrl_interface=/var/run/wpa_supplicant\n"
714 contents += "eapol_version=1\n"
715 contents += "fast_reauth=1\n"
716 contents += "ap_scan=1\n"
717 contents += "network={\n"
718 if wlanconfig.essid.value == 'Input hidden ESSID':
719 contents += "\tssid=\""+wlanconfig.hiddenessid.value+"\"\n"
720 contents += "\tscan_ssid=1\n"
722 contents += "\tssid=\""+wlanconfig.essid.value+"\"\n"
723 contents += "\tscan_ssid=0\n"
724 if wlanconfig.encrypt.value == "on":
725 if wlanconfig.method.value =="wep":
726 contents += "\tkey_mgmt=NONE\n"
727 contents += "\twep_key0="
728 if wlanconfig.keytype.value == "ascii":
729 contents += "\""+wlanconfig.key.value+"\"\n"
731 contents += wlanconfig.key.value+"\n"
733 # print "plainpwd : ",plainpwd
734 # print "passphrasekey : ",passphrasekey
735 if wlanconfig.method.value == "wpa":
736 contents += "\tkey_mgmt=WPA-PSK\n"
737 contents += "\tproto=WPA\n"
738 contents += "\tpairwise=CCMP TKIP\n"
739 contents += "\tgroup=CCMP TKIP\n"
740 elif wlanconfig.method.value == "wpa2":
741 contents += "\tkey_mgmt=WPA-PSK\n"
742 contents += "\tproto=RSN\n"
743 contents += "\tpairwise=CCMP TKIP\n"
744 contents += "\tgroup=CCMP TKIP\n"
746 contents += "\tkey_mgmt=WPA-PSK\n"
747 contents += "\tproto=WPA RSN\n"
748 contents += "\tpairwise=CCMP TKIP\n"
749 contents += "\tgroup=CCMP TKIP\n"
750 contents += plainpwd+"\n"
751 contents += passphrasekey+"\n"
753 contents += "\tkey_mgmt=NONE\n"
755 print "content = \n"+contents
756 wpafd.write(contents)
758 self.writeNetConfig(0)
760 self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
761 self.writeNetConfig(-1)
763 self.writeNetConfig(-2)
765 def writeNetConfig(self,ret = -1):
767 self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
770 self.session.open(MessageBox, _("Can NOT generate passphrase"), type = MessageBox.TYPE_ERROR, timeout = 10)
773 if wlanconfig.usedevice.value=="on":
774 iNetwork.setAdapterAttribute(self.iface, "up", True)
775 if wlanconfig.usedhcp.value =="on":
776 iNetwork.setAdapterAttribute(self.iface, "dhcp", True)
778 iNetwork.setAdapterAttribute(self.iface, "dhcp", False)
779 iNetwork.setAdapterAttribute(self.iface, "ip", wlanconfig.ip.value)
780 iNetwork.setAdapterAttribute(self.iface, "netmask", wlanconfig.netmask.value)
781 if wlanconfig.usegateway.value == "on":
782 iNetwork.setAdapterAttribute(self.iface, "gateway", wlanconfig.gateway.value)
784 iNetwork.setAdapterAttribute(self.iface, "up", False)
785 iNetwork.deactivateInterface(self.iface)
786 contents = "\tpre-up wpa_supplicant -i"+self.iface+" -c/etc/wpa_supplicant.conf -B -D"+iNetwork.detectWlanModule(self.iface)+"\n"
787 contents += "\tpost-down wpa_cli terminate\n\n"
788 iNetwork.setAdapterAttribute(self.iface, "configStrings", contents)
789 iNetwork.writeNetworkConfig()
790 iNetwork.restartNetwork(self.updateCurrentInterfaces)
791 self.configurationmsg = None
792 self.configurationmsg = self.session.openWithCallback(self.configFinished, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
795 def updateCurrentInterfaces(self,ret):
797 iNetwork.getInterfaces(self.configurationMsgClose)
799 def configurationMsgClose(self,ret):
800 if ret is True and self.configurationmsg is not None:
801 self.configurationmsg.close(True)
803 def configFinished(self,data):
806 self.session.openWithCallback(self.configFinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
807 selectap = wlanconfig.essid.value
809 def configFinishedCB(self,data):
814 def formatip(self, iplist):
817 # print "iplist : ",iplist
820 result = str(iplist[0])+"."+str(iplist[1])+"."+str(iplist[2])+"."+str(iplist[3])
823 # print "result : ",result
828 def keyCancelConfirm(self, result):
831 if self.oldInterfaceState is False:
832 iNetwork.setAdapterAttribute(self.iface, "up", False)
833 iNetwork.deactivateInterface(self.iface,self.keyCancelCB)
837 def keyCancel(self,yesno = True):
838 if self["config"].isChanged():
839 self.session.openWithCallback(self.keyCancelConfirm, MessageBox, _("Really close without saving settings?"))
841 self.keyCancelConfirm(True)
843 def keyCancelCB(self,data):
849 iNetwork.stopRestartConsole()
850 iNetwork.stopGetInterfacesConsole()
851 iNetwork.stopDeactivateInterfaceConsole()
852 self.stopwlanscanapConsole()
853 self.stopCheckNetworkSharesConsole()
854 self.stopWpaPhraseConsole()
856 def stopwlanscanapConsole(self):
857 if self.wlanscanap is not None:
858 if len(self.wlanscanap.appContainers):
859 for name in self.wlanscanap.appContainers.keys():
860 self.wlanscanap.kill(name)
862 def stopCheckNetworkSharesConsole(self):
863 if self.Console is not None:
864 if len(self.Console.appContainers):
865 for name in self.Console.appContainers.keys():
866 self.Console.kill(name)
868 def stopWpaPhraseConsole(self):
869 if self.wpaphraseconsole is not None:
870 if len(self.wpaphraseconsole.appContainers):
871 for name in self.wpaphraseconsole.appContainers.keys():
872 self.wpaphraseconsole.kill(name)
874 class WlanScanAp(Screen,HelpableScreen):
876 <screen position="center,center" size="510,400" title="Wireless Network AP Scan..." >
877 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
878 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
880 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
881 <ePixmap pixmap="skin_default/buttons/green.png" position="185,360" size="140,40" alphatest="on" />
882 <ePixmap pixmap="skin_default/buttons/blue.png" position="360,360" size="140,40" alphatest="on" />
884 <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" />
885 <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" />
886 <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" />
888 <widget name="menulist" position="20,20" size="230,260" backgroundColor="#371e1c1a" transparent="1" zPosition="10" scrollbarMode="showOnDemand" />
890 <widget source="Address" render="Label" position="265,70" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
891 <widget source="ESSID" render="Label" position="265,100" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
892 <widget source="Protocol" render="Label" position="265,130" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
893 <widget source="Frequency" render="Label" position="265,160" zPosition="1" size="240,40" font="Regular;18" halign="center" valign="center" />
894 <widget source="Encryption key" render="Label" position="265,200" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
895 <widget source="BitRate" render="Label" position="265,220" zPosition="1" size="240,60" font="Regular;18" halign="center" valign="center" />
898 def __init__(self, session, iface):
899 Screen.__init__(self,session)
900 HelpableScreen.__init__(self)
901 self.session = session
903 self.wlanscanap = None
907 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
909 "up": (self.up, _("move up to previous entry")),
910 "down": (self.down, _("move down to next entry")),
911 "left": (self.left, _("move up to first entry")),
912 "right": (self.right, _("move down to last entry")),
915 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
917 "cancel": (self.close, _("exit")),
918 "ok": (self.ok, "select AP"),
921 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
923 "red": (self.close, _("exit")),
924 "green": (self.ok, "select AP"),
925 "yellow": (self.restartScanAP, "restart scan AP"),
926 "blue": (self.startWlanConfig, "Edit Wireless settings"),
929 self["menulist"] = MenuList(self.setApList)
930 self["key_red"] = StaticText(_("Close"))
931 self["key_green"] = StaticText(_("Select"))
932 self["key_blue"] = StaticText(_("EditSetting"))
933 self["Address"] = StaticText(_("Scanning AP List.."))
934 self["ESSID"] = StaticText(_("Wait a moment"))
935 self["Protocol"] = StaticText(" ")
936 self["Frequency"] = StaticText(" ")
937 self["Encryption key"] = StaticText(" ")
938 self["BitRate"] = StaticText(" ")
939 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
940 self.getAplistTimer = eTimer()
941 self.getAplistTimer.callback.append(self.getApList)
942 self.scanAplistTimer = eTimer()
943 self.scanAplistTimer.callback.append(self.scanApList)
944 self.emptyListMsgTimer = eTimer()
945 self.emptyListMsgTimer.callback.append(self.emptyListMsg)
947 self.onClose.append(self.__onClose)
948 self.getAplistTimer.start(100,True)
951 self["menulist"].pageUp()
955 self["menulist"].pageDown()
959 self["menulist"].up()
963 self["menulist"].down()
968 selectAp=self["menulist"].getCurrent()[0]
972 def startWlanConfig(self):
973 selectAp=self["menulist"].getCurrent()[0]
979 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
980 self.scanAplistTimer.start(100,True)
982 def scanApList(self):
983 if self.oldInterfaceState is not True:
984 os_system("ifconfig "+self.iface+" up")
985 iNetwork.setAdapterAttribute(self.iface, "up", True)
987 wirelessObj = Wireless(self.iface)
989 Iwscanresult = wirelessObj.scan()
991 print "%s Interface doesn't support scanning.."%self.iface
992 # self.session.open(MessageBox, "%s Interface doesn't support scanning.."%self.iface, MessageBox.TYPE_ERROR,10)
993 self.configurationmsg.close(True)
994 if Iwscanresult is not None:
995 (num_channels, frequencies) = wirelessObj.getChannelInfo()
997 for ap in Iwscanresult:
998 self.apList[index] = {}
999 self.apList[index]["Address"] = ap.bssid
1000 if len(ap.essid) == 0:
1001 self.apList[index]["ESSID"] = "<hidden ESSID>"
1003 self.apList[index]["ESSID"] = ap.essid
1004 self.setApList.append( (self.apList[index]["ESSID"], index) )
1005 self.apList[index]["Protocol"] = ap.protocol
1006 self.apList[index]["Frequency"] = wirelessObj._formatFrequency(ap.frequency.getFrequency())
1008 self.apList[index]["Channel"] = frequencies.index(self.apList[index]["Frequency"] + 1)
1010 self.apList[index]["Channel"] = "Unknown"
1012 self.apList[index]["Quality"] = "%s/%s" % \
1013 ( ap.quality.quality, wirelessObj.getQualityMax().quality )
1014 self.apList[index]["Signal Level"] = "%s/%s" % \
1015 ( ap.quality.getSignallevel(), "100" )
1016 self.apList[index]["Noise Level"] = "%s/%s" % \
1017 ( ap.quality.getNoiselevel(), "100" )
1019 # get encryption key on/off
1020 key_status = "Unknown"
1021 if (ap.encode.flags & pythonwifi.flags.IW_ENCODE_DISABLED):
1023 elif (ap.encode.flags & pythonwifi.flags.IW_ENCODE_NOKEY):
1024 if (ap.encode.length <= 0):
1026 self.apList[index]["Encryption key"] = key_status
1027 self.apList[index]["BitRate"] = wirelessObj._formatBitrate(ap.rate[-1][-1])
1030 # print self.setApList
1031 self.displayApInfo()
1032 if len(self.apList) == 0:
1033 self.emptyListMsgTimer.start(100,True)
1035 def displayApInfo(self):
1036 if len(self.apList) >0:
1037 self["menulist"].setList(self.setApList)
1038 index = self["menulist"].getCurrent()[1]
1039 for key in ["Address", "ESSID", "Protocol", "Frequency", "Encryption key", "BitRate"]:
1040 if self.apList[index].has_key(key):
1041 self[key].setText((key+": "+self.apList[index][key]))
1043 self[key].setText((key+": None"))
1045 def emptyListMsg(self):
1046 self.session.open(MessageBox, _("No AP detected."), type = MessageBox.TYPE_INFO, timeout = 10)
1047 self["Address"].setText(_("No AP detected."))
1048 self["ESSID"].setText(_(""))
1050 def restartScanAP(self):
1051 self.getAplistTimer.start(100,True)
1053 def __onClose(self):
1054 if self.oldInterfaceState is False:
1055 iNetwork.setAdapterAttribute(self.iface, "up", False)
1056 iNetwork.deactivateInterface(self.iface)
1058 class NetworkAdapterTest(Screen):
1059 def __init__(self, session,iface):
1060 Screen.__init__(self, session)
1062 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
1064 self.onClose.append(self.cleanup)
1065 self.onHide.append(self.cleanup)
1067 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
1071 "up": lambda: self.updownhandler('up'),
1072 "down": lambda: self.updownhandler('down'),
1076 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1079 "back": self.cancel,
1081 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1083 "red": self.closeInfo,
1084 "back": self.closeInfo,
1086 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
1088 "green": self.KeyGreen,
1090 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
1092 "green": self.KeyGreenRestart,
1094 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
1096 "yellow": self.KeyYellow,
1099 self["shortcutsgreen_restart"].setEnabled(False)
1100 self["updown_actions"].setEnabled(False)
1101 self["infoshortcuts"].setEnabled(False)
1102 self.onClose.append(self.delTimer)
1103 self.onLayoutFinish.append(self.layoutFinished)
1104 self.steptimer = False
1106 self.activebutton = 0
1107 self.nextStepTimer = eTimer()
1108 self.nextStepTimer.callback.append(self.nextStepTimerFire)
1111 if self.oldInterfaceState is False:
1112 iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
1113 iNetwork.deactivateInterface(self.iface)
1116 def closeInfo(self):
1117 self["shortcuts"].setEnabled(True)
1118 self["infoshortcuts"].setEnabled(False)
1119 self["InfoText"].hide()
1120 self["InfoTextBorder"].hide()
1121 self["key_red"].setText(_("Close"))
1125 del self.nextStepTimer
1127 def nextStepTimerFire(self):
1128 self.nextStepTimer.stop()
1129 self.steptimer = False
1132 def updownhandler(self,direction):
1133 if direction == 'up':
1134 if self.activebutton >=2:
1135 self.activebutton -= 1
1137 self.activebutton = 6
1138 self.setActiveButton(self.activebutton)
1139 if direction == 'down':
1140 if self.activebutton <=5:
1141 self.activebutton += 1
1143 self.activebutton = 1
1144 self.setActiveButton(self.activebutton)
1146 def setActiveButton(self,button):
1148 self["EditSettingsButton"].setPixmapNum(0)
1149 self["EditSettings_Text"].setForegroundColorNum(0)
1150 self["NetworkInfo"].setPixmapNum(0)
1151 self["NetworkInfo_Text"].setForegroundColorNum(1)
1152 self["AdapterInfo"].setPixmapNum(1) # active
1153 self["AdapterInfo_Text"].setForegroundColorNum(2) # active
1155 self["AdapterInfo_Text"].setForegroundColorNum(1)
1156 self["AdapterInfo"].setPixmapNum(0)
1157 self["DhcpInfo"].setPixmapNum(0)
1158 self["DhcpInfo_Text"].setForegroundColorNum(1)
1159 self["NetworkInfo"].setPixmapNum(1) # active
1160 self["NetworkInfo_Text"].setForegroundColorNum(2) # active
1162 self["NetworkInfo"].setPixmapNum(0)
1163 self["NetworkInfo_Text"].setForegroundColorNum(1)
1164 self["IPInfo"].setPixmapNum(0)
1165 self["IPInfo_Text"].setForegroundColorNum(1)
1166 self["DhcpInfo"].setPixmapNum(1) # active
1167 self["DhcpInfo_Text"].setForegroundColorNum(2) # active
1169 self["DhcpInfo"].setPixmapNum(0)
1170 self["DhcpInfo_Text"].setForegroundColorNum(1)
1171 self["DNSInfo"].setPixmapNum(0)
1172 self["DNSInfo_Text"].setForegroundColorNum(1)
1173 self["IPInfo"].setPixmapNum(1) # active
1174 self["IPInfo_Text"].setForegroundColorNum(2) # active
1176 self["IPInfo"].setPixmapNum(0)
1177 self["IPInfo_Text"].setForegroundColorNum(1)
1178 self["EditSettingsButton"].setPixmapNum(0)
1179 self["EditSettings_Text"].setForegroundColorNum(0)
1180 self["DNSInfo"].setPixmapNum(1) # active
1181 self["DNSInfo_Text"].setForegroundColorNum(2) # active
1183 self["DNSInfo"].setPixmapNum(0)
1184 self["DNSInfo_Text"].setForegroundColorNum(1)
1185 self["EditSettingsButton"].setPixmapNum(1) # active
1186 self["EditSettings_Text"].setForegroundColorNum(2) # active
1187 self["AdapterInfo"].setPixmapNum(0)
1188 self["AdapterInfo_Text"].setForegroundColorNum(1)
1191 next = self.nextstep
1207 self.steptimer = True
1208 self.nextStepTimer.start(3000)
1209 self["key_yellow"].setText(_("Stop test"))
1212 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
1213 self["Adapter"].setForegroundColorNum(2)
1214 self["Adaptertext"].setForegroundColorNum(1)
1215 self["AdapterInfo_Text"].setForegroundColorNum(1)
1216 self["AdapterInfo_OK"].show()
1217 self.steptimer = True
1218 self.nextStepTimer.start(3000)
1221 self["Networktext"].setForegroundColorNum(1)
1222 self["Network"].setText(_("Please wait..."))
1223 self.AccessPointInfo(self.iface)
1224 self["NetworkInfo_Text"].setForegroundColorNum(1)
1225 self.steptimer = True
1226 self.nextStepTimer.start(3000)
1229 self["Dhcptext"].setForegroundColorNum(1)
1230 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
1231 self["Dhcp"].setForegroundColorNum(2)
1232 self["Dhcp"].setText(_("enabled"))
1233 self["DhcpInfo_Check"].setPixmapNum(0)
1235 self["Dhcp"].setForegroundColorNum(1)
1236 self["Dhcp"].setText(_("disabled"))
1237 self["DhcpInfo_Check"].setPixmapNum(1)
1238 self["DhcpInfo_Check"].show()
1239 self["DhcpInfo_Text"].setForegroundColorNum(1)
1240 self.steptimer = True
1241 self.nextStepTimer.start(3000)
1244 self["IPtext"].setForegroundColorNum(1)
1245 self["IP"].setText(_("Please wait..."))
1246 iNetwork.checkNetworkState(self.NetworkStatedataAvail)
1249 self.steptimer = False
1250 self.nextStepTimer.stop()
1251 self["DNStext"].setForegroundColorNum(1)
1252 self["DNS"].setText(_("Please wait..."))
1253 iNetwork.checkDNSLookup(self.DNSLookupdataAvail)
1256 self["shortcutsgreen"].setEnabled(False)
1257 self["shortcutsyellow"].setEnabled(True)
1258 self["updown_actions"].setEnabled(False)
1259 self["key_yellow"].setText("")
1260 self["key_green"].setText("")
1261 self.steptimer = True
1262 self.nextStepTimer.start(1000)
1264 def KeyGreenRestart(self):
1266 self.layoutFinished()
1267 self["Adapter"].setText((""))
1268 self["Network"].setText((""))
1269 self["Dhcp"].setText((""))
1270 self["IP"].setText((""))
1271 self["DNS"].setText((""))
1272 self["AdapterInfo_Text"].setForegroundColorNum(0)
1273 self["NetworkInfo_Text"].setForegroundColorNum(0)
1274 self["DhcpInfo_Text"].setForegroundColorNum(0)
1275 self["IPInfo_Text"].setForegroundColorNum(0)
1276 self["DNSInfo_Text"].setForegroundColorNum(0)
1277 self["shortcutsgreen_restart"].setEnabled(False)
1278 self["shortcutsgreen"].setEnabled(False)
1279 self["shortcutsyellow"].setEnabled(True)
1280 self["updown_actions"].setEnabled(False)
1281 self["key_yellow"].setText("")
1282 self["key_green"].setText("")
1283 self.steptimer = True
1284 self.nextStepTimer.start(1000)
1287 self["infoshortcuts"].setEnabled(True)
1288 self["shortcuts"].setEnabled(False)
1289 if self.activebutton == 1: # Adapter Check
1290 self["InfoText"].setText(_("This test detects your configured Wireless LAN-Adapter."))
1291 self["InfoTextBorder"].show()
1292 self["InfoText"].show()
1293 self["key_red"].setText(_("Back"))
1294 if self.activebutton == 2: #LAN Check
1295 self["InfoText"].setText(_("This test checks whether a network cable is connected to your Wireless LAN-Adapter."))
1296 self["InfoTextBorder"].show()
1297 self["InfoText"].show()
1298 self["key_red"].setText(_("Back"))
1299 if self.activebutton == 3: #DHCP Check
1300 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."))
1301 self["InfoTextBorder"].show()
1302 self["InfoText"].show()
1303 self["key_red"].setText(_("Back"))
1304 if self.activebutton == 4: # IP Check
1305 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"))
1306 self["InfoTextBorder"].show()
1307 self["InfoText"].show()
1308 self["key_red"].setText(_("Back"))
1309 if self.activebutton == 5: # DNS Check
1310 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"))
1311 self["InfoTextBorder"].show()
1312 self["InfoText"].show()
1313 self["key_red"].setText(_("Back"))
1314 if self.activebutton == 6: # Edit Settings
1316 self.session.open(WlanConfig,self.iface)
1317 self["shortcuts"].setEnabled(True)
1318 self["infoshortcuts"].setEnabled(False)
1320 def KeyYellow(self):
1322 self["shortcutsgreen_restart"].setEnabled(True)
1323 self["shortcutsgreen"].setEnabled(False)
1324 self["shortcutsyellow"].setEnabled(False)
1325 self["key_green"].setText(_("Restart test"))
1326 self["key_yellow"].setText("")
1327 self.steptimer = False
1328 self.nextStepTimer.stop()
1330 def layoutFinished(self):
1331 self.setTitle(_("Network test: ") + iNetwork.getFriendlyAdapterName(self.iface) )
1332 self["shortcutsyellow"].setEnabled(False)
1333 self["AdapterInfo_OK"].hide()
1334 self["NetworkInfo_Check"].hide()
1335 self["DhcpInfo_Check"].hide()
1336 self["IPInfo_Check"].hide()
1337 self["DNSInfo_Check"].hide()
1338 self["EditSettings_Text"].hide()
1339 self["EditSettingsButton"].hide()
1340 self["InfoText"].hide()
1341 self["InfoTextBorder"].hide()
1342 self["key_yellow"].setText("")
1344 def setLabels(self):
1345 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1346 self["Adapter"] = MultiColorLabel()
1347 self["AdapterInfo"] = MultiPixmap()
1348 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1349 self["AdapterInfo_OK"] = Pixmap()
1351 if self.iface in iNetwork.wlan_interfaces:
1352 self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1354 self["Networktext"] = MultiColorLabel(_("Local Network"))
1356 self["Network"] = MultiColorLabel()
1357 self["NetworkInfo"] = MultiPixmap()
1358 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1359 self["NetworkInfo_Check"] = MultiPixmap()
1361 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1362 self["Dhcp"] = MultiColorLabel()
1363 self["DhcpInfo"] = MultiPixmap()
1364 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1365 self["DhcpInfo_Check"] = MultiPixmap()
1367 self["IPtext"] = MultiColorLabel(_("IP Address"))
1368 self["IP"] = MultiColorLabel()
1369 self["IPInfo"] = MultiPixmap()
1370 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1371 self["IPInfo_Check"] = MultiPixmap()
1373 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1374 self["DNS"] = MultiColorLabel()
1375 self["DNSInfo"] = MultiPixmap()
1376 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1377 self["DNSInfo_Check"] = MultiPixmap()
1379 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1380 self["EditSettingsButton"] = MultiPixmap()
1382 self["key_red"] = StaticText(_("Close"))
1383 self["key_green"] = StaticText(_("Start test"))
1384 self["key_yellow"] = StaticText(_("Stop test"))
1386 self["InfoTextBorder"] = Pixmap()
1387 self["InfoText"] = Label()
1389 def NetworkStatedataAvail(self,data):
1391 self["IP"].setForegroundColorNum(2)
1392 self["IP"].setText(_("confirmed"))
1393 self["IPInfo_Check"].setPixmapNum(0)
1395 self["IP"].setForegroundColorNum(1)
1396 self["IP"].setText(_("unconfirmed"))
1397 self["IPInfo_Check"].setPixmapNum(1)
1398 self["IPInfo_Check"].show()
1399 self["IPInfo_Text"].setForegroundColorNum(1)
1400 self.steptimer = True
1401 self.nextStepTimer.start(3000)
1403 def DNSLookupdataAvail(self,data):
1405 self["DNS"].setForegroundColorNum(2)
1406 self["DNS"].setText(_("confirmed"))
1407 self["DNSInfo_Check"].setPixmapNum(0)
1409 self["DNS"].setForegroundColorNum(1)
1410 self["DNS"].setText(_("unconfirmed"))
1411 self["DNSInfo_Check"].setPixmapNum(1)
1412 self["DNSInfo_Check"].show()
1413 self["DNSInfo_Text"].setForegroundColorNum(1)
1414 self["EditSettings_Text"].show()
1415 self["EditSettingsButton"].setPixmapNum(1)
1416 self["EditSettings_Text"].setForegroundColorNum(2) # active
1417 self["EditSettingsButton"].show()
1418 self["key_yellow"].setText("")
1419 self["key_green"].setText(_("Restart test"))
1420 self["shortcutsgreen"].setEnabled(False)
1421 self["shortcutsgreen_restart"].setEnabled(True)
1422 self["shortcutsyellow"].setEnabled(False)
1423 self["updown_actions"].setEnabled(True)
1424 self.activebutton = 6
1426 def getInfoCB(self,status):
1427 if status is not None:
1428 if status.startswith("No Connection") or status.startswith("Not-Associated") or status == False:
1429 self["Network"].setForegroundColorNum(1)
1430 self["Network"].setText(_("disconnected"))
1431 self["NetworkInfo_Check"].setPixmapNum(1)
1432 self["NetworkInfo_Check"].show()
1434 self["Network"].setForegroundColorNum(2)
1435 self["Network"].setText(_("connected"))
1436 self["NetworkInfo_Check"].setPixmapNum(0)
1437 self["NetworkInfo_Check"].show()
1440 iNetwork.stopLinkStateConsole()
1441 iNetwork.stopPingConsole()
1442 iNetwork.stopDNSConsole()
1444 def AccessPointInfo(self,iface):
1445 cmd = "iwconfig %s"%iface
1446 self.iwconfigConsole = Console()
1447 self.iwconfigConsole.ePopen(cmd,self.readAP,self.getInfoCB)
1449 def readAP(self,result,retval,extra_args):
1450 (callback) = extra_args
1452 if self.iwconfigConsole is not None:
1454 self.iwconfigConsole = None
1455 for content in result.splitlines():
1456 if 'Access Point' in content:
1457 self.apState = content.strip().split('Access Point: ')[1]
1458 callback(self.apState)
1460 callback(self.apState)
1462 class Wlanstatus(Screen):
1464 <screen position="center,center" size="510,400" title="Wireless Network Status..." >
1465 <widget source="status" render="Label" position="5,15" size="500,350" font="Regular;18" zPosition="1" />
1467 <ePixmap pixmap="skin_default/buttons/red.png" position="185,360" size="140,40" alphatest="on" />
1468 <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" />
1471 def __init__(self, session,iface):
1472 Screen.__init__(self,session)
1473 self.session = session
1475 self["status"] = StaticText(_("Wait a moment..."))
1476 self["key_red"] = StaticText(_("Close"))
1477 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
1480 "cancel": self.close,
1484 self.onClose.append(self.cleanup)
1486 def readstatus(self):
1487 self.wlanstatus = Console()
1488 cmd1 = "iwconfig "+self.iface
1489 self.wlanstatus.ePopen(cmd1, self.iwconfigfinnished,self.statusdisplay)
1491 def iwconfigfinnished(self, result, retval,extra_args):
1493 (statecallback) = extra_args
1494 if self.wlanstatus is not None:
1496 statecallback(result)
1503 def statusdisplay(self,data):
1505 self["status"].setText(_("No information..."))
1507 self["status"].setText(data)
1513 self.stopWlanStatusConsole()
1515 def stopWlanStatusConsole(self):
1516 if self.wlanstatus is not None:
1517 if len(self.wlanstatus.appContainers):
1518 for name in self.wlanstatus.appContainers.keys():
1519 self.wlanstatus.kill(name)
1521 def openconfig(session, **kwargs):
1522 session.open(WlanSelection)
1524 def selSetup(menuid, **kwargs):
1526 if menuid != "system":
1529 for x in iNetwork.getInstalledAdapters():
1530 if x.startswith('eth'):
1534 return [(_("Wireless LAN Setup"), openconfig, "wlansetup_config", 80)]
1539 def Plugins(**kwargs):
1540 return PluginDescriptor(name=_("Wireless LAN Setup"), description="Wireless LAN Setup", where = PluginDescriptor.WHERE_MENU, fnc=selSetup)