コード例 #1
0
ファイル: plugin.py プロジェクト: takitr/enigma2-plugins
def NASpowerdown(Nname, Nuser, Npass, Ncommand, Nport):
    from telnetlib import Telnet
    if Nname == "":
        return _("no Name")
    l = _("Connection Error")
    try:
        tn = Telnet(Nname, Nport, 5)
        l = ""
        if Nuser != "":
            l = l + tn.expect(['ogin:', 'sername'], 10)[2]
            l = l + tn.read_very_lazy()
            tn.write('%s\r' % Nuser)
        if Npass != "":
            l = l + tn.read_until('assword:', 10)
            l = l + tn.read_very_lazy()
            tn.write('%s\r' % Npass)
        l = l + tn.expect(['#', ">"], 10)[2]
        l = l + tn.read_very_lazy()
        tn.write('%s\r' % Ncommand)
        l = l + tn.expect(['#', ">"], 20)[2]
        l = l + tn.read_very_lazy()
        if config.plugins.elektro.NASwait.value == True:
            tt = time() + 90
            l = l + "\n waiting...\n"
            while tt > time() and ping.doOne(Nname, 1) != None:
                sleep(2)
        tn.write('exit\r')
        l = l + tn.expect(['#', ">"], 5)[2]
        l = l + tn.read_very_lazy()
        tn.close()
    finally:
        return l
コード例 #2
0
def NASpowerdown(Nname,Nuser,Npass,Ncommand,Nport):
	from telnetlib import Telnet
	if Nname == "":
		return _("no Name")
	l=_("Connection Error")
	try:
		tn = Telnet(Nname, Nport, 5)
		l=""
		if Nuser != "":
			l = l + tn.expect(['ogin:','sername'],10)[2]
			l = l + tn.read_very_lazy()
			tn.write('%s\r' % Nuser)
		if Npass != "":
			l = l + tn.read_until('assword:',10)
			l = l + tn.read_very_lazy()
			tn.write('%s\r' % Npass)
		l = l + tn.expect(['#',">"],10)[2]
		l = l + tn.read_very_lazy()
		tn.write('%s\r' % Ncommand)
		l = l + tn.expect(['#',">"],20)[2]
		l = l + tn.read_very_lazy()
		if config.plugins.elektro.NASwait.value == True:
			tt = time() + 90
			l = l + "\n waiting...\n"
			while tt>time() and ping.doOne(Nname,1) != None:
				sleep(2)
		tn.write('exit\r')
		l = l + tn.expect(['#',">"],5)[2]
		l = l + tn.read_very_lazy()
		tn.close()
	finally:
		return l
コード例 #3
0
	def getInternetAvailable(self):
		import ping
		r = ping.doOne("8.8.8.8",1.5)
		if r != None and r <= 1.5:
			return True
		else:
			return False
コード例 #4
0
ファイル: Check.py プロジェクト: djhavoc/SSS
 def icmp_c(self, serviceID, ip):
     print 'icmp'
     socket.setdefaulttimeout(2)
     delay = ping.doOne(ip, timeout=3)
     if delay >= 0.0:
         self.recordResult('good', serviceID)
     else:
         error_msg = "No Response from Target"
         self.recordResult('bad', serviceID, error_msg)
コード例 #5
0
ファイル: Check.py プロジェクト: djhavoc/SSS
 def ipsec(self, serviceID, ipsec_gateway, ipsec_group, ipsec_secret, ipsec_user, ipsec_pass, ipsec_target_host_ip):
     '''check ipsec tunnel'''
     print 'ipsec'
     socket.setdefaulttimeout(2)
     ## establish vpn tunnel
     try:
         vpncShell = pexpect.spawn('/sbin/vpnc')
         vpncShell.logfile = sys.stdout
         vpncShell.expect('Enter IPSec gateway address:')
         vpncShell.sendline(ipsec_gateway)        
         vpncShell.expect('Enter IPSec ID for %s:' %(ipsec_gateway))
         vpncShell.sendline(ipsec_group)
         vpncShell.expect('Enter IPSec secret for %s@%s:' % (ipsec_group, ipsec_gateway))
         vpncShell.sendline(ipsec_secret)
         vpncShell.expect('Enter username for %s:' % (ipsec_gateway))
         vpncShell.sendline(ipsec_user)
         vpncShell.expect('Enter password for %s@%s:' % (ipsec_user, ipsec_gateway))
         vpncShell.sendline(ipsec_pass)
         vpncShell.expect('VPNC started in background')
         self.recordResult('good', serviceID)
     except:
         self.recordResult('bad', serviceID)
     time.sleep(1)
     pexpect.run('/sbin/route add -host %s dev tun0' % (ipsec_target_host_ip))
     
     print pexpect.run('/bin/netstat -r')
     try:
         delay = ping.doOne(ipsec_target_host_ip, timeout=2)
         #print 'DELAY: %s' % (delay)
         if delay >= 0.0:
             self.recordResultSecondary('good', serviceID)
         else:
             self.recordResultSecondary('bad', serviceID)
     except socket.error, e:
         #print "Ping Error:", e
         self.recordResultSecondary('bad', serviceID)
