Beispiel #1
0
    def get(self, request, *args, **kwargs):
        # Gets the latest complete report as an example
        es = Elasticsearch(settings.ELASTICSEARCH_HOSTS)
        q = {
            "size": 1,
            "sort": {
                "analysis_date": "desc"
            },
            "query": {
                "match_all": {}
            },
            "_source": ["handle", "apk_hash", "quark"]
        }
        report_example = es.search(index=settings.ELASTICSEARCH_APK_INDEX,
                                   body=q)
        tmp = transform_results(report_example)
        if tmp:
            report_example = tmp[0]
        else:
            report_example = tmp

        q = None
        matrix = None
        results = None
        list_results = False
        aggregations = []
        genetic_analysis = None

        f = SearchForm(request.GET)
        form_to_show = f
        if not request.GET:
            form_to_show = SearchForm()
        if f.is_valid():
            results, aggregations, genetic_analysis = f.do_search()
            list_results = True
            q = f.cleaned_data['q']
            matrix = get_similarity_matrix(results)

        return render(
            request, 'front/index.html', {
                'form': form_to_show,
                'results': results,
                'aggregations': aggregations,
                'genetic_analysis': genetic_analysis,
                'upload_form': BasicUploadForm(),
                'list_results': list_results,
                'report_example': report_example,
                'q': q,
                'matrix': matrix,
                'max_size': settings.MAX_APK_UPLOAD_SIZE
            })
Beispiel #2
0
 def do_search(self):
     q = self.cleaned_data['q']
     query = {
         "query": {
             "match": {
                 "apk_hash": q.lower()
             }
         },
         "_source": ["handle", "apk_hash", "size", "app_name"],
         "size": 50,
     }
     es = Elasticsearch([settings.ELASTICSEARCH_HOST])
     try:
         results = es.search(index=settings.ELASTICSEARCH_APK_INDEX,
                             body=query)
         results = transform_results(results)
         return results
     except Exception:
         return []