Beispiel #1
0
 def process_IN_DELETE(self, event):  # file be deleted
     if self.deleteFold:
         print "deleteFold delete"
         return False
     if not self.parsePath(event.pathname, 'delete'):
         if self.mode == 'safe':
             if not self.remove:
                 for path in self.path.split(','):
                     if path in event.pathname:
                         self.backup = backupFunc.backupAndRestore(path)
                         break
                 print "\033[0;31;40mDELETE event:%s  %s\033[0m" % (
                     event.pathname, datetime.datetime.now())
                 flag = self.backup.bakPathIsExist(event.pathname)
                 if flag == 'dictionary':
                     self.create = True
                     if not os.path.exists(event.pathname):
                         self.deleteFold = True
                         self.create = True
                         self.modify = True
                         self.backup.runResFold(event.pathname)
                         time.sleep(2)
                         self.create = False
                         self.modify = False
                         self.deleteFold = False
                 elif flag == 'file':
                     print "\033[0;31;40mYou can\'t delete %s,it has recovered!  %s\033[0m" % (
                         event.pathname, datetime.datetime.now())
                     content = self.backup.getDecompress(event.pathname)
                     self.create = True
                     self.modify = True
                     try:
                         with open(event.pathname, 'w') as file:
                             file.write(content)
                     except:
                         print "can't open %s" % (event.pathname)
                 else:
                     print "backup file %s is not exist,you can delete it!   %s" % (
                         event.pathname, datetime.datetime.now())
                 logging.info(
                     "\033[0;31;40m[HIGH][DEALED]DELETE event : %s  %s\033[0m"
                     % (os.path.join(event.path,
                                     event.name), datetime.datetime.now()))
             else:
                 self.remove = False
                 print "delete machine do"
         elif self.mode == 'human':
             print "\033[0;31;40mDELETE event:%s    %s\033[0m" % (
                 event.pathname, datetime.datetime.now())
             logging.info(
                 "\033[0;31;40m[HIGH]DELETE event : %s  %s\033[0m" %
                 (os.path.join(event.path,
                               event.name), datetime.datetime.now()))
     else:
         print "\033[0;31;40mDELETE event(white list):%s   %s\033[0m" % (
             event.pathname, datetime.datetime.now())
         logging.info(
             "\033[0;31;40m[HIGH][EXCPATH]DELETE event : %s  %s\033[0m" %
             (os.path.join(event.path,
                           event.name), datetime.datetime.now()))
Beispiel #2
0
    def process_IN_MODIFY(self, event):  # file be modified
        if self.deleteFold:
            return False
        if not self.parsePath(event.pathname, 'modify'):
            for path in self.path.split(','):
                if path in event.pathname:
                    self.backup = backupFunc.backupAndRestore(path)
                    break
            if self.mode == 'safe':
                if self.modify == True:
                    self.modify = False
                else:
                    print "\033[0;31;40mMODIFY event:%s   %s\033[0m" % (
                        event.pathname, datetime.datetime.now())

                    if self.backup.bakPathIsExist(event.pathname) == 'file':
                        print "\033[0;31;40mYou can\'t Modify %s,it has recovered!    %s\033[0m" % (
                            event.pathname, datetime.datetime.now())
                        content = self.backup.getDecompress(event.pathname)
                        self.create = True
                        self.modify = True
                        with open(event.pathname, 'w') as file:
                            file.write(content)
                logging.info(
                    "\033[0;31;40m[HIGH][DEALED]MODIFY event : %s  %s\033[0m" %
                    (os.path.join(event.path,
                                  event.name), datetime.datetime.now()))
            if self.mode == 'human':
                if not self.modify:
                    self.modify = True
                    print "\033[0;31;40mMODIFY event:%s   %s\033[0m" % (
                        event.pathname, datetime.datetime.now())
                    content = self.backup.getDecompress(event.pathname)
                    with open(event.pathname, 'r') as file:
                        compare = file.read()
                    diff_content = self.diff.run(content, compare)

                    with open('./diff.log', 'a') as file:
                        file.write(
                            "\033[0;31;40mFile %s had changed at %s\033[0m\n" %
                            (os.path.join(event.path, event.name),
                             datetime.datetime.now()))
                        file.write(diff_content)
                        file.write("\n\n\n")
                    logging.info(
                        "\033[0;31;40m[HIGH][LOG]MODIFY event : %s  %s\033[0m"
                        % (os.path.join(event.path,
                                        event.name), datetime.datetime.now()))
                else:
                    self.modify = False
                    print "modify machine do"
        else:
            print "\033[0;31;40mMODIFY event(white list):%s   %s\033[0m" % (
                event.pathname, datetime.datetime.now())
            logging.info(
                "\033[0;31;40m[HIGH][EXCPATH]MODIFY event : %s  %s\033[0m" %
                (os.path.join(event.path,
                              event.name), datetime.datetime.now()))
