예제 #1
0
 def store_passwd(cls, email, passwd):
     """
     """
     passwd_file = '%s/%s.passwd' % (gmvault_utils.get_home_dir_path(), email)
 
     fdesc = open(passwd_file, "w+")
     
     cipher       = blowfish.Blowfish(cls.get_secret_key(cls.SECRET_FILEPATH % (gmvault_utils.get_home_dir_path())))
     cipher.initCTR()
 
     fdesc.write(cipher.encryptCTR(passwd))
 
     fdesc.close()
예제 #2
0
    def read_oauth_tok_sec(cls, email):
        """
           Read oauth token secret credential
           Look for the defined in env GMVAULT_DIR so by default to ~/.gmvault
           Look for file GMVAULT_DIR/email.oauth
        """
        gmv_dir = gmvault_utils.get_home_dir_path()
        
        #look for email.passwed in GMV_DIR
        user_oauth_file_path = "%s/%s.oauth" % (gmv_dir, email)

        token  = None
        secret = None
        if os.path.exists(user_oauth_file_path):
            LOG.critical("Use oauth credentials from %s." % (user_oauth_file_path))
            
            oauth_file  = open(user_oauth_file_path)
            
            try:
                token, secret = oauth_file.read().split('::')
            except Exception, err:
                LOG.error("Error when reading oauth info from %s" % (user_oauth_file_path))
                
                LOG.exception(err)
                
                LOG.critical("Cannot read oauth credentials from %s. Force oauth credentials renewal." % (user_oauth_file_path))
예제 #3
0
    def get_gmails_ids_left_to_restore(self, db_gmail_ids_info):
        """
           Get the ids that still needs to be restored
           Return a dict key = gm_id, val = directory
        """

        filepath = "%s/%s_%s" % (gmvault_utils.get_home_dir_path(), self.login, self.RESTORE_PROGRESS)

        if not os.path.exists(filepath):
            LOG.critical(
                "last_id restore file %s doesn't exist.\nRestore the full list of backed up emails." % (filepath)
            )
            return db_gmail_ids_info

        json_obj = json.load(open(filepath, "r"))

        last_id = json_obj["last_id"]

        last_id_index = -1
        try:
            keys = db_gmail_ids_info.keys()
            last_id_index = keys.index(last_id)
            LOG.critical("Restart from gmail id %s." % (last_id))
        except ValueError, _:
            # element not in keys return current set of keys
            LOG.error("Cannot restore from last restore gmail id. It is not in the disk database.")
예제 #4
0
    def get_gmails_ids_left_to_restore(self, db_gmail_ids_info):
        """
           Get the ids that still needs to be restored
           Return a dict key = gm_id, val = directory
        """

        filepath = '%s/%s_%s' % (gmvault_utils.get_home_dir_path(), self.login,
                                 self.RESTORE_PROGRESS)

        if not os.path.exists(filepath):
            LOG.critical(
                "last_id restore file %s doesn't exist.\nRestore the full list of backed up emails."
                % (filepath))
            return db_gmail_ids_info

        json_obj = json.load(open(filepath, 'r'))

        last_id = json_obj['last_id']

        last_id_index = -1
        try:
            keys = db_gmail_ids_info.keys()
            last_id_index = keys.index(last_id)
            LOG.critical("Restart from gmail id %s." % (last_id))
        except ValueError, _:
            #element not in keys return current set of keys
            LOG.error(
                "Cannot restore from last restore gmail id. It is not in the disk database."
            )
예제 #5
0
    def read_oauth_tok_sec(cls, email):
        """
           Read oauth token secret credential
           Look by default to ~/.gmvault
           Look for file ~/.gmvault/email.oauth
        """
        gmv_dir = gmvault_utils.get_home_dir_path()
        
        #look for email.passwed in GMV_DIR
        user_oauth_file_path = "%s/%s.oauth" % (gmv_dir, email)

        token  = None
        secret = None
        if os.path.exists(user_oauth_file_path):
            LOG.critical("Get XOAuth credential from %s.\n" % (user_oauth_file_path))
            
            oauth_file  = open(user_oauth_file_path)
            
            try:
                oauth_result = oauth_file.read()
                if oauth_result:
                    oauth_result = oauth_result.split('::')
                    if len(oauth_result) == 2:
                        token  = oauth_result[0]
                        secret = oauth_result[1]
            except Exception, _: #pylint: disable-msg=W0703              
                LOG.critical("Cannot read oauth credentials from %s. Force oauth credentials renewal." % (user_oauth_file_path))
                LOG.critical("=== Exception traceback ===")
                LOG.critical(gmvault_utils.get_exception_traceback())
                LOG.critical("=== End of Exception traceback ===\n")
