diff options
Diffstat (limited to 'rpkid/rpki/gui/cacheview')
10 files changed, 245 insertions, 156 deletions
diff --git a/rpkid/rpki/gui/cacheview/forms.py b/rpkid/rpki/gui/cacheview/forms.py index cc33016e..28b8ff24 100644 --- a/rpkid/rpki/gui/cacheview/forms.py +++ b/rpkid/rpki/gui/cacheview/forms.py @@ -1,19 +1,19 @@ -# $Id$ -""" -Copyright (C) 2011 SPARTA, Inc. dba Cobham Analytic Solutions - -Permission to use, copy, modify, and distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND SPARTA DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS. IN NO EVENT SHALL SPARTA BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. -""" +# Copyright (C) 2011 SPARTA, Inc. dba Cobham Analytic Solutions +# Copyright (C) 2013 SPARTA, Inc. a Parsons Company +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND SPARTA DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL SPARTA BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +__version__ = '$Id$' from django import forms @@ -21,6 +21,7 @@ from rpki.gui.cacheview.misc import parse_ipaddr from rpki.exceptions import BadIPResource from rpki.resource_set import resource_range_as + class SearchForm(forms.Form): asn = forms.CharField(required=False, help_text='AS or range', label='AS') addr = forms.CharField(required=False, max_length=40, help_text='range/CIDR', label='IP Address') @@ -44,3 +45,7 @@ class SearchForm(forms.Form): # raise forms.ValidationError, 'invalid IP address range/prefix' return self.cleaned_data + + +class SearchForm2(forms.Form): + resource = forms.CharField(required=True) diff --git a/rpkid/rpki/gui/cacheview/models.py b/rpkid/rpki/gui/cacheview/models.py index 1fbed743..66ff8282 100644 --- a/rpkid/rpki/gui/cacheview/models.py +++ b/rpkid/rpki/gui/cacheview/models.py @@ -19,6 +19,7 @@ from datetime import datetime import time from django.db import models +from django.core.urlresolvers import reverse import rpki.resource_set import rpki.gui.models @@ -116,7 +117,7 @@ class SignedObject(models.Model): return bad, else if there are any warn status, return warn, else return good. """ for x in reversed(kinds): - if self.statuses.filter(generation=generations_dict['current'], status__kind=x[0]): + if self.repo.statuses.filter(generation=generations_dict['current'], status__kind=x[0]): return x[1] return None # should not happen @@ -134,9 +135,8 @@ class Cert(SignedObject): issuer = models.ForeignKey('self', related_name='children', null=True) sia = models.CharField(max_length=255) - @models.permalink def get_absolute_url(self): - return ('rpki.gui.cacheview.views.cert_detail', [str(self.pk)]) + return reverse('cert-detail', args=[str(self.pk)]) def get_cert_chain(self): """Return a list containing the complete certificate chain for this @@ -203,9 +203,8 @@ class ROA(SignedObject): prefixes_v6 = models.ManyToManyField(ROAPrefixV6, related_name='roas') issuer = models.ForeignKey('Cert', related_name='roas') - @models.permalink def get_absolute_url(self): - return ('rpki.gui.cacheview.views.roa_detail', [str(self.pk)]) + return reverse('roa-detail', args=[str(self.pk)]) class Meta: ordering = ('asid',) @@ -221,9 +220,9 @@ class Ghostbuster(SignedObject): telephone = TelephoneField(blank=True, null=True) issuer = models.ForeignKey('Cert', related_name='ghostbusters') - @models.permalink def get_absolute_url(self): - return ('rpki.gui.cacheview.views.ghostbuster_detail', [str(self.pk)]) + # note that ghostbuster-detail is different from gbr-detail! sigh + return reverse('ghostbuster-detail', args=[str(self.pk)]) def __unicode__(self): if self.full_name: diff --git a/rpkid/rpki/gui/cacheview/templates/cacheview/cacheview_base.html b/rpkid/rpki/gui/cacheview/templates/cacheview/cacheview_base.html index 9831e0cb..ec71d740 100644 --- a/rpkid/rpki/gui/cacheview/templates/cacheview/cacheview_base.html +++ b/rpkid/rpki/gui/cacheview/templates/cacheview/cacheview_base.html @@ -1,17 +1,10 @@ {% extends "base.html" %} - -{% block css %} -.good { background-color: #77ff77 } -.warn { background-color: yellow } -.bad { background-color: #ff5500 } -.section { border-width:thin; border-style:solid; border-color:black; margin-top:1em; padding:1em } -{% endblock %} +{% load url from future %} {% block sidebar %} -<ul class='compact'> - <li><a href="/cacheview/search">resource search</a> - <li><a href="/cacheview/query">roa search</a> - <li><a href="/rpki/">rpki dashboard</a> -</ul> +<form method='post' action='{% url 'res-search' %}'> + {% csrf_token %} + <input type='text' id='id_resource' name='resource' placeholder='prefix or AS'> + <button type='submit'>Search</button> +</form> {% endblock %} - diff --git a/rpkid/rpki/gui/cacheview/templates/cacheview/cert_detail.html b/rpkid/rpki/gui/cacheview/templates/cacheview/cert_detail.html index 9ff304a2..256e7780 100644 --- a/rpkid/rpki/gui/cacheview/templates/cacheview/cert_detail.html +++ b/rpkid/rpki/gui/cacheview/templates/cacheview/cert_detail.html @@ -8,8 +8,11 @@ Resource Certificate Detail <h2>RFC3779 Resources</h2> -<table> +<table class='table table-striped'> + <thead> <tr><th>AS Ranges</th><th>IP Ranges</th></tr> + </thead> + <tbody> <tr> <td style='text-align:left;vertical-align:top'> <ul class='compact'> @@ -26,6 +29,7 @@ Resource Certificate Detail </ul> </td> </tr> + </tbody> </table> <div class='section'> @@ -36,15 +40,18 @@ Resource Certificate Detail <li> <h3>Ghostbusters</h3> -<table> - <tr><th>Name</th><th>Valid</th><th>Until</th></tr> +<table class='table table-striped'> + <thead> + <tr><th>Name</th><th>Expires</th></tr> + </thead> + <tbody> {% for g in object.ghostbusters.all %} <tr class='{{ g.status_id }}'> <td><a href="{{ g.get_absolute_url }}">{{ g }}</a></td> - <td>{{ g.is_valid }}</td> <td>{{ g.not_after }}</td> </tr> + </tbody> {% endfor %} </table> @@ -53,37 +60,41 @@ Resource Certificate Detail {% if object.roas.all %} <li> <h3>ROAs</h3> -<table> - <tr><th>Prefix</th><th>AS</th><th>Valid</th><th>Until</th></tr> +<table class='table table-striped'> + <thead> + <tr><th>#</th><th>Prefix</th><th>AS</th><th>Expires</th></tr> + </thead> + <tbody> {% for roa in object.roas.all %} {% for pfx in roa.prefixes.all %} <tr class='{{ roa.status_id }}'> + <td><a href="{{ roa.get_absolute_url }}">#</a></td> <td>{{ pfx }}</td> <td>{{ roa.asid }}</td> - <td><a href="{{ roa.get_absolute_url }}">{{ roa.is_valid }}</a></td> <td>{{ roa.not_after }}</td> </tr> {% endfor %} {% endfor %} + </tbody> </table> {% endif %} {% if object.children.all %} <li> <h3>Children</h3> -<table> - <tr><th>Name</th><th>SIA</th><th>Valid</th><th>Until</th><th>Ghostbuster</th></tr> +<table class='table table-striped'> + <thead> + <tr><th>Name</th><th>Expires</th></tr> + </thead> + <tbody> {% for child in object.children.all %} <tr class='{{ child.status_id }}'> <td><a href="{{ child.get_absolute_url }}">{{ child.name }}</a></td> - <td>{{ child.sia }}</td> - <td>{{ child.is_valid }}</td> <td>{{ child.not_after }}</td> - <td><a href="{{ child.ghostbusters.all.0.get_absolute_url }}">{{ child.ghostbusters.all.0 }}</a></td> </tr> {% endfor %} - + </tbody> </table> {% endif %} diff --git a/rpkid/rpki/gui/cacheview/templates/cacheview/ghostbuster_detail.html b/rpkid/rpki/gui/cacheview/templates/cacheview/ghostbuster_detail.html index d179e7c2..4215f757 100644 --- a/rpkid/rpki/gui/cacheview/templates/cacheview/ghostbuster_detail.html +++ b/rpkid/rpki/gui/cacheview/templates/cacheview/ghostbuster_detail.html @@ -4,7 +4,7 @@ {% block detail %} <p> -<table> +<table class='table'> <tr><td>Full Name</td><td>{{ object.full_name }}</td></tr> <tr><td>Organization</td><td>{{ object.organization }}</td></tr> <tr><td>Email</td><td>{{ object.email_address }}</td></tr> diff --git a/rpkid/rpki/gui/cacheview/templates/cacheview/global_summary.html b/rpkid/rpki/gui/cacheview/templates/cacheview/global_summary.html new file mode 100644 index 00000000..0dbd0ffc --- /dev/null +++ b/rpkid/rpki/gui/cacheview/templates/cacheview/global_summary.html @@ -0,0 +1,26 @@ +{% extends "cacheview/cacheview_base.html" %} + +{% block content %} +<div class='page-header'> + <h1>Browse Global RPKI</h1> +</div> + +<table class="table table-striped"> + <thead> + <tr> + <th>Name</th> + <th>Expires</th> + <th>URI</th> + </tr> + </thead> + <tbody> + {% for r in roots %} + <tr> + <td><a href="{{ r.get_absolute_url }}">{{ r.name }}</a></td> + <td>{{ r.not_after }}</td> + <td>{{ r.repo.uri }}</td> + </tr> + {% endfor %} + </tbody> +</table> +{% endblock content %} diff --git a/rpkid/rpki/gui/cacheview/templates/cacheview/search_result.html b/rpkid/rpki/gui/cacheview/templates/cacheview/search_result.html index 3756047f..7cbf852e 100644 --- a/rpkid/rpki/gui/cacheview/templates/cacheview/search_result.html +++ b/rpkid/rpki/gui/cacheview/templates/cacheview/search_result.html @@ -2,7 +2,9 @@ {% block content %} -<h1>Search Results</h1> +<div class='page-header'> + <h1>Search Results <small>{{ resource }}</small></h1> +</div> <h2>Matching Resource Certificates</h2> {% if certs %} @@ -17,15 +19,24 @@ <h2>Matching ROAs</h2> {% if roas %} -<ul> +<table class='table table-striped'> + <thead> + <tr> + <th>#</th><th>Prefix</th><th>AS</th> + </tr> + </thead> + <tbody> {% for roa in roas %} -<li><a href="{{ roa.get_absolute_url }}">{{ roa }}</a> +<tr> + <td><a href="{{ roa.get_absolute_url }}">#</a></td> + <td>{{ roa.prefixes.all.0 }}</td> + <td>{{ roa.asid }}</td> +</tr> {% endfor %} -</ul> +</tbody> +</table> {% else %} <p>none</p> {% endif %} -<p><a href="{% url rpki.gui.cacheview.views.search_view %}">new search</a> - {% endblock %} diff --git a/rpkid/rpki/gui/cacheview/templates/cacheview/signedobject_detail.html b/rpkid/rpki/gui/cacheview/templates/cacheview/signedobject_detail.html index b5f629d8..22ae3d27 100644 --- a/rpkid/rpki/gui/cacheview/templates/cacheview/signedobject_detail.html +++ b/rpkid/rpki/gui/cacheview/templates/cacheview/signedobject_detail.html @@ -1,38 +1,55 @@ {% extends "cacheview/cacheview_base.html" %} {% block content %} +<div class='page-header'> <h1>{% block title %}Signed Object Detail{% endblock %}</h1> +</div> + +<h2>Cert Info</h2> +<table class='table table-striped'> + <tr><td>Subject Name</td><td>{{ object.name }}</td></tr> + <tr><td>SKI</td><td>{{ object.keyid }}</td></tr> + {% if object.sia %} + <tr><td>SIA</td><td>{{ object.sia }}</td></tr> + {% endif %} + <tr><td>Not Before</td><td>{{ object.not_before }}</td></tr> + <tr><td>Not After</td><td>{{ object.not_after }}</td></tr> +</table> <h2>Metadata</h2> -<table> - <tr><td>URI</td><td>{{ object.uri }}</td></tr> +<table class='table table-striped'> + <tr><td>URI</td><td>{{ object.repo.uri }}</td></tr> <tr><td>Last Modified</td><td>{{ object.mtime_as_datetime|date:"DATETIME_FORMAT" }}</td></tr> </table> -<h3>Validation Status</h3> -<table> +<h2>Validation Status</h2> +<table class='table table-striped'> + <thead> <tr><th>Timestamp</th><th>Generation</th><th>Status</th></tr> - {% for status in object.statuses.all %} + </thead> + <tbody> + {% for status in object.repo.statuses.all %} <tr class="{{ status.status.get_kind_display }}"><td>{{ status.timestamp }}</td><td>{{ status.get_generation_display }}</td><td>{{ status.status.status }}</td></tr> {% endfor %} + </tbody> </table> <h2>X.509 Certificate Chain</h2> -<table> - <tr><th>Depth</th><th>Name</th><th>SIA</th><th>Valid</th><th>Until</th><th>Ghostbuster</th></tr> +<table class='table table-striped'> + <thead> + <tr><th>Depth</th><th>Name</th></tr> + </thead> + <tbody> {% for cert in chain %} <tr class='{{ cert.1.status_id }}'> <td>{{ cert.0 }}</td> <td><a href="{{ cert.1.get_absolute_url }}">{{ cert.1.name }}</a></td> - <td>{{ cert.1.sia }}</td> - <td>{{ cert.1.is_valid }}</td> - <td>{{ cert.1.not_after }}</td> - <td><a href="{{ cert.1.ghostbusters.all.0.get_absolute_url }}">{{ cert.1.ghostbusters.all.0 }}</a></td> </tr> {% endfor %} +</tbody> </table> diff --git a/rpkid/rpki/gui/cacheview/urls.py b/rpkid/rpki/gui/cacheview/urls.py index 49634ed8..cc03a587 100644 --- a/rpkid/rpki/gui/cacheview/urls.py +++ b/rpkid/rpki/gui/cacheview/urls.py @@ -1,30 +1,32 @@ -# $Id$ -""" -Copyright (C) 2011 SPARTA, Inc. dba Cobham Analytic Solutions +# Copyright (C) 2011 SPARTA, Inc. dba Cobham Analytic Solutions +# Copyright (C) 2013 SPARTA, Inc. a Parsons Company +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND SPARTA DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL SPARTA BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. -Permission to use, copy, modify, and distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. +__version__ = '$Id$' -THE SOFTWARE IS PROVIDED "AS IS" AND SPARTA DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS. IN NO EVENT SHALL SPARTA BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. -""" - -from django.conf.urls import patterns +from django.conf.urls import patterns, url +from rpki.gui.cacheview.views import (CertDetailView, RoaDetailView, + GhostbusterDetailView) urlpatterns = patterns('', - (r'^query$', 'rpki.gui.cacheview.views.query_view'), - (r'^search$', 'rpki.gui.cacheview.views.search_view'), - (r'^as/(?P<pk>[^/]+)$', 'rpki.gui.cacheview.views.asrange_detail'), - (r'^addr/(?P<pk>[^/]+)$', 'rpki.gui.cacheview.views.addressrange_detail'), - (r'^cert/(?P<pk>[^/]+)$', 'rpki.gui.cacheview.views.cert_detail'), - (r'^gbr/(?P<pk>[^/]+)$', 'rpki.gui.cacheview.views.ghostbuster_detail'), - (r'^roa/(?P<pk>[^/]+)$', 'rpki.gui.cacheview.views.roa_detail'), + url(r'^search$', 'rpki.gui.cacheview.views.search_view', + name='res-search'), + url(r'^cert/(?P<pk>[^/]+)$', CertDetailView.as_view(), name='cert-detail'), + url(r'^gbr/(?P<pk>[^/]+)$', GhostbusterDetailView.as_view(), + name='ghostbuster-detail'), + url(r'^roa/(?P<pk>[^/]+)$', RoaDetailView.as_view(), name='roa-detail'), + (r'^$', 'rpki.gui.cacheview.views.global_summary'), ) # vim:sw=4 ts=8 expandtab diff --git a/rpkid/rpki/gui/cacheview/views.py b/rpkid/rpki/gui/cacheview/views.py index ffb04136..94870eb2 100644 --- a/rpkid/rpki/gui/cacheview/views.py +++ b/rpkid/rpki/gui/cacheview/views.py @@ -1,92 +1,104 @@ -""" -Copyright (C) 2011 SPARTA, Inc. dba Cobham Analytic Solutions - -Permission to use, copy, modify, and distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND SPARTA DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS. IN NO EVENT SHALL SPARTA BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. -""" - -from django.views.generic import list_detail -from django.shortcuts import get_object_or_404, redirect +# Copyright (C) 2011 SPARTA, Inc. dba Cobham Analytic Solutions +# Copyright (C) 2013 SPARTA, Inc. a Parsons Company +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND SPARTA DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL SPARTA BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +__version__ = '$Id$' + +from django.views.generic import DetailView +from django.shortcuts import render +from django.db.models import F from rpki.gui.cacheview import models, forms, misc -from rpki.gui.app.views import render -from rpki.resource_set import resource_range_as +from rpki.resource_set import resource_range_as, resource_range_ip from rpki.POW import IPAddress +from rpki.exceptions import BadIPResource -# Create your views here. def cert_chain(obj): """ returns an iterator covering all certs from the root cert down to the EE. """ - chain = [ obj ] + chain = [obj] while obj != obj.issuer: obj = obj.issuer chain.append(obj) return zip(range(len(chain)), reversed(chain)) -def signed_object_detail(request, model_class, pk): - """ - wrapper around object_detail which fetches the x.509 cert chain for signed - objects. - """ - obj = get_object_or_404(model_class, pk=pk) - return list_detail.object_detail(request, queryset=model_class.objects.all(), - object_id=pk, extra_context={ 'chain': cert_chain(obj) }) -def addressrange_detail(request, pk): - return list_detail.object_detail(request, models.AddressRange.objects.all(), pk) +class SignedObjectDetailView(DetailView): + def get_context_data(self, **kwargs): + context = super(SignedObjectDetailView, + self).get_context_data(**kwargs) + context['chain'] = cert_chain(self.object) + return context -def asrange_detail(request, pk): - return list_detail.object_detail(request, models.ASRange.objects.all(), pk) -def roa_detail(request, pk): - return signed_object_detail(request, models.ROA, pk) +class RoaDetailView(SignedObjectDetailView): + model = models.ROA -def cert_detail(request, pk): - return signed_object_detail(request, models.Cert, pk) -def ghostbuster_detail(request, pk): - return signed_object_detail(request, models.Ghostbuster, pk) +class CertDetailView(SignedObjectDetailView): + model = models.Cert -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) +class GhostbusterDetailView(SignedObjectDetailView): + model = models.Ghostbuster - 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) +def search_view(request): + certs = None + roas = None -def cmp_prefix(x,y): + 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}) + + +def cmp_prefix(x, y): r = cmp(x[0].family, y[0].family) if r == 0: - r = cmp(x[2], y[2]) # integer address + r = cmp(x[2], y[2]) # integer address if r == 0: r = cmp(x[0].bits, y[0].bits) if r == 0: @@ -95,13 +107,15 @@ def cmp_prefix(x,y): r = cmp(x[1].asid, y[1].asid) return r + #def cmp_prefix(x,y): # for attr in ('family', 'prefix', 'bits', 'max_length'): # r = cmp(getattr(x[0], attr), getattr(y[0], attr)) # if r: # return r # return cmp(x[1].asid, y[1].asid) - + + def query_view(request): """ Allow the user to search for an AS or prefix, and show all published ROA @@ -138,10 +152,21 @@ def query_view(request): prefix_list.sort(cmp=cmp_prefix) return render('cacheview/query_result.html', - { 'object_list': prefix_list }, request) + {'object_list': prefix_list}, request) else: form = forms.SearchForm() - return render('cacheview/search_form.html', { 'form':form, 'search_type': 'ROA ' }, request) + return render('cacheview/search_form.html', { + 'form': form, 'search_type': 'ROA '}, request) + + +def global_summary(request): + """Display a table summarizing the state of the global RPKI.""" + + roots = models.Cert.objects.filter(issuer=F('pk')) # self-signed + + return render(request, 'cacheview/global_summary.html', { + 'roots': roots + }) # vim:sw=4 ts=8 expandtab |