Esempio n. 1
0
def add_actor(request):
    """
    Add an Actor. Should be an AJAX POST.

    :param request: Django request.
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
    """

    if request.method == "POST" and request.is_ajax():
        request.user._setup()
        user = request.user
        data = request.POST
        form = AddActorForm(request.user, data)
        if form.is_valid():
            if user.has_access_to(ActorACL.WRITE):
                cleaned_data = form.cleaned_data
                name = cleaned_data['name']
                aliases = cleaned_data['aliases']
                description = cleaned_data['description']
                source = cleaned_data['source_name']
                reference = cleaned_data['source_reference']
                method = cleaned_data['source_method']
                tlp = cleaned_data['source_tlp']
                campaign = cleaned_data['campaign']
                confidence = cleaned_data['confidence']
                bucket_list = cleaned_data.get(
                    form_consts.Common.BUCKET_LIST_VARIABLE_NAME)
                ticket = cleaned_data.get(form_consts.Common.TICKET_VARIABLE_NAME)
                related_id = cleaned_data['related_id']
                related_type = cleaned_data['related_type']
                relationship_type = cleaned_data['relationship_type']

                result = add_new_actor(name,
                                       aliases=aliases,
                                       description=description,
                                       source=source,
                                       source_method=method,
                                       source_reference=reference,
                                       source_tlp=tlp,
                                       campaign=campaign,
                                       confidence=confidence,
                                       user=user,
                                       bucket_list=bucket_list,
                                       ticket=ticket,
                                       related_id=related_id,
                                       related_type=related_type,
                                       relationship_type=relationship_type)
            else:
                result = {"success":False,
                          "message":"User does not have permission to add Actors."}

            return HttpResponse(json.dumps(result,
                                           default=json_handler),
                                content_type="application/json")
        return HttpResponse(json.dumps({'success': False,
                                        'form':form.as_table()}),
                            content_type="application/json")
    return render(request, "error.html", {'error': 'Expected AJAX/POST'})
Esempio n. 2
0
def add_actor(request):
    """
    Add an Actor. Should be an AJAX POST.

    :param request: Django request.
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
    """

    if request.method == "POST" and request.is_ajax():
        data = request.POST
        form = AddActorForm(request.user, data)
        if form.is_valid():
            cleaned_data = form.cleaned_data
            name = cleaned_data['name']
            aliases = cleaned_data['aliases']
            description = cleaned_data['description']
            source = cleaned_data['source']
            reference = cleaned_data['source_reference']
            method = cleaned_data['source_method']
            campaign = cleaned_data['campaign']
            confidence = cleaned_data['confidence']
            analyst = request.user.username
            bucket_list = cleaned_data.get(form_consts.Common.BUCKET_LIST_VARIABLE_NAME)
            ticket = cleaned_data.get(form_consts.Common.TICKET_VARIABLE_NAME)
            related_id = cleaned_data['related_id']
            related_type = cleaned_data['related_type']
            relationship_type = cleaned_data['relationship_type']

            result = add_new_actor(name,
                                   aliases=aliases,
                                   description=description,
                                   source=source,
                                   source_method=method,
                                   source_reference=reference,
                                   campaign=campaign,
                                   confidence=confidence,
                                   analyst=analyst,
                                   bucket_list=bucket_list,
                                   ticket=ticket,
                                   related_id=related_id,
                                   related_type=related_type,
                                   relationship_type=relationship_type)
            return HttpResponse(json.dumps(result,
                                           default=json_handler),
                                content_type="application/json")
        return HttpResponse(json.dumps({'success': False,
                                        'form':form.as_table()}),
                            content_type="application/json")
    return render_to_response("error.html",
                              {'error': 'Expected AJAX/POST'},
                              RequestContext(request))
Esempio n. 3
0
def add_actor(request):
    """
    Add an Actor. Should be an AJAX POST.

    :param request: Django request.
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
    """

    if request.method == "POST" and request.is_ajax():
        data = request.POST
        form = AddActorForm(request.user, data)
        if form.is_valid():
            cleaned_data = form.cleaned_data
            name = cleaned_data["name"]
            aliases = cleaned_data["aliases"]
            description = cleaned_data["description"]
            source = cleaned_data["source"]
            reference = cleaned_data["source_reference"]
            method = cleaned_data["source_method"]
            campaign = cleaned_data["campaign"]
            confidence = cleaned_data["confidence"]
            analyst = request.user.username
            bucket_list = cleaned_data.get(form_consts.Common.BUCKET_LIST_VARIABLE_NAME)
            ticket = cleaned_data.get(form_consts.Common.TICKET_VARIABLE_NAME)

            result = add_new_actor(
                name,
                aliases=aliases,
                description=description,
                source=source,
                source_method=method,
                source_reference=reference,
                campaign=campaign,
                confidence=confidence,
                analyst=analyst,
                bucket_list=bucket_list,
                ticket=ticket,
            )
            return HttpResponse(json.dumps(result, default=json_handler), mimetype="application/json")
        return HttpResponse(json.dumps({"success": False, "form": form.as_table()}), mimetype="application/json")
    return render_to_response("error.html", {"error": "Expected AJAX/POST"}, RequestContext(request))
Esempio n. 4
0
def add_actor(request):
    """
    Add an Actor. Should be an AJAX POST.

    :param request: Django request.
    :type request: :class:`django.http.HttpRequest`
    :returns: :class:`django.http.HttpResponse`
    """

    if request.method == "POST" and request.is_ajax():
        request.user._setup()
        user = request.user
        data = request.POST
        form = AddActorForm(request.user, data)
        if form.is_valid():
            if user.has_access_to(ActorACL.WRITE):
                cleaned_data = form.cleaned_data
                name = cleaned_data['name']
                aliases = cleaned_data['aliases']
                description = cleaned_data['description']
                source = cleaned_data['source_name']
                reference = cleaned_data['source_reference']
                method = cleaned_data['source_method']
                tlp = cleaned_data['source_tlp']
                campaign = cleaned_data['campaign']
                confidence = cleaned_data['confidence']
                bucket_list = cleaned_data.get(
                    form_consts.Common.BUCKET_LIST_VARIABLE_NAME)
                ticket = cleaned_data.get(
                    form_consts.Common.TICKET_VARIABLE_NAME)
                related_id = cleaned_data['related_id']
                related_type = cleaned_data['related_type']
                relationship_type = cleaned_data['relationship_type']

                result = add_new_actor(name,
                                       aliases=aliases,
                                       description=description,
                                       source=source,
                                       source_method=method,
                                       source_reference=reference,
                                       source_tlp=tlp,
                                       campaign=campaign,
                                       confidence=confidence,
                                       user=user,
                                       bucket_list=bucket_list,
                                       ticket=ticket,
                                       related_id=related_id,
                                       related_type=related_type,
                                       relationship_type=relationship_type)
            else:
                result = {
                    "success": False,
                    "message": "User does not have permission to add Actors."
                }

            return HttpResponse(json.dumps(result, default=json_handler),
                                content_type="application/json")
        return HttpResponse(json.dumps({
            'success': False,
            'form': form.as_table()
        }),
                            content_type="application/json")
    return render(request, "error.html", {'error': 'Expected AJAX/POST'})