示例#1
0
文件: api.py 项目: m-wells/Commander
def add_record(params):
    """ Create a new record with passed-in data or interactively.
        The shared folder UID is also optional 
    """
    record = Record()
    if not record.title:
        while not record.title:
            record.title = input("... Title (req'd): ")
        record.folder = input("... Folder: ")
        record.login = input("... Login: "******"... Password: "******"... Login URL: ")
        record.notes = input("... Notes: ")
        while True:
            custom_dict = {}
            custom_dict['name'] = input("... Custom Field Name : ") 
            if not custom_dict['name']:
                break

            custom_dict['value'] = input("... Custom Field Value : ") 
            custom_dict['type'] = 'text' 
            record.custom_fields.append(custom_dict)

    new_record = prepare_record(params, record)
    request = make_request(params, 'record_update')
    request['add_records'] = [new_record]

    response_json = communicate(params, request)

    if response_json['result'] == 'success':
        new_revision = 0
        if 'add_records' in response_json:
            for info in response_json['add_records']:
                if info['record_uid'] == record.record_uid:
                    if info['status'] == 'success':
                        # all records in the transaction get the
                        # same revision.  this just checks 100% success
                        new_revision = response_json['revision']

        if new_revision == 0:
            print('Error: Revision not updated')
            return False

        if new_revision == new_record['revision']:
            print('Error: Revision did not change')
            return False

        print('New record successful for record_uid=' + \
            str(new_record['record_uid']) + ', revision=' + \
            str(new_record['revision']), ', new_revision=' + \
            str(new_revision))

        new_record['revision'] = new_revision

        # sync down the data which updates the caches
        sync_down(params)

        return True
示例#2
0
def parse_record_json(json):
    record = Record()
    record.folder = json['folder']
    record.title = json['title']
    record.login = json['login']
    record.password = json['password']
    record.login_url = json['login_url']
    record.notes = json['notes']
    record.custom_fields = json['custom_fields']
    return record
示例#3
0
def parse_json(json):
    record = Record()
    record.folder = json['folder']
    record.title = json['title']
    record.login = json['login']
    record.password = json['password']
    record.login_url = json['login_url']
    record.notes = json['notes']
    record.custom_fields = json['custom_fields']
    return record
示例#4
0
def parse_line(line):
    fields = line.split('\t')
    record = Record()
    record.folder = fields[0]
    record.title = fields[1]
    record.login = fields[2]
    record.password = fields[3]
    record.login_url = fields[4]
    record.notes = fields[5].replace('\\\\n', '\n')
    record.custom_fields = [{'name': fields[i], 'value': fields[i + 1], 'type': 'text'} for i in
                            range(6, len(fields) - 1, 2)]
    return record
示例#5
0
def parse_line(line):
    fields = line.split('\t')
    record = Record()
    record.folder = fields[0]
    record.title = fields[1]
    record.login = fields[2]
    record.password = fields[3]
    record.login_url = fields[4]
    record.notes = fields[5].replace('\\\\n', '\n')
    record.custom_fields = [{'name': fields[i], 'value': fields[i + 1], 'type': 'text'} for i in
                            range(6, len(fields) - 1, 2)]
    return record
示例#6
0
def sample_record():
    record = Record()
    record.folder = "folder"
    record.title = "title"
    record.login = "******"
    record.password = "******"
    record.login_url = "login_url"
    record.notes = "line1\nline2\nline3"
    record.custom_fields = [
        {"name": "cf1", "value": "cf1val", "type": "text"},
        {"name": "cf2", "value": "cf2val", "type": "text"},
    ]
    return record
示例#7
0
def sample_record():
    record = Record()
    record.folder = 'folder'
    record.title = 'title'
    record.login = '******'
    record.password = '******'
    record.login_url = 'login_url'
    record.notes = 'line1\nline2\nline3'
    record.custom_fields = [{
        'name': 'cf1',
        'value': 'cf1val',
        'type': 'text'
    }, {
        'name': 'cf2',
        'value': 'cf2val',
        'type': 'text'
    }]
    return record
