当前位置: 首页>>代码示例>>Python>>正文


Python Organization.get_org方法代码示例

本文整理汇总了Python中pritunl.organization.Organization.get_org方法的典型用法代码示例。如果您正苦于以下问题:Python Organization.get_org方法的具体用法?Python Organization.get_org怎么用?Python Organization.get_org使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pritunl.organization.Organization的用法示例。


在下文中一共展示了Organization.get_org方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: user_otp_secret_put

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def user_otp_secret_put(org_id, user_id):
    org = Organization.get_org(id=org_id)
    user = org.get_user(user_id)
    user.generate_otp_secret()
    user.commit()
    Event(type=USERS_UPDATED, resource_id=org.id)
    return utils.jsonify(user.dict())
开发者ID:bitland,项目名称:pritunl,代码行数:9,代码来源:user.py

示例2: user_key_link_get

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def user_key_link_get(org_id, user_id):
    org = Organization.get_org(id=org_id)
    key_id = uuid.uuid4().hex

    view_id = None
    uri_id = None
    for i in xrange(2):
        for i in xrange(2048):
            temp_id = ''.join(random.sample(SHORT_URL_CHARS, SHORT_URL_LEN))
            if not view_id:
                if not cache_db.exists(_get_view_key(temp_id)):
                    view_id = temp_id
                    break
            else:
                if not cache_db.exists(_get_uri_key(temp_id)):
                    uri_id = temp_id
                    break
        if not view_id and not uri_id:
            raise KeyLinkError('Failed to generate random id')

    cache_db.expire(_get_key_key(key_id), KEY_LINK_TIMEOUT)
    cache_db.dict_set(_get_key_key(key_id), 'org_id', org_id)
    cache_db.dict_set(_get_key_key(key_id), 'user_id', user_id)
    cache_db.dict_set(_get_key_key(key_id), 'view_id', view_id)
    cache_db.dict_set(_get_key_key(key_id), 'uri_id', uri_id)

    conf_urls = []
    if app_server.inline_certs:
        for server in org.iter_servers():
            conf_id = uuid.uuid4().hex

            cache_db.expire(_get_conf_key(conf_id), KEY_LINK_TIMEOUT)
            cache_db.dict_set(_get_conf_key(conf_id), 'org_id', org_id)
            cache_db.dict_set(_get_conf_key(conf_id), 'user_id', user_id)
            cache_db.dict_set(_get_conf_key(conf_id), 'server_id', server.id)

            conf_urls.append({
                'id': conf_id,
                'server_name': server.name,
                'url': '/key/%s.ovpn' % conf_id,
            })

    cache_db.expire(_get_view_key(view_id), KEY_LINK_TIMEOUT)
    cache_db.dict_set(_get_view_key(view_id), 'org_id', org_id)
    cache_db.dict_set(_get_view_key(view_id), 'user_id', user_id)
    cache_db.dict_set(_get_view_key(view_id), 'key_id', key_id)
    cache_db.dict_set(_get_view_key(view_id), 'uri_id', uri_id)
    cache_db.dict_set(_get_view_key(view_id),
        'conf_urls', json.dumps(conf_urls))

    cache_db.expire(_get_uri_key(uri_id), KEY_LINK_TIMEOUT)
    cache_db.dict_set(_get_uri_key(uri_id), 'org_id', org_id)
    cache_db.dict_set(_get_uri_key(uri_id), 'user_id', user_id)

    return utils.jsonify({
        'id': key_id,
        'key_url': '/key/%s.tar' % key_id,
        'view_url': '/k/%s' % view_id,
        'uri_url': '/ku/%s' % uri_id,
    })
开发者ID:WrongChao,项目名称:pritunl,代码行数:62,代码来源:key.py

示例3: user_put

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def user_put(org_id, user_id):
    org = Organization.get_org(id=org_id)
    user = org.get_user(user_id)
    name = utils.filter_str(flask.request.json['name'])
    user.rename(name)

    return utils.jsonify(user.dict())
开发者ID:pombredanne,项目名称:pritunl,代码行数:9,代码来源:user.py

示例4: user_post

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def user_post(org_id):
    org = Organization.get_org(id=org_id)
    users = []

    if isinstance(flask.request.json, list):
        users_data = flask.request.json
    else:
        users_data = [flask.request.json]

    for user_data in users_data:
        name = utils.filter_str(user_data['name'])
        email = utils.filter_str(user_data.get('email'))
        user = org.new_user(type=CERT_CLIENT, name=name, email=email)

        disabled = user_data.get('disabled')
        if disabled is not None:
            user.disabled = disabled

        user.commit()
        users.append(user.dict())

    Event(type=ORGS_UPDATED)
    Event(type=USERS_UPDATED, resource_id=org.id)
    Event(type=SERVERS_UPDATED)

    if isinstance(flask.request.json, list):
        LogEntry(message='Created %s new users.' % len(flask.request.json))
        return utils.jsonify(users)
    else:
        LogEntry(message='Created new user "%s".' % users[0]['name'])
        return utils.jsonify(users[0])
