Exemplo n.º 1
0
 def get_related_networks(self):
     from cyder.cydhcp.network.utils import calc_networks
     _, related_networks = calc_networks(self)
     networks = set(related_networks)
     networks.add(self)
     while related_networks:
         subnets = set()
         for network in related_networks:
             _, sub_networks = calc_networks(network)
             subnets.update(set(sub_networks))
         networks.update(subnets)
         related_networks = subnets
     return networks
Exemplo n.º 2
0
 def get_related_networks(self):
     from cyder.cydhcp.network.utils import calc_networks
     _, related_networks = calc_networks(self)
     networks = set(related_networks)
     networks.add(self)
     while related_networks:
         subnets = set()
         for network in related_networks:
             _, sub_networks = calc_networks(network)
             subnets.update(set(sub_networks))
         networks.update(subnets)
         related_networks = subnets
     return networks
Exemplo n.º 3
0
def network_detail(request, pk):
    network = get_object_or_404(Network, pk=pk)
    parent_networks, child_networks = calc_networks(network)

    return cy_detail(request, Network, 'network/network_detail.html', {
        'Supernet': 'supernets',
        'Ranges': 'range_set',
        'Attributes': 'networkav_set',
    }, obj=network)
Exemplo n.º 4
0
def network_detail(request, pk):
    network = get_object_or_404(Network, pk=pk)
    parent_networks, child_networks = calc_networks(network)
    return cy_detail(request, Network, 'network/network_detail.html', {
        'Ranges': 'range_set',
        'Parent Networks': parent_networks,
        'Child Networks': child_networks,
        'Attributes': 'networkkeyvalue_set',
    }, obj=network)
Exemplo n.º 5
0
def network_detail(request, network_pk):
    network = get_object_or_404(Network, pk=network_pk)
    network.update_network()
    attrs = network.networkkeyvalue_set.all()
    eldars, sub_networks = calc_networks(network)
    ranges = network.range_set.all()
    return render(
        request,
        "network/network_detail.html",
        {"network": network, "ranges": ranges, "eldars": eldars, "sub_networks": sub_networks, "attrs": attrs},
    )
Exemplo n.º 6
0
def network_detail(request, pk):
    network = get_object_or_404(Network, pk=pk)
    parent_networks, child_networks = calc_networks(network)

    return cy_detail(request,
                     Network,
                     'network/network_detail.html', {
                         'Supernet': 'supernets',
                         'Ranges': 'range_set',
                         'Attributes': 'networkav_set',
                     },
                     obj=network)
Exemplo n.º 7
0
 def get_related_networks(self):
     from cyder.cydhcp.network.models import Network
     from cyder.cydhcp.network.utils import calc_networks
     related_networks = Network.objects.filter(vlan=self)
     networks = set(related_networks)
     while related_networks:
         subnets = set()
         for network in related_networks:
             _, related = calc_networks(network)
             subnets.update(related)
         networks.update(subnets)
         related_networks = subnets
     return networks
Exemplo n.º 8
0
def network_detail(request, network_pk):
    network = get_object_or_404(Network, pk=network_pk)
    network.update_network()
    attrs = network.networkkeyvalue_set.all()
    eldars, sub_networks = calc_networks(network)
    ranges = network.range_set.all()
    return render(
        request, 'network/network_detail.html', {
            'network': network,
            'ranges': ranges,
            'eldars': eldars,
            'sub_networks': sub_networks,
            'attrs': attrs,
        })
Exemplo n.º 9
0
def main():
    build_str = "# DHCP Generated from cyder."
    networks = Network.objects.all()
    children = []
    for network in networks:
        _, sub = calc_networks(network)
        if not sub:
            children.append(network)
    for network in children:
        #build_str += build_subnet(network)
        build_str += network.build_subnet()
    for workgroup in Workgroup.objects.all():
        build_str += workgroup.build_workgroup()
    for vrf in Vrf.objects.all():
        build_str += vrf.build_vrf()
    for ctnr in Ctnr.objects.all():
        build_str += ctnr.build_legacy_class()

    f = open(os.path.join(os.path.dirname(__file__), 'test.conf'), 'w')
    f.write(build_str)
    f.close()
