diff options
author | Michael Elkins <melkins@tislabs.com> | 2011-02-15 19:36:07 +0000 |
---|---|---|
committer | Michael Elkins <melkins@tislabs.com> | 2011-02-15 19:36:07 +0000 |
commit | a3b3b13969cf98a5b1c4328bd4dca641b7be003c (patch) | |
tree | aa5ca8962231ef1229362675757511a1ee443aa4 /rpkid | |
parent | 0b6b025debcd4a43cb1407c98936e17fc6b13e1d (diff) |
Use the request.META['wsgi.errors'] log object instead of writing to sys.stderr so that log entries will show up in the virtual host specific log files.
svn path=/rpkid/rpki/gui/app/glue.py; revision=3680
Diffstat (limited to 'rpkid')
-rw-r--r-- | rpkid/rpki/gui/app/glue.py | 18 | ||||
-rw-r--r-- | rpkid/rpki/gui/app/views.py | 22 |
2 files changed, 22 insertions, 18 deletions
diff --git a/rpkid/rpki/gui/app/glue.py b/rpkid/rpki/gui/app/glue.py index 4e364e1a..0a5e9af3 100644 --- a/rpkid/rpki/gui/app/glue.py +++ b/rpkid/rpki/gui/app/glue.py @@ -50,13 +50,13 @@ def conf(handle): # print >>conf, template % data # invoke_rpki(handle, ['initialize']) -def invoke_rpki(handle, args): +def invoke_rpki(log, handle, args): """Invoke the myrpki cli for the specified configuration.""" myrpki_dir = conf(handle) config = myrpki_dir + '/rpki.conf' # default rpki.conf uses relative paths, so chdir() to the repo first cmd = 'cd %s && %s %s' % (myrpki_dir, settings.MYRPKI, ' '.join(['--config=' + config] + args)) - print >>sys.stderr, 'invoking', cmd + print >>log, 'invoking', cmd os.system(cmd) def read_file_from_handle(handle, fname): @@ -107,13 +107,13 @@ def output_roas(path, handle): w.writerows([req.as_roa_prefix(), req.roa.asn, '%s-group-%d' % (handle.handle, req.roa.pk)] for req in qs) -def configure_daemons(handle): +def configure_daemons(log, handle): args = ['configure_daemons'] for hosted in handle.hosting.all(): args.append(conf(hosted.handle) + '/myrpki.xml') - invoke_rpki(handle.handle, args) + invoke_rpki(log, handle.handle, args) -def configure_resources(handle): +def configure_resources(log, handle): '''Write out the csv files and invoke the myrpki.py command line tool.''' # chdir to the repo dir since the default rpki.conf uses relative # pathnames.. @@ -126,14 +126,14 @@ def configure_resources(handle): if not run_rpkidemo: run_rpkid = cfg.getboolean('run_rpkid') if run_rpkid: - configure_daemons(handle) + configure_daemons(log, handle) else: - invoke_rpki(handle.handle, ['configure_resources']) + invoke_rpki(log, handle.handle, ['configure_resources']) # send the myrpki.xml to the rpkid hosting me - configure_daemons(handle.host) + configure_daemons(log, handle.host) # process the response - invoke_rpki(handle.handle, ['configure_resources']) + invoke_rpki(log, handle.handle, ['configure_resources']) # vim:sw=4 ts=8 expandtab diff --git a/rpkid/rpki/gui/app/views.py b/rpkid/rpki/gui/app/views.py index 243aa2a2..77360d7d 100644 --- a/rpkid/rpki/gui/app/views.py +++ b/rpkid/rpki/gui/app/views.py @@ -274,7 +274,7 @@ class PrefixAllocateView(PrefixView): if self.form.is_valid(): self.obj.allocated = self.form.cleaned_data['child'] self.obj.save() - glue.configure_resources(self.handle) + glue.configure_resources(self.request.META['wsgi.errors'], self.handle) return http.HttpResponseRedirect(self.obj.get_absolute_url()) @handle_required @@ -316,7 +316,7 @@ class PrefixRoaView(PrefixView): def form_valid(self): asns = asnset(self.form.cleaned_data['asns']) add_roa_requests(self.handle, self.obj, asns, self.form.cleaned_data['max_length']) - glue.configure_resources(self.handle) + glue.configure_resources(self.request.META['wsgi.errors'], self.handle) return http.HttpResponseRedirect(self.obj.get_absolute_url()) @handle_required @@ -336,6 +336,7 @@ def prefix_delete_view(request, pk): @handle_required def roa_request_delete_view(request, pk): '''Remove a roa request from a particular prefix.''' + log = request.META['wsgi.errors'] handle = request.session['handle'] obj = get_object_or_404(models.RoaRequest.objects, pk=pk) prefix = obj.prefix @@ -346,12 +347,13 @@ def roa_request_delete_view(request, pk): obj.delete() if not roa.from_roa_request.all(): roa.delete() - glue.configure_resources(handle) + glue.configure_resources(log, handle) return http.HttpResponseRedirect(prefix.get_absolute_url()) @handle_required def asn_allocate_view(request, pk): + log = request.META['wsgi.errors'] handle = request.session['handle'] obj = get_object_or_404(models.Asn.objects, pk=pk) # ensure this resource range belongs to a parent of the current conf @@ -362,7 +364,7 @@ def asn_allocate_view(request, pk): if form.is_valid(): obj.allocated = form.cleaned_data['child'] obj.save() - glue.configure_resources(handle) + glue.configure_resources(log, handle) return http.HttpResponseRedirect(obj.get_absolute_url()) else: form = forms.PrefixAllocateForm(obj.allocated.pk if obj.allocated else None, @@ -477,20 +479,20 @@ def myrpki_xml(request, self_handle): will be required to complete the parent-child setup. """ conf = handle_or_404(request, self_handle) + log = request.META['wsgi.errors'] if request.method == 'POST': fname = glue.conf(self_handle) + '/myrpki.xml' if not os.path.exists(fname): - sys.stderr.write('Saving a copy of myrpki.xml for handle %s to inbox\n' % conf.handle) + print >>log, 'Saving a copy of myrpki.xml for handle %s to inbox' % conf.handle save_to_inbox(conf, 'myrpki', request.POST['content']) - sys.stderr.write('writing %s\n' % fname) - + print >>log, 'writing %s' % fname with open(fname, 'w') as myrpki_xml : myrpki_xml.write(request.POST['content']) - glue.configure_daemons(conf.host) + glue.configure_daemons(log, conf.host) return serve_file(self_handle, 'myrpki.xml', 'application/xml') @@ -502,15 +504,17 @@ def login(request): view will return 200 with the login page when the login fails, which is not desirable when using rpkidemo. """ + log = request.META['wsgi.errors'] if request.method == 'POST': username = request.POST['username'] password = request.POST['password'] + print >>log, 'login request for user %s' % username user = auth.authenticate(username=username, password=password) if user is not None and user.is_active: auth.login(request, user) return http.HttpResponse('<p>login succeeded</p>') - sys.stderr.write('failed login attempt for user %s\n' % username) + print >>log, 'failed login attempt for user %s\n' % username return http.HttpResponseForbidden('<p>bad username or password</p>') else: return http.HttpResponse('<p>This should never been seen by a human</p>') |