-from Components.config import config, ConfigYesNo, ConfigIP, NoSave, ConfigText, ConfigPassword, ConfigSelection, getConfigListEntry, ConfigNothing
-from Components.config import ConfigInteger, ConfigSubsection
-from Components.ConfigList import ConfigListScreen
-from Components.PluginComponent import plugins
-from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest
-from Components.ActionMap import ActionMap, NumberActionMap, HelpableActionMap
-from Components.Console import Console
-from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_CURRENT_SKIN
-from Tools.LoadPixmap import LoadPixmap
-from Plugins.Plugin import PluginDescriptor
-from enigma import eTimer, ePoint, eSize, RT_HALIGN_LEFT, eListboxPythonMultiContent, gFont
-from os import path as os_path, system as os_system, unlink,listdir
-from re import compile as re_compile, search as re_search
-from Tools.Directories import fileExists
-import time
-
-class WlanSelection(Screen,HelpableScreen):
- skin = """
- <screen name="WlanSelection" position="209,48" size="865,623" title="Wireless Network Configuration..." flags="wfNoBorder" backgroundColor="transparent">
- <ePixmap pixmap="Vu_HD/Bg_EPG_view.png" zPosition="-1" position="0,0" size="865,623" alphatest="on" />
- <ePixmap pixmap="Vu_HD/menu/ico_title_Setup.png" position="32,41" size="40,40" alphatest="blend" transparent="1" />
- <eLabel text="Wireless Network Adapter Selection..." position="90,50" size="600,32" font="Semiboldit;32" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
- <ePixmap pixmap="Vu_HD/icons/clock.png" position="750,55" zPosition="1" size="20,20" alphatest="blend" />
- <widget source="global.CurrentTime" render="Label" position="770,57" zPosition="1" size="50,20" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" halign="right" transparent="1">
- <convert type="ClockToText">Format:%H:%M</convert>
- </widget>
- <ePixmap pixmap="Vu_HD/buttons/red.png" position="45,98" size="25,25" alphatest="blend" />
- <ePixmap pixmap="Vu_HD/buttons/green.png" position="240,98" size="25,25" alphatest="blend" />
- <widget source="key_red" render="Label" position="66,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
- <widget source="key_green" render="Label" position="268,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
- <ePixmap pixmap="Vu_HD/border_menu.png" position="120,140" zPosition="-1" size="342,358" transparent="1" alphatest="blend" />
- <widget name="menulist" position="130,150" size="322,338" transparent="1" backgroundColor="#27d9dee2" zPosition="10" scrollbarMode="showOnDemand" />
- <widget source="description" render="Label" position="500,140" size="280,360" font="Regular;19" halign="center" valign="center" backgroundColor="#c5c9cc" transparent="1"/>
- </screen>"""
-
- def __init__(self, session):
- Screen.__init__(self,session)
- HelpableScreen.__init__(self)
- self.mainmenu = self.getWlandevice()
- self["menulist"] = MenuList(self.mainmenu)
- self["key_red"] = StaticText(_("Close"))
- self["key_green"] = StaticText(_("Select"))
- self["description"] = StaticText()
- self["description"].setText(_("Select Wireless Lan module. \n" ))
- self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
- {
- "ok": (self.ok, _("select interface")),
- "cancel": (self.close, _("exit network interface list")),
- })
-
- self["ColorActions"] = HelpableActionMap(self, "ColorActions",
- {
- "green": (self.ok, _("select interface")),
- "red": (self.close, _("exit network interface list")),
- })
-
- def ok(self):
-# print len(self["menulist"].list)
- if len(self["menulist"].list) == 0:
- self.session.open(MessageBox, (_("Can not find any WirelessLan Module\n")),MessageBox.TYPE_ERROR,5 )
- return
- ifaces=self["menulist"].getCurrent()[1]
- if ifaces == None:
- pass
- else:
- self.session.open(WlanSetup,ifaces)
-
- def getWlandevice(self):
- list = []
- for x in iNetwork.getAdapterList():
- if x.startswith('eth'):
- continue
- list.append((self.getAdapterDescription(x) + " (%s)"%x,x))
- return list
-
- def getAdapterDescription(self, iface):
- if iface == 'eth0':
- return _("Internal LAN adapter.")
- else:
- classdir = "/sys/class/net/" + iface + "/device/"
- driverdir = "/sys/class/net/" + iface + "/device/driver/"
- if os_path.exists(classdir):
- files = listdir(classdir)
- if 'driver' in files:
- if os_path.realpath(driverdir).endswith('rtw_usb_drv'):
- return _("Realtak")+ " " + _("WLAN adapter.")
- elif os_path.realpath(driverdir).endswith('ath_pci'):
- return _("Atheros")+ " " + _("WLAN adapter.")
- elif os_path.realpath(driverdir).endswith('zd1211b'):
- return _("Zydas")+ " " + _("WLAN adapter.")
- elif os_path.realpath(driverdir).endswith('rt73'):
- return _("Ralink")+ " " + _("WLAN adapter.")
- elif os_path.realpath(driverdir).endswith('rt73usb'):
- return _("Ralink")+ " " + _("WLAN adapter.")
- else:
- return str(os_path.basename(os_path.realpath(driverdir))) + " " + _("WLAN adapter")
- else:
- return _("Unknown network adapter.")
-
-class WlanSetup(Screen,HelpableScreen):
- skin = """
- <screen name="WlanSetup" position="209,48" size="865,623" title="Wireless Network Configuration..." flags="wfNoBorder" backgroundColor="transparent">
- <ePixmap pixmap="Vu_HD/Bg_EPG_view.png" zPosition="-1" position="0,0" size="865,623" alphatest="on" />
- <ePixmap pixmap="Vu_HD/menu/ico_title_Setup.png" position="32,41" size="40,40" alphatest="blend" transparent="1" />
- <eLabel text="Wireless Network Setup Menu..." position="90,50" size="600,32" font="Semiboldit;32" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
- <ePixmap pixmap="Vu_HD/icons/clock.png" position="750,55" zPosition="1" size="20,20" alphatest="blend" />
- <widget source="global.CurrentTime" render="Label" position="770,57" zPosition="1" size="50,20" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" halign="right" transparent="1">
- <convert type="ClockToText">Format:%H:%M</convert>
- </widget>
- <ePixmap pixmap="Vu_HD/buttons/red.png" position="45,98" size="25,25" alphatest="blend" />
- <ePixmap pixmap="Vu_HD/buttons/green.png" position="240,98" size="25,25" alphatest="blend" />
- <widget source="key_red" render="Label" position="66,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
- <widget source="key_green" render="Label" position="268,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
- <ePixmap pixmap="Vu_HD/border_menu.png" position="120,140" zPosition="-1" size="342,358" transparent="1" alphatest="blend" />
- <widget name="menulist" position="130,150" size="322,338" transparent="1" backgroundColor="#27d9dee2" zPosition="10" scrollbarMode="showOnDemand" />
- <widget source="description" render="Label" position="500,140" size="280,360" font="Regular;19" halign="center" valign="center" backgroundColor="#c5c9cc" transparent="1"/>
- </screen>"""
- def __init__(self, session, ifaces):
- Screen.__init__(self, session)
- HelpableScreen.__init__(self)
- self.session = session
- self.iface = ifaces
- self.restartLanRef = None
- self.LinkState = None
- self.mainmenu = self.MakeMenu()
- self["menulist"] = MenuList(self.mainmenu)
- self["key_red"] = StaticText(_("Close"))
- self["key_green"] = StaticText(_("Select"))
- self["description"] = StaticText()
- self["IFtext"] = StaticText()
- self["IF"] = StaticText()
- self["Statustext"] = StaticText()
- self["statuspic"] = MultiPixmap()
- self["statuspic"].hide()
- self.onLayoutFinish.append(self.loadDescription)
-
- self.oktext = _("Press OK on your remote control to continue.")
-
- self["WizardActions"] = HelpableActionMap(self, "WizardActions",
- {
- "up": (self.up, _("move up to previous entry")),
- "down": (self.down, _("move down to next entry")),
- "left": (self.left, _("move up to first entry")),
- "right": (self.right, _("move down to last entry")),
- })
-
- self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
- {
- "cancel": (self.close, _("exit networkadapter setup menu")),
- "ok": (self.ok, _("select menu entry")),
- })
-
- self["ColorActions"] = HelpableActionMap(self, "ColorActions",
- {
- "red": (self.close, _("exit networkadapter setup menu")),
- "green": (self.ok, _("select menu entry")),
- })
-
- self["actions"] = NumberActionMap(["WizardActions","ShortcutActions"],
- {
- "ok": self.ok,
- "back": self.close,
- "up": self.up,
- "down": self.down,
- "red": self.close,
- "left": self.left,
- "right": self.right,
- }, -2)
-
- def loadDescription(self):
- if self["menulist"].getCurrent()[1] == 'setting':
- self["description"].setText(_("Edit the network configuration of your STB.\n" ) + self.oktext )
- if self["menulist"].getCurrent()[1] == 'scanap':
- self["description"].setText(_("Scan your network for wireless access points and connect to them using your selected wireless device.\n" ) + self.oktext )
- if self["menulist"].getCurrent()[1] == 'dns':
- self["description"].setText(_("Edit the Nameserver configuration of your STB.\n" ) + self.oktext )
- if self["menulist"].getCurrent()[1] == 'status':
- self["description"].setText(_("Shows the state of your wireless LAN connection.\n" ) + self.oktext )
- if self["menulist"].getCurrent()[1] == 'test':
- self["description"].setText(_("Test the network configuration of your STB.\n" ) + self.oktext )
- if self["menulist"].getCurrent()[1] == 'restart':
- self["description"].setText(_("Restart your network connection and interfaces.\n" ) + self.oktext )
-
- def up(self):
- self["menulist"].up()
- self.loadDescription()
-
- def down(self):
- self["menulist"].down()
- self.loadDescription()
-
- def left(self):
- self["menulist"].pageUp()
- self.loadDescription()
-
- def right(self):
- self["menulist"].pageDown()
- self.loadDescription()
-
- def ok(self):
- if self["menulist"].getCurrent()[1] == 'setting':
- self.session.openWithCallback(self.checklist, WlanConfig, self.iface)
- elif self["menulist"].getCurrent()[1] == 'scanap':
- self.session.open(WlanScanAp, self.iface)
- elif self["menulist"].getCurrent()[1] == 'dns':
- self.session.open(NameserverSetup)
- elif self["menulist"].getCurrent()[1] == 'status':
- self.session.open(Wlanstatus, self.iface)
- elif self["menulist"].getCurrent()[1] == 'test':
- self.session.openWithCallback(self.checklist,NetworkAdapterTest,self.iface)
- elif self["menulist"].getCurrent()[1] == 'restart':
- self.session.openWithCallback(self.restartLan, MessageBox, (_("Are you sure you want to restart your network interfaces?\n\n") + self.oktext ) )
-
- def checklist(self):
- self["menulist"].setList(self.MakeMenu())
-
- def MakeMenu(self):
- menu = []
- menu.append((_("Adapter settings"), "setting"))
- menu.append((_("Scan Wireless AP"), "scanap"))
- menu.append((_("Nameserver settings"), "dns"))
- if iNetwork.getAdapterAttribute(self.iface, "up"):
- menu.append((_("Show WLAN Status"), "status"))
- menu.append((_("Network test"), "test"))
- menu.append((_("Restart network"), "restart"))
-
- return menu
-
- def restartLan(self, ret = False):
- if (ret == True):
- iNetwork.restartNetwork(self.restartLanDataAvail)
- self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while your network is restarting..."), type = MessageBox.TYPE_INFO, enable_input = False)
-
- def restartLanDataAvail(self, data):
- if data is True:
- iNetwork.getInterfaces(self.getInterfacesDataAvail)
-
- def getInterfacesDataAvail(self, data):
- if data is True:
- self.restartLanRef.close(True)
-
- def restartfinishedCB(self,data):
- if data is True:
- self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 5, default = False)
-
-wlanconfig = ConfigSubsection()
-wlanconfig.usedevice = ConfigSelection(default = "off", choices = [
- ("off", _("off")), ("on", _("on"))])
-wlanconfig.usedhcp = ConfigSelection(default = "off", choices = [
- ("off", _("no")), ("on", _("yes"))])
-wlanconfig.essid = ConfigSelection(default = "none", choices = ["none"])
-wlanconfig.encrypt = ConfigSelection(default = "off", choices = [
- ("off", _("no")), ("on", _("yes"))])
-wlanconfig.method = ConfigSelection(default = "wep", choices = [
- ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
-wlanconfig.keytype = ConfigSelection(default = "ascii", choices = [
- ("ascii", _("ASCII")), ("hex", _("HEX"))])
-wlanconfig.key = ConfigText(default = "XXXXXXXX", visible_width = 50, fixed_size = False)
-wlanconfig.usegateway = ConfigSelection(default = "off", choices = [
- ("off", _("no")), ("on", _("yes"))])
-wlanconfig.ip = ConfigIP([0,0,0,0])
-wlanconfig.netmask = ConfigIP([0,0,0,0])
-wlanconfig.gateway = ConfigIP([0,0,0,0])
-
-selectap = None
-class WlanConfig(Screen, ConfigListScreen, HelpableScreen):
- skin = """
- <screen name="WlanConfig" position="209,48" size="865,623" title="Wireless Network Configuration..." flags="wfNoBorder" backgroundColor="transparent">
- <ePixmap pixmap="Vu_HD/Bg_EPG_view.png" zPosition="-1" position="0,0" size="865,623" alphatest="on" />
- <ePixmap pixmap="Vu_HD/menu/ico_title_Setup.png" position="32,41" size="40,40" alphatest="blend" transparent="1" />
- <eLabel text="Wireless Network Configuration..." position="90,50" size="600,32" font="Semiboldit;32" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
- <ePixmap pixmap="Vu_HD/icons/clock.png" position="750,55" zPosition="1" size="20,20" alphatest="blend" />
- <widget source="global.CurrentTime" render="Label" position="770,57" zPosition="1" size="50,20" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" halign="right" transparent="1">
- <convert type="ClockToText">Format:%H:%M</convert>
- </widget>
- <ePixmap pixmap="Vu_HD/buttons/red.png" position="45,98" size="25,25" alphatest="blend" />
- <ePixmap pixmap="Vu_HD/buttons/green.png" position="240,98" size="25,25" alphatest="blend" />
- <widget source="key_red" render="Label" position="66,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
- <widget source="key_grean" render="Label" position="268,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
- <ePixmap pixmap="Vu_HD/border_menu.png" position="120,140" zPosition="-1" size="342,358" transparent="1" alphatest="blend" />
- <widget name="config" position="130,150" size="322,338" transparent="1" backgroundColor="#27d9dee2" zPosition="10" scrollbarMode="showOnDemand" />
- <eLabel text="IP Address : " position="500,160" size="200,26" font="Semiboldit;22" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
- <widget source="ipaddress" render="Label" position="530,190" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />
- <eLabel text="NetMask : " position="500,220" size="200,26" font="Semiboldit;22" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
- <widget source="netmask" render="Label" position="530,250" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />
- <eLabel text="Gateway : " position="500,280" size="200,26" font="Semiboldit;22" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
- <widget source="gateway" render="Label" position="530,310" zPosition="1" size="150,26" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />
- </screen>"""
-
- def __init__(self, session, iface):
- Screen.__init__(self,session)
- self.session = session
- self["key_red"] = StaticText(_("Close"))
- self["key_grean"] = StaticText(_("Ok"))
- self["ipaddress"] = StaticText(_("[ N/A ]"))
- self["netmask"] = StaticText(_("[ N/A ]"))
- self["gateway"] = StaticText(_("[ N/A ]"))
- self["OkCancelActions"] = ActionMap(["ShortcutActions", "SetupActions" ],
- {
- "ok": self.saveWlanConfig,
- "green": self.saveWlanConfig,
- "cancel": self.keyCancel,
- "red": self.keyCancel,
- }, -2)
- self.iface = iface
- self.ssid = None
- self.ap_scan = None
- self.scan_ssid = None
- self.key_mgmt = None
- self.proto = None
- self.key_type = None
- self.encryption_key = None
- self.wlanscanap = None
-# self.scanAPcount =5
- self.scanAPcount =1
- self.list = []
- ConfigListScreen.__init__(self, self.list,session = self.session)
- self.oldInterfaceState = iNetwork.getAdapterAttribute(self.iface, "up")
- self.readWpaSupplicantConf()
-# iNetwork.getInterfaces(self.readWlanSettings)
- self.readWlanSettings()
- self.scanAPFailedTimer = eTimer()
- self.scanAPFailedTimer.callback.append(self.scanAPFailed)
- self.scanAplistTimer = eTimer()
- self.scanAplistTimer.callback.append(self.scanApList)
- self.Console = Console()
- self.scanAplistTimer.start(100,True)
-
- def readWlanSettings(self,ret=None):
- if ret is not True:
- print "getAddrInet Fail... "
- if iNetwork.getAdapterAttribute(self.iface, "up") == True:
- default_tmp = "on"
- else:
- default_tmp = "off"
- wlanconfig.usedevice = ConfigSelection(default=default_tmp, choices = [("off", _("off")), ("on", _("on"))])
-
- if iNetwork.getAdapterAttribute(self.iface, "dhcp"):
- default_tmp = "on"
- else:
- default_tmp = "off"
- wlanconfig.usedhcp = ConfigSelection(default=default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
-
- wlanconfig.ip = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "ip")) or [0,0,0,0]
-
- wlanconfig.netmask = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "netmask") or [255,0,0,0])
- if iNetwork.getAdapterAttribute(self.iface, "gateway"):
- default_tmp = "on"
- else:
- default_tmp = "off"
- wlanconfig.usegateway = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
-
- wlanconfig.gateway = ConfigIP(default=iNetwork.getAdapterAttribute(self.iface, "gateway") or [0,0,0,0])
-
- self["ipaddress"] = StaticText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "ip"))))
- self["netmask"] = StaticText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "netmask"))))
- self["gateway"] = StaticText(_(self.formatip(iNetwork.getAdapterAttribute(self.iface, "gateway"))))
-
- if self.encryption_key is not None:
- default_tmp = "on"
- else:
- default_tmp = "off"
- wlanconfig.encrypt = ConfigSelection(default = default_tmp, choices = [("off", _("no")), ("on", _("yes"))])
-
- if self.key_mgmt=="NONE":
- default_tmp = "wep"
- elif self.key_mgmt == "WPA-PSK":
- if self.proto == "WPA":
- default_tmp = "wpa"
- elif self.proto == "RSN":
- default_tmp = "wpa2"
- elif self.proto in ( "WPA RSN", "WPA WPA2"):
- default_tmp = "wpa/wpa2"
- else:
- default_tmp = "wpa"
- else:
- default_tmp = "wep"
-
- wlanconfig.method = ConfigSelection(default = default_tmp, choices = [
- ("wep", _("WEP")), ("wpa", _("WPA")), ("wpa2", _("WPA2")),("wpa/wpa2", _("WPA/WPA2"))])
-
- if self.key_type == 0:
- default_tmp = "hex"
- else:
- default_tmp = "ascii"
- wlanconfig.keytype = ConfigSelection(default = default_tmp, choices = [
- ("ascii", _("ASCII")), ("hex", _("HEX"))])
- default_tmp = self.encryption_key or "XXXXXXXX"
- wlanconfig.key = ConfigText(default = default_tmp, visible_width = 50, fixed_size = False)
-
- def readWpaSupplicantConf(self):
- try:
- if fileExists("/etc/wpa_supplicant.conf"):
- wpafd = open("/etc/wpa_supplicant.conf","r")
- if wpafd >0:
- data = wpafd.readline()
- while len(data) > 0:
-# print "####readWpaSupplicantConf, data : ",data
- data = data.lstrip()
- if len(data) == 0:
- data = wpafd.readline()
- continue
- if data.startswith('ssid=') and len(data) > 6:
- self.ssid = data[6:-2]
- elif data.startswith('ap_scan=') :
- self.ap_scan = data[8:]
-# print "####readWpaSupplicantConf, ap_scan : ",self.ap_scan
- elif data.startswith('scan_ssid=') and len(data) > 10:
- self.scan_ssid = data[10:-1]
- elif data.startswith('key_mgmt=') and len(data) > 9:
- self.key_mgmt = data[9:-1]
- elif data.startswith('proto=') and len(data) > 6:
- self.proto = data[6:-1]
- elif data.startswith('wep_key0="') and len(data) > 11:
- self.key_type = 1 # ascii
- self.encryption_key = data[10:-2]
- elif data.startswith('wep_key0=') and len(data) > 9:
- self.key_type = 0 # hex
- self.encryption_key = data[9:-1]
- elif data.startswith('psk="') and len(data) > 6:
- self.key_type = 1 # ascii
- self.encryption_key = data[5:-2]
- elif data.startswith('psk=') and len(data) > 4:
- self.key_type = 0 # hex
- self.encryption_key = data[4:-1]
- data = wpafd.readline()
- print self.ssid,self.scan_ssid,self.key_mgmt,self.proto,self.key_type,self.encryption_key
- wpafd.close()
- else:
- print 'read error'
- else:
- pass
- except:
- print 'failed loading wpasupplicant.conf'
-
- def createConfig(self):
- self.configList=[]
- self.usedeviceEntry = getConfigListEntry(_("Use Device"), wlanconfig.usedevice)
- self.usedhcpEntry = getConfigListEntry(_("Use DHCP"), wlanconfig.usedhcp)
- self.essidEntry = getConfigListEntry(_("ESSID"), wlanconfig.essid)
- self.hiddenessidEntry = getConfigListEntry(_("Input Hidden ESSID"), wlanconfig.hiddenessid)
- self.encryptEntry = getConfigListEntry(_("Encrypt"), wlanconfig.encrypt)
- self.methodEntry = getConfigListEntry(_("Method"), wlanconfig.method)
- self.keytypeEntry = getConfigListEntry(_("Key Type"), wlanconfig.keytype)
- self.keyEntry = getConfigListEntry(_("KEY"), wlanconfig.key)
-
- self.ipEntry = getConfigListEntry(_("IP"), wlanconfig.ip)
- self.netmaskEntry = getConfigListEntry(_("NetMask"), wlanconfig.netmask)
-
- self.usegatewayEntry = getConfigListEntry(_("Use Gateway"), wlanconfig.usegateway)
- self.gatewayEntry = getConfigListEntry(_("Gateway"), wlanconfig.gateway)
-
- self.configList.append( self.usedeviceEntry )
- if wlanconfig.usedevice.value is "on":
- self.configList.append( self.usedhcpEntry )
- if wlanconfig.usedhcp.value is "off":
- self.configList.append(self.ipEntry)
- self.configList.append(self.netmaskEntry)
- self.configList.append(self.usegatewayEntry)
- if wlanconfig.usegateway.value is "on":
- self.configList.append(self.gatewayEntry)
- self.configList.append( self.essidEntry )
-# print "#### wlanconfig.essid.value : ",wlanconfig.essid.value
- if wlanconfig.essid.value == 'Input hidden ESSID':
- self.configList.append( self.hiddenessidEntry )
- self.configList.append( self.encryptEntry )
- if wlanconfig.encrypt.value is "on" :
- self.configList.append( self.methodEntry )
- self.configList.append( self.keytypeEntry )
- self.configList.append( self.keyEntry )
-
- self["config"].list = self.configList
- self["config"].l.setList(self.configList)
-# if not self.selectionChanged in self["config"].onSelectionChanged:
-# self["config"].onSelectionChanged.append(self.selectionChanged)
-
- def scanApList(self):
- self.apList = []
- self.configurationmsg = self.session.open(MessageBox, _("Please wait for scanning AP..."), type = MessageBox.TYPE_INFO, enable_input = False)
- cmd = "ifconfig "+self.iface+" up"
- print 'cmd ',cmd
- os_system(cmd)
- self.wlanscanap = Console()
- cmd = "iwlist "+self.iface+" scan"
- print 'cmd ',cmd
- self.wlanscanap.ePopen(cmd, self.apListFinnished,self.apListParse)
-
- def apListFinnished(self, result, retval,extra_args):
- (callback) = extra_args
- if self.wlanscanap is not None:
- if retval == 0:
- self.wlanscanap = None
- content = result.splitlines()
- first = content[0].split()
- completed = False
- for x in first:
- if x == 'completed':
- completed = True
- if completed == True:
- callback(result)
- else:
- callback(0)
- else:
- callback(0)
-
- def apListParse(self,data):
- global selectap
- if data == 0:
- if self.scanAPcount >0:
- self.scanAPcount -=1
- self.configurationmsg.close(True)
- time.sleep(3)
- self.scanAplistTimer.start(500,True)
- return
- else:
- self.configurationmsg.close(True)
- self.scanAPFailedTimer.start(500,True)
- return
- else:
- self.apList = []
-# self.scanAPcount =5
- self.scanAPcount =0
- list = data.splitlines()
- for x in list:
- xx = x.lstrip()
- if xx.startswith('ESSID:') and len(xx)>8 and xx[7:-1]not in self.apList:
- self.apList.append(xx[7:-1])
- self.apList.append('Input hidden ESSID')
-# print "###### selectap : ",selectap
- if selectap is not None and selectap in self.apList:
- wlanconfig.essid = ConfigSelection(default=selectap,choices = self.apList)
- elif self.ap_scan is not None and self.ap_scan.strip() == '2':
- wlanconfig.essid = ConfigSelection(default='Input hidden ESSID',choices = self.apList)
- elif self.ssid is not None and self.ssid in self.apList:
- wlanconfig.essid = ConfigSelection(default=self.ssid,choices = self.apList)
- else:
- wlanconfig.essid = ConfigSelection(choices = self.apList)
- if self.ssid is not None:
- wlanconfig.hiddenessid = ConfigText(default = self.ssid, visible_width = 50, fixed_size = False)
- else:
- wlanconfig.hiddenessid = ConfigText(default = "<Input ESSID>", visible_width = 50, fixed_size = False)
- self.configurationmsg.close(True)
- self.createConfig()
-
- def scanAPFailed(self):
- self.session.openWithCallback(self.keyCancel ,MessageBox, _("Scan AP Failed"), MessageBox.TYPE_ERROR,10)
-
- def keyLeft(self):
- ConfigListScreen.keyLeft(self)
- self.newConfig()
-
- def keyRight(self):
- ConfigListScreen.keyRight(self)
- self.newConfig()
-
- def newConfig(self):
- if self["config"].getCurrent() == self.usedeviceEntry or self["config"].getCurrent() == self.encryptEntry \
- or self["config"].getCurrent() == self.usedhcpEntry or self["config"].getCurrent() == self.usegatewayEntry \
- or self["config"].getCurrent() == self.essidEntry:
- self.createConfig()
-
- def saveWlanConfig(self):
- if self["config"].isChanged():
- self.session.openWithCallback(self.checkNetworkShares, MessageBox, (_("Are you sure you want to restart your network interfaces?\n") ) )
-
- def checkNetworkShares(self,ret = False):
- if ret == False:
- return
- if not self.Console:
- self.Console = Console()
- cmd = "cat /proc/mounts"
- self.Console.ePopen(cmd, self.checkSharesFinished, self.confirmAnotherIfaces)
-
- def checkSharesFinished(self, result, retval, extra_args):
- callback = extra_args
- print "checkMountsFinished : result : \n",result
- networks = ['nfs','smbfs','ncp','coda']
- for line in result.splitlines():
- split = line.strip().split(' ',3)
- if split[2] in networks:
- self.session.open(MessageBox, ("NOT deconfiguring network interfaces :\n network shares still mounted\n"), type = MessageBox.TYPE_ERROR, timeout = 10)
- callback(False)
- return
- callback(True)
-
- def confirmAnotherIfaces(self, ret = False):
- if ret == False:
- return
- else:
- num_configured_if = len(iNetwork.getConfiguredAdapters())
- if num_configured_if >= 1:
- if num_configured_if == 1 and self.iface in iNetwork.getConfiguredAdapters():
- self.writeWlanConfig(False)
- else:
- self.session.openWithCallback(self.writeWlanConfig, MessageBox, (_("Are you sure you want to deactive another network interfaces?\n") ) )
- else:
- self.writeWlanConfig(False)
-
- def writeWlanConfig(self,ret = False):
- if ret == True:
- configuredInterfaces = iNetwork.getConfiguredAdapters()
- for interface in configuredInterfaces:
- if interface == self.iface:
- continue
- iNetwork.setAdapterAttribute(interface, "up", False)
- iNetwork.deactivateInterface(interface)
- ret=self.writeWpasupplicantConf()
- if ret == -1:
- self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
- return
- elif ret == -2:
- self.session.open(MessageBox, _("hidden ESSID empty"), type = MessageBox.TYPE_ERROR, timeout = 10)
- return
- iffd = open("/etc/network/interfaces","r")
- if iffd > 0:
- prev_content = ""
- next_content = ""
- data = iffd.readline()
- status = 0
- while len(data) >0 :
- if data.startswith('iface '+self.iface) or data.startswith('auto '+self.iface):
- status = 1
- data = iffd.readline()
- continue
- elif not data.startswith('auto lo') and data.startswith('auto '):
- if ret == True or data[5:] not in iNetwork.getConfiguredAdapters():
- data = iffd.readline()
- continue
- if status == 1 and data.startswith('iface ') or data.startswith('auto '):
- status = 2
- if status == 0:
- prev_content += data
- elif status == 2:
- next_content += data
- data = iffd.readline()
- iffd.close()
- iffd = open("/etc/network/interfaces","w")
- if iffd > 0 :
- if prev_content == "":
- prev_content = "# automatically generated by STB\n"
- prev_content += "# do Not change manually!\n\n"
- prev_content += "auto lo\n"
- prev_content += "iface lo inet loopback\n\n"
- iffd.write(prev_content)
- if wlanconfig.usedevice.value=="on":
- iNetwork.setAdapterAttribute(self.iface, "up", True)
- contents = "auto "+self.iface+"\n"
- contents += "iface "+self.iface+" inet "
- if wlanconfig.usedhcp.value =="on":
- iNetwork.setAdapterAttribute(self.iface, "dhcp", True)
- contents +="dhcp\n"
- else:
- iNetwork.setAdapterAttribute(self.iface, "dhcp", False)
- contents +="static\n"
-# print wlanconfig.ip.value
- iNetwork.setAdapterAttribute(self.iface, "ip", wlanconfig.ip.value)
- iNetwork.setAdapterAttribute(self.iface, "netmask", wlanconfig.netmask.value)
- contents +="\taddress "+ self.formatip(wlanconfig.ip.value)+"\n"
- contents +="\tnetmask "+ self.formatip(wlanconfig.netmask.value)+"\n"
- if wlanconfig.usegateway.value == "on":
- iNetwork.setAdapterAttribute(self.iface, "gateway", wlanconfig.gateway.value)
- contents +="\tgateway "+ self.formatip(wlanconfig.gateway.value)+"\n"
- contents += "\tpre-up wpa_supplicant -i"+self.iface+" -c/etc/wpa_supplicant.conf -B -D"+iNetwork.detectWlanModule(self.iface)+"\n"
- contents += "\tpost-down wpa_cli terminate\n\n"
- iffd.write(contents)
- else:
- iNetwork.setAdapterAttribute(self.iface, "up", False)
- iNetwork.deactivateInterface(self.iface)
- iffd.write(next_content)
- iffd.close()
- else :
- self.session.open(MessageBox, _("/etc/network/interfaces open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
- return
- iNetwork.restartNetwork(self.updateCurrentInterfaces)
- self.configurationmsg = None
- self.configurationmsg = self.session.openWithCallback(self.configFinished, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
-
- def writeWpasupplicantConf(self):
- wpafd = open("/etc/wpa_supplicant.conf","w")
- if wpafd > 0:
- contents = "#WPA Supplicant Configuration by STB\n"
- contents += "ctrl_interface=/var/run/wpa_supplicant\n"
- contents += "eapol_version=1\n"
- contents += "fast_reauth=1\n"
-
- if wlanconfig.essid.value == 'Input hidden ESSID':
- contents += "ap_scan=2\n"
- else :
- contents += "ap_scan=1\n"
- contents += "network={\n"
- if wlanconfig.essid.value == 'Input hidden ESSID':
- if len(wlanconfig.hiddenessid.value) == 0:
- wpafd.close()
- return -2
- contents += "\tssid=\""+wlanconfig.hiddenessid.value+"\"\n"
- else :
- contents += "\tssid=\""+wlanconfig.essid.value+"\"\n"
- contents += "\tscan_ssid=0\n"
- if wlanconfig.encrypt.value == "on":
- if wlanconfig.method.value =="wep":
- contents += "\tkey_mgmt=NONE\n"
- contents += "\twep_key0="
- elif wlanconfig.method.value == "wpa":
- contents += "\tkey_mgmt=WPA-PSK\n"
- contents += "\tproto=WPA\n"
- contents += "\tpairwise=CCMP TKIP\n"
- contents += "\tgroup=CCMP TKIP\n"
- contents += "\tpsk="
- elif wlanconfig.method.value == "wpa2":
- contents += "\tkey_mgmt=WPA-PSK\n"
- contents += "\tproto=RSN\n"
- contents += "\tpairwise=CCMP TKIP\n"
- contents += "\tgroup=CCMP TKIP\n"
- contents += "\tpsk="
- else:
- contents += "\tkey_mgmt=WPA-PSK\n"
- contents += "\tproto=WPA RSN\n"
- contents += "\tpairwise=CCMP TKIP\n"
- contents += "\tgroup=CCMP TKIP\n"
- contents += "\tpsk="
- if wlanconfig.keytype.value == "ascii":
- contents += "\""+wlanconfig.key.value+"\"\n"
- else:
- contents += wlanconfig.key.value+"\n"
- else:
- contents += "\tkey_mgmt=NONE\n"
- contents += "}\n"
- print "content = \n"+contents
- wpafd.write(contents)
- wpafd.close()
- return 0
- else :
- self.session.open(MessageBox, _("wpa_supplicant.conf open error."), type = MessageBox.TYPE_ERROR, timeout = 10)
- return -1
- def updateCurrentInterfaces(self,ret):
- if ret is True:
- iNetwork.getInterfaces(self.configurationMsgClose)
-
- def configurationMsgClose(self,ret):
- if ret is True and self.configurationmsg is not None:
- self.configurationmsg.close(True)
-
- def configFinished(self,data):
- global selectap
- if data is True:
- self.session.openWithCallback(self.configFinishedCB, MessageBox, _("Your network configuration has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
- selectap = wlanconfig.essid.value
-
- def configFinishedCB(self,data):
- if data is not None:
- if data is True:
- self.close()
-
- def formatip(self, iplist):
- list = []
- list = iplist
-# print "iplist : ",iplist
- try:
- if len(iplist) == 4:
- result = str(iplist[0])+"."+str(iplist[1])+"."+str(iplist[2])+"."+str(iplist[3])
- else:
- result ="0.0.0.0"
-# print "result : ",result
- return result
- except:
- return "[N/A]"
-
- def keyCancelConfirm(self, result):
- if not result:
- return
- if self.oldInterfaceState is False:
- iNetwork.setAdapterAttribute(self.iface, "up", False)
- iNetwork.deactivateInterface(self.iface,self.keyCancelCB)
- else:
- self.close()
-
- def keyCancel(self,yesno = True):
- if self["config"].isChanged():
- self.session.openWithCallback(self.keyCancelConfirm, MessageBox, _("Really close without saving settings?"))
- else:
- self.keyCancelConfirm(True)
-
- def keyCancelCB(self,data):
- if data is not None:
- if data is True:
- self.close()
-
-# def selectionChanged(self):
-# current = self["config"].getCurrent()
-# print current
-
-class WlanScanAp(Screen,HelpableScreen):
- skin = """
- <screen name="WlanScanAp" position="209,48" size="865,623" title="Wireless Network Configuration..." flags="wfNoBorder" backgroundColor="transparent">
- <ePixmap pixmap="Vu_HD/Bg_EPG_view.png" zPosition="-1" position="0,0" size="865,623" alphatest="on" />
- <ePixmap pixmap="Vu_HD/menu/ico_title_Setup.png" position="32,41" size="40,40" alphatest="blend" transparent="1" />
- <eLabel text="Wireless Network AP Scan..." position="90,50" size="600,32" font="Semiboldit;32" foregroundColor="#5d5d5d" backgroundColor="#27b5b9bd" transparent="1" />
- <ePixmap pixmap="Vu_HD/icons/clock.png" position="750,55" zPosition="1" size="20,20" alphatest="blend" />
- <widget source="global.CurrentTime" render="Label" position="770,57" zPosition="1" size="50,20" font="Regular;20" foregroundColor="#1c1c1c" backgroundColor="#27d9dee2" halign="right" transparent="1">
- <convert type="ClockToText">Format:%H:%M</convert>
- </widget>
- <ePixmap pixmap="Vu_HD/buttons/red.png" position="45,98" size="25,25" alphatest="blend" />
- <ePixmap pixmap="Vu_HD/buttons/green.png" position="240,98" size="25,25" alphatest="blend" />
- <ePixmap pixmap="Vu_HD/buttons/blue.png" position="630,98" size="25,25" alphatest="blend" />
- <widget source="key_red" render="Label" position="66,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
- <widget source="key_green" render="Label" position="268,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
- <widget source="key_blue" render="Label" position="665,97" zPosition="1" size="150,25" font="Regular;20" halign="center" valign="center" backgroundColor="darkgrey" foregroundColor="#1c1c1c" transparent="1" />
- <ePixmap pixmap="Vu_HD/border_menu.png" position="120,140" zPosition="-1" size="342,358" transparent="1" alphatest="blend" />
- <widget name="menulist" position="130,150" size="322,338" transparent="1" backgroundColor="#27d9dee2" zPosition="10" scrollbarMode="showOnDemand" />
- <widget source="Address" render="Label" position="490,220" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />
- <widget source="ESSID" render="Label" position="490,250" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />
- <widget source="Protocol" render="Label" position="490,280" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />
- <widget source="Frequency" render="Label" position="490,310" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />
- <widget source="Encryption key" render="Label" position="490,340" zPosition="1" size="300,30" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />
- <widget source="BitRate" render="Label" position="490,370" zPosition="1" size="300,60" font="Regular;20" halign="center" valign="center" backgroundColor="#27b5b9bd" foregroundColor="#1c1c1c" transparent="1" />
- </screen>"""
-