コード例 #1
0
ファイル: views.py プロジェクト: murrown/cyder
def system_detail(request, pk):
    try:
        system = System.objects.get(id=pk)
    except:
        return redirect(reverse('system'))

    attrs = system.systemav_set.all()
    dynamic = DynamicInterface.objects.filter(system=system)
    related_systems = set()
    system_table = tablefy([system], request=request, detail_view=True)
    static = StaticInterface.objects.filter(system=system)
    static_intr = []
    dynamic_intr = []
    for intr in static:
        if intr.mac:
            related_systems.update(intr.get_related_systems())
        static_intr.append((tablefy((intr,), request=request),))
    for intr in dynamic:
        if intr.mac:
            related_systems.update(intr.get_related_systems())
        dynamic_intr.append((tablefy((intr,), request=request),))

    related_systems.discard(system)

    return cy_render(request, 'system/system_detail.html', {
        'attrs_table': tablefy(attrs, request=request),
        'static_intr_tables': static_intr,
        'dynamic_intr_tables': dynamic_intr,
        'related_systems_table': tablefy(list(related_systems),
                                         request=request),
        'obj_type': 'system',
        'obj': system,
        'obj_table': system_table,
        'pretty_obj_type': system.pretty_type,
    })
コード例 #2
0
ファイル: views.py プロジェクト: kiwim0n/cyder
def ctnr_detail(request, pk):
    ctnr = Ctnr.objects.get(id=pk)
    ctnrUsers = ctnr.ctnruser_set.select_related('user', 'user__profile')
    ctnrDomains = ctnr.domains.select_related().filter(
        is_reverse=False)
    ctnrRdomains = ctnr.domains.select_related().filter(is_reverse=True)
    ctnrRanges = ctnr.ranges.select_related()
    ctnrWorkgroups = ctnr.workgroups.select_related()
    ctnr_table = tablefy([ctnr], request=request, detail_view=True)

    if request.user.get_profile().has_perm(
            request, ACTION_UPDATE, obj_class='CtnrObject', ctnr=ctnr):

        extra_cols, domains = create_obj_extra_cols(
            ctnr, ctnrDomains, 'domain')
        domain_table = tablefy(domains, extra_cols=extra_cols, request=request)

        extra_cols, rdomains = create_obj_extra_cols(
            ctnr, ctnrRdomains, 'domain')
        rdomain_table = tablefy(rdomains, extra_cols=extra_cols,
                                request=request)

        extra_cols, ranges = create_obj_extra_cols(ctnr, ctnrRanges, 'range')
        range_table = tablefy(ranges, extra_cols=extra_cols, request=request)

        extra_cols, workgroups = create_obj_extra_cols(
            ctnr, ctnrWorkgroups, 'workgroup')
        workgroup_table = tablefy(workgroups, extra_cols=extra_cols,
                                  request=request)

    else:
        domain_table = tablefy(ctnrDomains, request=request)
        rdomain_table = tablefy(ctnrRdomains, request=request)
        range_table = tablefy(ctnrRanges, request=request)
        workgroup_table = tablefy(ctnrWorkgroups, request=request)

    if request.user.get_profile().has_perm(
            request, ACTION_UPDATE, obj_class='CtnrUser', ctnr=ctnr):

        extra_cols, users = create_user_extra_cols(ctnr, ctnrUsers,
                                                   actions=True)
        user_table = tablefy(users, extra_cols=extra_cols, users=True,
                             request=request, update=False)
    else:
        extra_cols, users = create_user_extra_cols(ctnr, ctnrUsers)
        user_table = tablefy(users, extra_cols=extra_cols, users=True,
                             request=request, update=False)

    return cy_render(request, 'ctnr/ctnr_detail.html', {
        'obj': ctnr,
        'obj_table': ctnr_table,
        'pretty_obj_type': ctnr.pretty_type,
        'obj_type': 'ctnr',
        'user_table': user_table,
        'domain_table': domain_table,
        'rdomain_table': rdomain_table,
        'range_table': range_table,
        'workgroup_table': workgroup_table,
    })
コード例 #3
0
ファイル: views.py プロジェクト: OSU-Net/cyder
def revoke_token(request, pk):
    token = Token.objects.get(pk=pk)

    if not (request.user.is_superuser or request.user == token.user):
        return HttpResponseForbidden()

    # ask for confirmation, then revoke the key
    if request.method == 'POST':
        form = TokenRevokeForm(request.POST)
        if form.is_valid():
            token.delete()
            return cy_render(request, 'authtoken/revoke_token_done.html')
        else:
            return HttpResponseBadRequest("Invalid form submission.")
    else:
        form = TokenRevokeForm()
        return cy_render(request, 'authtoken/revoke_token.html',
                      {'form': form, 'token': token})
