Exemplo n.º 1
0
def change_passwd(user, oldpassword, newpassword, ip, port):
    user = user.encode('ascii', 'ignore')
    realm_sep = '.'
    if realm_sep not in user:
        realm = "local"
    else:
        users = user.split(realm_sep)
        realm = users[0]
        users = users[1:]
        user = realm_sep.join(users)

    oldpassword = oldpassword.encode('ascii', 'ignore')
    newpassword = newpassword.encode('ascii', 'ignore')
    cont = authenticate(user, oldpassword, ip, port, realm)
    print cont
    if 'tokenId' in cont:
        raws = RawSerialize()
        obj = raws.unserialize(cont)
        tokenid = obj['tokenId']
        tokenid = tokenid.encode('ascii', 'ignore')
        cont = change_password(tokenid, user, oldpassword, newpassword, ip,
                               port, realm)
        print cont
        cont_logout = logout(tokenid, ip, port, realm)
        print cont_logout
        if '{}' == cont:
            return (True, "")

        obj = raws.unserialize(cont)
        return (False, obj['message'])

    raws = RawSerialize()
    obj = raws.unserialize(cont)
    return (False, obj['message'])
Exemplo n.º 2
0
def verify_passwd(user, password, ip, port):
    user = user.encode('ascii', 'ignore')
    password = password.encode('ascii', 'ignore')
    realm_sep = '.'
    if realm_sep not in user:
        realm = "local"
    else:
        users = user.split(realm_sep)
        realm = users[0]
        users = users[1:]
        user = realm_sep.join(users)
    cont = authenticate(user, password, ip, port, realm)
    print cont
    #print user,password
    if 'tokenId' in cont:
        raws = RawSerialize()
        obj = raws.unserialize(cont)
        tokenid = obj['tokenId']
        tokenid = tokenid.encode('ascii', 'ignore')
        cont = logout(tokenid, ip, port, realm)
        print cont
        return (True, '')

    if 'Invalid Password' in cont:
        return (False, 'InvalidPassword')
    elif 'Authentication Failed' in cont:
        return (False, 'InvalidCredentials')
    else:
        return (False, 'Invalid')
Exemplo n.º 3
0
def change_passwd(user, oldpassword, newpassword, ip, port):
    user        = user.encode('ascii','ignore')
    realm_sep = '.'
    if realm_sep not in user:
        realm = "local"
    else:
        users = user.split(realm_sep)
        realm = users[0]
        users = users[1:]
        user  = realm_sep.join(users)

    oldpassword = oldpassword.encode('ascii','ignore')
    newpassword = newpassword.encode('ascii','ignore')
    cont = authenticate(user, oldpassword, ip, port, realm)
    print cont
    if 'tokenId' in cont:
        raws = RawSerialize()
        obj = raws.unserialize(cont)
        tokenid = obj['tokenId']
        tokenid = tokenid.encode('ascii', 'ignore')
        cont = change_password(tokenid, user, oldpassword, newpassword, ip, port,realm)
        print cont
        cont_logout = logout(tokenid, ip, port, realm)
        print cont_logout
        if '{}' == cont:
            return (True,"")

        obj = raws.unserialize(cont)
        return (False,obj['message'])

    raws = RawSerialize()
    obj = raws.unserialize(cont)
    return (False,obj['message'])
Exemplo n.º 4
0
def verify_passwd(user, password, ip, port):
    user     = user.encode('ascii','ignore')
    password = password.encode('ascii','ignore')
    realm_sep = '.'
    if realm_sep not in user:
        realm = "local"
    else:
        users = user.split(realm_sep)
        realm = users[0]
        users = users[1:]
        user  = realm_sep.join(users)
    cont = authenticate(user, password, ip, port, realm)
    print cont
    #print user,password
    if 'tokenId' in cont:
        raws = RawSerialize()
        obj = raws.unserialize(cont)
        tokenid = obj['tokenId']
        tokenid = tokenid.encode('ascii', 'ignore')
        cont = logout(tokenid, ip, port, realm)
        print cont
        return (True,'')

    if   'Invalid Password' in cont:
        return (False,'InvalidPassword')
    elif 'Authentication Failed' in cont:
        return (False,'InvalidCredentials')
    else:
        return (False,'Invalid')
Exemplo n.º 5
0
def get_realm_user_list(realm, ip, port):
    err = False
    ret = []
    cont = authenticate('amAdmin', 'zx123456', ip, port)
    logger.info("authenticate:%s", cont)
    if 'tokenId' in cont:
        raws = RawSerialize()
        obj = raws.unserialize(cont)
        tokenid = obj['tokenId']
        tokenid = tokenid.encode('ascii', 'ignore')
        cont = get_user_list(tokenid, ip, port, realm)
        logger.info("realm:%s,get_user_list:%s", realm, cont)
        obj = raws.unserialize(cont)
        if 'result' in obj:
            ret = obj['result']
            err = True
        cont = logout(tokenid, ip, port)
        logger.info("logout:%s", cont)

    return (err, ret)
Exemplo n.º 6
0
def get_realm_user_list(realm, ip, port):
    err = False
    ret = []
    cont = authenticate('amAdmin', 'zx123456', ip, port)
    logger.info("authenticate:%s", cont)
    if 'tokenId' in cont:
        raws = RawSerialize()
        obj = raws.unserialize(cont)
        tokenid = obj['tokenId']
        tokenid = tokenid.encode('ascii', 'ignore')
        cont = get_user_list(tokenid, ip, port, realm)
        logger.info("realm:%s,get_user_list:%s", realm, cont)
        obj  = raws.unserialize(cont)
        if 'result' in obj:
            ret  = obj['result']
            err  = True
        cont = logout(tokenid, ip, port)
        logger.info("logout:%s", cont)

    return (err,ret)