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
31 class WlanSelection(Screen,HelpableScreen):
33 <screen position="center,center" size="510,400" title="Wireless Network Adapter Selection..." >
34 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
35 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
37 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
38 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
40 <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" />
41 <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" />
43 <widget name="menulist" position="20,20" size="230,260" transparent="1" backgroundColor="#371e1c1a" zPosition="10" scrollbarMode="showOnDemand" />
44 <widget source="description" render="Label" position="305,10" size="195,300" font="Regular;19" halign="center" valign="center" />
47 def __init__(self, session):
48 Screen.__init__(self,session)
49 HelpableScreen.__init__(self)
50 self.mainmenu = self.getWlandevice()
51 self["menulist"] = MenuList(self.mainmenu)
52 self["key_red"] = StaticText(_("Close"))
53 self["key_green"] = StaticText(_("Select"))
54 self["description"] = StaticText()
55 self["description"].setText(_("Select Wireless Lan module. \n" ))
56 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
58 "ok": (self.ok, _("select interface")),
59 "cancel": (self.close, _("exit network interface list")),
62 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
64 "green": (self.ok, _("select interface")),
65 "red": (self.close, _("exit network interface list")),
67 self.updateInterfaces()
68 self.onClose.append(self.cleanup)
70 def updateInterfaces(self):
71 iNetwork.config_ready = False
73 iNetwork.getInterfaces()
76 # print len(self["menulist"].list)
77 if len(self["menulist"].list) == 0:
78 self.session.open(MessageBox, (_("Can not find any WirelessLan Module\n")),MessageBox.TYPE_ERROR,5 )
80 ifaces=self["menulist"].getCurrent()[1]
84 self.session.open(WlanSetup,ifaces)
86 def getWlandevice(self):
88 for x in iNetwork.getInstalledAdapters():
89 if x.startswith('eth'):
91 description=self.getAdapterDescription(x)
92 if description == "Unknown network adapter":
93 list.append((description,x))
95 list.append((description + " (%s)"%x,x))
98 def getAdapterDescription(self, iface):
99 classdir = "/sys/class/net/" + iface + "/device/"
100 driverdir = "/sys/class/net/" + iface + "/device/driver/"
101 if os_path.exists(classdir):
102 files = listdir(classdir)
103 if 'driver' in files:
104 if os_path.realpath(driverdir).endswith('rtw_usb_drv'):
105 return _("Realtek")+ " " + _("WLAN adapter.")
106 elif os_path.realpath(driverdir).endswith('ath_pci'):
107 return _("Atheros")+ " " + _("WLAN adapter.")
108 elif os_path.realpath(driverdir).endswith('zd1211b'):
109 return _("Zydas")+ " " + _("WLAN adapter.")
110 elif os_path.realpath(driverdir).endswith('rt73'):
111 return _("Ralink")+ " " + _("WLAN adapter.")
112 elif os_path.realpath(driverdir).endswith('rt73usb'):
113 return _("Ralink")+ " " + _("WLAN adapter.")
115 return str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter")
117 return _("Unknown network adapter")
119 return _("Unknown network adapter")
122 iNetwork.stopGetInterfacesConsole()
124 class WlanSetup(Screen,HelpableScreen):
126 <screen position="center,center" size="510,400" title="Wireless Network Setup Menu..." >
127 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
128 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
130 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
131 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
133 <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" />
134 <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" />
136 <widget name="menulist" position="20,20" size="230,260" transparent="1" backgroundColor="#371e1c1a" zPosition="10" scrollbarMode="showOnDemand" />
137 <widget source="description" render="Label" position="305,10" size="195,300" font="Regular;19" halign="center" valign="center" />
140 def __init__(self, session, ifaces):
141 Screen.__init__(self, session)
142 HelpableScreen.__init__(self)
143 self.session = session
145 self.restartLanRef = None
146 self.LinkState = None
147 self.mainmenu = self.MakeMenu()
148 self["menulist"] = MenuList(self.mainmenu)
149 self["key_red"] = StaticText(_("Close"))
150 self["key_green"] = StaticText(_("Select"))
151 self["description"] = StaticText()
152 self["IFtext"] = StaticText()
153 self["IF"] = StaticText()
154 self["Statustext"] = StaticText()
155 self["statuspic"] = MultiPixmap()
156 self["statuspic"].hide()
157 self.onLayoutFinish.append(self.loadDescription)
159 self.oktext = _("Press OK on your remote control to continue.")
161 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
163 "up": (self.up, _("move up to previous entry")),
164 "down": (self.down, _("move down to next entry")),
165 "left": (self.left, _("move up to first entry")),
166 "right": (self.right, _("move down to last entry")),
169 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
171 "cancel": (self.close, _("exit networkadapter setup menu")),
172 "ok": (self.ok, _("select menu entry")),
175 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
177 "red": (self.close, _("exit networkadapter setup menu")),
178 "green": (self.ok, _("select menu entry")),
181 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
191 self.onClose.append(self.cleanup)
193 def loadDescription(self):
194 if self["menulist"].getCurrent()[1] == 'setting':
195 self["description"].setText(_("Edit the network configuration of your STB.\n" ) + self.oktext )
196 if self["menulist"].getCurrent()[1] == 'scanap':
197 self["description"].setText(_("Scan your network for wireless access points and connect to them using your selected wireless device.\n" ) + self.oktext )
198 if self["menulist"].getCurrent()[1] == 'dns':
199 self["description"].setText(_("Edit the Nameserver configuration of your STB.\n" ) + self.oktext )
200 if self["menulist"].getCurrent()[1] == 'status':
201 self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
202 if self["menulist"].getCurrent()[1] == 'test':
203 self["description"].setText(_("Test the network configuration of your STB.\n" ) + self.oktext )
204 if self["menulist"].getCurrent()[1] == 'restart':
205 self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
208 self["menulist"].up()
209 self.loadDescription()
212 self["menulist"].down()
213 self.loadDescription()
216 self["menulist"].pageUp()
217 self.loadDescription()
220 self["menulist"].pageDown()
221 self.loadDescription()
225 if self["menulist"].getCurrent()[1] == 'setting':
226 self.session.openWithCallback(self.checklist, WlanConfig, self.iface)
227 elif self["menulist"].getCurrent()[1] == 'scanap':
228 self.session.open(WlanScanAp, self.iface)
229 elif self["menulist"].getCurrent()[1] == 'dns':
230 self.session.open(NameserverSetup)
231 elif self["menulist"].getCurrent()[1] == 'status':
232 self.session.open(Wlanstatus, self.iface)
233 elif self["menulist"].getCurrent()[1] == 'test':
234 self.session.openWithCallback(self.checklist,NetworkAdapterTest,self.iface)
235 elif self["menulist"].getCurrent()[1] == 'restart':
236 self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
239 self["menulist"].setList(self.MakeMenu())
243 menu.append((_("Adapter settings"), "setting"))
244 menu.append((_("Scan Wireless AP"), "scanap"))
245 menu.append((_("Nameserver settings"), "dns"))
246 if iNetwork.getAdapterAttribute(self.iface, "up"):
247 menu.append((_("Show WLAN Status"), "status"))
248 menu.append((_("Network test"), "test"))
249 menu.append((_("Restart network"), "restart"))
253 def restartLan(self, ret = False):
255 iNetwork.restartNetwork(self.restartLanDataAvail)
256 self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while your network is restarting..."), type = MessageBox.TYPE_INFO, enable_input = False)
258 def restartLanDataAvail(self, data):
260 iNetwork.getInterfaces(self.getInterfacesDataAvail)
262 def getInterfacesDataAvail(self, data):
264 self.restartLanRef.close(True)
266 def restartfinishedCB(self,data):
268 self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 5, default = False)
271 iNetwork.stopRestartConsole()
272 iNetwork.stopGetInterfacesConsole()
274 wlanconfig = ConfigSubsection()
275 wlanconfig.usedevice = ConfigSelection(default = "off", choices = [
276 ("off", _("off")), ("on", _("on"))])
277 wlanconfig.usedhcp = ConfigSelection(default = "off", choices = [
278 ("off", _("no")), ("on", _("yes"))])
279 wlanconfig.essid = ConfigSelection(default = "none", choices = ["none"])
280 wlanconfig.encrypt = ConfigSelection(default = "off", choices = [
281 ("off", _("no")), ("on", _("yes"))])
282 wlanconfig.method = ConfigSelection(default = "wep", choices = [
283 ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
284 wlanconfig.keytype = ConfigSelection(default = "ascii", choices = [
285 ("ascii", _("ASCII")), ("hex", _("HEX"))])
286 wlanconfig.key = ConfigPassword(default = "XXXXXXXX", visible_width = 50, fixed_size = False)
287 wlanconfig.usegateway = ConfigSelection(default = "off", choices = [
288 ("off", _("no")), ("on", _("yes"))])
289 wlanconfig.ip = ConfigIP([0,0,0,0])
290 wlanconfig.netmask = ConfigIP([0,0,0,0])
291 wlanconfig.gateway = ConfigIP([0,0,0,0])
294 class WlanConfig(Screen, ConfigListScreen, HelpableScreen):
296 <screen position="center,center" size="510,400" title="Wireless Network Configuration..." >
297 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
298 <ePixmap pixmap="skin_default/buttons/green.png" position="360,360" size="140,40" alphatest="on" />
300 <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" />
301 <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" />
303 <widget name="config" position="10,10" backgroundColor="#371e1c1a" transparent="1" size="480,210" scrollbarMode="showOnDemand" />
304 <ePixmap pixmap="skin_default/div-h.png" position="0,225" zPosition="1" size="550,2" />
305 <eLabel text="IP Address : " position="100,250" size="190,21" font="Regular;19" />
306 <widget source="ipaddress" render="Label" position="300,250" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" />
307 <eLabel text="NetMask : " position="100,275" size="190,21" font="Regular;19" />
308 <widget source="netmask" render="Label" position="300,275" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" />
309 <eLabel text="Gateway : " position="100,300" size="190,21" font="Regular;19" />
310 <widget source="gateway" render="Label" position="300,300" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" />
313 def __init__(self, session, iface):
314 Screen.__init__(self,session)
315 self.session = session
316 self["key_red"] = StaticText(_("Close"))
317 self["key_green"] = StaticText(_("Ok"))
318 self["ipaddress"] = StaticText(_("[ N/A ]"))
319 self["netmask"] = StaticText(_("[ N/A ]"))
320 self["gateway"] = StaticText(_("[ N/A ]"))
321 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
323 "ok": self.saveWlanConfig,
324 "green": self.saveWlanConfig,
325 "cancel": self.keyCancel,
326 "red": self.keyCancel,
331 self.scan_ssid = None
335 self.encryption_key = None
336 self.wlanscanap = None
337 self.wpaphraseconsole = None
338 # self.scanAPcount =5
341 ConfigListScreen.__init__(self, self.list,session = self.session)
342 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
343 self.readWpaSupplicantConf()
344 self.scanAPFailedTimer = eTimer()
345 self.scanAPFailedTimer.callback.append(self.scanAPFailed)
346 self.scanAplistTimer = eTimer()
347 self.scanAplistTimer.callback.append(self.scanApList)
348 self.Console = Console()
349 # self.scanAplistTimer.start(100,True)
350 self.updateInterfaces(self.readWlanSettings)
351 self.onClose.append(self.cleanup)
353 def updateInterfaces(self,callback = None):
354 iNetwork.config_ready = False
355 iNetwork.msgPlugins()
356 iNetwork.getInterfaces(callback)
358 def readWlanSettings(self,ret=None):
360 print "getInterfaces Fail... "
361 if iNetwork.getAdapterAttribute(self.iface, "up") == True:
365 wlanconfig.usedevice = ConfigSelection(default=default_tmp, choices = [("off", _("off")), ("on", _("on"))])
367 if iNetwork.getAdapterAttribute(self.iface, "dhcp"):
371 wlanconfig.usedhcp = ConfigSelection(default=default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
373 wlanconfig.ip = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0]
375 wlanconfig.netmask = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0])
376 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
380 wlanconfig.usegateway = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
382 wlanconfig.gateway = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0])
384 self["ipaddress"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "ip"))))
385 self["netmask"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "netmask"))))
386 self["gateway"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "gateway"))))
388 if self.encryption_key is not None:
392 wlanconfig.encrypt = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
394 if self.key_mgmt=="NONE":
396 elif self.key_mgmt == "WPA-PSK":
397 if self.proto == "WPA":
399 elif self.proto == "RSN":
401 elif self.proto in ( "WPA RSN", "WPA WPA2"):
402 default_tmp = "wpa/wpa2"
408 wlanconfig.method = ConfigSelection(default = default_tmp, choices = [
409 ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
411 if self.key_type == 0:
414 default_tmp = "ascii"
415 wlanconfig.keytype = ConfigSelection(default = default_tmp, choices = [
416 ("ascii", _("ASCII")), ("hex", _("HEX"))])
417 default_tmp = self.encryption_key or "XXXXXXXX"
418 # default_tmp = "XXXXXXXX"
419 wlanconfig.key = ConfigPassword(default = default_tmp, visible_width = 50, fixed_size = False)
420 self.scanAplistTimer.start(100,True)
422 def readWpaSupplicantConf(self):
424 if fileExists("/etc/wpa_supplicant.conf"):
425 wpafd = open("/etc/wpa_supplicant.conf","r")
427 data = wpafd.readline()
429 # print "####readWpaSupplicantConf, data : ",data
432 data = wpafd.readline()
434 if data.startswith('ssid=') and len(data) > 6:
435 self.ssid = data[6:-2]
436 elif data.startswith('ap_scan=') :
437 self.ap_scan = data[8:]
438 # print "####readWpaSupplicantConf, ap_scan : ",self.ap_scan
439 elif data.startswith('scan_ssid=') and len(data) > 10:
440 self.scan_ssid = data[10:-1]
441 elif data.startswith('key_mgmt=') and len(data) > 9:
442 self.key_mgmt = data[9:-1]
443 elif data.startswith('proto=') and len(data) > 6:
444 self.proto = data[6:-1]
445 elif data.startswith('wep_key0="') and len(data) > 11:
446 self.key_type = 1 # ascii
447 self.encryption_key = data[10:-2]
448 elif data.startswith('wep_key0=') and len(data) > 9:
449 self.key_type = 0 # hex
450 self.encryption_key = data[9:-1]
451 elif data.startswith('psk="') and len(data) > 6:
452 self.key_type = 1 # ascii
453 self.encryption_key = data[5:-2]
454 elif data.startswith('#psk="') and len(data) > 6:
455 self.key_type = 0 # hex
456 self.encryption_key = data[6:-2]
457 elif not self.encryption_key and data.startswith('psk=') and len(data) > 4:
458 self.key_type = 0 # hex
459 self.encryption_key = data[4:-1]
460 data = wpafd.readline()
461 print self.ssid,self.scan_ssid,self.key_mgmt,self.proto,self.key_type,self.encryption_key
468 print 'failed loading wpasupplicant.conf'
470 def createConfig(self):
472 self.usedeviceEntry = getConfigListEntry(_("Use Device"), wlanconfig.usedevice)
473 self.usedhcpEntry = getConfigListEntry(_("Use DHCP"), wlanconfig.usedhcp)
474 self.essidEntry = getConfigListEntry(_("ESSID"), wlanconfig.essid)
475 self.hiddenessidEntry = getConfigListEntry(_("Input Hidden ESSID"), wlanconfig.hiddenessid)
476 self.encryptEntry = getConfigListEntry(_("Encrypt"), wlanconfig.encrypt)
477 self.methodEntry = getConfigListEntry(_("Method"), wlanconfig.method)
478 self.keytypeEntry = getConfigListEntry(_("Key Type"), wlanconfig.keytype)
479 self.keyEntry = getConfigListEntry(_("KEY"), wlanconfig.key)
481 self.ipEntry = getConfigListEntry(_("IP"), wlanconfig.ip)
482 self.netmaskEntry = getConfigListEntry(_("NetMask"), wlanconfig.netmask)
484 self.usegatewayEntry = getConfigListEntry(_("Use Gateway"), wlanconfig.usegateway)
485 self.gatewayEntry = getConfigListEntry(_("Gateway"), wlanconfig.gateway)
487 self.configList.append( self.usedeviceEntry )
488 if wlanconfig.usedevice.value is "on":
489 self.configList.append( self.usedhcpEntry )
490 if wlanconfig.usedhcp.value is "off":
491 self.configList.append(self.ipEntry)
492 self.configList.append(self.netmaskEntry)
493 self.configList.append(self.usegatewayEntry)
494 if wlanconfig.usegateway.value is "on":
495 self.configList.append(self.gatewayEntry)
496 self.configList.append( self.essidEntry )
497 # print "#### wlanconfig.essid.value : ",wlanconfig.essid.value
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)
509 # if not self.selectionChanged in self["config"].onSelectionChanged:
510 # self["config"].onSelectionChanged.append(self.selectionChanged)
512 def scanApList(self):
514 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
515 cmd = "ifconfig "+self.iface+" up"
518 self.wlanscanap = Console()
519 cmd = "iwlist "+self.iface+" scan"
521 self.wlanscanap.ePopen(cmd, self.apListFinnished,self.apListParse)
523 def apListFinnished(self, result, retval,extra_args):
524 (callback) = extra_args
525 if self.wlanscanap is not None:
527 self.wlanscanap = None
528 content = result.splitlines()
529 first = content[0].split()
534 if completed == True:
541 def apListParse(self,data):
544 if self.scanAPcount >0:
546 self.configurationmsg.close(True)
548 self.scanAplistTimer.start(500,True)
551 self.configurationmsg.close(True)
552 self.scanAPFailedTimer.start(500,True)
556 # self.scanAPcount =5
558 list = data.splitlines()
561 if xx.startswith('ESSID:') and len(xx)>8 and xx[7:-1]not in self.apList:
562 self.apList.append(xx[7:-1])
563 self.apList.append('Input hidden ESSID')
564 # print "###### selectap : ",selectap
565 if selectap is not None and selectap in self.apList:
566 wlanconfig.essid = ConfigSelection(default=selectap,choices = self.apList)
567 elif self.ap_scan is not None and self.ap_scan.strip() == '2':
568 wlanconfig.essid = ConfigSelection(default='Input hidden ESSID',choices = self.apList)
569 elif self.ssid is not None and self.ssid in self.apList:
570 wlanconfig.essid = ConfigSelection(default=self.ssid,choices = self.apList)
572 wlanconfig.essid = ConfigSelection(choices = self.apList)
573 if self.ssid is not None:
574 wlanconfig.hiddenessid = ConfigText(default = self.ssid, visible_width = 50, fixed_size = False)
576 wlanconfig.hiddenessid = ConfigText(default = "<Input ESSID>", visible_width = 50, fixed_size = False)
577 self.configurationmsg.close(True)
580 def scanAPFailed(self):
581 self.session.openWithCallback(self.keyCancel ,MessageBox, _("Scan AP Failed"), MessageBox.TYPE_ERROR,10)
584 ConfigListScreen.keyLeft(self)
588 ConfigListScreen.keyRight(self)
592 if self["config"].getCurrent() == self.usedeviceEntry or self["config"].getCurrent() == self.encryptEntry \
593 or self["config"].getCurrent() == self.usedhcpEntry or self["config"].getCurrent() == self.usegatewayEntry \
594 or self["config"].getCurrent() == self.essidEntry or self["config"].getCurrent() == self.methodEntry:
597 def saveWlanConfig(self):
599 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
600 self["config"].getCurrent()[1].onDeselect(self.session)
601 if self["config"].isChanged():
602 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Are you sure you want to restart your network interfaces?\n") ) )
604 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Network configuration is not changed....\n\nAre you sure you want to restart your network interfaces?\n") ) )
608 def checkNetworkConfig(self, ret = False):
610 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
611 self["config"].getCurrent()[1].onSelect(self.session)
613 if wlanconfig.essid.value == 'Input hidden ESSID':
614 if len(wlanconfig.hiddenessid.value) == 0:
615 self.session.open(MessageBox, ("PLEASE INPUT HIDDEN ESSID"), type = MessageBox.TYPE_ERROR, timeout = 10)
617 if len(wlanconfig.key.value) == 0:
618 self.session.open(MessageBox, ("PLEASE INPUT NETWORK KEY"), type = MessageBox.TYPE_ERROR, timeout = 10)
620 self.checkNetworkShares()
622 # def checkNetworkShares(self,ret = False):
624 # if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
625 # self["config"].getCurrent()[1].onSelect(self.session)
627 def checkNetworkShares(self):
629 self.Console = Console()
630 cmd = "cat /proc/mounts"
631 self.Console.ePopen(cmd, self.checkSharesFinished, self.confirmAnotherIfaces)
633 def checkSharesFinished(self, result, retval, extra_args):
634 callback = extra_args
635 print "checkMountsFinished : result : \n",result
636 networks = ['nfs','smbfs','ncp','coda']
637 for line in result.splitlines():
638 split = line.strip().split(' ',3)
639 if split[2] in networks:
640 self.session.open(MessageBox, ("NOT deconfiguring network interfaces :\n network shares still mounted\n"), type = MessageBox.TYPE_ERROR, timeout = 10)
642 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
643 self["config"].getCurrent()[1].onSelect(self.session)
647 def confirmAnotherIfaces(self, ret = False):
651 num_configured_if = len(iNetwork.getConfiguredAdapters())
652 if num_configured_if >= 1:
653 if num_configured_if == 1 and self.iface in iNetwork.getConfiguredAdapters():
654 self.getWpaPhrase(False)
656 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)
658 self.getWpaPhrase(False)
660 def getWpaPhrase(self,ret):
662 configuredInterfaces = iNetwork.getConfiguredAdapters()
663 for interface in configuredInterfaces:
664 if interface == self.iface:
666 iNetwork.setAdapterAttribute(interface, "up", False)
667 iNetwork.deactivateInterface(interface)
668 if wlanconfig.method.value =="wep":
669 self.writeWpasupplicantConf("wep") # passphrasekey is not None
671 if wlanconfig.essid.value == 'Input hidden ESSID':
672 cmd = "wpa_passphrase '%s' %s" % (wlanconfig.hiddenessid.value,wlanconfig.key.value)
674 cmd = "wpa_passphrase '%s' %s" % (wlanconfig.essid.value,wlanconfig.key.value)
676 self.wpaphraseconsole = Console()
677 self.wpaphraseconsole.ePopen(cmd, self.parseWpaPhrase, self.writeWpasupplicantConf)
679 def parseWpaPhrase(self, result, retval, extra_args):
680 print "parseWpaPhrase"
681 (writewlanconfig) = extra_args
682 if self.wpaphraseconsole is not None:
683 print "retval = ",retval
685 self.wpaphraseconsole.killAll()
686 self.wpaphraseconsole = None
687 print "parseWpaPhrase result : "
690 for line in result.splitlines():
691 if line.find('ssid') == -1 and line.find('#psk=') != -1:
693 elif line.find('psk=') != -1:
696 writewlanconfig(psk,plainpwd)
697 # writewlanconfig(None)
699 writewlanconfig(None)
701 writewlanconfig(None)
703 def writeWpasupplicantConf(self, passphrasekey=None,plainpwd=None):
705 wpafd = open("/etc/wpa_supplicant.conf","w")
707 contents = "#WPA Supplicant Configuration by STB\n"
708 contents += "ctrl_interface=/var/run/wpa_supplicant\n"
709 contents += "eapol_version=1\n"
710 contents += "fast_reauth=1\n"
712 if wlanconfig.essid.value == 'Input hidden ESSID':
713 contents += "ap_scan=2\n"
715 contents += "ap_scan=1\n"
716 contents += "network={\n"
717 if wlanconfig.essid.value == 'Input hidden ESSID':
718 contents += "\tssid=\""+wlanconfig.hiddenessid.value+"\"\n"
720 contents += "\tssid=\""+wlanconfig.essid.value+"\"\n"
721 contents += "\tscan_ssid=0\n"
722 if wlanconfig.encrypt.value == "on":
723 if wlanconfig.method.value =="wep":
724 contents += "\tkey_mgmt=NONE\n"
725 contents += "\twep_key0="
726 if wlanconfig.keytype.value == "ascii":
727 contents += "\""+wlanconfig.key.value+"\"\n"
729 contents += wlanconfig.key.value+"\n"
731 print "plainpwd : ",plainpwd
732 print "passphrasekey : ",passphrasekey
733 if wlanconfig.method.value == "wpa":
734 contents += "\tkey_mgmt=WPA-PSK\n"
735 contents += "\tproto=WPA\n"
736 contents += "\tpairwise=CCMP TKIP\n"
737 contents += "\tgroup=CCMP TKIP\n"
738 elif wlanconfig.method.value == "wpa2":
739 contents += "\tkey_mgmt=WPA-PSK\n"
740 contents += "\tproto=RSN\n"
741 contents += "\tpairwise=CCMP TKIP\n"
742 contents += "\tgroup=CCMP TKIP\n"
744 contents += "\tkey_mgmt=WPA-PSK\n"
745 contents += "\tproto=WPA RSN\n"
746 contents += "\tpairwise=CCMP TKIP\n"
747 contents += "\tgroup=CCMP TKIP\n"
748 contents += plainpwd+"\n"
749 contents += passphrasekey+"\n"
751 contents += "\tkey_mgmt=NONE\n"
753 print "content = \n"+contents
754 wpafd.write(contents)
756 self.writeNetConfig(0)
758 self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
759 self.writeNetConfig(-1)
761 self.writeNetConfig(-2)
763 def writeNetConfig(self,ret = -1):
765 self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
768 self.session.open(MessageBox, _("Can NOT generate passphrase"), type = MessageBox.TYPE_ERROR, timeout = 10)
771 if wlanconfig.usedevice.value=="on":
772 iNetwork.setAdapterAttribute(self.iface, "up", True)
773 if wlanconfig.usedhcp.value =="on":
774 iNetwork.setAdapterAttribute(self.iface, "dhcp", True)
776 iNetwork.setAdapterAttribute(self.iface, "dhcp", False)
777 iNetwork.setAdapterAttribute(self.iface, "ip", wlanconfig.ip.value)
778 iNetwork.setAdapterAttribute(self.iface, "netmask", wlanconfig.netmask.value)
779 if wlanconfig.usegateway.value == "on":
780 iNetwork.setAdapterAttribute(self.iface, "gateway", wlanconfig.gateway.value)
782 iNetwork.setAdapterAttribute(self.iface, "up", False)
783 iNetwork.deactivateInterface(self.iface)
784 contents = "\tpre-up wpa_supplicant -i"+self.iface+" -c/etc/wpa_supplicant.conf -B -D"+iNetwork.detectWlanModule(self.iface)+"\n"
785 contents += "\tpost-down wpa_cli terminate\n\n"
786 iNetwork.setAdapterAttribute(self.iface, "configStrings", contents)
787 iNetwork.writeNetworkConfig()
788 iNetwork.restartNetwork(self.updateCurrentInterfaces)
789 self.configurationmsg = None
790 self.configurationmsg = self.session.openWithCallback(self.configFinished, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
793 def updateCurrentInterfaces(self,ret):
795 iNetwork.getInterfaces(self.configurationMsgClose)
797 def configurationMsgClose(self,ret):
798 if ret is True and self.configurationmsg is not None:
799 self.configurationmsg.close(True)
801 def configFinished(self,data):
804 self.session.openWithCallback(self.configFinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
805 selectap = wlanconfig.essid.value
807 def configFinishedCB(self,data):
812 def formatip(self, iplist):
815 # print "iplist : ",iplist
818 result = str(iplist[0])+"."+str(iplist[1])+"."+str(iplist[2])+"."+str(iplist[3])
821 # print "result : ",result
826 def keyCancelConfirm(self, result):
829 if self.oldInterfaceState is False:
830 iNetwork.setAdapterAttribute(self.iface, "up", False)
831 iNetwork.deactivateInterface(self.iface,self.keyCancelCB)
835 def keyCancel(self,yesno = True):
836 if self["config"].isChanged():
837 self.session.openWithCallback(self.keyCancelConfirm, MessageBox, _("Really close without saving settings?"))
839 self.keyCancelConfirm(True)
841 def keyCancelCB(self,data):
847 iNetwork.stopRestartConsole()
848 iNetwork.stopGetInterfacesConsole()
849 iNetwork.stopDeactivateInterfaceConsole()
850 self.stopwlanscanapConsole()
851 self.stopCheckNetworkSharesConsole()
852 self.stopWpaPhraseConsole()
854 def stopwlanscanapConsole(self):
855 if self.wlanscanap is not None:
856 if len(self.wlanscanap.appContainers):
857 for name in self.wlanscanap.appContainers.keys():
858 self.wlanscanap.kill(name)
860 def stopCheckNetworkSharesConsole(self):
861 if self.Console is not None:
862 if len(self.Console.appContainers):
863 for name in self.Console.appContainers.keys():
864 self.Console.kill(name)
866 def stopWpaPhraseConsole(self):
867 if self.wpaphraseconsole is not None:
868 if len(self.wpaphraseconsole.appContainers):
869 for name in self.wpaphraseconsole.appContainers.keys():
870 self.wpaphraseconsole.kill(name)
872 class WlanScanAp(Screen,HelpableScreen):
874 <screen position="center,center" size="510,400" title="Wireless Network AP Scan..." >
875 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
876 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
878 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
879 <ePixmap pixmap="skin_default/buttons/green.png" position="185,360" size="140,40" alphatest="on" />
880 <ePixmap pixmap="skin_default/buttons/blue.png" position="360,360" size="140,40" alphatest="on" />
882 <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" />
883 <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" />
884 <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" />
886 <widget name="menulist" position="20,20" size="230,260" backgroundColor="#371e1c1a" transparent="1" zPosition="10" scrollbarMode="showOnDemand" />
888 <widget source="Address" render="Label" position="265,70" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
889 <widget source="ESSID" render="Label" position="265,100" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
890 <widget source="Protocol" render="Label" position="265,130" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
891 <widget source="Frequency" render="Label" position="265,160" zPosition="1" size="240,40" font="Regular;18" halign="center" valign="center" />
892 <widget source="Encryption key" render="Label" position="265,200" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
893 <widget source="BitRate" render="Label" position="265,220" zPosition="1" size="240,60" font="Regular;18" halign="center" valign="center" />
896 def __init__(self, session, iface):
897 Screen.__init__(self,session)
898 HelpableScreen.__init__(self)
899 self.session = session
901 self.wlanscanap = None
902 # self.scanAPcount = 5
907 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
909 "up": (self.up, _("move up to previous entry")),
910 "down": (self.down, _("move down to next entry")),
911 "left": (self.left, _("move up to first entry")),
912 "right": (self.right, _("move down to last entry")),
915 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
917 "cancel": (self.close, _("exit")),
918 "ok": (self.ok, "select AP"),
921 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
923 "red": (self.close, _("exit")),
924 "green": (self.ok, "select AP"),
925 "blue": (self.startWlanConfig, "Edit Wireless settings"),
928 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
939 self["menulist"] = MenuList(self.SetApList)
940 self["key_red"] = StaticText(_("Close"))
941 self["key_green"] = StaticText(_("Select"))
942 self["key_blue"] = StaticText(_("EditSetting"))
943 self["Address"] = StaticText(_("Scanning AP List.."))
944 self["ESSID"] = StaticText(_("Wait a moment"))
945 self["Protocol"] = StaticText(" ")
946 self["Frequency"] = StaticText(" ")
947 self["Encryption key"] = StaticText(" ")
948 self["BitRate"] = StaticText(" ")
949 self.scanAPFailedTimer = eTimer()
950 self.scanAPFailedTimer.callback.append(self.scanAPFailed)
951 self.scanAplistTimer = eTimer()
952 self.scanAplistTimer.callback.append(self.scanApList)
953 self.scanAplistTimer.start(100,True)
954 self.onClose.append(self.cleanup)
957 self["menulist"].pageUp()
961 self["menulist"].pageDown()
965 self["menulist"].up()
969 self["menulist"].down()
974 selectAp=self["menulist"].getCurrent()[0]
978 def startWlanConfig(self):
980 selectAp=self["menulist"].getCurrent()[0]
983 self.session.open(WlanConfig,self.iface)
986 def scanApList(self):
987 # print "self.scanAPcount : ",self.scanAPcount
990 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
991 os_system('ifconfig '+self.iface+" up")
992 self.wlanscanap = Console()
993 cmd = "iwlist "+self.iface+" scan"
995 self.wlanscanap.ePopen(cmd, self.iwlistfinnished,self.APListParse)
997 def iwlistfinnished(self, result, retval,extra_args):
998 # print "iwlistfinnished"
999 (statecallback) = extra_args
1000 if self.wlanscanap is not None:
1001 # print "retval = ",retval
1003 self.wlanscanap = None
1004 content = result.splitlines()
1005 first = content[0].split()
1008 if x == 'completed':
1010 if completed == True:
1011 statecallback(result)
1017 def APListParse(self,data):
1019 if self.scanAPcount >0:
1020 self.scanAPcount -=1
1021 self.configurationmsg.close(True)
1023 self.scanAplistTimer.start(500,True)
1026 self.configurationmsg.close(True)
1027 self.scanAPFailedTimer.start(500,True)
1032 # self.scanAPcount =5
1034 list = data.splitlines()
1036 # print "line : ",line
1037 if line.strip().startswith("Cell"): # Cell 01 - Address: 00:26:66:5C:EF:24
1038 parts = line.strip().split(" ")
1039 current_ap_id = int(parts[1])
1040 self.apList[current_ap_id]={}
1041 self.apList[current_ap_id]["Address"]=parts[4]
1042 elif line.strip().startswith("ESSID"):
1043 self.apList[current_ap_id]["ESSID"]=line.strip()[6:].strip('"')
1044 self.SetApList.append( (self.apList[current_ap_id]["ESSID"],current_ap_id) )
1045 elif line.strip().startswith("Protocol"):
1046 self.apList[current_ap_id]["Protocol"]=line.strip()[9:]
1047 elif line.strip().startswith("Frequency"):
1048 self.apList[current_ap_id]["Frequency"]=line.strip()[10:]
1049 elif line.strip().startswith("Encryption key"):
1050 self.apList[current_ap_id]["Encryption key"]=line.strip()[15:]
1051 elif line.strip().startswith("Bit Rates"):
1052 self.apList[current_ap_id]["BitRate"]=line.strip()[10:]
1054 print len(self.apList)
1055 self.configurationmsg.close(True)
1056 self.displayApInfo()
1058 def scanAPFailed(self):
1059 self.session.openWithCallback(self.ScanAPclose,MessageBox, _("Scan AP Failed"), MessageBox.TYPE_ERROR,10)
1061 def displayApInfo(self):
1062 if len(self.apList) >0:
1063 self["menulist"].setList(self.SetApList)
1064 index = self["menulist"].getCurrent()[1]
1065 for key in ["Address", "ESSID", "Protocol", "Frequency", "Encryption key", "BitRate"]:
1066 if self.apList[index].has_key(key):
1067 self[key].setText((key+": "+self.apList[index][key]))
1069 self[key].setText((key+": None"))
1071 self.session.openWithCallback(self.ScanAPclose, MessageBox, _("No AP detected."), type = MessageBox.TYPE_INFO, timeout = 10)
1073 def ScanAPclose(self,data):
1077 self.stopwlanscanapConsole()
1079 def stopwlanscanapConsole(self):
1080 if self.wlanscanap is not None:
1081 if len(self.wlanscanap.appContainers):
1082 for name in self.wlanscanap.appContainers.keys():
1083 self.wlanscanap.kill(name)
1085 class NetworkAdapterTest(Screen):
1086 def __init__(self, session,iface):
1087 Screen.__init__(self, session)
1089 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
1091 self.onClose.append(self.cleanup)
1092 self.onHide.append(self.cleanup)
1094 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
1098 "up": lambda: self.updownhandler('up'),
1099 "down": lambda: self.updownhandler('down'),
1103 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1106 "back": self.cancel,
1108 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1110 "red": self.closeInfo,
1111 "back": self.closeInfo,
1113 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
1115 "green": self.KeyGreen,
1117 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
1119 "green": self.KeyGreenRestart,
1121 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
1123 "yellow": self.KeyYellow,
1126 self["shortcutsgreen_restart"].setEnabled(False)
1127 self["updown_actions"].setEnabled(False)
1128 self["infoshortcuts"].setEnabled(False)
1129 self.onClose.append(self.delTimer)
1130 self.onLayoutFinish.append(self.layoutFinished)
1131 self.steptimer = False
1133 self.activebutton = 0
1134 self.nextStepTimer = eTimer()
1135 self.nextStepTimer.callback.append(self.nextStepTimerFire)
1138 if self.oldInterfaceState is False:
1139 iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
1140 iNetwork.deactivateInterface(self.iface)
1143 def closeInfo(self):
1144 self["shortcuts"].setEnabled(True)
1145 self["infoshortcuts"].setEnabled(False)
1146 self["InfoText"].hide()
1147 self["InfoTextBorder"].hide()
1148 self["key_red"].setText(_("Close"))
1152 del self.nextStepTimer
1154 def nextStepTimerFire(self):
1155 self.nextStepTimer.stop()
1156 self.steptimer = False
1159 def updownhandler(self,direction):
1160 if direction == 'up':
1161 if self.activebutton >=2:
1162 self.activebutton -= 1
1164 self.activebutton = 6
1165 self.setActiveButton(self.activebutton)
1166 if direction == 'down':
1167 if self.activebutton <=5:
1168 self.activebutton += 1
1170 self.activebutton = 1
1171 self.setActiveButton(self.activebutton)
1173 def setActiveButton(self,button):
1175 self["EditSettingsButton"].setPixmapNum(0)
1176 self["EditSettings_Text"].setForegroundColorNum(0)
1177 self["NetworkInfo"].setPixmapNum(0)
1178 self["NetworkInfo_Text"].setForegroundColorNum(1)
1179 self["AdapterInfo"].setPixmapNum(1) # active
1180 self["AdapterInfo_Text"].setForegroundColorNum(2) # active
1182 self["AdapterInfo_Text"].setForegroundColorNum(1)
1183 self["AdapterInfo"].setPixmapNum(0)
1184 self["DhcpInfo"].setPixmapNum(0)
1185 self["DhcpInfo_Text"].setForegroundColorNum(1)
1186 self["NetworkInfo"].setPixmapNum(1) # active
1187 self["NetworkInfo_Text"].setForegroundColorNum(2) # active
1189 self["NetworkInfo"].setPixmapNum(0)
1190 self["NetworkInfo_Text"].setForegroundColorNum(1)
1191 self["IPInfo"].setPixmapNum(0)
1192 self["IPInfo_Text"].setForegroundColorNum(1)
1193 self["DhcpInfo"].setPixmapNum(1) # active
1194 self["DhcpInfo_Text"].setForegroundColorNum(2) # active
1196 self["DhcpInfo"].setPixmapNum(0)
1197 self["DhcpInfo_Text"].setForegroundColorNum(1)
1198 self["DNSInfo"].setPixmapNum(0)
1199 self["DNSInfo_Text"].setForegroundColorNum(1)
1200 self["IPInfo"].setPixmapNum(1) # active
1201 self["IPInfo_Text"].setForegroundColorNum(2) # active
1203 self["IPInfo"].setPixmapNum(0)
1204 self["IPInfo_Text"].setForegroundColorNum(1)
1205 self["EditSettingsButton"].setPixmapNum(0)
1206 self["EditSettings_Text"].setForegroundColorNum(0)
1207 self["DNSInfo"].setPixmapNum(1) # active
1208 self["DNSInfo_Text"].setForegroundColorNum(2) # active
1210 self["DNSInfo"].setPixmapNum(0)
1211 self["DNSInfo_Text"].setForegroundColorNum(1)
1212 self["EditSettingsButton"].setPixmapNum(1) # active
1213 self["EditSettings_Text"].setForegroundColorNum(2) # active
1214 self["AdapterInfo"].setPixmapNum(0)
1215 self["AdapterInfo_Text"].setForegroundColorNum(1)
1218 next = self.nextstep
1234 self.steptimer = True
1235 self.nextStepTimer.start(3000)
1236 self["key_yellow"].setText(_("Stop test"))
1239 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
1240 self["Adapter"].setForegroundColorNum(2)
1241 self["Adaptertext"].setForegroundColorNum(1)
1242 self["AdapterInfo_Text"].setForegroundColorNum(1)
1243 self["AdapterInfo_OK"].show()
1244 self.steptimer = True
1245 self.nextStepTimer.start(3000)
1248 self["Networktext"].setForegroundColorNum(1)
1249 self["Network"].setText(_("Please wait..."))
1250 self.AccessPointInfo(self.iface)
1251 self["NetworkInfo_Text"].setForegroundColorNum(1)
1252 self.steptimer = True
1253 self.nextStepTimer.start(3000)
1256 self["Dhcptext"].setForegroundColorNum(1)
1257 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
1258 self["Dhcp"].setForegroundColorNum(2)
1259 self["Dhcp"].setText(_("enabled"))
1260 self["DhcpInfo_Check"].setPixmapNum(0)
1262 self["Dhcp"].setForegroundColorNum(1)
1263 self["Dhcp"].setText(_("disabled"))
1264 self["DhcpInfo_Check"].setPixmapNum(1)
1265 self["DhcpInfo_Check"].show()
1266 self["DhcpInfo_Text"].setForegroundColorNum(1)
1267 self.steptimer = True
1268 self.nextStepTimer.start(3000)
1271 self["IPtext"].setForegroundColorNum(1)
1272 self["IP"].setText(_("Please wait..."))
1273 iNetwork.checkNetworkState(self.NetworkStatedataAvail)
1276 self.steptimer = False
1277 self.nextStepTimer.stop()
1278 self["DNStext"].setForegroundColorNum(1)
1279 self["DNS"].setText(_("Please wait..."))
1280 iNetwork.checkDNSLookup(self.DNSLookupdataAvail)
1283 self["shortcutsgreen"].setEnabled(False)
1284 self["shortcutsyellow"].setEnabled(True)
1285 self["updown_actions"].setEnabled(False)
1286 self["key_yellow"].setText("")
1287 self["key_green"].setText("")
1288 self.steptimer = True
1289 self.nextStepTimer.start(1000)
1291 def KeyGreenRestart(self):
1293 self.layoutFinished()
1294 self["Adapter"].setText((""))
1295 self["Network"].setText((""))
1296 self["Dhcp"].setText((""))
1297 self["IP"].setText((""))
1298 self["DNS"].setText((""))
1299 self["AdapterInfo_Text"].setForegroundColorNum(0)
1300 self["NetworkInfo_Text"].setForegroundColorNum(0)
1301 self["DhcpInfo_Text"].setForegroundColorNum(0)
1302 self["IPInfo_Text"].setForegroundColorNum(0)
1303 self["DNSInfo_Text"].setForegroundColorNum(0)
1304 self["shortcutsgreen_restart"].setEnabled(False)
1305 self["shortcutsgreen"].setEnabled(False)
1306 self["shortcutsyellow"].setEnabled(True)
1307 self["updown_actions"].setEnabled(False)
1308 self["key_yellow"].setText("")
1309 self["key_green"].setText("")
1310 self.steptimer = True
1311 self.nextStepTimer.start(1000)
1314 self["infoshortcuts"].setEnabled(True)
1315 self["shortcuts"].setEnabled(False)
1316 if self.activebutton == 1: # Adapter Check
1317 self["InfoText"].setText(_("This test detects your configured Wireless LAN-Adapter."))
1318 self["InfoTextBorder"].show()
1319 self["InfoText"].show()
1320 self["key_red"].setText(_("Back"))
1321 if self.activebutton == 2: #LAN Check
1322 self["InfoText"].setText(_("This test checks whether a network cable is connected to your Wireless LAN-Adapter."))
1323 self["InfoTextBorder"].show()
1324 self["InfoText"].show()
1325 self["key_red"].setText(_("Back"))
1326 if self.activebutton == 3: #DHCP Check
1327 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."))
1328 self["InfoTextBorder"].show()
1329 self["InfoText"].show()
1330 self["key_red"].setText(_("Back"))
1331 if self.activebutton == 4: # IP Check
1332 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"))
1333 self["InfoTextBorder"].show()
1334 self["InfoText"].show()
1335 self["key_red"].setText(_("Back"))
1336 if self.activebutton == 5: # DNS Check
1337 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"))
1338 self["InfoTextBorder"].show()
1339 self["InfoText"].show()
1340 self["key_red"].setText(_("Back"))
1341 if self.activebutton == 6: # Edit Settings
1343 self.session.open(WlanConfig,self.iface)
1344 self["shortcuts"].setEnabled(True)
1345 self["infoshortcuts"].setEnabled(False)
1347 def KeyYellow(self):
1349 self["shortcutsgreen_restart"].setEnabled(True)
1350 self["shortcutsgreen"].setEnabled(False)
1351 self["shortcutsyellow"].setEnabled(False)
1352 self["key_green"].setText(_("Restart test"))
1353 self["key_yellow"].setText("")
1354 self.steptimer = False
1355 self.nextStepTimer.stop()
1357 def layoutFinished(self):
1358 self.setTitle(_("Network test: ") + iNetwork.getFriendlyAdapterName(self.iface) )
1359 self["shortcutsyellow"].setEnabled(False)
1360 self["AdapterInfo_OK"].hide()
1361 self["NetworkInfo_Check"].hide()
1362 self["DhcpInfo_Check"].hide()
1363 self["IPInfo_Check"].hide()
1364 self["DNSInfo_Check"].hide()
1365 self["EditSettings_Text"].hide()
1366 self["EditSettingsButton"].hide()
1367 self["InfoText"].hide()
1368 self["InfoTextBorder"].hide()
1369 self["key_yellow"].setText("")
1371 def setLabels(self):
1372 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1373 self["Adapter"] = MultiColorLabel()
1374 self["AdapterInfo"] = MultiPixmap()
1375 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1376 self["AdapterInfo_OK"] = Pixmap()
1378 if self.iface in iNetwork.wlan_interfaces:
1379 self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1381 self["Networktext"] = MultiColorLabel(_("Local Network"))
1383 self["Network"] = MultiColorLabel()
1384 self["NetworkInfo"] = MultiPixmap()
1385 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1386 self["NetworkInfo_Check"] = MultiPixmap()
1388 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1389 self["Dhcp"] = MultiColorLabel()
1390 self["DhcpInfo"] = MultiPixmap()
1391 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1392 self["DhcpInfo_Check"] = MultiPixmap()
1394 self["IPtext"] = MultiColorLabel(_("IP Address"))
1395 self["IP"] = MultiColorLabel()
1396 self["IPInfo"] = MultiPixmap()
1397 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1398 self["IPInfo_Check"] = MultiPixmap()
1400 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1401 self["DNS"] = MultiColorLabel()
1402 self["DNSInfo"] = MultiPixmap()
1403 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1404 self["DNSInfo_Check"] = MultiPixmap()
1406 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1407 self["EditSettingsButton"] = MultiPixmap()
1409 self["key_red"] = StaticText(_("Close"))
1410 self["key_green"] = StaticText(_("Start test"))
1411 self["key_yellow"] = StaticText(_("Stop test"))
1413 self["InfoTextBorder"] = Pixmap()
1414 self["InfoText"] = Label()
1416 def NetworkStatedataAvail(self,data):
1418 self["IP"].setForegroundColorNum(2)
1419 self["IP"].setText(_("confirmed"))
1420 self["IPInfo_Check"].setPixmapNum(0)
1422 self["IP"].setForegroundColorNum(1)
1423 self["IP"].setText(_("unconfirmed"))
1424 self["IPInfo_Check"].setPixmapNum(1)
1425 self["IPInfo_Check"].show()
1426 self["IPInfo_Text"].setForegroundColorNum(1)
1427 self.steptimer = True
1428 self.nextStepTimer.start(3000)
1430 def DNSLookupdataAvail(self,data):
1432 self["DNS"].setForegroundColorNum(2)
1433 self["DNS"].setText(_("confirmed"))
1434 self["DNSInfo_Check"].setPixmapNum(0)
1436 self["DNS"].setForegroundColorNum(1)
1437 self["DNS"].setText(_("unconfirmed"))
1438 self["DNSInfo_Check"].setPixmapNum(1)
1439 self["DNSInfo_Check"].show()
1440 self["DNSInfo_Text"].setForegroundColorNum(1)
1441 self["EditSettings_Text"].show()
1442 self["EditSettingsButton"].setPixmapNum(1)
1443 self["EditSettings_Text"].setForegroundColorNum(2) # active
1444 self["EditSettingsButton"].show()
1445 self["key_yellow"].setText("")
1446 self["key_green"].setText(_("Restart test"))
1447 self["shortcutsgreen"].setEnabled(False)
1448 self["shortcutsgreen_restart"].setEnabled(True)
1449 self["shortcutsyellow"].setEnabled(False)
1450 self["updown_actions"].setEnabled(True)
1451 self.activebutton = 6
1453 def getInfoCB(self,status):
1454 if status is not None:
1455 if status.startswith("No Connection") or status.startswith("Not-Associated") or status == False:
1456 self["Network"].setForegroundColorNum(1)
1457 self["Network"].setText(_("disconnected"))
1458 self["NetworkInfo_Check"].setPixmapNum(1)
1459 self["NetworkInfo_Check"].show()
1461 self["Network"].setForegroundColorNum(2)
1462 self["Network"].setText(_("connected"))
1463 self["NetworkInfo_Check"].setPixmapNum(0)
1464 self["NetworkInfo_Check"].show()
1467 iNetwork.stopLinkStateConsole()
1468 iNetwork.stopPingConsole()
1469 iNetwork.stopDNSConsole()
1471 def AccessPointInfo(self,iface):
1472 cmd = "iwconfig %s"%iface
1473 self.iwconfigConsole = Console()
1474 self.iwconfigConsole.ePopen(cmd,self.readAP,self.getInfoCB)
1476 def readAP(self,result,retval,extra_args):
1477 (callback) = extra_args
1479 if self.iwconfigConsole is not None:
1481 self.iwconfigConsole = None
1482 for content in result.splitlines():
1483 if 'Access Point' in content:
1484 self.apState = content.strip().split('Access Point: ')[1]
1485 callback(self.apState)
1487 callback(self.apState)
1489 class Wlanstatus(Screen):
1491 <screen position="center,center" size="510,400" title="Wireless Network Status..." >
1492 <widget source="status" render="Label" position="5,15" size="500,350" font="Regular;18" zPosition="1" />
1494 <ePixmap pixmap="skin_default/buttons/red.png" position="185,360" size="140,40" alphatest="on" />
1495 <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" />
1498 def __init__(self, session,iface):
1499 Screen.__init__(self,session)
1500 self.session = session
1502 self["status"] = StaticText(_("Wait a moment..."))
1503 self["key_red"] = StaticText(_("Close"))
1504 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
1507 "cancel": self.close,
1511 self.onClose.append(self.cleanup)
1513 def readstatus(self):
1514 self.wlanstatus = Console()
1515 cmd1 = "iwconfig "+self.iface
1516 self.wlanstatus.ePopen(cmd1, self.iwconfigfinnished,self.statusdisplay)
1518 def iwconfigfinnished(self, result, retval,extra_args):
1520 (statecallback) = extra_args
1521 if self.wlanstatus is not None:
1523 statecallback(result)
1530 def statusdisplay(self,data):
1532 self["status"].setText(_("No information..."))
1534 self["status"].setText(data)
1540 self.stopWlanStatusConsole()
1542 def stopWlanStatusConsole(self):
1543 if self.wlanstatus is not None:
1544 if len(self.wlanstatus.appContainers):
1545 for name in self.wlanstatus.appContainers.keys():
1546 self.wlanstatus.kill(name)
1548 def openconfig(session, **kwargs):
1549 session.open(WlanSelection)
1551 def selSetup(menuid, **kwargs):
1553 if menuid != "system":
1556 for x in iNetwork.getInstalledAdapters():
1557 if x.startswith('eth'):
1561 return [(_("Wireless LAN Setup"), openconfig, "wlansetup_config", 80)]
1566 def Plugins(**kwargs):
1567 return PluginDescriptor(name=_("Wireless LAN Setup"), description="Wireless LAN Setup", where = PluginDescriptor.WHERE_MENU, fnc=selSetup)