예제 #1
0
파일: forms.py 프로젝트: simonswine/PyRPKI
    def clean(self):
        asn = self.cleaned_data.get('asn')
        addr = self.cleaned_data.get('addr')
        if (asn and addr) or ((not asn) and (not addr)):
            raise forms.ValidationError, 'Please specify either an AS or IP range, not both'

        if asn:
            try:
                resource_range_as.parse_str(asn)
            except ValueError:
                raise forms.ValidationError, 'invalid AS range'

        if addr:
            #try:
            parse_ipaddr(addr)
            #except BadIPResource:
            #    raise forms.ValidationError, 'invalid IP address range/prefix'

        return self.cleaned_data
예제 #2
0
파일: forms.py 프로젝트: simonswine/PyRPKI
    def clean(self):
        asn = self.cleaned_data.get('asn')
        addr = self.cleaned_data.get('addr')
        if (asn and addr) or ((not asn) and (not addr)):
            raise forms.ValidationError, 'Please specify either an AS or IP range, not both'

        if asn:
            try:
                resource_range_as.parse_str(asn)
            except ValueError:
                raise forms.ValidationError, 'invalid AS range'

        if addr:
            #try:
            parse_ipaddr(addr)
            #except BadIPResource:
            #    raise forms.ValidationError, 'invalid IP address range/prefix'

        return self.cleaned_data
예제 #3
0
파일: views.py 프로젝트: mskf3000/rpki.net
def query_view(request):
    """
    Allow the user to search for an AS or prefix, and show all published ROA
    information.
    """

    if request.method == 'POST':
        form = forms.SearchForm(request.POST, request.FILES)
        if form.is_valid():
            certs = None
            roas = None

            addr = form.cleaned_data.get('addr')
            asn = form.cleaned_data.get('asn')

            if addr:
                family, r = misc.parse_ipaddr(addr)
                prefixes = models.ROAPrefix.objects.filter(family=family,
                                                           prefix=str(r.min))

                prefix_list = []
                for pfx in prefixes:
                    for roa in pfx.roas.all():
                        prefix_list.append((pfx, roa))
            elif asn:
                r = resource_range_as.parse_str(asn)
                roas = models.ROA.objects.filter(asid__gte=r.min,
                                                 asid__lte=r.max)

                # display the results sorted by prefix
                prefix_list = []
                for roa in roas:
                    for pfx in roa.prefixes.all():
                        addr = IPAddress(pfx.prefix.encode())
                        prefix_list.append((pfx, roa, addr))
                prefix_list.sort(cmp=cmp_prefix)

            return render('cacheview/query_result.html',
                          {'object_list': prefix_list}, request)
    else:
        form = forms.SearchForm()

    return render('cacheview/search_form.html', {
        'form': form,
        'search_type': 'ROA '
    }, request)
예제 #4
0
파일: views.py 프로젝트: simonswine/PyRPKI
def query_view(request):
    """
    Allow the user to search for an AS or prefix, and show all published ROA
    information.
    """

    if request.method == 'POST':
        form = forms.SearchForm(request.POST, request.FILES)
        if form.is_valid():
            certs = None
            roas = None

            addr = form.cleaned_data.get('addr')
            asn = form.cleaned_data.get('asn')

            if addr:
                family, r = misc.parse_ipaddr(addr)
                prefixes = models.ROAPrefix.objects.filter(family=family, prefix=str(r.min))

                prefix_list = []
                for pfx in prefixes:
                    for roa in pfx.roas.all():
                        prefix_list.append((pfx, roa))
            elif asn:
                r = resource_range_as.parse_str(asn)
                roas = models.ROA.objects.filter(asid__gte=r.min, asid__lte=r.max)

                # display the results sorted by prefix
                prefix_list = []
                for roa in roas:
                    for pfx in roa.prefixes.all():
                        if pfx.family == 4:
                            addr = v4addr(pfx.prefix.encode())
                        elif pfx.family == 6:
                            addr = v6addr(pfx.prefix.encode())

                        prefix_list.append((pfx, roa, addr))
                prefix_list.sort(cmp=cmp_prefix)

            return render('cacheview/query_result.html',
                    { 'object_list': prefix_list }, request)
    else:
        form = forms.SearchForm()

    return render('cacheview/search_form.html', { 'form':form, 'search_type': 'ROA ' }, request)
예제 #5
0
    def clean_asns(self):
        try:
            r = resource_range_as.parse_str(self.cleaned_data.get('asns'))
        except:
            raise forms.ValidationError('invalid AS or range')

        if not models.ResourceRangeAS.objects.filter(
            cert__conf=self.child.issuer,
            min__lte=r.min,
            max__gte=r.max).exists():
            raise forms.ValidationError('AS or range is not delegated to you')

        # determine if the entered range overlaps with any AS already
        # allocated to this child
        if self.child.asns.filter(end_as__gte=r.min, start_as__lte=r.max).exists():
            raise forms.ValidationError(
                'Overlap with previous allocation to this child')

        return str(r)
