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
340 ConfigListScreen.__init__(self, self.list,session = self.session)
341 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
342 self.readWpaSupplicantConf()
343 self.scanAPFailedTimer = eTimer()
344 self.scanAPFailedTimer.callback.append(self.scanAPFailed)
345 self.scanAplistTimer = eTimer()
346 self.scanAplistTimer.callback.append(self.scanApList)
347 self.Console = Console()
348 self.updateInterfaces(self.readWlanSettings)
349 self.onClose.append(self.cleanup)
351 def updateInterfaces(self,callback = None):
352 iNetwork.config_ready = False
353 iNetwork.msgPlugins()
354 iNetwork.getInterfaces(callback)
356 def readWlanSettings(self,ret=None):
358 print "getInterfaces Fail... "
359 if iNetwork.getAdapterAttribute(self.iface, "up") == True:
363 wlanconfig.usedevice = ConfigSelection(default=default_tmp, choices = [("off", _("off")), ("on", _("on"))])
365 if iNetwork.getAdapterAttribute(self.iface, "dhcp"):
369 wlanconfig.usedhcp = ConfigSelection(default=default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
371 wlanconfig.ip = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0]
373 wlanconfig.netmask = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0])
374 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
378 wlanconfig.usegateway = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
380 wlanconfig.gateway = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0])
382 self["ipaddress"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "ip"))))
383 self["netmask"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "netmask"))))
384 self["gateway"].setText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "gateway"))))
386 if self.encryption_key is not None:
390 wlanconfig.encrypt = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
392 if self.key_mgmt=="NONE":
394 elif self.key_mgmt == "WPA-PSK":
395 if self.proto == "WPA":
397 elif self.proto == "RSN":
399 elif self.proto in ( "WPA RSN", "WPA WPA2"):
400 default_tmp = "wpa/wpa2"
406 wlanconfig.method = ConfigSelection(default = default_tmp, choices = [
407 ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
409 if self.key_type == 0:
412 default_tmp = "ascii"
413 wlanconfig.keytype = ConfigSelection(default = default_tmp, choices = [
414 ("ascii", _("ASCII")), ("hex", _("HEX"))])
415 default_tmp = self.encryption_key or "XXXXXXXX"
416 wlanconfig.key = ConfigPassword(default = default_tmp, visible_width = 50, fixed_size = False)
417 self.scanAplistTimer.start(100,True)
419 def readWpaSupplicantConf(self):
421 if fileExists("/etc/wpa_supplicant.conf"):
422 wpafd = open("/etc/wpa_supplicant.conf","r")
424 data = wpafd.readline()
426 # print "####readWpaSupplicantConf, data : ",data
429 data = wpafd.readline()
431 if data.startswith('ssid=') and len(data) > 6:
432 self.ssid = data[6:-2]
433 elif data.startswith('ap_scan=') :
434 self.ap_scan = data[8:]
435 # print "####readWpaSupplicantConf, ap_scan : ",self.ap_scan
436 elif data.startswith('scan_ssid=') and len(data) > 10:
437 self.scan_ssid = data[10:-1]
438 elif data.startswith('key_mgmt=') and len(data) > 9:
439 self.key_mgmt = data[9:-1]
440 elif data.startswith('proto=') and len(data) > 6:
441 self.proto = data[6:-1]
442 elif data.startswith('wep_key0="') and len(data) > 11:
443 self.key_type = 1 # ascii
444 self.encryption_key = data[10:-2]
445 elif data.startswith('wep_key0=') and len(data) > 9:
446 self.key_type = 0 # hex
447 self.encryption_key = data[9:-1]
448 elif data.startswith('psk="') and len(data) > 6:
449 self.key_type = 1 # ascii
450 self.encryption_key = data[5:-2]
451 elif data.startswith('#psk="') and len(data) > 6:
452 self.key_type = 0 # hex
453 self.encryption_key = data[6:-2]
454 elif not self.encryption_key and data.startswith('psk=') and len(data) > 4:
455 self.key_type = 0 # hex
456 self.encryption_key = data[4:-1]
457 data = wpafd.readline()
458 print self.ssid,self.scan_ssid,self.key_mgmt,self.proto,self.key_type,self.encryption_key
465 print 'failed loading wpasupplicant.conf'
467 def createConfig(self):
469 self.usedeviceEntry = getConfigListEntry(_("Use Device"), wlanconfig.usedevice)
470 self.usedhcpEntry = getConfigListEntry(_("Use DHCP"), wlanconfig.usedhcp)
471 self.essidEntry = getConfigListEntry(_("ESSID"), wlanconfig.essid)
472 self.hiddenessidEntry = getConfigListEntry(_("Input Hidden ESSID"), wlanconfig.hiddenessid)
473 self.encryptEntry = getConfigListEntry(_("Encrypt"), wlanconfig.encrypt)
474 self.methodEntry = getConfigListEntry(_("Method"), wlanconfig.method)
475 self.keytypeEntry = getConfigListEntry(_("Key Type"), wlanconfig.keytype)
476 self.keyEntry = getConfigListEntry(_("KEY"), wlanconfig.key)
478 self.ipEntry = getConfigListEntry(_("IP"), wlanconfig.ip)
479 self.netmaskEntry = getConfigListEntry(_("NetMask"), wlanconfig.netmask)
481 self.usegatewayEntry = getConfigListEntry(_("Use Gateway"), wlanconfig.usegateway)
482 self.gatewayEntry = getConfigListEntry(_("Gateway"), wlanconfig.gateway)
484 self.configList.append( self.usedeviceEntry )
485 if wlanconfig.usedevice.value is "on":
486 self.configList.append( self.usedhcpEntry )
487 if wlanconfig.usedhcp.value is "off":
488 self.configList.append(self.ipEntry)
489 self.configList.append(self.netmaskEntry)
490 self.configList.append(self.usegatewayEntry)
491 if wlanconfig.usegateway.value is "on":
492 self.configList.append(self.gatewayEntry)
493 self.configList.append( self.essidEntry )
494 if wlanconfig.essid.value == 'Input hidden ESSID':
495 self.configList.append( self.hiddenessidEntry )
496 self.configList.append( self.encryptEntry )
497 if wlanconfig.encrypt.value is "on" :
498 self.configList.append( self.methodEntry )
499 if wlanconfig.method.value =="wep":
500 self.configList.append( self.keytypeEntry )
501 self.configList.append( self.keyEntry )
503 self["config"].list = self.configList
504 self["config"].l.setList(self.configList)
506 def scanApList(self):
508 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
509 cmd = "ifconfig "+self.iface+" up"
512 self.wlanscanap = Console()
513 cmd = "iwlist "+self.iface+" scan"
515 self.wlanscanap.ePopen(cmd, self.apListFinnished,self.apListParse)
517 def apListFinnished(self, result, retval,extra_args):
518 (callback) = extra_args
519 if self.wlanscanap is not None:
521 self.wlanscanap = None
522 content = result.splitlines()
523 first = content[0].split()
528 if completed == True:
535 def apListParse(self,data):
538 if self.scanAPcount >0:
540 self.configurationmsg.close(True)
542 self.scanAplistTimer.start(500,True)
545 self.configurationmsg.close(True)
546 self.scanAPFailedTimer.start(500,True)
551 list = data.splitlines()
554 if xx.startswith('ESSID:') and len(xx)>8 and xx[7:-1]not in self.apList:
555 self.apList.append(xx[7:-1])
556 self.apList.append('Input hidden ESSID')
557 if selectap is not None and selectap in self.apList:
558 wlanconfig.essid = ConfigSelection(default=selectap,choices = self.apList)
559 elif self.scan_ssid is not None and self.scan_ssid.strip() == '1':
560 wlanconfig.essid = ConfigSelection(default='Input hidden ESSID',choices = self.apList)
561 elif self.ssid is not None and self.ssid in self.apList:
562 wlanconfig.essid = ConfigSelection(default=self.ssid,choices = self.apList)
564 wlanconfig.essid = ConfigSelection(choices = self.apList)
565 if self.ssid is not None:
566 wlanconfig.hiddenessid = ConfigText(default = self.ssid, visible_width = 50, fixed_size = False)
568 wlanconfig.hiddenessid = ConfigText(default = "<Input ESSID>", visible_width = 50, fixed_size = False)
569 self.configurationmsg.close(True)
572 def scanAPFailed(self):
573 self.session.openWithCallback(self.keyCancel ,MessageBox, _("Scan AP Failed"), MessageBox.TYPE_ERROR,10)
576 ConfigListScreen.keyLeft(self)
580 ConfigListScreen.keyRight(self)
584 if self["config"].getCurrent() == self.usedeviceEntry or self["config"].getCurrent() == self.encryptEntry \
585 or self["config"].getCurrent() == self.usedhcpEntry or self["config"].getCurrent() == self.usegatewayEntry \
586 or self["config"].getCurrent() == self.essidEntry or self["config"].getCurrent() == self.methodEntry:
589 def saveWlanConfig(self):
591 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
592 self["config"].getCurrent()[1].onDeselect(self.session)
593 if self["config"].isChanged():
594 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Are you sure you want to restart your network interfaces?\n") ) )
596 self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Network configuration is not changed....\n\nAre you sure you want to restart your network interfaces?\n") ) )
600 def checkNetworkConfig(self, ret = False):
602 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
603 self["config"].getCurrent()[1].onSelect(self.session)
605 if wlanconfig.essid.value == 'Input hidden ESSID':
606 if len(wlanconfig.hiddenessid.value) == 0:
607 self.session.open(MessageBox, ("PLEASE INPUT HIDDEN ESSID"), type = MessageBox.TYPE_ERROR, timeout = 10)
609 if len(wlanconfig.key.value) == 0:
610 self.session.open(MessageBox, ("PLEASE INPUT NETWORK KEY"), type = MessageBox.TYPE_ERROR, timeout = 10)
612 self.checkNetworkShares()
614 def checkNetworkShares(self):
616 self.Console = Console()
617 cmd = "cat /proc/mounts"
618 self.Console.ePopen(cmd, self.checkSharesFinished, self.confirmAnotherIfaces)
620 def checkSharesFinished(self, result, retval, extra_args):
621 callback = extra_args
622 print "checkMountsFinished : result : \n",result
623 networks = ['nfs','smbfs','ncp','coda']
624 for line in result.splitlines():
625 split = line.strip().split(' ',3)
626 if split[2] in networks:
627 self.session.open(MessageBox, ("NOT deconfiguring network interfaces :\n network shares still mounted\n"), type = MessageBox.TYPE_ERROR, timeout = 10)
629 if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry :
630 self["config"].getCurrent()[1].onSelect(self.session)
634 def confirmAnotherIfaces(self, ret = False):
638 num_configured_if = len(iNetwork.getConfiguredAdapters())
639 if num_configured_if >= 1:
640 if num_configured_if == 1 and self.iface in iNetwork.getConfiguredAdapters():
641 self.getWpaPhrase(False)
643 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)
645 self.getWpaPhrase(False)
647 def getWpaPhrase(self,ret):
649 configuredInterfaces = iNetwork.getConfiguredAdapters()
650 for interface in configuredInterfaces:
651 if interface == self.iface:
653 iNetwork.setAdapterAttribute(interface, "up", False)
654 iNetwork.deactivateInterface(interface)
655 if wlanconfig.method.value =="wep":
656 self.writeWpasupplicantConf("wep") # passphrasekey is not None
658 if wlanconfig.essid.value == 'Input hidden ESSID':
659 cmd = 'wpa_passphrase %s %s' % (wlanconfig.hiddenessid.value,wlanconfig.key.value)
661 cmd = 'wpa_passphrase %s %s' % (wlanconfig.essid.value,wlanconfig.key.value)
663 self.wpaphraseconsole = Console()
664 self.wpaphraseconsole.ePopen(cmd, self.parseWpaPhrase, self.writeWpasupplicantConf)
666 def parseWpaPhrase(self, result, retval, extra_args):
667 print "parseWpaPhrase"
668 (writewlanconfig) = extra_args
669 if self.wpaphraseconsole is not None:
670 print "retval = ",retval
672 self.wpaphraseconsole.killAll()
673 self.wpaphraseconsole = None
674 print "parseWpaPhrase result : "
677 for line in result.splitlines():
678 if line.find('ssid') == -1 and line.find('#psk=') != -1:
680 elif line.find('psk=') != -1:
683 writewlanconfig(psk,plainpwd)
684 # writewlanconfig(None)
686 writewlanconfig(None)
688 writewlanconfig(None)
690 def writeWpasupplicantConf(self, passphrasekey=None,plainpwd=None):
692 wpafd = open("/etc/wpa_supplicant.conf","w")
694 contents = "#WPA Supplicant Configuration by STB\n"
695 contents += "ctrl_interface=/var/run/wpa_supplicant\n"
696 contents += "eapol_version=1\n"
697 contents += "fast_reauth=1\n"
698 contents += "ap_scan=1\n"
699 contents += "network={\n"
700 if wlanconfig.essid.value == 'Input hidden ESSID':
701 contents += "\tssid=\""+wlanconfig.hiddenessid.value+"\"\n"
702 contents += "\tscan_ssid=1\n"
704 contents += "\tssid=\""+wlanconfig.essid.value+"\"\n"
705 contents += "\tscan_ssid=0\n"
706 if wlanconfig.encrypt.value == "on":
707 if wlanconfig.method.value =="wep":
708 contents += "\tkey_mgmt=NONE\n"
709 contents += "\twep_key0="
710 if wlanconfig.keytype.value == "ascii":
711 contents += "\""+wlanconfig.key.value+"\"\n"
713 contents += wlanconfig.key.value+"\n"
715 print "plainpwd : ",plainpwd
716 print "passphrasekey : ",passphrasekey
717 if wlanconfig.method.value == "wpa":
718 contents += "\tkey_mgmt=WPA-PSK\n"
719 contents += "\tproto=WPA\n"
720 contents += "\tpairwise=CCMP TKIP\n"
721 contents += "\tgroup=CCMP TKIP\n"
722 elif wlanconfig.method.value == "wpa2":
723 contents += "\tkey_mgmt=WPA-PSK\n"
724 contents += "\tproto=RSN\n"
725 contents += "\tpairwise=CCMP TKIP\n"
726 contents += "\tgroup=CCMP TKIP\n"
728 contents += "\tkey_mgmt=WPA-PSK\n"
729 contents += "\tproto=WPA RSN\n"
730 contents += "\tpairwise=CCMP TKIP\n"
731 contents += "\tgroup=CCMP TKIP\n"
732 contents += plainpwd+"\n"
733 contents += passphrasekey+"\n"
735 contents += "\tkey_mgmt=NONE\n"
737 print "content = \n"+contents
738 wpafd.write(contents)
740 self.writeNetConfig(0)
742 self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
743 self.writeNetConfig(-1)
745 self.writeNetConfig(-2)
747 def writeNetConfig(self,ret = -1):
749 self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
752 self.session.open(MessageBox, _("Can NOT generate passphrase"), type = MessageBox.TYPE_ERROR, timeout = 10)
755 if wlanconfig.usedevice.value=="on":
756 iNetwork.setAdapterAttribute(self.iface, "up", True)
757 if wlanconfig.usedhcp.value =="on":
758 iNetwork.setAdapterAttribute(self.iface, "dhcp", True)
760 iNetwork.setAdapterAttribute(self.iface, "dhcp", False)
761 iNetwork.setAdapterAttribute(self.iface, "ip", wlanconfig.ip.value)
762 iNetwork.setAdapterAttribute(self.iface, "netmask", wlanconfig.netmask.value)
763 if wlanconfig.usegateway.value == "on":
764 iNetwork.setAdapterAttribute(self.iface, "gateway", wlanconfig.gateway.value)
766 iNetwork.setAdapterAttribute(self.iface, "up", False)
767 iNetwork.deactivateInterface(self.iface)
768 contents = "\tpre-up wpa_supplicant -i"+self.iface+" -c/etc/wpa_supplicant.conf -B -D"+iNetwork.detectWlanModule(self.iface)+"\n"
769 contents += "\tpost-down wpa_cli terminate\n\n"
770 iNetwork.setAdapterAttribute(self.iface, "configStrings", contents)
771 iNetwork.writeNetworkConfig()
772 iNetwork.restartNetwork(self.updateCurrentInterfaces)
773 self.configurationmsg = None
774 self.configurationmsg = self.session.openWithCallback(self.configFinished, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
777 def updateCurrentInterfaces(self,ret):
779 iNetwork.getInterfaces(self.configurationMsgClose)
781 def configurationMsgClose(self,ret):
782 if ret is True and self.configurationmsg is not None:
783 self.configurationmsg.close(True)
785 def configFinished(self,data):
788 self.session.openWithCallback(self.configFinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
789 selectap = wlanconfig.essid.value
791 def configFinishedCB(self,data):
796 def formatip(self, iplist):
799 # print "iplist : ",iplist
802 result = str(iplist[0])+"."+str(iplist[1])+"."+str(iplist[2])+"."+str(iplist[3])
805 # print "result : ",result
810 def keyCancelConfirm(self, result):
813 if self.oldInterfaceState is False:
814 iNetwork.setAdapterAttribute(self.iface, "up", False)
815 iNetwork.deactivateInterface(self.iface,self.keyCancelCB)
819 def keyCancel(self,yesno = True):
820 if self["config"].isChanged():
821 self.session.openWithCallback(self.keyCancelConfirm, MessageBox, _("Really close without saving settings?"))
823 self.keyCancelConfirm(True)
825 def keyCancelCB(self,data):
831 iNetwork.stopRestartConsole()
832 iNetwork.stopGetInterfacesConsole()
833 iNetwork.stopDeactivateInterfaceConsole()
834 self.stopwlanscanapConsole()
835 self.stopCheckNetworkSharesConsole()
836 self.stopWpaPhraseConsole()
838 def stopwlanscanapConsole(self):
839 if self.wlanscanap is not None:
840 if len(self.wlanscanap.appContainers):
841 for name in self.wlanscanap.appContainers.keys():
842 self.wlanscanap.kill(name)
844 def stopCheckNetworkSharesConsole(self):
845 if self.Console is not None:
846 if len(self.Console.appContainers):
847 for name in self.Console.appContainers.keys():
848 self.Console.kill(name)
850 def stopWpaPhraseConsole(self):
851 if self.wpaphraseconsole is not None:
852 if len(self.wpaphraseconsole.appContainers):
853 for name in self.wpaphraseconsole.appContainers.keys():
854 self.wpaphraseconsole.kill(name)
856 class WlanScanAp(Screen,HelpableScreen):
858 <screen position="center,center" size="510,400" title="Wireless Network AP Scan..." >
859 <ePixmap pixmap="skin_default/div-h.png" position="0,350" zPosition="1" size="560,2" />
860 <ePixmap pixmap="skin_default/border_menu.png" position="10,10" zPosition="1" size="250,300" transparent="1" alphatest="on" />
862 <ePixmap pixmap="skin_default/buttons/red.png" position="10,360" size="140,40" alphatest="on" />
863 <ePixmap pixmap="skin_default/buttons/green.png" position="185,360" size="140,40" alphatest="on" />
864 <ePixmap pixmap="skin_default/buttons/blue.png" position="360,360" size="140,40" alphatest="on" />
866 <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" />
867 <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" />
868 <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" />
870 <widget name="menulist" position="20,20" size="230,260" backgroundColor="#371e1c1a" transparent="1" zPosition="10" scrollbarMode="showOnDemand" />
872 <widget source="Address" render="Label" position="265,70" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
873 <widget source="ESSID" render="Label" position="265,100" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
874 <widget source="Protocol" render="Label" position="265,130" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
875 <widget source="Frequency" render="Label" position="265,160" zPosition="1" size="240,40" font="Regular;18" halign="center" valign="center" />
876 <widget source="Encryption key" render="Label" position="265,200" zPosition="1" size="240,30" font="Regular;18" halign="center" valign="center" />
877 <widget source="BitRate" render="Label" position="265,220" zPosition="1" size="240,60" font="Regular;18" halign="center" valign="center" />
880 def __init__(self, session, iface):
881 Screen.__init__(self,session)
882 HelpableScreen.__init__(self)
883 self.session = session
885 self.wlanscanap = None
886 # self.scanAPcount = 5
891 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
893 "up": (self.up, _("move up to previous entry")),
894 "down": (self.down, _("move down to next entry")),
895 "left": (self.left, _("move up to first entry")),
896 "right": (self.right, _("move down to last entry")),
899 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
901 "cancel": (self.close, _("exit")),
902 "ok": (self.ok, "select AP"),
905 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
907 "red": (self.close, _("exit")),
908 "green": (self.ok, "select AP"),
909 "blue": (self.startWlanConfig, "Edit Wireless settings"),
912 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
923 self["menulist"] = MenuList(self.SetApList)
924 self["key_red"] = StaticText(_("Close"))
925 self["key_green"] = StaticText(_("Select"))
926 self["key_blue"] = StaticText(_("EditSetting"))
927 self["Address"] = StaticText(_("Scanning AP List.."))
928 self["ESSID"] = StaticText(_("Wait a moment"))
929 self["Protocol"] = StaticText(" ")
930 self["Frequency"] = StaticText(" ")
931 self["Encryption key"] = StaticText(" ")
932 self["BitRate"] = StaticText(" ")
933 self.scanAPFailedTimer = eTimer()
934 self.scanAPFailedTimer.callback.append(self.scanAPFailed)
935 self.scanAplistTimer = eTimer()
936 self.scanAplistTimer.callback.append(self.scanApList)
937 self.scanAplistTimer.start(100,True)
938 self.onClose.append(self.cleanup)
941 self["menulist"].pageUp()
945 self["menulist"].pageDown()
949 self["menulist"].up()
953 self["menulist"].down()
958 selectAp=self["menulist"].getCurrent()[0]
962 def startWlanConfig(self):
964 selectAp=self["menulist"].getCurrent()[0]
967 self.session.open(WlanConfig,self.iface)
970 def scanApList(self):
971 # print "self.scanAPcount : ",self.scanAPcount
974 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
975 os_system('ifconfig '+self.iface+" up")
976 self.wlanscanap = Console()
977 cmd = "iwlist "+self.iface+" scan"
979 self.wlanscanap.ePopen(cmd, self.iwlistfinnished,self.APListParse)
981 def iwlistfinnished(self, result, retval,extra_args):
982 # print "iwlistfinnished"
983 (statecallback) = extra_args
984 if self.wlanscanap is not None:
985 # print "retval = ",retval
987 self.wlanscanap = None
988 content = result.splitlines()
989 first = content[0].split()
994 if completed == True:
995 statecallback(result)
1001 def APListParse(self,data):
1003 if self.scanAPcount >0:
1004 self.scanAPcount -=1
1005 self.configurationmsg.close(True)
1007 self.scanAplistTimer.start(500,True)
1010 self.configurationmsg.close(True)
1011 self.scanAPFailedTimer.start(500,True)
1016 # self.scanAPcount =5
1018 list = data.splitlines()
1020 # print "line : ",line
1021 if line.strip().startswith("Cell"): # Cell 01 - Address: 00:26:66:5C:EF:24
1022 parts = line.strip().split(" ")
1023 current_ap_id = int(parts[1])
1024 self.apList[current_ap_id]={}
1025 self.apList[current_ap_id]["Address"]=parts[4]
1026 elif line.strip().startswith("ESSID"):
1027 self.apList[current_ap_id]["ESSID"]=line.strip()[6:].strip('"')
1028 self.SetApList.append( (self.apList[current_ap_id]["ESSID"],current_ap_id) )
1029 elif line.strip().startswith("Protocol"):
1030 self.apList[current_ap_id]["Protocol"]=line.strip()[9:]
1031 elif line.strip().startswith("Frequency"):
1032 self.apList[current_ap_id]["Frequency"]=line.strip()[10:]
1033 elif line.strip().startswith("Encryption key"):
1034 self.apList[current_ap_id]["Encryption key"]=line.strip()[15:]
1035 elif line.strip().startswith("Bit Rates"):
1036 self.apList[current_ap_id]["BitRate"]=line.strip()[10:]
1038 print len(self.apList)
1039 self.configurationmsg.close(True)
1040 self.displayApInfo()
1042 def scanAPFailed(self):
1043 self.session.openWithCallback(self.ScanAPclose,MessageBox, _("Scan AP Failed"), MessageBox.TYPE_ERROR,10)
1045 def displayApInfo(self):
1046 if len(self.apList) >0:
1047 self["menulist"].setList(self.SetApList)
1048 index = self["menulist"].getCurrent()[1]
1049 for key in ["Address", "ESSID", "Protocol", "Frequency", "Encryption key", "BitRate"]:
1050 if self.apList[index].has_key(key):
1051 self[key].setText((key+": "+self.apList[index][key]))
1053 self[key].setText((key+": None"))
1055 self.session.openWithCallback(self.ScanAPclose, MessageBox, _("No AP detected."), type = MessageBox.TYPE_INFO, timeout = 10)
1057 def ScanAPclose(self,data):
1061 self.stopwlanscanapConsole()
1063 def stopwlanscanapConsole(self):
1064 if self.wlanscanap is not None:
1065 if len(self.wlanscanap.appContainers):
1066 for name in self.wlanscanap.appContainers.keys():
1067 self.wlanscanap.kill(name)
1069 class NetworkAdapterTest(Screen):
1070 def __init__(self, session,iface):
1071 Screen.__init__(self, session)
1073 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
1075 self.onClose.append(self.cleanup)
1076 self.onHide.append(self.cleanup)
1078 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
1082 "up": lambda: self.updownhandler('up'),
1083 "down": lambda: self.updownhandler('down'),
1087 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1090 "back": self.cancel,
1092 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1094 "red": self.closeInfo,
1095 "back": self.closeInfo,
1097 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
1099 "green": self.KeyGreen,
1101 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
1103 "green": self.KeyGreenRestart,
1105 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
1107 "yellow": self.KeyYellow,
1110 self["shortcutsgreen_restart"].setEnabled(False)
1111 self["updown_actions"].setEnabled(False)
1112 self["infoshortcuts"].setEnabled(False)
1113 self.onClose.append(self.delTimer)
1114 self.onLayoutFinish.append(self.layoutFinished)
1115 self.steptimer = False
1117 self.activebutton = 0
1118 self.nextStepTimer = eTimer()
1119 self.nextStepTimer.callback.append(self.nextStepTimerFire)
1122 if self.oldInterfaceState is False:
1123 iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
1124 iNetwork.deactivateInterface(self.iface)
1127 def closeInfo(self):
1128 self["shortcuts"].setEnabled(True)
1129 self["infoshortcuts"].setEnabled(False)
1130 self["InfoText"].hide()
1131 self["InfoTextBorder"].hide()
1132 self["key_red"].setText(_("Close"))
1136 del self.nextStepTimer
1138 def nextStepTimerFire(self):
1139 self.nextStepTimer.stop()
1140 self.steptimer = False
1143 def updownhandler(self,direction):
1144 if direction == 'up':
1145 if self.activebutton >=2:
1146 self.activebutton -= 1
1148 self.activebutton = 6
1149 self.setActiveButton(self.activebutton)
1150 if direction == 'down':
1151 if self.activebutton <=5:
1152 self.activebutton += 1
1154 self.activebutton = 1
1155 self.setActiveButton(self.activebutton)
1157 def setActiveButton(self,button):
1159 self["EditSettingsButton"].setPixmapNum(0)
1160 self["EditSettings_Text"].setForegroundColorNum(0)
1161 self["NetworkInfo"].setPixmapNum(0)
1162 self["NetworkInfo_Text"].setForegroundColorNum(1)
1163 self["AdapterInfo"].setPixmapNum(1) # active
1164 self["AdapterInfo_Text"].setForegroundColorNum(2) # active
1166 self["AdapterInfo_Text"].setForegroundColorNum(1)
1167 self["AdapterInfo"].setPixmapNum(0)
1168 self["DhcpInfo"].setPixmapNum(0)
1169 self["DhcpInfo_Text"].setForegroundColorNum(1)
1170 self["NetworkInfo"].setPixmapNum(1) # active
1171 self["NetworkInfo_Text"].setForegroundColorNum(2) # active
1173 self["NetworkInfo"].setPixmapNum(0)
1174 self["NetworkInfo_Text"].setForegroundColorNum(1)
1175 self["IPInfo"].setPixmapNum(0)
1176 self["IPInfo_Text"].setForegroundColorNum(1)
1177 self["DhcpInfo"].setPixmapNum(1) # active
1178 self["DhcpInfo_Text"].setForegroundColorNum(2) # active
1180 self["DhcpInfo"].setPixmapNum(0)
1181 self["DhcpInfo_Text"].setForegroundColorNum(1)
1182 self["DNSInfo"].setPixmapNum(0)
1183 self["DNSInfo_Text"].setForegroundColorNum(1)
1184 self["IPInfo"].setPixmapNum(1) # active
1185 self["IPInfo_Text"].setForegroundColorNum(2) # active
1187 self["IPInfo"].setPixmapNum(0)
1188 self["IPInfo_Text"].setForegroundColorNum(1)
1189 self["EditSettingsButton"].setPixmapNum(0)
1190 self["EditSettings_Text"].setForegroundColorNum(0)
1191 self["DNSInfo"].setPixmapNum(1) # active
1192 self["DNSInfo_Text"].setForegroundColorNum(2) # active
1194 self["DNSInfo"].setPixmapNum(0)
1195 self["DNSInfo_Text"].setForegroundColorNum(1)
1196 self["EditSettingsButton"].setPixmapNum(1) # active
1197 self["EditSettings_Text"].setForegroundColorNum(2) # active
1198 self["AdapterInfo"].setPixmapNum(0)
1199 self["AdapterInfo_Text"].setForegroundColorNum(1)
1202 next = self.nextstep
1218 self.steptimer = True
1219 self.nextStepTimer.start(3000)
1220 self["key_yellow"].setText(_("Stop test"))
1223 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
1224 self["Adapter"].setForegroundColorNum(2)
1225 self["Adaptertext"].setForegroundColorNum(1)
1226 self["AdapterInfo_Text"].setForegroundColorNum(1)
1227 self["AdapterInfo_OK"].show()
1228 self.steptimer = True
1229 self.nextStepTimer.start(3000)
1232 self["Networktext"].setForegroundColorNum(1)
1233 self["Network"].setText(_("Please wait..."))
1234 self.AccessPointInfo(self.iface)
1235 self["NetworkInfo_Text"].setForegroundColorNum(1)
1236 self.steptimer = True
1237 self.nextStepTimer.start(3000)
1240 self["Dhcptext"].setForegroundColorNum(1)
1241 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
1242 self["Dhcp"].setForegroundColorNum(2)
1243 self["Dhcp"].setText(_("enabled"))
1244 self["DhcpInfo_Check"].setPixmapNum(0)
1246 self["Dhcp"].setForegroundColorNum(1)
1247 self["Dhcp"].setText(_("disabled"))
1248 self["DhcpInfo_Check"].setPixmapNum(1)
1249 self["DhcpInfo_Check"].show()
1250 self["DhcpInfo_Text"].setForegroundColorNum(1)
1251 self.steptimer = True
1252 self.nextStepTimer.start(3000)
1255 self["IPtext"].setForegroundColorNum(1)
1256 self["IP"].setText(_("Please wait..."))
1257 iNetwork.checkNetworkState(self.NetworkStatedataAvail)
1260 self.steptimer = False
1261 self.nextStepTimer.stop()
1262 self["DNStext"].setForegroundColorNum(1)
1263 self["DNS"].setText(_("Please wait..."))
1264 iNetwork.checkDNSLookup(self.DNSLookupdataAvail)
1267 self["shortcutsgreen"].setEnabled(False)
1268 self["shortcutsyellow"].setEnabled(True)
1269 self["updown_actions"].setEnabled(False)
1270 self["key_yellow"].setText("")
1271 self["key_green"].setText("")
1272 self.steptimer = True
1273 self.nextStepTimer.start(1000)
1275 def KeyGreenRestart(self):
1277 self.layoutFinished()
1278 self["Adapter"].setText((""))
1279 self["Network"].setText((""))
1280 self["Dhcp"].setText((""))
1281 self["IP"].setText((""))
1282 self["DNS"].setText((""))
1283 self["AdapterInfo_Text"].setForegroundColorNum(0)
1284 self["NetworkInfo_Text"].setForegroundColorNum(0)
1285 self["DhcpInfo_Text"].setForegroundColorNum(0)
1286 self["IPInfo_Text"].setForegroundColorNum(0)
1287 self["DNSInfo_Text"].setForegroundColorNum(0)
1288 self["shortcutsgreen_restart"].setEnabled(False)
1289 self["shortcutsgreen"].setEnabled(False)
1290 self["shortcutsyellow"].setEnabled(True)
1291 self["updown_actions"].setEnabled(False)
1292 self["key_yellow"].setText("")
1293 self["key_green"].setText("")
1294 self.steptimer = True
1295 self.nextStepTimer.start(1000)
1298 self["infoshortcuts"].setEnabled(True)
1299 self["shortcuts"].setEnabled(False)
1300 if self.activebutton == 1: # Adapter Check
1301 self["InfoText"].setText(_("This test detects your configured Wireless LAN-Adapter."))
1302 self["InfoTextBorder"].show()
1303 self["InfoText"].show()
1304 self["key_red"].setText(_("Back"))
1305 if self.activebutton == 2: #LAN Check
1306 self["InfoText"].setText(_("This test checks whether a network cable is connected to your Wireless LAN-Adapter."))
1307 self["InfoTextBorder"].show()
1308 self["InfoText"].show()
1309 self["key_red"].setText(_("Back"))
1310 if self.activebutton == 3: #DHCP Check
1311 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."))
1312 self["InfoTextBorder"].show()
1313 self["InfoText"].show()
1314 self["key_red"].setText(_("Back"))
1315 if self.activebutton == 4: # IP Check
1316 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"))
1317 self["InfoTextBorder"].show()
1318 self["InfoText"].show()
1319 self["key_red"].setText(_("Back"))
1320 if self.activebutton == 5: # DNS Check
1321 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"))
1322 self["InfoTextBorder"].show()
1323 self["InfoText"].show()
1324 self["key_red"].setText(_("Back"))
1325 if self.activebutton == 6: # Edit Settings
1327 self.session.open(WlanConfig,self.iface)
1328 self["shortcuts"].setEnabled(True)
1329 self["infoshortcuts"].setEnabled(False)
1331 def KeyYellow(self):
1333 self["shortcutsgreen_restart"].setEnabled(True)
1334 self["shortcutsgreen"].setEnabled(False)
1335 self["shortcutsyellow"].setEnabled(False)
1336 self["key_green"].setText(_("Restart test"))
1337 self["key_yellow"].setText("")
1338 self.steptimer = False
1339 self.nextStepTimer.stop()
1341 def layoutFinished(self):
1342 self.setTitle(_("Network test: ") + iNetwork.getFriendlyAdapterName(self.iface) )
1343 self["shortcutsyellow"].setEnabled(False)
1344 self["AdapterInfo_OK"].hide()
1345 self["NetworkInfo_Check"].hide()
1346 self["DhcpInfo_Check"].hide()
1347 self["IPInfo_Check"].hide()
1348 self["DNSInfo_Check"].hide()
1349 self["EditSettings_Text"].hide()
1350 self["EditSettingsButton"].hide()
1351 self["InfoText"].hide()
1352 self["InfoTextBorder"].hide()
1353 self["key_yellow"].setText("")
1355 def setLabels(self):
1356 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1357 self["Adapter"] = MultiColorLabel()
1358 self["AdapterInfo"] = MultiPixmap()
1359 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1360 self["AdapterInfo_OK"] = Pixmap()
1362 if self.iface in iNetwork.wlan_interfaces:
1363 self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1365 self["Networktext"] = MultiColorLabel(_("Local Network"))
1367 self["Network"] = MultiColorLabel()
1368 self["NetworkInfo"] = MultiPixmap()
1369 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1370 self["NetworkInfo_Check"] = MultiPixmap()
1372 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1373 self["Dhcp"] = MultiColorLabel()
1374 self["DhcpInfo"] = MultiPixmap()
1375 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1376 self["DhcpInfo_Check"] = MultiPixmap()
1378 self["IPtext"] = MultiColorLabel(_("IP Address"))
1379 self["IP"] = MultiColorLabel()
1380 self["IPInfo"] = MultiPixmap()
1381 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1382 self["IPInfo_Check"] = MultiPixmap()
1384 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1385 self["DNS"] = MultiColorLabel()
1386 self["DNSInfo"] = MultiPixmap()
1387 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1388 self["DNSInfo_Check"] = MultiPixmap()
1390 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1391 self["EditSettingsButton"] = MultiPixmap()
1393 self["key_red"] = StaticText(_("Close"))
1394 self["key_green"] = StaticText(_("Start test"))
1395 self["key_yellow"] = StaticText(_("Stop test"))
1397 self["InfoTextBorder"] = Pixmap()
1398 self["InfoText"] = Label()
1400 def NetworkStatedataAvail(self,data):
1402 self["IP"].setForegroundColorNum(2)
1403 self["IP"].setText(_("confirmed"))
1404 self["IPInfo_Check"].setPixmapNum(0)
1406 self["IP"].setForegroundColorNum(1)
1407 self["IP"].setText(_("unconfirmed"))
1408 self["IPInfo_Check"].setPixmapNum(1)
1409 self["IPInfo_Check"].show()
1410 self["IPInfo_Text"].setForegroundColorNum(1)
1411 self.steptimer = True
1412 self.nextStepTimer.start(3000)
1414 def DNSLookupdataAvail(self,data):
1416 self["DNS"].setForegroundColorNum(2)
1417 self["DNS"].setText(_("confirmed"))
1418 self["DNSInfo_Check"].setPixmapNum(0)
1420 self["DNS"].setForegroundColorNum(1)
1421 self["DNS"].setText(_("unconfirmed"))
1422 self["DNSInfo_Check"].setPixmapNum(1)
1423 self["DNSInfo_Check"].show()
1424 self["DNSInfo_Text"].setForegroundColorNum(1)
1425 self["EditSettings_Text"].show()
1426 self["EditSettingsButton"].setPixmapNum(1)
1427 self["EditSettings_Text"].setForegroundColorNum(2) # active
1428 self["EditSettingsButton"].show()
1429 self["key_yellow"].setText("")
1430 self["key_green"].setText(_("Restart test"))
1431 self["shortcutsgreen"].setEnabled(False)
1432 self["shortcutsgreen_restart"].setEnabled(True)
1433 self["shortcutsyellow"].setEnabled(False)
1434 self["updown_actions"].setEnabled(True)
1435 self.activebutton = 6
1437 def getInfoCB(self,status):
1438 if status is not None:
1439 if status.startswith("No Connection") or status.startswith("Not-Associated") or status == False:
1440 self["Network"].setForegroundColorNum(1)
1441 self["Network"].setText(_("disconnected"))
1442 self["NetworkInfo_Check"].setPixmapNum(1)
1443 self["NetworkInfo_Check"].show()
1445 self["Network"].setForegroundColorNum(2)
1446 self["Network"].setText(_("connected"))
1447 self["NetworkInfo_Check"].setPixmapNum(0)
1448 self["NetworkInfo_Check"].show()
1451 iNetwork.stopLinkStateConsole()
1452 iNetwork.stopPingConsole()
1453 iNetwork.stopDNSConsole()
1455 def AccessPointInfo(self,iface):
1456 cmd = "iwconfig %s"%iface
1457 self.iwconfigConsole = Console()
1458 self.iwconfigConsole.ePopen(cmd,self.readAP,self.getInfoCB)
1460 def readAP(self,result,retval,extra_args):
1461 (callback) = extra_args
1463 if self.iwconfigConsole is not None:
1465 self.iwconfigConsole = None
1466 for content in result.splitlines():
1467 if 'Access Point' in content:
1468 self.apState = content.strip().split('Access Point: ')[1]
1469 callback(self.apState)
1471 callback(self.apState)
1473 class Wlanstatus(Screen):
1475 <screen position="center,center" size="510,400" title="Wireless Network Status..." >
1476 <widget source="status" render="Label" position="5,15" size="500,350" font="Regular;18" zPosition="1" />
1478 <ePixmap pixmap="skin_default/buttons/red.png" position="185,360" size="140,40" alphatest="on" />
1479 <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" />
1482 def __init__(self, session,iface):
1483 Screen.__init__(self,session)
1484 self.session = session
1486 self["status"] = StaticText(_("Wait a moment..."))
1487 self["key_red"] = StaticText(_("Close"))
1488 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
1491 "cancel": self.close,
1495 self.onClose.append(self.cleanup)
1497 def readstatus(self):
1498 self.wlanstatus = Console()
1499 cmd1 = "iwconfig "+self.iface
1500 self.wlanstatus.ePopen(cmd1, self.iwconfigfinnished,self.statusdisplay)
1502 def iwconfigfinnished(self, result, retval,extra_args):
1504 (statecallback) = extra_args
1505 if self.wlanstatus is not None:
1507 statecallback(result)
1514 def statusdisplay(self,data):
1516 self["status"].setText(_("No information..."))
1518 self["status"].setText(data)
1524 self.stopWlanStatusConsole()
1526 def stopWlanStatusConsole(self):
1527 if self.wlanstatus is not None:
1528 if len(self.wlanstatus.appContainers):
1529 for name in self.wlanstatus.appContainers.keys():
1530 self.wlanstatus.kill(name)
1532 def openconfig(session, **kwargs):
1533 session.open(WlanSelection)
1535 def selSetup(menuid, **kwargs):
1537 if menuid != "system":
1540 for x in iNetwork.getInstalledAdapters():
1541 if x.startswith('eth'):
1545 return [(_("Wireless LAN Setup"), openconfig, "wlansetup_config", 80)]
1550 def Plugins(**kwargs):
1551 return PluginDescriptor(name=_("Wireless LAN Setup"), description="Wireless LAN Setup", where = PluginDescriptor.WHERE_MENU, fnc=selSetup)