def get(self, request, result_id): """ There has to be GET: path='...' """ r = get_object_or_404(Result, id=result_id) result_dir = r.get_result_dir() try: relative_file_path = request.GET['path'] except KeyError: return return_error(request, "Can\'t open a file because there is no path specified.") if not relative_file_path: return return_error(request, "Can\'t open a file because file path is empty.") file_path = os.path.abspath(os.path.join(result_dir, relative_file_path)) if not file_path.startswith(result_dir): return return_error(request, "You are not allowed to access file '%s'." % relative_file_path) try: f = open(file_path, 'r') except IOError: raise Http404('Can\'t open file \'%s\'' % relative_file_path) response = HttpResponse(f, mimetype='text/plain') response["Content-Length"] = os.path.getsize(file_path) return response
def get(self, request, result_id): """ There has to be GET: path='...' """ r = get_object_or_404(Result, id=result_id) result_dir = r.get_result_dir() try: relative_file_path = request.GET['path'] except KeyError: return return_error( request, "Can\'t open a file because there is no path specified.") if not relative_file_path: return return_error( request, "Can\'t open a file because file path is empty.") file_path = os.path.abspath( os.path.join(result_dir, relative_file_path)) if not file_path.startswith(result_dir): return return_error( request, "You are not allowed to access file '%s'." % relative_file_path) try: f = open(file_path, 'r') except IOError: raise Http404('Can\'t open file \'%s\'' % relative_file_path) response = HttpResponse(f, mimetype='text/plain') response["Content-Length"] = os.path.getsize(file_path) return response
def get(self, request, *args, **kwargs): #localhost = Host.localhost() #run_object = Run.objects.create_for_host(localhost) from report.runner import run #run(request, run_object) try: run(request) except RuntimeError as ex: return return_error(request, str(ex)) except Exception as ex: logger.critical(traceback.format_exc()) return return_error(request, 'There was an error: \'%s\'' % str(ex)) return HttpResponseRedirect(reverse('results-list'))