Screens/NetworkSetup.py, SystemPlugins/WirelessLan,Networkwizard: dont use "hidden...
authorMladen Horvat <acid-burn@opendreambox.org>
Thu, 31 Mar 2011 10:09:21 +0000 (12:09 +0200)
committerMladen Horvat <acid-burn@opendreambox.org>
Thu, 31 Mar 2011 10:09:21 +0000 (12:09 +0200)
Add config option for entering a hidden network ssid. This is more intuitive as selecting the option from the found networks. refs #725

lib/python/Plugins/SystemPlugins/NetworkWizard/NetworkWizard.py
lib/python/Plugins/SystemPlugins/NetworkWizard/plugin.py
lib/python/Plugins/SystemPlugins/WirelessLan/Wlan.py
lib/python/Plugins/SystemPlugins/WirelessLan/plugin.py
lib/python/Screens/NetworkSetup.py

index e99309a90d45c0f8ea3c1266485b257a6b4718b0..9f2540665da857bf931d8c58641eefebfe164178 100755 (executable)
@@ -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 = """
                <screen position="0,0" size="720,576" title="Welcome..." flags="wfNoBorder" >
@@ -306,13 +284,13 @@ class NetworkWizard(WizardLanguage, Rc):
                                newList.append(oldentry)
                                
                for newentry in newList:
-                       if newentry[1] == "hidden...":
+                       if newentry[1] == "<hidden>":
                                continue
                        self.newAPlist.append(newentry)
                
                if len(self.newAPlist):
-                       if "hidden..." not in self.newAPlist:
-                               self.newAPlist.append(( _("enter hidden network SSID"), "hidden..." ))
+                       if "<hidden>" not in self.newAPlist:
+                               self.newAPlist.append(( _("enter hidden network SSID"), "<hidden>" ))
 
                        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 "<hidden>" not in self.APList:
+                               self.APList.append(( _("enter hidden network SSID"), "<hidden>" ))
                        
                        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] == "<hidden>":
+                                       continue
                                self.WlanList.append( (entry[1], entry[0]) )
                self.AccessPointsSelect(index)
 
index 56cebdbf1764e5c9f4422626e3ca97657fb41865..30a242309e480164ba11a401977cd392113a2391 100644 (file)
@@ -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)
index 5b76f9260e69ac57e2a6c739afc7de401e6191a9..4a7b1e88c6a10426807fbb89e1e446bd3780cd51 100755 (executable)
@@ -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                                          
index c296ab70f031a87b02d06909fbbaf30e653d3b81..6e88a3ea4636f389edbb5525340032e4117163dc 100644 (file)
@@ -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] == '<hidden>':
                                        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 == '<hidden>':                 
                        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 "<hidden>" not in tmpList:
+                               tmpList.append( ( _("enter hidden network SSID"), "<hidden>", 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 "<hidden>" not in self.cleanList:
+                       self.cleanList.append( ( _("enter hidden network SSID"), "<hidden>", 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] == "<hidden>":
+                               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
index 5d378524de8fcba18dd8707429e5f688eefe4f2d..e7ba6071aee54deff0bbda40d5bb0bf800f6cad3 100755 (executable)
@@ -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 == '<hidden>':
+                                       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 '<hidden>'):
                                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: