+ def checkDNSLookup(self,statecallback):
+ cmd1 = "nslookup www.dream-multimedia-tv.de"
+ cmd2 = "nslookup www.heise.de"
+ cmd3 = "nslookup www.google.de"
+ self.DnsConsole = Console()
+ self.DnsConsole.ePopen(cmd1, self.checkDNSLookupFinished,statecallback)
+ self.DnsConsole.ePopen(cmd2, self.checkDNSLookupFinished,statecallback)
+ self.DnsConsole.ePopen(cmd3, self.checkDNSLookupFinished,statecallback)
+
+ def checkDNSLookupFinished(self, result, retval,extra_args):
+ (statecallback) = extra_args
+ if self.DnsConsole is not None:
+ if retval == 0:
+ self.DnsConsole = None
+ statecallback(self.DnsState)
+ else:
+ self.DnsState += 1
+ if len(self.DnsConsole.appContainers) == 0:
+ statecallback(self.DnsState)
+
+ def deactivateInterface(self,ifaces,callback = None):
+ self.config_ready = False
+ self.msgPlugins()
+ commands = []
+ def buildCommands(iface):
+ commands.append("ifdown " + iface)
+ commands.append("ip addr flush dev " + iface)
+ #wpa_supplicant sometimes doesn't quit properly on SIGTERM
+ if os_path.exists('/var/run/wpa_supplicant/'+ iface):
+ commands.append("wpa_cli -i" + iface + " terminate")
+
+ if not self.deactivateInterfaceConsole:
+ self.deactivateInterfaceConsole = Console()
+
+ if isinstance(ifaces, (list, tuple)):
+ for iface in ifaces:
+ if iface != 'eth0' or not self.onRemoteRootFS():
+ buildCommands(iface)
+ else:
+ if ifaces == 'eth0' and self.onRemoteRootFS():
+ if callback is not None:
+ callback(True)
+ return
+ buildCommands(ifaces)
+ self.deactivateInterfaceConsole.eBatch(commands, self.deactivateInterfaceFinished, [ifaces,callback], debug=True)
+
+ def deactivateInterfaceFinished(self,extra_args):
+ (ifaces, callback) = extra_args
+ def checkCommandResult(iface):
+ if self.deactivateInterfaceConsole and self.deactivateInterfaceConsole.appResults.has_key("ifdown " + iface):
+ result = str(self.deactivateInterfaceConsole.appResults.get("ifdown " + iface)).strip("\n")
+ if result == "ifdown: interface " + iface + " not configured":
+ return False
+ else:
+ return True
+ #ifdown sometimes can't get the interface down.
+ if isinstance(ifaces, (list, tuple)):
+ for iface in ifaces:
+ if checkCommandResult(iface) is False:
+ Console().ePopen(("ifconfig " + iface + " down" ))
+ else:
+ if checkCommandResult(ifaces) is False:
+ Console().ePopen(("ifconfig " + ifaces + " down" ))
+
+ if self.deactivateInterfaceConsole:
+ if len(self.deactivateInterfaceConsole.appContainers) == 0:
+ if callback is not None:
+ callback(True)
+
+ def activateInterface(self,iface,callback = None):
+ if self.config_ready:
+ self.config_ready = False
+ self.msgPlugins()
+ if iface == 'eth0' and self.onRemoteRootFS():
+ if callback is not None:
+ callback(True)
+ return
+ if not self.activateInterfaceConsole:
+ self.activateInterfaceConsole = Console()
+ commands = []
+ commands.append("ifup " + iface)
+ self.activateInterfaceConsole.eBatch(commands, self.activateInterfaceFinished, callback, debug=True)
+
+ def activateInterfaceFinished(self,extra_args):
+ callback = extra_args
+ if self.activateInterfaceConsole:
+ if len(self.activateInterfaceConsole.appContainers) == 0:
+ if callback is not None:
+ callback(True)
+
+ def sysfsPath(self, iface):
+ return '/sys/class/net/' + iface
+
+ def isWirelessInterface(self, iface):
+ if iface in self.wlan_interfaces:
+ return True
+
+ if os_path.isdir(self.sysfsPath(iface) + '/wireless'):
+ return True
+
+ # r871x_usb_drv on kernel 2.6.12 is not identifiable over /sys/class/net/'ifacename'/wireless so look also inside /proc/net/wireless
+ device = re_compile('[a-z]{2,}[0-9]*:')
+ ifnames = []
+ fp = open('/proc/net/wireless', 'r')
+ for line in fp:
+ try:
+ ifnames.append(device.search(line).group()[:-1])
+ except AttributeError:
+ pass
+ if iface in ifnames:
+ return True
+
+ return False
+
+ def getWlanModuleDir(self, iface = None):
+ devicedir = self.sysfsPath(iface) + '/device'
+ moduledir = devicedir + '/driver/module'
+ if os_path.isdir(moduledir):
+ return moduledir
+
+ # identification is not possible over default moduledir
+ for x in listdir(devicedir):
+ # rt3070 on kernel 2.6.18 registers wireless devices as usb_device (e.g. 1-1.3:1.0) and identification is only possible over /sys/class/net/'ifacename'/device/1-xxx
+ if x.startswith("1-"):
+ moduledir = devicedir + '/' + x + '/driver/module'
+ if os_path.isdir(moduledir):
+ return moduledir
+ # rt73, zd1211b, r871x_usb_drv on kernel 2.6.12 can be identified over /sys/class/net/'ifacename'/device/driver, so look also here
+ moduledir = devicedir + '/driver'
+ if os_path.isdir(moduledir):
+ return moduledir
+
+ return None
+
+ def detectWlanModule(self, iface = None):
+ if not self.isWirelessInterface(iface):
+ return None
+
+ devicedir = self.sysfsPath(iface) + '/device'
+ if os_path.isdir(devicedir + '/ieee80211'):
+ return 'nl80211'
+
+ moduledir = self.getWlanModuleDir(iface)
+ if moduledir:
+ module = os_path.basename(os_path.realpath(moduledir))
+ if module in ('ath_pci','ath5k'):
+ return 'madwifi'
+ if module in ('rt73','rt73'):
+ return 'ralink'
+ if module == 'zd1211b':
+ return 'zydas'
+ return 'wext'
+
+ def calc_netmask(self,nmask):
+ from struct import pack, unpack
+ from socket import inet_ntoa, inet_aton
+ mask = 1L<<31
+ xnet = (1L<<32)-1
+ cidr_range = range(0, 32)
+ cidr = long(nmask)
+ if cidr not in cidr_range:
+ print 'cidr invalid: %d' % cidr
+ return None
+ else:
+ nm = ((1L<<cidr)-1)<<(32-cidr)
+ netmask = str(inet_ntoa(pack('>L', nm)))
+ return netmask