コード例 #4
0
ファイル: views.py プロジェクト: OSU-Net/cyder
def cydhcp_detail(request, pk):
    obj_type = request.path.split('/')[2]
    Klass, FormKlass = get_klasses(obj_type)
    obj = get_object_or_404(Klass, pk=pk)
    attr_getter = getattr(obj, "{0}av_set".format(obj_type))
    return cy_render(request, "{0}/{0}_detail.html".format(obj_type), {
        obj_type: obj,
        'attrs': attr_getter.all()
    })
コード例 #5
0
ファイル: views.py プロジェクト: akeym/cyder
def build_network(request, network_pk):
    network = get_object_or_404(Network, pk=network_pk)
    if request.GET.get('raw', False):
        DEBUG_BUILD_STRING = network.build_subnet(raw=True)
        return HttpResponse(DEBUG_BUILD_STRING)
    else:
        DEBUG_BUILD_STRING = network.build_subnet(raw=False)
        return cy_render(
            'build/sample_build.html',
            {'data': DEBUG_BUILD_STRING, 'network': network})
コード例 #6
0
ファイル: views.py プロジェクト: murrown/cyder
def search(request):
    """Search page."""
    search = request.GET.get('search', '')
    if search:
        meta, tables = _search(request)
    else:
        meta, tables = [], []

    return cy_render(request, 'search/search.html', {
        'search': search,
        'meta': meta,
        'tables': tables,
        'zones': [z.name for z in get_zones()]
    })
コード例 #7
0
ファイル: views.py プロジェクト: OSU-Net/cyder
def request_token(request):
    # prompt user for purpose, give them spiel about API access, then generate
    if request.method == 'POST':
        form = TokenRequestForm(request.POST)
        if form.is_valid():
            # create the new token
            token = Token.objects.create(
                user=request.user, purpose=form.cleaned_data['purpose'])
            # show the user their new token
            return HttpResponseRedirect(
                '/api/authtoken/{0}'.format(str(token.pk)))
    else:
        form = TokenRequestForm()
    return cy_render(request, 'authtoken/request_token.html', {'form': form})
コード例 #8
0
ファイル: views.py プロジェクト: OSU-Net/cyder
def cydns_index(request):
    from cyder.models import (AddressRecord, CNAME, Domain, Nameserver, PTR,
                              MX, SOA, SRV, SSHFP, TXT)
    ctnr = request.session['ctnr']
    counts = []
    Klasses = [(AddressRecord, 'Address Records'), (PTR, 'PTRs'), (MX, 'MXs'),
        (SRV,'SRVs'), (SSHFP, 'SSHFPs'), (TXT, 'TXTs'), (CNAME, 'CNAMES')]

    if ctnr.name != 'global':
        domains = ctnr.domains.all()
        soa_list = []
        for Klass in Klasses:
            counts.append((Klass[1], Klass[0].objects.filter(ctnr=ctnr).count()))

        ns_count = 0
        for domain in domains:
            ns_count += domain.nameserver_set.count()

            if domain.soa not in soa_list:
                soa_list.append(domain.soa)

        counts.append(('SOAs', len(soa_list)))
        counts.append(('Nameservers', ns_count))

    else:
        domains = Domain.objects.all()
        Klasses.append((SOA, 'SOAs'))
        Klasses.append((Nameserver, 'Nameservers'))
        for Klass in Klasses:
            counts.append((Klass[1], Klass[0].objects.all().count()))


    counts.append(('Domains', domains.filter(is_reverse=False).count()))
    counts.append(('Reverse Domains',
               domains.filter(is_reverse=True).count()))

    return cy_render(request, 'cydns/cydns_index.html', {'counts': counts})
