Exemplo n.º 1
0
def generate_division_jtable(request, option):
    """
    Generate the jtable data for rendering in the list template.

    :param request: The request for this jtable.
    :type request: :class:`django.http.HttpRequest`
    :param option: Action to take.
    :type option: str of either 'jtlist', 'jtdelete', or 'inline'.
    :returns: :class:`django.http.HttpResponse`
    """

    refresh = request.GET.get("refresh", "no")
    if refresh == "yes":
        target_user_stats()
    if option == "jtlist":
        limit = int(request.GET.get("jtPageSize", 25))
        skip = int(request.GET.get("jtStartIndex", 0))

        response = {}
        response["Result"] = "OK"
        fields = ["division", "email_count", "id", "schema_version"]
        response["TotalRecordCount"] = Division.objects().count()
        response["Records"] = (
            Division.objects().skip(skip).limit(limit).order_by("-email_count").only(*fields).to_dict()
        )
        # response['Records'] = [d.to_dict() for d in response['Records']]

        return HttpResponse(json.dumps(response, default=json_handler), content_type="application/json")

    type_ = "division"
    jtopts = {
        "title": "Divisions",
        "default_sort": "email_count DESC",
        "listurl": reverse("crits.targets.views.%ss_listing" % (type_,), args=("jtlist",)),
        "deleteurl": None,
        "searchurl": None,
        "fields": ["division", "email_count", "id"],
        "hidden_fields": ["_id"],
        "linked_fields": [],
    }
    jtable = build_jtable(jtopts, request)
    jtable["toolbar"] = [
        {
            "tooltip": "'Refresh division stats'",
            "text": "'Refresh'",
            "click": "function () {$.get('"
            + reverse("crits.targets.views.%ss_listing" % (type_))
            + "', {'refresh': 'yes'}); $('target_listing').jtable('load');}",
        }
    ]
    if option == "inline":
        return render_to_response(
            "jtable.html",
            {"jtable": jtable, "jtid": "%s_listing" % type_, "button": "%ss_tab" % type_},
            RequestContext(request),
        )
    else:
        return render_to_response(
            "%s_listing.html" % type_, {"jtable": jtable, "jtid": "%s_listing" % type_}, RequestContext(request)
        )
Exemplo n.º 2
0
    def handle(self, *args, **options):
        """
        Script Execution.
        """

        stats.generate_yara_hits()
        stats.generate_sources()
        stats.generate_filetypes()
        stats.generate_campaign_stats()
        stats.generate_counts()
        stats.target_user_stats()
        stats.campaign_date_stats()
Exemplo n.º 3
0
def generate_target_jtable(request, option):
    """
    Generate the jtable data for rendering in the list template.

    :param request: The request for this jtable.
    :type request: :class:`django.http.HttpRequest`
    :param option: Action to take.
    :type option: str of either 'jtlist', 'jtdelete', or 'inline'.
    :returns: :class:`django.http.HttpResponse`
    """

    refresh = request.GET.get("refresh", "no")
    if refresh == "yes":
        target_user_stats()
    obj_type = Target
    type_ = "target"
    mapper = obj_type._meta['jtable_opts']
    if option == "jtlist":
        # Handle campaign listings
        query = {}
        if "campaign" in request.GET:
             campaign = request.GET.get("campaign",None)
             emails = get_campaign_targets(campaign, request.user.username)
             query = {"email_address":{"$in": emails}}
        # Sets display url
        details_url = mapper['details_url']
        details_url_key = mapper['details_url_key']
        fields = mapper['fields']
        response = jtable_ajax_list(obj_type, details_url, details_url_key,
                                    request, includes=fields, query=query)
        return HttpResponse(json.dumps(response,
                                       default=json_handler),
                                       content_type="application/json")
    if option == "jtdelete":
        response = {"Result": "ERROR"}
        if jtable_ajax_delete(obj_type,request):
            response = {"Result": "OK"}
        return HttpResponse(json.dumps(response,
                                       default=json_handler),
                                       content_type="application/json")
    jtopts = {
        'title': "Targets",
        'default_sort': mapper['default_sort'],
        'listurl': reverse('crits.%ss.views.%ss_listing' %
                           (type_, type_), args=('jtlist',)),
        'deleteurl': reverse('crits.%ss.views.%ss_listing' %
                             (type_, type_), args=('jtdelete',)),
        'searchurl': reverse(mapper['searchurl']),
        'fields': mapper['jtopts_fields'],
        'hidden_fields': mapper['hidden_fields'],
        'linked_fields': mapper['linked_fields'],
        'details_link': mapper['details_link'],
        'no_sort': mapper['no_sort']
    }
    jtable = build_jtable(jtopts,request)
    jtable['toolbar'] = [
        {
            'tooltip': "'All Targets'",
            'text': "'All'",
            'click': "function () {$('#target_listing').jtable('load', {'refresh': 'yes'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'New Targets'",
            'text': "'New'",
            'click': "function () {$('#target_listing').jtable('load', {'refresh': 'yes', 'status': 'New'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'In Progress Targets'",
            'text': "'In Progress'",
            'click': "function () {$('#target_listing').jtable('load', {'refresh': 'yes', 'status': 'In Progress'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'Analyzed Targets'",
            'text': "'Analyzed'",
            'click': "function () {$('#target_listing').jtable('load', {'refresh': 'yes', 'status': 'Analyzed'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'Deprecated Targets'",
            'text': "'Deprecated'",
            'click': "function () {$('#target_listing').jtable('load', {'refresh': 'yes', 'status': 'Deprecated'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'Refresh target stats'",
            'text': "'Refresh'",
            'click': "function () {$.get('"+reverse('crits.%ss.views.%ss_listing' % (type_,type_))+"', {'refresh': 'yes'}); $('target_listing').jtable('load');}",
        },
        {
            'tooltip': "'Add Target'",
            'text': "'Add Target'",
            'click': "function () {$('#new-target').click()}",
        },
    ]
    if option == "inline":
        return render_to_response("jtable.html",
                                  {'jtable': jtable,
                                   'jtid': '%s_listing' % type_,
                                   'button' : '%ss_tab' % type_},
                                  RequestContext(request))
    else:
        return render_to_response("%s_listing.html" % type_,
                                  {'jtable': jtable,
                                   'jtid': '%s_listing' % type_},
                                  RequestContext(request))
