def generate_comment_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` """ obj_type = Comment type_ = "comment" if option == "jtlist": # Sets display url details_url = "" details_url_key = "id" fields = ["obj_type", "comment", "url_key", "created", "analyst", "source", "id"] response = jtable_ajax_list(obj_type, details_url, details_url_key, request, includes=fields) 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": "Comments", "default_sort": "date DESC", "listurl": reverse("crits.%ss.views.%ss_listing" % (type_, type_), args=("jtlist",)), "deleteurl": reverse("crits.%ss.views.%ss_listing" % (type_, type_), args=("jtdelete",)), "searchurl": reverse("crits.%ss.views.%ss_listing" % (type_, type_)), "fields": ["details", "obj_type", "comment", "date", "analyst", "source", "id"], "hidden_fields": ["id"], "linked_fields": ["analyst"], "details_link": "details", "no_sort": ["details"], } jtable = build_jtable(jtopts, request) 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) )
def generate_ip_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` """ obj_type = IP type_ = "ip" mapper = obj_type._meta['jtable_opts'] if option == "jtlist": # 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) 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': "IPs", '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 IPs'", 'text': "'All'", 'click': "function () {$('#ip_listing').jtable('load', {'refresh': 'yes'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'New IPs'", 'text': "'New'", 'click': "function () {$('#ip_listing').jtable('load', {'refresh': 'yes', 'status': 'New'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'In Progress IPs'", 'text': "'In Progress'", 'click': "function () {$('#ip_listing').jtable('load', {'refresh': 'yes', 'status': 'In Progress'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'Analyzed IPs'", 'text': "'Analyzed'", 'click': "function () {$('#ip_listing').jtable('load', {'refresh': 'yes', 'status': 'Analyzed'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'Deprecated IPs'", 'text': "'Deprecated'", 'click': "function () {$('#ip_listing').jtable('load', {'refresh': 'yes', 'status': 'Deprecated'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'Add IP'", 'text': "'Add IP'", 'click': "function () {$('#new-ip').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))
def generate_analysis_results_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` """ obj_type = AnalysisResult type_ = "analysis_result" mapper = obj_type._meta['jtable_opts'] if option == "jtlist": # 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) 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': "Analysis Results", 'default_sort': mapper['default_sort'], 'listurl': reverse('crits.services.views.%ss_listing' % type_, args=('jtlist',)), 'deleteurl': reverse('crits.services.views.%ss_listing' % 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'] = [ ] 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))
def generate_actor_identifier_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` """ obj_type = ActorIdentifier type_ = "actor_identifier" mapper = obj_type._meta['jtable_opts'] if option == "jtlist": # 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) 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): obj_id = request.POST.get('id', None) if obj_id: # Remove this identifier from any Actors who reference it. Actor.objects(identifiers__identifier_id=obj_id)\ .update(pull__identifiers__identifier_id=obj_id) response = {"Result": "OK"} return HttpResponse(json.dumps(response, default=json_handler), content_type="application/json") jtopts = { 'title': "Actor Identifiers", 'default_sort': mapper['default_sort'], 'listurl': reverse('crits.actors.views.%ss_listing' % (type_), args=('jtlist',)), 'deleteurl': reverse('crits.actors.views.%ss_listing' % (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) for field in jtable['fields']: if field['fieldname'] == "'name'": url = reverse('crits.actors.views.actors_listing') field['display'] = """ function (data) { return '<a href="%s?q='+data.record.id+'&search_type=actor_identifier&force_full=1">'+data.record.name+'</a>'; } """ % url break jtable['toolbar'] = [ { 'tooltip': "'Add Actor Identifier'", 'text': "'Add Actor Identifier'", 'click': "function () {$('#new-actor-identifier').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))
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))
def generate_event_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` """ obj_type = Event type_ = "event" mapper = obj_type._meta['jtable_opts'] if option == "jtlist": # Sets display url details_url = mapper['details_url'] details_url_key = mapper['details_url_key'] fields = mapper['fields'] # filter list on relationship to given ObjectId query = {} if 'related' in request.GET: try: oid = ObjectId(request.GET.get('related')) query = {'relationships.value': oid} except: pass 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': "Events", '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('crits-%ss-views-%ss_listing' % (type_, type_)), '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 Events'", 'text': "'All'", 'click': "function () {$('#event_listing').jtable('load', {'refresh': 'yes'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'New Events'", 'text': "'New'", 'click': "function () {$('#event_listing').jtable('load', {'refresh': 'yes', 'status': 'New'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'In Progress Events'", 'text': "'In Progress'", 'click': "function () {$('#event_listing').jtable('load', {'refresh': 'yes', 'status': 'In Progress'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'Analyzed Events'", 'text': "'Analyzed'", 'click': "function () {$('#event_listing').jtable('load', {'refresh': 'yes', 'status': 'Analyzed'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'Deprecated Events'", 'text': "'Deprecated'", 'click': "function () {$('#event_listing').jtable('load', {'refresh': 'yes', 'status': 'Deprecated'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'Add Event'", 'text': "'Add Event'", 'click': "function () {$('#new-event').click()}", }, ] if option == "inline": return render(request, "jtable.html", {'jtable': jtable, 'jtid': '%s_listing' % type_, 'button' : '%ss_tab' % type_}, ) else: return render(request, "%s_listing.html" % type_, {'jtable': jtable, 'jtid': '%s_listing' % type_}, )
def generate_comment_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` """ obj_type = Comment type_ = "comment" if option == "jtlist": # Sets display url details_url = '' details_url_key = "id" fields = ["obj_type", "comment", "url_key", "created", "analyst", "source", "id"] response = jtable_ajax_list(obj_type, details_url, details_url_key, request, includes=fields) 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': "Comments", 'default_sort': "date DESC", 'listurl': reverse('crits-%ss-views-%ss_listing' % (type_, type_), args=('jtlist',)), 'deleteurl': reverse('crits-%ss-views-%ss_listing' % (type_, type_), args=('jtdelete',)), 'searchurl': reverse('crits-%ss-views-%ss_listing' % (type_,type_)), 'fields': ["details", "obj_type", "comment", "date", "analyst", "source", "id"], 'hidden_fields': ["id", ], 'linked_fields': ["analyst", ], 'details_link': 'details', 'no_sort': ['details', ], } jtable = build_jtable(jtopts,request) if option == "inline": return render(request, "jtable.html", {'jtable': jtable, 'jtid': '%s_listing' % type_, 'button' : '%ss_tab' % type_}, ) else: return render(request, "%s_listing.html" % type_, {'jtable': jtable, 'jtid': '%s_listing' % type_}, )
def generate_signature_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` """ obj_type = Signature type_ = "signature" mapper = obj_type._meta["jtable_opts"] if option == "jtlist": # 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) 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": "Signature", "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 Signatures'", "text": "'All'", "click": "function () {$('#signature_listing').jtable('load', {'refresh': 'yes'});}", "cssClass": "'jtable-toolbar-center'", }, { "tooltip": "'New Signature'", "text": "'New'", "click": "function () {$('#signature_listing').jtable('load', {'refresh': 'yes', 'status': 'New'});}", "cssClass": "'jtable-toolbar-center'", }, { "tooltip": "'In Progress Signatures'", "text": "'In Progress'", "click": "function () {$('#signature_listing').jtable('load', {'refresh': 'yes', 'status': 'In Progress'});}", "cssClass": "'jtable-toolbar-center'", }, { "tooltip": "'Analyzed Signatures'", "text": "'Analyzed'", "click": "function () {$('#signature_listing').jtable('load', {'refresh': 'yes', 'status': 'Analyzed'});}", "cssClass": "'jtable-toolbar-center'", }, { "tooltip": "'Deprecated Signatures'", "text": "'Deprecated'", "click": "function () {$('#signature_listing').jtable('load', {'refresh': 'yes', 'status': 'Deprecated'});}", "cssClass": "'jtable-toolbar-center'", }, {"tooltip": "'Add Signature'", "text": "'Add Signature'", "click": "function () {$('#new-signature').click()}"}, ] if option == "inline": return render_to_response( "jtable.html", {"jtable": jtable, "jtid": "%s_listing" % type_, "button": "%s_tab" % type_}, RequestContext(request), ) else: return render_to_response( "%s_listing.html" % type_, {"jtable": jtable, "jtid": "%s_listing" % type_}, RequestContext(request) )
def generate_actor_identifier_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` """ obj_type = ActorIdentifier type_ = "actor_identifier" mapper = obj_type._meta['jtable_opts'] if option == "jtlist": # 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) 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): obj_id = request.POST.get('id', None) if obj_id: # Remove this identifier from any Actors who reference it. Actor.objects(identifiers__identifier_id=obj_id)\ .update(pull__identifiers__identifier_id=obj_id) response = {"Result": "OK"} return HttpResponse(json.dumps(response, default=json_handler), content_type="application/json") jtopts = { 'title': "Actor Identifiers", 'default_sort': mapper['default_sort'], 'listurl': reverse('crits.actors.views.%ss_listing' % (type_), args=('jtlist', )), 'deleteurl': reverse('crits.actors.views.%ss_listing' % (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) for field in jtable['fields']: if field['fieldname'] == "'name'": url = reverse('crits.actors.views.actors_listing') field['display'] = """ function (data) { return '<a href="%s?q='+data.record.id+'&search_type=actor_identifier&force_full=1">'+data.record.name+'</a>'; } """ % url break jtable['toolbar'] = [ { 'tooltip': "'Add Actor Identifier'", 'text': "'Add Actor Identifier'", 'click': "function () {$('#new-actor-identifier').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))
def generate_indicator_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` """ obj_type = Indicator type_ = "indicator" mapper = obj_type._meta['jtable_opts'] if option == "jtlist": # 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) 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': "Indicators", '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'] } config = CRITsConfig.objects().first() print config.splunk_search_url if not config.splunk_search_url: del jtopts['fields'][1] jtable = build_jtable(jtopts, request) jtable['toolbar'] = [ { 'tooltip': "'All Indicators'", 'text': "'All'", 'click': "function () {$('#indicator_listing').jtable('load', {'refresh': 'yes'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'New Indicators'", 'text': "'New'", 'click': "function () {$('#indicator_listing').jtable('load', {'refresh': 'yes', 'status': 'New'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'In Progress Indicators'", 'text': "'In Progress'", 'click': "function () {$('#indicator_listing').jtable('load', {'refresh': 'yes', 'status': 'In Progress'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'Analyzed Indicators'", 'text': "'Analyzed'", 'click': "function () {$('#indicator_listing').jtable('load', {'refresh': 'yes', 'status': 'Analyzed'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'Deprecated Indicators'", 'text': "'Deprecated'", 'click': "function () {$('#indicator_listing').jtable('load', {'refresh': 'yes', 'status': 'Deprecated'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'Add Indicator'", 'text': "'Add Indicator'", 'click': "function () {$('#new-indicator').click()}", }, ] if config.splunk_search_url: for field in jtable['fields']: if field['fieldname'].startswith("'splunk"): field['display'] = """ function (data) { return '<a href="%s' + data.record.value + '"><img src="/new_images/splunk.png" /></a>'; } """ % config.splunk_search_url 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))
def generate_actor_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` """ obj_type = Actor type_ = "actor" mapper = obj_type._meta['jtable_opts'] if option == "jtlist": # 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) 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': "Actors", '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': "'Add Actor'", 'text': "'Add Actor'", 'click': "function () {$('#new-actor').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))
def generate_actor_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` """ request.user._setup() user = request.user obj_type = Actor type_ = "actor" mapper = obj_type._meta['jtable_opts'] if option == "jtlist": # 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) return HttpResponse(json.dumps(response, default=json_handler), content_type="application/json") if option == "jtdelete": if user.has_access_to(ActorACL.DELETE): if jtable_ajax_delete(obj_type, request): response = {"Result": "OK"} else: respones = {"Result": "ERROR"} else: response = {"Result": "OK", "message": "User does not have permission to delete"} return HttpResponse(json.dumps(response, default=json_handler), content_type="application/json") jtopts = { 'title': "Actors", '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': "'Add Actor'", 'text': "'Add Actor'", 'click': "function () {$('#new-actor').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))
def generate_ip_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` """ obj_type = IP type_ = "ip" mapper = obj_type._meta['jtable_opts'] if option == "jtlist": # 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) 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': "IPs", '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 IPs'", 'text': "'All'", 'click': "function () {$('#ip_listing').jtable('load', {'refresh': 'yes'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'New IPs'", 'text': "'New'", 'click': "function () {$('#ip_listing').jtable('load', {'refresh': 'yes', 'status': 'New'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'In Progress IPs'", 'text': "'In Progress'", 'click': "function () {$('#ip_listing').jtable('load', {'refresh': 'yes', 'status': 'In Progress'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'Analyzed IPs'", 'text': "'Analyzed'", 'click': "function () {$('#ip_listing').jtable('load', {'refresh': 'yes', 'status': 'Analyzed'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'Deprecated IPs'", 'text': "'Deprecated'", 'click': "function () {$('#ip_listing').jtable('load', {'refresh': 'yes', 'status': 'Deprecated'});}", 'cssClass': "'jtable-toolbar-center'", }, { 'tooltip': "'Add IP'", 'text': "'Add IP'", 'click': "function () {$('#new-ip').click()}", }, ] if option == "inline": return render( request, "jtable.html", { 'jtable': jtable, 'jtid': '%s_listing' % type_, 'button': '%ss_tab' % type_ }, ) else: return render( request, "%s_listing.html" % type_, { 'jtable': jtable, 'jtid': '%s_listing' % type_ }, )
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))
def generate_comment_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` """ obj_type = Comment type_ = "comment" if option == "jtlist": # Sets display url details_url = '' details_url_key = "id" fields = [ "obj_type", "comment", "url_key", "created", "analyst", "source", "id" ] response = jtable_ajax_list(obj_type, details_url, details_url_key, request, includes=fields) 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': "Comments", 'default_sort': "date DESC", 'listurl': reverse('crits-%ss-views-%ss_listing' % (type_, type_), args=('jtlist', )), 'deleteurl': reverse('crits-%ss-views-%ss_listing' % (type_, type_), args=('jtdelete', )), 'searchurl': reverse('crits-%ss-views-%ss_listing' % (type_, type_)), 'fields': ["details", "obj_type", "comment", "date", "analyst", "source", "id"], 'hidden_fields': [ "id", ], 'linked_fields': [ "analyst", ], 'details_link': 'details', 'no_sort': [ 'details', ], } jtable = build_jtable(jtopts, request) if option == "inline": return render( request, "jtable.html", { 'jtable': jtable, 'jtid': '%s_listing' % type_, 'button': '%ss_tab' % type_ }, ) else: return render( request, "%s_listing.html" % type_, { 'jtable': jtable, 'jtid': '%s_listing' % type_ }, )