示例#8
0
from keepercommander.record import Record
from keepercommander.params import KeeperParams
from keepercommander import display, api

my_params = KeeperParams()

while not my_params.user:
    my_params.user = getpass.getpass(prompt='User(Email): ', stream=None)

while not my_params.password:
    my_params.password = getpass.getpass(prompt='Master Password: '******'Test Record'
r.login = '******'

# generate a 32-char random password
r.password = ''.join(random.SystemRandom().choice(string.printable) for _ in range(32)) 

if api.add_record(my_params, r):
    print('Added record UID='+r.record_uid) 

# Delete the record 
if r.record_uid:
    api.delete_record(my_params, r.record_uid)


示例#9
0
def do_command(params):
    if (params.command == 'q'):
        return False

    elif (params.command == 'l'):
        if (len(params.record_cache) == 0):
            print('No records')
        else:
            results = api.search_records(params, '')
            display.formatted_records(results)

    elif (params.command == 'lsf'):
        if (len(params.shared_folder_cache) == 0):
            print('No shared folders')
        else:
            results = api.search_shared_folders(params, '')
            display.formatted_shared_folders(results)

    elif (params.command == 'lt'):
        if (len(params.team_cache) == 0):
            print('No teams')
        else:
            results = api.search_teams(params, '')
            display.formatted_teams(results)

    elif (params.command[:2] == 'g '):
        if (api.is_shared_folder(params, params.command[2:])):
            sf = api.get_shared_folder(params, params.command[2:])
            if sf:
                sf.display()
        elif (api.is_team(params, params.command[2:])):
            team = api.get_team(params, params.command[2:])
            if team:
                team.display()
        else:
            r = api.get_record(params, params.command[2:])
            if r:
                r.display()

    elif (params.command[:2] == 'r '):
        api.rotate_password(params, params.command[2:])

    elif (params.command[:2] == 'd '):
        api.delete_record(params, params.command[2:])

    elif (params.command == 'c'):
        print(chr(27) + "[2J")

    elif (params.command[:2] == 's '):
        results = api.search_records(params, params.command[2:])
        display.formatted_records(results)

    elif (params.command[:2] == 'b '):
        results = api.search_records(params, params.command[2:])
        for r in results:
            api.rotate_password(params, r.record_uid)

    elif (params.command[:3] == 'an '):
        api.append_notes(params, params.command[3:])

    elif (params.command == 'd'):
        api.sync_down(params)

    elif (params.command == 'a'):
        record = Record()
        while not record.title:
            record.title = input("... Title (req'd): ")
        record.folder = input("... Folder: ")
        record.login = input("... Login: "******"... Password: "******"... Login URL: ")
        record.notes = input("... Notes: ")
        while True:
            custom_dict = {}
            custom_dict['name'] = input("... Custom Field Name : ")
            if not custom_dict['name']:
                break

            custom_dict['value'] = input("... Custom Field Value : ")
            custom_dict['type'] = 'text'
            record.custom_fields.append(custom_dict)

        api.add_record(params, record)

    elif (params.command == 'h'):
        display.formatted_history(stack)

    elif (params.command == 'debug'):
        if params.debug:
            params.debug = False
            print('Debug OFF')
        else:
            params.debug = True
            print('Debug ON')

    elif params.command == '':
        pass

    else:
        print('\n\nShell Commands:\n')
        print('  d         ... download & decrypt data')
        print('  l         ... list folders and record titles')
        print('  lsf       ... list shared folders')
        print('  lt        ... list teams')
        print('  s <regex> ... search with regular expression')
        print('  g <uid>   ... get record or shared folder details for uid')
        print('  r <uid>   ... rotate password for uid')
        print(
            '  b <regex> ... rotate password for matches of regular expression'
        )
        print('  a         ... add a new record interactively')
        print('  an <uid>  ... append some notes to the specified record')
        print('  c         ... clear the screen')
        print('  h         ... show command history')
        print('  q         ... quit')
        print('')

    if params.command:
        if params.command != 'h':
            stack.append(params.command)
            stack.reverse()

    return True