Exemplo n.º 4
0
def generate_target_jtable(request, option):
    """
    Generate the jtable data for rendering in the list template.

    :param request: The request for this jtable.
    :type request: :class:`django.http.HttpRequest`
    :param option: Action to take.
    :type option: str of either 'jtlist', 'jtdelete', or 'inline'.
    :returns: :class:`django.http.HttpResponse`
    """

    refresh = request.GET.get("refresh", "no")
    if refresh == "yes":
        target_user_stats()
    obj_type = Target
    type_ = "target"
    mapper = obj_type._meta['jtable_opts']
    if option == "jtlist":
        # Handle campaign listings
        query = {}
        if "campaign" in request.GET:
            campaign = request.GET.get("campaign", None)
            emails = get_campaign_targets(campaign, request.user.username)
            query = {"email_address": {"$in": emails}}
        # Sets display url
        details_url = mapper['details_url']
        details_url_key = mapper['details_url_key']
        fields = mapper['fields']
        response = jtable_ajax_list(obj_type,
                                    details_url,
                                    details_url_key,
                                    request,
                                    includes=fields,
                                    query=query)
        return HttpResponse(json.dumps(response, default=json_handler),
                            content_type="application/json")
    if option == "jtdelete":
        response = {"Result": "ERROR"}
        if jtable_ajax_delete(obj_type, request):
            response = {"Result": "OK"}
        return HttpResponse(json.dumps(response, default=json_handler),
                            content_type="application/json")
    jtopts = {
        'title':
        "Targets",
        'default_sort':
        mapper['default_sort'],
        'listurl':
        reverse('crits.%ss.views.%ss_listing' % (type_, type_),
                args=('jtlist', )),
        'deleteurl':
        reverse('crits.%ss.views.%ss_listing' % (type_, type_),
                args=('jtdelete', )),
        'searchurl':
        reverse(mapper['searchurl']),
        'fields':
        mapper['jtopts_fields'],
        'hidden_fields':
        mapper['hidden_fields'],
        'linked_fields':
        mapper['linked_fields'],
        'details_link':
        mapper['details_link'],
        'no_sort':
        mapper['no_sort']
    }
    jtable = build_jtable(jtopts, request)
    jtable['toolbar'] = [
        {
            'tooltip': "'All Targets'",
            'text': "'All'",
            'click':
            "function () {$('#target_listing').jtable('load', {'refresh': 'yes'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'New Targets'",
            'text': "'New'",
            'click':
            "function () {$('#target_listing').jtable('load', {'refresh': 'yes', 'status': 'New'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'In Progress Targets'",
            'text': "'In Progress'",
            'click':
            "function () {$('#target_listing').jtable('load', {'refresh': 'yes', 'status': 'In Progress'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'Analyzed Targets'",
            'text': "'Analyzed'",
            'click':
            "function () {$('#target_listing').jtable('load', {'refresh': 'yes', 'status': 'Analyzed'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip': "'Deprecated Targets'",
            'text': "'Deprecated'",
            'click':
            "function () {$('#target_listing').jtable('load', {'refresh': 'yes', 'status': 'Deprecated'});}",
            'cssClass': "'jtable-toolbar-center'",
        },
        {
            'tooltip':
            "'Refresh target stats'",
            'text':
            "'Refresh'",
            'click':
            "function () {$.get('" + reverse('crits.%ss.views.%ss_listing' %
                                             (type_, type_)) +
            "', {'refresh': 'yes'}); $('target_listing').jtable('load');}",
        },
        {
            'tooltip': "'Add Target'",
            'text': "'Add Target'",
            'click': "function () {$('#new-target').click()}",
        },
    ]
    if option == "inline":
        return render_to_response(
            "jtable.html", {
                'jtable': jtable,
                'jtid': '%s_listing' % type_,
                'button': '%ss_tab' % type_
            }, RequestContext(request))
    else:
        return render_to_response("%s_listing.html" % type_, {
            'jtable': jtable,
            'jtid': '%s_listing' % type_
        }, RequestContext(request))