Beispiel #1
0
def new_signature_dependency(request):
    """
    Add a new Signature dependency 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():
        form = NewSignatureDependencyForm(request.POST)
        analyst = request.user.username
        if form.is_valid():

            result = add_new_signature_dependency(form.cleaned_data['data_type_dependency'],
                                           analyst)
            if result:
                message = {'message': '<div>Signature Dependency added successfully!</div>',
                           'success': True}
            else:
                message = {'message': '<div>Signature Dependency addition failed!</div>',
                           'success': False}
        else:
            message = {'form': form.as_table()}
        return HttpResponse(json.dumps(message),
                            content_type="application/json")
    else:
        return render_to_response('error.html',
                              {'error':'Expected AJAX POST'})
Beispiel #2
0
def new_signature_dependency(request):
    """
    Add a new Signature dependency 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():
        form = NewSignatureDependencyForm(request.POST)
        analyst = request.user.username
        if form.is_valid():

            result = add_new_signature_dependency(
                form.cleaned_data['data_type_dependency'], analyst)
            if result:
                message = {
                    'message':
                    '<div>Signature Dependency added successfully!</div>',
                    'success': True
                }
            else:
                message = {
                    'message':
                    '<div>Signature Dependency addition failed!</div>',
                    'success': False
                }
        else:
            message = {'form': form.as_table()}
        return HttpResponse(json.dumps(message),
                            content_type="application/json")
    else:
        return render_to_response('error.html',
                                  {'error': 'Expected AJAX POST'})
Beispiel #3
0
def new_signature_dependency(request):
    """
    Add a new Signature dependency 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():
        form = NewSignatureDependencyForm(request.POST)
        user = request.user
        if form.is_valid():
            if user.has_access_to(GeneralACL.ADD_NEW_SIGNATURE_DEPENDENCY):
                result = add_new_signature_dependency(form.cleaned_data['data_type_dependency'],
                                               user.username)
                if result:
                    message = {'message': '<div>Signature Dependency added successfully!</div>',
                               'success': True}
                else:
                    message = {'message': '<div>Signature Dependency addition failed!</div>',
                               'success': False}
            else:
                message = {'message': '<div>User does not have permission to add signature dependency.</div>',
                            'success': False}
        else:
            message = {'form': form.as_table()}
        return HttpResponse(json.dumps(message),
                            content_type="application/json")
    else:
        return render(request, 'error.html',
                              {'error':'Expected AJAX POST'})
Beispiel #4
0
def new_signature_dependency(request):
    """
    Add a new Signature dependency 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():
        form = NewSignatureDependencyForm(request.POST)
        user = request.user
        if form.is_valid():
            if user.has_access_to(GeneralACL.ADD_NEW_SIGNATURE_DEPENDENCY):
                result = add_new_signature_dependency(
                    form.cleaned_data['data_type_dependency'], user.username)
                if result:
                    message = {
                        'message':
                        '<div>Signature Dependency added successfully!</div>',
                        'success': True
                    }
                else:
                    message = {
                        'message':
                        '<div>Signature Dependency addition failed!</div>',
                        'success': False
                    }
            else:
                message = {
                    'message':
                    '<div>User does not have permission to add signature dependency.</div>',
                    'success': False
                }
        else:
            message = {'form': form.as_table()}
        return HttpResponse(json.dumps(message),
                            content_type="application/json")
    else:
        return render(request, 'error.html', {'error': 'Expected AJAX POST'})
