Exemplo n.º 1
0
def add_event(request):
    """
    Add an event to CRITs. Should be an AJAX POST.

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

    if request.method == "POST" and request.is_ajax():
        event_form = EventForm(request.user, request.POST)
        if event_form.is_valid():
            data = event_form.cleaned_data
            result = add_new_event(title=data['title'],
                                   description=data['description'],
                                   event_type=data['event_type'],
                                   source=data['source'],
                                   method=data['method'],
                                   reference=data['reference'],
                                   date=data['occurrence_date'],
                                   bucket_list=data[form_consts.Common.BUCKET_LIST_VARIABLE_NAME],
                                   ticket=data[form_consts.Common.TICKET_VARIABLE_NAME],
                                   analyst=request.user.username)
            if 'object' in result:
                del result['object']
            return HttpResponse(json.dumps(result), mimetype="application/json")
        else:
            return HttpResponse(json.dumps({'form': event_form.as_table(),
                                            'success': False}),
                                mimetype="application/json")
    else:
        return render_to_response("error.html",
                                  {"error": "Expected AJAX POST"},
                                  RequestContext(request))
Exemplo n.º 2
0
def add_event(request):
    """
    Add an event to CRITs. Should be an AJAX POST.

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

    if request.method == "POST" and request.is_ajax():
        event_form = EventForm(request.user, request.POST)
        if event_form.is_valid():
            data = event_form.cleaned_data
            result = add_new_event(title=data['title'],
                                   description=data['description'],
                                   event_type=data['event_type'],
                                   source=data['source'],
                                   method=data['method'],
                                   reference=data['reference'],
                                   date=data['occurrence_date'],
                                   bucket_list=data[form_consts.Common.BUCKET_LIST_VARIABLE_NAME],
                                   ticket=data[form_consts.Common.TICKET_VARIABLE_NAME],
                                   analyst=request.user.username)
            if 'object' in result:
                del result['object']
            return HttpResponse(json.dumps(result), mimetype="application/json")
        else:
            return HttpResponse(json.dumps({'form': event_form.as_table(),
                                            'success': False}),
                                mimetype="application/json")
    else:
        return render_to_response("error.html",
                                  {"error": "Expected AJAX POST"},
                                  RequestContext(request))
Exemplo n.º 3
0
def add_event(request):
    """
    Add an event to CRITs. Should be an AJAX POST.

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

    user = request.user

    if request.method == "POST" and request.is_ajax():
        if user.has_access_to(EventACL.WRITE):
            event_form = EventForm(request.user, request.POST)
            if event_form.is_valid():
                data = event_form.cleaned_data
                result = add_new_event(
                    title=data['title'],
                    description=data['description'],
                    event_type=data['event_type'],
                    source_name=data['source_name'],
                    source_method=data['source_method'],
                    source_reference=data['source_reference'],
                    source_tlp=data['source_tlp'],
                    date=data['occurrence_date'],
                    bucket_list=data[
                        form_consts.Common.BUCKET_LIST_VARIABLE_NAME],
                    ticket=data[form_consts.Common.TICKET_VARIABLE_NAME],
                    user=request.user,
                    campaign=data['campaign'],
                    campaign_confidence=data['campaign_confidence'],
                    related_id=data['related_id'],
                    related_type=data['related_type'],
                    relationship_type=data['relationship_type'])
                if 'object' in result:
                    del result['object']
                return HttpResponse(json.dumps(result),
                                    content_type="application/json")
            else:
                return HttpResponse(json.dumps({
                    'form': event_form.as_table(),
                    'success': False
                }),
                                    content_type="application/json")
        else:
            return HttpResponse(
                json.dumps({
                    'success':
                    False,
                    'message':
                    'User does not have permission to add event.'
                }))
    else:
        return render_to_response("error.html",
                                  {"error": "Expected AJAX POST"},
                                  RequestContext(request))
Exemplo n.º 4
0
def add_event(request):
    """
    Add an event to CRITs. Should be an AJAX POST.

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

    user = request.user

    if request.method == "POST" and request.is_ajax():
        if user.has_access_to(EventACL.WRITE):
            event_form = EventForm(request.user, request.POST)
            if event_form.is_valid():
                data = event_form.cleaned_data
                result = add_new_event(title=data['title'],
                                       description=data['description'],
                                       event_type=data['event_type'],
                                       source_name=data['source_name'],
                                       source_method=data['source_method'],
                                       source_reference=data['source_reference'],
                                       source_tlp=data['source_tlp'],
                                       date=data['occurrence_date'],
                                       bucket_list=data[form_consts.Common.BUCKET_LIST_VARIABLE_NAME],
                                       ticket=data[form_consts.Common.TICKET_VARIABLE_NAME],
                                       user=request.user,
                                       campaign=data['campaign'],
                                       campaign_confidence=data['campaign_confidence'],
                                       related_id=data['related_id'],
                                       related_type=data['related_type'],
                                       relationship_type=data['relationship_type'])
                if 'object' in result:
                    del result['object']
                return HttpResponse(json.dumps(result), content_type="application/json")
            else:
                return HttpResponse(json.dumps({'form': event_form.as_table(),
                                                'success': False}),
                                    content_type="application/json")
        else:
            return HttpResponse(json.dumps({'success':False,
                                            'message':'User does not have permission to add event.'}))
    else:
        return render_to_response("error.html",
                                  {"error": "Expected AJAX POST"},
                                  RequestContext(request))