X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/040e658a3f89783e0030392110e87cc992264cdd..ecd15d83806de513514e2ef84892b6d30c64cc8c:/lib/python/Components/Network.py diff --git a/lib/python/Components/Network.py b/lib/python/Components/Network.py index 8e9fc120..b9da48d8 100755 --- a/lib/python/Components/Network.py +++ b/lib/python/Components/Network.py @@ -3,6 +3,8 @@ from re import compile as re_compile, search as re_search from socket import * from enigma import eConsoleAppContainer from Components.Console import Console +from Components.PluginComponent import plugins +from Plugins.Plugin import PluginDescriptor class Network: def __init__(self): @@ -12,17 +14,30 @@ class Network: self.NetworkState = 0 self.DnsState = 0 self.nameservers = [] - self.ethtool_bin = "/usr/sbin/ethtool" + self.ethtool_bin = "ethtool" self.container = eConsoleAppContainer() self.Console = Console() self.LinkConsole = Console() self.restartConsole = Console() self.deactivateConsole = Console() + self.deactivateInterfaceConsole = Console() self.activateConsole = Console() self.resetNetworkConsole = Console() self.DnsConsole = Console() + self.PingConsole = Console() + self.config_ready = None self.getInterfaces() + def onRemoteRootFS(self): + fp = file('/proc/mounts', 'r') + mounts = fp.readlines() + fp.close() + for line in mounts: + parts = line.strip().split(' ') + if parts[1] == '/' and (parts[2] == 'nfs' or parts[2] == 'smbfs'): + return True + return False + def getInterfaces(self, callback = None): devicesPattern = re_compile('[a-z]+[0-9]+') self.configuredInterfaces = [] @@ -32,7 +47,7 @@ class Network: for line in result: try: device = devicesPattern.search(line).group() - if device == 'wifi0': + if device in ('wifi0', 'wmaster0'): continue self.getDataForInterface(device, callback) except AttributeError: @@ -62,6 +77,8 @@ class Network: def getDataForInterface(self, iface,callback): #get ip out of ip addr, as avahi sometimes overrides it in ifconfig. + if not self.Console: + self.Console = Console() cmd = "ip -o addr" self.Console.ePopen(cmd, self.IPaddrFinished, [iface,callback]) @@ -74,7 +91,7 @@ class Network: macRegexp = '[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[a-z0-9]{2}\:[a-z0-9]{2}\:[a-z0-9]{2}' ipLinePattern = re_compile('inet ' + ipRegexp + '/') ipPattern = re_compile(ipRegexp) - netmaskLinePattern = re_compile('/' + netRegexp + ' brd ') + netmaskLinePattern = re_compile('/' + netRegexp) netmaskPattern = re_compile(netRegexp) bcastLinePattern = re_compile(' brd ' + ipRegexp) upPattern = re_compile('UP') @@ -200,7 +217,7 @@ class Network: ifaces[currif]["gateway"] = map(int, split[1].split('.')) if self.ifaces[currif].has_key("gateway"): if self.ifaces[currif]["gateway"] != ifaces[currif]["gateway"] and ifaces[currif]["dhcp"] == False: - self.ifaces[currif]["gateway"] = map(int, split[1].split('.')) + self.ifaces[currif]["gateway"] = map(int, split[1].split('.')) if (split[0] == "pre-up"): if self.ifaces[currif].has_key("preup"): self.ifaces[currif]["preup"] = i @@ -211,15 +228,18 @@ class Network: for ifacename, iface in ifaces.items(): if self.ifaces.has_key(ifacename): self.ifaces[ifacename]["dhcp"] = iface["dhcp"] - if len(self.Console.appContainers) == 0: - # save configured interfacelist - self.configuredNetworkAdapters = self.configuredInterfaces - # load ns only once - self.loadNameserverConfig() - print "read configured interfac:", ifaces - print "self.ifaces after loading:", self.ifaces - if callback is not None: - callback(True) + if self.Console: + if len(self.Console.appContainers) == 0: + # save configured interfacelist + self.configuredNetworkAdapters = self.configuredInterfaces + # load ns only once + self.loadNameserverConfig() + print "read configured interface:", ifaces + print "self.ifaces after loading:", self.ifaces + self.config_ready = True + self.msgPlugins() + if callback is not None: + callback(True) def loadNameserverConfig(self): ipRegexp = "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" @@ -244,6 +264,10 @@ class Network: print "nameservers:", self.nameservers def deactivateNetworkConfig(self, callback = None): + if self.onRemoteRootFS(): + if callback is not None: + callback(True) + return self.deactivateConsole = Console() self.commands = [] self.commands.append("/etc/init.d/avahi-daemon stop") @@ -262,6 +286,10 @@ class Network: callback(True) def activateNetworkConfig(self, callback = None): + if self.onRemoteRootFS(): + if callback is not None: + callback(True) + return self.activateConsole = Console() self.commands = [] self.commands.append("/etc/init.d/networking start") @@ -335,6 +363,10 @@ class Network: 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") @@ -393,6 +425,7 @@ class Network: def checkNetworkState(self,statecallback): # www.dream-multimedia-tv.de, www.heise.de, www.google.de + self.NetworkState = 0 cmd1 = "ping -c 1 82.149.226.170" cmd2 = "ping -c 1 193.99.144.85" cmd3 = "ping -c 1 209.85.135.103" @@ -412,8 +445,14 @@ class Network: if len(self.PingConsole.appContainers) == 0: statecallback(self.NetworkState) - def restartNetwork(self,callback): + def restartNetwork(self,callback = None): + if self.onRemoteRootFS(): + if callback is not None: + callback(True) + return self.restartConsole = Console() + self.config_ready = False + self.msgPlugins() self.commands = [] self.commands.append("/etc/init.d/avahi-daemon stop") for iface in self.ifaces.keys(): @@ -427,8 +466,8 @@ class Network: self.restartConsole.eBatch(self.commands, self.restartNetworkFinished, callback, debug=True) def restartNetworkFinished(self,extra_args): - callback = extra_args - if len(self.restartConsole.appContainers) == 0: + ( callback ) = extra_args + if callback is not None: callback(True) def getLinkState(self,iface,callback): @@ -438,29 +477,47 @@ class Network: def getLinkStateFinished(self, result, retval,extra_args): (callback) = extra_args + if self.LinkConsole is not None: if len(self.LinkConsole.appContainers) == 0: callback(result) + def stopPingConsole(self): + if self.PingConsole is not None: + if len(self.PingConsole.appContainers): + for name in self.PingConsole.appContainers.keys(): + self.PingConsole.kill(name) + def stopLinkStateConsole(self): if self.LinkConsole is not None: - self.LinkConsole = None - + if len(self.LinkConsole.appContainers): + for name in self.LinkConsole.appContainers.keys(): + self.LinkConsole.kill(name) + def stopDNSConsole(self): if self.DnsConsole is not None: - self.DnsConsole = None - + if len(self.DnsConsole.appContainers): + for name in self.DnsConsole.appContainers.keys(): + self.DnsConsole.kill(name) + def stopRestartConsole(self): if self.restartConsole is not None: - self.restartConsole = None - - def RestartConsoleRunning(self): - if self.restartConsole is not None: - if len(self.restartConsole.appContainers) == 0: - return False - else: - return True - + if len(self.restartConsole.appContainers): + for name in self.restartConsole.appContainers.keys(): + self.restartConsole.kill(name) + + def stopGetInterfacesConsole(self): + if self.Console is not None: + if len(self.Console.appContainers): + for name in self.Console.appContainers.keys(): + self.Console.kill(name) + + def stopDeactivateInterfaceConsole(self): + if self.deactivateInterfaceConsole is not None: + if len(self.deactivateInterfaceConsole.appContainers): + for name in self.deactivateInterfaceConsole.appContainers.keys(): + self.deactivateInterfaceConsole.kill(name) + def checkforInterface(self,iface): if self.getAdapterAttribute(iface, 'up') is True: return True @@ -492,17 +549,25 @@ class Network: if len(self.DnsConsole.appContainers) == 0: statecallback(self.DnsState) - def deactivateInterface(self,iface): + def deactivateInterface(self,iface,callback = None): + if self.onRemoteRootFS(): + if callback is not None: + callback(True) + return self.deactivateInterfaceConsole = Console() self.commands = [] cmd1 = "ip addr flush " + iface cmd2 = "ifconfig " + iface + " down" self.commands.append(cmd1) self.commands.append(cmd2) - self.deactivateInterfaceConsole.eBatch(self.commands, self.deactivateInterfaceFinished, extra_args = None, debug=True) + self.deactivateInterfaceConsole.eBatch(self.commands, self.deactivateInterfaceFinished, callback, debug=True) def deactivateInterfaceFinished(self,extra_args): - pass + callback = extra_args + if self.deactivateInterfaceConsole: + if len(self.deactivateInterfaceConsole.appContainers) == 0: + if callback is not None: + callback(True) def detectWlanModule(self): self.wlanmodule = None @@ -515,11 +580,11 @@ class Network: self.wlanmodule = 'madwifi' if os_path.exists(rt73_dir): rtfiles = listdir(rt73_dir) - if len(rtfiles) == 2: + if len(rtfiles) == 2 or len(rtfiles) == 5: self.wlanmodule = 'ralink' if os_path.exists(zd1211b_dir): zdfiles = listdir(zd1211b_dir) - if len(zdfiles) == 1: + if len(zdfiles) == 1 or len(zdfiles) == 5: self.wlanmodule = 'zydas' return self.wlanmodule @@ -538,6 +603,11 @@ class Network: netmask = str(inet_ntoa(pack('>L', nm))) return netmask + def msgPlugins(self): + if self.config_ready is not None: + for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKCONFIG_READ): + p(reason=self.config_ready) + iNetwork = Network() def InitNetwork():