コード例 #1
0
def save_info():
    data = request.get_json(silent=True)
    name = data.get('name')
    permissions = data.get('permissions')
    with db.auto_commit():
        Role.save(name=name, permissions=Permission.list_items_by_uids(permissions))
    return Success()
コード例 #2
0
ファイル: zone.py プロジェクト: thinks520/ATField
def save_info():
    data = request.get_json(silent=True)
    name = data.get('name')
    parent_uid = data.get('parent_uid')
    with db.auto_commit():
        Zone.save(name=name, parent_uid=parent_uid)
    return Success()
コード例 #3
0
ファイル: domain.py プロジェクト: thinks520/ATField
def remove():
    data = request.get_json(silent=True)
    uid = data.get('uid')
    d = Domain.get_item_by_uid(uid)
    with db.auto_commit():
        d.remove()
    return Success()
コード例 #4
0
ファイル: domain.py プロジェクト: thinks520/ATField
def activate():
    data = request.get_json(silent=True)
    uid = data.get('uid')
    d = Domain.get_item_by_uid(uid, status=0)
    with db.auto_commit():
        d.activate()
    return Success()
コード例 #5
0
def get_user_info():
    data = {
        'uid': g.current_user.uid,
        'name': g.current_user.name,
        'roles': [],
        'permissions': []
    }
    permission_list = {}
    for role in g.current_user.roles:
        for permission in role.permissions:
            module, action = permission.endpoint.split('+')
            if not permission_list.get(module, None):
                permission_list[module] = []
            permission_list[module].append(action)
        data['roles'].append(
            {
                'uid': role.uid,
                'name': role.name,
            }
        )
    for module, action in permission_list.items():
        data['permissions'].append({
            'name': module,
            'actions': action
        })
    return Success(msg=data)
コード例 #6
0
ファイル: cgi.py プロジェクト: thinks520/ATField
def get_list():
    page_no = request.args.get('pageNo', 1, type=int)
    page_size = request.args.get('pageSize', 10, type=int)
    uid = request.args.get('uid', '', type=str)
    http_uid = request.args.get('http_uid', '', type=str)
    url = request.args.get('url', '', type=str)
    method = request.args.get('method', '', type=str)
    code = request.args.get('code', 200, type=int)
    status = request.args.get('status', 1, type=int)
    pagination = CGI.list_items_paginate_by_search(page=page_no,
                                                   per_page=page_size,
                                                   uid=uid,
                                                   status=status,
                                                   http_uid=http_uid,
                                                   url=url,
                                                   method=method,
                                                   code=code)
    data = {
        'pageSize':
        pagination.per_page,
        'pageNo':
        pagination.page,
        'totalCount':
        pagination.total,
        'data': [{
            'uid': c.uid,
            'http_uid': c.http_uid,
            'url': c.url,
            'method': c.method,
            'code': c.code,
            'status': c.status,
            'info': c.info
        } for c in pagination.items]
    }
    return Success(msg=data)
コード例 #7
0
def get_list():
    uid = request.args.get('uid', '', type=str)
    name = request.args.get('name', '', type=str)
    status = request.args.get('status', 1, type=int)
    users = User.list_items_by_search(uid=uid, name=name, status=status)
    data = {
        'pageSize': len(users),
        'pageNo': 1,
        'totalCount': len(users),
        'data': [{
            'uid': u.uid,
            'name': u.name,
            'status': u.status,
            'roles': [r.uid for r in u.roles]
        } for u in users],
        'roles': [{
            'uid': r.uid,
            'name': r.name,
            'permissions': [p.uid for p in r.permissions],
        } for r in Role.list_items()],
        'permissions': [{
            'uid': p.uid,
            'endpoint': p.endpoint
        } for p in Permission.list_items()],
    }
    for u in data['data']:
        u['permissions'] = set()
        for r in data['roles']:
            if r['uid'] in u['roles']:
                for permission in r['permissions']:
                    u['permissions'].add(permission)
        u['permissions'] = list(u['permissions'])
    return Success(msg=data)
コード例 #8
0
ファイル: zone.py プロジェクト: thinks520/ATField
def update_info():
    data = request.get_json(silent=True)
    uid = data.get('uid')
    name = data.get('name')
    z = Zone.get_item_by_uid(uid=uid)
    with db.auto_commit():
        z.update(name=name)
    return Success()
コード例 #9
0
def save_info():
    data = request.get_json(silent=True)
    name = data.get('name')
    roles = data.get('roles')
    password = data.get('password')
    with db.auto_commit():
        User.save(name=name, roles=Role.list_items_by_uids(roles), password=password)
    return Success()