コード例 #9
0
ファイル: views.py プロジェクト: woakes070048/cyder
def cydns_index(request):
    from cyder.models import (AddressRecord, CNAME, Domain, Nameserver, PTR,
                              MX, SOA, SRV, SSHFP, TXT)
    ctnr = request.session['ctnr']
    counts = []
    Klasses = [(AddressRecord, 'Address Records'), (PTR, 'PTRs'), (MX, 'MXs'),
               (SRV, 'SRVs'), (SSHFP, 'SSHFPs'), (TXT, 'TXTs'),
               (CNAME, 'CNAMES')]

    if ctnr.name != 'global':
        domains = ctnr.domains.all()
        soa_list = []
        for Klass in Klasses:
            counts.append(
                (Klass[1], Klass[0].objects.filter(ctnr=ctnr).count()))

        ns_count = 0
        for domain in domains:
            ns_count += domain.nameserver_set.count()

            if domain.soa not in soa_list:
                soa_list.append(domain.soa)

        counts.append(('SOAs', len(soa_list)))
        counts.append(('Nameservers', ns_count))

    else:
        domains = Domain.objects.all()
        Klasses.append((SOA, 'SOAs'))
        Klasses.append((Nameserver, 'Nameservers'))
        for Klass in Klasses:
            counts.append((Klass[1], Klass[0].objects.all().count()))

    counts.append(('Domains', domains.filter(is_reverse=False).count()))
    counts.append(('Reverse Domains', domains.filter(is_reverse=True).count()))

    return cy_render(request, 'cydns/cydns_index.html', {'counts': counts})
コード例 #10
0
ファイル: views.py プロジェクト: OSU-Net/cyder
            if is_ajax_form(request):
                return HttpResponse(json.dumps({'errors': form.errors}))
    elif request.method == 'GET':
        form = FormKlass(instance=obj)

        object_list = _filter(request, Klass)
        page_obj = make_paginator(request, do_sort(request, object_list), 50)

    if issubclass(type(form), UsabilityFormMixin):
        form.make_usable(request)

    return cy_render(request, 'cydns/cydns_view.html', {
        'form': form,
        'obj': obj,
        'obj_type': obj_type,
        'object_table': tablefy(page_obj, request=request),
        'page_obj': page_obj,
        'pretty_obj_type': Klass.pretty_type,
        'pk': pk,
    })


def cydns_table_update(request, pk, object_type=None):
    return table_update(request, pk, object_type)


def cydns_search_obj(request):
    return search_obj(request)


def cydns_index(request):
コード例 #11
0
def ctnr_detail(request, pk):
    ctnr = Ctnr.objects.get(id=pk)
    ctnrUsers = ctnr.ctnruser_set.select_related('user', 'user__profile')
    ctnrDomains = ctnr.domains.select_related().filter(is_reverse=False)
    ctnrRdomains = ctnr.domains.select_related().filter(is_reverse=True)
    ctnrRanges = ctnr.ranges.select_related()
    ctnrWorkgroups = ctnr.workgroups.select_related()
    ctnr_table = tablefy([ctnr], request=request, detail_view=True)

    if request.user.get_profile().has_perm(request,
                                           ACTION_UPDATE,
                                           obj_class='CtnrObject',
                                           ctnr=ctnr):

        extra_cols, domains = create_obj_extra_cols(ctnr, ctnrDomains,
                                                    'domain')
        domain_table = tablefy(domains,
                               extra_cols=extra_cols,
                               request=request,
                               update=False)

        extra_cols, rdomains = create_obj_extra_cols(ctnr, ctnrRdomains,
                                                     'domain')
        rdomain_table = tablefy(rdomains,
                                extra_cols=extra_cols,
                                request=request,
                                update=False)

        extra_cols, ranges = create_obj_extra_cols(ctnr, ctnrRanges, 'range')
        range_table = tablefy(ranges,
                              extra_cols=extra_cols,
                              request=request,
                              update=False)

        extra_cols, workgroups = create_obj_extra_cols(ctnr, ctnrWorkgroups,
                                                       'workgroup')
        workgroup_table = tablefy(workgroups,
                                  extra_cols=extra_cols,
                                  request=request,
                                  update=False)

    else:
        domain_table = tablefy(ctnrDomains, request=request)
        rdomain_table = tablefy(ctnrRdomains, request=request)
        range_table = tablefy(ctnrRanges, request=request)
        workgroup_table = tablefy(ctnrWorkgroups, request=request)

    if request.user.get_profile().has_perm(request,
                                           ACTION_UPDATE,
                                           obj_class='CtnrUser',
                                           ctnr=ctnr):

        extra_cols, users = create_user_extra_cols(ctnr,
                                                   ctnrUsers,
                                                   actions=True)
        user_table = tablefy(users,
                             extra_cols=extra_cols,
                             users=True,
                             request=request,
                             update=False)
    else:
        extra_cols, users = create_user_extra_cols(ctnr, ctnrUsers)
        user_table = tablefy(users,
                             extra_cols=extra_cols,
                             users=True,
                             request=request,
                             update=False)

    return cy_render(
        request, 'ctnr/ctnr_detail.html', {
            'obj': ctnr,
            'obj_table': ctnr_table,
            'pretty_obj_type': ctnr.pretty_type,
            'obj_type': 'ctnr',
            'user_table': user_table,
            'domain_table': domain_table,
            'rdomain_table': rdomain_table,
            'range_table': range_table,
            'workgroup_table': workgroup_table,
        })
