WirelesslanSetup : fix bugs..
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / WirelessLanSetup / plugin.py
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
29 import time
30
31 class WlanSelection(Screen,HelpableScreen):
32         skin = """
33         <screen name="WlanSelection" position="209,48" size="865,623" title="Wireless Network Configuration..." flags="wfNoBorder" backgroundColor="transparent">
34                 <ePixmap pixmap="Vu_HD/Bg_EPG_view.png" zPosition="-1" position="0,0" size="865,623" alphatest="on" />
35                 <ePixmap pixmap="Vu_HD/menu/ico_title_Setup.png" position="32,41" size="40,40" alphatest="blend"  transparent="1" />
36                 <eLabel text="Wireless Network Adapter Selection..." position="90,50" size="600,32" font="Semiboldit;32" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
37                 <ePixmap pixmap="Vu_HD/icons/clock.png" position="750,55" zPosition="1" size="20,20" alphatest="blend" />
38                 <widget source="global.CurrentTime" render="Label" position="770,57" zPosition="1" size="50,20" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" halign="right" transparent="1">
39                         <convert type="ClockToText">Format:%H:%M</convert>
40                 </widget>
41                 <ePixmap pixmap="Vu_HD/buttons/red.png" position="45,98" size="25,25" alphatest="blend" />
42                 <ePixmap pixmap="Vu_HD/buttons/green.png" position="240,98" size="25,25" alphatest="blend" />
43                 <widget source="key_red" render="Label" position="66,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
44                 <widget source="key_green" render="Label" position="268,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
45                 <ePixmap pixmap="Vu_HD/border_menu.png" position="120,140" zPosition="-1" size="342,358" transparent="1" alphatest="blend" />
46                 <widget name="menulist" position="130,150" size="322,338" transparent="1" backgroundColor="#27d9dee2" zPosition="10" scrollbarMode="showOnDemand" />
47                 <widget source="description" render="Label" position="500,140" size="280,360" font="Regular;19" halign="center" valign="center" backgroundColor="#c5c9cc" transparent="1"/>
48         </screen>"""
49         
50         def __init__(self, session):
51                 Screen.__init__(self,session)
52                 HelpableScreen.__init__(self)
53                 self.mainmenu = self.getWlandevice()
54                 self["menulist"] = MenuList(self.mainmenu)
55                 self["key_red"] = StaticText(_("Close"))
56                 self["key_green"] = StaticText(_("Select"))
57                 self["description"] = StaticText()
58                 self["description"].setText(_("Select Wireless Lan module. \n" ))
59                 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
60                 {
61                         "ok": (self.ok, _("select interface")),
62                         "cancel": (self.close, _("exit network interface list")),
63                 })
64
65                 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
66                 {
67                         "green": (self.ok, _("select interface")),
68                         "red": (self.close, _("exit network interface list")),
69                 })
70
71         def ok(self):
72 #               print len(self["menulist"].list)
73                 if len(self["menulist"].list) == 0:
74                         self.session.open(MessageBox, (_("Can not find any WirelessLan Module\n")),MessageBox.TYPE_ERROR,5 )
75                         return
76                 ifaces=self["menulist"].getCurrent()[1]
77                 if ifaces == None:
78                         pass
79                 else:
80                         self.session.open(WlanSetup,ifaces)
81
82         def getWlandevice(self):
83                 list = []
84                 for x in iNetwork.getAdapterList():
85                         if x.startswith('eth'):
86                                 continue
87                         list.append((self.getAdapterDescription(x) + " (%s)"%x,x))
88                 return list
89
90         def getAdapterDescription(self, iface):
91                 if iface == 'eth0':
92                         return _("Internal LAN adapter.")
93                 else:
94                         classdir = "/sys/class/net/" + iface + "/device/"
95                         driverdir = "/sys/class/net/" + iface + "/device/driver/"
96                         if os_path.exists(classdir):
97                                 files = listdir(classdir)
98                                 if 'driver' in files:
99                                         if os_path.realpath(driverdir).endswith('rtw_usb_drv'):
100                                                 return _("Realtak")+ " " + _("WLAN adapter.")
101                                         elif os_path.realpath(driverdir).endswith('ath_pci'):
102                                                 return _("Atheros")+ " " + _("WLAN adapter.")
103                                         elif os_path.realpath(driverdir).endswith('zd1211b'):
104                                                 return _("Zydas")+ " " + _("WLAN adapter.")
105                                         elif os_path.realpath(driverdir).endswith('rt73'):
106                                                 return _("Ralink")+ " " + _("WLAN adapter.")
107                                         elif os_path.realpath(driverdir).endswith('rt73usb'):
108                                                 return _("Ralink")+ " " + _("WLAN adapter.")
109                                         else:
110                                                 return str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter")
111                                 else:
112                                         return _("Unknown network adapter.")
113
114 class WlanSetup(Screen,HelpableScreen):
115         skin = """
116         <screen name="WlanSetup" position="209,48" size="865,623" title="Wireless Network Configuration..." flags="wfNoBorder" backgroundColor="transparent">   
117                 <ePixmap pixmap="Vu_HD/Bg_EPG_view.png" zPosition="-1" position="0,0" size="865,623" alphatest="on" />
118                 <ePixmap pixmap="Vu_HD/menu/ico_title_Setup.png" position="32,41" size="40,40" alphatest="blend"  transparent="1" />
119                 <eLabel text="Wireless Network Setup Menu..." position="90,50" size="600,32" font="Semiboldit;32" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
120                 <ePixmap pixmap="Vu_HD/icons/clock.png" position="750,55" zPosition="1" size="20,20" alphatest="blend" />
121                 <widget source="global.CurrentTime" render="Label" position="770,57" zPosition="1" size="50,20" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" halign="right" transparent="1">
122                         <convert type="ClockToText">Format:%H:%M</convert>
123                 </widget>
124                 <ePixmap pixmap="Vu_HD/buttons/red.png" position="45,98" size="25,25" alphatest="blend" />
125                 <ePixmap pixmap="Vu_HD/buttons/green.png" position="240,98" size="25,25" alphatest="blend" />
126                 <widget source="key_red" render="Label" position="66,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
127                 <widget source="key_green" render="Label" position="268,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
128                 <ePixmap pixmap="Vu_HD/border_menu.png" position="120,140" zPosition="-1" size="342,358" transparent="1" alphatest="blend" />
129                 <widget name="menulist" position="130,150" size="322,338" transparent="1" backgroundColor="#27d9dee2" zPosition="10" scrollbarMode="showOnDemand" />
130                 <widget source="description" render="Label" position="500,140" size="280,360" font="Regular;19" halign="center" valign="center" backgroundColor="#c5c9cc" transparent="1"/>
131         </screen>"""
132         def __init__(self, session, ifaces):
133                 Screen.__init__(self, session)
134                 HelpableScreen.__init__(self)
135                 self.session = session
136                 self.iface = ifaces
137                 self.restartLanRef = None
138                 self.LinkState = None
139                 self.mainmenu = self.MakeMenu()
140                 self["menulist"] = MenuList(self.mainmenu)
141                 self["key_red"] = StaticText(_("Close"))
142                 self["key_green"] = StaticText(_("Select"))
143                 self["description"] = StaticText()
144                 self["IFtext"] = StaticText()
145                 self["IF"] = StaticText()
146                 self["Statustext"] = StaticText()
147                 self["statuspic"] = MultiPixmap()
148                 self["statuspic"].hide()
149                 self.onLayoutFinish.append(self.loadDescription)
150                 
151                 self.oktext = _("Press OK on your remote control to continue.")
152                 
153                 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
154                         {
155                         "up": (self.up, _("move up to previous entry")),
156                         "down": (self.down, _("move down to next entry")),
157                         "left": (self.left, _("move up to first entry")),
158                         "right": (self.right, _("move down to last entry")),
159                         })
160                 
161                 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
162                         {
163                         "cancel": (self.close, _("exit networkadapter setup menu")),
164                         "ok": (self.ok, _("select menu entry")),
165                         })
166
167                 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
168                         {
169                         "red": (self.close, _("exit networkadapter setup menu")),
170                         "green": (self.ok, _("select menu entry")),
171                         })
172
173                 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
174                 {
175                         "ok": self.ok,
176                         "back": self.close,
177                         "up": self.up,
178                         "down": self.down,
179                         "red": self.close,
180                         "left": self.left,
181                         "right": self.right,
182                 }, -2)
183
184         def loadDescription(self):
185                 if self["menulist"].getCurrent()[1] == 'setting':
186                         self["description"].setText(_("Edit the network configuration of your STB.\n" ) + self.oktext )
187                 if self["menulist"].getCurrent()[1] == 'scanap':
188                         self["description"].setText(_("Scan your network for wireless access points and connect to them using your selected wireless device.\n" ) + self.oktext )
189                 if self["menulist"].getCurrent()[1] == 'dns':
190                         self["description"].setText(_("Edit the Nameserver configuration of your STB.\n" ) + self.oktext )
191                 if self["menulist"].getCurrent()[1] == 'status':
192                         self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
193                 if self["menulist"].getCurrent()[1] == 'test':
194                         self["description"].setText(_("Test the network configuration of your STB.\n" ) + self.oktext )
195                 if self["menulist"].getCurrent()[1] == 'restart':
196                         self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
197
198         def up(self):
199                 self["menulist"].up()
200                 self.loadDescription()
201
202         def down(self):
203                 self["menulist"].down()
204                 self.loadDescription()
205
206         def left(self):
207                 self["menulist"].pageUp()
208                 self.loadDescription()
209
210         def right(self):
211                 self["menulist"].pageDown()
212                 self.loadDescription()
213
214         def ok(self):
215                 if self["menulist"].getCurrent()[1] == 'setting':
216                         self.session.openWithCallback(self.checklist, WlanConfig, self.iface)
217                 elif self["menulist"].getCurrent()[1] == 'scanap':
218                         self.session.open(WlanScanAp, self.iface)
219                 elif self["menulist"].getCurrent()[1] == 'dns':
220                         self.session.open(NameserverSetup)
221                 elif self["menulist"].getCurrent()[1] == 'status':
222                         self.session.open(Wlanstatus, self.iface)
223                 elif self["menulist"].getCurrent()[1] == 'test':
224                         self.session.openWithCallback(self.checklist,NetworkAdapterTest,self.iface)
225                 elif self["menulist"].getCurrent()[1] == 'restart':
226                         self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
227
228         def checklist(self):
229                 self["menulist"].setList(self.MakeMenu())
230
231         def MakeMenu(self):
232                 menu = []
233                 menu.append((_("Adapter settings"), "setting"))
234                 menu.append((_("Scan Wireless AP"), "scanap"))
235                 menu.append((_("Nameserver settings"), "dns"))
236                 if iNetwork.getAdapterAttribute(self.iface, "up"):
237                         menu.append((_("Show WLAN Status"), "status"))
238                 menu.append((_("Network test"), "test"))
239                 menu.append((_("Restart network"), "restart"))
240
241                 return menu
242
243         def restartLan(self, ret = False):
244                 if (ret == True):
245                         iNetwork.restartNetwork(self.restartLanDataAvail)
246                         self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while your network is restarting..."), type = MessageBox.TYPE_INFO, enable_input = False)
247
248         def restartLanDataAvail(self, data):
249                 if data is True:
250                         iNetwork.getInterfaces(self.getInterfacesDataAvail)
251
252         def getInterfacesDataAvail(self, data):
253                 if data is True:
254                         self.restartLanRef.close(True)
255
256         def restartfinishedCB(self,data):
257                 if data is True:
258                         self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 5, default = False)
259
260 wlanconfig = ConfigSubsection()
261 wlanconfig.usedevice = ConfigSelection(default = "off", choices = [
262         ("off", _("off")), ("on", _("on"))])
263 wlanconfig.usedhcp = ConfigSelection(default = "off", choices = [
264         ("off", _("no")), ("on", _("yes"))])
265 wlanconfig.essid = ConfigSelection(default = "none", choices = ["none"])
266 wlanconfig.encrypt = ConfigSelection(default = "off", choices = [
267         ("off", _("no")), ("on", _("yes"))])
268 wlanconfig.method = ConfigSelection(default = "wep", choices = [
269         ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
270 wlanconfig.keytype = ConfigSelection(default = "ascii", choices = [
271         ("ascii", _("ASCII")), ("hex", _("HEX"))])
272 wlanconfig.key = ConfigText(default = "XXXXXXXX", visible_width = 50, fixed_size = False)
273 wlanconfig.usegateway = ConfigSelection(default = "off", choices = [
274         ("off", _("no")), ("on", _("yes"))])
275 wlanconfig.ip    = ConfigIP([0,0,0,0])
276 wlanconfig.netmask = ConfigIP([0,0,0,0])
277 wlanconfig.gateway = ConfigIP([0,0,0,0])
278
279 selectap = None 
280 class WlanConfig(Screen, ConfigListScreen, HelpableScreen):
281         skin = """
282         <screen name="WlanConfig" position="209,48" size="865,623" title="Wireless Network Configuration..." flags="wfNoBorder" backgroundColor="transparent">  
283                 <ePixmap pixmap="Vu_HD/Bg_EPG_view.png" zPosition="-1" position="0,0" size="865,623" alphatest="on" />
284                 <ePixmap pixmap="Vu_HD/menu/ico_title_Setup.png" position="32,41" size="40,40" alphatest="blend"  transparent="1" />
285                 <eLabel text="Wireless Network Configuration..." position="90,50" size="600,32" font="Semiboldit;32" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
286                 <ePixmap pixmap="Vu_HD/icons/clock.png" position="750,55" zPosition="1" size="20,20" alphatest="blend" />
287                 <widget source="global.CurrentTime" render="Label" position="770,57" zPosition="1" size="50,20" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" halign="right" transparent="1">
288                         <convert type="ClockToText">Format:%H:%M</convert>
289                 </widget>
290                 <ePixmap pixmap="Vu_HD/buttons/red.png" position="45,98" size="25,25" alphatest="blend" />
291                 <ePixmap pixmap="Vu_HD/buttons/green.png" position="240,98" size="25,25" alphatest="blend" />
292                 <widget source="key_red" render="Label" position="66,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
293                 <widget source="key_grean" render="Label" position="268,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
294                 <ePixmap pixmap="Vu_HD/border_menu.png" position="120,140" zPosition="-1" size="342,358" transparent="1" alphatest="blend" />
295                 <widget name="config" position="130,150" size="322,338" transparent="1" backgroundColor="#27d9dee2" zPosition="10" scrollbarMode="showOnDemand" />
296                 <eLabel text="IP Address : " position="500,160" size="200,26" font="Semiboldit;22" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />             
297                 <widget source="ipaddress" render="Label" position="530,190" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />             
298                 <eLabel text="NetMask : " position="500,220" size="200,26" font="Semiboldit;22" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />                
299                 <widget source="netmask" render="Label" position="530,250" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />               
300                 <eLabel text="Gateway : " position="500,280" size="200,26" font="Semiboldit;22" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />                
301                 <widget source="gateway" render="Label" position="530,310" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />               
302         </screen>"""
303
304         def __init__(self, session, iface):
305                 Screen.__init__(self,session)
306                 self.session = session
307                 self["key_red"] = StaticText(_("Close"))
308                 self["key_grean"] = StaticText(_("Ok"))
309                 self["ipaddress"] = StaticText(_("[ N/A ]"))
310                 self["netmask"] = StaticText(_("[ N/A ]"))              
311                 self["gateway"] = StaticText(_("[ N/A ]"))
312                 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
313                 {
314                         "ok": self.saveWlanConfig,
315                         "green": self.saveWlanConfig,
316                         "cancel": self.keyCancel,
317                         "red": self.keyCancel,
318                 }, -2)
319                 self.iface = iface
320                 self.ssid = None
321                 self.ap_scan = None
322                 self.scan_ssid = None
323                 self.key_mgmt = None
324                 self.proto = None
325                 self.key_type = None
326                 self.encryption_key = None
327                 self.wlanscanap = None
328 #               self.scanAPcount =5
329                 self.scanAPcount =0
330                 self.list = []
331                 ConfigListScreen.__init__(self, self.list,session = self.session)
332                 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
333                 self.readWpaSupplicantConf()
334 #               iNetwork.getInterfaces()
335                 self.readWlanSettings()
336                 self.scanAPFailedTimer = eTimer()
337                 self.scanAPFailedTimer.callback.append(self.scanAPFailed)
338                 self.scanAplistTimer = eTimer()
339                 self.scanAplistTimer.callback.append(self.scanApList)
340                 self.Console = Console()
341                 self.scanAplistTimer.start(100,True)
342
343         def readWlanSettings(self):
344                 iNetwork.getAddrInet(self.iface,None)
345                 if iNetwork.getAdapterAttribute(self.iface, "up") == True:
346                         default_tmp = "on"
347                 else:
348                         default_tmp = "off"
349                 wlanconfig.usedevice = ConfigSelection(default=default_tmp, choices = [("off", _("off")), ("on", _("on"))])
350
351                 if iNetwork.getAdapterAttribute(self.iface, "dhcp"):
352                         default_tmp = "on"
353                 else:
354                         default_tmp = "off"
355                 wlanconfig.usedhcp = ConfigSelection(default=default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
356
357                 wlanconfig.ip = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0]
358
359                 wlanconfig.netmask = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0])
360                 if iNetwork.getAdapterAttribute(self.iface, "gateway"):
361                         default_tmp = "on"
362                 else:
363                         default_tmp = "off"
364                 wlanconfig.usegateway = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
365
366                 wlanconfig.gateway = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0])
367
368                 self["ipaddress"] = StaticText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "ip"))))
369                 self["netmask"] = StaticText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "netmask"))))
370                 self["gateway"] = StaticText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "gateway"))))
371
372                 if self.encryption_key is not None:
373                         default_tmp = "on"
374                 else:
375                         default_tmp = "off"
376                 wlanconfig.encrypt = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
377
378                 if self.key_mgmt=="NONE":
379                         default_tmp = "wep"
380                 elif self.key_mgmt == "WPA-PSK":
381                         if self.proto == "WPA":
382                                 default_tmp = "wpa"
383                         elif self.proto == "RSN":
384                                 default_tmp = "wpa2"
385                         elif self.proto in ( "WPA RSN", "WPA WPA2"):
386                                 default_tmp = "wpa/wpa2"
387                         else:
388                                 default_tmp = "wpa"
389                 else:
390                         default_tmp = "wep"
391
392                 wlanconfig.method = ConfigSelection(default = default_tmp, choices = [
393                         ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
394
395                 if self.key_type == 0:
396                         default_tmp = "hex"
397                 else:
398                         default_tmp = "ascii"
399                 wlanconfig.keytype = ConfigSelection(default = default_tmp, choices = [
400                         ("ascii", _("ASCII")), ("hex", _("HEX"))])
401                 default_tmp = self.encryption_key or "XXXXXXXX"
402                 wlanconfig.key = ConfigText(default = default_tmp, visible_width = 50, fixed_size = False)
403
404         def readWpaSupplicantConf(self):
405                 try:
406                         if fileExists("/etc/wpa_supplicant.conf"):
407                                 wpafd = open("/etc/wpa_supplicant.conf","r")
408                                 if wpafd >0:
409                                         data = wpafd.readline()
410                                         while len(data) > 0:
411 #                                               print "####readWpaSupplicantConf, data : ",data
412                                                 data = data.lstrip()
413                                                 if len(data) == 0:
414                                                         data = wpafd.readline()
415                                                         continue
416                                                 if data.startswith('ssid=') and len(data) > 6:
417                                                         self.ssid = data[6:-2]
418                                                 elif data.startswith('ap_scan=') :
419                                                         self.ap_scan = data[8:]
420 #                                                       print "####readWpaSupplicantConf, ap_scan : ",self.ap_scan
421                                                 elif data.startswith('scan_ssid=') and len(data) > 10:
422                                                         self.scan_ssid = data[10:-1]
423                                                 elif data.startswith('key_mgmt=') and len(data) > 9:
424                                                         self.key_mgmt = data[9:-1]
425                                                 elif data.startswith('proto=') and len(data) > 6:
426                                                         self.proto = data[6:-1]
427                                                 elif data.startswith('wep_key0="') and len(data) > 11:
428                                                         self.key_type = 1 # ascii
429                                                         self.encryption_key = data[10:-2]
430                                                 elif data.startswith('wep_key0=') and len(data) > 9:
431                                                         self.key_type = 0 # hex
432                                                         self.encryption_key = data[9:-1]
433                                                 elif data.startswith('psk="') and len(data) > 6:
434                                                         self.key_type = 1 # ascii
435                                                         self.encryption_key = data[5:-2]
436                                                 elif data.startswith('psk=') and len(data) > 4:
437                                                         self.key_type = 0 # hex
438                                                         self.encryption_key = data[4:-1]
439                                                 data = wpafd.readline()
440                                         print self.ssid,self.scan_ssid,self.key_mgmt,self.proto,self.key_type,self.encryption_key
441                                         wpafd.close()
442                                 else:
443                                         print 'read error'
444                         else:
445                                 pass
446                 except:
447                         print 'failed loading wpasupplicant.conf'
448
449         def createConfig(self):
450                 self.configList=[]
451                 self.usedeviceEntry = getConfigListEntry(_("Use Device"), wlanconfig.usedevice)
452                 self.usedhcpEntry = getConfigListEntry(_("Use DHCP"), wlanconfig.usedhcp)
453                 self.essidEntry = getConfigListEntry(_("ESSID"), wlanconfig.essid)
454                 self.hiddenessidEntry = getConfigListEntry(_("Input Hidden ESSID"), wlanconfig.hiddenessid)
455                 self.encryptEntry = getConfigListEntry(_("Encrypt"), wlanconfig.encrypt)
456                 self.methodEntry = getConfigListEntry(_("Method"), wlanconfig.method)
457                 self.keytypeEntry = getConfigListEntry(_("Key Type"), wlanconfig.keytype)
458                 self.keyEntry = getConfigListEntry(_("KEY"), wlanconfig.key)
459
460                 self.ipEntry = getConfigListEntry(_("IP"), wlanconfig.ip)
461                 self.netmaskEntry = getConfigListEntry(_("NetMask"), wlanconfig.netmask)
462
463                 self.usegatewayEntry = getConfigListEntry(_("Use Gateway"), wlanconfig.usegateway)
464                 self.gatewayEntry = getConfigListEntry(_("Gateway"), wlanconfig.gateway)
465
466                 self.configList.append( self.usedeviceEntry )
467                 if wlanconfig.usedevice.value is "on":
468                         self.configList.append( self.usedhcpEntry )
469                         if wlanconfig.usedhcp.value is "off":
470                                 self.configList.append(self.ipEntry)
471                                 self.configList.append(self.netmaskEntry)
472                                 self.configList.append(self.usegatewayEntry)
473                                 if wlanconfig.usegateway.value is "on":
474                                         self.configList.append(self.gatewayEntry)
475                         self.configList.append( self.essidEntry )
476 #                       print "#### wlanconfig.essid.value : ",wlanconfig.essid.value
477                         if wlanconfig.essid.value == 'Input hidden ESSID':
478                                 self.configList.append( self.hiddenessidEntry )
479                         self.configList.append( self.encryptEntry )
480                         if wlanconfig.encrypt.value is "on" :
481                                 self.configList.append( self.methodEntry )
482                                 self.configList.append( self.keytypeEntry )
483                                 self.configList.append( self.keyEntry )
484
485                 self["config"].list = self.configList
486                 self["config"].l.setList(self.configList)
487 #               if not self.selectionChanged in self["config"].onSelectionChanged:
488 #                       self["config"].onSelectionChanged.append(self.selectionChanged)
489
490         def scanApList(self):
491                 self.apList = []
492                 self.scanAPcount -=1
493                 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
494                 cmd = "ifconfig "+self.iface+" up"
495                 print 'cmd ',cmd
496                 os_system(cmd)
497                 self.wlanscanap = Console()
498                 cmd = "iwlist "+self.iface+" scan"
499                 print 'cmd ',cmd
500                 self.wlanscanap.ePopen(cmd, self.apListFinnished,self.apListParse)
501
502         def apListFinnished(self, result, retval,extra_args):
503                 (callback) = extra_args
504                 if self.wlanscanap is not None:
505                         if retval == 0:
506                                 self.wlanscanap = None
507                                 content = result.splitlines()
508                                 first = content[0].split()
509                                 completed = False
510                                 for x in first:
511                                         if x == 'completed':
512                                                 completed = True
513                                 if completed == True:
514                                         callback(result)
515                                 else:
516                                         callback(0)
517                         else:
518                                 callback(0)
519
520         def apListParse(self,data):
521                 global selectap
522                 if data == 0:
523                         if self.scanAPcount >0:
524                                 self.configurationmsg.close(True)
525                                 self.scanAplistTimer.start(100,True)
526                                 return
527                         else:
528                                 self.configurationmsg.close(True)
529                                 self.scanAPFailedTimer.start(500,True)
530                                 return
531                 else:
532                         self.apList = []
533 #                       self.scanAPcount =5
534                         self.scanAPcount =0
535                         list = data.splitlines()
536                         for x in list:
537                                 xx = x.lstrip()
538                                 if xx.startswith('ESSID:') and len(xx)>8:
539                                         self.apList.append(xx[7:-1])
540                         self.apList.append('Input hidden ESSID')
541 #                       print "###### selectap : ",selectap
542                         if selectap is not None and selectap in self.apList:
543                                 wlanconfig.essid = ConfigSelection(default=selectap,choices = self.apList)
544                         elif self.ap_scan is not None and self.ap_scan.strip() == '2':
545                                 wlanconfig.essid = ConfigSelection(default='Input hidden ESSID',choices = self.apList)
546                         elif self.ssid is not None and self.ssid in self.apList:
547                                 wlanconfig.essid = ConfigSelection(default=self.ssid,choices = self.apList)
548                         else:
549                                 wlanconfig.essid = ConfigSelection(choices = self.apList)
550                         if self.ssid is not None:
551                                 wlanconfig.hiddenessid = ConfigText(default = self.ssid, visible_width = 50, fixed_size = False)
552                         else:
553                                 wlanconfig.hiddenessid = ConfigText(default = "<Input ESSID>", visible_width = 50, fixed_size = False)
554                 self.configurationmsg.close(True)
555                 self.createConfig()
556
557         def scanAPFailed(self):
558                 self.session.openWithCallback(self.keyCancel ,MessageBox, _("Scan AP Failed"), MessageBox.TYPE_ERROR,10)
559
560         def keyLeft(self):
561                 ConfigListScreen.keyLeft(self)
562                 self.newConfig()
563
564         def keyRight(self):
565                 ConfigListScreen.keyRight(self)
566                 self.newConfig()
567
568         def newConfig(self):
569                 if self["config"].getCurrent() == self.usedeviceEntry or self["config"].getCurrent() == self.encryptEntry \
570                         or self["config"].getCurrent() == self.usedhcpEntry or self["config"].getCurrent() == self.usegatewayEntry \
571                         or self["config"].getCurrent() == self.essidEntry:
572                         self.createConfig()
573
574         def saveWlanConfig(self):
575                 if self["config"].isChanged():
576                         self.session.openWithCallback(self.checkNetworkShares, MessageBox, (_("Are you sure you want to restart your network interfaces?\n") ) )
577
578         def checkNetworkShares(self,ret = False):
579                 if ret == False:
580                         return
581 #               print "########## checkNetworkShares : "
582                 if not self.Console:
583                         self.Console = Console()
584                 cmd = "cat /proc/mounts"
585                 self.Console.ePopen(cmd, self.checkSharesFinished, self.confirmAnotherIfaces)
586
587         def checkSharesFinished(self, result, retval, extra_args):
588                 callback = extra_args
589                 print "checkMountsFinished : result : \n",result
590                 networks = ['nfs','smbfs','ncp','coda']
591                 for line in result.splitlines():
592                         split = line.strip().split(' ',3)
593                         if split[2] in networks:
594                                 self.session.open(MessageBox, ("NOT deconfiguring network interfaces :\n network shares still mounted\n"), type = MessageBox.TYPE_ERROR, timeout = 10)
595                                 callback(False)
596                                 return
597                 callback(True)
598
599         def confirmAnotherIfaces(self, ret = False):
600                 if ret == False:
601                         return
602                 else:
603                         num_configured_if = len(iNetwork.getConfiguredAdapters())
604                         if num_configured_if >= 1:
605                                 if num_configured_if == 1 and self.iface in iNetwork.getConfiguredAdapters():
606                                         self.writeWlanConfig(False)
607                                 else:
608                                         self.session.openWithCallback(self.writeWlanConfig, MessageBox, (_("Are you sure you want to deactive another network interfaces?\n") ) )
609                         else:
610                                 self.writeWlanConfig(False)
611
612         def writeWlanConfig(self,ret = False):
613                 if ret == True:
614                         configuredInterfaces = iNetwork.getConfiguredAdapters()
615                         for interface in configuredInterfaces:
616                                 if interface == self.iface:
617                                         continue
618                                 iNetwork.setAdapterAttribute(interface, "up", False)
619                                 iNetwork.deactivateInterface(interface)
620                 ret=self.writeWpasupplicantConf()
621                 if ret == -1:
622                         self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
623                         return
624                 elif ret == -2:
625                         self.session.open(MessageBox, _("hidden ESSID empty"), type = MessageBox.TYPE_ERROR, timeout = 10)
626                         return
627                 iffd = open("/etc/network/interfaces","r")
628                 if iffd > 0:
629                         prev_content = ""
630                         next_content = ""
631                         data = iffd.readline()
632                         status = 0
633                         while len(data) >0 :
634                                 if data.startswith('iface '+self.iface) or data.startswith('auto '+self.iface):
635                                         status = 1
636                                         data = iffd.readline()
637                                         continue
638                                 elif not data.startswith('auto lo') and data.startswith('auto '):
639                                         if ret == True or data[5:] not in iNetwork.getConfiguredAdapters():
640                                                 data = iffd.readline()
641                                                 continue
642                                 if status == 1 and data.startswith('iface ') or data.startswith('auto '):
643                                         status = 2
644                                 if status == 0:
645                                         prev_content += data
646                                 elif status == 2:
647                                         next_content += data
648                                 data = iffd.readline()
649                         iffd.close()
650                         iffd = open("/etc/network/interfaces","w")
651                         if iffd > 0 :
652                                 if prev_content == "":
653                                         prev_content = "# automatically generated by STB\n"
654                                         prev_content += "# do Not change manually!\n\n"
655                                         prev_content += "auto lo\n"
656                                         prev_content += "iface lo inet loopback\n\n"
657                                 iffd.write(prev_content)
658                                 if wlanconfig.usedevice.value=="on":
659                                         iNetwork.setAdapterAttribute(self.iface, "up", True)
660                                         contents = "auto "+self.iface+"\n"
661                                         contents += "iface "+self.iface+" inet "
662                                         if wlanconfig.usedhcp.value =="on":
663                                                 iNetwork.setAdapterAttribute(self.iface, "dhcp", True)                                  
664                                                 contents +="dhcp\n"
665                                         else:
666                                                 iNetwork.setAdapterAttribute(self.iface, "dhcp", False)
667                                                 contents +="static\n"
668 #                                               print wlanconfig.ip.value
669                                                 iNetwork.setAdapterAttribute(self.iface, "ip", wlanconfig.ip.value)
670                                                 iNetwork.setAdapterAttribute(self.iface, "netmask", wlanconfig.netmask.value)                                           
671                                                 contents +="\taddress "+ self.formatip(wlanconfig.ip.value)+"\n"
672                                                 contents +="\tnetmask "+ self.formatip(wlanconfig.netmask.value)+"\n"
673                                                 if wlanconfig.usegateway.value == "on":
674                                                         iNetwork.setAdapterAttribute(self.iface, "gateway", wlanconfig.gateway.value)                   
675                                                         contents +="\tgateway "+ self.formatip(wlanconfig.gateway.value)+"\n"
676                                         contents += "\tpre-up wpa_supplicant -i"+self.iface+" -c/etc/wpa_supplicant.conf -B -D"+iNetwork.detectWlanModule(self.iface)+"\n"
677                                         contents += "\tpost-down wpa_cli terminate\n\n"
678                                         iffd.write(contents)
679                                 else:
680                                         iNetwork.setAdapterAttribute(self.iface, "up", False)
681                                         iNetwork.deactivateInterface(self.iface)
682                                 iffd.write(next_content)
683                                 iffd.close()
684                 else :
685                         self.session.open(MessageBox, _("/etc/network/interfaces open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
686                         return
687                 iNetwork.restartNetwork(self.updateCurrentInterfaces)
688                 self.configurationmsg = None
689                 self.configurationmsg = self.session.openWithCallback(self.configFinished, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
690
691         def writeWpasupplicantConf(self):
692                 wpafd = open("/etc/wpa_supplicant.conf","w")
693                 if wpafd > 0:
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
699                         if wlanconfig.essid.value == 'Input hidden ESSID':
700                                 contents += "ap_scan=2\n"
701                         else :
702                                 contents += "ap_scan=1\n"
703                         contents += "network={\n"
704                         if wlanconfig.essid.value == 'Input hidden ESSID':
705                                 if len(wlanconfig.hiddenessid.value) == 0:
706                                         wpafd.close()
707                                         return -2
708                                 contents += "\tssid=\""+wlanconfig.hiddenessid.value+"\"\n"
709                         else :
710                                 contents += "\tssid=\""+wlanconfig.essid.value+"\"\n"
711                         contents += "\tscan_ssid=0\n"
712                         if wlanconfig.encrypt.value == "on":
713                                 if wlanconfig.method.value =="wep":
714                                         contents += "\tkey_mgmt=NONE\n"
715                                         contents += "\twep_key0="
716                                 elif wlanconfig.method.value == "wpa":
717                                         contents += "\tkey_mgmt=WPA-PSK\n"
718                                         contents += "\tproto=WPA\n"
719                                         contents += "\tpairwise=CCMP TKIP\n"
720                                         contents += "\tgroup=CCMP TKIP\n"
721                                         contents += "\tpsk="
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"
727                                         contents += "\tpsk="
728                                 else:
729                                         contents += "\tkey_mgmt=WPA-PSK\n"
730                                         contents += "\tproto=WPA RSN\n"
731                                         contents += "\tpairwise=CCMP TKIP\n"
732                                         contents += "\tgroup=CCMP TKIP\n"
733                                         contents += "\tpsk="
734                                 if wlanconfig.keytype.value == "ascii":
735                                         contents += "\""+wlanconfig.key.value+"\"\n"
736                                 else:
737                                         contents += wlanconfig.key.value+"\n"
738                         else:
739                                 contents += "\tkey_mgmt=NONE\n"
740                         contents += "}\n"
741                         print "content = \n"+contents
742                         wpafd.write(contents)
743                         wpafd.close()
744                         return 0
745                 else :
746                         self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
747                         return -1
748         def updateCurrentInterfaces(self,ret):
749                 if ret is True:
750                         iNetwork.getInterfaces(self.configurationMsgClose)
751
752         def configurationMsgClose(self,ret):
753                 if ret is True and self.configurationmsg is not None:
754                         self.configurationmsg.close(True)
755
756         def configFinished(self,data):
757                 global selectap
758                 if data is True:
759                         self.session.openWithCallback(self.configFinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
760                         selectap = wlanconfig.essid.value
761
762         def configFinishedCB(self,data):
763                 if data is not None:
764                         if data is True:
765                                 self.close()
766         
767         def formatip(self, iplist):
768                 list = []
769                 list = iplist
770                 try:
771                         if len(iplist) == 4:
772                                 result = str(iplist[0])+"."+str(iplist[1])+"."+str(iplist[2])+"."+str(iplist[3])
773                         else:
774                                 result ="0.0.0.0"
775                         return result
776                 except:
777                         return "[N/A]"
778                         
779         def keyCancelConfirm(self, result):
780                 if not result:
781                         return
782                 if self.oldInterfaceState is False:
783                         iNetwork.deactivateInterface(self.iface,self.keyCancelCB)
784                 else:
785                         self.close()
786
787         def keyCancel(self,yesno = True):
788                 if self["config"].isChanged():
789                         self.session.openWithCallback(self.keyCancelConfirm, MessageBox, _("Really close without saving settings?"))
790                 else:
791                         self.keyCancelConfirm(True)
792
793         def keyCancelCB(self,data):
794                 if data is not None:
795                         if data is True:
796                                 self.close()
797
798 #       def selectionChanged(self):
799 #               current = self["config"].getCurrent()
800 #               print current
801
802 class WlanScanAp(Screen,HelpableScreen):
803         skin = """
804         <screen name="WlanScanAp" position="209,48" size="865,623" title="Wireless Network Configuration..." flags="wfNoBorder" backgroundColor="transparent">
805                 <ePixmap pixmap="Vu_HD/Bg_EPG_view.png" zPosition="-1" position="0,0" size="865,623" alphatest="on" />
806                 <ePixmap pixmap="Vu_HD/menu/ico_title_Setup.png" position="32,41" size="40,40" alphatest="blend"  transparent="1" />
807                 <eLabel text="Wireless Network AP Scan..." position="90,50" size="600,32" font="Semiboldit;32" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
808                 <ePixmap pixmap="Vu_HD/icons/clock.png" position="750,55" zPosition="1" size="20,20" alphatest="blend" />
809                 <widget source="global.CurrentTime" render="Label" position="770,57" zPosition="1" size="50,20" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" halign="right" transparent="1">
810                         <convert type="ClockToText">Format:%H:%M</convert>
811                 </widget>
812                 <ePixmap pixmap="Vu_HD/buttons/red.png" position="45,98" size="25,25" alphatest="blend" />
813                 <ePixmap pixmap="Vu_HD/buttons/green.png" position="240,98" size="25,25" alphatest="blend" />
814                 <ePixmap pixmap="Vu_HD/buttons/blue.png" position="630,98" size="25,25" alphatest="blend" />
815                 <widget source="key_red" render="Label" position="66,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
816                 <widget source="key_green" render="Label" position="268,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
817                 <widget source="key_blue" render="Label" position="665,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
818                 <ePixmap pixmap="Vu_HD/border_menu.png" position="120,140" zPosition="-1" size="342,358" transparent="1" alphatest="blend" />
819                 <widget name="menulist" position="130,150" size="322,338" transparent="1" backgroundColor="#27d9dee2" zPosition="10" scrollbarMode="showOnDemand" />
820                 <widget source="Address" render="Label" position="490,220" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />               
821                 <widget source="ESSID" render="Label" position="490,250" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />
822                 <widget source="Protocol" render="Label" position="490,280" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />      
823                 <widget source="Frequency" render="Label" position="490,310" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />     
824                 <widget source="Encryption key" render="Label" position="490,340" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />        
825                 <widget source="BitRate" render="Label" position="490,370" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />
826         </screen>"""
827
828         def __init__(self, session, iface):
829                 Screen.__init__(self,session)
830                 HelpableScreen.__init__(self)
831                 self.session = session
832                 self.iface = iface
833                 self.wlanscanap = None
834 #               self.scanAPcount = 5
835                 self.scanAPcount = 0
836                 self.apList = {}
837                 self.SetApList = []
838
839                 self["WizardActions"] = HelpableActionMap(self, "WizardActions",
840                 {
841                         "up": (self.up, _("move up to previous entry")),
842                         "down": (self.down, _("move down to next entry")),
843                         "left": (self.left, _("move up to first entry")),
844                         "right": (self.right, _("move down to last entry")),
845                 })
846
847                 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
848                 {
849                         "cancel": (self.close, _("exit")),
850                         "ok": (self.ok, "select AP"),
851                 })
852
853                 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
854                 {
855                         "red": (self.close, _("exit")),
856                         "green": (self.ok, "select AP"),
857                         "blue": (self.startWlanConfig, "Edit Wireless settings"),
858                 })
859
860                 self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
861                 {
862                         "ok": self.ok,
863                         "back": self.close,
864                         "up": self.up,
865                         "down": self.down,
866                         "red": self.close,
867                         "left": self.left,
868                         "right": self.right,
869                 }, -2)
870
871                 self["menulist"] = MenuList(self.SetApList)
872                 self["key_red"] = StaticText(_("Close"))
873                 self["key_green"] = StaticText(_("Select"))
874                 self["key_blue"] = StaticText(_("EditSetting"))
875                 self["Address"] = StaticText(_("Scanning AP List.."))
876                 self["ESSID"] = StaticText(_("Wait a moment"))
877                 self["Protocol"] = StaticText(" ")
878                 self["Frequency"] = StaticText(" ")
879                 self["Encryption key"] = StaticText(" ")
880                 self["BitRate"] = StaticText(" ")
881                 self.scanAPFailedTimer = eTimer()
882                 self.scanAPFailedTimer.callback.append(self.scanAPFailed)
883                 self.scanAplistTimer = eTimer()
884                 self.scanAplistTimer.callback.append(self.scanApList)
885                 self.scanAplistTimer.start(100,True)
886                 
887         def left(self):
888                 self["menulist"].pageUp()
889                 self.displayApInfo()
890         
891         def right(self):
892                 self["menulist"].pageDown()
893                 self.displayApInfo()
894
895         def up(self):
896                 self["menulist"].up()
897                 self.displayApInfo()
898                 
899         def down(self):
900                 self["menulist"].down()
901                 self.displayApInfo()
902
903         def ok(self):
904                 global selectap
905                 selectAp=self["menulist"].getCurrent()[0]
906                 selectap = selectAp
907                 self.close()
908
909         def startWlanConfig(self):
910                 global selectap
911                 selectAp=self["menulist"].getCurrent()[0]
912                 selectap = selectAp
913                 self.session.open(WlanConfig,self.iface)
914 #               self.close()
915
916         def scanApList(self):
917         #       print "self.scanAPcount : ",self.scanAPcount
918                 self.apList = {}
919                 self.SetApList = []
920                 self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
921                 self.scanAPcount -=1
922                 os_system('ifconfig '+self.iface+" up")
923                 self.wlanscanap = Console()
924                 cmd = "iwlist "+self.iface+" scan"
925                 print cmd
926                 self.wlanscanap.ePopen(cmd, self.iwlistfinnished,self.APListParse)
927
928         def iwlistfinnished(self, result, retval,extra_args):
929 #               print "iwlistfinnished"
930                 (statecallback) = extra_args
931                 if self.wlanscanap is not None:
932 #                       print "retval = ",retval
933                         if retval == 0:
934                                 self.wlanscanap = None
935                                 content = result.splitlines()
936                                 first = content[0].split()
937                                 completed = False
938                                 for x in first:
939                                         if x == 'completed':
940                                                 completed = True
941                                 if completed == True:
942                                         statecallback(result)
943                                 else:
944                                         statecallback(0)
945                         else:
946                                 statecallback(0)
947
948         def APListParse(self,data):
949                 if data == 0:
950                         if self.scanAPcount >0:
951                                 self.configurationmsg.close(True)
952                                 self.scanAplistTimer.start(100,True)
953                                 return
954                         else:
955                                 self.configurationmsg.close(True)
956                                 self.scanAPFailedTimer.start(500,True)
957                                 return
958                 else:
959 #                       print data
960                         self.apList = {}
961 #                       self.scanAPcount =5
962                         self.scanAPcount =0
963                         list = data.splitlines()
964                         for line in list:
965 #                               print "line : ",line
966                                 if line.strip().startswith("Cell"): #  Cell 01 - Address: 00:26:66:5C:EF:24
967                                         parts = line.strip().split(" ")
968                                         current_ap_id = int(parts[1])
969                                         self.apList[current_ap_id]={}
970                                         self.apList[current_ap_id]["Address"]=parts[4]
971                                 elif line.strip().startswith("ESSID"):
972                                         self.apList[current_ap_id]["ESSID"]=line.strip()[6:].strip('"')
973                                         self.SetApList.append( (self.apList[current_ap_id]["ESSID"],current_ap_id) )
974                                 elif line.strip().startswith("Protocol"):
975                                         self.apList[current_ap_id]["Protocol"]=line.strip()[9:]
976                                 elif line.strip().startswith("Frequency"):
977                                         self.apList[current_ap_id]["Frequency"]=line.strip()[10:]
978                                 elif line.strip().startswith("Encryption key"):
979                                         self.apList[current_ap_id]["Encryption key"]=line.strip()[15:]
980                                 elif line.strip().startswith("Bit Rates"):
981                                         self.apList[current_ap_id]["BitRate"]=line.strip()[10:]
982                         print self.apList
983                         print len(self.apList)
984                 self.configurationmsg.close(True)
985                 self.displayApInfo()
986
987         def scanAPFailed(self):
988                 self.session.openWithCallback(self.ScanAPclose,MessageBox, _("Scan AP Failed"), MessageBox.TYPE_ERROR,10)
989
990         def displayApInfo(self):
991                 if len(self.apList) >0:
992                         self["menulist"].setList(self.SetApList)
993                         index = self["menulist"].getCurrent()[1]
994                         for key in ["Address", "ESSID", "Protocol", "Frequency", "Encryption key", "BitRate"]:
995                                 if self.apList[index].has_key(key):
996                                         self[key].setText((key+":  "+self.apList[index][key]))
997                                 else:
998                                         self[key].setText(("None"))
999                 else:
1000                         self.session.openWithCallback(self.ScanAPclose, MessageBox, _("No AP detected."), type = MessageBox.TYPE_INFO, timeout = 10)
1001
1002         def ScanAPclose(self,data):
1003                 self.close()
1004
1005 class NetworkAdapterTest(Screen):
1006         def __init__(self, session,iface):
1007                 Screen.__init__(self, session)
1008                 self.iface = iface
1009                 self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
1010                 self.setLabels()
1011                 self.onClose.append(self.cleanup)
1012                 self.onHide.append(self.cleanup)
1013                 
1014                 self["updown_actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
1015                 {
1016                         "ok": self.KeyOK,
1017                         "blue": self.KeyOK,
1018                         "up": lambda: self.updownhandler('up'),
1019                         "down": lambda: self.updownhandler('down'),
1020                 
1021                 }, -2)
1022                 
1023                 self["shortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1024                 {
1025                         "red": self.cancel,
1026                         "back": self.cancel,
1027                 }, -2)
1028                 self["infoshortcuts"] = ActionMap(["ShortcutActions","WizardActions"],
1029                 {
1030                         "red": self.closeInfo,
1031                         "back": self.closeInfo,
1032                 }, -2)
1033                 self["shortcutsgreen"] = ActionMap(["ShortcutActions"],
1034                 {
1035                         "green": self.KeyGreen,
1036                 }, -2)
1037                 self["shortcutsgreen_restart"] = ActionMap(["ShortcutActions"],
1038                 {
1039                         "green": self.KeyGreenRestart,
1040                 }, -2)
1041                 self["shortcutsyellow"] = ActionMap(["ShortcutActions"],
1042                 {
1043                         "yellow": self.KeyYellow,
1044                 }, -2)
1045                 
1046                 self["shortcutsgreen_restart"].setEnabled(False)
1047                 self["updown_actions"].setEnabled(False)
1048                 self["infoshortcuts"].setEnabled(False)
1049                 self.onClose.append(self.delTimer)      
1050                 self.onLayoutFinish.append(self.layoutFinished)
1051                 self.steptimer = False
1052                 self.nextstep = 0
1053                 self.activebutton = 0
1054                 self.nextStepTimer = eTimer()
1055                 self.nextStepTimer.callback.append(self.nextStepTimerFire)
1056
1057         def cancel(self):
1058                 if self.oldInterfaceState is False:
1059                         iNetwork.setAdapterAttribute(self.iface, "up", self.oldInterfaceState)
1060                         iNetwork.deactivateInterface(self.iface)
1061                 self.close()
1062
1063         def closeInfo(self):
1064                 self["shortcuts"].setEnabled(True)              
1065                 self["infoshortcuts"].setEnabled(False)
1066                 self["InfoText"].hide()
1067                 self["InfoTextBorder"].hide()
1068                 self["key_red"].setText(_("Close"))
1069
1070         def delTimer(self):
1071                 del self.steptimer
1072                 del self.nextStepTimer
1073
1074         def nextStepTimerFire(self):
1075                 self.nextStepTimer.stop()
1076                 self.steptimer = False
1077                 self.runTest()
1078
1079         def updownhandler(self,direction):
1080                 if direction == 'up':
1081                         if self.activebutton >=2:
1082                                 self.activebutton -= 1
1083                         else:
1084                                 self.activebutton = 6
1085                         self.setActiveButton(self.activebutton)
1086                 if direction == 'down':
1087                         if self.activebutton <=5:
1088                                 self.activebutton += 1
1089                         else:
1090                                 self.activebutton = 1
1091                         self.setActiveButton(self.activebutton)
1092
1093         def setActiveButton(self,button):
1094                 if button == 1:
1095                         self["EditSettingsButton"].setPixmapNum(0)
1096                         self["EditSettings_Text"].setForegroundColorNum(0)
1097                         self["NetworkInfo"].setPixmapNum(0)
1098                         self["NetworkInfo_Text"].setForegroundColorNum(1)
1099                         self["AdapterInfo"].setPixmapNum(1)               # active
1100                         self["AdapterInfo_Text"].setForegroundColorNum(2) # active
1101                 if button == 2:
1102                         self["AdapterInfo_Text"].setForegroundColorNum(1)
1103                         self["AdapterInfo"].setPixmapNum(0)
1104                         self["DhcpInfo"].setPixmapNum(0)
1105                         self["DhcpInfo_Text"].setForegroundColorNum(1)
1106                         self["NetworkInfo"].setPixmapNum(1)               # active
1107                         self["NetworkInfo_Text"].setForegroundColorNum(2) # active
1108                 if button == 3:
1109                         self["NetworkInfo"].setPixmapNum(0)
1110                         self["NetworkInfo_Text"].setForegroundColorNum(1)
1111                         self["IPInfo"].setPixmapNum(0)
1112                         self["IPInfo_Text"].setForegroundColorNum(1)
1113                         self["DhcpInfo"].setPixmapNum(1)                  # active
1114                         self["DhcpInfo_Text"].setForegroundColorNum(2)    # active
1115                 if button == 4:
1116                         self["DhcpInfo"].setPixmapNum(0)
1117                         self["DhcpInfo_Text"].setForegroundColorNum(1)
1118                         self["DNSInfo"].setPixmapNum(0)
1119                         self["DNSInfo_Text"].setForegroundColorNum(1)
1120                         self["IPInfo"].setPixmapNum(1)                  # active
1121                         self["IPInfo_Text"].setForegroundColorNum(2)    # active                
1122                 if button == 5:
1123                         self["IPInfo"].setPixmapNum(0)
1124                         self["IPInfo_Text"].setForegroundColorNum(1)
1125                         self["EditSettingsButton"].setPixmapNum(0)
1126                         self["EditSettings_Text"].setForegroundColorNum(0)
1127                         self["DNSInfo"].setPixmapNum(1)                 # active
1128                         self["DNSInfo_Text"].setForegroundColorNum(2)   # active
1129                 if button == 6:
1130                         self["DNSInfo"].setPixmapNum(0)
1131                         self["DNSInfo_Text"].setForegroundColorNum(1)
1132                         self["EditSettingsButton"].setPixmapNum(1)         # active
1133                         self["EditSettings_Text"].setForegroundColorNum(2) # active
1134                         self["AdapterInfo"].setPixmapNum(0)
1135                         self["AdapterInfo_Text"].setForegroundColorNum(1)
1136                         
1137         def runTest(self):
1138                 next = self.nextstep
1139                 if next == 0:
1140                         self.doStep1()
1141                 elif next == 1:
1142                         self.doStep2()
1143                 elif next == 2:
1144                         self.doStep3()
1145                 elif next == 3:
1146                         self.doStep4()
1147                 elif next == 4:
1148                         self.doStep5()
1149                 elif next == 5:
1150                         self.doStep6()
1151                 self.nextstep += 1
1152
1153         def doStep1(self):
1154                 self.steptimer = True
1155                 self.nextStepTimer.start(3000)
1156                 self["key_yellow"].setText(_("Stop test"))
1157
1158         def doStep2(self):
1159                 self["Adapter"].setText(iNetwork.getFriendlyAdapterName(self.iface))
1160                 self["Adapter"].setForegroundColorNum(2)
1161                 self["Adaptertext"].setForegroundColorNum(1)
1162                 self["AdapterInfo_Text"].setForegroundColorNum(1)
1163                 self["AdapterInfo_OK"].show()
1164                 self.steptimer = True
1165                 self.nextStepTimer.start(3000)
1166
1167         def doStep3(self):
1168                 self["Networktext"].setForegroundColorNum(1)
1169                 self["Network"].setText(_("Please wait..."))
1170                 self.AccessPointInfo(self.iface)
1171                 self["NetworkInfo_Text"].setForegroundColorNum(1)
1172                 self.steptimer = True
1173                 self.nextStepTimer.start(3000)
1174
1175         def doStep4(self):
1176                 self["Dhcptext"].setForegroundColorNum(1)
1177                 if iNetwork.getAdapterAttribute(self.iface, 'dhcp') is True:
1178                         self["Dhcp"].setForegroundColorNum(2)
1179                         self["Dhcp"].setText(_("enabled"))
1180                         self["DhcpInfo_Check"].setPixmapNum(0)
1181                 else:
1182                         self["Dhcp"].setForegroundColorNum(1)
1183                         self["Dhcp"].setText(_("disabled"))
1184                         self["DhcpInfo_Check"].setPixmapNum(1)
1185                 self["DhcpInfo_Check"].show()
1186                 self["DhcpInfo_Text"].setForegroundColorNum(1)
1187                 self.steptimer = True
1188                 self.nextStepTimer.start(3000)
1189
1190         def doStep5(self):
1191                 self["IPtext"].setForegroundColorNum(1)
1192                 self["IP"].setText(_("Please wait..."))
1193                 iNetwork.checkNetworkState(self.NetworkStatedataAvail)
1194
1195         def doStep6(self):
1196                 self.steptimer = False
1197                 self.nextStepTimer.stop()
1198                 self["DNStext"].setForegroundColorNum(1)
1199                 self["DNS"].setText(_("Please wait..."))
1200                 iNetwork.checkDNSLookup(self.DNSLookupdataAvail)
1201
1202         def KeyGreen(self):
1203                 self["shortcutsgreen"].setEnabled(False)
1204                 self["shortcutsyellow"].setEnabled(True)
1205                 self["updown_actions"].setEnabled(False)
1206                 self["key_yellow"].setText("")
1207                 self["key_green"].setText("")
1208                 self.steptimer = True
1209                 self.nextStepTimer.start(1000)
1210
1211         def KeyGreenRestart(self):
1212                 self.nextstep = 0
1213                 self.layoutFinished()
1214                 self["Adapter"].setText((""))
1215                 self["Network"].setText((""))
1216                 self["Dhcp"].setText((""))
1217                 self["IP"].setText((""))
1218                 self["DNS"].setText((""))
1219                 self["AdapterInfo_Text"].setForegroundColorNum(0)
1220                 self["NetworkInfo_Text"].setForegroundColorNum(0)
1221                 self["DhcpInfo_Text"].setForegroundColorNum(0)
1222                 self["IPInfo_Text"].setForegroundColorNum(0)
1223                 self["DNSInfo_Text"].setForegroundColorNum(0)
1224                 self["shortcutsgreen_restart"].setEnabled(False)
1225                 self["shortcutsgreen"].setEnabled(False)
1226                 self["shortcutsyellow"].setEnabled(True)
1227                 self["updown_actions"].setEnabled(False)
1228                 self["key_yellow"].setText("")
1229                 self["key_green"].setText("")
1230                 self.steptimer = True
1231                 self.nextStepTimer.start(1000)
1232
1233         def KeyOK(self):
1234                 self["infoshortcuts"].setEnabled(True)
1235                 self["shortcuts"].setEnabled(False)
1236                 if self.activebutton == 1: # Adapter Check
1237                         self["InfoText"].setText(_("This test detects your configured Wireless LAN-Adapter."))
1238                         self["InfoTextBorder"].show()
1239                         self["InfoText"].show()
1240                         self["key_red"].setText(_("Back"))
1241                 if self.activebutton == 2: #LAN Check
1242                         self["InfoText"].setText(_("This test checks whether a network cable is connected to your Wireless LAN-Adapter."))
1243                         self["InfoTextBorder"].show()
1244                         self["InfoText"].show()
1245                         self["key_red"].setText(_("Back"))
1246                 if self.activebutton == 3: #DHCP Check
1247                         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."))
1248                         self["InfoTextBorder"].show()
1249                         self["InfoText"].show()
1250                         self["key_red"].setText(_("Back"))
1251                 if self.activebutton == 4: # IP Check
1252                         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"))
1253                         self["InfoTextBorder"].show()
1254                         self["InfoText"].show()
1255                         self["key_red"].setText(_("Back"))
1256                 if self.activebutton == 5: # DNS Check
1257                         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"))
1258                         self["InfoTextBorder"].show()
1259                         self["InfoText"].show()
1260                         self["key_red"].setText(_("Back"))
1261                 if self.activebutton == 6: # Edit Settings
1262                         self.session.open(WlanConfig,self.iface)
1263                         self["shortcuts"].setEnabled(True)              
1264                         self["infoshortcuts"].setEnabled(False)
1265
1266         def KeyYellow(self):
1267                 self.nextstep = 0
1268                 self["shortcutsgreen_restart"].setEnabled(True)
1269                 self["shortcutsgreen"].setEnabled(False)
1270                 self["shortcutsyellow"].setEnabled(False)
1271                 self["key_green"].setText(_("Restart test"))
1272                 self["key_yellow"].setText("")
1273                 self.steptimer = False
1274                 self.nextStepTimer.stop()
1275
1276         def layoutFinished(self):
1277                 self.setTitle(_("Network test: ") + iNetwork.getFriendlyAdapterName(self.iface) )
1278                 self["shortcutsyellow"].setEnabled(False)
1279                 self["AdapterInfo_OK"].hide()
1280                 self["NetworkInfo_Check"].hide()
1281                 self["DhcpInfo_Check"].hide()
1282                 self["IPInfo_Check"].hide()
1283                 self["DNSInfo_Check"].hide()
1284                 self["EditSettings_Text"].hide()
1285                 self["EditSettingsButton"].hide()
1286                 self["InfoText"].hide()
1287                 self["InfoTextBorder"].hide()
1288                 self["key_yellow"].setText("")
1289
1290         def setLabels(self):
1291                 self["Adaptertext"] = MultiColorLabel(_("LAN Adapter"))
1292                 self["Adapter"] = MultiColorLabel()
1293                 self["AdapterInfo"] = MultiPixmap()
1294                 self["AdapterInfo_Text"] = MultiColorLabel(_("Show Info"))
1295                 self["AdapterInfo_OK"] = Pixmap()
1296                 
1297                 if self.iface in iNetwork.wlan_interfaces:
1298                         self["Networktext"] = MultiColorLabel(_("Wireless Network"))
1299                 else:
1300                         self["Networktext"] = MultiColorLabel(_("Local Network"))
1301                 
1302                 self["Network"] = MultiColorLabel()
1303                 self["NetworkInfo"] = MultiPixmap()
1304                 self["NetworkInfo_Text"] = MultiColorLabel(_("Show Info"))
1305                 self["NetworkInfo_Check"] = MultiPixmap()
1306                 
1307                 self["Dhcptext"] = MultiColorLabel(_("DHCP"))
1308                 self["Dhcp"] = MultiColorLabel()
1309                 self["DhcpInfo"] = MultiPixmap()
1310                 self["DhcpInfo_Text"] = MultiColorLabel(_("Show Info"))
1311                 self["DhcpInfo_Check"] = MultiPixmap()
1312                 
1313                 self["IPtext"] = MultiColorLabel(_("IP Address"))
1314                 self["IP"] = MultiColorLabel()
1315                 self["IPInfo"] = MultiPixmap()
1316                 self["IPInfo_Text"] = MultiColorLabel(_("Show Info"))
1317                 self["IPInfo_Check"] = MultiPixmap()
1318                 
1319                 self["DNStext"] = MultiColorLabel(_("Nameserver"))
1320                 self["DNS"] = MultiColorLabel()
1321                 self["DNSInfo"] = MultiPixmap()
1322                 self["DNSInfo_Text"] = MultiColorLabel(_("Show Info"))
1323                 self["DNSInfo_Check"] = MultiPixmap()
1324                 
1325                 self["EditSettings_Text"] = MultiColorLabel(_("Edit settings"))
1326                 self["EditSettingsButton"] = MultiPixmap()
1327                 
1328                 self["key_red"] = StaticText(_("Close"))
1329                 self["key_green"] = StaticText(_("Start test"))
1330                 self["key_yellow"] = StaticText(_("Stop test"))
1331                 
1332                 self["InfoTextBorder"] = Pixmap()
1333                 self["InfoText"] = Label()
1334
1335         def NetworkStatedataAvail(self,data):
1336                 if data <= 2:
1337                         self["IP"].setForegroundColorNum(2)
1338                         self["IP"].setText(_("confirmed"))
1339                         self["IPInfo_Check"].setPixmapNum(0)
1340                 else:
1341                         self["IP"].setForegroundColorNum(1)
1342                         self["IP"].setText(_("unconfirmed"))
1343                         self["IPInfo_Check"].setPixmapNum(1)
1344                 self["IPInfo_Check"].show()
1345                 self["IPInfo_Text"].setForegroundColorNum(1)            
1346                 self.steptimer = True
1347                 self.nextStepTimer.start(3000)          
1348                 
1349         def DNSLookupdataAvail(self,data):
1350                 if data <= 2:
1351                         self["DNS"].setForegroundColorNum(2)
1352                         self["DNS"].setText(_("confirmed"))
1353                         self["DNSInfo_Check"].setPixmapNum(0)
1354                 else:
1355                         self["DNS"].setForegroundColorNum(1)
1356                         self["DNS"].setText(_("unconfirmed"))
1357                         self["DNSInfo_Check"].setPixmapNum(1)
1358                 self["DNSInfo_Check"].show()
1359                 self["DNSInfo_Text"].setForegroundColorNum(1)
1360                 self["EditSettings_Text"].show()
1361                 self["EditSettingsButton"].setPixmapNum(1)
1362                 self["EditSettings_Text"].setForegroundColorNum(2) # active
1363                 self["EditSettingsButton"].show()
1364                 self["key_yellow"].setText("")
1365                 self["key_green"].setText(_("Restart test"))
1366                 self["shortcutsgreen"].setEnabled(False)
1367                 self["shortcutsgreen_restart"].setEnabled(True)
1368                 self["shortcutsyellow"].setEnabled(False)
1369                 self["updown_actions"].setEnabled(True)
1370                 self.activebutton = 6
1371
1372         def getInfoCB(self,status):
1373                 if status is not None:
1374                         if status.startswith("No Connection") or status.startswith("Not-Associated") or status == False:
1375                                 self["Network"].setForegroundColorNum(1)
1376                                 self["Network"].setText(_("disconnected"))
1377                                 self["NetworkInfo_Check"].setPixmapNum(1)
1378                                 self["NetworkInfo_Check"].show()
1379                         else:
1380                                 self["Network"].setForegroundColorNum(2)
1381                                 self["Network"].setText(_("connected"))
1382                                 self["NetworkInfo_Check"].setPixmapNum(0)
1383                                 self["NetworkInfo_Check"].show()
1384                                                 
1385         def cleanup(self):
1386                 iNetwork.stopLinkStateConsole()
1387                 iNetwork.stopDNSConsole()
1388
1389         def AccessPointInfo(self,iface):
1390                 cmd = "iwconfig %s"%iface
1391                 self.iwconfigConsole = Console()
1392                 self.iwconfigConsole.ePopen(cmd,self.readAP,self.getInfoCB)
1393
1394         def readAP(self,result,retval,extra_args):
1395                 (callback) = extra_args
1396                 self.apState = False
1397                 if self.iwconfigConsole is not None:
1398                         if retval == 0:
1399                                 self.iwconfigConsole = None
1400                                 for content in result.splitlines():
1401                                         if 'Access Point' in content:
1402                                                 self.apState = content.strip().split('Access Point: ')[1]
1403                                                 callback(self.apState)
1404                                                 return
1405                 callback(self.apState)
1406                 
1407 class Wlanstatus(Screen):
1408         skin = """
1409         <screen name="Wlanstatus" position="209,48" size="865,623" title="Wireless Network Configuration..." flags="wfNoBorder" backgroundColor="transparent">
1410                 <ePixmap pixmap="Vu_HD/Bg_EPG_view.png" zPosition="-1" position="0,0" size="865,623" alphatest="on" />
1411                 <ePixmap pixmap="Vu_HD/menu/ico_title_Setup.png" position="32,41" size="40,40" alphatest="blend"  transparent="1" />
1412                 <eLabel text="Wireless Network Status..." position="90,50" size="600,32" font="Semiboldit;32" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
1413                 <ePixmap pixmap="Vu_HD/icons/clock.png" position="750,55" zPosition="1" size="20,20" alphatest="blend" />
1414                 <widget source="global.CurrentTime" render="Label" position="770,57" zPosition="1" size="50,20" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" halign="right" transparent="1">
1415                         <convert type="ClockToText">Format:%H:%M</convert>
1416                 </widget>
1417                 <ePixmap pixmap="Vu_HD/buttons/red.png" position="45,98" size="25,25" alphatest="blend" />
1418                 <widget source="key_red" render="Label" position="66,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
1419                 <widget source="status" render="Label" position="110,200" size="650,400" transparent="1" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" zPosition="1" />
1420         </screen>"""
1421         def __init__(self, session,iface):
1422                 Screen.__init__(self,session)
1423                 self.session = session
1424                 self.iface = iface
1425                 self["status"] = StaticText(_("Wait a moment..."))
1426                 self["key_red"] = StaticText(_("Close"))
1427                 self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
1428                 {
1429                         "ok": self.ok,
1430                         "cancel": self.close,
1431                         "red": self.close,
1432                 }, -2)
1433                 self.readstatus()
1434
1435         def readstatus(self):
1436                 self.wlanstatus = Console()
1437                 cmd1 = "iwconfig "+self.iface
1438                 self.wlanstatus.ePopen(cmd1, self.iwconfigfinnished,self.statusdisplay)
1439
1440         def iwconfigfinnished(self, result, retval,extra_args):
1441                 try:
1442                         (statecallback) = extra_args
1443                         if self.wlanstatus is not None:
1444                                 if retval == 0:
1445                                         statecallback(result)
1446                                 else:
1447                                         statecallback(0)
1448                 except:
1449                         self.close()
1450
1451
1452         def statusdisplay(self,data):
1453                 if data == 0:
1454                         self["status"].setText(_("No information..."))
1455                 else:
1456                         self["status"].setText(data)
1457
1458         def ok(self):
1459                 pass
1460
1461 def openconfig(session, **kwargs):
1462         session.open(WlanSelection)
1463
1464 def selSetup(menuid, **kwargs):
1465         list=[]
1466         if menuid != "system":
1467                 return [ ]
1468         else:
1469                 for x in iNetwork.getAdapterList():
1470                         if x.startswith('eth'):
1471                                 continue
1472                         list.append(x)
1473                 if len(list):
1474                         return [(_("Wireless LAN Setup"), openconfig, "wlansetup_config", 80)]
1475                 else:
1476                         return [ ]
1477         return [ ]
1478
1479 def Plugins(**kwargs):
1480         return  PluginDescriptor(name=_("Wireless LAN Setup"), description="Wireless LAN Setup", where = PluginDescriptor.WHERE_MENU, fnc=selSetup)