开发者ID:bitland,项目名称:pritunl,代码行数:33,代码来源:user.py

示例5: org_get

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def org_get(org_id=None):
    if org_id:
        return utils.jsonify(Organization.get_org(id=org_id).dict())
    else:
        orgs = []
        for org in Organization.iter_orgs():
            orgs.append(org.dict())
        return utils.jsonify(orgs)
开发者ID:WrongChao,项目名称:pritunl,代码行数:10,代码来源:org.py

示例6: user_get

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def user_get(org_id, user_id=None, page=None):
    org = Organization.get_org(id=org_id)
    if user_id:
        return utils.jsonify(org.get_user(user_id).dict())
    else:
        page = flask.request.args.get('page', None)
        page = int(page) if page else page
        search = flask.request.args.get('search', None)
        limit = int(flask.request.args.get('limit', USER_PAGE_COUNT))
        otp_auth = False
        search_more = True
        server_count = 0
        clients = {}

        for server in org.iter_servers():
            server_count += 1
            if server.otp_auth:
                otp_auth = True
            server_clients = server.clients
            for client_id in server_clients:
                client = server_clients[client_id]
                if client_id not in clients:
                    clients[client_id] = {}
                clients[client_id][server.id] = client

        users = []
        for user in org.iter_users(page=page, prefix=search,
                prefix_limit=limit):
            if user is None:
                search_more = False
                break
            is_client = user.id in clients
            user_dict = user.dict()
            user_dict['status'] = True if is_client else False
            user_dict['otp_auth'] = otp_auth
            user_dict['servers'] = clients[user.id] if is_client else {}
            users.append(user_dict)

        if page is not None:
            return utils.jsonify({
                'page': page,
                'page_total': org.page_total,
                'server_count': server_count,
                'users': users,
            })
        elif search is not None:
            return utils.jsonify({
                'search': search,
                'search_more': search_more,
                'search_limit': limit,
                'search_count': org.get_last_prefix_count(),
                'search_time':  round((time.time() - flask.g.start), 4),
                'server_count': server_count,
                'users': users,
            })
        else:
            return utils.jsonify(users)
开发者ID:ogrishman,项目名称:pritunl,代码行数:59,代码来源:user.py

示例7: _get_key_archive

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def _get_key_archive(org_id, user_id):
    org = Organization.get_org(id=org_id)
    user = org.get_user(user_id)
    key_archive = user.build_key_archive()
    response = flask.Response(response=key_archive,
        mimetype='application/octet-stream')
    response.headers.add('Content-Disposition',
        'attachment; filename="%s.tar"' % user.name)
    return response
开发者ID:bitland,项目名称:pritunl,代码行数:11,代码来源:key.py

示例8: user_put

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def user_put(org_id, user_id):
    org = Organization.get_org(id=org_id)
    user = org.get_user(user_id)

    name = flask.request.json.get('name')
    if name:
        name = utils.filter_str(name)

    if 'email' in flask.request.json:
        email = flask.request.json['email']
        if email:
            user.email = utils.filter_str(email)
        else:
            user.email = None

    disabled = flask.request.json.get('disabled')
    if disabled is not None:
        user.disabled = disabled

    if name:
        user.rename(name)
    else:
        user.commit()
        Event(type=USERS_UPDATED, resource_id=user.org.id)

    if disabled:
        if user.type == CERT_CLIENT:
            LogEntry(message='Disabled user "%s".' % user.name)

        for server in org.iter_servers():
            server_clients = server.clients
            if user_id in server_clients:
                server.restart()
    elif disabled == False and user.type == CERT_CLIENT:
        LogEntry(message='Enabled user "%s".' % user.name)

    send_key_email = flask.request.json.get('send_key_email')
    if send_key_email and user.email:
        try:
            user.send_key_email(send_key_email)
        except EmailNotConfiguredError:
            return utils.jsonify({
                'error': EMAIL_NOT_CONFIGURED,
                'error_msg': EMAIL_NOT_CONFIGURED_MSG,
            }, 400)
        except EmailFromInvalid:
            return utils.jsonify({
                'error': EMAIL_FROM_INVALID,
                'error_msg': EMAIL_FROM_INVALID_MSG,
            }, 400)
        except EmailApiKeyInvalid:
            return utils.jsonify({
                'error': EMAIL_API_KEY_INVALID,
                'error_msg': EMAIL_API_KEY_INVALID_MSG,
            }, 400)

    return utils.jsonify(user.dict())