コード例 #6
0
	def CheckElektro(self):
		# first set the next wakeuptime - it would be much better to call that function on sleep. This will be a todo!
		self.setNextWakeuptime()

		#convert to seconds
		time_s = self.getTime()
		ltime = localtime()
		if config.plugins.elektro.profile.value == "1":
			config_wakeup = config.plugins.elektro.wakeup
			config_sleep = config.plugins.elektro.sleep
			config_nextday = config.plugins.elektro.nextday
		else:
			config_wakeup = config.plugins.elektro.wakeup2
			config_sleep = config.plugins.elektro.sleep2
			config_nextday = config.plugins.elektro.nextday2

		#Which day is it? The next day starts at nextday
		if debug:
			print pluginPrintname, "wday 1:", str(ltime.tm_wday)
		if time_s < self.clkToTime(config_nextday):
			day = (ltime.tm_wday - 1) % 7
		else:
			day = ltime.tm_wday
		if debug:
			print pluginPrintname, "wday 2:", str(day)

		#Let's get the day
		wakeuptime = self.clkToTime(config_wakeup[day])
		sleeptime = self.clkToTime(config_sleep[day])

		print pluginPrintname, "Profile:", config.plugins.elektro.profile.value
		print pluginPrintname, "Nextday:", self.getPrintTime(self.clkToTime(config.plugins.elektro.nextday))
		print pluginPrintname, "Current time:", self.getPrintTime(time_s)
		print pluginPrintname, "Wakeup time:", self.getPrintTime(wakeuptime)
		print pluginPrintname, "Sleep time:", self.getPrintTime(sleeptime)

		#convert into relative Times
		time_s = self.getReltime(time_s)
		wakeuptime  = self.getReltime(wakeuptime)
		sleeptime = self.getReltime(sleeptime)

		if debug:
			print pluginPrintname, "Current Rel-time:", self.getPrintTime(time_s)
			print pluginPrintname, "Wakeup Rel-time:", self.getPrintTime(wakeuptime)
			print pluginPrintname, "Sleep Rel-time:", self.getPrintTime(sleeptime)


		#let's see if we should be sleeping
		trysleep = False
		if time_s < (wakeuptime - elektroShutdownThreshold): # Wakeup is in the future -> sleep!
			trysleep = True
			print pluginPrintname, "Wakeup!", str(time_s), " <", str(wakeuptime)
		if sleeptime < time_s : #Sleep is in the past -> sleep!
			trysleep = True
			print pluginPrintname, "Sleep:", str(sleeptime), " <", str(time_s)

		#We are not tying to go to sleep anymore -> maybe go to sleep again the next time
		if trysleep == False:
			self.dontsleep = False

		#The User aborted to got to sleep -> Don't go to sleep.
		if self.dontsleep:
			trysleep = False

		# If we are in holydaymode we should try to got to sleep anyway
		# This should be set after self.dontsleep has been handled
		if config.plugins.elektro.holiday.value:
			trysleep = True

		# We are not enabled -> Dont go to sleep (This could have been catched earlier!)
		if config.plugins.elektro.enable.value == False:
			trysleep = False

		# Only go to sleep if we are in standby or sleep is forced by settings
		if  not ((Standby.inStandby) or (config.plugins.elektro.force.value == True) ):
			trysleep = False

		# No Sleep while recording
		if self.session.nav.RecordTimer.isRecording():
			trysleep = False

		# No Sleep on Online IPs - joergm6
		if trysleep == True and config.plugins.elektro.IPenable.value == True:
			for i in range(10):
				ip = "%d.%d.%d.%d" % tuple(config.plugins.elektro.ip[i].value)
				if ip != "0.0.0.0":
					if ping.doOne(ip,0.1) != None:
						print pluginPrintname, ip, "online"
						trysleep = False
						break

		# No Sleep on HDD running - joergm6
		if (config.plugins.elektro.hddsleep.value == True) and (harddiskmanager.HDDCount() > 0):
			hddlist = harddiskmanager.HDDList()
			if hddlist[0][1].model().startswith("ATA"):
				if not hddlist[0][1].isSleeping():
					trysleep = False

		# Will there be a recording in a short while?
		nextRecTime = self.session.nav.RecordTimer.getNextRecordingTime()
		if  (nextRecTime > 0) and (nextRecTime - (int)(time()) <  elektroShutdownThreshold):
			trysleep = False

		# Looks like there really is a reason to go to sleep -> Lets try it!
		if trysleep:
			#self.();
			try:
				self.session.openWithCallback(self.DoElektroSleep, MessageBox, _("Go to sleep now?"),type = MessageBox.TYPE_YESNO,timeout = 60)
			except:
				#reset the timer and try again
				self.TimerSleep.startLongTimer(elektrostarttime)

		#set Timer, which calls this function again.
		self.TimerSleep.startLongTimer(elektrostarttime)
