Esempio n. 1
0
def main():
    try:
        args = vars(parse_config())
    except EnvironmentError as e:
        print(str(e))
        sys.exit(1)

    args['data_dir'] = os.path.expanduser(args['data_dir'])

    def check_with_encrypter(password):
        encrypter = make_encrypter(password)
        return check_password.check(args['data_dir'], encrypter, read_only=True)

    ss = Selfstats(os.path.join(args['data_dir'], cfg.DBNAME), args)

    if ss.need_text or ss.need_keys:
        if args['password'] is None:
            args['password'] = get_password(verify=check_with_encrypter)

        models.ENCRYPTER = make_encrypter(args['password'])

        if not check_password.check(args['data_dir'], models.ENCRYPTER, read_only=True):
            print('Password failed')
            sys.exit(1)

    ss.do()
Esempio n. 2
0
 def check_with_encrypter(password):
     encrypter = make_encrypter(password)
     return check_password.check(args['data_dir'], encrypter, read_only=True)
Esempio n. 3
0
def main():
    try:
        args = vars(parse_config())
    except EnvironmentError as e:
        print(str(e))
        sys.exit(1)

    log = set_logger(args)
    log.info("Starting Selfspy...")

    args['data_dir'] = os.path.expanduser(args['data_dir'])

    def check_with_encrypter(password):
        encrypter = make_encrypter(password)
        return check_password.check(args['data_dir'], encrypter)

    try:
        os.makedirs(args['data_dir'])
    except OSError:
        pass

    lockname = os.path.join(args['data_dir'], cfg.LOCK_FILE)
    cfg.LOCK = LockFile(lockname)
    if cfg.LOCK.is_locked():
        print('%s is locked! I am probably already running.' % lockname)
        print(
            'If you can find no selfspy process running, it is a stale lock and you can safely remove it.'
        )
        print('Shutting down.')
        sys.exit(1)

    if args['no_text']:
        args['password'] = ""

    if args['password'] is None:
        args['password'] = get_password(verify=check_with_encrypter)

    encrypter = make_encrypter(args['password'])

    if not check_password.check(args['data_dir'], encrypter):
        print('Password failed')
        sys.exit(1)

    if args['change_password']:
        new_password = get_password(message="New Password: ")
        new_encrypter = make_encrypter(new_password)
        print('Re-encrypting your keys...')
        astore = ActivityStore(os.path.join(args['data_dir'], cfg.DBNAME),
                               encrypter,
                               store_text=(not args['no_text']),
                               repeat_char=(not args['no_repeat']))
        astore.change_password(new_encrypter)
        # delete the old password.digest
        os.remove(os.path.join(args['data_dir'], check_password.DIGEST_NAME))
        check_password.check(args['data_dir'], new_encrypter)
        # don't assume we want the logger to run afterwards
        print('Exiting...')
        sys.exit(0)

    astore = ActivityStore(os.path.join(args['data_dir'], cfg.DBNAME),
                           encrypter,
                           store_text=(not args['no_text']),
                           repeat_char=(not args['no_repeat']))
    cfg.LOCK.acquire()
    try:
        astore.run()
    except SystemExit:
        astore.close()
    except KeyboardInterrupt:
        pass
    # In OS X this is has to be released in sniff_cocoa
    cfg.LOCK.release()