コード例 #10
0
ファイル: host.py プロジェクト: thinks520/ATField
def save_info():
    data = request.get_json(silent=True)
    ip = data.get('ip')
    origin = data.get('origin')
    zone_uid = data.get('zone_uid')
    with db.auto_commit():
        Host.save(ip=ip, origin=origin, zone_uid=zone_uid)
    return Success()
コード例 #11
0
ファイル: zone.py プロジェクト: thinks520/ATField
def get_list():
    zones = Zone.recursion_items()
    data = {
        'pageSize': len(zones),
        'pageNo': 1,
        'totalCount': len(zones),
        'data': zones
    }
    return Success(msg=data)
コード例 #12
0
def update_info():
    data = request.get_json(silent=True)
    uid = data.get('uid')
    name = data.get('name')
    permissions = data.get('permissions')
    r = Role.get_item_by_uid(uid=uid)
    with db.auto_commit():
        r.update(name=name, permissions=Permission.list_items_by_uids(permissions))
    return Success()
コード例 #13
0
def update_info():
    data = request.get_json(silent=True)
    uid = data.get('uid')
    name = data.get('name')
    roles = data.get('roles')
    u = User.get_item_by_uid(uid=uid)
    with db.auto_commit():
        u.update(name=name, roles=Role.list_items_by_uids(roles))
    return Success()
コード例 #14
0
ファイル: host.py プロジェクト: thinks520/ATField
def update_info():
    data = request.get_json(silent=True)
    uid = data.get('uid')
    origin = data.get('origin')
    zone_uid = data.get('zone_uid')
    with db.auto_commit():
        h = Host.get_item_by_uid(uid=uid)
        h.update(origin=origin, zone_uid=zone_uid)
    return Success()
コード例 #15
0
ファイル: host.py プロジェクト: thinks520/ATField
def get_service():
    uid = request.args.get('uid', '', type=str)
    h = Host.get_item_by_uid(uid=uid)
    data = {
        'pageSize': len(h.services),
        'pageNo': 1,
        'totalCount': len(h.services),
        'data': h.services
    }
    return Success(msg=data)
コード例 #16
0
def get_token():
    data = request.get_json(silent=True)
    username = data.get('username')
    password = data.get('password')
    user = User.get_item_by_name(name=username)
    if not user or not user.verify_password(password):
        return AuthFailedException(msg='user or secret error')
    return Success(msg={
        'token': user.generate_api_auth_token(current_app.config['TOKEN_EXPIRATION'])
    })
コード例 #17
0
ファイル: domain.py プロジェクト: thinks520/ATField
def update_info():
    data = request.get_json(silent=True)
    uid = data.get('uid')
    domain_type = int(data.get('type'))
    origin = data.get('origin')
    info = json.loads(data.get('info'))
    zone_uid = data.get('zone_uid')
    with db.auto_commit():
        d = Domain.get_item_by_uid(uid=uid)
        d.update(type=domain_type, origin=origin, zone_uid=zone_uid, info=info)
    return Success()
コード例 #18
0
ファイル: permission.py プロジェクト: thinks520/ATField
def get_list():
    uid = request.args.get('uid', '', type=str)
    endpoint = request.args.get('endpoint', '', type=str)
    status = request.args.get('status', 1, type=int)
    permissions = Permission.list_items_by_search(uid=uid, endpoint=endpoint, status=status)
    data = {
        'pageSize': len(permissions),
        'pageNo': 1,
        'totalCount': len(permissions),
        'data': [{'uid': p.uid, 'endpoint': p.endpoint, 'status': p.status} for p in permissions]
    }
    return Success(msg=data)
コード例 #19
0
ファイル: domain.py プロジェクト: thinks520/ATField
def save_info():
    data = request.get_json(silent=True)
    name = data.get('name')
    domain_type = int(data.get('type'))
    origin = data.get('origin')
    info = json.loads(data.get('info'))
    zone_uid = data.get('zone_uid')
    with db.auto_commit():
        Domain.save(type=domain_type,
                    origin=origin,
                    name=name,
                    info=info,
                    zone_uid=zone_uid)
    return Success()
コード例 #20
0
ファイル: cgi.py プロジェクト: thinks520/ATField
def save_info():
    data = request.get_json(silent=True)
    http_uid = data.get('http_uid')
    url = data.get('url')
    method = data.get('method')
    code = data.get('code')
    info = json.loads(data.get('info'))
    with db.auto_commit():
        CGI.save(http_uid=http_uid,
                 url=url,
                 method=method,
                 code=code,
                 info=info)
    return Success()
