From 2cd5e724aea3a79d91e91db37ac7ec387c0f91de Mon Sep 17 00:00:00 2001 From: Mladen Horvat Date: Fri, 13 Jun 2008 13:14:09 +0000 Subject: [PATCH] some fixes and cleanups --- wirelesslan/src/Wlan.py | 50 ++++++++++++++++++++++++++++++++------- wirelesslan/src/plugin.py | 44 +++++++++++++++++++++------------- 2 files changed, 70 insertions(+), 24 deletions(-) diff --git a/wirelesslan/src/Wlan.py b/wirelesslan/src/Wlan.py index 55c46e6e..26087c58 100644 --- a/wirelesslan/src/Wlan.py +++ b/wirelesslan/src/Wlan.py @@ -150,7 +150,7 @@ class WlanList(HTMLComponent, GUIComponent): self.iface = iface self.length = 0 - + self.aplist = None self.l = None self.l = eListboxPythonMultiContent() @@ -182,12 +182,16 @@ class WlanList(HTMLComponent, GUIComponent): def reload(self): aps = self.w.getNetworkList() list = [] + self.aplist = [] if aps is not None: print "[Wlan.py] got Accespoints!" for ap in aps: a = aps[ap] if a['active']: + if a['essid'] == "": + a['essid'] = a['bssid'] list.append( (a['essid'], a['bssid'], a['encrypted'], a['iface'], a['maxrate'], a['signal']) ) + self.aplist.append( a['essid']) self.length = len(list) self.l.setList([]) @@ -207,7 +211,9 @@ class WlanList(HTMLComponent, GUIComponent): def getLength(self): return self.length - + + def getList(self): + return self.aplist class wpaSupplicant: @@ -222,14 +228,17 @@ class wpaSupplicant: encryption = config.plugins.wlan.encryption.type.value psk = config.plugins.wlan.encryption.psk.value - + fp = file('/etc/wpa_supplicant.conf', 'w') fp.write('#WPA Supplicant Configuration by enigma2\n\n') fp.write('ctrl_interface=/var/run/wpa_supplicant\n') fp.write('ctrl_interface_group=0\n') + fp.write('eapol_version=1\n') + fp.write('ap_scan=1\n') + fp.write('fast_reauth=1\n') fp.write('network={\n') fp.write('\tssid="'+essid+'"\n') - fp.write('\tscan_ssid=1\n') + fp.write('\tscan_ssid=0\n') if encrypted: @@ -262,10 +271,9 @@ class wpaSupplicant: fp = file('/etc/wpa_supplicant.conf', 'r') supplicant = fp.readlines() fp.close() - + for s in supplicant: - - split = s.strip().split('=') + split = s.strip().split('=',1) if split[0] == 'ssid': print "[Wlan.py] Got SSID "+split[1][1:-1] config.plugins.wlan.essid.value = split[1][1:-1] @@ -288,9 +296,35 @@ class wpaSupplicant: else: pass + wsconfig = { + 'ssid': config.plugins.wlan.essid.value, + 'encryption': config.plugins.wlan.encryption.enabled.value, + 'encryption_type': config.plugins.wlan.encryption.type.value, + 'key': config.plugins.wlan.encryption.psk.value, + } + + for (key, item) in wsconfig.items(): + if item is "None" or item is "": + if key == 'ssid': + wsconfig['ssid'] = "home" + if key == 'encryption': + wsconfig['encryption'] = False + if key == 'encryption': + wsconfig['encryption_type'] = "WPA" + if key == 'encryption': + wsconfig['key'] = "mysecurewlan" + except: print "[Wlan.py] Error parsing /etc/wpa_supplicant.conf" - + wsconfig = { + 'ssid': "home", + 'encryption': False, + 'encryption_type': "WPA", + 'key': "mysecurewlan", + } + print "WS-CONFIG-->",wsconfig + return wsconfig + def restart(self, iface): system("start-stop-daemon -K -x /usr/sbin/wpa_supplicant") diff --git a/wirelesslan/src/plugin.py b/wirelesslan/src/plugin.py index 4361253f..50f5eb18 100644 --- a/wirelesslan/src/plugin.py +++ b/wirelesslan/src/plugin.py @@ -4,7 +4,7 @@ from Components.ActionMap import ActionMap, NumberActionMap from Components.Pixmap import Pixmap from Components.Label import Label from Components.MenuList import MenuList -from Components.config import config, getConfigListEntry +from Components.config import config, getConfigListEntry, ConfigYesNo, NoSave, ConfigSubsection, ConfigText, ConfigSelection from Components.ConfigList import ConfigListScreen from Components.Network import Network, iNetwork from Plugins.Plugin import PluginDescriptor @@ -12,6 +12,18 @@ from os import system from Wlan import Wlan, WlanList, wpaSupplicant plugin_path = "/usr/lib/enigma2/python/Plugins/SystemPlugins/WirelessLan" +list = [] +list.append(_("WEP")) +list.append(_("WPA")) +list.append(_("WPA2")) + +config.plugins.wlan = ConfigSubsection() +config.plugins.wlan.essid = 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"))) +config.plugins.wlan.encryption.psk = NoSave(ConfigText(default = "mysecurewlan", fixed_size = False)) class WlanSelectScreen(Screen): skin = """ @@ -88,10 +100,10 @@ class WlanStatus(Screen): - - - - + + + + @@ -184,7 +196,7 @@ class WlanScan(Screen): - + @@ -208,7 +220,7 @@ class WlanScan(Screen): self["list"] = WlanList(self.session, iface) self.setInfo() - + self["canceltext"] = Label(_("Close")) self["selecttext"] = Label(_("Connect")) self["rescantext"] = Label(_("Refresh")) @@ -229,26 +241,26 @@ class WlanScan(Screen): def select(self): cur = self["list"].getCurrent() - print "CURRENT",cur + #print "CURRENT",cur if cur[1] is not None: essid = cur[0] + if essid == '': + essid = cur[1] encrypted = cur[2] - iface = cur[3] - self.session.openWithCallback(self.WlanSetupClosed, WlanConfiguration, iface, essid, encrypted) + self.close(essid,self["list"].getList()) else: - self.session.openWithCallback(self.WlanSetupClosed, WlanConfiguration) + self.close(self["list"].getList()) def WlanSetupClosed(self, *ret): - print "RET im WlanSetupClosed",ret if ret[0] == 2: - self.close() + self.close(None) def rescan(self): self["list"].reload() self.setInfo() def exit(self): - self.close( (None ,) ) + self.close(None) def setInfo(self): length = self["list"].getLength() @@ -373,9 +385,9 @@ def configStrings(iface): ret=system("dmesg | grep \"rt73: using permanent MAC addr\"") ret2=system("dmesg | grep \"rt73: using net dev supplied MAC addr\"") if ret == 0 or ret2 == 0: - return " post-down start-stop-daemon -K -x /usr/sbin/wpa_supplicant\n pre-up /usr/sbin/wpa_supplicant -i"+iface+" -c/etc/wpa_supplicant.conf -B -Dralink" + return " pre-up /usr/sbin/wpa_supplicant -i"+iface+" -c/etc/wpa_supplicant.conf -B -Dralink\n post-down killall -q wpa_supplicant" else: - return " post-down start-stop-daemon -K -x /usr/sbin/wpa_supplicant\n pre-up /usr/sbin/wpa_supplicant -i"+iface+" -c/etc/wpa_supplicant.conf -B" + return " pre-up /usr/sbin/wpa_supplicant -i"+iface+" -c/etc/wpa_supplicant.conf -B\n post-down killall -q wpa_supplicant" def Plugins(**kwargs): -- 2.20.1