X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/2c862a6323b51e446270ee3b6845ed234ed8771d..c3c412e8765520205b7cf8413ddf8abca74f1bc3:/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py diff --git a/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py b/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py old mode 100755 new mode 100644 index 28ee363e..6e88a3ea --- a/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py +++ b/lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py @@ -1,4 +1,4 @@ -from enigma import eTimer, eTPM +from enigma import eTimer, eTPM, eEnv from Screens.Screen import Screen from Components.ActionMap import ActionMap, NumberActionMap from Components.Pixmap import Pixmap,MultiPixmap @@ -8,17 +8,20 @@ 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 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, system + +plugin_path = eEnv.resolve("${libdir}/enigma2/python/Plugins/SystemPlugins/WirelessLan") -plugin_path = "/usr/lib/enigma2/python/Plugins/SystemPlugins/WirelessLan" list = [] list.append("WEP") @@ -32,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)) @@ -217,6 +220,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) @@ -226,10 +231,11 @@ 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: - if cur[1] == 'hidden...': + if cur[1] == '': essid = cur[1] else: essid = cur[0] @@ -237,31 +243,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() @@ -270,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)) @@ -290,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] )) @@ -312,8 +303,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 = [] @@ -336,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] )) @@ -361,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") ))#continue + if entry[1] == "": + continue else: self.WlanList.append( (entry[0], entry[0]) ) @@ -391,7 +381,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() @@ -399,34 +389,35 @@ 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() + iWlan.setInterface(iface) + i = iWlan.getWirelessInterfaces() if i: - if iface in i: + if iface in i or iNetwork.isWirelessInterface(iface): return WlanStatusScreenMain + return None return None - def configStrings(iface): hardware_info = HardwareInfo() if hardware_info.device_name != "dm7025": @@ -435,17 +426,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,13 +444,13 @@ def configStrings(iface): driver = iNetwork.detectWlanModule(iface) else: driver = 'dreambox' - if driver in ('ralink', 'zydas'): - return " pre-up /usr/sbin/wpa_supplicant -i"+iface+" -c/etc/wpa_supplicant.conf -B -D"+driver+"\n post-down wpa_cli terminate" - else: - if config.plugins.wlan.essid.value == "hidden...": - return ' pre-up iwconfig '+iface+' essid "'+config.plugins.wlan.hiddenessid.value+'"\n pre-up /usr/sbin/wpa_supplicant -i'+iface+' -c/etc/wpa_supplicant.conf -B -dd -D'+driver+'\n post-down wpa_cli terminate' - else: - return ' pre-up iwconfig '+iface+' essid "'+config.plugins.wlan.essid.value+'"\n pre-up /usr/sbin/wpa_supplicant -i'+iface+' -c/etc/wpa_supplicant.conf -B -dd -D'+driver+'\n post-down wpa_cli terminate' + 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 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 def Plugins(**kwargs): - return PluginDescriptor(name=_("Wireless LAN"), description=_("Connect to a Wireless Network"), where = PluginDescriptor.WHERE_NETWORKSETUP, fnc={"ifaceSupported": callFunction, "configStrings": configStrings, "WlanPluginEntry": lambda x: "Wireless Network Configuartion..."}) + return PluginDescriptor(name=_("Wireless LAN"), description=_("Connect to a Wireless Network"), where = PluginDescriptor.WHERE_NETWORKSETUP, needsRestart = False, fnc={"ifaceSupported": callFunction, "configStrings": configStrings, "WlanPluginEntry": lambda x: "Wireless Network Configuartion..."})