コード例 #21
0
ファイル: cgi.py プロジェクト: thinks520/ATField
def update_info():
    data = request.get_json(silent=True)
    uid = data.get('uid')
    http_uid = data.get('http_uid')
    url = data.get('url')
    method = data.get('method')
    code = data.get('code')
    info = json.loads(data.get('info'))
    c = CGI.get_item_by_uid(uid=uid)
    with db.auto_commit():
        c.update(http_uid=http_uid,
                 url=url,
                 method=method,
                 code=code,
                 info=info)
    return Success()
コード例 #22
0
ファイル: asset.py プロジェクト: thinks520/ATField
def get_cgi():
    page_no = request.get('pageNo', 1, type=int)
    page_size = request.args.get('pageSize', 10, type=int)
    uid = request.args.get('uid', '', type=str)
    http_uid = request.args.get('http_uid', '', type=str)
    url = request.args.get('url', '', type=str)
    method = request.args.get('method', '', type=str)
    code = request.args.get('code', 200, type=int)
    pagination = CGI.list_items_paginate_by_search(page=page_no,
                                                   per_page=page_size,
                                                   uid=uid,
                                                   http_uid=http_uid,
                                                   url=url,
                                                   method=method,
                                                   code=code)
    return Success(msg=pagination)
コード例 #23
0
ファイル: asset.py プロジェクト: thinks520/ATField
def get_domain():
    page_no = request.args.get('pageNo', 1, type=int)
    page_size = request.args.get('pageSize', 10, type=int)
    uid = request.args.get('uid', '', type=str)
    zone_uid = request.args.get('zone_uid', '', type=str)
    name = request.args.get('name', '', type=str)
    domain_type = request.args.get('type', '', type=str)
    origin = request.args.get('origin', '', type=str)
    pagination = Domain.list_items_paginate_by_search(
        page=page_no,
        per_page=page_size,
        uid=uid,
        zone_list=Zone.recursion_children_uid_list(zone_uid),
        name=name,
        type=domain_type,
        origin=origin,
        status=1)
    return Success(msg=pagination)
コード例 #24
0
ファイル: asset.py プロジェクト: thinks520/ATField
def get_host():
    page_no = request.args.get('pageNo', 1, type=int)
    page_size = request.args.get('pageSize', 10, type=int)
    uid = request.args.get('uid', '', type=str)
    zone_uid = request.args.get('zone_uid', '', type=str)
    ip = request.args.get('ip', '', type=str)
    origin = request.args.get('origin', '', type=str)
    cpe = request.args.get('cpe', '', type=str)
    pagination = Host.list_items_paginate_by_search(
        page=page_no,
        per_page=page_size,
        uid=uid,
        ip=ip,
        zone_list=Zone.recursion_children_uid_list(zone_uid),
        origin=origin,
        cpe=cpe,
        status=1)
    return Success(msg=pagination)
コード例 #25
0
ファイル: asset.py プロジェクト: thinks520/ATField
def get_http():
    page_no = request.args.get('pageNo', 1, type=int)
    page_size = request.args.get('pageSize', 10, type=int)
    uid = request.args.get('uid', '', type=str)
    zone_uid = request.args.get('zone_uid', '', type=str)
    website = request.args.get('website', '', type=str)
    business = request.args.get('business', '', type=str)
    title = request.args.get('title', '', type=str)
    status = request.args.get('status', 1, type=int)
    pagination = HTTP.list_items_paginate_by_search(
        page=page_no,
        per_page=page_size,
        uid=uid,
        website=website,
        zone_list=Zone.recursion_children_uid_list(zone_uid),
        business=business,
        title=title,
        status=status)
    return Success(msg=pagination)
コード例 #26
0
def get_list():
    uid = request.args.get('uid', '', type=str)
    name = request.args.get('name', '', type=str)
    status = request.args.get('status', 1, type=int)
    roles = Role.list_items_by_search(uid=uid, name=name, status=status)
    data = {
        'pageSize': len(roles),
        'pageNo': 1,
        'totalCount': len(roles),
        'data': [{
            'uid': r.uid,
            'name': r.name,
            'status': r.status,
            'permissions': [permission.uid for permission in r.permissions]
        } for r in roles],
        'permissions': [{
            'uid': p.uid,
            'endpoint': p.endpoint
        } for p in Permission.list_items()]
    }
    return Success(msg=data)