Exemplo n.º 10
0
def search_ip(request):
    if request.method == "POST":
        form = IpSearchForm(request.POST)
        try:
            if form.is_valid():
                ip_type = form.cleaned_data['ip_type']
                search_ip = form.cleaned_data['search_ip']
                try:
                    if ip_type == '4':
                        network = ipaddr.IPv4Network(search_ip)
                    if ip_type == '6':
                        network = ipaddr.IPv6Network(search_ip)
                except ipaddr.AddressValueError, e:
                    form._errors['__all__'] = ErrorList(
                        ["Bad IPv{0} Address {1}".format(ip_type, search_ip)])
                    return render(request, 'cydhcp/cydhcp_form.html',
                                  {'form': form})
                try:
                    network = Network.objects.get(network_str=search_ip)
                    search_ip = network
                    found_exact = True
                except ObjectDoesNotExist:
                    found_exact = False
                    network = Network(ip_type,
                                      network_str=search_ip,
                                      ip_type=ip_type)
                parent = calc_parent(network)
                eldars, sub_networks = calc_networks(network)
                if ip_type == '6':
                    sip_upper, sip_lower = ipv6_to_longs(network.network.ip)
                    eip_upper, eip_lower = ipv6_to_longs(
                        network.network.broadcast)
                else:
                    sip_upper, sip_lower = 0, int(network.network.ip)
                    eip_upper, eip_lower = 0, int(network.network.broadcast)

                addrs_count = AddressRecord.objects.filter(
                    ip_upper__gte=sip_upper,
                    ip_lower__gte=sip_lower,
                    ip_upper__lte=eip_upper,
                    ip_lower__lte=eip_lower).count()

                if addrs_count > 100:
                    addrs = None  # This is too much
                else:
                    addrs = AddressRecord.objects.filter(
                        ip_upper__gte=sip_upper,
                        ip_lower__gte=sip_lower,
                        ip_upper__lte=eip_upper,
                        ip_lower__lte=eip_lower)

                ptrs_count = PTR.objects.filter(
                    ip_upper__gte=sip_upper,
                    ip_lower__gte=sip_lower,
                    ip_upper__lte=eip_upper,
                    ip_lower__lte=eip_lower).count()

                if ptrs_count > 100:
                    ptrs = None  # This is too much
                else:
                    ptrs = PTR.objects.filter(ip_upper__gte=sip_upper,
                                              ip_lower__gte=sip_lower,
                                              ip_upper__lte=eip_upper,
                                              ip_lower__lte=eip_lower)

            return render(
                request, 'cydhcp/cydhcp_results.html', {
                    'search_ip': search_ip,
                    'found_exact': found_exact,
                    'addrs': addrs,
                    'addrs_count': addrs_count,
                    'ptrs_count': ptrs_count,
                    'ptrs': ptrs,
                    'parent': parent,
                    'eldars': eldars,
                    'sub_networks': sub_networks,
                })
        except ValidationError, e:
            form._errors['__all__'] = ErrorList(e.messages)
            return render(request, 'cydhcp/cydhcp_form.html', {'form': form})
Exemplo n.º 11
0
def search_ip(request):
    if request.method == "POST":
        form = IpSearchForm(request.POST)
        try:
            if form.is_valid():
                ip_type = form.cleaned_data['ip_type']
                search_ip = form.cleaned_data['search_ip']
                try:
                    if ip_type == '4':
                        network = ipaddr.IPv4Network(search_ip)
                    if ip_type == '6':
                        network = ipaddr.IPv6Network(search_ip)
                except ipaddr.AddressValueError, e:
                    form._errors['__all__'] = ErrorList(
                        ["Bad IPv{0} Address {1}".format(ip_type, search_ip)])
                    return render(request, 'cydhcp/cydhcp_form.html', {
                        'form': form
                    })
                try:
                    network = Network.objects.get(network_str=search_ip)
                    search_ip = network
                    found_exact = True
                except ObjectDoesNotExist:
                    found_exact = False
                    network = Network(ip_type, network_str=search_ip,
                                      ip_type=ip_type)
                parent = calc_parent(network)
                eldars, sub_networks = calc_networks(network)
                if ip_type == '6':
                    sip_upper, sip_lower = ipv6_to_longs(network.network.ip)
                    eip_upper, eip_lower = ipv6_to_longs(
                        network.network.broadcast)
                else:
                    sip_upper, sip_lower = 0, int(network.network.ip)
                    eip_upper, eip_lower = 0, int(network.network.broadcast)

                addrs_count = AddressRecord.objects.filter(
                    ip_upper__gte=sip_upper,
                    ip_lower__gte=sip_lower,
                    ip_upper__lte=eip_upper,
                    ip_lower__lte=eip_lower).count()

                if addrs_count > 100:
                    addrs = None  # This is too much
                else:
                    addrs = AddressRecord.objects.filter(
                        ip_upper__gte=sip_upper,
                        ip_lower__gte=sip_lower,
                        ip_upper__lte=eip_upper,
                        ip_lower__lte=eip_lower)

                ptrs_count = PTR.objects.filter(
                    ip_upper__gte=sip_upper,
                    ip_lower__gte=sip_lower,
                    ip_upper__lte=eip_upper,
                    ip_lower__lte=eip_lower).count()

                if ptrs_count > 100:
                    ptrs = None  # This is too much
                else:
                    ptrs = PTR.objects.filter(
                        ip_upper__gte=sip_upper,
                        ip_lower__gte=sip_lower,
                        ip_upper__lte=eip_upper,
                        ip_lower__lte=eip_lower)

            return render(request, 'cydhcp/cydhcp_results.html', {
                'search_ip': search_ip,
                'found_exact': found_exact,
                'addrs': addrs,
                'addrs_count': addrs_count,
                'ptrs_count': ptrs_count,
                'ptrs': ptrs,
                'parent': parent,
                'eldars': eldars,
                'sub_networks': sub_networks,
            })
        except ValidationError, e:
            form._errors['__all__'] = ErrorList(e.messages)
            return render(request, 'cydhcp/cydhcp_form.html', {
                'form': form
            })