예제 #6
0
파일: gmvault.py 프로젝트: ghewgill/gmvault
 def get_gmails_ids_left_to_sync(self, gmail_ids):
     """
        Get the ids that still needs to be sync
        Return a list of ids
     """
     
     filepath = '%s/%s_%s' % (gmvault_utils.get_home_dir_path(), self.login, self.SYNC_PROGRESS)
     
     if not os.path.exists(filepath):
         LOG.critical("last_id.sync file %s doesn't exist.\nSync the full list of backed up emails." %(filepath))
         return gmail_ids
     
     json_obj = json.load(open(filepath, 'r'))
     
     last_id = json_obj['last_id']
     
     last_id_index = -1
     
     new_gmail_ids = gmail_ids
     
     try:
         last_id_index = gmail_ids.index(last_id)
         LOG.critical("Restart from gmail id %s." % (last_id))
         new_gmail_ids = gmail_ids[last_id_index:]
     except ValueError, _:
         #element not in keys return current set of keys
         LOG.error("Cannot restore from last restore gmail id. It is not in Gmail. Sync the complete list of gmail ids requested from Gmail.")
예제 #7
0
 def get_gmails_ids_left_to_sync(self, imap_ids):
     """
        Get the ids that still needs to be sync
        Return a list of ids
     """
     
     filepath = '%s/%s_%s' % (gmvault_utils.get_home_dir_path(), self.login, self.SYNC_PROGRESS)
     
     if not os.path.exists(filepath):
         LOG.critical("last_id.sync file %s doesn't exist.\nSync the full list of backed up emails." %(filepath))
         return imap_ids
     
     json_obj = json.load(open(filepath, 'r'))
     
     last_id = json_obj['last_id']
     
     last_id_index = -1
     
     new_gmail_ids = imap_ids
     
     try:
         #get imap_id from stored gmail_id
         dummy = self.src.search({'type':'imap', 'req':'X-GM-MSGID %s' % (last_id)})
         
         imap_id = dummy[0]
         last_id_index = imap_ids.index(imap_id)
         LOG.critical("Restart from gmail id %s (imap id %s)." % (last_id, imap_id))
         new_gmail_ids = imap_ids[last_id_index:]   
     except Exception, _: #ignore any exception and try to get all ids in case of problems.
         #element not in keys return current set of keys
         LOG.critical("Error: Cannot restore from last restore gmail id. It is not in Gmail. Sync the complete list of gmail ids requested from Gmail.")
예제 #8
0
 def store_passwd(cls, email, passwd):
     """
        Encrypt and store gmail password
     """
     passwd_file = '%s/%s.passwd' % (gmvault_utils.get_home_dir_path(), email)
 
     fdesc = os.open(passwd_file, os.O_CREAT|os.O_WRONLY, 0600)
     
     cipher       = blowfish.Blowfish(cls.get_secret_key(cls.SECRET_FILEPATH % (gmvault_utils.get_home_dir_path())))
     cipher.initCTR()
 
     encrypted = cipher.encryptCTR(passwd)
     the_bytes = os.write(fdesc, encrypted)
 
     os.close(fdesc)
     
     if the_bytes < len(encrypted):
         raise Exception("Error: Cannot write password in %s" % (passwd_file))
예제 #9
0
    def save_lastid(self, op_type, gm_id):
        """
           Save the passed gmid in last_id.restore
           For the moment reopen the file every time
        """

        if op_type == self.OP_RESTORE:
            filepath = "%s/%s_%s" % (gmvault_utils.get_home_dir_path(), self.login, self.RESTORE_PROGRESS)
        elif op_type == self.OP_SYNC:
            filepath = "%s/%s_%s" % (gmvault_utils.get_home_dir_path(), self.login, self.SYNC_PROGRESS)
        else:
            raise Exception(
                "Bad Operation in save_restore_last_id. This should not happen, send the error to the software developers."
            )

        fd = open(filepath, "w")

        json.dump({"last_id": gm_id}, fd)

        fd.close()