Beispiel #3
0
 def backup_func(self):
     print 'Backup file doing...'
     self.getSettings()
     if self.websitePath:
         # call backup function
         # backup end and save self.backup=True and save others
         webPath=self.websitePath.split(',')
         for path in webPath:
             self.backupFc=backupFunc.backupAndRestore(path)
             self.backupFc.runCompress()
         self.save("backup",'true')
         print 'Backup file done...'
     else:
         print "\033[0;31;40mWebsite file Path not give!\033[0m"
Beispiel #4
0
 def backup_func(self):
     print 'Backup file doing...'
     self.getSettings()
     if self.websitePath:
         # call backup function
         # backup end and save self.backup=True and save others
         webPath = self.websitePath.split(',')
         for path in webPath:
             self.backupFc = backupFunc.backupAndRestore(path)
             self.backupFc.runCompress()
         self.save("backup", 'true')
         print 'Backup file done...'
     else:
         print "\033[0;31;40mWebsite file Path not give!\033[0m"
Beispiel #5
0
    def process_IN_CREATE(self, event):  # file be created
        print "\033[0;31;40mCREATE event:%s    %s\033[0m" % (
            event.pathname, datetime.datetime.now())
        if self.deleteFold:
            print "deleteFold create"
            return False
        if not self.parsePath(event.pathname, 'create'):
            if self.mode == 'safe':

                if not self.create:
                    print "\033[0;31;40mCREATE event:%s   %s\033[0m" % (
                        event.pathname, datetime.datetime.now())
                    for path in self.path.split(','):
                        if path in event.pathname:
                            self.backup = backupFunc.backupAndRestore(path)
                            break
                    flag = self.backup.bakPathIsExist(event.pathname)
                    if flag == 'noexist':
                        print "\033[0;31;40mYou can\'t create %s,it has deleted!   %s\033[0m" % (
                            event.pathname, datetime.datetime.now())
                        self.remove = True
                        if os.path.isdir(event.pathname):
                            shutil.rmtree(event.pathname)
                        elif os.path.isfile(event.pathname):
                            os.remove(event.pathname)
                    logging.info(
                        "\033[0;31;40m[HIGH][DEALED]CREATE event : %s  %s\033[0m"
                        % (os.path.join(event.path,
                                        event.name), datetime.datetime.now()))
                else:
                    self.create = False
                    print "create machine do"
            elif self.mode == 'human':
                print "\033[0;31;40mCREATE event:%s\033[0m" % (event.pathname)
                logging.info(
                    "\033[0;31;40m[HIGH]CREATE event : %s  %s\033[0m" %
                    (os.path.join(event.path,
                                  event.name), datetime.datetime.now()))
        else:
            print "\033[0;31;40mCREATE event(white list):%s\033[0m" % (
                event.pathname)
            logging.info(
                "\033[0;31;40m[HIGH][EXCPATH]CREATE event : %s  %s\033[0m" %
                (os.path.join(event.path,
                              event.name), datetime.datetime.now()))
Beispiel #6
0
 def recover(self,path):
     print "recover %s:doing..." % (path)
     self.backupFc=backupFunc.backupAndRestore(path)
     self.backupFc.runDecompress()
     print "recover %s:done..." % (path)
Beispiel #7
0
 def recover(self, path):
     print "recover %s:doing..." % (path)
     self.backupFc = backupFunc.backupAndRestore(path)
     self.backupFc.runDecompress()
     print "recover %s:done..." % (path)