1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Screens.InputBox import InputBox
4 from Screens.Standby import *
5 from Screens.VirtualKeyBoard import VirtualKeyBoard
6 from Screens.HelpMenu import HelpableScreen
7 from Components.Network import iNetwork
8 from Screens.NetworkSetup import NameserverSetup
9 from Components.Sources.StaticText import StaticText
10 from Components.Sources.Boolean import Boolean
11 from Components.Sources.List import List
12 from Components.Label import Label,MultiColorLabel
13 from Components.Pixmap import Pixmap,MultiPixmap
14 from Components.MenuList import MenuList
15 from Components.config import config, ConfigYesNo, ConfigIP, NoSave, ConfigText, ConfigPassword, ConfigSelection, getConfigListEntry, ConfigNothing
16 from Components.config import ConfigInteger, ConfigSubsection
17 from Components.ConfigList import ConfigListScreen
18 from Components.PluginComponent import plugins
19 from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest
20 from Components.ActionMap import ActionMap, NumberActionMap, HelpableActionMap
21 from Components.Console import Console
22 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_CURRENT_SKIN
23 from Tools.LoadPixmap import LoadPixmap
24 from Plugins.Plugin import PluginDescriptor
25 from enigma import eTimer, ePoint, eSize, RT_HALIGN_LEFT, eListboxPythonMultiContent, gFont
26 from os import path as os_path, system as os_system, unlink,listdir
27 from re import compile as re_compile, search as re_search
28 from Tools.Directories import fileExists
30 from pythonwifi.iwlibs import Wireless
31 import pythonwifi.flags
33 class WlanSelection(Screen,HelpableScreen):
35 <screen position="center,center" size="510,400" title="Wireless Network Adapter Selection..." >
36 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
37 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
39 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
40 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
42 <widget source="key_red" render="Label" position="10,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
43 <widget source="key_green" render="Label" position="360,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
45 <widget name="menulist" position="20,20" size="230,260" transparent="1" backgroundColor="#371e1c1a" zPosition="10" scrollbarMode="showOnDemand" />
46 <widget source="description" render="Label" position="305,10" size="195,300" font="Regular;19" halign="center" valign="center" />
49 def __init__(self, session):
50 Screen.__init__(self,session)
51 HelpableScreen.__init__(self)
52 self.mainmenu = self.getWlandevice()
53 self["menulist"] = MenuList(self.mainmenu)
54 self["key_red"] = StaticText(_("Close"))
55 self["key_green"] = StaticText(_("Select"))
56 self["description"] = StaticText()
57 self["description"].setText(_("Select Wireless Lan module. \n" ))
58 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
60 "ok": (self.ok, _("select interface")),
61 "cancel": (self.close, _("exit network interface list")),
64 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
66 "green": (self.ok, _("select interface")),
67 "red": (self.close, _("exit network interface list")),
69 self.updateInterfaces()
70 self.onClose.append(self.cleanup)
72 def updateInterfaces(self):
73 iNetwork.config_ready = False
75 iNetwork.getInterfaces()
78 # print len(self["menulist"].list)
79 if len(self["menulist"].list) == 0:
80 self.session.open(MessageBox, (_("Can not find any WirelessLan Module\n")),MessageBox.TYPE_ERROR,5 )
82 ifaces=self["menulist"].getCurrent()[1]
86 self.session.open(WlanSetup,ifaces)
88 def getWlandevice(self):
90 for x in iNetwork.getInstalledAdapters():
91 if x.startswith('eth'):
93 description=self.getAdapterDescription(x)
94 if description == "Unknown network adapter":
95 list.append((description,x))
97 list.append((description + " (%s)"%x,x))
100 def getAdapterDescription(self, iface):
101 classdir = "/sys/class/net/" + iface + "/device/"
102 driverdir = "/sys/class/net/" + iface + "/device/driver/"
103 if os_path.exists(classdir):
104 files = listdir(classdir)
105 if 'driver' in files:
106 if os_path.realpath(driverdir).endswith('rtw_usb_drv'):
107 return _("Realtek")+ " " + _("WLAN adapter.")
108 elif os_path.realpath(driverdir).endswith('ath_pci'):
109 return _("Atheros")+ " " + _("WLAN adapter.")
110 elif os_path.realpath(driverdir).endswith('zd1211b'):
111 return _("Zydas")+ " " + _("WLAN adapter.")
112 elif os_path.realpath(driverdir).endswith('rt73'):
113 return _("Ralink")+ " " + _("WLAN adapter.")
114 elif os_path.realpath(driverdir).endswith('rt73usb'):
115 return _("Ralink")+ " " + _("WLAN adapter.")
117 return str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter")
119 return _("Unknown network adapter")
121 return _("Unknown network adapter")
124 iNetwork.stopGetInterfacesConsole()
126 class WlanSetup(Screen,HelpableScreen):
128 <screen position="center,center" size="510,400" title="Wireless Network Setup Menu..." >
129 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
130 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
132 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
133 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
135 <widget source="key_red" render="Label" position="10,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
136 <widget source="key_green" render="Label" position="360,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
138 <widget name="menulist" position="20,20" size="230,260" transparent="1" backgroundColor="#371e1c1a" zPosition="10" scrollbarMode="showOnDemand" />
139 <widget source="description" render="Label" position="305,10" size="195,300" font="Regular;19" halign="center" valign="center" />
142 def __init__(self, session, ifaces):
143 Screen.__init__(self, session)
144 HelpableScreen.__init__(self)
145 self.session = session
147 self.restartLanRef = None
148 self.LinkState = None
149 self.mainmenu = self.MakeMenu()
150 self["menulist"] = MenuList(self.mainmenu)
151 self["key_red"] = StaticText(_("Close"))
152 self["key_green"] = StaticText(_("Select"))
153 self["description"] = StaticText()
154 self["IFtext"] = StaticText()
155 self["IF"] = StaticText()
156 self["Statustext"] = StaticText()
157 self["statuspic"] = MultiPixmap()
158 self["statuspic"].hide()
159 self.onLayoutFinish.append(self.loadDescription)
161 self.oktext = _("Press OK on your remote control to continue.")
163 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
165 "up": (self.up, _("move up to previous entry")),
166 "down": (self.down, _("move down to next entry")),
167 "left": (self.left, _("move up to first entry")),
168 "right": (self.right, _("move down to last entry")),
171 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
173 "cancel": (self.close, _("exit networkadapter setup menu")),
174 "ok": (self.ok, _("select menu entry")),
177 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
179 "red": (self.close, _("exit networkadapter setup menu")),
180 "green": (self.ok, _("select menu entry")),
183 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
193 self.onClose.append(self.cleanup)
195 def loadDescription(self):
196 if self["menulist"].getCurrent()[1] == 'setting':
197 self["description"].setText(_("Edit the network configuration of your STB.\n" ) + self.oktext )
198 if self["menulist"].getCurrent()[1] == 'scanap':
199 self["description"].setText(_("Scan your network for wireless access points and connect to them using your selected wireless device.\n" ) + self.oktext )
200 if self["menulist"].getCurrent()[1] == 'dns':
201 self["description"].setText(_("Edit the Nameserver configuration of your STB.\n" ) + self.oktext )
202 if self["menulist"].getCurrent()[1] == 'status':
203 self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
204 if self["menulist"].getCurrent()[1] == 'test':
205 self["description"].setText(_("Test the network configuration of your STB.\n" ) + self.oktext )
206 if self["menulist"].getCurrent()[1] == 'restart':
207 self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
210 self["menulist"].up()
211 self.loadDescription()
214 self["menulist"].down()
215 self.loadDescription()
218 self["menulist"].pageUp()
219 self.loadDescription()
222 self["menulist"].pageDown()
223 self.loadDescription()
227 if self["menulist"].getCurrent()[1] == 'setting':
228 self.session.openWithCallback(self.checklist, WlanConfig, self.iface)
229 elif self["menulist"].getCurrent()[1] == 'scanap':
230 self.session.openWithCallback(self.WlanScanApCallback, WlanScanAp, self.iface)
231 elif self["menulist"].getCurrent()[1] == 'dns':
232 self.session.open(NameserverSetup)
233 elif self["menulist"].getCurrent()[1] == 'status':
234 self.session.open(Wlanstatus, self.iface)
235 elif self["menulist"].getCurrent()[1] == 'test':
236 self.session.openWithCallback(self.checklist,NetworkAdapterTest,self.iface)
237 elif self["menulist"].getCurrent()[1] == 'restart':
238 self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
241 self["menulist"].setList(self.MakeMenu())
245 menu.append((_("Adapter settings"), "setting"))
246 menu.append((_("Scan Wireless AP"), "scanap"))
247 menu.append((_("Nameserver settings"), "dns"))
248 if iNetwork.getAdapterAttribute(self.iface, "up"):
249 menu.append((_("Show WLAN Status"), "status"))
250 menu.append((_("Network test"), "test"))
251 menu.append((_("Restart network"), "restart"))
255 def WlanScanApCallback(self, essid = None):
256 if essid is not None:
257 self.session.openWithCallback(self.checklist, WlanConfig, self.iface, essid)
259 def restartLan(self, ret = False):
261 iNetwork.restartNetwork(self.restartLanDataAvail)
262 self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while your network is restarting..."), type = MessageBox.TYPE_INFO, enable_input = False)
264 def restartLanDataAvail(self, data):
266 iNetwork.getInterfaces(self.getInterfacesDataAvail)
268 def getInterfacesDataAvail(self, data):
270 self.restartLanRef.close(True)
272 def restartfinishedCB(self,data):
274 self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 5, default = False)
277 iNetwork.stopRestartConsole()
278 iNetwork.stopGetInterfacesConsole()
280 wlanconfig = ConfigSubsection()
281 wlanconfig.usedevice = ConfigSelection(default = "off", choices = [
282 ("off", _("off")), ("on", _("on"))])
283 wlanconfig.usedhcp = ConfigSelection(default = "off", choices = [
284 ("off", _("no")), ("on", _("yes"))])
285 wlanconfig.essid = ConfigSelection(default = "none", choices = ["none"])
286 wlanconfig.encrypt = ConfigSelection(default = "off", choices = [
287 ("off", _("no")), ("on", _("yes"))])
288 wlanconfig.method = ConfigSelection(default = "wep", choices = [
289 ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
290 wlanconfig.keytype = ConfigSelection(default = "ascii", choices = [
291 ("ascii", _("ASCII")), ("hex", _("HEX"))])
292 wlanconfig.key = ConfigPassword(default = "XXXXXXXX", visible_width = 50, fixed_size = False)
293 wlanconfig.usegateway = ConfigSelection(default = "off", choices = [
294 ("off", _("no")), ("on", _("yes"))])
295 wlanconfig.ip = ConfigIP([0,0,0,0])
296 wlanconfig.netmask = ConfigIP([0,0,0,0])
297 wlanconfig.gateway = ConfigIP([0,0,0,0])
300 class WlanConfig(Screen, ConfigListScreen, HelpableScreen):
302 <screen position="center,center" size="510,400" title="Wireless Network Configuration..." >
303 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
304 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
306 <widget source="key_red" render="Label" position="10,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
307 <widget source="key_green" render="Label" position="360,360" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
309 <widget name="config" position="10,10" backgroundColor="#371e1c1a" transparent="1" size="480,210" scrollbarMode="showOnDemand" />
310 <ePixmap pixmap="skin_default/div-h.png" position="0,225" zPosition="1" size="550,2" />
311 <eLabel text="IP Address : " position="100,250" size="190,21" font="Regular;19" />
312 <widget source="ipaddress" render="Label" position="300,250" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" />
313 <eLabel text="NetMask : " position="100,275" size="190,21" font="Regular;19" />
314 <widget source="netmask" render="Label" position="300,275" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" />
315 <eLabel text="Gateway : " position="100,300" size="190,21" font="Regular;19" />
316 <widget source="gateway" render="Label" position="300,300" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" />
319 def __init__(self, session, iface, essidSelected = None):
320 Screen.__init__(self,session)
321 self.session = session
322 self["key_red"] = StaticText(_("Close"))
323 self["key_green"] = StaticText(_("Ok"))
324 self["ipaddress"] = StaticText(_("[ N/A ]"))
325 self["netmask"] = StaticText(_("[ N/A ]"))
326 self["gateway"] = StaticText(_("[ N/A ]"))
327 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
329 "ok": self.saveWlanConfig,
330 "green": self.saveWlanConfig,
331 "cancel": self.keyCancel,
332 "red": self.keyCancel,
335 self.essidSelected = essidSelected
338 self.scan_ssid = None
342 self.encryption_key = None
343 self.wlanscanap = None
344 self.wpaphraseconsole = None
346 ConfigListScreen.__init__(self, self.list,session = self.session)
347 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
348 self.readWpaSupplicantConf()
349 self.scanAplistTimer = eTimer()
350 self.scanAplistTimer.callback.append(self.scanApList)
351 self.Console = Console()
352 self.updateInterfaces(self.readWlanSettings)
353 self.onClose.append(self.cleanup)
355 def updateInterfaces(self,callback = None):
356 iNetwork.config_ready = False
357 iNetwork.msgPlugins()
358 iNetwork.getInterfaces(callback)
360 def readWlanSettings(self,ret=None):
362 print "getInterfaces Fail... "
363 if iNetwork.getAdapterAttribute(self.iface, "up") == True:
367 wlanconfig.usedevice = ConfigSelection(default=default_tmp, choices = [("off", _("off")), ("on", _("on"))])
369 if iNetwork.getAdapterAttribute(self.iface, "dhcp"):
373 wlanconfig.usedhcp = ConfigSelection(default=default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
375 wlanconfig.ip = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0]
377 wlanconfig.netmask = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0])
378 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
382 wlanconfig.usegateway = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
384 wlanconfig.gateway = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0])
386 self["ipaddress"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "ip"))))
387 self["netmask"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "netmask"))))
388 self["gateway"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "gateway"))))
390 if self.encryption_key is not None:
394 wlanconfig.encrypt = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
396 if self.key_mgmt=="NONE":
398 elif self.key_mgmt == "WPA-PSK":
399 if self.proto == "WPA":
401 elif self.proto == "RSN":
403 elif self.proto in ( "WPA RSN", "WPA WPA2"):
404 default_tmp = "wpa/wpa2"
410 wlanconfig.method = ConfigSelection(default = default_tmp, choices = [
411 ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
413 if self.key_type == 0:
416 default_tmp = "ascii"
417 wlanconfig.keytype = ConfigSelection(default = default_tmp, choices = [
418 ("ascii", _("ASCII")), ("hex", _("HEX"))])
419 default_tmp = self.encryption_key or "XXXXXXXX"
420 wlanconfig.key = ConfigPassword(default = default_tmp, visible_width = 50, fixed_size = False)
423 def readWpaSupplicantConf(self):
425 if fileExists("/etc/wpa_supplicant.conf"):
426 wpafd = open("/etc/wpa_supplicant.conf","r")
428 data = wpafd.readline()
430 # print "####readWpaSupplicantConf, data : ",data
433 data = wpafd.readline()
435 if data.startswith('ssid=') and len(data) > 6:
436 self.ssid = data[6:-2]
437 elif data.startswith('ap_scan=') :
438 self.ap_scan = data[8:]
439 # print "####readWpaSupplicantConf, ap_scan : ",self.ap_scan
440 elif data.startswith('scan_ssid=') and len(data) > 10:
441 self.scan_ssid = data[10:-1]
442 elif data.startswith('key_mgmt=') and len(data) > 9:
443 self.key_mgmt = data[9:-1]
444 elif data.startswith('proto=') and len(data) > 6:
445 self.proto = data[6:-1]
446 elif data.startswith('wep_key0="') and len(data) > 11:
447 self.key_type = 1 # ascii
448 self.encryption_key = data[10:-2]
449 elif data.startswith('wep_key0=') and len(data) > 9:
450 self.key_type = 0 # hex
451 self.encryption_key = data[9:-1]
452 elif data.startswith('psk="') and len(data) > 6:
453 self.key_type = 1 # ascii
454 self.encryption_key = data[5:-2]
455 elif data.startswith('#psk="') and len(data) > 6:
456 self.key_type = 0 # hex
457 self.encryption_key = data[6:-2]
458 elif not self.encryption_key and data.startswith('psk=') and len(data) > 4:
459 self.key_type = 0 # hex
460 self.encryption_key = data[4:-1]
461 data = wpafd.readline()
462 # print self.ssid,self.scan_ssid,self.key_mgmt,self.proto,self.key_type,self.encryption_key
469 print 'failed loading wpasupplicant.conf'
471 def createConfig(self):
473 self.usedeviceEntry = getConfigListEntry(_("Use Device"), wlanconfig.usedevice)
474 self.usedhcpEntry = getConfigListEntry(_("Use DHCP"), wlanconfig.usedhcp)
475 self.essidEntry = getConfigListEntry(_("ESSID"), wlanconfig.essid)
476 self.hiddenessidEntry = getConfigListEntry(_("Input Hidden ESSID"), wlanconfig.hiddenessid)
477 self.encryptEntry = getConfigListEntry(_("Encrypt"), wlanconfig.encrypt)
478 self.methodEntry = getConfigListEntry(_("Method"), wlanconfig.method)
479 self.keytypeEntry = getConfigListEntry(_("Key Type"), wlanconfig.keytype)
480 self.keyEntry = getConfigListEntry(_("KEY"), wlanconfig.key)
482 self.ipEntry = getConfigListEntry(_("IP"), wlanconfig.ip)
483 self.netmaskEntry = getConfigListEntry(_("NetMask"), wlanconfig.netmask)
485 self.usegatewayEntry = getConfigListEntry(_("Use Gateway"), wlanconfig.usegateway)
486 self.gatewayEntry = getConfigListEntry(_("Gateway"), wlanconfig.gateway)
488 self.configList.append( self.usedeviceEntry )
489 if wlanconfig.usedevice.value is "on":
490 self.configList.append( self.usedhcpEntry )
491 if wlanconfig.usedhcp.value is "off":
492 self.configList.append(self.ipEntry)
493 self.configList.append(self.netmaskEntry)
494 self.configList.append(self.usegatewayEntry)
495 if wlanconfig.usegateway.value is "on":
496 self.configList.append(self.gatewayEntry)
497 self.configList.append( self.essidEntry )
498 if wlanconfig.essid.value == 'Input hidden ESSID':
499 self.configList.append( self.hiddenessidEntry )
500 self.configList.append( self.encryptEntry )
501 if wlanconfig.encrypt.value is "on" :
502 self.configList.append( self.methodEntry )
503 if wlanconfig.method.value =="wep":
504 self.configList.append( self.keytypeEntry )
505 self.configList.append( self.keyEntry )
507 self["config"].list = self.configList
508 self["config"].l.setList(self.configList)
511 if self.essidSelected is None:
513 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
514 self.scanAplistTimer.start(100,True)
516 self.apList = [self.essidSelected]
517 wlanconfig.essid = ConfigSelection(choices = self.apList)
518 if self.ssid is not None:
519 wlanconfig.hiddenessid = ConfigText(default = self.ssid, visible_width = 50, fixed_size = False)
521 wlanconfig.hiddenessid = ConfigText(default = "<Input ESSID>", visible_width = 50, fixed_size = False)
524 def scanApList(self):
526 wirelessObj = Wireless(self.iface)
528 Iwscanresult = wirelessObj.scan()
530 print "%s Interface doesn't support scanning.."%self.iface
531 self.session.open(MessageBox, "%s Interface doesn't support scanning.."%self.iface, MessageBox.TYPE_ERROR,10)
532 self.configurationmsg.close(True)
533 if Iwscanresult is None:
534 self.session.open(MessageBox, _("No scan results"), MessageBox.TYPE_ERROR,10)
536 for ap in Iwscanresult:
537 if ap.essid not in self.apList and len(ap.essid) > 0:
538 self.apList.append(ap.essid)
539 self.apList.append('Input hidden ESSID')
540 if selectap is not None and selectap in self.apList:
541 wlanconfig.essid = ConfigSelection(default=selectap,choices = self.apList)
542 elif self.scan_ssid is not None and self.scan_ssid.strip() == '1':
543 wlanconfig.essid = ConfigSelection(default='Input hidden ESSID',choices = self.apList)
544 elif self.ssid is not None and self.ssid in self.apList:
545 wlanconfig.essid = ConfigSelection(default=self.ssid, choices = self.apList)
548 wlanconfig.essid = ConfigSelection(defalut = self.apList[0], choices = self.apList)
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)
558 ConfigListScreen.keyLeft(self)
562 ConfigListScreen.keyRight(self)
566 if self["config"].getCurrent() == self.usedeviceEntry or self["config"].getCurrent() == self.encryptEntry \
567 or self["config"].getCurrent() == self.usedhcpEntry or self["config"].getCurrent() == self.usegatewayEntry \
568 or self["config"].getCurrent() == self.essidEntry or self["config"].getCurrent() == self.methodEntry:
571 def saveWlanConfig(self):
573 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
574 self["config"].getCurrent()[1].onDeselect(self.session)
575 if self["config"].isChanged():
576 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Are you sure you want to restart your network interfaces?\n") ) )
578 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Network configuration is not changed....\n\nAre you sure you want to restart your network interfaces?\n") ) )
582 def checkNetworkConfig(self, ret = False):
584 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
585 self["config"].getCurrent()[1].onSelect(self.session)
587 if wlanconfig.essid.value == 'Input hidden ESSID':
588 if len(wlanconfig.hiddenessid.value) == 0:
589 self.session.open(MessageBox, ("PLEASE INPUT HIDDEN ESSID"), type = MessageBox.TYPE_ERROR, timeout = 10)
591 if len(wlanconfig.key.value) == 0:
592 self.session.open(MessageBox, ("PLEASE INPUT NETWORK KEY"), type = MessageBox.TYPE_ERROR, timeout = 10)
594 self.checkNetworkShares()
596 def checkNetworkShares(self):
598 self.Console = Console()
599 cmd = "cat /proc/mounts"
600 self.Console.ePopen(cmd, self.checkSharesFinished, self.confirmAnotherIfaces)
602 def checkSharesFinished(self, result, retval, extra_args):
603 callback = extra_args
604 # print "checkMountsFinished : result : \n",result
605 networks = ['nfs','smbfs','ncp','coda']
606 for line in result.splitlines():
607 split = line.strip().split(' ',3)
608 if split[2] in networks:
609 self.session.open(MessageBox, ("NOT deconfiguring network interfaces :\n network shares still mounted\n"), type = MessageBox.TYPE_ERROR, timeout = 10)
611 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
612 self["config"].getCurrent()[1].onSelect(self.session)
616 def confirmAnotherIfaces(self, ret = False):
620 num_configured_if = len(iNetwork.getConfiguredAdapters())
621 if num_configured_if >= 1:
622 if num_configured_if == 1 and self.iface in iNetwork.getConfiguredAdapters():
623 self.getWpaPhrase(False)
625 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)
627 self.getWpaPhrase(False)
629 def getWpaPhrase(self,ret):
631 configuredInterfaces = iNetwork.getConfiguredAdapters()
632 for interface in configuredInterfaces:
633 if interface == self.iface:
635 iNetwork.setAdapterAttribute(interface, "up", False)
636 iNetwork.deactivateInterface(interface)
637 if wlanconfig.method.value =="wep":
638 self.writeWpasupplicantConf("wep") # passphrasekey is not None
640 if wlanconfig.essid.value == 'Input hidden ESSID':
641 cmd = 'wpa_passphrase %s %s' % (wlanconfig.hiddenessid.value,wlanconfig.key.value)
643 cmd = 'wpa_passphrase %s %s' % (wlanconfig.essid.value,wlanconfig.key.value)
645 self.wpaphraseconsole = Console()
646 self.wpaphraseconsole.ePopen(cmd, self.parseWpaPhrase, self.writeWpasupplicantConf)
648 def parseWpaPhrase(self, result, retval, extra_args):
649 (writewlanconfig) = extra_args
650 if self.wpaphraseconsole is not None:
652 self.wpaphraseconsole.killAll()
653 self.wpaphraseconsole = None
654 # print "parseWpaPhrase result : "
657 for line in result.splitlines():
658 if line.find('ssid') == -1 and line.find('#psk=') != -1:
660 elif line.find('psk=') != -1:
663 writewlanconfig(psk,plainpwd)
665 writewlanconfig(None)
667 writewlanconfig(None)
669 def writeWpasupplicantConf(self, passphrasekey=None,plainpwd=None):
671 wpafd = open("/etc/wpa_supplicant.conf","w")
673 contents = "#WPA Supplicant Configuration by STB\n"
674 contents += "ctrl_interface=/var/run/wpa_supplicant\n"
675 contents += "eapol_version=1\n"
676 contents += "fast_reauth=1\n"
677 contents += "ap_scan=1\n"
678 contents += "network={\n"
679 if wlanconfig.essid.value == 'Input hidden ESSID':
680 contents += "\tssid=\""+wlanconfig.hiddenessid.value+"\"\n"
681 contents += "\tscan_ssid=1\n"
683 contents += "\tssid=\""+wlanconfig.essid.value+"\"\n"
684 contents += "\tscan_ssid=0\n"
685 if wlanconfig.encrypt.value == "on":
686 if wlanconfig.method.value =="wep":
687 contents += "\tkey_mgmt=NONE\n"
688 contents += "\twep_key0="
689 if wlanconfig.keytype.value == "ascii":
690 contents += "\""+wlanconfig.key.value+"\"\n"
692 contents += wlanconfig.key.value+"\n"
694 # print "plainpwd : ",plainpwd
695 # print "passphrasekey : ",passphrasekey
696 if wlanconfig.method.value == "wpa":
697 contents += "\tkey_mgmt=WPA-PSK\n"
698 contents += "\tproto=WPA\n"
699 contents += "\tpairwise=CCMP TKIP\n"
700 contents += "\tgroup=CCMP TKIP\n"
701 elif wlanconfig.method.value == "wpa2":
702 contents += "\tkey_mgmt=WPA-PSK\n"
703 contents += "\tproto=RSN\n"
704 contents += "\tpairwise=CCMP TKIP\n"
705 contents += "\tgroup=CCMP TKIP\n"
707 contents += "\tkey_mgmt=WPA-PSK\n"
708 contents += "\tproto=WPA RSN\n"
709 contents += "\tpairwise=CCMP TKIP\n"
710 contents += "\tgroup=CCMP TKIP\n"
711 contents += plainpwd+"\n"
712 contents += passphrasekey+"\n"
714 contents += "\tkey_mgmt=NONE\n"
716 print "content = \n"+contents
717 wpafd.write(contents)
719 self.writeNetConfig(0)
721 self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
722 self.writeNetConfig(-1)
724 self.writeNetConfig(-2)
726 def writeNetConfig(self,ret = -1):
728 self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
731 self.session.open(MessageBox, _("Can NOT generate passphrase"), type = MessageBox.TYPE_ERROR, timeout = 10)
734 if wlanconfig.usedevice.value=="on":
735 iNetwork.setAdapterAttribute(self.iface, "up", True)
736 if wlanconfig.usedhcp.value =="on":
737 iNetwork.setAdapterAttribute(self.iface, "dhcp", True)
739 iNetwork.setAdapterAttribute(self.iface, "dhcp", False)
740 iNetwork.setAdapterAttribute(self.iface, "ip", wlanconfig.ip.value)
741 iNetwork.setAdapterAttribute(self.iface, "netmask", wlanconfig.netmask.value)
742 if wlanconfig.usegateway.value == "on":
743 iNetwork.setAdapterAttribute(self.iface, "gateway", wlanconfig.gateway.value)
745 iNetwork.setAdapterAttribute(self.iface, "up", False)
746 iNetwork.deactivateInterface(self.iface)
747 contents = "\tpre-up wpa_supplicant -i"+self.iface+" -c/etc/wpa_supplicant.conf -B -D"+iNetwork.detectWlanModule(self.iface)+"\n"
748 contents += "\tpost-down wpa_cli terminate\n\n"
749 iNetwork.setAdapterAttribute(self.iface, "configStrings", contents)
750 iNetwork.writeNetworkConfig()
751 iNetwork.restartNetwork(self.updateCurrentInterfaces)
752 self.configurationmsg = None
753 self.configurationmsg = self.session.openWithCallback(self.configFinished, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
756 def updateCurrentInterfaces(self,ret):
758 iNetwork.getInterfaces(self.configurationMsgClose)
760 def configurationMsgClose(self,ret):
761 if ret is True and self.configurationmsg is not None:
762 self.configurationmsg.close(True)
764 def configFinished(self,data):
767 self.session.openWithCallback(self.configFinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
768 selectap = wlanconfig.essid.value
770 def configFinishedCB(self,data):
775 def formatip(self, iplist):
778 # print "iplist : ",iplist
781 result = str(iplist[0])+"."+str(iplist[1])+"."+str(iplist[2])+"."+str(iplist[3])
784 # print "result : ",result
789 def keyCancelConfirm(self, result):
792 if self.oldInterfaceState is False:
793 iNetwork.setAdapterAttribute(self.iface, "up", False)
794 iNetwork.deactivateInterface(self.iface,self.keyCancelCB)
798 def keyCancel(self,yesno = True):
799 if self["config"].isChanged():
800 self.session.openWithCallback(self.keyCancelConfirm, MessageBox, _("Really close without saving settings?"))
802 self.keyCancelConfirm(True)
804 def keyCancelCB(self,data):
810 iNetwork.stopRestartConsole()
811 iNetwork.stopGetInterfacesConsole()
812 iNetwork.stopDeactivateInterfaceConsole()
813 self.stopwlanscanapConsole()
814 self.stopCheckNetworkSharesConsole()
815 self.stopWpaPhraseConsole()
817 def stopwlanscanapConsole(self):
818 if self.wlanscanap is not None:
819 if len(self.wlanscanap.appContainers):
820 for name in self.wlanscanap.appContainers.keys():
821 self.wlanscanap.kill(name)
823 def stopCheckNetworkSharesConsole(self):
824 if self.Console is not None:
825 if len(self.Console.appContainers):
826 for name in self.Console.appContainers.keys():
827 self.Console.kill(name)
829 def stopWpaPhraseConsole(self):
830 if self.wpaphraseconsole is not None:
831 if len(self.wpaphraseconsole.appContainers):
832 for name in self.wpaphraseconsole.appContainers.keys():
833 self.wpaphraseconsole.kill(name)
835 class WlanScanAp(Screen,HelpableScreen):
837 <screen position="center,center" size="510,400" title="Wireless Network AP Scan..." >
838 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
839 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
841 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
842 <ePixmap pixmap="skin_default/buttons/green.png" position="185,360" size="140,40" alphatest="on" />
843 <ePixmap pixmap="skin_default/buttons/blue.png" position="360,360" size="140,40" alphatest="on" />
845 <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" />
846 <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" />
847 <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" />
849 <widget name="menulist" position="20,20" size="230,260" backgroundColor="#371e1c1a" transparent="1" zPosition="10" scrollbarMode="showOnDemand" />
851 <widget source="Address" render="Label" position="265,70" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
852 <widget source="ESSID" render="Label" position="265,100" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
853 <widget source="Protocol" render="Label" position="265,130" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
854 <widget source="Frequency" render="Label" position="265,160" zPosition="1" size="240,40" font="Regular;18" halign="center" valign="center" />
855 <widget source="Encryption key" render="Label" position="265,200" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
856 <widget source="BitRate" render="Label" position="265,220" zPosition="1" size="240,60" font="Regular;18" halign="center" valign="center" />
859 def __init__(self, session, iface):
860 Screen.__init__(self,session)
861 HelpableScreen.__init__(self)
862 self.session = session
864 self.wlanscanap = None
868 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
870 "up": (self.up, _("move up to previous entry")),
871 "down": (self.down, _("move down to next entry")),
872 "left": (self.left, _("move up to first entry")),
873 "right": (self.right, _("move down to last entry")),
876 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
878 "cancel": (self.close, _("exit")),
879 "ok": (self.ok, "select AP"),
882 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
884 "red": (self.close, _("exit")),
885 "green": (self.ok, "select AP"),
886 "yellow": (self.restartScanAP, "restart scan AP"),
887 "blue": (self.startWlanConfig, "Edit Wireless settings"),
890 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
901 self["menulist"] = MenuList(self.setApList)
902 self["key_red"] = StaticText(_("Close"))
903 self["key_green"] = StaticText(_("Select"))
904 self["key_blue"] = StaticText(_("EditSetting"))
905 self["Address"] = StaticText(_("Scanning AP List.."))
906 self["ESSID"] = StaticText(_("Wait a moment"))
907 self["Protocol"] = StaticText(" ")
908 self["Frequency"] = StaticText(" ")
909 self["Encryption key"] = StaticText(" ")
910 self["BitRate"] = StaticText(" ")
911 self.getAplistTimer = eTimer()
912 self.getAplistTimer.callback.append(self.getApList)
913 self.scanAplistTimer = eTimer()
914 self.scanAplistTimer.callback.append(self.scanApList)
916 self.getAplistTimer.start(100,True)
919 self["menulist"].pageUp()
923 self["menulist"].pageDown()
927 self["menulist"].up()
931 self["menulist"].down()
936 selectAp=self["menulist"].getCurrent()[0]
940 def startWlanConfig(self):
941 selectAp=self["menulist"].getCurrent()[0]
947 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
948 self.scanAplistTimer.start(100,True)
950 def scanApList(self):
952 wirelessObj = Wireless(self.iface)
954 Iwscanresult = wirelessObj.scan()
956 print "%s Interface doesn't support scanning.."%self.iface
957 self.session.open(MessageBox, "%s Interface doesn't support scanning.."%self.iface, MessageBox.TYPE_ERROR,10)
958 self.configurationmsg.close(True)
959 if Iwscanresult is None:
960 self.session.open(MessageBox, _("No scan results"), MessageBox.TYPE_ERROR,10)
962 (num_channels, frequencies) = wirelessObj.getChannelInfo()
964 for ap in Iwscanresult:
965 self.apList[index] = {}
966 self.apList[index]["Address"] = ap.bssid
967 if len(ap.essid) == 0:
968 self.apList[index]["ESSID"] = "<hidden ESSID>"
970 self.apList[index]["ESSID"] = ap.essid
971 self.setApList.append( (self.apList[index]["ESSID"], index) )
972 self.apList[index]["Protocol"] = ap.protocol
973 self.apList[index]["Frequency"] = wirelessObj._formatFrequency(ap.frequency.getFrequency())
975 self.apList[index]["Channel"] = frequencies.index(self.apList[index]["Frequency"] + 1)
977 self.apList[index]["Channel"] = "Unknown"
979 self.apList[index]["Quality"] = "%s/%s" % \
980 ( ap.quality.quality, wirelessObj.getQualityMax().quality )
981 self.apList[index]["Signal Level"] = "%s/%s" % \
982 ( ap.quality.getSignallevel(), "100" )
983 self.apList[index]["Noise Level"] = "%s/%s" % \
984 ( ap.quality.getNoiselevel(), "100" )
986 # get encryption key on/off
987 key_status = "Unknown"
988 if (ap.encode.flags & pythonwifi.flags.IW_ENCODE_DISABLED):
990 elif (ap.encode.flags & pythonwifi.flags.IW_ENCODE_NOKEY):
991 if (ap.encode.length <= 0):
993 self.apList[index]["Encryption key"] = key_status
994 self.apList[index]["BitRate"] = wirelessObj._formatBitrate(ap.rate[-1][-1])
997 # print self.setApList
1000 def displayApInfo(self):
1001 if len(self.apList) >0:
1002 self["menulist"].setList(self.setApList)
1003 index = self["menulist"].getCurrent()[1]
1004 for key in ["Address", "ESSID", "Protocol", "Frequency", "Encryption key", "BitRate"]:
1005 if self.apList[index].has_key(key):
1006 self[key].setText((key+": "+self.apList[index][key]))
1008 self[key].setText((key+": None"))
1010 self.session.open(MessageBox, _("No AP detected."), type = MessageBox.TYPE_INFO, timeout = 10)
1012 def restartScanAP(self):
1013 self.getAplistTimer.start(100,True)
1015 class NetworkAdapterTest(Screen):
1016 def __init__(self, session,iface):
1017 Screen.__init__(self, session)
1019 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
1021 self.onClose.append(self.cleanup)
1022 self.onHide.append(self.cleanup)
1024 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
1028 "up": lambda: self.updownhandler('up'),
1029 "down": lambda: self.updownhandler('down'),
1033 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1036 "back": self.cancel,
1038 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1040 "red": self.closeInfo,
1041 "back": self.closeInfo,
1043 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
1045 "green": self.KeyGreen,
1047 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
1049 "green": self.KeyGreenRestart,
1051 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
1053 "yellow": self.KeyYellow,
1056 self["shortcutsgreen_restart"].setEnabled(False)
1057 self["updown_actions"].setEnabled(False)
1058 self["infoshortcuts"].setEnabled(False)
1059 self.onClose.append(self.delTimer)
1060 self.onLayoutFinish.append(self.layoutFinished)
1061 self.steptimer = False
1063 self.activebutton = 0
1064 self.nextStepTimer = eTimer()
1065 self.nextStepTimer.callback.append(self.nextStepTimerFire)
1068 if self.oldInterfaceState is False:
1069 iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
1070 iNetwork.deactivateInterface(self.iface)
1073 def closeInfo(self):
1074 self["shortcuts"].setEnabled(True)
1075 self["infoshortcuts"].setEnabled(False)
1076 self["InfoText"].hide()
1077 self["InfoTextBorder"].hide()
1078 self["key_red"].setText(_("Close"))
1082 del self.nextStepTimer
1084 def nextStepTimerFire(self):
1085 self.nextStepTimer.stop()
1086 self.steptimer = False
1089 def updownhandler(self,direction):
1090 if direction == 'up':
1091 if self.activebutton >=2:
1092 self.activebutton -= 1
1094 self.activebutton = 6
1095 self.setActiveButton(self.activebutton)
1096 if direction == 'down':
1097 if self.activebutton <=5:
1098 self.activebutton += 1
1100 self.activebutton = 1
1101 self.setActiveButton(self.activebutton)
1103 def setActiveButton(self,button):
1105 self["EditSettingsButton"].setPixmapNum(0)
1106 self["EditSettings_Text"].setForegroundColorNum(0)
1107 self["NetworkInfo"].setPixmapNum(0)
1108 self["NetworkInfo_Text"].setForegroundColorNum(1)
1109 self["AdapterInfo"].setPixmapNum(1) # active
1110 self["AdapterInfo_Text"].setForegroundColorNum(2) # active
1112 self["AdapterInfo_Text"].setForegroundColorNum(1)
1113 self["AdapterInfo"].setPixmapNum(0)
1114 self["DhcpInfo"].setPixmapNum(0)
1115 self["DhcpInfo_Text"].setForegroundColorNum(1)
1116 self["NetworkInfo"].setPixmapNum(1) # active
1117 self["NetworkInfo_Text"].setForegroundColorNum(2) # active
1119 self["NetworkInfo"].setPixmapNum(0)
1120 self["NetworkInfo_Text"].setForegroundColorNum(1)
1121 self["IPInfo"].setPixmapNum(0)
1122 self["IPInfo_Text"].setForegroundColorNum(1)
1123 self["DhcpInfo"].setPixmapNum(1) # active
1124 self["DhcpInfo_Text"].setForegroundColorNum(2) # active
1126 self["DhcpInfo"].setPixmapNum(0)
1127 self["DhcpInfo_Text"].setForegroundColorNum(1)
1128 self["DNSInfo"].setPixmapNum(0)
1129 self["DNSInfo_Text"].setForegroundColorNum(1)
1130 self["IPInfo"].setPixmapNum(1) # active
1131 self["IPInfo_Text"].setForegroundColorNum(2) # active
1133 self["IPInfo"].setPixmapNum(0)
1134 self["IPInfo_Text"].setForegroundColorNum(1)
1135 self["EditSettingsButton"].setPixmapNum(0)
1136 self["EditSettings_Text"].setForegroundColorNum(0)
1137 self["DNSInfo"].setPixmapNum(1) # active
1138 self["DNSInfo_Text"].setForegroundColorNum(2) # active
1140 self["DNSInfo"].setPixmapNum(0)
1141 self["DNSInfo_Text"].setForegroundColorNum(1)
1142 self["EditSettingsButton"].setPixmapNum(1) # active
1143 self["EditSettings_Text"].setForegroundColorNum(2) # active
1144 self["AdapterInfo"].setPixmapNum(0)
1145 self["AdapterInfo_Text"].setForegroundColorNum(1)
1148 next = self.nextstep
1164 self.steptimer = True
1165 self.nextStepTimer.start(3000)
1166 self["key_yellow"].setText(_("Stop test"))
1169 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
1170 self["Adapter"].setForegroundColorNum(2)
1171 self["Adaptertext"].setForegroundColorNum(1)
1172 self["AdapterInfo_Text"].setForegroundColorNum(1)
1173 self["AdapterInfo_OK"].show()
1174 self.steptimer = True
1175 self.nextStepTimer.start(3000)
1178 self["Networktext"].setForegroundColorNum(1)
1179 self["Network"].setText(_("Please wait..."))
1180 self.AccessPointInfo(self.iface)
1181 self["NetworkInfo_Text"].setForegroundColorNum(1)
1182 self.steptimer = True
1183 self.nextStepTimer.start(3000)
1186 self["Dhcptext"].setForegroundColorNum(1)
1187 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
1188 self["Dhcp"].setForegroundColorNum(2)
1189 self["Dhcp"].setText(_("enabled"))
1190 self["DhcpInfo_Check"].setPixmapNum(0)
1192 self["Dhcp"].setForegroundColorNum(1)
1193 self["Dhcp"].setText(_("disabled"))
1194 self["DhcpInfo_Check"].setPixmapNum(1)
1195 self["DhcpInfo_Check"].show()
1196 self["DhcpInfo_Text"].setForegroundColorNum(1)
1197 self.steptimer = True
1198 self.nextStepTimer.start(3000)
1201 self["IPtext"].setForegroundColorNum(1)
1202 self["IP"].setText(_("Please wait..."))
1203 iNetwork.checkNetworkState(self.NetworkStatedataAvail)
1206 self.steptimer = False
1207 self.nextStepTimer.stop()
1208 self["DNStext"].setForegroundColorNum(1)
1209 self["DNS"].setText(_("Please wait..."))
1210 iNetwork.checkDNSLookup(self.DNSLookupdataAvail)
1213 self["shortcutsgreen"].setEnabled(False)
1214 self["shortcutsyellow"].setEnabled(True)
1215 self["updown_actions"].setEnabled(False)
1216 self["key_yellow"].setText("")
1217 self["key_green"].setText("")
1218 self.steptimer = True
1219 self.nextStepTimer.start(1000)
1221 def KeyGreenRestart(self):
1223 self.layoutFinished()
1224 self["Adapter"].setText((""))
1225 self["Network"].setText((""))
1226 self["Dhcp"].setText((""))
1227 self["IP"].setText((""))
1228 self["DNS"].setText((""))
1229 self["AdapterInfo_Text"].setForegroundColorNum(0)
1230 self["NetworkInfo_Text"].setForegroundColorNum(0)
1231 self["DhcpInfo_Text"].setForegroundColorNum(0)
1232 self["IPInfo_Text"].setForegroundColorNum(0)
1233 self["DNSInfo_Text"].setForegroundColorNum(0)
1234 self["shortcutsgreen_restart"].setEnabled(False)
1235 self["shortcutsgreen"].setEnabled(False)
1236 self["shortcutsyellow"].setEnabled(True)
1237 self["updown_actions"].setEnabled(False)
1238 self["key_yellow"].setText("")
1239 self["key_green"].setText("")
1240 self.steptimer = True
1241 self.nextStepTimer.start(1000)
1244 self["infoshortcuts"].setEnabled(True)
1245 self["shortcuts"].setEnabled(False)
1246 if self.activebutton == 1: # Adapter Check
1247 self["InfoText"].setText(_("This test detects your configured Wireless LAN-Adapter."))
1248 self["InfoTextBorder"].show()
1249 self["InfoText"].show()
1250 self["key_red"].setText(_("Back"))
1251 if self.activebutton == 2: #LAN Check
1252 self["InfoText"].setText(_("This test checks whether a network cable is connected to your Wireless LAN-Adapter."))
1253 self["InfoTextBorder"].show()
1254 self["InfoText"].show()
1255 self["key_red"].setText(_("Back"))
1256 if self.activebutton == 3: #DHCP Check
1257 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."))
1258 self["InfoTextBorder"].show()
1259 self["InfoText"].show()
1260 self["key_red"].setText(_("Back"))
1261 if self.activebutton == 4: # IP Check
1262 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"))
1263 self["InfoTextBorder"].show()
1264 self["InfoText"].show()
1265 self["key_red"].setText(_("Back"))
1266 if self.activebutton == 5: # DNS Check
1267 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"))
1268 self["InfoTextBorder"].show()
1269 self["InfoText"].show()
1270 self["key_red"].setText(_("Back"))
1271 if self.activebutton == 6: # Edit Settings
1273 self.session.open(WlanConfig,self.iface)
1274 self["shortcuts"].setEnabled(True)
1275 self["infoshortcuts"].setEnabled(False)
1277 def KeyYellow(self):
1279 self["shortcutsgreen_restart"].setEnabled(True)
1280 self["shortcutsgreen"].setEnabled(False)
1281 self["shortcutsyellow"].setEnabled(False)
1282 self["key_green"].setText(_("Restart test"))
1283 self["key_yellow"].setText("")
1284 self.steptimer = False
1285 self.nextStepTimer.stop()
1287 def layoutFinished(self):
1288 self.setTitle(_("Network test: ") + iNetwork.getFriendlyAdapterName(self.iface) )
1289 self["shortcutsyellow"].setEnabled(False)
1290 self["AdapterInfo_OK"].hide()
1291 self["NetworkInfo_Check"].hide()
1292 self["DhcpInfo_Check"].hide()
1293 self["IPInfo_Check"].hide()
1294 self["DNSInfo_Check"].hide()
1295 self["EditSettings_Text"].hide()
1296 self["EditSettingsButton"].hide()
1297 self["InfoText"].hide()
1298 self["InfoTextBorder"].hide()
1299 self["key_yellow"].setText("")
1301 def setLabels(self):
1302 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1303 self["Adapter"] = MultiColorLabel()
1304 self["AdapterInfo"] = MultiPixmap()
1305 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1306 self["AdapterInfo_OK"] = Pixmap()
1308 if self.iface in iNetwork.wlan_interfaces:
1309 self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1311 self["Networktext"] = MultiColorLabel(_("Local Network"))
1313 self["Network"] = MultiColorLabel()
1314 self["NetworkInfo"] = MultiPixmap()
1315 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1316 self["NetworkInfo_Check"] = MultiPixmap()
1318 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1319 self["Dhcp"] = MultiColorLabel()
1320 self["DhcpInfo"] = MultiPixmap()
1321 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1322 self["DhcpInfo_Check"] = MultiPixmap()
1324 self["IPtext"] = MultiColorLabel(_("IP Address"))
1325 self["IP"] = MultiColorLabel()
1326 self["IPInfo"] = MultiPixmap()
1327 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1328 self["IPInfo_Check"] = MultiPixmap()
1330 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1331 self["DNS"] = MultiColorLabel()
1332 self["DNSInfo"] = MultiPixmap()
1333 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1334 self["DNSInfo_Check"] = MultiPixmap()
1336 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1337 self["EditSettingsButton"] = MultiPixmap()
1339 self["key_red"] = StaticText(_("Close"))
1340 self["key_green"] = StaticText(_("Start test"))
1341 self["key_yellow"] = StaticText(_("Stop test"))
1343 self["InfoTextBorder"] = Pixmap()
1344 self["InfoText"] = Label()
1346 def NetworkStatedataAvail(self,data):
1348 self["IP"].setForegroundColorNum(2)
1349 self["IP"].setText(_("confirmed"))
1350 self["IPInfo_Check"].setPixmapNum(0)
1352 self["IP"].setForegroundColorNum(1)
1353 self["IP"].setText(_("unconfirmed"))
1354 self["IPInfo_Check"].setPixmapNum(1)
1355 self["IPInfo_Check"].show()
1356 self["IPInfo_Text"].setForegroundColorNum(1)
1357 self.steptimer = True
1358 self.nextStepTimer.start(3000)
1360 def DNSLookupdataAvail(self,data):
1362 self["DNS"].setForegroundColorNum(2)
1363 self["DNS"].setText(_("confirmed"))
1364 self["DNSInfo_Check"].setPixmapNum(0)
1366 self["DNS"].setForegroundColorNum(1)
1367 self["DNS"].setText(_("unconfirmed"))
1368 self["DNSInfo_Check"].setPixmapNum(1)
1369 self["DNSInfo_Check"].show()
1370 self["DNSInfo_Text"].setForegroundColorNum(1)
1371 self["EditSettings_Text"].show()
1372 self["EditSettingsButton"].setPixmapNum(1)
1373 self["EditSettings_Text"].setForegroundColorNum(2) # active
1374 self["EditSettingsButton"].show()
1375 self["key_yellow"].setText("")
1376 self["key_green"].setText(_("Restart test"))
1377 self["shortcutsgreen"].setEnabled(False)
1378 self["shortcutsgreen_restart"].setEnabled(True)
1379 self["shortcutsyellow"].setEnabled(False)
1380 self["updown_actions"].setEnabled(True)
1381 self.activebutton = 6
1383 def getInfoCB(self,status):
1384 if status is not None:
1385 if status.startswith("No Connection") or status.startswith("Not-Associated") or status == False:
1386 self["Network"].setForegroundColorNum(1)
1387 self["Network"].setText(_("disconnected"))
1388 self["NetworkInfo_Check"].setPixmapNum(1)
1389 self["NetworkInfo_Check"].show()
1391 self["Network"].setForegroundColorNum(2)
1392 self["Network"].setText(_("connected"))
1393 self["NetworkInfo_Check"].setPixmapNum(0)
1394 self["NetworkInfo_Check"].show()
1397 iNetwork.stopLinkStateConsole()
1398 iNetwork.stopPingConsole()
1399 iNetwork.stopDNSConsole()
1401 def AccessPointInfo(self,iface):
1402 cmd = "iwconfig %s"%iface
1403 self.iwconfigConsole = Console()
1404 self.iwconfigConsole.ePopen(cmd,self.readAP,self.getInfoCB)
1406 def readAP(self,result,retval,extra_args):
1407 (callback) = extra_args
1409 if self.iwconfigConsole is not None:
1411 self.iwconfigConsole = None
1412 for content in result.splitlines():
1413 if 'Access Point' in content:
1414 self.apState = content.strip().split('Access Point: ')[1]
1415 callback(self.apState)
1417 callback(self.apState)
1419 class Wlanstatus(Screen):
1421 <screen position="center,center" size="510,400" title="Wireless Network Status..." >
1422 <widget source="status" render="Label" position="5,15" size="500,350" font="Regular;18" zPosition="1" />
1424 <ePixmap pixmap="skin_default/buttons/red.png" position="185,360" size="140,40" alphatest="on" />
1425 <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" />
1428 def __init__(self, session,iface):
1429 Screen.__init__(self,session)
1430 self.session = session
1432 self["status"] = StaticText(_("Wait a moment..."))
1433 self["key_red"] = StaticText(_("Close"))
1434 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
1437 "cancel": self.close,
1441 self.onClose.append(self.cleanup)
1443 def readstatus(self):
1444 self.wlanstatus = Console()
1445 cmd1 = "iwconfig "+self.iface
1446 self.wlanstatus.ePopen(cmd1, self.iwconfigfinnished,self.statusdisplay)
1448 def iwconfigfinnished(self, result, retval,extra_args):
1450 (statecallback) = extra_args
1451 if self.wlanstatus is not None:
1453 statecallback(result)
1460 def statusdisplay(self,data):
1462 self["status"].setText(_("No information..."))
1464 self["status"].setText(data)
1470 self.stopWlanStatusConsole()
1472 def stopWlanStatusConsole(self):
1473 if self.wlanstatus is not None:
1474 if len(self.wlanstatus.appContainers):
1475 for name in self.wlanstatus.appContainers.keys():
1476 self.wlanstatus.kill(name)
1478 def openconfig(session, **kwargs):
1479 session.open(WlanSelection)
1481 def selSetup(menuid, **kwargs):
1483 if menuid != "system":
1486 for x in iNetwork.getInstalledAdapters():
1487 if x.startswith('eth'):
1491 return [(_("Wireless LAN Setup"), openconfig, "wlansetup_config", 80)]
1496 def Plugins(**kwargs):
1497 return PluginDescriptor(name=_("Wireless LAN Setup"), description="Wireless LAN Setup", where = PluginDescriptor.WHERE_MENU, fnc=selSetup)