Beispiel #5
0
def upload_signature(request, link_id=None):
    """
    Upload new Signature to CRITs.

    :param request: Django request object (Required)
    :type request: :class:`django.http.HttpRequest`
    :param link_id: The LinkId of Signature if this is a new version upload.
    :type link_id: str
    :returns: :class:`django.http.HttpResponse`
    """

    if request.method == 'POST':
        form = UploadSignatureForm(request.user, request.POST)
        if form.is_valid():
            analyst = request.user.username
            data = request.POST.get('data', None)
            source = form.cleaned_data.get('source')
            user = request.user.username
            description = form.cleaned_data.get('description', '')
            title = form.cleaned_data.get('title', None)
            data_type = form.cleaned_data.get('data_type', None)
            data_type_min_version = form.cleaned_data.get('data_type_min_version', None)
            data_type_max_version = form.cleaned_data.get('data_type_max_version', None)
            related_id=form.cleaned_data.get('related_id', '')
            related_type = form.cleaned_data.get('related_type', '')
            relationship_type = form.cleaned_data.get('relationship_type', '')

            ''' Parse out dependencies and add any new ones '''
            depend_string = form.cleaned_data.get('data_type_dependency', None)
            new_list = depend_string.split(',')
            data_type_dependency = []

            for dtd in new_list:
                dtd = dtd.strip()
                dtd = str(dtd)
                if dtd:
                    data_type_dependency.append(dtd)
                    add_new_signature_dependency(dtd,analyst)

            copy_rels = request.POST.get('copy_relationships', False)
            link_id = link_id
            bucket_list = form.cleaned_data.get('bucket_list')
            ticket = form.cleaned_data.get('ticket')
            method = form.cleaned_data.get('method', '') or 'Upload'
            reference = form.cleaned_data.get('reference', '')
            status = handle_signature_file(data, source, user,
                                          description, title, data_type,
                                          data_type_min_version,
                                          data_type_max_version,
                                          data_type_dependency, link_id,
                                          method=method,
                                          reference=reference,
                                          copy_rels=copy_rels,
                                          bucket_list=bucket_list,
                                          ticket=ticket,
                                          related_id=related_id,
                                          related_type=related_type,
                                          relationship_type=relationship_type)
            if status['success']:
                jdump = json.dumps({
                    'message': 'signature uploaded successfully! <a href="%s">View signature</a>'
                    % reverse('crits.signatures.views.signature_detail',
                              args=[status['_id']]), 'success': True})
                return HttpResponse(jdump, content_type="application/json")

            else:
                jdump = json.dumps({'success': False,
                                    'message': status['message']})
                return HttpResponse(jdump, content_type="application/json")

        else:
            jdump = json.dumps({'success': False,
                                'form': form.as_table()})
            return HttpResponse(jdump, content_type="application/json")

    else:
        return render_to_response('error.html',
                                  {'error': "Expected POST."},
                                  RequestContext(request))
Beispiel #6
0
def upload_signature(request, link_id=None):
    """
    Upload new Signature to CRITs.

    :param request: Django request object (Required)
    :type request: :class:`django.http.HttpRequest`
    :param link_id: The LinkId of Signature if this is a new version upload.
    :type link_id: str
    :returns: :class:`django.http.HttpResponse`
    """

    if request.method == 'POST':
        form = UploadSignatureForm(request.user, request.POST)
        if form.is_valid():
            analyst = request.user.username
            data = request.POST.get('data', None)
            source = form.cleaned_data.get('source')
            user = request.user.username
            description = form.cleaned_data.get('description', '')
            title = form.cleaned_data.get('title', None)
            data_type = form.cleaned_data.get('data_type', None)
            data_type_min_version = form.cleaned_data.get(
                'data_type_min_version', None)
            data_type_max_version = form.cleaned_data.get(
                'data_type_max_version', None)
            ''' Parse out dependencies and add any new ones '''
            depend_string = form.cleaned_data.get('data_type_dependency', None)
            new_list = depend_string.split(',')
            data_type_dependency = []

            for dtd in new_list:
                dtd = dtd.strip()
                dtd = str(dtd)
                if dtd:
                    data_type_dependency.append(dtd)
                    add_new_signature_dependency(dtd, analyst)

            copy_rels = request.POST.get('copy_relationships', False)
            link_id = link_id
            bucket_list = form.cleaned_data.get('bucket_list')
            ticket = form.cleaned_data.get('ticket')
            method = form.cleaned_data.get('method', '') or 'Upload'
            reference = form.cleaned_data.get('reference', '')
            status = handle_signature_file(data,
                                           source,
                                           user,
                                           description,
                                           title,
                                           data_type,
                                           data_type_min_version,
                                           data_type_max_version,
                                           data_type_dependency,
                                           link_id,
                                           method=method,
                                           reference=reference,
                                           copy_rels=copy_rels,
                                           bucket_list=bucket_list,
                                           ticket=ticket)
            if status['success']:
                jdump = json.dumps({
                    'message':
                    'signature uploaded successfully! <a href="%s">View signature</a>'
                    % reverse('crits.signatures.views.signature_detail',
                              args=[status['_id']]),
                    'success':
                    True
                })
                return HttpResponse(jdump, content_type="application/json")

            else:
                jdump = json.dumps({
                    'success': False,
                    'message': status['message']
                })
                return HttpResponse(jdump, content_type="application/json")

        else:
            jdump = json.dumps({'success': False, 'form': form.as_table()})
            return HttpResponse(jdump, content_type="application/json")

    else:
        return render_to_response('error.html', {'error': "Expected POST."},
                                  RequestContext(request))