diff options
author | Michael Elkins <melkins@tislabs.com> | 2014-11-26 22:30:27 +0000 |
---|---|---|
committer | Michael Elkins <melkins@tislabs.com> | 2014-11-26 22:30:27 +0000 |
commit | cb8308e2fd1292e09bb523115180e2d9165012d0 (patch) | |
tree | af9e101515a303613520480176c87ea25a7a3d23 | |
parent | c0d2779fdd8b002ef90c6204e5a755325566feaa (diff) |
catch lxml.etree.XMLSyntaxError and notify the user when the uploaded XML file was invalid. closes #736
svn path=/trunk/; revision=6038
-rw-r--r-- | rpki/gui/app/views.py | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/rpki/gui/app/views.py b/rpki/gui/app/views.py index f7492434..c739b55e 100644 --- a/rpki/gui/app/views.py +++ b/rpki/gui/app/views.py @@ -27,6 +27,7 @@ from tempfile import NamedTemporaryFile import cStringIO import csv import logging +import lxml.etree from django.utils.decorators import method_decorator from django.contrib.auth.decorators import login_required @@ -146,19 +147,28 @@ def generic_import(request, queryset, configure, form_class=None, # expects it. if handle == '': handle = None - # configure_repository returns None, so can't use tuple expansion - # here. Unpack the tuple below if post_import_redirect is None. - r = configure(z, tmpf.name, handle) - # force rpkid run now - z.synchronize_ca(poke=True) - os.remove(tmpf.name) - if post_import_redirect: - url = post_import_redirect + try: + # configure_repository returns None, so can't use tuple expansion + # here. Unpack the tuple below if post_import_redirect is None. + r = configure(z, tmpf.name, handle) + except lxml.etree.XMLSyntaxError as e: + logger.exception('caught XMLSyntaxError while parsing uploaded file') + messages.error( + request, + 'The uploaded file has an invalid XML syntax' + ) else: - _, handle = r - url = queryset.get(issuer=conf, - handle=handle).get_absolute_url() - return http.HttpResponseRedirect(url) + # force rpkid run now + z.synchronize_ca(poke=True) + if post_import_redirect: + url = post_import_redirect + else: + _, handle = r + url = queryset.get(issuer=conf, + handle=handle).get_absolute_url() + return http.HttpResponseRedirect(url) + finally: + os.remove(tmpf.name) else: form = form_class() |