コード例 #7
0
ファイル: plugin.py プロジェクト: takitr/enigma2-plugins
    def CheckElektro(self):
        # first set the next wakeuptime - it would be much better to call that function on sleep. This will be a todo!
        self.setNextWakeuptime()

        #convert to seconds
        time_s = self.getTime()
        ltime = localtime()
        if config.plugins.elektro.profile.value == "1":
            config_wakeup = config.plugins.elektro.wakeup
            config_sleep = config.plugins.elektro.sleep
            config_nextday = config.plugins.elektro.nextday
        else:
            config_wakeup = config.plugins.elektro.wakeup2
            config_sleep = config.plugins.elektro.sleep2
            config_nextday = config.plugins.elektro.nextday2

        #Which day is it? The next day starts at nextday
        if debug:
            print pluginPrintname, "wday 1:", str(ltime.tm_wday)
        if time_s < self.clkToTime(config_nextday):
            day = (ltime.tm_wday - 1) % 7
        else:
            day = ltime.tm_wday
        if debug:
            print pluginPrintname, "wday 2:", str(day)

        #Let's get the day
        wakeuptime = self.clkToTime(config_wakeup[day])
        sleeptime = self.clkToTime(config_sleep[day])

        print pluginPrintname, "Profile:", config.plugins.elektro.profile.value
        print pluginPrintname, "Nextday:", self.getPrintTime(
            self.clkToTime(config.plugins.elektro.nextday))
        print pluginPrintname, "Current time:", self.getPrintTime(time_s)
        print pluginPrintname, "Wakeup time:", self.getPrintTime(wakeuptime)
        print pluginPrintname, "Sleep time:", self.getPrintTime(sleeptime)

        #convert into relative Times
        time_s = self.getReltime(time_s)
        wakeuptime = self.getReltime(wakeuptime)
        sleeptime = self.getReltime(sleeptime)

        if debug:
            print pluginPrintname, "Current Rel-time:", self.getPrintTime(
                time_s)
            print pluginPrintname, "Wakeup Rel-time:", self.getPrintTime(
                wakeuptime)
            print pluginPrintname, "Sleep Rel-time:", self.getPrintTime(
                sleeptime)

        #let's see if we should be sleeping
        trysleep = False
        if time_s < (wakeuptime - elektroShutdownThreshold
                     ):  # Wakeup is in the future -> sleep!
            trysleep = True
            print pluginPrintname, "Wakeup!", str(time_s), " <", str(
                wakeuptime)
        if sleeptime < time_s:  #Sleep is in the past -> sleep!
            trysleep = True
            print pluginPrintname, "Sleep:", str(sleeptime), " <", str(time_s)

        #We are not tying to go to sleep anymore -> maybe go to sleep again the next time
        if trysleep == False:
            self.dontsleep = False

        #The User aborted to got to sleep -> Don't go to sleep.
        if self.dontsleep:
            trysleep = False

        # If we are in holydaymode we should try to got to sleep anyway
        # This should be set after self.dontsleep has been handled
        if config.plugins.elektro.holiday.value:
            trysleep = True

        # We are not enabled -> Dont go to sleep (This could have been catched earlier!)
        if config.plugins.elektro.enable.value == False:
            trysleep = False

        # Only go to sleep if we are in standby or sleep is forced by settings
        if not ((Standby.inStandby) or
                (config.plugins.elektro.force.value == True)):
            trysleep = False

        # No Sleep while recording
        if self.session.nav.RecordTimer.isRecording():
            trysleep = False

        # No Sleep on Online IPs - joergm6
        if trysleep == True and config.plugins.elektro.IPenable.value == True:
            for i in range(10):
                ip = "%d.%d.%d.%d" % tuple(config.plugins.elektro.ip[i].value)
                if ip != "0.0.0.0":
                    if ping.doOne(ip, 0.1) != None:
                        print pluginPrintname, ip, "online"
                        trysleep = False
                        break

        # No Sleep on HDD running - joergm6
        if (config.plugins.elektro.hddsleep.value
                == True) and (harddiskmanager.HDDCount() > 0):
            hddlist = harddiskmanager.HDDList()
            if hddlist[0][1].model().startswith("ATA"):
                if not hddlist[0][1].isSleeping():
                    trysleep = False

        # Will there be a recording in a short while?
        nextRecTime = self.session.nav.RecordTimer.getNextRecordingTime()
        if (nextRecTime > 0) and (nextRecTime -
                                  (int)(time()) < elektroShutdownThreshold):
            trysleep = False

        # Looks like there really is a reason to go to sleep -> Lets try it!
        if trysleep:
            #self.();
            try:
                self.session.openWithCallback(self.DoElektroSleep,
                                              MessageBox,
                                              _("Go to sleep now?"),
                                              type=MessageBox.TYPE_YESNO,
                                              timeout=60)
            except:
                #reset the timer and try again
                self.TimerSleep.startLongTimer(elektrostarttime)

        #set Timer, which calls this function again.
        self.TimerSleep.startLongTimer(elektrostarttime)
