From bb9ef1d4f055e0012f63ca480d08a9a3b1f34d80 Mon Sep 17 00:00:00 2001 From: acid-burn Date: Wed, 16 Mar 2011 11:07:17 +0100 Subject: SystemPlugins/WirelessLan: improve wireless device/module detection. improve iwconfig response parsing. read and save wpa_supplicant configurations into per interface separated files. refs #389 --- .../Plugins/SystemPlugins/WirelessLan/Wlan.py | 63 ++++++++-------------- .../Plugins/SystemPlugins/WirelessLan/plugin.py | 37 +++++++------ 2 files changed, 45 insertions(+), 55 deletions(-) (limited to 'lib/python/Plugins/SystemPlugins') diff --git a/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py b/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py index 480f201f..718adf9c 100755 --- a/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py +++ b/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py @@ -1,7 +1,7 @@ from Components.config import config, ConfigYesNo, NoSave, ConfigSubsection, ConfigText, ConfigSelection, ConfigPassword from Components.Console import Console -from os import system +from os import system, path as os_path from string import maketrans, strip import sys import types @@ -46,20 +46,18 @@ class Wlan: def stopWlanConsole(self): if self.WlanConsole is not None: - print "killing self.WlanConsole" + print "[Wlan] killing self.WlanConsole" + self.WlanConsole.killAll() self.WlanConsole = None del self.WlanConsole def getDataForInterface(self, callback = None): - #get ip out of ip addr, as avahi sometimes overrides it in ifconfig. - print "self.iface im getDataForInterface",self.iface if len(self.WlanConsole.appContainers) == 0: self.WlanConsole = Console() cmd = "iwconfig " + self.iface self.WlanConsole.ePopen(cmd, self.iwconfigFinished, callback) def iwconfigFinished(self, result, retval, extra_args): - print "self.iface im iwconfigFinished",self.iface callback = extra_args data = { 'essid': False, 'frequency': False, 'acesspoint': False, 'bitrate': False, 'encryption': False, 'quality': False, 'signal': False } @@ -85,7 +83,6 @@ class Wlan: ssid = _("Hidden networkname") else: ssid = tmpssid - if ssid is not None: data['essid'] = ssid if 'Frequency' in line: @@ -122,44 +119,29 @@ class Wlan: self.wlaniface[self.iface] = data if len(self.WlanConsole.appContainers) == 0: - print "self.wlaniface after loading:", self.wlaniface - self.WlanConsole = None + print "[Wlan.py] self.wlaniface after loading:", self.wlaniface if callback is not None: callback(True,self.wlaniface) def getAdapterAttribute(self, attribute): if self.wlaniface.has_key(self.iface): - print "self.wlaniface.has_key",self.iface + print "[Wlan.py] self.wlaniface.has_key",self.iface if self.wlaniface[self.iface].has_key(attribute): return self.wlaniface[self.iface][attribute] return None def asciify(self, str): return str.translate(self.asciitrans) - def getWirelessInterfaces(self): - device = re_compile('[a-z]{2,}[0-9]*:') - ifnames = [] - - fp = open('/proc/net/wireless', 'r') - for line in fp: - try: - # append matching pattern, without the trailing colon - ifnames.append(device.search(line).group()[:-1]) - except AttributeError: - pass - return ifnames + return getWNICnames() - def getNetworkList(self): system("ifconfig "+self.iface+" up") ifobj = Wireless(self.iface) # a Wireless NIC Object - #Association mappings #stats, quality, discard, missed_beacon = ifobj.getStatistics() #snr = quality.signallevel - quality.noiselevel - try: scanresults = ifobj.scan() except: @@ -210,7 +192,6 @@ class Wlan: #print "GOT APS ENTRY:",aps[bssid] index = index + 1 return aps - def getStatus(self): ifobj = Wireless(self.iface) @@ -228,28 +209,25 @@ class Wlan: 'channel': str(self.channel), #'channel': str(fq.getChannel(str(ifobj.getFrequency()[0:-3]))), } - for (key, item) in status.items(): if item is "None" or item is "": status[key] = _("N/A") - return status class wpaSupplicant: - def __init__(self): + def __init__(self, iface): + self.iface = iface pass - def writeConfig(self): - essid = config.plugins.wlan.essid.value hiddenessid = config.plugins.wlan.hiddenessid.value encrypted = config.plugins.wlan.encryption.enabled.value encryption = config.plugins.wlan.encryption.type.value wepkeytype = config.plugins.wlan.encryption.wepkeytype.value psk = config.plugins.wlan.encryption.psk.value - fp = file('/etc/wpa_supplicant.conf', 'w') + fp = file('/etc/' + self.iface + '_wpa_supplicant.conf', 'w') fp.write('#WPA Supplicant Configuration by enigma2\n') fp.write('ctrl_interface=/var/run/wpa_supplicant\n') fp.write('eapol_version=1\n') @@ -292,12 +270,16 @@ class wpaSupplicant: fp.write('}') fp.write('\n') fp.close() - system("cat /etc/wpa_supplicant.conf") + system('cat /etc/' + self.iface + '_wpa_supplicant.conf') def loadConfig(self): + configfile = '/etc/wpa_supplicant.conf' + if os_path.isfile('/etc/' + self.iface + '_wpa_supplicant.conf'): + configfile = '/etc/' + self.iface + '_wpa_supplicant.conf' + print "[wpaSupplicant] using configfile:",configfile try: #parse the wpasupplicant configfile - fp = file('/etc/wpa_supplicant.conf', 'r') + fp = file(configfile, 'r') supplicant = fp.readlines() fp.close() ap_scan = False @@ -324,7 +306,6 @@ class wpaSupplicant: mode = 'WPA2' if split[1] in ('WPA RSN', 'WPA WPA2'): mode = 'WPA/WPA2' - config.plugins.wlan.encryption.type.value = mode print "[Wlan.py] Got Encryption: "+mode @@ -372,9 +353,8 @@ class wpaSupplicant: wsconfig['encryption_wepkeytype'] = "ASCII" if key == 'encryption': wsconfig['key'] = "mysecurewlan" - except: - print "[Wlan.py] Error parsing /etc/wpa_supplicant.conf" + print "[Wlan.py] Error parsing ",configfile wsconfig = { 'hiddenessid': "home", 'ssid': "home", @@ -395,7 +375,7 @@ class Status: def stopWlanConsole(self): if self.WlanConsole is not None: - print "killing self.WlanConsole" + print "[iStatus] killing self.WlanConsole" self.WlanConsole.killAll() self.WlanConsole = None @@ -458,15 +438,18 @@ class Status: enc = _("Unsupported") else: enc = _("Disabled") - else: + elif "Security" in line: enc = line[line.index('Encryption key')+15 :line.index(' Security')] if enc is not None: enc = _("Enabled") + else: + enc = line[line.index('Encryption key')+15 :len(line)] + if enc is not None: + enc = _("Enabled") if enc is not None: data['encryption'] = enc if 'Quality' in line: if "/100" in line: - #qual = line[line.index('Quality')+8:line.index('/100')] qual = line[line.index('Quality')+8:line.index(' Signal')] else: qual = line[line.index('Quality')+8:line.index('Sig')] @@ -494,7 +477,7 @@ class Status: if self.WlanConsole is not None: if len(self.WlanConsole.appContainers) == 0: - print "self.wlaniface after loading:", self.wlaniface + print "[Wlan.py] self.wlaniface after loading:", self.wlaniface if callback is not None: callback(True,self.wlaniface) diff --git a/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py b/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py index efec340a..290d139b 100644 --- a/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py +++ b/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py @@ -8,7 +8,7 @@ from Components.Sources.List import List from Components.MenuList import MenuList from Components.config import config, getConfigListEntry, ConfigYesNo, NoSave, ConfigSubsection, ConfigText, ConfigSelection, ConfigPassword from Components.ConfigList import ConfigListScreen -from Components.Network import Network, iNetwork +from Components.Network import iNetwork from Components.Console import Console from Plugins.Plugin import PluginDescriptor from os import system, path as os_path, listdir @@ -17,6 +17,8 @@ from Tools.LoadPixmap import LoadPixmap from Tools.HardwareInfo import HardwareInfo from Wlan import Wlan, wpaSupplicant, iStatus import sha +from time import time +from os import urandom plugin_path = eEnv.resolve("${libdir}/enigma2/python/Plugins/SystemPlugins/WirelessLan") @@ -399,34 +401,39 @@ def decrypt_block(src, mod): return dest return None -def validate_cert(cert, key): +def validate_certificate(cert, key): buf = decrypt_block(cert[8:], key) if buf is None: return None return buf[36:107] + cert[139:196] -def read_random(): +def get_random(): try: - fd = open("/dev/urandom", "r") - buf = fd.read(8) - fd.close() - return buf + xor = lambda a,b: ''.join(chr(ord(c)^ord(d)) for c,d in zip(a,b*100)) + random = urandom(8) + x = str(time())[-8:] + result = xor(random, x) + + return result except: return None def WlanStatusScreenMain(session, iface): session.open(WlanStatus, iface) - def callFunction(iface): w = Wlan(iface) i = w.getWirelessInterfaces() if i: if iface in i: return WlanStatusScreenMain + else: + if iNetwork.isWirelessInterface(iface): + return WlanStatusScreenMain + else: + return None return None - def configStrings(iface): hardware_info = HardwareInfo() if hardware_info.device_name != "dm7025": @@ -435,17 +442,16 @@ def configStrings(iface): l2cert = etpm.getCert(eTPM.TPMD_DT_LEVEL2_CERT) if l2cert is None: return - l2key = validate_cert(l2cert, rootkey) + l2key = validate_certificate(l2cert, rootkey) if l2key is None: return l3cert = etpm.getCert(eTPM.TPMD_DT_LEVEL3_CERT) if l3cert is None: - print "better run the genuine dreambox plugin" return - l3key = validate_cert(l3cert, l2key) + l3key = validate_certificate(l3cert, l2key) if l3key is None: return - rnd = read_random() + rnd = get_random() if rnd is None: return val = etpm.challenge(rnd) @@ -454,10 +460,11 @@ def configStrings(iface): driver = iNetwork.detectWlanModule(iface) else: driver = 'dreambox' + print 'Using "%s" as wpa-supplicant driver' % (driver) ret = "" - if driver == 'madwifi' and config.plugins.wlan.essid.value == "hidden...": + if config.plugins.wlan.essid.value == "hidden...": ret += "\tpre-up iwconfig " + iface + " essid \"" + config.plugins.wlan.hiddenessid.value + "\" || true\n" - ret += "\tpre-up wpa_supplicant -i" + iface + " -c/etc/wpa_supplicant.conf -B -dd -D" + driver + " || true\n" + ret += "\tpre-up wpa_supplicant -i" + iface + " -c/etc/" + iface + "_wpa_supplicant.conf -B -dd -D" + driver + " || true\n" ret += "\tpre-down wpa_cli -i" + iface + " terminate || true\n" return ret -- cgit v1.2.3 From d3b93520aa641af4b8da8e0368dfa8392cd385c4 Mon Sep 17 00:00:00 2001 From: acid-burn Date: Wed, 16 Mar 2011 11:12:48 +0100 Subject: NetworkWizard: follow network.py to improve wireless interface/module detection. refs #389 --- .../Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/python/Plugins/SystemPlugins') diff --git a/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py b/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py index d7e83072..a31b2d49 100755 --- a/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py +++ b/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py @@ -82,6 +82,7 @@ class NetworkWizard(WizardLanguage, Rc): self.originalAth0State = None self.originalEth0State = None self.originalWlan0State = None + self.originalRa0State = None self.originalInterfaceStateChanged = False self.Text = None self.rescanTimer = eTimer() @@ -110,6 +111,7 @@ class NetworkWizard(WizardLanguage, Rc): self.originalAth0State = iNetwork.getAdapterAttribute('ath0', 'up') self.originalEth0State = iNetwork.getAdapterAttribute('eth0', 'up') self.originalWlan0State = iNetwork.getAdapterAttribute('wlan0', 'up') + self.originalRa0State = iNetwork.getAdapterAttribute('ra0', 'up') def selectInterface(self): self.InterfaceState = None @@ -151,7 +153,9 @@ class NetworkWizard(WizardLanguage, Rc): if self.originalWlan0State is False and self.originalInterfaceStateChanged is False: if iNetwork.checkforInterface('wlan0') is True: iNetwork.deactivateInterface('wlan0') - + if self.originalRa0State is False and self.originalInterfaceStateChanged is False: + if iNetwork.checkforInterface('ra0') is True: + iNetwork.deactivateInterface('ra0') def listInterfaces(self): self.rescanTimer.stop() self.checkOldInterfaceState() @@ -183,7 +187,7 @@ class NetworkWizard(WizardLanguage, Rc): #Reset Network to defaults if network broken iNetwork.resetNetworkConfig('lan', self.resetNetworkConfigCB) self.resetRef = self.session.openWithCallback(self.resetNetworkConfigFinished, MessageBox, _("Please wait while we prepare your network interfaces..."), type = MessageBox.TYPE_INFO, enable_input = False) - if iface in ('eth0', 'wlan0', 'ath0'): + if iface in ('eth0', 'wlan0', 'ath0', 'ra0'): if iface in iNetwork.configuredNetworkAdapters and len(iNetwork.configuredNetworkAdapters) == 1: if iNetwork.getAdapterAttribute(iface, 'up') is True: self.isInterfaceUp = True @@ -232,7 +236,7 @@ class NetworkWizard(WizardLanguage, Rc): def AdapterSetupEndCB(self,data): if data is True: - if self.selectedInterface in ('wlan0', 'ath0'): + if iNetwork.isWirelessInterface(self.selectedInterface): if self.WlanPluginInstalled == True: from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus iStatus.getDataForInterface(self.selectedInterface,self.checkWlanStateCB) @@ -275,7 +279,7 @@ class NetworkWizard(WizardLanguage, Rc): def checkNetworkCB(self,data): if data is True: - if self.selectedInterface in ('wlan0', 'ath0'): + if iNetwork.isWirelessInterface(self.selectedInterface): if self.WlanPluginInstalled == True: from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus iStatus.getDataForInterface(self.selectedInterface,self.checkWlanStateCB) -- cgit v1.2.3 From ff37d0658b1fb0b1b4b6ed710ad58cfc62a6a139 Mon Sep 17 00:00:00 2001 From: acid-burn Date: Wed, 16 Mar 2011 11:22:37 +0100 Subject: SoftwareManager: add new wpa_supplicant configfiles to backup defaults. refs #389 --- lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py | 2 +- lib/python/Plugins/SystemPlugins/SoftwareManager/ImageWizard.py | 2 +- lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/python/Plugins/SystemPlugins') diff --git a/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py b/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py index 01649bb3..f06ae3e1 100755 --- a/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py +++ b/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py @@ -20,7 +20,7 @@ from datetime import date config.plugins.configurationbackup = ConfigSubsection() config.plugins.configurationbackup.backuplocation = ConfigText(default = '/media/hdd/', visible_width = 50, fixed_size = False) -config.plugins.configurationbackup.backupdirs = ConfigLocations(default=[eEnv.resolve('${sysconfdir}/enigma2/'), '/etc/network/interfaces', '/etc/wpa_supplicant.conf', '/etc/resolv.conf', '/etc/default_gw', '/etc/hostname']) +config.plugins.configurationbackup.backupdirs = ConfigLocations(default=[eEnv.resolve('${sysconfdir}/enigma2/'), '/etc/network/interfaces', '/etc/wpa_supplicant.conf', '/etc/wlan0_wpa_supplicant.conf', '/etc/ath0_wpa_supplicant.conf', '/etc/resolv.conf', '/etc/default_gw', '/etc/hostname']) def getBackupPath(): backuppath = config.plugins.configurationbackup.backuplocation.value diff --git a/lib/python/Plugins/SystemPlugins/SoftwareManager/ImageWizard.py b/lib/python/Plugins/SystemPlugins/SoftwareManager/ImageWizard.py index 32d7140a..843abdc3 100755 --- a/lib/python/Plugins/SystemPlugins/SoftwareManager/ImageWizard.py +++ b/lib/python/Plugins/SystemPlugins/SoftwareManager/ImageWizard.py @@ -16,7 +16,7 @@ from Components.Harddisk import harddiskmanager config.misc.firstrun = ConfigBoolean(default = True) config.plugins.configurationbackup = ConfigSubsection() config.plugins.configurationbackup.backuplocation = ConfigText(default = '/media/hdd/', visible_width = 50, fixed_size = False) -config.plugins.configurationbackup.backupdirs = ConfigLocations(default=[eEnv.resolve('${sysconfdir}/enigma2/'), '/etc/network/interfaces', '/etc/wpa_supplicant.conf']) +config.plugins.configurationbackup.backupdirs = ConfigLocations(default=[eEnv.resolve('${sysconfdir}/enigma2/'), '/etc/network/interfaces', '/etc/wpa_supplicant.conf', '/etc/wlan0_wpa_supplicant.conf', '/etc/ath0_wpa_supplicant.conf', '/etc/resolv.conf', '/etc/default_gw', '/etc/hostname']) backupfile = "enigma2settingsbackup.tar.gz" diff --git a/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py b/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py index b3a0a17a..7901fd07 100644 --- a/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py +++ b/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py @@ -43,7 +43,7 @@ from SoftwareTools import iSoftwareTools config.plugins.configurationbackup = ConfigSubsection() config.plugins.configurationbackup.backuplocation = ConfigText(default = '/media/hdd/', visible_width = 50, fixed_size = False) -config.plugins.configurationbackup.backupdirs = ConfigLocations(default=[eEnv.resolve('${sysconfdir}/enigma2/'), '/etc/network/interfaces', '/etc/wpa_supplicant.conf', '/etc/resolv.conf', '/etc/default_gw', '/etc/hostname']) +config.plugins.configurationbackup.backupdirs = ConfigLocations(default=[eEnv.resolve('${sysconfdir}/enigma2/'), '/etc/network/interfaces', '/etc/wpa_supplicant.conf', '/etc/wlan0_wpa_supplicant.conf', '/etc/ath0_wpa_supplicant.conf', '/etc/resolv.conf', '/etc/default_gw', '/etc/hostname']) config.plugins.SoftwareManager = ConfigSubsection() config.plugins.SoftwareManager.overwriteConfigFiles = ConfigSelection( -- cgit v1.2.3 From 39650c9a5526bc2c82066e546f343b7bf8404dd9 Mon Sep 17 00:00:00 2001 From: Mladen Horvat Date: Wed, 30 Mar 2011 09:58:34 +0200 Subject: SystemPlugins/NetworkWizard: Don't depend on device names where possible. Some code cleanups and improvements. refs #389 --- .../SystemPlugins/NetworkWizard/NetworkWizard.py | 147 ++++++++++----------- 1 file changed, 69 insertions(+), 78 deletions(-) (limited to 'lib/python/Plugins/SystemPlugins') diff --git a/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py b/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py index a31b2d49..e99309a9 100755 --- a/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py +++ b/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py @@ -8,6 +8,7 @@ from Components.config import config, ConfigBoolean, configfile, ConfigYesNo, No from Components.Network import iNetwork from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE from enigma import eTimer +from os import system config.misc.firstrun = ConfigBoolean(default = True) list = [] @@ -65,8 +66,9 @@ class NetworkWizard(WizardLanguage, Rc): self.Adapterlist = None self.InterfaceState = None self.isInterfaceUp = None - self.WlanPluginInstalled = None + self.WlanPluginInstalled = False self.ap = None + self.w = None if interface is not None: self.selectedInterface = interface else: @@ -79,10 +81,8 @@ class NetworkWizard(WizardLanguage, Rc): self.newAPlist = None self.WlanList = None self.oldlist = None - self.originalAth0State = None - self.originalEth0State = None - self.originalWlan0State = None - self.originalRa0State = None + + self.originalInterfaceState = {} self.originalInterfaceStateChanged = False self.Text = None self.rescanTimer = eTimer() @@ -96,68 +96,60 @@ class NetworkWizard(WizardLanguage, Rc): self.close() def markDone(self): - self.rescanTimer.stop() + self.stopScan() del self.rescanTimer self.checkOldInterfaceState() pass - def getInstalledInterfaceCount(self): + def stopScan(self): self.rescanTimer.stop() + if self.w is not None: + from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan + iWlan.stopGetNetworkList() + self.w = None + + def getInstalledInterfaceCount(self): + self.originalInterfaceState = {} + self.stopScan() self.Adapterlist = iNetwork.getAdapterList() self.InstalledInterfaceCount = len(self.Adapterlist) if self.Adapterlist is not None: if self.InstalledInterfaceCount == 1 and self.selectedInterface is None: self.selectedInterface = self.Adapterlist[0] - self.originalAth0State = iNetwork.getAdapterAttribute('ath0', 'up') - self.originalEth0State = iNetwork.getAdapterAttribute('eth0', 'up') - self.originalWlan0State = iNetwork.getAdapterAttribute('wlan0', 'up') - self.originalRa0State = iNetwork.getAdapterAttribute('ra0', 'up') + for interface in iNetwork.getAdapterList(): + self.originalInterfaceState[interface] = {} + self.originalInterfaceState[interface]["up"] = iNetwork.getAdapterAttribute(interface, 'up') def selectInterface(self): self.InterfaceState = None - if self.selectedInterface is None and self.InstalledInterfaceCount <= 1: - if self.selectedInterface == 'eth0': - self.NextStep = 'nwconfig' - else: - self.NextStep = 'scanwlan' - self.checkInterface(self.selectedInterface) - elif self.selectedInterface is not None and self.InstalledInterfaceCount <= 1: - if self.selectedInterface == 'eth0': - self.NextStep = 'nwconfig' + if self.selectedInterface is None: + if self.InstalledInterfaceCount <= 1: + if not iNetwork.isWirelessInterface(self.selectedInterface): + self.NextStep = 'nwconfig' + else: + self.NextStep = 'scanwlan' + self.checkInterface(self.selectedInterface) else: - self.NextStep = 'scanwlan' - self.checkInterface(self.selectedInterface) - elif self.selectedInterface is None and self.InstalledInterfaceCount > 1: - self.NextStep = 'selectinterface' - self.currStep = self.getStepWithID(self.NextStep) - self.afterAsyncCode() - elif self.selectedInterface is not None and self.InstalledInterfaceCount > 1: - if self.selectedInterface == 'eth0': + self.NextStep = 'selectinterface' + self.currStep = self.getStepWithID(self.NextStep) + self.afterAsyncCode() + else: + if not iNetwork.isWirelessInterface(self.selectedInterface): self.NextStep = 'nwconfig' else: self.NextStep = 'scanwlan' self.checkInterface(self.selectedInterface) - else: - self.NextStep = 'selectinterface' - self.currStep = self.getStepWithID(self.NextStep) - self.afterAsyncCode() def checkOldInterfaceState(self): # disable up interface if it was originally down and config is unchanged. - if self.originalAth0State is False and self.originalInterfaceStateChanged is False: - if iNetwork.checkforInterface('ath0') is True: - iNetwork.deactivateInterface('ath0') - if self.originalEth0State is False and self.originalInterfaceStateChanged is False: - if iNetwork.checkforInterface('eth0') is True: - iNetwork.deactivateInterface('eth0') - if self.originalWlan0State is False and self.originalInterfaceStateChanged is False: - if iNetwork.checkforInterface('wlan0') is True: - iNetwork.deactivateInterface('wlan0') - if self.originalRa0State is False and self.originalInterfaceStateChanged is False: - if iNetwork.checkforInterface('ra0') is True: - iNetwork.deactivateInterface('ra0') + if self.originalInterfaceStateChanged is False: + for interface in self.originalInterfaceState.keys(): + if self.originalInterfaceState[interface]["up"] is False: + if iNetwork.checkforInterface(interface) is True: + system("ifconfig " + interface + " down") + def listInterfaces(self): - self.rescanTimer.stop() + self.stopScan() self.checkOldInterfaceState() list = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()] list.append((_("Exit network wizard"), "end")) @@ -179,7 +171,7 @@ class NetworkWizard(WizardLanguage, Rc): self.InterfaceSelect(self.selection) def checkInterface(self,iface): - self.rescanTimer.stop() + self.stopScan() if self.Adapterlist is None: self.Adapterlist = iNetwork.getAdapterList() if self.NextStep is not 'end': @@ -187,7 +179,7 @@ class NetworkWizard(WizardLanguage, Rc): #Reset Network to defaults if network broken iNetwork.resetNetworkConfig('lan', self.resetNetworkConfigCB) self.resetRef = self.session.openWithCallback(self.resetNetworkConfigFinished, MessageBox, _("Please wait while we prepare your network interfaces..."), type = MessageBox.TYPE_INFO, enable_input = False) - if iface in ('eth0', 'wlan0', 'ath0', 'ra0'): + if iface in iNetwork.getInstalledAdapters(): if iface in iNetwork.configuredNetworkAdapters and len(iNetwork.configuredNetworkAdapters) == 1: if iNetwork.getAdapterAttribute(iface, 'up') is True: self.isInterfaceUp = True @@ -336,43 +328,43 @@ class NetworkWizard(WizardLanguage, Rc): def listAccessPoints(self): self.APList = [] - try: - from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan - except ImportError: + if self.WlanPluginInstalled is False: self.APList.append( ( _("No networks found"),_("unavailable") ) ) return self.APList else: try: - self.w = Wlan(self.selectedInterface) - aps = self.w.getNetworkList() + from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan + iWlan.setInterface(self.selectedInterface) + self.w = iWlan.getInterface() + aps = iWlan.getNetworkList() except ValueError: self.APList = [] self.APList.append( ( _("No networks found"),_("unavailable") ) ) return self.APList - else: - if aps is not None: - print "[NetworkWizard.py] got Accespoints!" - tmplist = [] - complist = [] - for ap in aps: - a = aps[ap] - if a['active']: - tmplist.append( (a['bssid'], a['essid']) ) - complist.append( (a['bssid'], a['essid']) ) - - for entry in tmplist: - if entry[1] == "": - for compentry in complist: - if compentry[0] == entry[0]: - complist.remove(compentry) - for entry in complist: - self.APList.append( (entry[1], entry[1]) ) + + if aps is not None: + print "[NetworkWizard.py] got Accespoints!" + tmplist = [] + complist = [] + for ap in aps: + a = aps[ap] + if a['active']: + tmplist.append( (a['bssid'], a['essid']) ) + complist.append( (a['bssid'], a['essid']) ) + + for entry in tmplist: + if entry[1] == "": + for compentry in complist: + if compentry[0] == entry[0]: + complist.remove(compentry) + for entry in complist: + self.APList.append( (entry[1], entry[1]) ) - if "hidden..." not in self.APList: - self.APList.append(( _("enter hidden network SSID"), "hidden..." )) + if "hidden..." not in self.APList: + self.APList.append(( _("enter hidden network SSID"), "hidden..." )) - self.rescanTimer.start(3000) - return self.APList + self.rescanTimer.start(5000) + return self.APList def AccessPointsSelectionMade(self, index): self.ap = index @@ -391,19 +383,19 @@ class NetworkWizard(WizardLanguage, Rc): self.AccessPointsSelect(self.selection) def checkWlanSelection(self): - self.rescanTimer.stop() + self.stopScan() self.currStep = self.getStepWithID(self.NextStep) def isWlanPluginInstalled(self): try: - from Plugins.SystemPlugins.WirelessLan.Wlan import Wlan + from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan except ImportError: self.WlanPluginInstalled = False else: self.WlanPluginInstalled = True def listChoices(self): - self.rescanTimer.stop() + self.stopScan() list = [] if self.WlanPluginInstalled == True: list.append((_("Configure your wireless LAN again"), "scanwlan")) @@ -425,4 +417,3 @@ class NetworkWizard(WizardLanguage, Rc): def ChoicesSelectionMoved(self): pass - -- cgit v1.2.3 From 26a1c69f126a59ec9aeda715ef6d516d42fd10c4 Mon Sep 17 00:00:00 2001 From: Mladen Horvat Date: Wed, 30 Mar 2011 10:49:10 +0200 Subject: SystemPlugins/WirelessLan: Don't depend on device names where possible. Better wireless lan interface detection and scanning. Changed file naming for wpa_supplicant configuration to wpa_supplicant."interfacename".conf. refs #389 --- .../Plugins/SystemPlugins/WirelessLan/Wlan.py | 262 +++++++-------------- .../Plugins/SystemPlugins/WirelessLan/plugin.py | 57 ++--- 2 files changed, 108 insertions(+), 211 deletions(-) (limited to 'lib/python/Plugins/SystemPlugins') diff --git a/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py b/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py index 718adf9c..5b76f926 100755 --- a/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py +++ b/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py @@ -1,5 +1,6 @@ from Components.config import config, ConfigYesNo, NoSave, ConfigSubsection, ConfigText, ConfigSelection, ConfigPassword from Components.Console import Console +from Components.Network import iNetwork from os import system, path as os_path from string import maketrans, strip @@ -29,8 +30,14 @@ config.plugins.wlan.encryption.type = NoSave(ConfigSelection(list, default = "WP config.plugins.wlan.encryption.wepkeytype = NoSave(ConfigSelection(weplist, default = "ASCII")) config.plugins.wlan.encryption.psk = NoSave(ConfigPassword(default = "mysecurewlan", fixed_size = False)) +def getWlanConfigName(iface): + return '/etc/wpa_supplicant.' + iface + '.conf' + class Wlan: - def __init__(self, iface): + def __init__(self, iface = None): + self.iface = iface + self.oldInterfaceState = None + a = ''; b = '' for i in range(0, 255): a = a + chr(i) @@ -39,109 +46,30 @@ class Wlan: else: b = b + chr(i) - self.iface = iface - self.wlaniface = {} - self.WlanConsole = Console() self.asciitrans = maketrans(a, b) - def stopWlanConsole(self): - if self.WlanConsole is not None: - print "[Wlan] killing self.WlanConsole" - self.WlanConsole.killAll() - self.WlanConsole = None - del self.WlanConsole - - def getDataForInterface(self, callback = None): - if len(self.WlanConsole.appContainers) == 0: - self.WlanConsole = Console() - cmd = "iwconfig " + self.iface - self.WlanConsole.ePopen(cmd, self.iwconfigFinished, callback) - - def iwconfigFinished(self, result, retval, extra_args): - callback = extra_args - data = { 'essid': False, 'frequency': False, 'acesspoint': False, 'bitrate': False, 'encryption': False, 'quality': False, 'signal': False } - - for line in result.splitlines(): - line = line.strip() - if "ESSID" in line: - if "off/any" in line: - ssid = _("No Connection") - else: - if "Nickname" in line: - tmpssid=(line[line.index('ESSID')+7:line.index('" Nickname')]) - if tmpssid == '': - ssid = _("Hidden networkname") - elif tmpssid ==' ': - ssid = _("Hidden networkname") - else: - ssid = tmpssid - else: - tmpssid=(line[line.index('ESSID')+7:len(line)-1]) - if tmpssid == '': - ssid = _("Hidden networkname") - elif tmpssid ==' ': - ssid = _("Hidden networkname") - else: - ssid = tmpssid - if ssid is not None: - data['essid'] = ssid - if 'Frequency' in line: - frequency = line[line.index('Frequency')+10 :line.index(' GHz')] - if frequency is not None: - data['frequency'] = frequency - if "Access Point" in line: - ap=line[line.index('Access Point')+14:len(line)-1] - if ap is not None: - data['acesspoint'] = ap - if "Bit Rate" in line: - br = line[line.index('Bit Rate')+9 :line.index(' Mb/s')] - if br is not None: - data['bitrate'] = br - if 'Encryption key' in line: - if ":off" in line: - enc = _("Disabled") - else: - enc = line[line.index('Encryption key')+15 :line.index(' Security')] - if enc is not None: - data['encryption'] = _("Enabled") - if 'Quality' in line: - if "/100" in line: - qual = line[line.index('Quality')+8:line.index('/100')] - else: - qual = line[line.index('Quality')+8:line.index('Sig')] - if qual is not None: - data['quality'] = qual - if 'Signal level' in line: - signal = line[line.index('Signal level')+13 :line.index(' dBm')] - if signal is not None: - data['signal'] = signal - - self.wlaniface[self.iface] = data - - if len(self.WlanConsole.appContainers) == 0: - print "[Wlan.py] self.wlaniface after loading:", self.wlaniface - if callback is not None: - callback(True,self.wlaniface) - - def getAdapterAttribute(self, attribute): - if self.wlaniface.has_key(self.iface): - print "[Wlan.py] self.wlaniface.has_key",self.iface - if self.wlaniface[self.iface].has_key(attribute): - return self.wlaniface[self.iface][attribute] - return None - def asciify(self, str): return str.translate(self.asciitrans) def getWirelessInterfaces(self): return getWNICnames() + def setInterface(self, iface = None): + self.iface = iface + + def getInterface(self): + return self.iface + def getNetworkList(self): - system("ifconfig "+self.iface+" up") + if self.oldInterfaceState is None: + self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up") + if self.oldInterfaceState is False: + if iNetwork.getAdapterAttribute(self.iface, "up") is False: + iNetwork.setAdapterAttribute(self.iface, "up", True) + system("ifconfig "+self.iface+" up") + ifobj = Wireless(self.iface) # a Wireless NIC Object - #Association mappings - #stats, quality, discard, missed_beacon = ifobj.getStatistics() - #snr = quality.signallevel - quality.noiselevel + try: scanresults = ifobj.scan() except: @@ -170,7 +98,6 @@ class Wlan: element = element.encode() extra.append( strip(self.asciify(element)) ) for element in extra: - print element if 'SignalStrength' in element: signal = element[element.index('SignalStrength')+15:element.index(',L')] if 'LinkQuality' in element: @@ -193,92 +120,79 @@ class Wlan: index = index + 1 return aps - def getStatus(self): - ifobj = Wireless(self.iface) - fq = Iwfreq() - try: - self.channel = str(fq.getChannel(str(ifobj.getFrequency()[0:-3]))) - except: - self.channel = 0 - status = { - 'BSSID': str(ifobj.getAPaddr()), #ifobj.getStatistics() - 'ESSID': str(ifobj.getEssid()), - 'quality': "%s/%s" % (ifobj.getStatistics()[1].quality,ifobj.getQualityMax().quality), - 'signal': str(ifobj.getStatistics()[1].siglevel-0x100) + " dBm", - 'bitrate': str(ifobj.getBitrate()), - 'channel': str(self.channel), - #'channel': str(fq.getChannel(str(ifobj.getFrequency()[0:-3]))), - } - for (key, item) in status.items(): - if item is "None" or item is "": - status[key] = _("N/A") - return status + def stopGetNetworkList(self): + if self.oldInterfaceState is not None: + if self.oldInterfaceState is False: + iNetwork.setAdapterAttribute(self.iface, "up", False) + system("ifconfig "+self.iface+" down") + self.oldInterfaceState = None + self.iface = None +iWlan = Wlan() class wpaSupplicant: - def __init__(self, iface): - self.iface = iface + def __init__(self): pass - def writeConfig(self): - essid = config.plugins.wlan.essid.value - hiddenessid = config.plugins.wlan.hiddenessid.value - encrypted = config.plugins.wlan.encryption.enabled.value - encryption = config.plugins.wlan.encryption.type.value - wepkeytype = config.plugins.wlan.encryption.wepkeytype.value - psk = config.plugins.wlan.encryption.psk.value - fp = file('/etc/' + self.iface + '_wpa_supplicant.conf', 'w') - fp.write('#WPA Supplicant Configuration by enigma2\n') - fp.write('ctrl_interface=/var/run/wpa_supplicant\n') - fp.write('eapol_version=1\n') - fp.write('fast_reauth=1\n') - if essid == 'hidden...': - fp.write('ap_scan=2\n') - else: - fp.write('ap_scan=1\n') - fp.write('network={\n') - if essid == 'hidden...': - fp.write('\tssid="'+hiddenessid+'"\n') - else: - fp.write('\tssid="'+essid+'"\n') - fp.write('\tscan_ssid=0\n') - if encrypted: - if encryption in ('WPA', 'WPA2', 'WPA/WPA2'): - fp.write('\tkey_mgmt=WPA-PSK\n') + def writeConfig(self, iface): + essid = config.plugins.wlan.essid.value + hiddenessid = config.plugins.wlan.hiddenessid.value + encrypted = config.plugins.wlan.encryption.enabled.value + encryption = config.plugins.wlan.encryption.type.value + wepkeytype = config.plugins.wlan.encryption.wepkeytype.value + psk = config.plugins.wlan.encryption.psk.value + fp = file(getWlanConfigName(iface), 'w') + fp.write('#WPA Supplicant Configuration by enigma2\n') + fp.write('ctrl_interface=/var/run/wpa_supplicant\n') + fp.write('eapol_version=1\n') + fp.write('fast_reauth=1\n') + if essid == 'hidden...': + fp.write('ap_scan=2\n') + else: + fp.write('ap_scan=1\n') + fp.write('network={\n') + if essid == 'hidden...': + fp.write('\tssid="'+hiddenessid+'"\n') + else: + fp.write('\tssid="'+essid+'"\n') + fp.write('\tscan_ssid=0\n') + if encrypted: + if encryption in ('WPA', 'WPA2', 'WPA/WPA2'): + fp.write('\tkey_mgmt=WPA-PSK\n') - if encryption == 'WPA': - fp.write('\tproto=WPA\n') - fp.write('\tpairwise=TKIP\n') - fp.write('\tgroup=TKIP\n') - elif encryption == 'WPA2': - fp.write('\tproto=RSN\n') - fp.write('\tpairwise=CCMP\n') - fp.write('\tgroup=CCMP\n') - else: - fp.write('\tproto=WPA RSN\n') - fp.write('\tpairwise=CCMP TKIP\n') - fp.write('\tgroup=CCMP TKIP\n') - fp.write('\tpsk="'+psk+'"\n') - elif encryption == 'WEP': - fp.write('\tkey_mgmt=NONE\n') - if wepkeytype == 'ASCII': - fp.write('\twep_key0="'+psk+'"\n') - else: - fp.write('\twep_key0='+psk+'\n') - else: - fp.write('\tkey_mgmt=NONE\n') - fp.write('}') - fp.write('\n') - fp.close() - system('cat /etc/' + self.iface + '_wpa_supplicant.conf') + if encryption == 'WPA': + fp.write('\tproto=WPA\n') + fp.write('\tpairwise=TKIP\n') + fp.write('\tgroup=TKIP\n') + elif encryption == 'WPA2': + fp.write('\tproto=RSN\n') + fp.write('\tpairwise=CCMP\n') + fp.write('\tgroup=CCMP\n') + else: + fp.write('\tproto=WPA RSN\n') + fp.write('\tpairwise=CCMP TKIP\n') + fp.write('\tgroup=CCMP TKIP\n') + fp.write('\tpsk="'+psk+'"\n') + elif encryption == 'WEP': + fp.write('\tkey_mgmt=NONE\n') + if wepkeytype == 'ASCII': + fp.write('\twep_key0="'+psk+'"\n') + else: + fp.write('\twep_key0='+psk+'\n') + else: + fp.write('\tkey_mgmt=NONE\n') + fp.write('}') + fp.write('\n') + fp.close() + system('cat ' + getWlanConfigName(iface)) - def loadConfig(self): - configfile = '/etc/wpa_supplicant.conf' - if os_path.isfile('/etc/' + self.iface + '_wpa_supplicant.conf'): - configfile = '/etc/' + self.iface + '_wpa_supplicant.conf' - print "[wpaSupplicant] using configfile:",configfile + def loadConfig(self,iface): + configfile = getWlanConfigName(iface) + if not os_path.exists(configfile): + configfile = '/etc/wpa_supplicant.conf' try: #parse the wpasupplicant configfile + print "[Wlan.py] parsing configfile: ",configfile fp = file(configfile, 'r') supplicant = fp.readlines() fp.close() @@ -288,14 +202,14 @@ class wpaSupplicant: for s in supplicant: split = s.strip().split('=',1) if split[0] == 'ap_scan': - print "[Wlan.py] Got Hidden SSID Scan Value "+split[1] + print "[Wlan.py] Got Hidden SSID Scan Value ",split[1] if split[1] == '2': ap_scan = True else: ap_scan = False elif split[0] == 'ssid': - print "[Wlan.py] Got SSID "+split[1][1:-1] + print "[Wlan.py] Got SSID ",split[1][1:-1] essid = split[1][1:-1] elif split[0] == 'proto': diff --git a/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py b/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py index 290d139b..c296ab70 100644 --- a/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py +++ b/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py @@ -15,10 +15,10 @@ from os import system, path as os_path, listdir from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE from Tools.LoadPixmap import LoadPixmap from Tools.HardwareInfo import HardwareInfo -from Wlan import Wlan, wpaSupplicant, iStatus -import sha +from Wlan import iWlan, wpaSupplicant, iStatus, getWlanConfigName +import hashlib from time import time -from os import urandom +from os import urandom, system plugin_path = eEnv.resolve("${libdir}/enigma2/python/Plugins/SystemPlugins/WirelessLan") @@ -219,6 +219,8 @@ class WlanScan(Screen): "red": self.cancel, "green": self.select, }) + iWlan.setInterface(self.iface) + self.w = iWlan.getInterface() self.onLayoutFinish.append(self.layoutFinished) self.getAccessPoints(refresh = False) @@ -228,6 +230,7 @@ class WlanScan(Screen): def select(self): cur = self["list"].getCurrent() if cur is not None: + iWlan.stopGetNetworkList() self.rescanTimer.stop() del self.rescanTimer if cur[1] is not None: @@ -239,31 +242,16 @@ class WlanScan(Screen): else: self.close(None,None) else: + iWlan.stopGetNetworkList() self.rescanTimer.stop() del self.rescanTimer self.close(None,None) - def WlanSetupClosed(self, *ret): - if ret[0] == 2: - self.rescanTimer.stop() - del self.rescanTimer - self.close(None) - def cancel(self): - if self.oldInterfaceState is False: - iNetwork.setAdapterAttribute(self.iface, "up", False) - iNetwork.deactivateInterface(self.iface,self.deactivateInterfaceCB) - else: - self.rescanTimer.stop() - del self.rescanTimer - self.close(None) - - def deactivateInterfaceCB(self,data): - if data is not None: - if data is True: - self.rescanTimer.stop() - del self.rescanTimer - self.close(None) + iWlan.stopGetNetworkList() + self.rescanTimer.stop() + del self.rescanTimer + self.close(None) def rescanTimerFired(self): self.rescanTimer.stop() @@ -314,8 +302,7 @@ class WlanScan(Screen): def getAccessPoints(self, refresh = False): self.APList = [] self.cleanList = [] - self.w = Wlan(self.iface) - aps = self.w.getNetworkList() + aps = iWlan.getNetworkList() if aps is not None: print "[WirelessLan.py] got Accespoints!" tmpList = [] @@ -364,7 +351,7 @@ class WlanScan(Screen): self.WlanList = [] for entry in self['list'].list: if entry[1] == "hidden...": - self.WlanList.append(( "hidden...",_("enter hidden network SSID") ))#continue + self.WlanList.append(( "hidden...",_("enter hidden network SSID") )) else: self.WlanList.append( (entry[0], entry[0]) ) @@ -393,7 +380,7 @@ def decrypt_block(src, mod): if len(src) != 128 and len(src) != 202: return None dest = rsa_pub1024(src[:128], mod) - hash = sha.new(dest[1:107]) + hash = hashlib.sha1(dest[1:107]) if len(src) == 202: hash.update(src[131:192]) result = hash.digest() @@ -422,16 +409,12 @@ def WlanStatusScreenMain(session, iface): session.open(WlanStatus, iface) def callFunction(iface): - w = Wlan(iface) - i = w.getWirelessInterfaces() + iWlan.setInterface(iface) + i = iWlan.getWirelessInterfaces() if i: - if iface in i: + if iface in i or iNetwork.isWirelessInterface(iface): return WlanStatusScreenMain - else: - if iNetwork.isWirelessInterface(iface): - return WlanStatusScreenMain - else: - return None + return None return None def configStrings(iface): @@ -462,9 +445,9 @@ def configStrings(iface): driver = 'dreambox' print 'Using "%s" as wpa-supplicant driver' % (driver) ret = "" - if config.plugins.wlan.essid.value == "hidden...": + if driver == 'madwifi' and config.plugins.wlan.essid.value == "hidden...": ret += "\tpre-up iwconfig " + iface + " essid \"" + config.plugins.wlan.hiddenessid.value + "\" || true\n" - ret += "\tpre-up wpa_supplicant -i" + iface + " -c/etc/" + iface + "_wpa_supplicant.conf -B -dd -D" + driver + " || true\n" + ret += "\tpre-up wpa_supplicant -i" + iface + " -c" + getWlanConfigName(iface) + " -B -dd -D" + driver + " || true\n" ret += "\tpre-down wpa_cli -i" + iface + " terminate || true\n" return ret -- cgit v1.2.3 From ceaa1fb4f062d800be6ae5baffe261d9f4b39517 Mon Sep 17 00:00:00 2001 From: Mladen Horvat Date: Wed, 30 Mar 2011 11:05:26 +0200 Subject: SystemPlugins/SoftwareManager: change default backup names for wpa_supplicant configuration files. refs #389 --- .../SystemPlugins/SoftwareManager/BackupRestore.py | 3 +-- .../SystemPlugins/SoftwareManager/ImageWizard.py | 3 ++- .../SystemPlugins/SoftwareManager/SoftwareTools.py | 17 ++++++++++------- .../Plugins/SystemPlugins/SoftwareManager/plugin.py | 12 ++++++------ 4 files changed, 19 insertions(+), 16 deletions(-) (limited to 'lib/python/Plugins/SystemPlugins') diff --git a/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py b/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py index f06ae3e1..bfe28b46 100755 --- a/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py +++ b/lib/python/Plugins/SystemPlugins/SoftwareManager/BackupRestore.py @@ -17,10 +17,9 @@ from os import popen, path, makedirs, listdir, access, stat, rename, remove, W_O from time import gmtime, strftime, localtime from datetime import date - config.plugins.configurationbackup = ConfigSubsection() config.plugins.configurationbackup.backuplocation = ConfigText(default = '/media/hdd/', visible_width = 50, fixed_size = False) -config.plugins.configurationbackup.backupdirs = ConfigLocations(default=[eEnv.resolve('${sysconfdir}/enigma2/'), '/etc/network/interfaces', '/etc/wpa_supplicant.conf', '/etc/wlan0_wpa_supplicant.conf', '/etc/ath0_wpa_supplicant.conf', '/etc/resolv.conf', '/etc/default_gw', '/etc/hostname']) +config.plugins.configurationbackup.backupdirs = ConfigLocations(default=[eEnv.resolve('${sysconfdir}/enigma2/'), '/etc/network/interfaces', '/etc/wpa_supplicant.conf', '/etc/wpa_supplicant.ath0.conf', '/etc/wpa_supplicant.wlan0.conf', '/etc/resolv.conf', '/etc/default_gw', '/etc/hostname']) def getBackupPath(): backuppath = config.plugins.configurationbackup.backuplocation.value diff --git a/lib/python/Plugins/SystemPlugins/SoftwareManager/ImageWizard.py b/lib/python/Plugins/SystemPlugins/SoftwareManager/ImageWizard.py index 843abdc3..3ea787c1 100755 --- a/lib/python/Plugins/SystemPlugins/SoftwareManager/ImageWizard.py +++ b/lib/python/Plugins/SystemPlugins/SoftwareManager/ImageWizard.py @@ -13,10 +13,11 @@ from enigma import eEnv from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigText, ConfigLocations, ConfigBoolean from Components.Harddisk import harddiskmanager + config.misc.firstrun = ConfigBoolean(default = True) config.plugins.configurationbackup = ConfigSubsection() config.plugins.configurationbackup.backuplocation = ConfigText(default = '/media/hdd/', visible_width = 50, fixed_size = False) -config.plugins.configurationbackup.backupdirs = ConfigLocations(default=[eEnv.resolve('${sysconfdir}/enigma2/'), '/etc/network/interfaces', '/etc/wpa_supplicant.conf', '/etc/wlan0_wpa_supplicant.conf', '/etc/ath0_wpa_supplicant.conf', '/etc/resolv.conf', '/etc/default_gw', '/etc/hostname']) +config.plugins.configurationbackup.backupdirs = ConfigLocations(default=[eEnv.resolve('${sysconfdir}/enigma2/'), '/etc/network/interfaces', '/etc/wpa_supplicant.conf', '/etc/wpa_supplicant.ath0.conf', '/etc/wpa_supplicant.wlan0.conf', '/etc/resolv.conf', '/etc/default_gw', '/etc/hostname']) backupfile = "enigma2settingsbackup.tar.gz" diff --git a/lib/python/Plugins/SystemPlugins/SoftwareManager/SoftwareTools.py b/lib/python/Plugins/SystemPlugins/SoftwareManager/SoftwareTools.py index 87f0a4d6..178efadc 100755 --- a/lib/python/Plugins/SystemPlugins/SoftwareManager/SoftwareTools.py +++ b/lib/python/Plugins/SystemPlugins/SoftwareManager/SoftwareTools.py @@ -9,9 +9,10 @@ from Components.Ipkg import IpkgComponent from Components.Network import iNetwork from Tools.Directories import pathExists, fileExists, resolveFilename, SCOPE_METADIR from Tools.HardwareInfo import HardwareInfo -import sha - +import hashlib from time import time +from os import urandom + rootkey = ['\x9f', '|', '\xe4', 'G', '\xc9', '\xb4', '\xf4', '#', '&', '\xce', '\xb3', '\xfe', '\xda', '\xc9', 'U', '`', '\xd8', '\x8c', 's', 'o', '\x90', '\x9b', '\\', 'b', '\xc0', '\x89', '\xd1', '\x8c', '\x9e', 'J', 'T', '\xc5', 'X', '\xa1', '\xb8', '\x13', '5', 'E', '\x02', '\xc9', '\xb2', '\xe6', 't', '\x89', '\xde', '\xcd', '\x9d', '\x11', '\xdd', '\xc7', '\xf4', '\xe4', '\xe4', '\xbc', '\xdb', '\x9c', '\xea', '}', '\xad', '\xda', 't', 'r', '\x9b', '\xdc', '\xbc', '\x18', '3', '\xe7', '\xaf', '|', '\xae', '\x0c', '\xe3', '\xb5', '\x84', '\x8d', '\r', '\x8d', '\x9d', '2', '\xd0', '\xce', '\xd5', 'q', '\t', '\x84', 'c', '\xa8', ')', '\x99', '\xdc', '<', '"', 'x', '\xe8', '\x87', '\x8f', '\x02', ';', 'S', 'm', '\xd5', '\xf0', '\xa3', '_', '\xb7', 'T', '\t', '\xde', '\xa7', '\xf1', '\xc9', '\xae', '\x8a', '\xd7', '\xd2', '\xcf', '\xb2', '.', '\x13', '\xfb', '\xac', 'j', '\xdf', '\xb1', '\x1d', ':', '?'] def bin2long(s): @@ -30,7 +31,7 @@ def decrypt_block(src, mod): if len(src) != 128 and len(src) != 202: return None dest = rsa_pub1024(src[:128], mod) - hash = sha.new(dest[1:107]) + hash = hashlib.sha1(dest[1:107]) if len(src) == 202: hash.update(src[131:192]) result = hash.digest() @@ -46,10 +47,12 @@ def validate_cert(cert, key): def read_random(): try: - fd = open("/dev/urandom", "r") - buf = fd.read(8) - fd.close() - return buf + xor = lambda a,b: ''.join(chr(ord(c)^ord(d)) for c,d in zip(a,b*100)) + random = urandom(8) + x = str(time())[-8:] + result = xor(random, x) + + return result except: return None diff --git a/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py b/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py index 7901fd07..f78b7582 100644 --- a/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py +++ b/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py @@ -43,10 +43,10 @@ from SoftwareTools import iSoftwareTools config.plugins.configurationbackup = ConfigSubsection() config.plugins.configurationbackup.backuplocation = ConfigText(default = '/media/hdd/', visible_width = 50, fixed_size = False) -config.plugins.configurationbackup.backupdirs = ConfigLocations(default=[eEnv.resolve('${sysconfdir}/enigma2/'), '/etc/network/interfaces', '/etc/wpa_supplicant.conf', '/etc/wlan0_wpa_supplicant.conf', '/etc/ath0_wpa_supplicant.conf', '/etc/resolv.conf', '/etc/default_gw', '/etc/hostname']) +config.plugins.configurationbackup.backupdirs = ConfigLocations(default=[eEnv.resolve('${sysconfdir}/enigma2/'), '/etc/network/interfaces', '/etc/wpa_supplicant.conf', '/etc/wpa_supplicant.ath0.conf', '/etc/wpa_supplicant.wlan0.conf', '/etc/resolv.conf', '/etc/default_gw', '/etc/hostname']) -config.plugins.SoftwareManager = ConfigSubsection() -config.plugins.SoftwareManager.overwriteConfigFiles = ConfigSelection( +config.plugins.softwaremanager = ConfigSubsection() +config.plugins.softwaremanager.overwriteConfigFiles = ConfigSelection( [ ("Y", _("Yes, always")), ("N", _("No, never")), @@ -365,7 +365,7 @@ class SoftwareManagerSetup(Screen, ConfigListScreen): def createSetup(self): self.list = [ ] - self.overwriteConfigfilesEntry = getConfigListEntry(_("Overwrite configuration files ?"), config.plugins.SoftwareManager.overwriteConfigFiles) + self.overwriteConfigfilesEntry = getConfigListEntry(_("Overwrite configuration files ?"), config.plugins.softwaremanager.overwriteConfigFiles) self.list.append(self.overwriteConfigfilesEntry) self["config"].list = self.list self["config"].l.setSeperation(400) @@ -1414,8 +1414,8 @@ class UpdatePlugin(Screen): self.status.setText(_("Configuring")) elif event == IpkgComponent.EVENT_MODIFIED: - if config.plugins.SoftwareManager.overwriteConfigFiles.value in ("N", "Y"): - self.ipkg.write(True and config.plugins.SoftwareManager.overwriteConfigFiles.value) + if config.plugins.softwaremanager.overwriteConfigFiles.value in ("N", "Y"): + self.ipkg.write(True and config.plugins.softwaremanager.overwriteConfigFiles.value) else: self.session.openWithCallback( self.modificationCallback, -- cgit v1.2.3 From c3c412e8765520205b7cf8413ddf8abca74f1bc3 Mon Sep 17 00:00:00 2001 From: Mladen Horvat Date: Thu, 31 Mar 2011 12:09:21 +0200 Subject: Screens/NetworkSetup.py, SystemPlugins/WirelessLan,Networkwizard: dont use "hidden..." as selector for hidden networks. Add config option for entering a hidden network ssid. This is more intuitive as selecting the option from the found networks. refs #725 --- .../SystemPlugins/NetworkWizard/NetworkWizard.py | 40 ++++------------ .../Plugins/SystemPlugins/NetworkWizard/plugin.py | 4 +- .../Plugins/SystemPlugins/WirelessLan/Wlan.py | 54 +++++++++------------- .../Plugins/SystemPlugins/WirelessLan/plugin.py | 25 +++++----- lib/python/Screens/NetworkSetup.py | 42 ++++++++++------- 5 files changed, 72 insertions(+), 93 deletions(-) (limited to 'lib/python/Plugins/SystemPlugins') diff --git a/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py b/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py index e99309a9..9f254066 100755 --- a/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py +++ b/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py @@ -4,33 +4,11 @@ from Screens.Rc import Rc from Screens.MessageBox import MessageBox from Components.Pixmap import Pixmap, MovingPixmap, MultiPixmap from Components.Sources.Boolean import Boolean -from Components.config import config, ConfigBoolean, configfile, ConfigYesNo, NoSave, ConfigSubsection, ConfigText, getConfigListEntry, ConfigSelection, ConfigPassword from Components.Network import iNetwork from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE from enigma import eTimer from os import system -config.misc.firstrun = ConfigBoolean(default = True) -list = [] -list.append("WEP") -list.append("WPA") -list.append("WPA2") -list.append("WPA/WPA2") - -weplist = [] -weplist.append("ASCII") -weplist.append("HEX") - -config.plugins.wlan = ConfigSubsection() -config.plugins.wlan.essid = NoSave(ConfigText(default = "home", fixed_size = False)) -config.plugins.wlan.hiddenessid = NoSave(ConfigText(default = "home", fixed_size = False)) - -config.plugins.wlan.encryption = ConfigSubsection() -config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = False)) -config.plugins.wlan.encryption.type = NoSave(ConfigSelection(list, default = "WPA/WPA2" )) -config.plugins.wlan.encryption.wepkeytype = NoSave(ConfigSelection(weplist, default = "ASCII")) -config.plugins.wlan.encryption.psk = NoSave(ConfigPassword(default = "mysecurewlan", fixed_size = False)) - class NetworkWizard(WizardLanguage, Rc): skin = """ @@ -306,13 +284,13 @@ class NetworkWizard(WizardLanguage, Rc): newList.append(oldentry) for newentry in newList: - if newentry[1] == "hidden...": + if newentry[1] == "": continue self.newAPlist.append(newentry) if len(self.newAPlist): - if "hidden..." not in self.newAPlist: - self.newAPlist.append(( _("enter hidden network SSID"), "hidden..." )) + if "" not in self.newAPlist: + self.newAPlist.append(( _("enter hidden network SSID"), "" )) if (self.wizard[self.currStep].has_key("dynamiclist")): currentListEntry = self["list"].getCurrent() @@ -359,9 +337,9 @@ class NetworkWizard(WizardLanguage, Rc): complist.remove(compentry) for entry in complist: self.APList.append( (entry[1], entry[1]) ) - - if "hidden..." not in self.APList: - self.APList.append(( _("enter hidden network SSID"), "hidden..." )) + + if "" not in self.APList: + self.APList.append(( _("enter hidden network SSID"), "" )) self.rescanTimer.start(5000) return self.APList @@ -369,10 +347,10 @@ class NetworkWizard(WizardLanguage, Rc): def AccessPointsSelectionMade(self, index): self.ap = index self.WlanList = [] - currList = [] if (self.wizard[self.currStep].has_key("dynamiclist")): - currList = self['list'].list - for entry in currList: + for entry in self['list'].list: + if entry[1] == "": + continue self.WlanList.append( (entry[1], entry[0]) ) self.AccessPointsSelect(index) diff --git a/lib/python/Plugins/SystemPlugins/NetworkWizard/plugin.py b/lib/python/Plugins/SystemPlugins/NetworkWizard/plugin.py index 56cebdbf..30a24230 100644 --- a/lib/python/Plugins/SystemPlugins/NetworkWizard/plugin.py +++ b/lib/python/Plugins/SystemPlugins/NetworkWizard/plugin.py @@ -1,6 +1,8 @@ from Screens.Screen import Screen from Plugins.Plugin import PluginDescriptor -from Components.config import getConfigListEntry, config +from Components.config import getConfigListEntry, config, ConfigBoolean + +config.misc.firstrun = ConfigBoolean(default = True) def NetworkWizardMain(session, **kwargs): session.open(NetworkWizard) diff --git a/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py b/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py index 5b76f926..4a7b1e88 100755 --- a/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py +++ b/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py @@ -22,7 +22,7 @@ weplist.append("HEX") config.plugins.wlan = ConfigSubsection() config.plugins.wlan.essid = NoSave(ConfigText(default = "home", fixed_size = False)) -config.plugins.wlan.hiddenessid = NoSave(ConfigText(default = "home", fixed_size = False)) +config.plugins.wlan.hiddenessid = NoSave(ConfigYesNo(default = False)) config.plugins.wlan.encryption = ConfigSubsection() config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = True)) @@ -146,15 +146,13 @@ class wpaSupplicant: fp.write('ctrl_interface=/var/run/wpa_supplicant\n') fp.write('eapol_version=1\n') fp.write('fast_reauth=1\n') - if essid == 'hidden...': + + if hiddenessid: fp.write('ap_scan=2\n') else: fp.write('ap_scan=1\n') fp.write('network={\n') - if essid == 'hidden...': - fp.write('\tssid="'+hiddenessid+'"\n') - else: - fp.write('\tssid="'+essid+'"\n') + fp.write('\tssid="'+essid+'"\n') fp.write('\tscan_ssid=0\n') if encrypted: if encryption in ('WPA', 'WPA2', 'WPA/WPA2'): @@ -184,7 +182,7 @@ class wpaSupplicant: fp.write('}') fp.write('\n') fp.close() - system('cat ' + getWlanConfigName(iface)) + #system('cat ' + getWlanConfigName(iface)) def loadConfig(self,iface): configfile = getWlanConfigName(iface) @@ -196,22 +194,22 @@ class wpaSupplicant: fp = file(configfile, 'r') supplicant = fp.readlines() fp.close() - ap_scan = False essid = None for s in supplicant: split = s.strip().split('=',1) if split[0] == 'ap_scan': - print "[Wlan.py] Got Hidden SSID Scan Value ",split[1] + #print "[Wlan.py] Got Hidden SSID Scan Value ",split[1] if split[1] == '2': - ap_scan = True + config.plugins.wlan.hiddenessid.value = True else: - ap_scan = False - + config.plugins.wlan.hiddenessid.value = False + elif split[0] == 'ssid': - print "[Wlan.py] Got SSID ",split[1][1:-1] + #print "[Wlan.py] Got SSID ",split[1][1:-1] essid = split[1][1:-1] - + config.plugins.wlan.essid.value = essid + elif split[0] == 'proto': config.plugins.wlan.encryption.enabled.value = True if split[1] == 'WPA' : @@ -220,8 +218,8 @@ class wpaSupplicant: mode = 'WPA2' if split[1] in ('WPA RSN', 'WPA WPA2'): mode = 'WPA/WPA2' + #print "[Wlan.py] Got Encryption: ",mode config.plugins.wlan.encryption.type.value = mode - print "[Wlan.py] Got Encryption: "+mode elif split[0] == 'wep_key0': config.plugins.wlan.encryption.enabled.value = True @@ -238,12 +236,6 @@ class wpaSupplicant: else: pass - if ap_scan is True: - config.plugins.wlan.hiddenessid.value = essid - config.plugins.wlan.essid.value = 'hidden...' - else: - config.plugins.wlan.hiddenessid.value = essid - config.plugins.wlan.essid.value = essid wsconfig = { 'hiddenessid': config.plugins.wlan.hiddenessid.value, 'ssid': config.plugins.wlan.essid.value, @@ -256,28 +248,28 @@ class wpaSupplicant: for (key, item) in wsconfig.items(): if item is "None" or item is "": if key == 'hiddenessid': - wsconfig['hiddenessid'] = "home" + wsconfig['hiddenessid'] = False if key == 'ssid': wsconfig['ssid'] = "home" if key == 'encryption': wsconfig['encryption'] = True - if key == 'encryption': + if key == 'encryption_type': wsconfig['encryption_type'] = "WPA/WPA2" - if key == 'encryption': + if key == 'encryption_wepkeytype': wsconfig['encryption_wepkeytype'] = "ASCII" - if key == 'encryption': + if key == 'key': wsconfig['key'] = "mysecurewlan" except: print "[Wlan.py] Error parsing ",configfile wsconfig = { - 'hiddenessid': "home", + 'hiddenessid': False, 'ssid': "home", 'encryption': True, 'encryption_type': "WPA/WPA2", 'encryption_wepkeytype': "ASCII", 'key': "mysecurewlan", } - print "[Wlan.py] WS-CONFIG-->",wsconfig + #print "[Wlan.py] WS-CONFIG-->",wsconfig return wsconfig @@ -309,17 +301,13 @@ class Status: else: if "Nickname" in line: tmpssid=(line[line.index('ESSID')+7:line.index('" Nickname')]) - if tmpssid == '': - ssid = _("Hidden networkname") - elif tmpssid ==' ': + if tmpssid in ('', ' '): ssid = _("Hidden networkname") else: ssid = tmpssid else: tmpssid=(line[line.index('ESSID')+7:len(line)-1]) - if tmpssid == '': - ssid = _("Hidden networkname") - elif tmpssid ==' ': + if tmpssid in ('', ' '): ssid = _("Hidden networkname") else: ssid = tmpssid diff --git a/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py b/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py index c296ab70..6e88a3ea 100644 --- a/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py +++ b/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py @@ -22,6 +22,7 @@ from os import urandom, system plugin_path = eEnv.resolve("${libdir}/enigma2/python/Plugins/SystemPlugins/WirelessLan") + list = [] list.append("WEP") list.append("WPA") @@ -34,7 +35,7 @@ weplist.append("HEX") config.plugins.wlan = ConfigSubsection() config.plugins.wlan.essid = NoSave(ConfigText(default = "home", fixed_size = False)) -config.plugins.wlan.hiddenessid = NoSave(ConfigText(default = "home", fixed_size = False)) +config.plugins.wlan.hiddenessid = NoSave(ConfigYesNo(default = False)) config.plugins.wlan.encryption = ConfigSubsection() config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = False)) @@ -234,7 +235,7 @@ class WlanScan(Screen): self.rescanTimer.stop() del self.rescanTimer if cur[1] is not None: - if cur[1] == 'hidden...': + if cur[1] == '': essid = cur[1] else: essid = cur[0] @@ -260,7 +261,7 @@ class WlanScan(Screen): def buildEntryComponent(self, essid, bssid, encrypted, iface, maxrate, signal): divpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/div-h.png")) encryption = encrypted and _("Yes") or _("No") - if bssid == 'hidden...': + if bssid == '': return((essid, bssid, None, None, None, None, divpng)) else: return((essid, bssid, _("Signal: ") + str(signal), _("Max. Bitrate: ") + str(maxrate), _("Encrypted: ") + encryption, _("Interface: ") + str(iface), divpng)) @@ -280,9 +281,9 @@ class WlanScan(Screen): tmpList.append(data) if len(tmpList): - if "hidden..." not in tmpList: - tmpList.append( ( _("enter hidden network SSID"), "hidden...", True, self.iface, _("unavailable"), "" ) ) - + if "" not in tmpList: + tmpList.append( ( _("enter hidden network SSID"), "", True, self.iface, _("unavailable"), "" ) ) + for entry in tmpList: self.newAPList.append(self.buildEntryComponent( entry[0], entry[1], entry[2], entry[3], entry[4], entry[5] )) @@ -325,8 +326,8 @@ class WlanScan(Screen): else: self.oldlist[entry[0]]['data'] = entry - if "hidden..." not in self.cleanList: - self.cleanList.append( ( _("enter hidden network SSID"), "hidden...", True, self.iface, _("unavailable"), "" ) ) + if "" not in self.cleanList: + self.cleanList.append( ( _("enter hidden network SSID"), "", True, self.iface, _("unavailable"), "" ) ) for entry in self.cleanList: self.APList.append(self.buildEntryComponent( entry[0], entry[1], entry[2], entry[3], entry[4], entry[5] )) @@ -350,8 +351,8 @@ class WlanScan(Screen): def buildWlanList(self): self.WlanList = [] for entry in self['list'].list: - if entry[1] == "hidden...": - self.WlanList.append(( "hidden...",_("enter hidden network SSID") )) + if entry[1] == "": + continue else: self.WlanList.append( (entry[0], entry[0]) ) @@ -445,8 +446,8 @@ def configStrings(iface): driver = 'dreambox' print 'Using "%s" as wpa-supplicant driver' % (driver) ret = "" - if driver == 'madwifi' and config.plugins.wlan.essid.value == "hidden...": - ret += "\tpre-up iwconfig " + iface + " essid \"" + config.plugins.wlan.hiddenessid.value + "\" || true\n" + if driver == 'madwifi' and config.plugins.wlan.hiddenessid.value: + ret += "\tpre-up iwconfig " + iface + " essid \"" + config.plugins.wlan.essid.value + "\" || true\n" ret += "\tpre-up wpa_supplicant -i" + iface + " -c" + getWlanConfigName(iface) + " -B -dd -D" + driver + " || true\n" ret += "\tpre-down wpa_cli -i" + iface + " terminate || true\n" return ret diff --git a/lib/python/Screens/NetworkSetup.py b/lib/python/Screens/NetworkSetup.py index 5d378524..e7ba6071 100755 --- a/lib/python/Screens/NetworkSetup.py +++ b/lib/python/Screens/NetworkSetup.py @@ -11,7 +11,7 @@ from Components.Sources.List import List from Components.Label import Label,MultiColorLabel from Components.Pixmap import Pixmap,MultiPixmap from Components.MenuList import MenuList -from Components.config import config, ConfigYesNo, ConfigIP, NoSave, ConfigText, ConfigPassword, ConfigSelection, getConfigListEntry, ConfigNothing +from Components.config import config, ConfigYesNo, ConfigIP, NoSave, ConfigText, ConfigPassword, ConfigSelection, getConfigListEntry, ConfigNothing, ConfigBoolean from Components.ConfigList import ConfigListScreen from Components.PluginComponent import plugins from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest @@ -308,6 +308,7 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen): self.iface = networkinfo self.essid = essid self.aplist = aplist + self.extended = None self.applyConfigRef = None self.finished_cb = None @@ -406,6 +407,7 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen): self.weplist = None self.wsconfig = None self.default = None + self.hiddenNW = None if iNetwork.isWirelessInterface(self.iface): from Plugins.SystemPlugins.WirelessLan.Wlan import wpaSupplicant, iWlan @@ -442,16 +444,22 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen): self.wsconfig = self.ws.loadConfig(self.iface) if self.essid is not None: # ssid from wlan scan self.default = self.essid + self.hiddenNW = self.wsconfig['hiddenessid'] + if self.essid == '': + self.hiddenNW = True + self.default = self.default = self.wsconfig['ssid'] else: + self.hiddenNW = self.wsconfig['hiddenessid'] self.default = self.wsconfig['ssid'] - if "hidden..." not in self.nwlist: - self.nwlist.append(("hidden...",_("enter hidden network SSID"))) - if self.default not in self.nwlist: + if (self.default not in self.nwlist and self.default is not ''): self.nwlist.append((self.default,self.default)) - config.plugins.wlan.essid = NoSave(ConfigSelection(self.nwlist, default = self.default )) - config.plugins.wlan.hiddenessid = NoSave(ConfigText(default = self.wsconfig['hiddenessid'], visible_width = 50, fixed_size = False)) - + + config.plugins.wlan.hiddenessid = NoSave(ConfigYesNo(default = self.hiddenNW)) + if config.plugins.wlan.hiddenessid.value is True: + config.plugins.wlan.essid = NoSave(ConfigText(default = self.default, visible_width = 50, fixed_size = False)) + else: + config.plugins.wlan.essid = NoSave(ConfigSelection(self.nwlist, default = self.default )) config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = self.wsconfig['encryption'] )) config.plugins.wlan.encryption.type = NoSave(ConfigSelection(self.encryptionlist, default = self.wsconfig['encryption_type'] )) config.plugins.wlan.encryption.wepkeytype = NoSave(ConfigSelection(self.weplist, default = self.wsconfig['encryption_wepkeytype'] )) @@ -497,14 +505,16 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen): if p.__call__.has_key("configStrings"): self.configStrings = p.__call__["configStrings"] - if config.plugins.wlan.essid.value == 'hidden...': - self.wlanSSID = getConfigListEntry(_("Network SSID"), config.plugins.wlan.essid) - self.list.append(self.wlanSSID) - self.hiddenSSID = getConfigListEntry(_("Hidden network SSID"), config.plugins.wlan.hiddenessid) - self.list.append(self.hiddenSSID) + self.hiddenSSID = getConfigListEntry(_("enter hidden network SSID"), config.plugins.wlan.hiddenessid) + self.list.append(self.hiddenSSID) + + if config.plugins.wlan.hiddenessid.value is True: + config.plugins.wlan.essid = NoSave(ConfigText(default = self.default, visible_width = 50, fixed_size = False)) + self.wlanSSID = getConfigListEntry(_("Hidden network SSID"), config.plugins.wlan.essid) else: + config.plugins.wlan.essid = NoSave(ConfigSelection(self.nwlist, default = self.default )) self.wlanSSID = getConfigListEntry(_("Network SSID"), config.plugins.wlan.essid) - self.list.append(self.wlanSSID) + self.list.append(self.wlanSSID) self.encryptionEnabled = getConfigListEntry(_("Encryption"), config.plugins.wlan.encryption.enabled) self.list.append(self.encryptionEnabled) @@ -532,8 +542,8 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen): self.createSetup() if self["config"].getCurrent() == self.gatewayEntry: self.createSetup() - if iNetwork.isWirelessInterface(self.iface): - if self["config"].getCurrent() == self.wlanSSID: + if iNetwork.isWirelessInterface(self.iface): + if self["config"].getCurrent() == self.hiddenSSID: self.createSetup() if self["config"].getCurrent() == self.encryptionEnabled: self.createSetup() @@ -677,7 +687,7 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen): def hideInputHelp(self): current = self["config"].getCurrent() - if current == self.hiddenSSID and config.plugins.wlan.essid.value == 'hidden...': + if current == self.wlanSSID and config.plugins.wlan.hiddenessid.value: if current[1].help_window.instance is not None: current[1].help_window.instance.hide() elif current == self.encryptionKey and config.plugins.wlan.encryption.enabled.value: -- cgit v1.2.3 From c563ffd07163d5982fa4a3d8e9c2486f480b899a Mon Sep 17 00:00:00 2001 From: Mladen Horvat Date: Wed, 13 Apr 2011 16:23:09 +0200 Subject: Enigma2-{Network,NetworkWizard,WirelessLan}: more work on wireless lan / networking. removed 'hidden' links from lists and replaced with more intuitive options in networkwizard/networksetup. fixes #725 --- lib/python/Components/Network.py | 27 ++- .../SystemPlugins/NetworkWizard/NetworkWizard.py | 89 ++++------ .../SystemPlugins/NetworkWizard/networkwizard.xml | 25 ++- .../Plugins/SystemPlugins/WirelessLan/Wlan.py | 190 +++++++++------------ .../Plugins/SystemPlugins/WirelessLan/plugin.py | 140 ++++++++------- lib/python/Screens/NetworkSetup.py | 123 +++++-------- 6 files changed, 283 insertions(+), 311 deletions(-) (limited to 'lib/python/Plugins/SystemPlugins') diff --git a/lib/python/Components/Network.py b/lib/python/Components/Network.py index f38ee515..68f98017 100755 --- a/lib/python/Components/Network.py +++ b/lib/python/Components/Network.py @@ -541,7 +541,7 @@ class Network: def buildCommands(iface): commands.append("ifdown " + iface) commands.append("ip addr flush dev " + iface) - # HACK: wpa_supplicant sometimes doesn't quit properly on SIGTERM + #wpa_supplicant sometimes doesn't quit properly on SIGTERM if os_path.exists('/var/run/wpa_supplicant/'+ iface): commands.append("wpa_cli -i" + iface + " terminate") @@ -558,16 +558,35 @@ class Network: callback(True) return buildCommands(ifaces) - self.deactivateInterfaceConsole.eBatch(commands, self.deactivateInterfaceFinished, callback, debug=True) + self.deactivateInterfaceConsole.eBatch(commands, self.deactivateInterfaceFinished, [ifaces,callback], debug=True) def deactivateInterfaceFinished(self,extra_args): - callback = extra_args + (ifaces, callback) = extra_args + def checkCommandResult(iface): + if self.deactivateInterfaceConsole and self.deactivateInterfaceConsole.appResults.has_key("ifdown " + iface): + result = str(self.deactivateInterfaceConsole.appResults.get("ifdown " + iface)).strip("\n") + if result == "ifdown: interface " + iface + " not configured": + return False + else: + return True + #ifdown sometimes can't get the interface down. + if isinstance(ifaces, (list, tuple)): + for iface in ifaces: + if checkCommandResult(iface) is False: + Console().ePopen(("ifconfig " + iface + " down" )) + else: + if checkCommandResult(ifaces) is False: + Console().ePopen(("ifconfig " + ifaces + " down" )) + if self.deactivateInterfaceConsole: if len(self.deactivateInterfaceConsole.appContainers) == 0: if callback is not None: callback(True) def activateInterface(self,iface,callback = None): + if self.config_ready: + self.config_ready = False + self.msgPlugins() if iface == 'eth0' and self.onRemoteRootFS(): if callback is not None: callback(True) @@ -576,7 +595,7 @@ class Network: self.activateInterfaceConsole = Console() commands = [] commands.append("ifup " + iface) - self.deactivateInterfaceConsole.eBatch(commands, self.activateInterfaceFinished, callback, debug=True) + self.activateInterfaceConsole.eBatch(commands, self.activateInterfaceFinished, callback, debug=True) def activateInterfaceFinished(self,extra_args): callback = extra_args diff --git a/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py b/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py index 9f254066..cb954bb2 100755 --- a/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py +++ b/lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py @@ -57,7 +57,6 @@ class NetworkWizard(WizardLanguage, Rc): self.AdapterRef = None self.APList = None self.newAPlist = None - self.WlanList = None self.oldlist = None self.originalInterfaceState = {} @@ -79,6 +78,11 @@ class NetworkWizard(WizardLanguage, Rc): self.checkOldInterfaceState() pass + def back(self): + self.stopScan() + self.ap = None + WizardLanguage.back(self) + def stopScan(self): self.rescanTimer.stop() if self.w is not None: @@ -88,7 +92,6 @@ class NetworkWizard(WizardLanguage, Rc): def getInstalledInterfaceCount(self): self.originalInterfaceState = {} - self.stopScan() self.Adapterlist = iNetwork.getAdapterList() self.InstalledInterfaceCount = len(self.Adapterlist) if self.Adapterlist is not None: @@ -105,7 +108,7 @@ class NetworkWizard(WizardLanguage, Rc): if not iNetwork.isWirelessInterface(self.selectedInterface): self.NextStep = 'nwconfig' else: - self.NextStep = 'scanwlan' + self.NextStep = 'asknetworktype' self.checkInterface(self.selectedInterface) else: self.NextStep = 'selectinterface' @@ -115,19 +118,19 @@ class NetworkWizard(WizardLanguage, Rc): if not iNetwork.isWirelessInterface(self.selectedInterface): self.NextStep = 'nwconfig' else: - self.NextStep = 'scanwlan' + self.NextStep = 'asknetworktype' self.checkInterface(self.selectedInterface) def checkOldInterfaceState(self): # disable up interface if it was originally down and config is unchanged. if self.originalInterfaceStateChanged is False: for interface in self.originalInterfaceState.keys(): - if self.originalInterfaceState[interface]["up"] is False: - if iNetwork.checkforInterface(interface) is True: - system("ifconfig " + interface + " down") + if interface == self.selectedInterface: + if self.originalInterfaceState[interface]["up"] is False: + if iNetwork.checkforInterface(interface) is True: + system("ifconfig " + interface + " down") def listInterfaces(self): - self.stopScan() self.checkOldInterfaceState() list = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()] list.append((_("Exit network wizard"), "end")) @@ -143,7 +146,7 @@ class NetworkWizard(WizardLanguage, Rc): elif index == 'eth0': self.NextStep = 'nwconfig' else: - self.NextStep = 'scanwlan' + self.NextStep = 'asknetworktype' def InterfaceSelectionMoved(self): self.InterfaceSelect(self.selection) @@ -229,7 +232,7 @@ class NetworkWizard(WizardLanguage, Rc): if data is True: if status is not None: text1 = _("Your Dreambox is now ready to use.\n\nYour internet connection is working now.\n\n") - text2 = _('Accesspoint:') + "\t" + str(status[self.selectedInterface]["acesspoint"]) + "\n" + text2 = _('Accesspoint:') + "\t" + str(status[self.selectedInterface]["accesspoint"]) + "\n" text3 = _('SSID:') + "\t" + str(status[self.selectedInterface]["essid"]) + "\n" text4 = _('Link Quality:') + "\t" + str(status[self.selectedInterface]["quality"])+ "\n" text5 = _('Signal Strength:') + "\t" + str(status[self.selectedInterface]["signal"]) + "\n" @@ -239,7 +242,7 @@ class NetworkWizard(WizardLanguage, Rc): infotext = text1 + text2 + text3 + text4 + text5 + text7 +"\n" + text8 self.currStep = self.getStepWithID("checkWlanstatusend") self.Text = infotext - if str(status[self.selectedInterface]["acesspoint"]) == "Not-Associated": + if str(status[self.selectedInterface]["accesspoint"]) == "Not-Associated": self.InterfaceState = False self.afterAsyncCode() @@ -284,42 +287,32 @@ class NetworkWizard(WizardLanguage, Rc): newList.append(oldentry) for newentry in newList: - if newentry[1] == "": - continue self.newAPlist.append(newentry) - - if len(self.newAPlist): - if "" not in self.newAPlist: - self.newAPlist.append(( _("enter hidden network SSID"), "" )) + if len(self.newAPlist): if (self.wizard[self.currStep].has_key("dynamiclist")): currentListEntry = self["list"].getCurrent() - idx = 0 - for entry in self.newAPlist: - if entry == currentListEntry: - newListIndex = idx - idx +=1 + if currentListEntry is not None: + idx = 0 + for entry in self.newAPlist: + if entry == currentListEntry: + newListIndex = idx + idx +=1 self.wizard[self.currStep]["evaluatedlist"] = self.newAPlist self['list'].setList(self.newAPlist) - self["list"].setIndex(newListIndex) + if newListIndex is not None: + self["list"].setIndex(newListIndex) self["list"].updateList(self.newAPlist) def listAccessPoints(self): self.APList = [] if self.WlanPluginInstalled is False: - self.APList.append( ( _("No networks found"),_("unavailable") ) ) - return self.APList + self.APList.append( ( _("No networks found"), None ) ) else: - try: - from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan - iWlan.setInterface(self.selectedInterface) - self.w = iWlan.getInterface() - aps = iWlan.getNetworkList() - except ValueError: - self.APList = [] - self.APList.append( ( _("No networks found"),_("unavailable") ) ) - return self.APList - + from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan + iWlan.setInterface(self.selectedInterface) + self.w = iWlan.getInterface() + aps = iWlan.getNetworkList() if aps is not None: print "[NetworkWizard.py] got Accespoints!" tmplist = [] @@ -337,28 +330,16 @@ class NetworkWizard(WizardLanguage, Rc): complist.remove(compentry) for entry in complist: self.APList.append( (entry[1], entry[1]) ) - - if "" not in self.APList: - self.APList.append(( _("enter hidden network SSID"), "" )) + if not len(aps): + self.APList.append( ( _("No networks found"), None ) ) - self.rescanTimer.start(5000) - return self.APList + self.rescanTimer.start(4000) + return self.APList - def AccessPointsSelectionMade(self, index): - self.ap = index - self.WlanList = [] - if (self.wizard[self.currStep].has_key("dynamiclist")): - for entry in self['list'].list: - if entry[1] == "": - continue - self.WlanList.append( (entry[1], entry[0]) ) - self.AccessPointsSelect(index) - - def AccessPointsSelect(self, index): - self.NextStep = 'wlanconfig' def AccessPointsSelectionMoved(self): - self.AccessPointsSelect(self.selection) + self.ap = self.selection + self.NextStep = 'wlanconfig' def checkWlanSelection(self): self.stopScan() @@ -391,7 +372,7 @@ class NetworkWizard(WizardLanguage, Rc): self.selectedInterface = "eth0" self.NextStep = 'nwconfig' else: - self.NextStep = 'scanwlan' + self.NextStep = 'asknetworktype' def ChoicesSelectionMoved(self): pass diff --git a/lib/python/Plugins/SystemPlugins/NetworkWizard/networkwizard.xml b/lib/python/Plugins/SystemPlugins/NetworkWizard/networkwizard.xml index c4300436..0b3a2988 100755 --- a/lib/python/Plugins/SystemPlugins/NetworkWizard/networkwizard.xml +++ b/lib/python/Plugins/SystemPlugins/NetworkWizard/networkwizard.xml @@ -87,13 +87,33 @@ self.selectKey("DOWN") + + + +self.condition = (self.isInterfaceUp == True and self.WlanPluginInstalled == True) + + + + +self.clearSelectedKeys() +self.selectKey("OK") +self.selectKey("UP") +self.selectKey("DOWN") + + + + + + + + self.condition = (self.isInterfaceUp == True and self.WlanPluginInstalled == True) - + self.clearSelectedKeys() self.selectKey("OK") @@ -138,7 +158,7 @@ self.selectKey("DOWN") - + self.clearSelectedKeys() self.selectKey("OK") @@ -196,4 +216,3 @@ self.selectKey("OK") - diff --git a/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py b/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py index 4a7b1e88..a1851579 100755 --- a/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py +++ b/lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py @@ -6,29 +6,28 @@ from os import system, path as os_path from string import maketrans, strip import sys import types -from re import compile as re_compile, search as re_search +from re import compile as re_compile, search as re_search, escape as re_escape from pythonwifi.iwlibs import getNICnames, Wireless, Iwfreq, getWNICnames from pythonwifi import flags as wififlags list = [] +list.append("Unencrypted") list.append("WEP") list.append("WPA") -list.append("WPA2") list.append("WPA/WPA2") +list.append("WPA2") weplist = [] weplist.append("ASCII") weplist.append("HEX") config.plugins.wlan = ConfigSubsection() -config.plugins.wlan.essid = NoSave(ConfigText(default = "home", fixed_size = False)) +config.plugins.wlan.essid = NoSave(ConfigText(default = "", fixed_size = False)) config.plugins.wlan.hiddenessid = NoSave(ConfigYesNo(default = False)) +config.plugins.wlan.encryption = NoSave(ConfigSelection(list, default = "WPA2")) +config.plugins.wlan.wepkeytype = NoSave(ConfigSelection(weplist, default = "ASCII")) +config.plugins.wlan.psk = NoSave(ConfigPassword(default = "", fixed_size = False)) -config.plugins.wlan.encryption = ConfigSubsection() -config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = True)) -config.plugins.wlan.encryption.type = NoSave(ConfigSelection(list, default = "WPA/WPA2")) -config.plugins.wlan.encryption.wepkeytype = NoSave(ConfigSelection(weplist, default = "ASCII")) -config.plugins.wlan.encryption.psk = NoSave(ConfigPassword(default = "mysecurewlan", fixed_size = False)) def getWlanConfigName(iface): return '/etc/wpa_supplicant.' + iface + '.conf' @@ -74,10 +73,9 @@ class Wlan: scanresults = ifobj.scan() except: scanresults = None - print "[Wlan.py] No Wireless Networks could be found" - + print "[Wlan.py] No wireless networks could be found" + aps = {} if scanresults is not None: - aps = {} (num_channels, frequencies) = ifobj.getChannelInfo() index = 1 for result in scanresults: @@ -116,9 +114,9 @@ class Wlan: 'signal' : str(signal), 'custom' : extra, } - #print "GOT APS ENTRY:",aps[bssid] + index = index + 1 - return aps + return aps def stopGetNetworkList(self): if self.oldInterfaceState is not None: @@ -137,10 +135,9 @@ class wpaSupplicant: def writeConfig(self, iface): essid = config.plugins.wlan.essid.value hiddenessid = config.plugins.wlan.hiddenessid.value - encrypted = config.plugins.wlan.encryption.enabled.value - encryption = config.plugins.wlan.encryption.type.value - wepkeytype = config.plugins.wlan.encryption.wepkeytype.value - psk = config.plugins.wlan.encryption.psk.value + encryption = config.plugins.wlan.encryption.value + wepkeytype = config.plugins.wlan.wepkeytype.value + psk = config.plugins.wlan.psk.value fp = file(getWlanConfigName(iface), 'w') fp.write('#WPA Supplicant Configuration by enigma2\n') fp.write('ctrl_interface=/var/run/wpa_supplicant\n') @@ -154,31 +151,29 @@ class wpaSupplicant: fp.write('network={\n') fp.write('\tssid="'+essid+'"\n') fp.write('\tscan_ssid=0\n') - if encrypted: - if encryption in ('WPA', 'WPA2', 'WPA/WPA2'): - fp.write('\tkey_mgmt=WPA-PSK\n') - - if encryption == 'WPA': - fp.write('\tproto=WPA\n') - fp.write('\tpairwise=TKIP\n') - fp.write('\tgroup=TKIP\n') - elif encryption == 'WPA2': - fp.write('\tproto=RSN\n') - fp.write('\tpairwise=CCMP\n') - fp.write('\tgroup=CCMP\n') - else: - fp.write('\tproto=WPA RSN\n') - fp.write('\tpairwise=CCMP TKIP\n') - fp.write('\tgroup=CCMP TKIP\n') - fp.write('\tpsk="'+psk+'"\n') - elif encryption == 'WEP': - fp.write('\tkey_mgmt=NONE\n') - if wepkeytype == 'ASCII': - fp.write('\twep_key0="'+psk+'"\n') - else: - fp.write('\twep_key0='+psk+'\n') + if encryption in ('WPA', 'WPA2', 'WPA/WPA2'): + fp.write('\tkey_mgmt=WPA-PSK\n') + if encryption == 'WPA': + fp.write('\tproto=WPA\n') + fp.write('\tpairwise=TKIP\n') + fp.write('\tgroup=TKIP\n') + elif encryption == 'WPA2': + fp.write('\tproto=RSN\n') + fp.write('\tpairwise=CCMP\n') + fp.write('\tgroup=CCMP\n') + else: + fp.write('\tproto=WPA RSN\n') + fp.write('\tpairwise=CCMP TKIP\n') + fp.write('\tgroup=CCMP TKIP\n') + fp.write('\tpsk="'+psk+'"\n') + elif encryption == 'WEP': + fp.write('\tkey_mgmt=NONE\n') + if wepkeytype == 'ASCII': + fp.write('\twep_key0="'+psk+'"\n') + else: + fp.write('\twep_key0='+psk+'\n') else: - fp.write('\tkey_mgmt=NONE\n') + fp.write('\tkey_mgmt=NONE\n') fp.write('}') fp.write('\n') fp.close() @@ -195,54 +190,51 @@ class wpaSupplicant: supplicant = fp.readlines() fp.close() essid = None + encryption = "Unencrypted" for s in supplicant: split = s.strip().split('=',1) if split[0] == 'ap_scan': - #print "[Wlan.py] Got Hidden SSID Scan Value ",split[1] if split[1] == '2': config.plugins.wlan.hiddenessid.value = True else: config.plugins.wlan.hiddenessid.value = False - + elif split[0] == 'ssid': - #print "[Wlan.py] Got SSID ",split[1][1:-1] essid = split[1][1:-1] config.plugins.wlan.essid.value = essid - + elif split[0] == 'proto': - config.plugins.wlan.encryption.enabled.value = True if split[1] == 'WPA' : mode = 'WPA' if split[1] == 'RSN': mode = 'WPA2' if split[1] in ('WPA RSN', 'WPA WPA2'): mode = 'WPA/WPA2' - #print "[Wlan.py] Got Encryption: ",mode - config.plugins.wlan.encryption.type.value = mode + encryption = mode elif split[0] == 'wep_key0': - config.plugins.wlan.encryption.enabled.value = True - config.plugins.wlan.encryption.type.value = 'WEP' + encryption = 'WEP' if split[1].startswith('"') and split[1].endswith('"'): - config.plugins.wlan.encryption.wepkeytype.value = 'ASCII' - config.plugins.wlan.encryption.psk.value = split[1][1:-1] + config.plugins.wlan.wepkeytype.value = 'ASCII' + config.plugins.wlan.psk.value = split[1][1:-1] else: - config.plugins.wlan.encryption.wepkeytype.value = 'HEX' - config.plugins.wlan.encryption.psk.value = split[1] + config.plugins.wlan.wepkeytype.value = 'HEX' + config.plugins.wlan.psk.value = split[1] elif split[0] == 'psk': - config.plugins.wlan.encryption.psk.value = split[1][1:-1] + config.plugins.wlan.psk.value = split[1][1:-1] else: pass + + config.plugins.wlan.encryption.value = encryption wsconfig = { 'hiddenessid': config.plugins.wlan.hiddenessid.value, 'ssid': config.plugins.wlan.essid.value, - 'encryption': config.plugins.wlan.encryption.enabled.value, - 'encryption_type': config.plugins.wlan.encryption.type.value, - 'encryption_wepkeytype': config.plugins.wlan.encryption.wepkeytype.value, - 'key': config.plugins.wlan.encryption.psk.value, + 'encryption': config.plugins.wlan.encryption.value, + 'wepkeytype': config.plugins.wlan.wepkeytype.value, + 'key': config.plugins.wlan.psk.value, } for (key, item) in wsconfig.items(): @@ -250,24 +242,21 @@ class wpaSupplicant: if key == 'hiddenessid': wsconfig['hiddenessid'] = False if key == 'ssid': - wsconfig['ssid'] = "home" + wsconfig['ssid'] = "" if key == 'encryption': - wsconfig['encryption'] = True - if key == 'encryption_type': - wsconfig['encryption_type'] = "WPA/WPA2" - if key == 'encryption_wepkeytype': - wsconfig['encryption_wepkeytype'] = "ASCII" + wsconfig['encryption'] = "WPA2" + if key == 'wepkeytype': + wsconfig['wepkeytype'] = "ASCII" if key == 'key': - wsconfig['key'] = "mysecurewlan" + wsconfig['key'] = "" except: print "[Wlan.py] Error parsing ",configfile wsconfig = { 'hiddenessid': False, - 'ssid': "home", - 'encryption': True, - 'encryption_type': "WPA/WPA2", - 'encryption_wepkeytype': "ASCII", - 'key': "mysecurewlan", + 'ssid': "", + 'encryption': "WPA2", + 'wepkeytype': "ASCII", + 'key': "", } #print "[Wlan.py] WS-CONFIG-->",wsconfig return wsconfig @@ -277,6 +266,7 @@ class Status: def __init__(self): self.wlaniface = {} self.backupwlaniface = {} + self.statusCallback = None self.WlanConsole = Console() def stopWlanConsole(self): @@ -288,66 +278,54 @@ class Status: def getDataForInterface(self, iface, callback = None): self.WlanConsole = Console() cmd = "iwconfig " + iface - self.WlanConsole.ePopen(cmd, self.iwconfigFinished, [iface, callback]) + if callback is not None: + self.statusCallback = callback + self.WlanConsole.ePopen(cmd, self.iwconfigFinished, iface) def iwconfigFinished(self, result, retval, extra_args): - (iface, callback) = extra_args - data = { 'essid': False, 'frequency': False, 'acesspoint': False, 'bitrate': False, 'encryption': False, 'quality': False, 'signal': False } + iface = extra_args + data = { 'essid': False, 'frequency': False, 'accesspoint': False, 'bitrate': False, 'encryption': False, 'quality': False, 'signal': False } for line in result.splitlines(): line = line.strip() if "ESSID" in line: if "off/any" in line: - ssid = _("No Connection") + ssid = "off" else: if "Nickname" in line: - tmpssid=(line[line.index('ESSID')+7:line.index('" Nickname')]) - if tmpssid in ('', ' '): - ssid = _("Hidden networkname") - else: - ssid = tmpssid + ssid=(line[line.index('ESSID')+7:line.index('" Nickname')]) else: - tmpssid=(line[line.index('ESSID')+7:len(line)-1]) - if tmpssid in ('', ' '): - ssid = _("Hidden networkname") - else: - ssid = tmpssid + ssid=(line[line.index('ESSID')+7:len(line)-1]) if ssid is not None: data['essid'] = ssid - if 'Frequency' in line: + if "Frequency" in line: frequency = line[line.index('Frequency')+10 :line.index(' GHz')] if frequency is not None: data['frequency'] = frequency if "Access Point" in line: - ap=line[line.index('Access Point')+14:len(line)] + if "Sensitivity" in line: + ap=line[line.index('Access Point')+14:line.index(' Sensitivity')] + else: + ap=line[line.index('Access Point')+14:len(line)] if ap is not None: - data['acesspoint'] = ap - if ap == "Not-Associated": - data['essid'] = _("No Connection") + data['accesspoint'] = ap if "Bit Rate" in line: if "kb" in line: br = line[line.index('Bit Rate')+9 :line.index(' kb/s')] - if br == '0': - br = _("Unsupported") - else: - br += " Mb/s" else: - br = line[line.index('Bit Rate')+9 :line.index(' Mb/s')] + " Mb/s" + br = line[line.index('Bit Rate')+9 :line.index(' Mb/s')] if br is not None: data['bitrate'] = br - if 'Encryption key' in line: + if "Encryption key" in line: if ":off" in line: - if data['acesspoint'] is not "Not-Associated": - enc = _("Unsupported") - else: - enc = _("Disabled") + enc = "off" elif "Security" in line: enc = line[line.index('Encryption key')+15 :line.index(' Security')] if enc is not None: - enc = _("Enabled") + enc = "on" else: enc = line[line.index('Encryption key')+15 :len(line)] if enc is not None: - enc = _("Enabled") + enc = "on" if enc is not None: data['encryption'] = enc if 'Quality' in line: @@ -359,8 +337,7 @@ class Status: data['quality'] = qual if 'Signal level' in line: if "dBm" in line: - signal = line[line.index('Signal level')+13 :line.index(' dBm')] - signal += " dBm" + signal = line[line.index('Signal level')+13 :line.index(' dBm')] + " dBm" elif "/100" in line: if "Noise" in line: signal = line[line.index('Signal level')+13:line.index(' Noise')] @@ -380,8 +357,9 @@ class Status: if self.WlanConsole is not None: if len(self.WlanConsole.appContainers) == 0: print "[Wlan.py] self.wlaniface after loading:", self.wlaniface - if callback is not None: - callback(True,self.wlaniface) + if self.statusCallback is not None: + self.statusCallback(True,self.wlaniface) + self.statusCallback = None def getAdapterAttribute(self, iface, attribute): self.iface = iface diff --git a/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py b/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py index 6e88a3ea..3462146f 100644 --- a/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py +++ b/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py @@ -19,29 +19,29 @@ from Wlan import iWlan, wpaSupplicant, iStatus, getWlanConfigName import hashlib from time import time from os import urandom, system +from re import escape as re_escape plugin_path = eEnv.resolve("${libdir}/enigma2/python/Plugins/SystemPlugins/WirelessLan") list = [] +list.append("Unencrypted") list.append("WEP") list.append("WPA") -list.append("WPA2") list.append("WPA/WPA2") +list.append("WPA2") weplist = [] weplist.append("ASCII") weplist.append("HEX") config.plugins.wlan = ConfigSubsection() -config.plugins.wlan.essid = NoSave(ConfigText(default = "home", fixed_size = False)) +config.plugins.wlan.essid = NoSave(ConfigText(default = "", fixed_size = False)) config.plugins.wlan.hiddenessid = NoSave(ConfigYesNo(default = False)) +config.plugins.wlan.encryption = NoSave(ConfigSelection(list, default = "WPA2")) +config.plugins.wlan.wepkeytype = NoSave(ConfigSelection(weplist, default = "ASCII")) +config.plugins.wlan.psk = NoSave(ConfigPassword(default = "", fixed_size = False)) -config.plugins.wlan.encryption = ConfigSubsection() -config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = False)) -config.plugins.wlan.encryption.type = NoSave(ConfigSelection(list, default = "WPA/WPA2" )) -config.plugins.wlan.encryption.wepkeytype = NoSave(ConfigSelection(weplist, default = "ASCII")) -config.plugins.wlan.encryption.psk = NoSave(ConfigPassword(default = "mysecurewlan", fixed_size = False)) class WlanStatus(Screen): @@ -108,7 +108,7 @@ class WlanStatus(Screen): }, -1) self.timer = eTimer() self.timer.timeout.get().append(self.resetList) - self.onShown.append(lambda: self.timer.start(5000)) + self.onShown.append(lambda: self.timer.start(8000)) self.onLayoutFinish.append(self.layoutFinished) self.onClose.append(self.cleanup) @@ -116,7 +116,7 @@ class WlanStatus(Screen): iStatus.stopWlanConsole() def layoutFinished(self): - self.setTitle(_("Wireless Network State")) + self.setTitle(_("Wireless network state")) def resetList(self): iStatus.getDataForInterface(self.iface,self.getInfoCB) @@ -125,32 +125,65 @@ class WlanStatus(Screen): if data is not None: if data is True: if status is not None: - self["BSSID"].setText(status[self.iface]["acesspoint"]) - self["ESSID"].setText(status[self.iface]["essid"]) - self["quality"].setText(status[self.iface]["quality"]) - self["signal"].setText(status[self.iface]["signal"]) - self["bitrate"].setText(status[self.iface]["bitrate"]) - self["enc"].setText(status[self.iface]["encryption"]) + if status[self.iface]["essid"] == "off": + essid = _("No Connection") + else: + essid = status[self.iface]["essid"] + if status[self.iface]["accesspoint"] == "Not-Associated": + accesspoint = _("Not-Associated") + essid = _("No Connection") + else: + accesspoint = status[self.iface]["accesspoint"] + if self.has_key("BSSID"): + self["BSSID"].setText(accesspoint) + if self.has_key("ESSID"): + self["ESSID"].setText(essid) + + quality = status[self.iface]["quality"] + if self.has_key("quality"): + self["quality"].setText(quality) + + if status[self.iface]["bitrate"] == '0': + bitrate = _("Unsupported") + else: + bitrate = str(status[self.iface]["bitrate"]) + " Mb/s" + if self.has_key("bitrate"): + self["bitrate"].setText(bitrate) + + signal = status[self.iface]["signal"] + if self.has_key("signal"): + self["signal"].setText(signal) + + if status[self.iface]["encryption"] == "off": + if accesspoint == "Not-Associated": + encryption = _("Disabled") + else: + encryption = _("Unsupported") + else: + encryption = _("Enabled") + if self.has_key("enc"): + self["enc"].setText(encryption) self.updateStatusLink(status) def exit(self): self.timer.stop() - self.close(True) + self.close(True) def updateStatusbar(self): - self["BSSID"].setText(_("Please wait...")) - self["ESSID"].setText(_("Please wait...")) - self["quality"].setText(_("Please wait...")) - self["signal"].setText(_("Please wait...")) - self["bitrate"].setText(_("Please wait...")) - self["enc"].setText(_("Please wait...")) + wait_txt = _("Please wait...") + self["BSSID"].setText(wait_txt) + self["ESSID"].setText(wait_txt) + self["quality"].setText(wait_txt) + self["signal"].setText(wait_txt) + self["bitrate"].setText(wait_txt) + self["enc"].setText(wait_txt) self["IFtext"].setText(_("Network:")) self["IF"].setText(iNetwork.getFriendlyAdapterName(self.iface)) self["Statustext"].setText(_("Link:")) def updateStatusLink(self,status): if status is not None: - if status[self.iface]["acesspoint"] == "No Connection" or status[self.iface]["acesspoint"] == "Not-Associated" or status[self.iface]["acesspoint"] == False: + if status[self.iface]["essid"] == "off" or status[self.iface]["accesspoint"] == "Not-Associated" or status[self.iface]["accesspoint"] == False: self["statuspic"].setPixmapNum(1) else: self["statuspic"].setPixmapNum(0) @@ -234,19 +267,15 @@ class WlanScan(Screen): iWlan.stopGetNetworkList() self.rescanTimer.stop() del self.rescanTimer - if cur[1] is not None: - if cur[1] == '': - essid = cur[1] - else: - essid = cur[0] - self.close(essid,self.getWlanList()) + if cur[0] is not None: + self.close(cur[0]) else: - self.close(None,None) + self.close(None) else: iWlan.stopGetNetworkList() self.rescanTimer.stop() del self.rescanTimer - self.close(None,None) + self.close(None) def cancel(self): iWlan.stopGetNetworkList() @@ -261,10 +290,7 @@ class WlanScan(Screen): def buildEntryComponent(self, essid, bssid, encrypted, iface, maxrate, signal): divpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/div-h.png")) encryption = encrypted and _("Yes") or _("No") - if bssid == '': - return((essid, bssid, None, None, None, None, divpng)) - else: - return((essid, bssid, _("Signal: ") + str(signal), _("Max. Bitrate: ") + str(maxrate), _("Encrypted: ") + encryption, _("Interface: ") + str(iface), divpng)) + return((essid, bssid, _("Signal: ") + str(signal), _("Max. Bitrate: ") + str(maxrate), _("Encrypted: ") + encryption, _("Interface: ") + str(iface), divpng)) def updateAPList(self): newList = [] @@ -281,20 +307,19 @@ class WlanScan(Screen): tmpList.append(data) if len(tmpList): - if "" not in tmpList: - tmpList.append( ( _("enter hidden network SSID"), "", True, self.iface, _("unavailable"), "" ) ) - for entry in tmpList: self.newAPList.append(self.buildEntryComponent( entry[0], entry[1], entry[2], entry[3], entry[4], entry[5] )) currentListEntry = self["list"].getCurrent() - idx = 0 - for entry in self.newAPList: - if entry[0] == currentListEntry[0]: - newListIndex = idx - idx +=1 + if currentListEntry is not None: + idx = 0 + for entry in self.newAPList: + if entry[0] == currentListEntry[0]: + newListIndex = idx + idx +=1 self['list'].setList(self.newAPList) - self["list"].setIndex(newListIndex) + if newListIndex is not None: + self["list"].setIndex(newListIndex) self["list"].updateList(self.newAPList) self.listLength = len(self.newAPList) self.buildWlanList() @@ -326,9 +351,6 @@ class WlanScan(Screen): else: self.oldlist[entry[0]]['data'] = entry - if "" not in self.cleanList: - self.cleanList.append( ( _("enter hidden network SSID"), "", True, self.iface, _("unavailable"), "" ) ) - for entry in self.cleanList: self.APList.append(self.buildEntryComponent( entry[0], entry[1], entry[2], entry[3], entry[4], entry[5] )) @@ -341,20 +363,17 @@ class WlanScan(Screen): def setInfo(self): length = self.getLength() - if length <= 1: - self["info"].setText(_("No wireless networks found! Please refresh.")) - elif length == 2: + if length == 0: + self["info"].setText(_("No wireless networks found! Searching...")) + elif length == 1: self["info"].setText(_("1 wireless network found!")) else: - self["info"].setText(str(length-1)+_(" wireless networks found!")) + self["info"].setText(str(length)+_(" wireless networks found!")) def buildWlanList(self): self.WlanList = [] for entry in self['list'].list: - if entry[1] == "": - continue - else: - self.WlanList.append( (entry[0], entry[0]) ) + self.WlanList.append( (entry[0], entry[0]) ) def getLength(self): return self.listLength @@ -419,8 +438,11 @@ def callFunction(iface): return None def configStrings(iface): - hardware_info = HardwareInfo() - if hardware_info.device_name != "dm7025": + try: + device = open("/proc/stb/info/model", "r").readline().strip() + except: + device = "" + if device != "dm7025": rootkey = ['\x9f', '|', '\xe4', 'G', '\xc9', '\xb4', '\xf4', '#', '&', '\xce', '\xb3', '\xfe', '\xda', '\xc9', 'U', '`', '\xd8', '\x8c', 's', 'o', '\x90', '\x9b', '\\', 'b', '\xc0', '\x89', '\xd1', '\x8c', '\x9e', 'J', 'T', '\xc5', 'X', '\xa1', '\xb8', '\x13', '5', 'E', '\x02', '\xc9', '\xb2', '\xe6', 't', '\x89', '\xde', '\xcd', '\x9d', '\x11', '\xdd', '\xc7', '\xf4', '\xe4', '\xe4', '\xbc', '\xdb', '\x9c', '\xea', '}', '\xad', '\xda', 't', 'r', '\x9b', '\xdc', '\xbc', '\x18', '3', '\xe7', '\xaf', '|', '\xae', '\x0c', '\xe3', '\xb5', '\x84', '\x8d', '\r', '\x8d', '\x9d', '2', '\xd0', '\xce', '\xd5', 'q', '\t', '\x84', 'c', '\xa8', ')', '\x99', '\xdc', '<', '"', 'x', '\xe8', '\x87', '\x8f', '\x02', ';', 'S', 'm', '\xd5', '\xf0', '\xa3', '_', '\xb7', 'T', '\t', '\xde', '\xa7', '\xf1', '\xc9', '\xae', '\x8a', '\xd7', '\xd2', '\xcf', '\xb2', '.', '\x13', '\xfb', '\xac', 'j', '\xdf', '\xb1', '\x1d', ':', '?'] etpm = eTPM() l2cert = etpm.getCert(eTPM.TPMD_DT_LEVEL2_CERT) @@ -440,14 +462,14 @@ def configStrings(iface): return val = etpm.challenge(rnd) result = decrypt_block(val, l3key) - if hardware_info.device_name == "dm7025" or result[80:88] == rnd: + if device == "dm7025" or result[80:88] == rnd: driver = iNetwork.detectWlanModule(iface) else: driver = 'dreambox' print 'Using "%s" as wpa-supplicant driver' % (driver) ret = "" if driver == 'madwifi' and config.plugins.wlan.hiddenessid.value: - ret += "\tpre-up iwconfig " + iface + " essid \"" + config.plugins.wlan.essid.value + "\" || true\n" + ret += "\tpre-up iwconfig " + iface + " essid \"" + re_escape(config.plugins.wlan.essid.value) + "\" || true\n" ret += "\tpre-up wpa_supplicant -i" + iface + " -c" + getWlanConfigName(iface) + " -B -dd -D" + driver + " || true\n" ret += "\tpre-down wpa_cli -i" + iface + " terminate || true\n" return ret diff --git a/lib/python/Screens/NetworkSetup.py b/lib/python/Screens/NetworkSetup.py index e7ba6071..4b15ee00 100755 --- a/lib/python/Screens/NetworkSetup.py +++ b/lib/python/Screens/NetworkSetup.py @@ -296,18 +296,16 @@ class NameserverSetup(Screen, ConfigListScreen, HelpableScreen): class AdapterSetup(Screen, ConfigListScreen, HelpableScreen): - def __init__(self, session, networkinfo, essid=None, aplist=None): + def __init__(self, session, networkinfo, essid=None): Screen.__init__(self, session) HelpableScreen.__init__(self) self.session = session if isinstance(networkinfo, (list, tuple)): self.iface = networkinfo[0] self.essid = networkinfo[1] - self.aplist = networkinfo[2] else: self.iface = networkinfo self.essid = essid - self.aplist = aplist self.extended = None self.applyConfigRef = None @@ -399,71 +397,36 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen): self.gatewayEntry = None self.hiddenSSID = None self.wlanSSID = None - self.encryptionEnabled = None - self.encryptionKey = None + self.encryption = None self.encryptionType = None - self.nwlist = None + self.encryptionKey = None self.encryptionlist = None self.weplist = None self.wsconfig = None self.default = None - self.hiddenNW = None if iNetwork.isWirelessInterface(self.iface): - from Plugins.SystemPlugins.WirelessLan.Wlan import wpaSupplicant, iWlan - iWlan.setInterface(self.iface) - self.w = iWlan.getInterface() + from Plugins.SystemPlugins.WirelessLan.Wlan import wpaSupplicant self.ws = wpaSupplicant() self.encryptionlist = [] + self.encryptionlist.append(("Unencrypted", _("Unencrypted"))) self.encryptionlist.append(("WEP", _("WEP"))) self.encryptionlist.append(("WPA", _("WPA"))) - self.encryptionlist.append(("WPA2", _("WPA2"))) self.encryptionlist.append(("WPA/WPA2", _("WPA or WPA2"))) + self.encryptionlist.append(("WPA2", _("WPA2"))) self.weplist = [] self.weplist.append("ASCII") self.weplist.append("HEX") - if self.aplist is not None: - self.nwlist = self.aplist - self.nwlist.sort(key = lambda x: x[0]) - else: - self.nwlist = [] - self.aps = None - try: - self.aps = iWlan.getNetworkList() - if self.aps is not None: - for ap in self.aps: - a = self.aps[ap] - if a['active']: - if a['essid'] != '': - self.nwlist.append((a['essid'],a['essid'])) - self.nwlist.sort(key = lambda x: x[0]) - iWlan.stopGetNetworkList() - except: - self.nwlist.append(("No Networks found",_("No Networks found"))) self.wsconfig = self.ws.loadConfig(self.iface) - if self.essid is not None: # ssid from wlan scan - self.default = self.essid - self.hiddenNW = self.wsconfig['hiddenessid'] - if self.essid == '': - self.hiddenNW = True - self.default = self.default = self.wsconfig['ssid'] - else: - self.hiddenNW = self.wsconfig['hiddenessid'] - self.default = self.wsconfig['ssid'] + if self.essid is None: + self.essid = self.wsconfig['ssid'] - if (self.default not in self.nwlist and self.default is not ''): - self.nwlist.append((self.default,self.default)) - - config.plugins.wlan.hiddenessid = NoSave(ConfigYesNo(default = self.hiddenNW)) - if config.plugins.wlan.hiddenessid.value is True: - config.plugins.wlan.essid = NoSave(ConfigText(default = self.default, visible_width = 50, fixed_size = False)) - else: - config.plugins.wlan.essid = NoSave(ConfigSelection(self.nwlist, default = self.default )) - config.plugins.wlan.encryption.enabled = NoSave(ConfigYesNo(default = self.wsconfig['encryption'] )) - config.plugins.wlan.encryption.type = NoSave(ConfigSelection(self.encryptionlist, default = self.wsconfig['encryption_type'] )) - config.plugins.wlan.encryption.wepkeytype = NoSave(ConfigSelection(self.weplist, default = self.wsconfig['encryption_wepkeytype'] )) - config.plugins.wlan.encryption.psk = NoSave(ConfigPassword(default = self.wsconfig['key'], visible_width = 50, fixed_size = False)) + config.plugins.wlan.hiddenessid = NoSave(ConfigYesNo(default = self.wsconfig['hiddenessid'])) + config.plugins.wlan.essid = NoSave(ConfigText(default = self.essid, visible_width = 50, fixed_size = False)) + config.plugins.wlan.encryption = NoSave(ConfigSelection(self.encryptionlist, default = self.wsconfig['encryption'] )) + config.plugins.wlan.wepkeytype = NoSave(ConfigSelection(self.weplist, default = self.wsconfig['wepkeytype'] )) + config.plugins.wlan.psk = NoSave(ConfigPassword(default = self.wsconfig['key'], visible_width = 50, fixed_size = False)) self.activateInterfaceEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "up") or False)) self.dhcpConfigEntry = NoSave(ConfigYesNo(default=iNetwork.getAdapterAttribute(self.iface, "dhcp") or False)) @@ -505,30 +468,20 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen): if p.__call__.has_key("configStrings"): self.configStrings = p.__call__["configStrings"] - self.hiddenSSID = getConfigListEntry(_("enter hidden network SSID"), config.plugins.wlan.hiddenessid) + self.hiddenSSID = getConfigListEntry(_("Hidden network"), config.plugins.wlan.hiddenessid) self.list.append(self.hiddenSSID) - - if config.plugins.wlan.hiddenessid.value is True: - config.plugins.wlan.essid = NoSave(ConfigText(default = self.default, visible_width = 50, fixed_size = False)) - self.wlanSSID = getConfigListEntry(_("Hidden network SSID"), config.plugins.wlan.essid) - else: - config.plugins.wlan.essid = NoSave(ConfigSelection(self.nwlist, default = self.default )) - self.wlanSSID = getConfigListEntry(_("Network SSID"), config.plugins.wlan.essid) + self.wlanSSID = getConfigListEntry(_("Networkname (SSID)"), config.plugins.wlan.essid) self.list.append(self.wlanSSID) - self.encryptionEnabled = getConfigListEntry(_("Encryption"), config.plugins.wlan.encryption.enabled) - self.list.append(self.encryptionEnabled) - - if config.plugins.wlan.encryption.enabled.value: - self.encryptionType = getConfigListEntry(_("Encryption Type"), config.plugins.wlan.encryption.type) - self.list.append(self.encryptionType) - if config.plugins.wlan.encryption.type.value == 'WEP': - self.list.append(getConfigListEntry(_("Encryption Keytype"), config.plugins.wlan.encryption.wepkeytype)) - self.encryptionKey = getConfigListEntry(_("Encryption Key"), config.plugins.wlan.encryption.psk) - self.list.append(self.encryptionKey) - else: - self.encryptionKey = getConfigListEntry(_("Encryption Key"), config.plugins.wlan.encryption.psk) - self.list.append(self.encryptionKey) + self.encryption = getConfigListEntry(_("Encryption"), config.plugins.wlan.encryption) + self.list.append(self.encryption) + self.encryptionType = getConfigListEntry(_("Encryption Keytype"), config.plugins.wlan.wepkeytype) + self.encryptionKey = getConfigListEntry(_("Encryption Key"), config.plugins.wlan.psk) + + if config.plugins.wlan.encryption.value != "Unencrypted": + if config.plugins.wlan.encryption.value == 'WEP': + self.list.append(self.encryptionType) + self.list.append(self.encryptionKey) self["config"].list = self.list self["config"].l.setList(self.list) @@ -543,11 +496,7 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen): if self["config"].getCurrent() == self.gatewayEntry: self.createSetup() if iNetwork.isWirelessInterface(self.iface): - if self["config"].getCurrent() == self.hiddenSSID: - self.createSetup() - if self["config"].getCurrent() == self.encryptionEnabled: - self.createSetup() - if self["config"].getCurrent() == self.encryptionType: + if self["config"].getCurrent() == self.encryption: self.createSetup() def keyLeft(self): @@ -607,16 +556,20 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen): iNetwork.setAdapterAttribute(self.iface, "gateway", self.gatewayConfigEntry.value) else: iNetwork.removeAdapterAttribute(self.iface, "gateway") - if self.extended is not None and self.configStrings is not None: + + if (self.extended is not None and self.configStrings is not None): iNetwork.setAdapterAttribute(self.iface, "configStrings", self.configStrings(self.iface)) self.ws.writeConfig(self.iface) - + if self.activateInterfaceEntry.value is False: iNetwork.deactivateInterface(self.iface,self.deactivateInterfaceCB) iNetwork.writeNetworkConfig() self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False) else: - iNetwork.deactivateInterface(self.iface,self.activateInterfaceCB) + if self.oldInterfaceState is False: + iNetwork.activateInterface(self.iface,self.deactivateInterfaceCB) + else: + iNetwork.deactivateInterface(self.iface,self.activateInterfaceCB) iNetwork.writeNetworkConfig() self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False) else: @@ -687,10 +640,10 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen): def hideInputHelp(self): current = self["config"].getCurrent() - if current == self.wlanSSID and config.plugins.wlan.hiddenessid.value: + if current == self.wlanSSID: if current[1].help_window.instance is not None: current[1].help_window.instance.hide() - elif current == self.encryptionKey and config.plugins.wlan.encryption.enabled.value: + elif current == self.encryptionKey and config.plugins.wlan.encryption.value is not "Unencrypted": if current[1].help_window.instance is not None: current[1].help_window.instance.hide() @@ -764,7 +717,7 @@ class AdapterSetupConfiguration(Screen, HelpableScreen): ifobj = Wireless(iface) # a Wireless NIC Object wlanresponse = ifobj.getAPaddr() except IOError, (error_no, error_str): - if error_no in (errno.EOPNOTSUPP, errno.EINVAL, errno.ENODEV, errno.EPERM): + if error_no in (errno.EOPNOTSUPP, errno.ENODEV, errno.EPERM): return False else: print "error: ",error_no,error_str @@ -939,7 +892,7 @@ class AdapterSetupConfiguration(Screen, HelpableScreen): def WlanScanClosed(self,*ret): if ret[0] is not None: - self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,ret[0],ret[1]) + self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,ret[0]) else: from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus iStatus.stopWlanConsole() @@ -998,7 +951,7 @@ class AdapterSetupConfiguration(Screen, HelpableScreen): if data is not None: if data is True: if status is not None: - if status[self.iface]["acesspoint"] == "No Connection" or status[self.iface]["acesspoint"] == "Not-Associated" or status[self.iface]["acesspoint"] == False: + if status[self.iface]["essid"] == "off" or status[self.iface]["accesspoint"] == "Not-Associated" or status[self.iface]["accesspoint"] == False: self.LinkState = False self["statuspic"].setPixmapNum(1) self["statuspic"].show() @@ -1420,7 +1373,7 @@ class NetworkAdapterTest(Screen): if data is not None: if data is True: if status is not None: - if status[self.iface]["acesspoint"] == "No Connection" or status[self.iface]["acesspoint"] == "Not-Associated" or status[self.iface]["acesspoint"] == False: + if status[self.iface]["essid"] == "off" or status[self.iface]["accesspoint"] == "Not-Associated" or status[self.iface]["accesspoint"] == False: self["Network"].setForegroundColorNum(1) self["Network"].setText(_("disconnected")) self["NetworkInfo_Check"].setPixmapNum(1) -- cgit v1.2.3 From 710962d4f216b12c7cc25a189cbcc890a2ab5622 Mon Sep 17 00:00:00 2001 From: Mladen Horvat Date: Wed, 13 Apr 2011 23:12:10 +0200 Subject: Components/DreamInfoHandler.py, SystemPlugins/SoftwareManager: add possibility to have also non plugins/skins inside SoftwareManager. add support for 'needsRestart' option inside meta descriptions for non plugins/skins. refs #389 --- lib/python/Components/DreamInfoHandler.py | 4 ++++ .../SystemPlugins/SoftwareManager/SoftwareTools.py | 2 +- .../Plugins/SystemPlugins/SoftwareManager/plugin.py | 16 ++++++++++------ 3 files changed, 15 insertions(+), 7 deletions(-) (limited to 'lib/python/Plugins/SystemPlugins') diff --git a/lib/python/Components/DreamInfoHandler.py b/lib/python/Components/DreamInfoHandler.py index 8e9c29d1..8097365c 100755 --- a/lib/python/Components/DreamInfoHandler.py +++ b/lib/python/Components/DreamInfoHandler.py @@ -84,6 +84,8 @@ class InfoHandler(xml.sax.ContentHandler): self.attributes["packagename"] = str(attrs["packagename"]) if attrs.has_key("packagetype"): self.attributes["packagetype"] = str(attrs["packagetype"]) + if attrs.has_key("needsRestart"): + self.attributes["needsRestart"] = str(attrs["needsRestart"]) if attrs.has_key("shortdescription"): self.attributes["shortdescription"] = str(attrs["shortdescription"]) @@ -120,6 +122,8 @@ class InfoHandler(xml.sax.ContentHandler): self.attributes["name"] = str(data) if self.elements[-1] == "packagename": self.attributes["packagename"] = str(data) + if self.elements[-1] == "needsRestart": + self.attributes["needsRestart"] = str(data) if self.elements[-1] == "shortdescription": self.attributes["shortdescription"] = str(data) if self.elements[-1] == "description": diff --git a/lib/python/Plugins/SystemPlugins/SoftwareManager/SoftwareTools.py b/lib/python/Plugins/SystemPlugins/SoftwareManager/SoftwareTools.py index 178efadc..ec2f82cc 100755 --- a/lib/python/Plugins/SystemPlugins/SoftwareManager/SoftwareTools.py +++ b/lib/python/Plugins/SystemPlugins/SoftwareManager/SoftwareTools.py @@ -244,7 +244,7 @@ class SoftwareTools(DreamInfoHandler): if self.NetworkConnectionAvailable == True: if not self.UpdateConsole: self.UpdateConsole = Console() - cmd = "opkg install enigma2-meta enigma2-plugins-meta enigma2-skins-meta" + cmd = "opkg install enigma2-meta enigma2-plugins-meta enigma2-skins-meta enigma2-drivers-meta" self.UpdateConsole.ePopen(cmd, self.InstallMetaPackageCB, callback) else: self.InstallMetaPackageCB(True) diff --git a/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py b/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py index f78b7582..12fd6094 100644 --- a/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py +++ b/lib/python/Plugins/SystemPlugins/SoftwareManager/plugin.py @@ -489,7 +489,6 @@ class SoftwareManagerInfo(Screen): self.list = [] backupfiles = config.plugins.configurationbackup.backupdirs.value for entry in backupfiles: - print entry self.list.append((entry,)) self['list'].setList(self.list) @@ -569,6 +568,7 @@ class PluginManager(Screen, DreamInfoHandler): self.currentSelectedIndex = None self.currentSelectedPackage = None self.saved_currentSelectedPackage = None + self.restartRequired = False self.onShown.append(self.setWindowTitle) self.onLayoutFinish.append(self.getUpdateInfos) @@ -892,6 +892,8 @@ class PluginManager(Screen, DreamInfoHandler): self.package = iSoftwareTools.packageDetails[0] if self.package[0].has_key("attributes"): self.attributes = self.package[0]["attributes"] + if self.attributes.has_key("needsRestart"): + self.restartRequired = True if self.attributes.has_key("package"): self.packagefiles = self.attributes["package"] if plugin[1] == 'installed': @@ -924,11 +926,11 @@ class PluginManager(Screen, DreamInfoHandler): def runExecuteFinished(self): self.reloadPluginlist() - restartRequired = plugins.restartRequired - if restartRequired: + if plugins.restartRequired or self.restartRequired: self.session.openWithCallback(self.ExecuteReboot, MessageBox, _("Install or remove finished.") +" "+_("Do you want to reboot your Dreambox?"), MessageBox.TYPE_YESNO) else: self.selectedFiles = [] + self.restartRequired = False self.detailsClosed(True) def ExecuteReboot(self, result): @@ -936,6 +938,7 @@ class PluginManager(Screen, DreamInfoHandler): quitMainloop(3) else: self.selectedFiles = [] + self.restartRequired = False self.detailsClosed(True) def reloadPluginlist(self): @@ -1174,7 +1177,7 @@ class PluginDetails(Screen, DreamInfoHandler): self.package = self.packageDetails[0] if self.package[0].has_key("attributes"): self.attributes = self.package[0]["attributes"] - + self.restartRequired = False self.cmdList = [] self.oktext = _("\nAfter pressing OK, please wait!") self.picload = ePicLoad() @@ -1272,6 +1275,8 @@ class PluginDetails(Screen, DreamInfoHandler): def go(self): if self.attributes.has_key("package"): self.packagefiles = self.attributes["package"] + if self.attributes.has_key("needsRestart"): + self.restartRequired = True self.cmdList = [] if self.pluginstate in ('installed', 'remove'): if self.packagefiles: @@ -1293,8 +1298,7 @@ class PluginDetails(Screen, DreamInfoHandler): def runUpgradeFinished(self): self.reloadPluginlist() - restartRequired = plugins.restartRequired - if restartRequired: + if plugins.restartRequired or self.restartRequired: self.session.openWithCallback(self.UpgradeReboot, MessageBox, _("Installation finished.") +" "+_("Do you want to reboot your Dreambox?"), MessageBox.TYPE_YESNO) else: self.close(True) -- cgit v1.2.3