コード例 #27
0
ファイル: host.py プロジェクト: thinks520/ATField
def get_list():
    page_no = request.args.get('pageNo', 1, type=int)
    page_size = request.args.get('pageSize', 10, type=int)
    uid = request.args.get('uid', '', type=str)
    zone_uid = request.args.get('zone_uid', None, type=str)
    ip = request.args.get('ip', '', type=str)
    origin = request.args.get('origin', '', type=str)
    cpe = request.args.get('cpe', '', type=str)
    status = request.args.get('status', 1, type=int)
    pagination = Host.list_items_paginate_by_search(
        page=page_no,
        per_page=page_size,
        uid=uid,
        ip=ip,
        zone_list=Zone.recursion_children_uid_list(zone_uid),
        origin=origin,
        cpe=cpe,
        status=status)
    data = {
        'pageSize':
        pagination.per_page,
        'pageNo':
        pagination.page,
        'totalCount':
        pagination.total,
        'data': [{
            'uid': h.uid,
            'ip': h.ip,
            'zone_uid': h.zone_uid,
            'origin': h.origin,
            'cpe': h.cpe,
            'service_count': h.service_count,
            'status': h.status,
            'info': h.info,
        } for h in pagination.items],
        'zones':
        Zone.recursion_items()
    }
    return Success(msg=data)
コード例 #28
0
ファイル: domain.py プロジェクト: thinks520/ATField
def get_list():
    page_no = request.args.get('pageNo', 1, type=int)
    page_size = request.args.get('pageSize', 10, type=int)
    uid = request.args.get('uid', '', type=str)
    name = request.args.get('name', '', type=str)
    domain_type = request.args.get('type', '', type=str)
    origin = request.args.get('origin', '', type=str)
    zone_uid = request.args.get('zone_uid', '', type=str)
    status = request.args.get('status', 1, type=int)
    pagination = Domain.list_items_paginate_by_search(
        page=page_no,
        per_page=page_size,
        uid=uid,
        zone_list=Zone.recursion_children_uid_list(zone_uid),
        name=name,
        type=domain_type,
        origin=origin,
        status=status)
    data = {
        'pageSize':
        pagination.per_page,
        'pageNo':
        pagination.page,
        'totalCount':
        pagination.total,
        'data': [{
            'uid': d.uid,
            'name': d.name,
            'type': d.type,
            'origin': d.origin,
            'zone_uid': d.zone_uid,
            'status': d.status,
            'info': d.info
        } for d in pagination.items],
        'zones':
        Zone.recursion_items()
    }
    return Success(msg=data)
コード例 #29
0
ファイル: asset.py プロジェクト: thinks520/ATField
def get_service():
    page_no = request.args.get('pageNo', 1, type=int)
    page_size = request.args.get('pageSize', 10, type=int)
    uid = request.args.get('uid', '', type=str)
    zone_uid = request.args.get('zone_uid', '', type=str)
    host_ip = request.args.get('host_ip', '', type=str)
    port = request.args.get('port', '', type=str)
    name = request.args.get('name', '', type=str)
    protocol = request.args.get('protocol', '', type=str)
    tunnel = request.args.get('tunnel', '', type=str)
    cpe = request.args.get('cpe', '', type=str)
    pagination = Service.list_items_paginate_by_search(
        page=page_no,
        per_page=page_size,
        uid=uid,
        host_ip=host_ip,
        port=port,
        status=1,
        cpe=cpe,
        name=name,
        zone_list=Zone.recursion_children_uid_list(zone_uid),
        protocol=protocol,
        tunnel=tunnel)
    return Success(msg=pagination)
コード例 #30
0
ファイル: service.py プロジェクト: thinks520/ATField
def get_list():
    page_no = request.args.get('pageNo', 1, type=int)
    page_size = request.args.get('pageSize', 10, type=int)
    zone_uid = request.args.get('zone_uid', '', type=str)
    uid = request.args.get('uid', '', type=str)
    host_ip = request.args.get('host_ip', '', type=str)
    port = request.args.get('port', '', type=str)
    name = request.args.get('name', '', type=str)
    protocol = request.args.get('protocol', '', type=str)
    tunnel = request.args.get('tunnel', '', type=str)
    cpe = request.args.get('cpe', '', type=str)
    status = request.args.get('status', 1, type=int)
    pagination = Service.list_items_paginate_by_search(page=page_no, per_page=page_size, uid=uid,
                                                       host_ip=host_ip, port=port, status=status, cpe=cpe, name=name,
                                                       zone_list=Zone.recursion_children_uid_list(zone_uid),
                                                       protocol=protocol, tunnel=tunnel)
    data = {
        'pageSize': pagination.per_page,
        'pageNo': pagination.page,
        'totalCount': pagination.total,
        'data': [{
            'uid': s.uid,
            'zone_uid': s.zone_uid,
            'host_uid': s.host_uid,
            'host_ip': s.host_ip,
            'port': s.port,
            'protocol': s.protocol,
            'tunnel': s.tunnel,
            'name': s.name,
            'cpe': s.cpe,
            'status': s.status,
            'info': s.info
        } for s in pagination.items],
        'zones': Zone.recursion_items()
    }
    return Success(msg=data)