diff options
author | Michael Elkins <melkins@tislabs.com> | 2010-10-27 00:15:10 +0000 |
---|---|---|
committer | Michael Elkins <melkins@tislabs.com> | 2010-10-27 00:15:10 +0000 |
commit | f46c88d5c75b58226663a65f8516a571bc4e3ae2 (patch) | |
tree | 407726d50b85e64ee4084b3e45679355c2112662 /portal-gui | |
parent | 1672b574f9b0b3cb2ee8c3b8a947ae2f411c4904 (diff) |
add support for uploading identity.xml and repository requests from rpkidemo
svn path=/portal-gui/rpkigui/myrpki/urls.py; revision=3497
Diffstat (limited to 'portal-gui')
-rw-r--r-- | portal-gui/rpkigui/myrpki/urls.py | 4 | ||||
-rw-r--r-- | portal-gui/rpkigui/myrpki/views.py | 43 |
2 files changed, 46 insertions, 1 deletions
diff --git a/portal-gui/rpkigui/myrpki/urls.py b/portal-gui/rpkigui/myrpki/urls.py index f172319c..db6d2b95 100644 --- a/portal-gui/rpkigui/myrpki/urls.py +++ b/portal-gui/rpkigui/myrpki/urls.py @@ -42,7 +42,9 @@ urlpatterns = patterns('', (r'^demo/down/asns/(?P<self_handle>[^/]+)$', views.download_asns), (r'^demo/down/myrpki/(?P<self_handle>[^/]+)$', views.download_myrpki_xml), (r'^demo/down/prefixes/(?P<self_handle>[^/]+)$', views.download_prefixes), - (r'^demo/down/roas/(?P<self_handle>[^/]+)$', views.download_roas) + (r'^demo/down/roas/(?P<self_handle>[^/]+)$', views.download_roas), + (r'^upload-parent-request/(?P<self_handle>[^/]+)$', views.upload_parent_request), + (r'^upload-repository-request/(?P<self_handle>[^/]+)$', views.upload_repository_request), ) # vim:sw=4 ts=8 expandtab diff --git a/portal-gui/rpkigui/myrpki/views.py b/portal-gui/rpkigui/myrpki/views.py index bc08b35a..79e3d6e2 100644 --- a/portal-gui/rpkigui/myrpki/views.py +++ b/portal-gui/rpkigui/myrpki/views.py @@ -26,6 +26,7 @@ from django.template import RequestContext from django.db import IntegrityError from django import http from django.views.generic.list_detail import object_list +from django.views.decorators.csrf import csrf_exempt from rpkigui.myrpki import models, forms, glue, misc, AllocationTree from rpkigui.myrpki.asnset import asnset @@ -489,4 +490,46 @@ def download_myrpki_xml(request, self_handle): conf = handle_or_404(request, self_handle) return serve_file(conf.handle, 'myrpki.xml', 'application/xml') +def get_parent_handle(conf): + "determine who my parent is. for now just assume its hardcoded into the django db" + parent_set = models.Parent.objects.filter(conf=conf) + if parent_set: + return parent_set[0].handle + else: + raise http.Http404, 'you have no parents' + +# FIXME: nasty hack: disable CSRF protection since rpkidemo doesn't GET a form +# prior to posting. +# FIXME: refactor common ports of the upload request handlers to remove dupe code +@csrf_exempt +def upload_parent_request(request, self_handle): + conf = handle_or_404(request, self_handle) + if request.method == 'POST': + input_file = tempfile.NamedTemporaryFile(delete=False) + input_file.write(request.POST['content']) + input_file.close() + parent_handle = get_parent_handle(conf) + args = ['configure_child', input_file.name ] + glue.invoke_rpki(parent_handle, args) + os.remove(input_file.name) + return serve_file(parent_handle, 'entitydb/children/%s.xml' % (self_handle,), 'application/xml') + return http.Http404, 'GET not implemented' + +# FIXME: nasty hack: disable CSRF protection since rpkidemo doesn't GET a form +# prior to posting. +@csrf_exempt +def upload_repository_request(request, self_handle): + conf = handle_or_404(request, self_handle) + if request.method == 'POST': + input_file = tempfile.NamedTemporaryFile(delete=False) + input_file.write(request.POST['content']) + input_file.close() + parent_handle = get_parent_handle(conf) + args = ['configure_publication_client', input_file.name ] + glue.invoke_rpki(parent_handle, args) + os.remove(input_file.name) + #FIXME: not sure which file gets sent back in this case + return serve_file(parent_handle, 'entitydb/repositories/%s.xml' % (self_handle,), 'application/xml') + return http.Http404, 'GET not implemented' + # vim:sw=4 ts=8 expandtab |