예제 #6
0
    def clean_asns(self):
        try:
            r = resource_range_as.parse_str(self.cleaned_data.get('asns'))
        except:
            raise forms.ValidationError('invalid AS or range')

        if not models.ResourceRangeAS.objects.filter(
                cert__conf=self.child.issuer, min__lte=r.min,
                max__gte=r.max).exists():
            raise forms.ValidationError('AS or range is not delegated to you')

        # determine if the entered range overlaps with any AS already
        # allocated to this child
        if self.child.asns.filter(end_as__gte=r.min,
                                  start_as__lte=r.max).exists():
            raise forms.ValidationError(
                'Overlap with previous allocation to this child')

        return str(r)
예제 #7
0
파일: views.py 프로젝트: mskf3000/rpki.net
def search_view(request):
    certs = None
    roas = None

    if request.method == 'POST':
        form = forms.SearchForm2(request.POST, request.FILES)
        if form.is_valid():
            resource = form.cleaned_data.get('resource')
            # try to determine the type of input given
            try:
                r = resource_range_as.parse_str(resource)
                certs = models.Cert.objects.filter(asns__min__gte=r.min,
                                                   asns__max__lte=r.max)
                roas = models.ROA.objects.filter(asid__gte=r.min,
                                                 asid__lte=r.max)
            except:
                try:
                    r = resource_range_ip.parse_str(resource)
                    if r.version == 4:
                        certs = models.Cert.objects.filter(
                            addresses__prefix_min__lte=r.min,
                            addresses__prefix_max__gte=r.max)
                        roas = models.ROA.objects.filter(
                            prefixes__prefix_min__lte=r.min,
                            prefixes__prefix_max__gte=r.max)
                    else:
                        certs = models.Cert.objects.filter(
                            addresses_v6__prefix_min__lte=r.min,
                            addresses_v6__prefix_max__gte=r.max)
                        roas = models.ROA.objects.filter(
                            prefixes_v6__prefix_min__lte=r.min,
                            prefixes_v6__prefix_max__gte=r.max)
                except BadIPResource:
                    pass

    return render(request, 'cacheview/search_result.html', {
        'resource': resource,
        'certs': certs,
        'roas': roas
    })
예제 #8
0
def search_view(request):
    certs = None
    roas = None

    if request.method == 'POST':
        form = forms.SearchForm2(request.POST, request.FILES)
        if form.is_valid():
            resource = form.cleaned_data.get('resource')
            # try to determine the type of input given
            try:
                r = resource_range_as.parse_str(resource)
                certs = models.Cert.objects.filter(asns__min__gte=r.min,
                                                   asns__max__lte=r.max)
                roas = models.ROA.objects.filter(asid__gte=r.min,
                                                 asid__lte=r.max)
            except:
                try:
                    r = resource_range_ip.parse_str(resource)
                    if r.version == 4:
                        certs = models.Cert.objects.filter(
                            addresses__prefix_min__lte=r.min,
                            addresses__prefix_max__gte=r.max)
                        roas = models.ROA.objects.filter(
                            prefixes__prefix_min__lte=r.min,
                            prefixes__prefix_max__gte=r.max)
                    else:
                        certs = models.Cert.objects.filter(
                            addresses_v6__prefix_min__lte=r.min,
                            addresses_v6__prefix_max__gte=r.max)
                        roas = models.ROA.objects.filter(
                            prefixes_v6__prefix_min__lte=r.min,
                            prefixes_v6__prefix_max__gte=r.max)
                except BadIPResource:
                    pass

    return render(request, 'cacheview/search_result.html',
                  {'resource': resource, 'certs': certs, 'roas': roas})
예제 #9
0
def search_view(request):
    if request.method == 'POST':
        form = forms.SearchForm(request.POST, request.FILES)
        if form.is_valid():
            certs = None
            roas = None

            addr = form.cleaned_data.get('addr')
            asn = form.cleaned_data.get('asn')

            if addr:
                family, r = misc.parse_ipaddr(addr)
                certs = models.Cert.objects.filter(addresses__family=family, addresses__min=str(r.min), addresses__max=str(r.max))
                roas = models.ROA.objects.filter(prefixes__family=family, prefixes__prefix=str(r.min))
            elif asn:
                r = resource_range_as.parse_str(asn)
                certs = models.Cert.objects.filter(asns__min__gte=r.min, asns__max__lte=r.max)
                roas = models.ROA.objects.filter(asid__gte=r.min, asid__lte=r.max)

            return render('cacheview/search_result.html', { 'certs': certs, 'roas': roas }, request)
    else:
        form = forms.SearchForm()

    return render('cacheview/search_form.html', { 'form': form, 'search_type': 'Resource' }, request)