Exemple #1
0
def custom_report(request):
    # saving the report
    form = CustomReportJsonForm(request.POST)

    if form.is_valid():
        selected_widgets = report_widget_factory(
            json_data=request.POST['json'],
            request=request,
            user=request.user,
            finding_notes=False)
        report_name = 'Custom PDF Report: ' + request.user.username
        report_format = 'AsciiDoc'
        finding_notes = True

        if 'report-options' in selected_widgets:
            options = selected_widgets['report-options']
            report_name = 'Custom PDF Report: ' + options.report_name
            report_format = options.report_type
            finding_notes = (options.include_finding_notes == '1')

        selected_widgets = report_widget_factory(
            json_data=request.POST['json'],
            request=request,
            user=request.user,
            finding_notes=finding_notes)

        if report_format == 'PDF':
            report = Report(name=report_name,
                            type="Custom",
                            format=report_format,
                            requester=request.user,
                            task_id='tbd',
                            options=request.POST['json'])
            report.save()
            async_custom_pdf_report.delay(
                report=report,
                template="dojo/custom_pdf_report.html",
                filename="custom_pdf_report.pdf",
                host=request.scheme + "://" + request.META['HTTP_HOST'],
                user=request.user,
                uri=request.build_absolute_uri(report.get_url()),
                finding_notes=finding_notes)
            messages.add_message(
                request,
                messages.SUCCESS,
                'Your report is building, you will receive an email when it is ready.',
                extra_tags='alert-success')

            return HttpResponseRedirect(reverse('reports'))
        elif report_format == 'AsciiDoc':
            widgets = selected_widgets.values()
            return render(request, 'dojo/custom_asciidoc_report.html', {
                "widgets": widgets,
                "finding_notes": finding_notes
            })
        else:
            return HttpResponseForbidden()
    else:
        return HttpResponseForbidden()
def custom_report(request):
    # saving the report
    form = CustomReportJsonForm(request.POST)
    host = report_url_resolver(request)
    if form.is_valid():
        selected_widgets = report_widget_factory(json_data=request.POST['json'], request=request, user=request.user,
                                                 finding_notes=False, finding_images=False, host=host)
        report_name = 'Custom PDF Report: ' + request.user.username
        report_format = 'AsciiDoc'
        finding_notes = True
        finding_images = True

        if 'report-options' in selected_widgets:
            options = selected_widgets['report-options']
            report_name = 'Custom PDF Report: ' + options.report_name
            report_format = options.report_type
            finding_notes = (options.include_finding_notes == '1')
            finding_images = (options.include_finding_images == '1')

        selected_widgets = report_widget_factory(json_data=request.POST['json'], request=request, user=request.user,
                                                 finding_notes=finding_notes, finding_images=finding_images, host=host)

        if report_format == 'PDF':
            report = Report(name=report_name,
                            type="Custom",
                            format=report_format,
                            requester=request.user,
                            task_id='tbd',
                            options=request.POST['json'])
            report.save()
            async_custom_pdf_report.delay(report=report,
                                          template="dojo/custom_pdf_report.html",
                                          filename="custom_pdf_report.pdf",
                                          host=host,
                                          user=request.user,
                                          uri=request.build_absolute_uri(report.get_url()),
                                          finding_notes=finding_notes,
                                          finding_images=finding_images)
            messages.add_message(request, messages.SUCCESS,
                                 'Your report is building, you will receive an email when it is ready.',
                                 extra_tags='alert-success')

            return HttpResponseRedirect(reverse('reports'))
        elif report_format == 'AsciiDoc':
            widgets = selected_widgets.values()
            return render(request,
                          'dojo/custom_asciidoc_report.html',
                          {"widgets": widgets,
                           "host": host,
                           "finding_notes": finding_notes,
                           "finding_images": finding_images,
                           "user_id": request.user.id})
        else:
            return HttpResponseForbidden()
    else:
        return HttpResponseForbidden()
Exemple #3
0
def custom_report(request):
    # saving the report
    form = CustomReportJsonForm(request.POST)
    host = report_url_resolver(request)
    if form.is_valid():
        selected_widgets = report_widget_factory(
            json_data=request.POST['json'],
            request=request,
            user=request.user,
            finding_notes=False,
            finding_images=False,
            host=host)
        report_format = 'AsciiDoc'
        finding_notes = True
        finding_images = True

        if 'report-options' in selected_widgets:
            options = selected_widgets['report-options']
            report_format = options.report_type
            finding_notes = (options.include_finding_notes == '1')
            finding_images = (options.include_finding_images == '1')

        selected_widgets = report_widget_factory(
            json_data=request.POST['json'],
            request=request,
            user=request.user,
            finding_notes=finding_notes,
            finding_images=finding_images,
            host=host)

        if report_format == 'AsciiDoc':
            widgets = list(selected_widgets.values())
            return render(
                request, 'dojo/custom_asciidoc_report.html', {
                    "widgets": widgets,
                    "host": host,
                    "finding_notes": finding_notes,
                    "finding_images": finding_images,
                    "user_id": request.user.id
                })
        elif report_format == 'HTML':
            widgets = list(selected_widgets.values())
            return render(
                request, 'dojo/custom_html_report.html', {
                    "widgets": widgets,
                    "host": host,
                    "finding_notes": finding_notes,
                    "finding_images": finding_images,
                    "user_id": request.user.id
                })
        else:
            return HttpResponseForbidden()
    else:
        return HttpResponseForbidden()