コード例 #8
0
	def CheckElektro(self):
		# first set the next wakeuptime - it would be much better to call that function on sleep. This will be a todo!
		self.setNextWakeuptime()

		#convert to seconds
		time_s = self.getTime()
		ltime = localtime()
		if config.plugins.elektro.profile.value == "1":
			config_wakeup = config.plugins.elektro.wakeup
			config_sleep = config.plugins.elektro.sleep
			config_nextday = config.plugins.elektro.nextday
		else:
			config_wakeup = config.plugins.elektro.wakeup2
			config_sleep = config.plugins.elektro.sleep2
			config_nextday = config.plugins.elektro.nextday2

		#Which day is it? The next day starts at nextday
		if debug:
			print pluginPrintname, "wday 1:", str(ltime.tm_wday)
		if time_s < self.clkToTime(config_nextday):
			day = (ltime.tm_wday - 1) % 7
		else:
			day = ltime.tm_wday
		if debug:
			print pluginPrintname, "wday 2:", str(day)

		#Let's get the day
		wakeuptime = lwakeuptime = self.clkToTime(config_wakeup[day])
		sleeptime = lsleeptime = self.clkToTime(config_sleep[day])
		ltime_s = time_s

		print pluginPrintname, "Profile:", config.plugins.elektro.profile.value
		print pluginPrintname, "Nextday:", self.getPrintTime(self.clkToTime(config.plugins.elektro.nextday))
		print pluginPrintname, "Current time:", self.getPrintTime(time_s)
		print pluginPrintname, "Wakeup time:", self.getPrintTime(wakeuptime)
		print pluginPrintname, "Sleep time:", self.getPrintTime(sleeptime)

		#convert into relative Times
		time_s = self.getReltime(time_s)
		wakeuptime  = self.getReltime(wakeuptime)
		sleeptime = self.getReltime(sleeptime)

		if debug:
			print pluginPrintname, "Current Rel-time:", self.getPrintTime(time_s)
			print pluginPrintname, "Wakeup Rel-time:", self.getPrintTime(wakeuptime)
			print pluginPrintname, "Sleep Rel-time:", self.getPrintTime(sleeptime)

		#let's see if we should be sleeping
		trysleep = False
		if time_s < (wakeuptime - elektroShutdownThreshold): # Wakeup is in the future -> sleep!
			trysleep = True
			print pluginPrintname, "Wakeup!", self.getPrintTime(ltime_s), " <", self.getPrintTime(lwakeuptime)
		if sleeptime < time_s : #Sleep is in the past -> sleep!
			trysleep = True
			print pluginPrintname, "try Sleep:", self.getPrintTime(lsleeptime), " <", self.getPrintTime(ltime_s)

		#We are not tying to go to sleep anymore -> maybe go to sleep again the next time
		if trysleep == False:
			print pluginPrintname, "don't try sleep -> maybe go to sleep again the next time"
			self.dontsleep = False

		#The User aborted to got to sleep -> Don't go to sleep.
		if self.dontsleep:
			print pluginPrintname, "don't sleep - User aborted to got to sleep"
			trysleep = False

		# If we are in holydaymode we should try to got to sleep anyway
		# This should be set after self.dontsleep has been handled
		if config.plugins.elektro.holiday.value:
			print pluginPrintname, "sleep - we are in holiday mode"
			trysleep = True

		# We are not enabled -> Dont go to sleep (This could have been catched earlier!)
		if config.plugins.elektro.enable.value == False:
			print pluginPrintname, "don't sleep - Elektro not activated"
			trysleep = False

		# Only go to sleep if we are in standby or sleep is forced by settings
		if trysleep == True and not ((Standby.inStandby) or (config.plugins.elektro.force.value == True)):
			print pluginPrintname, "don't sleep - not in standby or sleep not forced by settings"
			trysleep = False

		# wakeuptime coming up in a short while - Sven H
		# avoid deepstandby on recordtimer-end with auto-afterevent, if wakeuptime after recordstart
		if wakeuptime > 0 and (wakeuptime - time_s) < elektroShutdownThreshold and NavigationInstance.instance.wasTimerWakeup() and Screens.Standby.inStandby and config.misc.standbyCounter.value == 1 and config.misc.isNextRecordTimerAfterEventActionAuto.value:
			print pluginPrintname, "wakeuptime coming up in a short while: set isNextRecordTimerAfterEventActionAuto to False"
			config.misc.isNextRecordTimerAfterEventActionAuto.value = False

		# No Sleep while recording
		if trysleep == True and self.session.nav.RecordTimer.isRecording():
			print pluginPrintname, "don't sleep - current recording"
			trysleep = False

		# No Sleep on Online IPs - joergm6
		if trysleep == True and config.plugins.elektro.IPenable.value == True:
			for i in range(10):
				ip = "%d.%d.%d.%d" % tuple(config.plugins.elektro.ip[i].value)
				if ip != "0.0.0.0":
					if ping.doOne(ip,0.1) != None:
						print pluginPrintname, "don't sleep - ip online:", ip
						trysleep = False
						break

		# No Sleep on HDD running
		if trysleep == True and (config.plugins.elektro.hddsleep.value == True) and (harddiskmanager.HDDCount() > 0):
			hddlist = harddiskmanager.HDDList()
			#new code by Sven H
			for hdd in hddlist:
				#print "[Elektro] ", hdd[0], hdd[1].bus_description(), hdd[1].isSleeping()
				if hdd[1].bus_description() == "SATA" and not hdd[1].isSleeping():
					print pluginPrintname, "don't sleep - HDD is active:", hdd[0]
					trysleep = False
			#old code by joergm6
			#if hddlist[0][1].model().startswith("ATA"):
			#	if not hddlist[0][1].isSleeping():
			#		print pluginPrintname, "HDD is active"
			#		trysleep = False

		# No Sleep on network activity - betonme
		if trysleep == True and (config.plugins.elektro.netsleep.value == True) and (harddiskmanager.HDDCount() > 0):
			with open("/proc/net/tcp", 'r') as f:
				lines = f.readlines()
				lines.pop(0)
				for line in lines:
					content = line.split()
					if content[3] == "01":
						# Connection established
						print pluginPrintname, "don't sleep - tcp-Connection established"
						trysleep = False
						break
			with open("/proc/net/udp", 'r') as f:
				lines = f.readlines()
				lines.pop(0)
				for line in lines:
					content = line.split()
					if content[3] == "01":
						# Connection established
						print pluginPrintname, "don't sleep - udp-Connection established"
						trysleep = False
						break

		# No Sleep on nfs-read activity - Sven H
		if trysleep == True and (config.plugins.elektro.nfssleep.value == True):
			with open("/proc/net/rpc/nfsd", 'r') as f:
				lines = f.readlines()
				for line in lines:
					content = line.split()
					if content[0] == "io":
						current_nfsread = content[1]
						#print pluginPrintname, "nfs-read activity - last, current", self.last_nfsread, current_nfsread
						if (current_nfsread != self.last_nfsread):
							print pluginPrintname, "don't sleep because current nfs-read activity"
							trysleep = False
						self.last_nfsread = current_nfsread
						break

		# Will there be a recording in a short while?
		nextRecTime = self.session.nav.RecordTimer.getNextRecordingTime()
		if trysleep == True and (nextRecTime > 0) and (nextRecTime - (int)(time()) <  elektroShutdownThreshold):
			print pluginPrintname, "don't sleep - there be a recording in a short while"
			trysleep = False

		# Looks like there really is a reason to go to sleep -> Lets try it!
		if trysleep:
			#self.();
			try:
				self.session.openWithCallback(self.DoElektroSleep, MessageBox, _("Go to sleep now?"),type = MessageBox.TYPE_YESNO,timeout = 60)
			except:
				#reset the timer and try again
				self.TimerSleep.startLongTimer(elektrostarttime)

		#set Timer, which calls this function again.
		self.TimerSleep.startLongTimer(elektrostarttime)