Ejemplo n.º 1
0
def email_eml_add(request):
    """
    Upload an email using EML.

    :param request: Django request object (Required)
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
    """

    eml_form = EmailEMLForm(request.user, request.POST, request.FILES)
    json_reply = {
                   'form': eml_form.as_table(),
                   'success': False,
                   'message': ""
                 }

    if request.method != "POST":
        json_reply['message'] = "Must submit via POST."
        return render_to_response('file_upload_response.html',
                                  {'response': json.dumps(json_reply)},
                                  RequestContext(request))

    if not eml_form.is_valid():
        json_reply['message'] = "Form is invalid."
        return render_to_response('file_upload_response.html',
                                  {'response': json.dumps(json_reply)},
                                  RequestContext(request))

    data = ''
    for chunk in request.FILES['filedata']:
        data += chunk

    method = "EML Upload"
    if eml_form.cleaned_data['source_method']:
        method = method + " - " + eml_form.cleaned_data['source_method']

    obj = handle_eml(data, eml_form.cleaned_data['source'],
                     eml_form.cleaned_data['source_reference'],
                     request.user.username,
                     method,
                     campaign=eml_form.cleaned_data['campaign'],
                     confidence=eml_form.cleaned_data['campaign_confidence'],
                     bucket_list=eml_form.cleaned_data['bucket_list'],
                     ticket=eml_form.cleaned_data['ticket'],
                     related_id=eml_form.cleaned_data['related_id'],
                     related_type=eml_form.cleaned_data['related_type'],
                     relationship_type=eml_form.cleaned_data['relationship_type'])
    if not obj['status']:
        json_reply['message'] = obj['reason']
        return render_to_response('file_upload_response.html',
                                  {'response': json.dumps(json_reply)},
                                  RequestContext(request))

    json_reply['success'] = True
    json_reply['message'] = 'Email uploaded successfully. <a href="%s">View email.</a>' % reverse('crits.emails.views.email_detail', args=[obj['object'].id])
    return render_to_response('file_upload_response.html',
                              {'response': json.dumps(json_reply)},
                              RequestContext(request))
Ejemplo n.º 2
0
def email_eml_add(request):
    """
    Upload an email using EML.

    :param request: Django request object (Required)
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
    """

    eml_form = EmailEMLForm(request.user, request.POST, request.FILES)
    json_reply = {"form": eml_form.as_table(), "success": False, "message": ""}

    if request.method != "POST":
        json_reply["message"] = "Must submit via POST."
        return render_to_response(
            "file_upload_response.html", {"response": json.dumps(json_reply)}, RequestContext(request)
        )

    if not eml_form.is_valid():
        json_reply["message"] = "Form is invalid."
        return render_to_response(
            "file_upload_response.html", {"response": json.dumps(json_reply)}, RequestContext(request)
        )

    data = ""
    for chunk in request.FILES["filedata"]:
        data += chunk

    method = "EML Upload"
    if eml_form.cleaned_data["source_method"]:
        method = method + " - " + eml_form.cleaned_data["source_method"]

    obj = handle_eml(
        data,
        eml_form.cleaned_data["source"],
        eml_form.cleaned_data["source_reference"],
        request.user.username,
        method,
        campaign=eml_form.cleaned_data["campaign"],
        confidence=eml_form.cleaned_data["campaign_confidence"],
    )
    if not obj["status"]:
        json_reply["message"] = obj["reason"]
        return render_to_response(
            "file_upload_response.html", {"response": json.dumps(json_reply)}, RequestContext(request)
        )

    json_reply["success"] = True
    json_reply["message"] = 'Email uploaded successfully. <a href="%s">View email.</a>' % reverse(
        "crits.emails.views.email_detail", args=[obj["object"].id]
    )
    return render_to_response(
        "file_upload_response.html", {"response": json.dumps(json_reply)}, RequestContext(request)
    )
Ejemplo n.º 3
0
def email_eml_add(request):
    """
    Upload an email using EML.

    :param request: Django request object (Required)
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
    """

    eml_form = EmailEMLForm(request.user, request.POST, request.FILES)
    user = request.user

    json_reply = {'form': eml_form.as_table(), 'success': False}

    if request.method != "POST":
        message = "Must submit via POST."
    else:
        if not eml_form.is_valid():
            message = "Form is invalid."
        elif not user.has_access_to(EmailACL.WRITE):
            message = "User does not have permission to add email."

        else:
            form_data = eml_form.cleaned_data
            data = ''
            for chunk in request.FILES['filedata']:
                data += chunk

            method = "EML Upload"
            if form_data['source_method']:
                method = method + " - " + form_data['source_method']

            result = handle_eml(
                data, form_data['source_name'], form_data['source_reference'],
                method, form_data['source_tlp'], user, form_data['campaign'],
                form_data['campaign_confidence'], form_data['bucket_list'],
                form_data['ticket'], form_data['related_id'],
                form_data['related_type'], form_data['relationship_type'])

            if result['status']:
                redirect = reverse('crits-emails-views-email_detail',
                                   args=[result['object'].id])
                json_reply['success'] = True
                message = 'Email uploaded successfully'
                if result.get('reason'):
                    message += ', but %s' % result['reason']
                message += ('. <a href="%s">View email.</a>' % redirect)
            else:
                message = result['reason']

    json_reply['message'] = message
    return render(request, 'file_upload_response.html',
                  {'response': json.dumps(json_reply)})
Ejemplo n.º 4
0
def email_eml_add(request):
    """
    Upload an email using EML.

    :param request: Django request object (Required)
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
    """

    eml_form = EmailEMLForm(request.user, request.POST, request.FILES)
    user = request.user

    json_reply = {
                   'form': eml_form.as_table(),
                   'success': False
                 }

    if request.method != "POST":
        message = "Must submit via POST."
    else:
        if not eml_form.is_valid():
            message = "Form is invalid."
        elif not user.has_access_to(EmailACL.WRITE):
            message = "User does not have permission to add email."

        else:
            form_data = eml_form.cleaned_data
            data = ''
            for chunk in request.FILES['filedata']:
                data += chunk

            method = "EML Upload"
            if form_data['source_method']:
                method = method + " - " + form_data['source_method']

            result = handle_eml(data,
                                form_data['source_name'],
                                form_data['source_reference'],
                                method,
                                form_data['source_tlp'],
                                request.user,
                                form_data['campaign'],
                                form_data['campaign_confidence'],
                                form_data['bucket_list'],
                                form_data['ticket'],
                                form_data['related_id'],
                                form_data['related_type'],
                                form_data['relationship_type'])

            if result['status']:
                redirect = reverse('crits.emails.views.email_detail',
                                   args=[result['object'].id])
                json_reply['success'] = True
                message = 'Email uploaded successfully'
                if result.get('reason'):
                    message += ', but %s' % result['reason']
                message += ('. <a href="%s">View email.</a>' % redirect)
            else:
                message = result['reason']

    json_reply['message'] = message
    return render_to_response('file_upload_response.html',
                              {'response': json.dumps(json_reply)},
                              RequestContext(request))