Esempio n. 1
0
    def startAll(self):
        """
            1. sync.api gets this computers ip address (ipv4)
            2. checks if it is a first start of script (if there is not a /var/log/tdgsync.log)
            3. cron calls with its defined interval, sync.api and sync.api checks if its ip changed.
            4. - if changed, it sends current ip address to a defined ftp server and sends a tweet
            5. and stores new ip address to /var/log/tdgsync.log, waits for another cron call
           

            This makes just a one http request to get ip address to minimize internet activity
        """
        myip = self.getIP()   
   
        if self.isFirstStart():#First start of the service checks whether there is a /var/log/tdgsync.log or not
            self.printLog(functions.fillString(self.startmessage,myip))
            self.printLog(self.aRandomMessage(myip))
            self.sendIPviaFTP(myip)
        else:
            if self.isIPChanged(myip):
                self.sendIPviaFTP(myip)
                self.printLog(functions.fillString(self.dynamicmessage,myip))
            else:
                pass

            if reader.getCallTimes(constants.LOGFILE)==self.limitTime: #this is for sending a random message 
                self.printLog(self.aRandomMessage(myip))
                reader.replaceEngine("calltimes","0",constants.LOGFILE)


        self.logIP(myip)
Esempio n. 2
0
    def sendIPviaFTP(self, ip):
        
        #making output
        htmldraft =reader.getHTMLString(self.configfile)
        output = cStringIO.StringIO(functions.fillString(htmldraft,ip))

        try:
            ftp = FTP(self.hostname,self.login,self.password)
            functions.ftpBrowse(ftp, self.filepath)
            ftp.storbinary('STOR %s' % self.filename.split("/")[-1], output)
            ftp.close()
            output.close()
        except:
            self.printLog("Error - FTP connection problem to the %s" % self.hostname)
            traceback.print_exc()
Esempio n. 3
0
 def aRandomMessage(self,ip):
     randomsentence = random.choice(reader.getSentencesLines(self.configfile))
     randomsentence = functions.fillString(randomsentence,ip)
     return randomsentence