X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=blobdiff_plain;f=lib%2Fpython%2FPlugins%2FSystemPlugins%2FWirelessLanSetup%2Fplugin.py;h=2f1eb90c28c0eb1a7d8057e0e7abfd470ef5fbbb;hp=7e6c4c6c1953b9e1a5dbad2a7316168b514dc833;hb=b2660920e43e2f0d56be9387ba92a76ec77e58bc;hpb=c6f5865c644e03e31ec19ac0a80492981bed71c3 diff --git a/lib/python/Plugins/SystemPlugins/WirelessLanSetup/plugin.py b/lib/python/Plugins/SystemPlugins/WirelessLanSetup/plugin.py index 7e6c4c6..2f1eb90 100755 --- a/lib/python/Plugins/SystemPlugins/WirelessLanSetup/plugin.py +++ b/lib/python/Plugins/SystemPlugins/WirelessLanSetup/plugin.py @@ -27,26 +27,25 @@ from os import path as os_path, system as os_system, unlink,listdir from re import compile as re_compile, search as re_search from Tools.Directories import fileExists import time +from pythonwifi.iwlibs import Wireless +import pythonwifi.flags class WlanSelection(Screen,HelpableScreen): - skin = """ - - - - - - - Format:%H:%M - - - - - - - - - """ - + skin = """ + + + + + + + + + + + + + + """ def __init__(self, session): Screen.__init__(self,session) HelpableScreen.__init__(self) @@ -67,6 +66,13 @@ class WlanSelection(Screen,HelpableScreen): "green": (self.ok, _("select interface")), "red": (self.close, _("exit network interface list")), }) + self.updateInterfaces() + self.onClose.append(self.cleanup) + + def updateInterfaces(self): + iNetwork.config_ready = False + iNetwork.msgPlugins() + iNetwork.getInterfaces() def ok(self): # print len(self["menulist"].list) @@ -81,7 +87,7 @@ class WlanSelection(Screen,HelpableScreen): def getWlandevice(self): list = [] - for x in iNetwork.getAdapterList(): + for x in iNetwork.getInstalledAdapters(): if x.startswith('eth'): continue description=self.getAdapterDescription(x) @@ -98,7 +104,7 @@ class WlanSelection(Screen,HelpableScreen): files = listdir(classdir) if 'driver' in files: if os_path.realpath(driverdir).endswith('rtw_usb_drv'): - return _("Realtak")+ " " + _("WLAN adapter.") + return _("Realtek")+ " " + _("WLAN adapter.") elif os_path.realpath(driverdir).endswith('ath_pci'): return _("Atheros")+ " " + _("WLAN adapter.") elif os_path.realpath(driverdir).endswith('zd1211b'): @@ -114,24 +120,25 @@ class WlanSelection(Screen,HelpableScreen): else: return _("Unknown network adapter") + def cleanup(self): + iNetwork.stopGetInterfacesConsole() + class WlanSetup(Screen,HelpableScreen): - skin = """ - - - - - - - Format:%H:%M - - - - - - - - - """ + skin = """ + + + + + + + + + + + + + + """ def __init__(self, session, ifaces): Screen.__init__(self, session) HelpableScreen.__init__(self) @@ -183,6 +190,7 @@ class WlanSetup(Screen,HelpableScreen): "left": self.left, "right": self.right, }, -2) + self.onClose.append(self.cleanup) def loadDescription(self): if self["menulist"].getCurrent()[1] == 'setting': @@ -215,10 +223,11 @@ class WlanSetup(Screen,HelpableScreen): self.loadDescription() def ok(self): + self.cleanup() if self["menulist"].getCurrent()[1] == 'setting': self.session.openWithCallback(self.checklist, WlanConfig, self.iface) elif self["menulist"].getCurrent()[1] == 'scanap': - self.session.open(WlanScanAp, self.iface) + self.session.openWithCallback(self.WlanScanApCallback, WlanScanAp, self.iface) elif self["menulist"].getCurrent()[1] == 'dns': self.session.open(NameserverSetup) elif self["menulist"].getCurrent()[1] == 'status': @@ -243,6 +252,10 @@ class WlanSetup(Screen,HelpableScreen): return menu + def WlanScanApCallback(self, essid = None): + if essid is not None: + self.session.openWithCallback(self.checklist, WlanConfig, self.iface, essid) + def restartLan(self, ret = False): if (ret == True): iNetwork.restartNetwork(self.restartLanDataAvail) @@ -260,6 +273,10 @@ class WlanSetup(Screen,HelpableScreen): if data is True: self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 5, default = False) + def cleanup(self): + iNetwork.stopRestartConsole() + iNetwork.stopGetInterfacesConsole() + wlanconfig = ConfigSubsection() wlanconfig.usedevice = ConfigSelection(default = "off", choices = [ ("off", _("off")), ("on", _("on"))]) @@ -272,7 +289,7 @@ wlanconfig.method = ConfigSelection(default = "wep", choices = [ ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))]) wlanconfig.keytype = ConfigSelection(default = "ascii", choices = [ ("ascii", _("ASCII")), ("hex", _("HEX"))]) -wlanconfig.key = ConfigText(default = "XXXXXXXX", visible_width = 50, fixed_size = False) +wlanconfig.key = ConfigPassword(default = "XXXXXXXX", visible_width = 50, fixed_size = False) wlanconfig.usegateway = ConfigSelection(default = "off", choices = [ ("off", _("no")), ("on", _("yes"))]) wlanconfig.ip = ConfigIP([0,0,0,0]) @@ -281,34 +298,29 @@ wlanconfig.gateway = ConfigIP([0,0,0,0]) selectap = None class WlanConfig(Screen, ConfigListScreen, HelpableScreen): - skin = """ - - - - - - - Format:%H:%M - - - - - - - - - - - - - - """ - - def __init__(self, session, iface): + skin = """ + + + + + + + + + + + + + + + + + """ + def __init__(self, session, iface, essidSelected = None): Screen.__init__(self,session) self.session = session self["key_red"] = StaticText(_("Close")) - self["key_grean"] = StaticText(_("Ok")) + self["key_green"] = StaticText(_("Ok")) self["ipaddress"] = StaticText(_("[ N/A ]")) self["netmask"] = StaticText(_("[ N/A ]")) self["gateway"] = StaticText(_("[ N/A ]")) @@ -320,6 +332,7 @@ class WlanConfig(Screen, ConfigListScreen, HelpableScreen): "red": self.keyCancel, }, -2) self.iface = iface + self.essidSelected = essidSelected self.ssid = None self.ap_scan = None self.scan_ssid = None @@ -328,19 +341,23 @@ class WlanConfig(Screen, ConfigListScreen, HelpableScreen): self.key_type = None self.encryption_key = None self.wlanscanap = None -# self.scanAPcount =5 - self.scanAPcount =1 + self.wpaphraseconsole = None self.list = [] ConfigListScreen.__init__(self, self.list,session = self.session) self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up") self.readWpaSupplicantConf() - self.scanAPFailedTimer = eTimer() - self.scanAPFailedTimer.callback.append(self.scanAPFailed) self.scanAplistTimer = eTimer() self.scanAplistTimer.callback.append(self.scanApList) + self.emptyListMsgTimer = eTimer() + self.emptyListMsgTimer.callback.append(self.emptyListMsg) self.Console = Console() -# self.scanAplistTimer.start(100,True) - iNetwork.getInterfaces(self.readWlanSettings) + self.updateInterfaces(self.readWlanSettings) + self.onClose.append(self.cleanup) + + def updateInterfaces(self,callback = None): + iNetwork.config_ready = False + iNetwork.msgPlugins() + iNetwork.getInterfaces(callback) def readWlanSettings(self,ret=None): if ret is not True: @@ -402,8 +419,8 @@ class WlanConfig(Screen, ConfigListScreen, HelpableScreen): wlanconfig.keytype = ConfigSelection(default = default_tmp, choices = [ ("ascii", _("ASCII")), ("hex", _("HEX"))]) default_tmp = self.encryption_key or "XXXXXXXX" - wlanconfig.key = ConfigText(default = default_tmp, visible_width = 50, fixed_size = False) - self.scanAplistTimer.start(100,True) + wlanconfig.key = ConfigPassword(default = default_tmp, visible_width = 50, fixed_size = False) + self.getApList() def readWpaSupplicantConf(self): try: @@ -437,11 +454,14 @@ class WlanConfig(Screen, ConfigListScreen, HelpableScreen): elif data.startswith('psk="') and len(data) > 6: self.key_type = 1 # ascii self.encryption_key = data[5:-2] - elif data.startswith('psk=') and len(data) > 4: + elif data.startswith('#psk="') and len(data) > 6: + self.key_type = 0 # hex + self.encryption_key = data[6:-2] + elif not self.encryption_key and data.startswith('psk=') and len(data) > 4: self.key_type = 0 # hex self.encryption_key = data[4:-1] data = wpafd.readline() - print self.ssid,self.scan_ssid,self.key_mgmt,self.proto,self.key_type,self.encryption_key +# print self.ssid,self.scan_ssid,self.key_mgmt,self.proto,self.key_type,self.encryption_key wpafd.close() else: print 'read error' @@ -477,90 +497,70 @@ class WlanConfig(Screen, ConfigListScreen, HelpableScreen): if wlanconfig.usegateway.value is "on": self.configList.append(self.gatewayEntry) self.configList.append( self.essidEntry ) -# print "#### wlanconfig.essid.value : ",wlanconfig.essid.value if wlanconfig.essid.value == 'Input hidden ESSID': self.configList.append( self.hiddenessidEntry ) self.configList.append( self.encryptEntry ) if wlanconfig.encrypt.value is "on" : self.configList.append( self.methodEntry ) - self.configList.append( self.keytypeEntry ) + if wlanconfig.method.value =="wep": + self.configList.append( self.keytypeEntry ) self.configList.append( self.keyEntry ) self["config"].list = self.configList self["config"].l.setList(self.configList) -# if not self.selectionChanged in self["config"].onSelectionChanged: -# self["config"].onSelectionChanged.append(self.selectionChanged) - - def scanApList(self): - self.apList = [] - self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False) - cmd = "ifconfig "+self.iface+" up" - print 'cmd ',cmd - os_system(cmd) - self.wlanscanap = Console() - cmd = "iwlist "+self.iface+" scan" - print 'cmd ',cmd - self.wlanscanap.ePopen(cmd, self.apListFinnished,self.apListParse) - - def apListFinnished(self, result, retval,extra_args): - (callback) = extra_args - if self.wlanscanap is not None: - if retval == 0: - self.wlanscanap = None - content = result.splitlines() - first = content[0].split() - completed = False - for x in first: - if x == 'completed': - completed = True - if completed == True: - callback(result) - else: - callback(0) - else: - callback(0) - def apListParse(self,data): - global selectap - if data == 0: - if self.scanAPcount >0: - self.scanAPcount -=1 - self.configurationmsg.close(True) - time.sleep(3) - self.scanAplistTimer.start(500,True) - return - else: - self.configurationmsg.close(True) - self.scanAPFailedTimer.start(500,True) - return - else: + def getApList(self): + if self.essidSelected is None: self.apList = [] -# self.scanAPcount =5 - self.scanAPcount =0 - list = data.splitlines() - for x in list: - xx = x.lstrip() - if xx.startswith('ESSID:') and len(xx)>8 and xx[7:-1]not in self.apList: - self.apList.append(xx[7:-1]) - self.apList.append('Input hidden ESSID') -# print "###### selectap : ",selectap - if selectap is not None and selectap in self.apList: - wlanconfig.essid = ConfigSelection(default=selectap,choices = self.apList) - elif self.ap_scan is not None and self.ap_scan.strip() == '2': - wlanconfig.essid = ConfigSelection(default='Input hidden ESSID',choices = self.apList) - elif self.ssid is not None and self.ssid in self.apList: - wlanconfig.essid = ConfigSelection(default=self.ssid,choices = self.apList) - else: - wlanconfig.essid = ConfigSelection(choices = self.apList) + self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False) + self.scanAplistTimer.start(100,True) + else: + self.apList = [self.essidSelected] + wlanconfig.essid = ConfigSelection(choices = self.apList) if self.ssid is not None: wlanconfig.hiddenessid = ConfigText(default = self.ssid, visible_width = 50, fixed_size = False) else: wlanconfig.hiddenessid = ConfigText(default = "", visible_width = 50, fixed_size = False) + self.createConfig() + + def scanApList(self): + if self.oldInterfaceState is not True: + os_system("ifconfig "+self.iface+" up") + iNetwork.setAdapterAttribute(self.iface, "up", True) + Iwscanresult = None + wirelessObj = Wireless(self.iface) + try: + Iwscanresult = wirelessObj.scan() + except IOError: + print "%s Interface doesn't support scanning.."%self.iface +# self.session.open(MessageBox, "%s Interface doesn't support scanning.."%self.iface, MessageBox.TYPE_ERROR,10) self.configurationmsg.close(True) + if Iwscanresult is None: + self.emptyListMsgTimer.start(100,True) + else: + for ap in Iwscanresult: + if ap.essid not in self.apList and len(ap.essid) > 0: + self.apList.append(ap.essid) + self.apList.append('Input hidden ESSID') + if selectap is not None and selectap in self.apList: + wlanconfig.essid = ConfigSelection(default=selectap,choices = self.apList) + elif self.scan_ssid is not None and self.scan_ssid.strip() == '1': + wlanconfig.essid = ConfigSelection(default='Input hidden ESSID',choices = self.apList) + elif self.ssid is not None and self.ssid in self.apList: + wlanconfig.essid = ConfigSelection(default=self.ssid, choices = self.apList) + else: + try: + wlanconfig.essid = ConfigSelection(defalut = self.apList[0], choices = self.apList) + except: + wlanconfig.essid = ConfigSelection(choices = self.apList) + if self.ssid is not None: + wlanconfig.hiddenessid = ConfigText(default = self.ssid, visible_width = 50, fixed_size = False) + else: + wlanconfig.hiddenessid = ConfigText(default = "", visible_width = 50, fixed_size = False) self.createConfig() - def scanAPFailed(self): - self.session.openWithCallback(self.keyCancel ,MessageBox, _("Scan AP Failed"), MessageBox.TYPE_ERROR,10) + def emptyListMsg(self): + self.session.open(MessageBox, _("No AP detected."), type = MessageBox.TYPE_INFO, timeout = 10) def keyLeft(self): ConfigListScreen.keyLeft(self) @@ -573,22 +573,35 @@ class WlanConfig(Screen, ConfigListScreen, HelpableScreen): def newConfig(self): if self["config"].getCurrent() == self.usedeviceEntry or self["config"].getCurrent() == self.encryptEntry \ or self["config"].getCurrent() == self.usedhcpEntry or self["config"].getCurrent() == self.usegatewayEntry \ - or self["config"].getCurrent() == self.essidEntry: + or self["config"].getCurrent() == self.essidEntry or self["config"].getCurrent() == self.methodEntry: self.createConfig() def saveWlanConfig(self): - if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry : - self["config"].getCurrent()[1].onDeselect(self.session) - if self["config"].isChanged(): - self.session.openWithCallback(self.checkNetworkShares, MessageBox, (_("Are you sure you want to restart your network interfaces?\n") ) ) - else: - self.session.openWithCallback(self.checkNetworkShares, MessageBox, (_("Network configuration is not changed....\n\nAre you sure you want to restart your network interfaces?\n") ) ) + try: + if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry : + self["config"].getCurrent()[1].onDeselect(self.session) + if self["config"].isChanged(): + self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Are you sure you want to restart your network interfaces?\n") ) ) + else: + self.session.openWithCallback(self.checkNetworkConfig, MessageBox, (_("Network configuration is not changed....\n\nAre you sure you want to restart your network interfaces?\n") ) ) + except: + pass - def checkNetworkShares(self,ret = False): + def checkNetworkConfig(self, ret = False): if ret == False: if self["config"].getCurrent() == self.keyEntry or self["config"].getCurrent() == self.hiddenessidEntry : self["config"].getCurrent()[1].onSelect(self.session) return + if wlanconfig.essid.value == 'Input hidden ESSID': + if len(wlanconfig.hiddenessid.value) == 0: + self.session.open(MessageBox, ("PLEASE INPUT HIDDEN ESSID"), type = MessageBox.TYPE_ERROR, timeout = 10) + return + if len(wlanconfig.key.value) == 0: + self.session.open(MessageBox, ("PLEASE INPUT NETWORK KEY"), type = MessageBox.TYPE_ERROR, timeout = 10) + return + self.checkNetworkShares() + + def checkNetworkShares(self): if not self.Console: self.Console = Console() cmd = "cat /proc/mounts" @@ -596,7 +609,7 @@ class WlanConfig(Screen, ConfigListScreen, HelpableScreen): def checkSharesFinished(self, result, retval, extra_args): callback = extra_args - print "checkMountsFinished : result : \n",result +# print "checkMountsFinished : result : \n",result networks = ['nfs','smbfs','ncp','coda'] for line in result.splitlines(): split = line.strip().split(' ',3) @@ -615,13 +628,13 @@ class WlanConfig(Screen, ConfigListScreen, HelpableScreen): num_configured_if = len(iNetwork.getConfiguredAdapters()) if num_configured_if >= 1: if num_configured_if == 1 and self.iface in iNetwork.getConfiguredAdapters(): - self.writeWlanConfig(False) + self.getWpaPhrase(False) else: - self.session.openWithCallback(self.writeWlanConfig, MessageBox, _("A second configured interface has been found.\n\nDo you want to disable the second network interface?"), default = True) + self.session.openWithCallback(self.getWpaPhrase, MessageBox, _("A second configured interface has been found.\n\nDo you want to disable the second network interface?"), default = True) else: - self.writeWlanConfig(False) + self.getWpaPhrase(False) - def writeWlanConfig(self,ret = False): + def getWpaPhrase(self,ret): if ret == True: configuredInterfaces = iNetwork.getConfiguredAdapters() for interface in configuredInterfaces: @@ -629,12 +642,101 @@ class WlanConfig(Screen, ConfigListScreen, HelpableScreen): continue iNetwork.setAdapterAttribute(interface, "up", False) iNetwork.deactivateInterface(interface) - ret=self.writeWpasupplicantConf() + if wlanconfig.method.value =="wep": + self.writeWpasupplicantConf("wep") # passphrasekey is not None + else: + if wlanconfig.essid.value == 'Input hidden ESSID': + cmd = "wpa_passphrase '%s' %s" % (wlanconfig.hiddenessid.value,wlanconfig.key.value) + else : + cmd = "wpa_passphrase '%s' %s" % (wlanconfig.essid.value,wlanconfig.key.value) + print cmd + self.wpaphraseconsole = Console() + self.wpaphraseconsole.ePopen(cmd, self.parseWpaPhrase, self.writeWpasupplicantConf) + + def parseWpaPhrase(self, result, retval, extra_args): + (writewlanconfig) = extra_args + if self.wpaphraseconsole is not None: + if retval == 0: + self.wpaphraseconsole.killAll() + self.wpaphraseconsole = None +# print "parseWpaPhrase result : " +# print result + psk = None + for line in result.splitlines(): + if line.find('ssid') == -1 and line.find('#psk=') != -1: + plainpwd = line + elif line.find('psk=') != -1: + psk = line + if psk: + writewlanconfig(psk,plainpwd) + else: + writewlanconfig(None) + else: + writewlanconfig(None) + + def writeWpasupplicantConf(self, passphrasekey=None,plainpwd=None): + if passphrasekey: + wpafd = open("/etc/wpa_supplicant.conf","w") + if wpafd > 0: + contents = "#WPA Supplicant Configuration by STB\n" + contents += "ctrl_interface=/var/run/wpa_supplicant\n" + contents += "eapol_version=1\n" + contents += "fast_reauth=1\n" + contents += "ap_scan=1\n" + contents += "network={\n" + if wlanconfig.essid.value == 'Input hidden ESSID': + contents += "\tssid=\""+wlanconfig.hiddenessid.value+"\"\n" + contents += "\tscan_ssid=1\n" + else : + contents += "\tssid=\""+wlanconfig.essid.value+"\"\n" + contents += "\tscan_ssid=0\n" + if wlanconfig.encrypt.value == "on": + if wlanconfig.method.value =="wep": + contents += "\tkey_mgmt=NONE\n" + contents += "\twep_key0=" + if wlanconfig.keytype.value == "ascii": + contents += "\""+wlanconfig.key.value+"\"\n" + else: + contents += wlanconfig.key.value+"\n" + else: +# print "plainpwd : ",plainpwd +# print "passphrasekey : ",passphrasekey + if wlanconfig.method.value == "wpa": + contents += "\tkey_mgmt=WPA-PSK\n" + contents += "\tproto=WPA\n" + contents += "\tpairwise=CCMP TKIP\n" + contents += "\tgroup=CCMP TKIP\n" + elif wlanconfig.method.value == "wpa2": + contents += "\tkey_mgmt=WPA-PSK\n" + contents += "\tproto=RSN\n" + contents += "\tpairwise=CCMP TKIP\n" + contents += "\tgroup=CCMP TKIP\n" + else: + contents += "\tkey_mgmt=WPA-PSK\n" + contents += "\tproto=WPA RSN\n" + contents += "\tpairwise=CCMP TKIP\n" + contents += "\tgroup=CCMP TKIP\n" + contents += plainpwd+"\n" + contents += passphrasekey+"\n" + else: + contents += "\tkey_mgmt=NONE\n" + contents += "}\n" + print "content = \n"+contents + wpafd.write(contents) + wpafd.close() + self.writeNetConfig(0) + else : + self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10) + self.writeNetConfig(-1) + else: + self.writeNetConfig(-2) + + def writeNetConfig(self,ret = -1): if ret == -1: self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10) return elif ret == -2: - self.session.open(MessageBox, _("hidden ESSID empty"), type = MessageBox.TYPE_ERROR, timeout = 10) + self.session.open(MessageBox, _("Can NOT generate passphrase"), type = MessageBox.TYPE_ERROR, timeout = 10) return if wlanconfig.usedevice.value=="on": @@ -658,63 +760,7 @@ class WlanConfig(Screen, ConfigListScreen, HelpableScreen): self.configurationmsg = None self.configurationmsg = self.session.openWithCallback(self.configFinished, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False) - def writeWpasupplicantConf(self): - wpafd = open("/etc/wpa_supplicant.conf","w") - if wpafd > 0: - contents = "#WPA Supplicant Configuration by STB\n" - contents += "ctrl_interface=/var/run/wpa_supplicant\n" - contents += "eapol_version=1\n" - contents += "fast_reauth=1\n" - if wlanconfig.essid.value == 'Input hidden ESSID': - contents += "ap_scan=2\n" - else : - contents += "ap_scan=1\n" - contents += "network={\n" - if wlanconfig.essid.value == 'Input hidden ESSID': - if len(wlanconfig.hiddenessid.value) == 0: - wpafd.close() - return -2 - contents += "\tssid=\""+wlanconfig.hiddenessid.value+"\"\n" - else : - contents += "\tssid=\""+wlanconfig.essid.value+"\"\n" - contents += "\tscan_ssid=0\n" - if wlanconfig.encrypt.value == "on": - if wlanconfig.method.value =="wep": - contents += "\tkey_mgmt=NONE\n" - contents += "\twep_key0=" - elif wlanconfig.method.value == "wpa": - contents += "\tkey_mgmt=WPA-PSK\n" - contents += "\tproto=WPA\n" - contents += "\tpairwise=CCMP TKIP\n" - contents += "\tgroup=CCMP TKIP\n" - contents += "\tpsk=" - elif wlanconfig.method.value == "wpa2": - contents += "\tkey_mgmt=WPA-PSK\n" - contents += "\tproto=RSN\n" - contents += "\tpairwise=CCMP TKIP\n" - contents += "\tgroup=CCMP TKIP\n" - contents += "\tpsk=" - else: - contents += "\tkey_mgmt=WPA-PSK\n" - contents += "\tproto=WPA RSN\n" - contents += "\tpairwise=CCMP TKIP\n" - contents += "\tgroup=CCMP TKIP\n" - contents += "\tpsk=" - if wlanconfig.keytype.value == "ascii": - contents += "\""+wlanconfig.key.value+"\"\n" - else: - contents += wlanconfig.key.value+"\n" - else: - contents += "\tkey_mgmt=NONE\n" - contents += "}\n" - print "content = \n"+contents - wpafd.write(contents) - wpafd.close() - return 0 - else : - self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10) - return -1 def updateCurrentInterfaces(self,ret): if ret is True: iNetwork.getInterfaces(self.configurationMsgClose) @@ -768,46 +814,64 @@ class WlanConfig(Screen, ConfigListScreen, HelpableScreen): if data is True: self.close() -# def selectionChanged(self): -# current = self["config"].getCurrent() -# print current + def cleanup(self): + iNetwork.stopRestartConsole() + iNetwork.stopGetInterfacesConsole() + iNetwork.stopDeactivateInterfaceConsole() + self.stopwlanscanapConsole() + self.stopCheckNetworkSharesConsole() + self.stopWpaPhraseConsole() + + def stopwlanscanapConsole(self): + if self.wlanscanap is not None: + if len(self.wlanscanap.appContainers): + for name in self.wlanscanap.appContainers.keys(): + self.wlanscanap.kill(name) + + def stopCheckNetworkSharesConsole(self): + if self.Console is not None: + if len(self.Console.appContainers): + for name in self.Console.appContainers.keys(): + self.Console.kill(name) + + def stopWpaPhraseConsole(self): + if self.wpaphraseconsole is not None: + if len(self.wpaphraseconsole.appContainers): + for name in self.wpaphraseconsole.appContainers.keys(): + self.wpaphraseconsole.kill(name) class WlanScanAp(Screen,HelpableScreen): - skin = """ - - - - - - - Format:%H:%M - - - - - - - - - - - - - - - - """ - + skin = """ + + + + + + + + + + + + + + + + + + + + + + """ def __init__(self, session, iface): Screen.__init__(self,session) HelpableScreen.__init__(self) self.session = session self.iface = iface self.wlanscanap = None -# self.scanAPcount = 5 - self.scanAPcount = 1 self.apList = {} - self.SetApList = [] + self.setApList = [] self["WizardActions"] = HelpableActionMap(self, "WizardActions", { @@ -815,7 +879,7 @@ class WlanScanAp(Screen,HelpableScreen): "down": (self.down, _("move down to next entry")), "left": (self.left, _("move up to first entry")), "right": (self.right, _("move down to last entry")), - }) + }, -2) self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions", { @@ -827,21 +891,11 @@ class WlanScanAp(Screen,HelpableScreen): { "red": (self.close, _("exit")), "green": (self.ok, "select AP"), + "yellow": (self.restartScanAP, "restart scan AP"), "blue": (self.startWlanConfig, "Edit Wireless settings"), }) - self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"], - { - "ok": self.ok, - "back": self.close, - "up": self.up, - "down": self.down, - "red": self.close, - "left": self.left, - "right": self.right, - }, -2) - - self["menulist"] = MenuList(self.SetApList) + self["menulist"] = MenuList(self.setApList) self["key_red"] = StaticText(_("Close")) self["key_green"] = StaticText(_("Select")) self["key_blue"] = StaticText(_("EditSetting")) @@ -851,11 +905,16 @@ class WlanScanAp(Screen,HelpableScreen): self["Frequency"] = StaticText(" ") self["Encryption key"] = StaticText(" ") self["BitRate"] = StaticText(" ") - self.scanAPFailedTimer = eTimer() - self.scanAPFailedTimer.callback.append(self.scanAPFailed) + self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up") + self.getAplistTimer = eTimer() + self.getAplistTimer.callback.append(self.getApList) self.scanAplistTimer = eTimer() self.scanAplistTimer.callback.append(self.scanApList) - self.scanAplistTimer.start(100,True) + self.emptyListMsgTimer = eTimer() + self.emptyListMsgTimer.callback.append(self.emptyListMsg) + self.apList = {} + self.onClose.append(self.__onClose) + self.getAplistTimer.start(100,True) def left(self): self["menulist"].pageUp() @@ -880,101 +939,90 @@ class WlanScanAp(Screen,HelpableScreen): self.close() def startWlanConfig(self): - global selectap selectAp=self["menulist"].getCurrent()[0] - selectap = selectAp - self.session.open(WlanConfig,self.iface) -# self.close() + self.close(selectAp) - def scanApList(self): - # print "self.scanAPcount : ",self.scanAPcount + def getApList(self): self.apList = {} - self.SetApList = [] + self.setApList = [] self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False) - os_system('ifconfig '+self.iface+" up") - self.wlanscanap = Console() - cmd = "iwlist "+self.iface+" scan" - print cmd - self.wlanscanap.ePopen(cmd, self.iwlistfinnished,self.APListParse) - - def iwlistfinnished(self, result, retval,extra_args): -# print "iwlistfinnished" - (statecallback) = extra_args - if self.wlanscanap is not None: -# print "retval = ",retval - if retval == 0: - self.wlanscanap = None - content = result.splitlines() - first = content[0].split() - completed = False - for x in first: - if x == 'completed': - completed = True - if completed == True: - statecallback(result) - else: - statecallback(0) - else: - statecallback(0) + self.scanAplistTimer.start(100,True) - def APListParse(self,data): - if data == 0: - if self.scanAPcount >0: - self.scanAPcount -=1 - self.configurationmsg.close(True) - time.sleep(3) - self.scanAplistTimer.start(500,True) - return - else: - self.configurationmsg.close(True) - self.scanAPFailedTimer.start(500,True) - return - else: -# print data - self.apList = {} -# self.scanAPcount =5 - self.scanAPcount =0 - list = data.splitlines() - for line in list: -# print "line : ",line - if line.strip().startswith("Cell"): # Cell 01 - Address: 00:26:66:5C:EF:24 - parts = line.strip().split(" ") - current_ap_id = int(parts[1]) - self.apList[current_ap_id]={} - self.apList[current_ap_id]["Address"]=parts[4] - elif line.strip().startswith("ESSID"): - self.apList[current_ap_id]["ESSID"]=line.strip()[6:].strip('"') - self.SetApList.append( (self.apList[current_ap_id]["ESSID"],current_ap_id) ) - elif line.strip().startswith("Protocol"): - self.apList[current_ap_id]["Protocol"]=line.strip()[9:] - elif line.strip().startswith("Frequency"): - self.apList[current_ap_id]["Frequency"]=line.strip()[10:] - elif line.strip().startswith("Encryption key"): - self.apList[current_ap_id]["Encryption key"]=line.strip()[15:] - elif line.strip().startswith("Bit Rates"): - self.apList[current_ap_id]["BitRate"]=line.strip()[10:] - print self.apList - print len(self.apList) + def scanApList(self): + if self.oldInterfaceState is not True: + os_system("ifconfig "+self.iface+" up") + iNetwork.setAdapterAttribute(self.iface, "up", True) + Iwscanresult = None + wirelessObj = Wireless(self.iface) + try: + Iwscanresult = wirelessObj.scan() + except IOError: + print "%s Interface doesn't support scanning.."%self.iface +# self.session.open(MessageBox, "%s Interface doesn't support scanning.."%self.iface, MessageBox.TYPE_ERROR,10) self.configurationmsg.close(True) + if Iwscanresult is not None: + (num_channels, frequencies) = wirelessObj.getChannelInfo() + index = 1 + for ap in Iwscanresult: + self.apList[index] = {} + self.apList[index]["Address"] = ap.bssid + if len(ap.essid) == 0: + self.apList[index]["ESSID"] = "" + else: + self.apList[index]["ESSID"] = ap.essid + self.setApList.append( (self.apList[index]["ESSID"], index) ) + self.apList[index]["Protocol"] = ap.protocol + self.apList[index]["Frequency"] = wirelessObj._formatFrequency(ap.frequency.getFrequency()) + try: + self.apList[index]["Channel"] = frequencies.index(self.apList[index]["Frequency"] + 1) + except: + self.apList[index]["Channel"] = "Unknown" + + self.apList[index]["Quality"] = "%s/%s" % \ + ( ap.quality.quality, wirelessObj.getQualityMax().quality ) + self.apList[index]["Signal Level"] = "%s/%s" % \ + ( ap.quality.getSignallevel(), "100" ) + self.apList[index]["Noise Level"] = "%s/%s" % \ + ( ap.quality.getNoiselevel(), "100" ) + +# get encryption key on/off + key_status = "Unknown" + if (ap.encode.flags & pythonwifi.flags.IW_ENCODE_DISABLED): + key_status = "off" + elif (ap.encode.flags & pythonwifi.flags.IW_ENCODE_NOKEY): + if (ap.encode.length <= 0): + key_status = "on" + self.apList[index]["Encryption key"] = key_status + self.apList[index]["BitRate"] = wirelessObj._formatBitrate(ap.rate[-1][-1]) + index += 1 +# print self.apList +# print self.setApList self.displayApInfo() - - def scanAPFailed(self): - self.session.openWithCallback(self.ScanAPclose,MessageBox, _("Scan AP Failed"), MessageBox.TYPE_ERROR,10) + if len(self.apList) == 0: + self.emptyListMsgTimer.start(100,True) def displayApInfo(self): if len(self.apList) >0: - self["menulist"].setList(self.SetApList) + self["menulist"].setList(self.setApList) index = self["menulist"].getCurrent()[1] for key in ["Address", "ESSID", "Protocol", "Frequency", "Encryption key", "BitRate"]: if self.apList[index].has_key(key): self[key].setText((key+": "+self.apList[index][key])) else: - self[key].setText(("None")) - else: - self.session.openWithCallback(self.ScanAPclose, MessageBox, _("No AP detected."), type = MessageBox.TYPE_INFO, timeout = 10) + self[key].setText((key+": None")) - def ScanAPclose(self,data): - self.close() + def emptyListMsg(self): + self.session.open(MessageBox, _("No AP detected."), type = MessageBox.TYPE_INFO, timeout = 10) + self["Address"].setText(_("No AP detected.")) + self["ESSID"].setText(_("")) + + def restartScanAP(self): + self.getAplistTimer.start(100,True) + + def __onClose(self): + if self.oldInterfaceState is False: + iNetwork.setAdapterAttribute(self.iface, "up", False) + iNetwork.deactivateInterface(self.iface) class NetworkAdapterTest(Screen): def __init__(self, session,iface): @@ -1233,6 +1281,7 @@ class NetworkAdapterTest(Screen): self["InfoText"].show() self["key_red"].setText(_("Back")) if self.activebutton == 6: # Edit Settings + self.cleanup() self.session.open(WlanConfig,self.iface) self["shortcuts"].setEnabled(True) self["infoshortcuts"].setEnabled(False) @@ -1358,6 +1407,7 @@ class NetworkAdapterTest(Screen): def cleanup(self): iNetwork.stopLinkStateConsole() + iNetwork.stopPingConsole() iNetwork.stopDNSConsole() def AccessPointInfo(self,iface): @@ -1379,19 +1429,14 @@ class NetworkAdapterTest(Screen): callback(self.apState) class Wlanstatus(Screen): - skin = """ - - - - - - - Format:%H:%M - - - - - """ + skin = """ + + + + + + + """ def __init__(self, session,iface): Screen.__init__(self,session) self.session = session @@ -1405,6 +1450,7 @@ class Wlanstatus(Screen): "red": self.close, }, -2) self.readstatus() + self.onClose.append(self.cleanup) def readstatus(self): self.wlanstatus = Console() @@ -1432,6 +1478,15 @@ class Wlanstatus(Screen): def ok(self): pass + def cleanup(self): + self.stopWlanStatusConsole() + + def stopWlanStatusConsole(self): + if self.wlanstatus is not None: + if len(self.wlanstatus.appContainers): + for name in self.wlanstatus.appContainers.keys(): + self.wlanstatus.kill(name) + def openconfig(session, **kwargs): session.open(WlanSelection) @@ -1440,7 +1495,7 @@ def selSetup(menuid, **kwargs): if menuid != "system": return [ ] else: - for x in iNetwork.getAdapterList(): + for x in iNetwork.getInstalledAdapters(): if x.startswith('eth'): continue list.append(x)