+ def getNumberOfAdapters(self):
+ return len(self.ifaces)
+
+ def getFriendlyAdapterName(self, x):
+ # maybe this needs to be replaced by an external list.
+ friendlyNames = {
+ "eth0": _("Integrated Ethernet"),
+ "wlan0": _("Wireless"),
+ "ath0": _("Integrated Wireless")
+ }
+ return friendlyNames.get(x, x) # when we have no friendly name, use adapter name
+
+ def getAdapterName(self, iface):
+ return iface
+
+ def getAdapterList(self):
+ return self.ifaces.keys()
+
+ def getAdapterAttribute(self, iface, attribute):
+ if self.ifaces.has_key(iface):
+ if self.ifaces[iface].has_key(attribute):
+ return self.ifaces[iface][attribute]
+ return None
+
+ def setAdapterAttribute(self, iface, attribute, value):
+ print "setting for adapter", iface, "attribute", attribute, " to value", value
+ if self.ifaces.has_key(iface):
+ self.ifaces[iface][attribute] = value
+
+ def removeAdapterAttribute(self, iface, attribute):
+ if self.ifaces.has_key(iface):
+ if self.ifaces[iface].has_key(attribute):
+ del self.ifaces[iface][attribute]
+
+ def getNameserverList(self):
+ if len(self.nameservers) == 0:
+ return [[0, 0, 0, 0], [0, 0, 0, 0]]
+ else:
+ return self.nameservers
+
+ def clearNameservers(self):
+ self.nameservers = []
+
+ def addNameserver(self, nameserver):
+ if nameserver not in self.nameservers:
+ self.nameservers.append(nameserver)
+
+ def removeNameserver(self, nameserver):
+ if nameserver in self.nameservers:
+ self.nameservers.remove(nameserver)
+
+ def changeNameserver(self, oldnameserver, newnameserver):
+ if oldnameserver in self.nameservers:
+ for i in range(len(self.nameservers)):
+ if self.nameservers[i] == oldnameserver:
+ self.nameservers[i] = newnameserver
+
+ def resetNetworkConfig(self, mode='lan', callback = None):
+ if self.onRemoteRootFS():
+ if callback is not None:
+ callback(True)
+ return
+ self.resetNetworkConsole = Console()
+ self.commands = []
+ self.commands.append("/etc/init.d/avahi-daemon stop")
+ for iface in self.ifaces.keys():
+ cmd = "ip addr flush " + iface
+ self.commands.append(cmd)
+ self.commands.append("/etc/init.d/networking stop")
+ self.commands.append("killall -9 udhcpc")
+ self.commands.append("rm /var/run/udhcpc*")
+ self.resetNetworkConsole.eBatch(self.commands, self.resetNetworkFinishedCB, [mode, callback], debug=True)
+
+ def resetNetworkFinishedCB(self, extra_args):
+ (mode, callback) = extra_args
+ if len(self.resetNetworkConsole.appContainers) == 0:
+ self.writeDefaultNetworkConfig(mode, callback)
+
+ def writeDefaultNetworkConfig(self,mode='lan', callback = None):
+ fp = file('/etc/network/interfaces', 'w')
+ fp.write("# automatically generated by enigma 2\n# do NOT change manually!\n\n")
+ fp.write("auto lo\n")
+ fp.write("iface lo inet loopback\n\n")
+ if mode == 'wlan':
+ fp.write("auto wlan0\n")
+ fp.write("iface wlan0 inet dhcp\n")
+ if mode == 'wlan-mpci':
+ fp.write("auto ath0\n")
+ fp.write("iface ath0 inet dhcp\n")
+ if mode == 'lan':
+ fp.write("auto eth0\n")
+ fp.write("iface eth0 inet dhcp\n")
+ fp.write("\n")
+ fp.close()
+
+ self.resetNetworkConsole = Console()
+ self.commands = []
+ if mode == 'wlan':
+ self.commands.append("ifconfig eth0 down")
+ self.commands.append("ifconfig ath0 down")
+ self.commands.append("ifconfig wlan0 up")
+ if mode == 'wlan-mpci':
+ self.commands.append("ifconfig eth0 down")
+ self.commands.append("ifconfig wlan0 down")
+ self.commands.append("ifconfig ath0 up")
+ if mode == 'lan':
+ self.commands.append("ifconfig eth0 up")
+ self.commands.append("ifconfig wlan0 down")
+ self.commands.append("ifconfig ath0 down")
+ self.commands.append("/etc/init.d/avahi-daemon start")
+ self.resetNetworkConsole.eBatch(self.commands, self.resetNetworkFinished, [mode,callback], debug=True)
+
+ def resetNetworkFinished(self,extra_args):
+ (mode, callback) = extra_args
+ if len(self.resetNetworkConsole.appContainers) == 0:
+ if callback is not None:
+ callback(True,mode)