예제 #10
0
 def store_oauth_credentials(cls, email, token, secret):
     """
     """
     oauth_file = '%s/%s.oauth' % (gmvault_utils.get_home_dir_path(), email)
 
     fdesc = open(oauth_file, "w+")
     
     fdesc.write(token)
     fdesc.write('::')
     fdesc.write(secret)
 
     fdesc.close()
예제 #11
0
 def store_oauth_credentials(cls, email, token, secret):
     """
     """
     oauth_file = '%s/%s.oauth' % (gmvault_utils.get_home_dir_path(), email)
 
     fdesc = os.open(oauth_file, os.O_CREAT|os.O_WRONLY, 0600)
     
     os.write(fdesc, token)
     os.write(fdesc, '::')
     os.write(fdesc, secret)
 
     os.close(fdesc)
예제 #12
0
    def save_restore_lastid(self, gm_id):
        """
           Save the passed gmid in last_id.restore
           For the moment reopen the file every time
        """
        filepath = '%s/%s_%s' % (gmvault_utils.get_home_dir_path(), self.login,
                                 self.RESTORE_PROGRESS)
        fd = open(filepath, 'w')

        json.dump({'last_id': gm_id}, fd)

        fd.close()
예제 #13
0
파일: gmvault.py 프로젝트: JennYung/gmvault
 def save_restore_lastid(self, gm_id):
     """
        Save the passed gmid in last_id.restore
        For the moment reopen the file every time
     """
     filepath = '%s/%s_%s' % (gmvault_utils.get_home_dir_path(), self.login, self.RESTORE_PROGRESS)
     fd = open(filepath, 'w')
     
     json.dump({
                 'last_id' : gm_id  
               }, fd)
     
     fd.close()
예제 #14
0
 def store_oauth_credentials(cls, email, token, secret):
     """
        store oauth_credentials
     """
     oauth_file = '%s/%s.oauth' % (gmvault_utils.get_home_dir_path(), email)
 
     fdesc = os.open(oauth_file, os.O_CREAT|os.O_WRONLY, 0600)
     
     os.write(fdesc, token)
     os.write(fdesc, '::')
     os.write(fdesc, secret)
 
     os.close(fdesc)
예제 #15
0
 def get_secret(cls):
     """
        Get a secret from secret file or generate it
        TO BE REMOVED
     """
     secret_file_path = cls.SECRET_FILEPATH % (gmvault_utils.get_home_dir_path())
     if os.path.exists(secret_file_path):
         secret = open(secret_file_path).read()
     else:
         secret = gmvault_utils.make_password()
         fdesc = open(secret_file_path, 'w+')
         fdesc.write(secret)
         fdesc.close()
     
     return secret
예제 #16
0
    def read_password(cls, email):
        """
           Read password credentials
           Look by default to ~/.gmvault
           Look for file ~/.gmvault/email.passwd
        """
        gmv_dir = gmvault_utils.get_home_dir_path()
        
        #look for email.passwed in GMV_DIR
        user_passwd_file_path = "%s/%s.passwd" % (gmv_dir, email)

        password = None
        if os.path.exists(user_passwd_file_path):
            passwd_file  = open(user_passwd_file_path)
            
            password     = passwd_file.read()
            cipher       = blowfish.Blowfish(cls.get_secret_key(cls.SECRET_FILEPATH % (gmvault_utils.get_home_dir_path())))
            cipher.initCTR()
            password     = cipher.decryptCTR(password)

            #LOG.debug("password=[%s]" % (password))
        
        return password
예제 #17
0
    def read_password(cls, email):
        """
           Read password credentials
           Look for the defined in env GMVAULT_DIR so by default to ~/.gmvault
           Look for file GMVAULT_DIR/email.passwd
        """
        gmv_dir = gmvault_utils.get_home_dir_path()
        
        #look for email.passwed in GMV_DIR
        user_passwd_file_path = "%s/%s.passwd" % (gmv_dir, email)

        password = None
        if os.path.exists(user_passwd_file_path):
            passwd_file  = open(user_passwd_file_path)
            
            password     = passwd_file.read()
            cipher       = blowfish.Blowfish(cls.get_secret_key(cls.SECRET_FILEPATH % (gmvault_utils.get_home_dir_path())))
            cipher.initCTR()
            password     = cipher.decryptCTR(password)

            #LOG.debug("password=[%s]" % (password))
        
        return password