コード例 #12
0
def core_index(request):
    return cy_render(request, 'core/core_index.html')
コード例 #13
0
ファイル: views.py プロジェクト: OSU-Net/cyder
def token_detail(request, pk):
    token = Token.objects.get(pk=pk)
    user = token.user

    return cy_render(request, 'authtoken/token_detail.html',
                  {'token': token, 'user': user})
コード例 #14
0
ファイル: views.py プロジェクト: murrown/cyder
def range_detail(request, pk):
    mrange = get_object_or_404(Range, pk=pk)

    if mrange.allow == ALLOW_ANY:
        allow = ['Any client']
    elif mrange.allow == ALLOW_KNOWN:
        allow = ['Known clients']
    else:
        allow = []
        if mrange.allow == ALLOW_VRF:
            allow += map(str, Vrf.objects.filter(network=mrange.network))
        if mrange.allow == ALLOW_LEGACY:
            allow += map(str, Ctnr.objects.filter(ranges=mrange))

    allow.sort(key=lambda x: x.lower())

    range_type = mrange.range_type
    range_data = []
    ip_usage_percent = None
    dynamic_interfaces = []
    dynamic_interfaces_page_obj = None
    dynamic_interfaces_table = None
    if range_type == 'st':
        start_upper = mrange.start_upper
        start_lower = mrange.start_lower
        end_upper = mrange.end_upper
        end_lower = mrange.end_lower
        range_data, ip_usage_percent = range_usage(
            two_to_one(start_upper, start_lower),
            two_to_one(end_upper, end_lower),
            mrange.ip_type)
    else:
        ip_usage_percent = mrange.range_usage
        DynamicInterface = get_model('cyder', 'dynamicinterface')
        dynamic_interfaces = DynamicInterface.objects.filter(range=mrange)
        dynamic_interfaces_page_obj = make_paginator(
            request, do_sort(request, dynamic_interfaces), 10)
        dynamic_interfaces_table = tablefy(dynamic_interfaces_page_obj,
                                           request=request, excluded=['Range'])

    range_table = tablefy((mrange,), request=request, detail_view=True)

    ctnr_table = tablefy(mrange.ctnr_set.all(), request=request)

    if ip_usage_percent:
        ip_usage_percent = "{0}%".format(ip_usage_percent)
    return cy_render(request, 'range/range_detail.html', {
        'obj': mrange,
        'obj_type': 'range',
        'pretty_obj_type': mrange.pretty_type,
        'ranges_table': range_table,
        'range_data': make_paginator(request, range_data, 50),
        'range_type': range_type,
        'attrs_table': tablefy(mrange.rangeav_set.all(),
                               request=request),
        'allow_list': allow,
        'range_used': ip_usage_percent,
        'dynamic_intr_table': dynamic_interfaces_table,
        'page_obj': dynamic_interfaces_page_obj,
        'ctnr_table': ctnr_table
    })
コード例 #15
0
ファイル: views.py プロジェクト: woakes070048/cyder
            if is_ajax_form(request):
                return HttpResponse(json.dumps({'errors': form.errors}))
    elif request.method == 'GET':
        form = FormKlass(instance=obj)

        object_list = _filter(request, Klass)
        page_obj = make_paginator(request, do_sort(request, object_list), 50)

    if issubclass(type(form), UsabilityFormMixin):
        form.make_usable(request)

    return cy_render(
        request, 'cydns/cydns_view.html', {
            'form': form,
            'obj': obj,
            'obj_type': obj_type,
            'object_table': tablefy(page_obj, request=request),
            'page_obj': page_obj,
            'pretty_obj_type': Klass.pretty_type,
            'pk': pk,
        })


def cydns_table_update(request, pk, object_type=None):
    return table_update(request, pk, object_type)


def cydns_search_obj(request):
    return search_obj(request)


def cydns_index(request):