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