开发者ID:monsterChen,项目名称:pritunl,代码行数:59,代码来源:user.py

示例9: user_delete

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def user_delete(org_id, user_id):
    org = Organization.get_org(id=org_id)
    user = org.get_user(user_id)
    user_id = user.id
    user.remove()

    for server in org.iter_servers():
        server_clients = server.clients
        if user_id in server_clients:
            server.restart()

    return utils.jsonify({})
开发者ID:WrongChao,项目名称:pritunl,代码行数:14,代码来源:user.py

示例10: _get_key_archive

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def _get_key_archive(org_id, user_id):
    org = Organization.get_org(id=org_id)
    user = org.get_user(user_id)
    archive_temp_path = user.build_key_archive()
    try:
        with open(archive_temp_path, 'r') as archive_file:
            response = flask.Response(response=archive_file.read(),
                mimetype='application/octet-stream')
            response.headers.add('Content-Disposition',
                'attachment; filename="%s.tar"' % user.name)
    finally:
        user.clean_key_archive()
    return response
开发者ID:ogrishman,项目名称:pritunl,代码行数:15,代码来源:key.py

示例11: user_post

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def user_post(org_id):
    org = Organization.get_org(id=org_id)
    name = utils.filter_str(flask.request.json["name"])
    email = None
    if "email" in flask.request.json:
        email = utils.filter_str(flask.request.json["email"])
    user = org.new_user(type=CERT_CLIENT, name=name, email=email)

    disabled = flask.request.json.get("disabled")
    if disabled is not None:
        user.disabled = disabled
        user.commit()

    return utils.jsonify(user.dict())
开发者ID:WrongChao,项目名称:pritunl,代码行数:16,代码来源:user.py

示例12: server_org_delete

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def server_org_delete(server_id, org_id):
    server = Server.get_server(id=server_id)
    org = Organization.get_org(id=org_id)
    if server.status:
        return utils.jsonify({
            'error': SERVER_NOT_OFFLINE,
            'error_msg': SERVER_NOT_OFFLINE_DETACH_ORG_MSG,
        }, 400)
    server.remove_org(org)
    server.commit()
    Event(type=SERVERS_UPDATED)
    Event(type=SERVER_ORGS_UPDATED, resource_id=server.id)
    Event(type=USERS_UPDATED, resource_id=org.id)
    return utils.jsonify({})
开发者ID:bitland,项目名称:pritunl,代码行数:16,代码来源:server.py

示例13: user_delete

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def user_delete(org_id, user_id):
    org = Organization.get_org(id=org_id)
    user = org.get_user(user_id)
    name = user.name
    user.remove()

    Event(type=ORGS_UPDATED)
    Event(type=USERS_UPDATED, resource_id=org.id)

    for server in org.iter_servers():
        server_clients = server.clients
        if user_id in server_clients:
            server.restart()

    LogEntry(message='Deleted user "%s".' % name)

    return utils.jsonify({})
开发者ID:bitland,项目名称:pritunl,代码行数:19,代码来源:user.py

示例14: server_org_put

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def server_org_put(server_id, org_id):
    server = Server.get_server(id=server_id)
    org = Organization.get_org(id=org_id)
    if server.status:
        return utils.jsonify({
            'error': SERVER_NOT_OFFLINE,
            'error_msg': SERVER_NOT_OFFLINE_ATTACH_ORG_MSG,
        }, 400)
    server.add_org(org)
    server.commit()
    Event(type=SERVERS_UPDATED)
    Event(type=SERVER_ORGS_UPDATED, resource_id=server.id)
    Event(type=USERS_UPDATED, resource_id=org.id)
    return utils.jsonify({
        'id': org.id,
        'server': server.id,
        'name': org.name,
    })
开发者ID:bitland,项目名称:pritunl,代码行数:20,代码来源:server.py

示例15: user_uri_key_page_get

# 需要导入模块: from pritunl.organization import Organization [as 别名]
# 或者: from pritunl.organization.Organization import get_org [as 别名]
def user_uri_key_page_get(uri_id):
    org_id = cache_db.dict_get(_get_uri_key(uri_id), 'org_id')
    user_id = cache_db.dict_get(_get_uri_key(uri_id), 'user_id')

    # Check for expire
    if not cache_db.exists(_get_uri_key(uri_id)):
        time.sleep(RATE_LIMIT_SLEEP)
        return flask.abort(404)

    org = Organization.get_org(id=org_id)
    user = org.get_user(user_id)

    keys = {}
    for server in org.iter_servers():
        key = user.build_key_conf(server.id)
        keys[key['name']] = key['conf']

    return utils.jsonify(keys)
开发者ID:WrongChao,项目名称:pritunl,代码行数:20,代码来源:key.py


注:本文中的pritunl.organization.Organization.get_org方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。