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" />
317 <widget name="VKeyIcon" pixmap="skin_default/buttons/key_text.png" position="460,230" zPosition="10" size="35,25" transparent="1" alphatest="on" />
318 <widget name="HelpWindow" pixmap="skin_default/buttons/key_text.png" position="383,420" zPosition="1" size="1,1" transparent="1" alphatest="on" />
321 def __init__(self, session, iface, essidSelected = None):
322 Screen.__init__(self,session)
323 self.session = session
324 self["key_red"] = StaticText(_("Close"))
325 self["key_green"] = StaticText(_("Ok"))
326 self["ipaddress"] = StaticText(_("[ N/A ]"))
327 self["netmask"] = StaticText(_("[ N/A ]"))
328 self["gateway"] = StaticText(_("[ N/A ]"))
329 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
331 "ok": self.saveWlanConfig,
332 "green": self.saveWlanConfig,
333 "cancel": self.keyCancel,
334 "red": self.keyCancel,
336 self["HelpWindow"] = Pixmap()
337 self["HelpWindow"].hide()
338 self["VKeyIcon"] = Pixmap()
339 self["VKeyIcon"].hide()
341 self.essidSelected = essidSelected
344 self.scan_ssid = None
348 self.encryption_key = None
349 self.wlanscanap = None
350 self.wpaphraseconsole = None
352 ConfigListScreen.__init__(self, self.list,session = self.session)
353 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
354 self.readWpaSupplicantConf()
355 self.scanAplistTimer = eTimer()
356 self.scanAplistTimer.callback.append(self.scanApList)
357 self.emptyListMsgTimer = eTimer()
358 self.emptyListMsgTimer.callback.append(self.emptyListMsg)
359 self.Console = Console()
360 self.updateInterfaces(self.readWlanSettings)
361 self.onClose.append(self.cleanup)
363 def updateInterfaces(self,callback = None):
364 iNetwork.config_ready = False
365 iNetwork.msgPlugins()
366 iNetwork.getInterfaces(callback)
368 def readWlanSettings(self,ret=None):
370 print "getInterfaces Fail... "
371 if iNetwork.getAdapterAttribute(self.iface, "up") == True:
375 wlanconfig.usedevice = ConfigSelection(default=default_tmp, choices = [("off", _("off")), ("on", _("on"))])
377 if iNetwork.getAdapterAttribute(self.iface, "dhcp"):
381 wlanconfig.usedhcp = ConfigSelection(default=default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
383 wlanconfig.ip = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0]
385 wlanconfig.netmask = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0])
386 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
390 wlanconfig.usegateway = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
392 wlanconfig.gateway = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0])
394 self["ipaddress"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "ip"))))
395 self["netmask"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "netmask"))))
396 self["gateway"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "gateway"))))
398 if self.encryption_key is not None:
402 wlanconfig.encrypt = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
404 if self.key_mgmt=="NONE":
406 elif self.key_mgmt == "WPA-PSK":
407 if self.proto == "WPA":
409 elif self.proto == "RSN":
411 elif self.proto in ( "WPA RSN", "WPA WPA2"):
412 default_tmp = "wpa/wpa2"
418 wlanconfig.method = ConfigSelection(default = default_tmp, choices = [
419 ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
421 if self.key_type == 0:
424 default_tmp = "ascii"
425 wlanconfig.keytype = ConfigSelection(default = default_tmp, choices = [
426 ("ascii", _("ASCII")), ("hex", _("HEX"))])
427 default_tmp = self.encryption_key or "XXXXXXXX"
428 wlanconfig.key = ConfigPassword(default = default_tmp, visible_width = 50, fixed_size = False)
431 def readWpaSupplicantConf(self):
433 if fileExists("/etc/wpa_supplicant.conf"):
434 wpafd = open("/etc/wpa_supplicant.conf","r")
436 data = wpafd.readline()
438 # print "####readWpaSupplicantConf, data : ",data
441 data = wpafd.readline()
443 if data.startswith('ssid=') and len(data) > 6:
444 self.ssid = data[6:-2]
445 elif data.startswith('ap_scan=') :
446 self.ap_scan = data[8:]
447 # print "####readWpaSupplicantConf, ap_scan : ",self.ap_scan
448 elif data.startswith('scan_ssid=') and len(data) > 10:
449 self.scan_ssid = data[10:-1]
450 elif data.startswith('key_mgmt=') and len(data) > 9:
451 self.key_mgmt = data[9:-1]
452 elif data.startswith('proto=') and len(data) > 6:
453 self.proto = data[6:-1]
454 elif data.startswith('wep_key0="') and len(data) > 11:
455 self.key_type = 1 # ascii
456 self.encryption_key = data[10:-2]
457 elif data.startswith('wep_key0=') and len(data) > 9:
458 self.key_type = 0 # hex
459 self.encryption_key = data[9:-1]
460 elif data.startswith('psk="') and len(data) > 6:
461 self.key_type = 1 # ascii
462 self.encryption_key = data[5:-2]
463 elif data.startswith('#psk="') and len(data) > 6:
464 self.key_type = 0 # hex
465 self.encryption_key = data[6:-2]
466 elif not self.encryption_key and data.startswith('psk=') and len(data) > 4:
467 self.key_type = 0 # hex
468 self.encryption_key = data[4:-1]
469 data = wpafd.readline()
470 # print self.ssid,self.scan_ssid,self.key_mgmt,self.proto,self.key_type,self.encryption_key
477 print 'failed loading wpasupplicant.conf'
479 def createConfig(self):
481 self.usedeviceEntry = getConfigListEntry(_("Use Device"), wlanconfig.usedevice)
482 self.usedhcpEntry = getConfigListEntry(_("Use DHCP"), wlanconfig.usedhcp)
483 self.essidEntry = getConfigListEntry(_("ESSID"), wlanconfig.essid)
484 self.hiddenessidEntry = getConfigListEntry(_("Input Hidden ESSID"), wlanconfig.hiddenessid)
485 self.encryptEntry = getConfigListEntry(_("Encrypt"), wlanconfig.encrypt)
486 self.methodEntry = getConfigListEntry(_("Method"), wlanconfig.method)
487 self.keytypeEntry = getConfigListEntry(_("Key Type"), wlanconfig.keytype)
488 self.keyEntry = getConfigListEntry(_("KEY"), wlanconfig.key)
490 self.ipEntry = getConfigListEntry(_("IP"), wlanconfig.ip)
491 self.netmaskEntry = getConfigListEntry(_("NetMask"), wlanconfig.netmask)
493 self.usegatewayEntry = getConfigListEntry(_("Use Gateway"), wlanconfig.usegateway)
494 self.gatewayEntry = getConfigListEntry(_("Gateway"), wlanconfig.gateway)
496 self.configList.append( self.usedeviceEntry )
497 if wlanconfig.usedevice.value is "on":
498 self.configList.append( self.usedhcpEntry )
499 if wlanconfig.usedhcp.value is "off":
500 self.configList.append(self.ipEntry)
501 self.configList.append(self.netmaskEntry)
502 self.configList.append(self.usegatewayEntry)
503 if wlanconfig.usegateway.value is "on":
504 self.configList.append(self.gatewayEntry)
505 self.configList.append( self.essidEntry )
506 if wlanconfig.essid.value == 'Input hidden ESSID':
507 self.configList.append( self.hiddenessidEntry )
508 self.configList.append( self.encryptEntry )
509 if wlanconfig.encrypt.value is "on" :
510 self.configList.append( self.methodEntry )
511 if wlanconfig.method.value =="wep":
512 self.configList.append( self.keytypeEntry )
513 self.configList.append( self.keyEntry )
515 self["config"].list = self.configList
516 self["config"].l.setList(self.configList)
517 if not self.showTextIcon in self["config"].onSelectionChanged:
518 self["config"].onSelectionChanged.append(self.showTextIcon)
520 def showTextIcon(self):
521 if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
522 self["VKeyIcon"].show()
524 self["VKeyIcon"].hide()
527 if self.essidSelected is None:
529 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
530 self.scanAplistTimer.start(100,True)
532 self.apList = [self.essidSelected]
533 wlanconfig.essid = ConfigSelection(choices = self.apList)
534 if self.ssid is not None:
535 wlanconfig.hiddenessid = ConfigText(default = self.ssid, visible_width = 50, fixed_size = False)
537 wlanconfig.hiddenessid = ConfigText(default = "<Input ESSID>", visible_width = 50, fixed_size = False)
540 def scanApList(self):
541 if self.oldInterfaceState is not True:
542 os_system("ifconfig "+self.iface+" up")
543 iNetwork.setAdapterAttribute(self.iface, "up", True)
545 wirelessObj = Wireless(self.iface)
547 Iwscanresult = wirelessObj.scan()
549 print "%s Interface doesn't support scanning.."%self.iface
550 # self.session.open(MessageBox, "%s Interface doesn't support scanning.."%self.iface, MessageBox.TYPE_ERROR,10)
551 self.configurationmsg.close(True)
552 if Iwscanresult is None:
553 self.emptyListMsgTimer.start(100,True)
555 for ap in Iwscanresult:
556 if ap.essid not in self.apList and len(ap.essid) > 0:
557 self.apList.append(ap.essid)
558 self.apList.append('Input hidden ESSID')
559 if selectap is not None and selectap in self.apList:
560 wlanconfig.essid = ConfigSelection(default=selectap,choices = self.apList)
561 elif self.scan_ssid is not None and self.scan_ssid.strip() == '1':
562 wlanconfig.essid = ConfigSelection(default='Input hidden ESSID',choices = self.apList)
563 elif self.ssid is not None and self.ssid in self.apList:
564 wlanconfig.essid = ConfigSelection(default=self.ssid, choices = self.apList)
567 wlanconfig.essid = ConfigSelection(defalut = self.apList[0], choices = self.apList)
569 wlanconfig.essid = ConfigSelection(choices = self.apList)
570 if self.ssid is not None:
571 wlanconfig.hiddenessid = ConfigText(default = self.ssid, visible_width = 50, fixed_size = False)
573 wlanconfig.hiddenessid = ConfigText(default = "<Input ESSID>", visible_width = 50, fixed_size = False)
576 def emptyListMsg(self):
577 self.session.open(MessageBox, _("No AP detected."), type = MessageBox.TYPE_INFO, timeout = 10)
580 ConfigListScreen.keyLeft(self)
584 ConfigListScreen.keyRight(self)
588 if self["config"].getCurrent() == self.usedeviceEntry or self["config"].getCurrent() == self.encryptEntry \
589 or self["config"].getCurrent() == self.usedhcpEntry or self["config"].getCurrent() == self.usegatewayEntry \
590 or self["config"].getCurrent() == self.essidEntry or self["config"].getCurrent() == self.methodEntry:
593 def saveWlanConfig(self):
595 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
596 self["config"].getCurrent()[1].onDeselect(self.session)
597 if self["config"].isChanged():
598 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Are you sure you want to restart your network interfaces?\n") ) )
600 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Network configuration is not changed....\n\nAre you sure you want to restart your network interfaces?\n") ) )
604 def checkNetworkConfig(self, ret = False):
606 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
607 self["config"].getCurrent()[1].onSelect(self.session)
609 if wlanconfig.essid.value == 'Input hidden ESSID':
610 if len(wlanconfig.hiddenessid.value) == 0:
611 self.session.open(MessageBox, ("PLEASE INPUT HIDDEN ESSID"), type = MessageBox.TYPE_ERROR, timeout = 10)
613 if len(wlanconfig.key.value) == 0:
614 self.session.open(MessageBox, ("PLEASE INPUT NETWORK KEY"), type = MessageBox.TYPE_ERROR, timeout = 10)
616 self.checkNetworkShares()
618 def checkNetworkShares(self):
620 self.Console = Console()
621 cmd = "cat /proc/mounts"
622 self.Console.ePopen(cmd, self.checkSharesFinished, self.confirmAnotherIfaces)
624 def checkSharesFinished(self, result, retval, extra_args):
625 callback = extra_args
626 # print "checkMountsFinished : result : \n",result
627 networks = ['nfs','smbfs','ncp','coda']
628 for line in result.splitlines():
629 split = line.strip().split(' ',3)
630 if split[2] in networks:
631 self.session.open(MessageBox, ("NOT deconfiguring network interfaces :\n network shares still mounted\n"), type = MessageBox.TYPE_ERROR, timeout = 10)
633 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
634 self["config"].getCurrent()[1].onSelect(self.session)
638 def confirmAnotherIfaces(self, ret = False):
642 num_configured_if = len(iNetwork.getConfiguredAdapters())
643 if num_configured_if >= 1:
644 if num_configured_if == 1 and self.iface in iNetwork.getConfiguredAdapters():
645 self.getWpaPhrase(False)
647 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)
649 self.getWpaPhrase(False)
651 def getWpaPhrase(self,ret):
653 configuredInterfaces = iNetwork.getConfiguredAdapters()
654 for interface in configuredInterfaces:
655 if interface == self.iface:
657 iNetwork.setAdapterAttribute(interface, "up", False)
658 iNetwork.deactivateInterface(interface)
659 if wlanconfig.method.value =="wep":
660 self.writeWpasupplicantConf("wep") # passphrasekey is not None
662 if wlanconfig.essid.value == 'Input hidden ESSID':
663 cmd = "wpa_passphrase '%s' %s" % (wlanconfig.hiddenessid.value,wlanconfig.key.value)
665 cmd = "wpa_passphrase '%s' %s" % (wlanconfig.essid.value,wlanconfig.key.value)
667 self.wpaphraseconsole = Console()
668 self.wpaphraseconsole.ePopen(cmd, self.parseWpaPhrase, self.writeWpasupplicantConf)
670 def parseWpaPhrase(self, result, retval, extra_args):
671 (writewlanconfig) = extra_args
672 if self.wpaphraseconsole is not None:
674 self.wpaphraseconsole.killAll()
675 self.wpaphraseconsole = None
676 # print "parseWpaPhrase result : "
679 for line in result.splitlines():
680 if line.find('ssid') == -1 and line.find('#psk=') != -1:
682 elif line.find('psk=') != -1:
685 writewlanconfig(psk,plainpwd)
687 writewlanconfig(None)
689 writewlanconfig(None)
691 def writeWpasupplicantConf(self, passphrasekey=None,plainpwd=None):
693 wpafd = open("/etc/wpa_supplicant.conf","w")
695 contents = "#WPA Supplicant Configuration by STB\n"
696 contents += "ctrl_interface=/var/run/wpa_supplicant\n"
697 contents += "eapol_version=1\n"
698 contents += "fast_reauth=1\n"
699 contents += "ap_scan=1\n"
700 contents += "network={\n"
701 if wlanconfig.essid.value == 'Input hidden ESSID':
702 contents += "\tssid=\""+wlanconfig.hiddenessid.value+"\"\n"
703 contents += "\tscan_ssid=1\n"
705 contents += "\tssid=\""+wlanconfig.essid.value+"\"\n"
706 contents += "\tscan_ssid=0\n"
707 if wlanconfig.encrypt.value == "on":
708 if wlanconfig.method.value =="wep":
709 contents += "\tkey_mgmt=NONE\n"
710 contents += "\twep_key0="
711 if wlanconfig.keytype.value == "ascii":
712 contents += "\""+wlanconfig.key.value+"\"\n"
714 contents += wlanconfig.key.value+"\n"
716 # print "plainpwd : ",plainpwd
717 # print "passphrasekey : ",passphrasekey
718 if wlanconfig.method.value == "wpa":
719 contents += "\tkey_mgmt=WPA-PSK\n"
720 contents += "\tproto=WPA\n"
721 contents += "\tpairwise=CCMP TKIP\n"
722 contents += "\tgroup=CCMP TKIP\n"
723 elif wlanconfig.method.value == "wpa2":
724 contents += "\tkey_mgmt=WPA-PSK\n"
725 contents += "\tproto=RSN\n"
726 contents += "\tpairwise=CCMP TKIP\n"
727 contents += "\tgroup=CCMP TKIP\n"
729 contents += "\tkey_mgmt=WPA-PSK\n"
730 contents += "\tproto=WPA RSN\n"
731 contents += "\tpairwise=CCMP TKIP\n"
732 contents += "\tgroup=CCMP TKIP\n"
733 contents += plainpwd+"\n"
734 contents += passphrasekey+"\n"
736 contents += "\tkey_mgmt=NONE\n"
738 print "content = \n"+contents
739 wpafd.write(contents)
741 self.writeNetConfig(0)
743 self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
744 self.writeNetConfig(-1)
746 self.writeNetConfig(-2)
748 def writeNetConfig(self,ret = -1):
750 self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
753 self.session.open(MessageBox, _("Can NOT generate passphrase"), type = MessageBox.TYPE_ERROR, timeout = 10)
756 if wlanconfig.usedevice.value=="on":
757 iNetwork.setAdapterAttribute(self.iface, "up", True)
758 if wlanconfig.usedhcp.value =="on":
759 iNetwork.setAdapterAttribute(self.iface, "dhcp", True)
761 iNetwork.setAdapterAttribute(self.iface, "dhcp", False)
762 iNetwork.setAdapterAttribute(self.iface, "ip", wlanconfig.ip.value)
763 iNetwork.setAdapterAttribute(self.iface, "netmask", wlanconfig.netmask.value)
764 if wlanconfig.usegateway.value == "on":
765 iNetwork.setAdapterAttribute(self.iface, "gateway", wlanconfig.gateway.value)
767 iNetwork.setAdapterAttribute(self.iface, "up", False)
768 iNetwork.deactivateInterface(self.iface)
769 contents = "\tpre-up wpa_supplicant -i"+self.iface+" -c/etc/wpa_supplicant.conf -B -D"+iNetwork.detectWlanModule(self.iface)+"\n"
770 contents += "\tpost-down wpa_cli terminate\n\n"
771 iNetwork.setAdapterAttribute(self.iface, "configStrings", contents)
772 iNetwork.writeNetworkConfig()
773 iNetwork.restartNetwork(self.updateCurrentInterfaces)
774 self.configurationmsg = None
775 self.configurationmsg = self.session.openWithCallback(self.configFinished, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
778 def updateCurrentInterfaces(self,ret):
780 iNetwork.getInterfaces(self.configurationMsgClose)
782 def configurationMsgClose(self,ret):
783 if ret is True and self.configurationmsg is not None:
784 self.configurationmsg.close(True)
786 def configFinished(self,data):
789 self.session.openWithCallback(self.configFinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
790 selectap = wlanconfig.essid.value
792 def configFinishedCB(self,data):
797 def formatip(self, iplist):
800 # print "iplist : ",iplist
803 result = str(iplist[0])+"."+str(iplist[1])+"."+str(iplist[2])+"."+str(iplist[3])
806 # print "result : ",result
811 def keyCancelConfirm(self, result):
814 if self.oldInterfaceState is False:
815 iNetwork.setAdapterAttribute(self.iface, "up", False)
816 iNetwork.deactivateInterface(self.iface,self.keyCancelCB)
820 def keyCancel(self,yesno = True):
821 if self["config"].isChanged():
822 self.session.openWithCallback(self.keyCancelConfirm, MessageBox, _("Really close without saving settings?"))
824 self.keyCancelConfirm(True)
826 def keyCancelCB(self,data):
832 iNetwork.stopRestartConsole()
833 iNetwork.stopGetInterfacesConsole()
834 iNetwork.stopDeactivateInterfaceConsole()
835 self.stopwlanscanapConsole()
836 self.stopCheckNetworkSharesConsole()
837 self.stopWpaPhraseConsole()
839 def stopwlanscanapConsole(self):
840 if self.wlanscanap is not None:
841 if len(self.wlanscanap.appContainers):
842 for name in self.wlanscanap.appContainers.keys():
843 self.wlanscanap.kill(name)
845 def stopCheckNetworkSharesConsole(self):
846 if self.Console is not None:
847 if len(self.Console.appContainers):
848 for name in self.Console.appContainers.keys():
849 self.Console.kill(name)
851 def stopWpaPhraseConsole(self):
852 if self.wpaphraseconsole is not None:
853 if len(self.wpaphraseconsole.appContainers):
854 for name in self.wpaphraseconsole.appContainers.keys():
855 self.wpaphraseconsole.kill(name)
857 class WlanScanAp(Screen,HelpableScreen):
859 <screen position="center,center" size="510,400" title="Wireless Network AP Scan..." >
860 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
861 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
863 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
864 <ePixmap pixmap="skin_default/buttons/green.png" position="185,360" size="140,40" alphatest="on" />
865 <ePixmap pixmap="skin_default/buttons/blue.png" position="360,360" size="140,40" alphatest="on" />
867 <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" />
868 <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" />
869 <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" />
871 <widget name="menulist" position="20,20" size="230,260" backgroundColor="#371e1c1a" transparent="1" zPosition="10" scrollbarMode="showOnDemand" />
873 <widget source="Address" render="Label" position="265,70" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
874 <widget source="ESSID" render="Label" position="265,100" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
875 <widget source="Protocol" render="Label" position="265,130" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
876 <widget source="Frequency" render="Label" position="265,160" zPosition="1" size="240,40" font="Regular;18" halign="center" valign="center" />
877 <widget source="Encryption key" render="Label" position="265,200" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
878 <widget source="BitRate" render="Label" position="265,220" zPosition="1" size="240,60" font="Regular;18" halign="center" valign="center" />
881 def __init__(self, session, iface):
882 Screen.__init__(self,session)
883 HelpableScreen.__init__(self)
884 self.session = session
886 self.wlanscanap = None
890 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
892 "up": (self.up, _("move up to previous entry")),
893 "down": (self.down, _("move down to next entry")),
894 "left": (self.left, _("move up to first entry")),
895 "right": (self.right, _("move down to last entry")),
898 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
900 "cancel": (self.close, _("exit")),
901 "ok": (self.ok, "select AP"),
904 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
906 "red": (self.close, _("exit")),
907 "green": (self.ok, "select AP"),
908 "yellow": (self.restartScanAP, "restart scan AP"),
909 "blue": (self.startWlanConfig, "Edit Wireless settings"),
912 self["menulist"] = MenuList(self.setApList)
913 self["key_red"] = StaticText(_("Close"))
914 self["key_green"] = StaticText(_("Select"))
915 self["key_blue"] = StaticText(_("EditSetting"))
916 self["Address"] = StaticText(_("Scanning AP List.."))
917 self["ESSID"] = StaticText(_("Wait a moment"))
918 self["Protocol"] = StaticText(" ")
919 self["Frequency"] = StaticText(" ")
920 self["Encryption key"] = StaticText(" ")
921 self["BitRate"] = StaticText(" ")
922 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
923 self.getAplistTimer = eTimer()
924 self.getAplistTimer.callback.append(self.getApList)
925 self.scanAplistTimer = eTimer()
926 self.scanAplistTimer.callback.append(self.scanApList)
927 self.emptyListMsgTimer = eTimer()
928 self.emptyListMsgTimer.callback.append(self.emptyListMsg)
930 self.onClose.append(self.__onClose)
931 self.getAplistTimer.start(100,True)
934 self["menulist"].pageUp()
938 self["menulist"].pageDown()
942 self["menulist"].up()
946 self["menulist"].down()
951 selectAp=self["menulist"].getCurrent()[0]
955 def startWlanConfig(self):
956 selectAp=self["menulist"].getCurrent()[0]
962 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
963 self.scanAplistTimer.start(100,True)
965 def scanApList(self):
966 if self.oldInterfaceState is not True:
967 os_system("ifconfig "+self.iface+" up")
968 iNetwork.setAdapterAttribute(self.iface, "up", True)
970 wirelessObj = Wireless(self.iface)
972 Iwscanresult = wirelessObj.scan()
974 print "%s Interface doesn't support scanning.."%self.iface
975 # self.session.open(MessageBox, "%s Interface doesn't support scanning.."%self.iface, MessageBox.TYPE_ERROR,10)
976 self.configurationmsg.close(True)
977 if Iwscanresult is not None:
978 (num_channels, frequencies) = wirelessObj.getChannelInfo()
980 for ap in Iwscanresult:
981 self.apList[index] = {}
982 self.apList[index]["Address"] = ap.bssid
983 if len(ap.essid) == 0:
984 self.apList[index]["ESSID"] = "<hidden ESSID>"
986 self.apList[index]["ESSID"] = ap.essid
987 self.setApList.append( (self.apList[index]["ESSID"], index) )
988 self.apList[index]["Protocol"] = ap.protocol
989 self.apList[index]["Frequency"] = wirelessObj._formatFrequency(ap.frequency.getFrequency())
991 self.apList[index]["Channel"] = frequencies.index(self.apList[index]["Frequency"] + 1)
993 self.apList[index]["Channel"] = "Unknown"
995 self.apList[index]["Quality"] = "%s/%s" % \
996 ( ap.quality.quality, wirelessObj.getQualityMax().quality )
997 self.apList[index]["Signal Level"] = "%s/%s" % \
998 ( ap.quality.getSignallevel(), "100" )
999 self.apList[index]["Noise Level"] = "%s/%s" % \
1000 ( ap.quality.getNoiselevel(), "100" )
1002 # get encryption key on/off
1003 key_status = "Unknown"
1004 if (ap.encode.flags & pythonwifi.flags.IW_ENCODE_DISABLED):
1006 elif (ap.encode.flags & pythonwifi.flags.IW_ENCODE_NOKEY):
1007 if (ap.encode.length <= 0):
1009 self.apList[index]["Encryption key"] = key_status
1010 self.apList[index]["BitRate"] = wirelessObj._formatBitrate(ap.rate[-1][-1])
1013 # print self.setApList
1014 self.displayApInfo()
1015 if len(self.apList) == 0:
1016 self.emptyListMsgTimer.start(100,True)
1018 def displayApInfo(self):
1019 if len(self.apList) >0:
1020 self["menulist"].setList(self.setApList)
1021 index = self["menulist"].getCurrent()[1]
1022 for key in ["Address", "ESSID", "Protocol", "Frequency", "Encryption key", "BitRate"]:
1023 if self.apList[index].has_key(key):
1024 self[key].setText((key+": "+self.apList[index][key]))
1026 self[key].setText((key+": None"))
1028 def emptyListMsg(self):
1029 self.session.open(MessageBox, _("No AP detected."), type = MessageBox.TYPE_INFO, timeout = 10)
1030 self["Address"].setText(_("No AP detected."))
1031 self["ESSID"].setText(_(""))
1033 def restartScanAP(self):
1034 self.getAplistTimer.start(100,True)
1036 def __onClose(self):
1037 if self.oldInterfaceState is False:
1038 iNetwork.setAdapterAttribute(self.iface, "up", False)
1039 iNetwork.deactivateInterface(self.iface)
1041 class NetworkAdapterTest(Screen):
1042 def __init__(self, session,iface):
1043 Screen.__init__(self, session)
1045 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
1047 self.onClose.append(self.cleanup)
1048 self.onHide.append(self.cleanup)
1050 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
1054 "up": lambda: self.updownhandler('up'),
1055 "down": lambda: self.updownhandler('down'),
1059 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1062 "back": self.cancel,
1064 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1066 "red": self.closeInfo,
1067 "back": self.closeInfo,
1069 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
1071 "green": self.KeyGreen,
1073 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
1075 "green": self.KeyGreenRestart,
1077 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
1079 "yellow": self.KeyYellow,
1082 self["shortcutsgreen_restart"].setEnabled(False)
1083 self["updown_actions"].setEnabled(False)
1084 self["infoshortcuts"].setEnabled(False)
1085 self.onClose.append(self.delTimer)
1086 self.onLayoutFinish.append(self.layoutFinished)
1087 self.steptimer = False
1089 self.activebutton = 0
1090 self.nextStepTimer = eTimer()
1091 self.nextStepTimer.callback.append(self.nextStepTimerFire)
1094 if self.oldInterfaceState is False:
1095 iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
1096 iNetwork.deactivateInterface(self.iface)
1099 def closeInfo(self):
1100 self["shortcuts"].setEnabled(True)
1101 self["infoshortcuts"].setEnabled(False)
1102 self["InfoText"].hide()
1103 self["InfoTextBorder"].hide()
1104 self["key_red"].setText(_("Close"))
1108 del self.nextStepTimer
1110 def nextStepTimerFire(self):
1111 self.nextStepTimer.stop()
1112 self.steptimer = False
1115 def updownhandler(self,direction):
1116 if direction == 'up':
1117 if self.activebutton >=2:
1118 self.activebutton -= 1
1120 self.activebutton = 6
1121 self.setActiveButton(self.activebutton)
1122 if direction == 'down':
1123 if self.activebutton <=5:
1124 self.activebutton += 1
1126 self.activebutton = 1
1127 self.setActiveButton(self.activebutton)
1129 def setActiveButton(self,button):
1131 self["EditSettingsButton"].setPixmapNum(0)
1132 self["EditSettings_Text"].setForegroundColorNum(0)
1133 self["NetworkInfo"].setPixmapNum(0)
1134 self["NetworkInfo_Text"].setForegroundColorNum(1)
1135 self["AdapterInfo"].setPixmapNum(1) # active
1136 self["AdapterInfo_Text"].setForegroundColorNum(2) # active
1138 self["AdapterInfo_Text"].setForegroundColorNum(1)
1139 self["AdapterInfo"].setPixmapNum(0)
1140 self["DhcpInfo"].setPixmapNum(0)
1141 self["DhcpInfo_Text"].setForegroundColorNum(1)
1142 self["NetworkInfo"].setPixmapNum(1) # active
1143 self["NetworkInfo_Text"].setForegroundColorNum(2) # active
1145 self["NetworkInfo"].setPixmapNum(0)
1146 self["NetworkInfo_Text"].setForegroundColorNum(1)
1147 self["IPInfo"].setPixmapNum(0)
1148 self["IPInfo_Text"].setForegroundColorNum(1)
1149 self["DhcpInfo"].setPixmapNum(1) # active
1150 self["DhcpInfo_Text"].setForegroundColorNum(2) # active
1152 self["DhcpInfo"].setPixmapNum(0)
1153 self["DhcpInfo_Text"].setForegroundColorNum(1)
1154 self["DNSInfo"].setPixmapNum(0)
1155 self["DNSInfo_Text"].setForegroundColorNum(1)
1156 self["IPInfo"].setPixmapNum(1) # active
1157 self["IPInfo_Text"].setForegroundColorNum(2) # active
1159 self["IPInfo"].setPixmapNum(0)
1160 self["IPInfo_Text"].setForegroundColorNum(1)
1161 self["EditSettingsButton"].setPixmapNum(0)
1162 self["EditSettings_Text"].setForegroundColorNum(0)
1163 self["DNSInfo"].setPixmapNum(1) # active
1164 self["DNSInfo_Text"].setForegroundColorNum(2) # active
1166 self["DNSInfo"].setPixmapNum(0)
1167 self["DNSInfo_Text"].setForegroundColorNum(1)
1168 self["EditSettingsButton"].setPixmapNum(1) # active
1169 self["EditSettings_Text"].setForegroundColorNum(2) # active
1170 self["AdapterInfo"].setPixmapNum(0)
1171 self["AdapterInfo_Text"].setForegroundColorNum(1)
1174 next = self.nextstep
1190 self.steptimer = True
1191 self.nextStepTimer.start(3000)
1192 self["key_yellow"].setText(_("Stop test"))
1195 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
1196 self["Adapter"].setForegroundColorNum(2)
1197 self["Adaptertext"].setForegroundColorNum(1)
1198 self["AdapterInfo_Text"].setForegroundColorNum(1)
1199 self["AdapterInfo_OK"].show()
1200 self.steptimer = True
1201 self.nextStepTimer.start(3000)
1204 self["Networktext"].setForegroundColorNum(1)
1205 self["Network"].setText(_("Please wait..."))
1206 self.AccessPointInfo(self.iface)
1207 self["NetworkInfo_Text"].setForegroundColorNum(1)
1208 self.steptimer = True
1209 self.nextStepTimer.start(3000)
1212 self["Dhcptext"].setForegroundColorNum(1)
1213 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
1214 self["Dhcp"].setForegroundColorNum(2)
1215 self["Dhcp"].setText(_("enabled"))
1216 self["DhcpInfo_Check"].setPixmapNum(0)
1218 self["Dhcp"].setForegroundColorNum(1)
1219 self["Dhcp"].setText(_("disabled"))
1220 self["DhcpInfo_Check"].setPixmapNum(1)
1221 self["DhcpInfo_Check"].show()
1222 self["DhcpInfo_Text"].setForegroundColorNum(1)
1223 self.steptimer = True
1224 self.nextStepTimer.start(3000)
1227 self["IPtext"].setForegroundColorNum(1)
1228 self["IP"].setText(_("Please wait..."))
1229 iNetwork.checkNetworkState(self.NetworkStatedataAvail)
1232 self.steptimer = False
1233 self.nextStepTimer.stop()
1234 self["DNStext"].setForegroundColorNum(1)
1235 self["DNS"].setText(_("Please wait..."))
1236 iNetwork.checkDNSLookup(self.DNSLookupdataAvail)
1239 self["shortcutsgreen"].setEnabled(False)
1240 self["shortcutsyellow"].setEnabled(True)
1241 self["updown_actions"].setEnabled(False)
1242 self["key_yellow"].setText("")
1243 self["key_green"].setText("")
1244 self.steptimer = True
1245 self.nextStepTimer.start(1000)
1247 def KeyGreenRestart(self):
1249 self.layoutFinished()
1250 self["Adapter"].setText((""))
1251 self["Network"].setText((""))
1252 self["Dhcp"].setText((""))
1253 self["IP"].setText((""))
1254 self["DNS"].setText((""))
1255 self["AdapterInfo_Text"].setForegroundColorNum(0)
1256 self["NetworkInfo_Text"].setForegroundColorNum(0)
1257 self["DhcpInfo_Text"].setForegroundColorNum(0)
1258 self["IPInfo_Text"].setForegroundColorNum(0)
1259 self["DNSInfo_Text"].setForegroundColorNum(0)
1260 self["shortcutsgreen_restart"].setEnabled(False)
1261 self["shortcutsgreen"].setEnabled(False)
1262 self["shortcutsyellow"].setEnabled(True)
1263 self["updown_actions"].setEnabled(False)
1264 self["key_yellow"].setText("")
1265 self["key_green"].setText("")
1266 self.steptimer = True
1267 self.nextStepTimer.start(1000)
1270 self["infoshortcuts"].setEnabled(True)
1271 self["shortcuts"].setEnabled(False)
1272 if self.activebutton == 1: # Adapter Check
1273 self["InfoText"].setText(_("This test detects your configured Wireless LAN-Adapter."))
1274 self["InfoTextBorder"].show()
1275 self["InfoText"].show()
1276 self["key_red"].setText(_("Back"))
1277 if self.activebutton == 2: #LAN Check
1278 self["InfoText"].setText(_("This test checks whether a network cable is connected to your Wireless LAN-Adapter."))
1279 self["InfoTextBorder"].show()
1280 self["InfoText"].show()
1281 self["key_red"].setText(_("Back"))
1282 if self.activebutton == 3: #DHCP Check
1283 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."))
1284 self["InfoTextBorder"].show()
1285 self["InfoText"].show()
1286 self["key_red"].setText(_("Back"))
1287 if self.activebutton == 4: # IP Check
1288 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"))
1289 self["InfoTextBorder"].show()
1290 self["InfoText"].show()
1291 self["key_red"].setText(_("Back"))
1292 if self.activebutton == 5: # DNS Check
1293 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"))
1294 self["InfoTextBorder"].show()
1295 self["InfoText"].show()
1296 self["key_red"].setText(_("Back"))
1297 if self.activebutton == 6: # Edit Settings
1299 self.session.open(WlanConfig,self.iface)
1300 self["shortcuts"].setEnabled(True)
1301 self["infoshortcuts"].setEnabled(False)
1303 def KeyYellow(self):
1305 self["shortcutsgreen_restart"].setEnabled(True)
1306 self["shortcutsgreen"].setEnabled(False)
1307 self["shortcutsyellow"].setEnabled(False)
1308 self["key_green"].setText(_("Restart test"))
1309 self["key_yellow"].setText("")
1310 self.steptimer = False
1311 self.nextStepTimer.stop()
1313 def layoutFinished(self):
1314 self.setTitle(_("Network test: ") + iNetwork.getFriendlyAdapterName(self.iface) )
1315 self["shortcutsyellow"].setEnabled(False)
1316 self["AdapterInfo_OK"].hide()
1317 self["NetworkInfo_Check"].hide()
1318 self["DhcpInfo_Check"].hide()
1319 self["IPInfo_Check"].hide()
1320 self["DNSInfo_Check"].hide()
1321 self["EditSettings_Text"].hide()
1322 self["EditSettingsButton"].hide()
1323 self["InfoText"].hide()
1324 self["InfoTextBorder"].hide()
1325 self["key_yellow"].setText("")
1327 def setLabels(self):
1328 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1329 self["Adapter"] = MultiColorLabel()
1330 self["AdapterInfo"] = MultiPixmap()
1331 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1332 self["AdapterInfo_OK"] = Pixmap()
1334 if self.iface in iNetwork.wlan_interfaces:
1335 self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1337 self["Networktext"] = MultiColorLabel(_("Local Network"))
1339 self["Network"] = MultiColorLabel()
1340 self["NetworkInfo"] = MultiPixmap()
1341 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1342 self["NetworkInfo_Check"] = MultiPixmap()
1344 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1345 self["Dhcp"] = MultiColorLabel()
1346 self["DhcpInfo"] = MultiPixmap()
1347 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1348 self["DhcpInfo_Check"] = MultiPixmap()
1350 self["IPtext"] = MultiColorLabel(_("IP Address"))
1351 self["IP"] = MultiColorLabel()
1352 self["IPInfo"] = MultiPixmap()
1353 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1354 self["IPInfo_Check"] = MultiPixmap()
1356 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1357 self["DNS"] = MultiColorLabel()
1358 self["DNSInfo"] = MultiPixmap()
1359 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1360 self["DNSInfo_Check"] = MultiPixmap()
1362 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1363 self["EditSettingsButton"] = MultiPixmap()
1365 self["key_red"] = StaticText(_("Close"))
1366 self["key_green"] = StaticText(_("Start test"))
1367 self["key_yellow"] = StaticText(_("Stop test"))
1369 self["InfoTextBorder"] = Pixmap()
1370 self["InfoText"] = Label()
1372 def NetworkStatedataAvail(self,data):
1374 self["IP"].setForegroundColorNum(2)
1375 self["IP"].setText(_("confirmed"))
1376 self["IPInfo_Check"].setPixmapNum(0)
1378 self["IP"].setForegroundColorNum(1)
1379 self["IP"].setText(_("unconfirmed"))
1380 self["IPInfo_Check"].setPixmapNum(1)
1381 self["IPInfo_Check"].show()
1382 self["IPInfo_Text"].setForegroundColorNum(1)
1383 self.steptimer = True
1384 self.nextStepTimer.start(3000)
1386 def DNSLookupdataAvail(self,data):
1388 self["DNS"].setForegroundColorNum(2)
1389 self["DNS"].setText(_("confirmed"))
1390 self["DNSInfo_Check"].setPixmapNum(0)
1392 self["DNS"].setForegroundColorNum(1)
1393 self["DNS"].setText(_("unconfirmed"))
1394 self["DNSInfo_Check"].setPixmapNum(1)
1395 self["DNSInfo_Check"].show()
1396 self["DNSInfo_Text"].setForegroundColorNum(1)
1397 self["EditSettings_Text"].show()
1398 self["EditSettingsButton"].setPixmapNum(1)
1399 self["EditSettings_Text"].setForegroundColorNum(2) # active
1400 self["EditSettingsButton"].show()
1401 self["key_yellow"].setText("")
1402 self["key_green"].setText(_("Restart test"))
1403 self["shortcutsgreen"].setEnabled(False)
1404 self["shortcutsgreen_restart"].setEnabled(True)
1405 self["shortcutsyellow"].setEnabled(False)
1406 self["updown_actions"].setEnabled(True)
1407 self.activebutton = 6
1409 def getInfoCB(self,status):
1410 if status is not None:
1411 if status.startswith("No Connection") or status.startswith("Not-Associated") or status == False:
1412 self["Network"].setForegroundColorNum(1)
1413 self["Network"].setText(_("disconnected"))
1414 self["NetworkInfo_Check"].setPixmapNum(1)
1415 self["NetworkInfo_Check"].show()
1417 self["Network"].setForegroundColorNum(2)
1418 self["Network"].setText(_("connected"))
1419 self["NetworkInfo_Check"].setPixmapNum(0)
1420 self["NetworkInfo_Check"].show()
1423 iNetwork.stopLinkStateConsole()
1424 iNetwork.stopPingConsole()
1425 iNetwork.stopDNSConsole()
1427 def AccessPointInfo(self,iface):
1428 cmd = "iwconfig %s"%iface
1429 self.iwconfigConsole = Console()
1430 self.iwconfigConsole.ePopen(cmd,self.readAP,self.getInfoCB)
1432 def readAP(self,result,retval,extra_args):
1433 (callback) = extra_args
1435 if self.iwconfigConsole is not None:
1437 self.iwconfigConsole = None
1438 for content in result.splitlines():
1439 if 'Access Point' in content:
1440 self.apState = content.strip().split('Access Point: ')[1]
1441 callback(self.apState)
1443 callback(self.apState)
1445 class Wlanstatus(Screen):
1447 <screen position="center,center" size="510,400" title="Wireless Network Status..." >
1448 <widget source="status" render="Label" position="5,15" size="500,350" font="Regular;18" zPosition="1" />
1450 <ePixmap pixmap="skin_default/buttons/red.png" position="185,360" size="140,40" alphatest="on" />
1451 <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" />
1454 def __init__(self, session,iface):
1455 Screen.__init__(self,session)
1456 self.session = session
1458 self["status"] = StaticText(_("Wait a moment..."))
1459 self["key_red"] = StaticText(_("Close"))
1460 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
1463 "cancel": self.close,
1467 self.onClose.append(self.cleanup)
1469 def readstatus(self):
1470 self.wlanstatus = Console()
1471 cmd1 = "iwconfig "+self.iface
1472 self.wlanstatus.ePopen(cmd1, self.iwconfigfinnished,self.statusdisplay)
1474 def iwconfigfinnished(self, result, retval,extra_args):
1476 (statecallback) = extra_args
1477 if self.wlanstatus is not None:
1479 statecallback(result)
1486 def statusdisplay(self,data):
1488 self["status"].setText(_("No information..."))
1490 self["status"].setText(data)
1496 self.stopWlanStatusConsole()
1498 def stopWlanStatusConsole(self):
1499 if self.wlanstatus is not None:
1500 if len(self.wlanstatus.appContainers):
1501 for name in self.wlanstatus.appContainers.keys():
1502 self.wlanstatus.kill(name)
1504 def openconfig(session, **kwargs):
1505 session.open(WlanSelection)
1507 def selSetup(menuid, **kwargs):
1509 if menuid != "system":
1512 for x in iNetwork.getInstalledAdapters():
1513 if x.startswith('eth'):
1517 return [(_("Wireless LAN Setup"), openconfig, "wlansetup_config", 80)]
1522 def Plugins(**kwargs):
1523 return PluginDescriptor(name=_("Wireless LAN Setup"), description="Wireless LAN Setup", where = PluginDescriptor.WHERE_MENU, fnc=selSetup)