aboutsummaryrefslogtreecommitdiff
path: root/rpki/gui/app/views.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2016-03-30 03:44:36 +0000
committerRob Austein <sra@hactrn.net>2016-03-30 03:44:36 +0000
commitbc6e06a3aedc3108eed6763ea1624c791e981e08 (patch)
tree177149f90d96d4cd5c3bedee1e131e35261aef9e /rpki/gui/app/views.py
parentfa535af8d439db2e20b34c6e80b2ee86f4255f53 (diff)
Still more UID-swapped file I/O, and general cleanup of UI file I/O.
GUI no longer uses (an additional layer of) temporary files between itself and zookeeper. Zookeeper file read methods now take file-like objects. rpkic now opens input files as the real UID, then reverts back to the effective UID before handing the resulting file off to the zookeeper. This caught several more instances of rpkic file I/O that were not doing the real/effective UID swap properly while loading CSV and VCard files. As far as I can tell from testing, this didn't break anything that worked before. Whether it fixed all the file I/O problems remains to be seen. svn path=/branches/tk705/; revision=6339
Diffstat (limited to 'rpki/gui/app/views.py')
-rw-r--r--rpki/gui/app/views.py38
1 files changed, 5 insertions, 33 deletions
diff --git a/rpki/gui/app/views.py b/rpki/gui/app/views.py
index cd2f0e16..1c954765 100644
--- a/rpki/gui/app/views.py
+++ b/rpki/gui/app/views.py
@@ -23,7 +23,6 @@ __version__ = '$Id$'
import os
import os.path
-from tempfile import NamedTemporaryFile
import cStringIO
import csv
import logging
@@ -137,10 +136,6 @@ def generic_import(request, queryset, configure, form_class=None,
if request.method == 'POST':
form = form_class(request.POST, request.FILES)
if form.is_valid():
- tmpf = NamedTemporaryFile(prefix='import', suffix='.xml',
- delete=False)
- tmpf.write(form.cleaned_data['xml'].read())
- tmpf.close()
z = Zookeeper(handle=conf.handle)
handle = form.cleaned_data.get('handle')
# CharField uses an empty string for the empty value, rather than
@@ -151,7 +146,7 @@ def generic_import(request, queryset, configure, form_class=None,
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)
+ r = configure(z, form.cleaned_data['xml'], handle)
except lxml.etree.XMLSyntaxError as e:
logger.exception('caught XMLSyntaxError while parsing uploaded file')
messages.error(
@@ -168,8 +163,6 @@ def generic_import(request, queryset, configure, form_class=None,
url = queryset.get(issuer=conf,
handle=handle).get_absolute_url()
return http.HttpResponseRedirect(url)
- finally:
- os.remove(tmpf.name)
else:
form = form_class()
@@ -333,13 +326,10 @@ def import_asns(request):
if request.method == 'POST':
form = forms.ImportCSVForm(request.POST, request.FILES)
if form.is_valid():
- f = NamedTemporaryFile(prefix='asns', suffix='.csv', delete=False)
- f.write(request.FILES['csv'].read())
- f.close()
z = Zookeeper(handle=conf.handle, disable_signal_handlers=True)
try:
z.load_asns(
- f.name,
+ request.FILES['csv'],
ignore_missing_children=form.cleaned_data['ignore_missing_children']
)
except rpki.irdb.models.Child.DoesNotExist:
@@ -354,8 +344,6 @@ def import_asns(request):
z.run_rpkid_now()
messages.success(request, 'Successfully imported AS delgations from CSV file.')
return redirect(dashboard)
- finally:
- os.unlink(f.name)
else:
form = forms.ImportCSVForm()
return render(request, 'app/import_resource_form.html', {
@@ -382,13 +370,10 @@ def import_prefixes(request):
if request.method == 'POST':
form = forms.ImportCSVForm(request.POST, request.FILES)
if form.is_valid():
- f = NamedTemporaryFile(prefix='prefixes', suffix='.csv', delete=False)
- f.write(request.FILES['csv'].read())
- f.close()
z = Zookeeper(handle=conf.handle, disable_signal_handlers=True)
try:
z.load_prefixes(
- f.name,
+ request.FILES['csv'],
ignore_missing_children=form.cleaned_data['ignore_missing_children']
)
except rpki.irdb.models.Child.DoesNotExist:
@@ -400,8 +385,6 @@ def import_prefixes(request):
z.run_rpkid_now()
messages.success(request, 'Successfully imported AS delgations from CSV file.')
return redirect(dashboard)
- finally:
- os.unlink(f.name)
else:
form = forms.ImportCSVForm()
return render(request, 'app/import_resource_form.html', {
@@ -904,14 +887,10 @@ def roa_import(request):
if request.method == 'POST':
form = forms.ImportCSVForm(request.POST, request.FILES)
if form.is_valid():
- import tempfile
- tmp = tempfile.NamedTemporaryFile(suffix='.csv', prefix='roas', delete=False)
- tmp.write(request.FILES['csv'].read())
- tmp.close()
z = Zookeeper(handle=request.session['handle'],
disable_signal_handlers=True)
try:
- z.load_roa_requests(tmp.name)
+ z.load_roa_requests(request.FILES['csv'])
except rpki.csv_utils.BadCSVSyntax as e:
messages.error(request,
'CSV has bad syntax: %s' % (e,))
@@ -919,8 +898,6 @@ def roa_import(request):
z.run_rpkid_now()
messages.success(request, 'Successfully imported ROAs.')
return redirect(dashboard)
- finally:
- os.unlink(tmp.name)
else:
form = forms.ImportCSVForm()
return render(request, 'app/import_resource_form.html', {
@@ -1452,14 +1429,9 @@ class RouterImportView(FormView):
def form_valid(self, form):
conf = get_conf(self.request.user, self.request.session['handle'])
- tmpf = NamedTemporaryFile(prefix='import', suffix='.xml',
- delete=False)
- tmpf.write(form.cleaned_data['xml'].read())
- tmpf.close()
z = Zookeeper(handle=conf.handle, disable_signal_handlers=True)
- z.add_router_certificate_request(tmpf.name)
+ z.add_router_certificate_request(form.cleaned_data['xml'])
z.run_rpkid_now()
- os.remove(tmpf.name)
return super(RouterImportView, self).form_valid(form)
def get_context_data(self, **kwargs):