Example #1
0
    def inv_import(self):
        if request.method == "GET":
            return render_template(
                "{}/import.html".format(self.klass.__name__.lower()))
        else:
            text = request.form.get('text')
            url = request.form.get('url')

            if text:
                investigation = Investigation(import_text=text)
                investigation.save()
                return redirect(
                    url_for(
                        'frontend.InvestigationView:import_from',
                        id=investigation.id))
            else:
                try:
                    if url:
                        import_method = ImportMethod.objects.get(acts_on="url")
                        results = import_method.run(url)
                    else:
                        target = AttachedFile.from_upload(request.files['file'])
                        import_method = ImportMethod.objects.get(
                            acts_on=target.content_type)
                        results = import_method.run(target)

                    return redirect(
                        url_for(
                            'frontend.InvestigationView:import_wait',
                            id=results.id))
                except DoesNotExist:
                    flash("This file type is not supported.", "danger")
                    return render_template(
                        "{}/import.html".format(self.klass.__name__.lower()))
Example #2
0
def graph_node(klass, id):
    if klass == 'entity':
        node = get_object_or_404(Entity, id=id)
    else:
        node = get_object_or_404(Observable, id=id)

    investigation = Investigation().save()
    investigation.add([], [node])

    return render_template("graph.html", investigation=bson_renderer(investigation.info()))
Example #3
0
    def graph_node(self, klass, id):
        if klass == 'entity':
            node = get_object_or_404(Entity, id=id)
        elif klass == 'indicator':
            node = get_object_or_404(Indicator, id=id)
        else:
            node = get_object_or_404(Observable, id=id)

        investigation = Investigation().save()
        investigation.add([], [node])

        return render_template("{}/graph.html".format(self.klass.__name__.lower()), investigation=bson_renderer(investigation.info()))
Example #4
0
    def graph_node(self, klass, id):
        if klass == 'entity':
            node = get_object_or_404(Entity, id=id)
        elif klass == 'indicator':
            node = get_object_or_404(Indicator, id=id)
        else:
            node = get_object_or_404(Observable, id=id)

        investigation = Investigation(created_by=current_user.username).save()
        investigation.add([], [node])

        return render_template(
            "{}/graph.html".format(self.klass.__name__.lower()),
            investigation=bson_renderer(investigation.info()))
Example #5
0
 def multidelete(self):
     data = loads(request.data)
     ids = iterify(data['ids'])
     for i, inv in enumerate(Investigation.objects(links__id__in=ids)):
         inv.modify({"links__id": id}, set__links__S__id="local-{}-{}".format(time.time(), i))
     self.objectmanager.objects(id__in=ids).delete()
     return render({"deleted": ids})
Example #6
0
    def delete(self, id):
        """Deletes the corresponding entry from the database

        :query ObjectID id: Element ID
        :>json string deleted: The deleted element's ObjectID
        """
        obj = self.objectmanager.objects.get(id=id)
        for i, inv in enumerate(Investigation.objects(links__id=id)):
            inv.modify({"links__id": id}, set__links__S__id="local-{}-{}".format(time.time(), i))
        obj.delete()
        return render({"deleted": id})
Example #7
0
    def inv_import(self):
        if request.method == "GET":
            return render_template(
                "{}/import.html".format(self.klass.__name__.lower()),
                groups=get_user_groups())
        else:
            text = request.form.get('text')
            url = request.form.get('url')
            sharing = request.form.get('sharing')

            if text:
                investigation = Investigation(
                    created_by=current_user.username, import_text=text)
                # set sharing permissions
                investigation.save()
                investigation.sharing_permissions(sharing)
                return redirect(
                    url_for(
                        'frontend.InvestigationView:import_from',
                        id=investigation.id))
            else:
                try:
                    if url:
                        import_method = ImportMethod.objects.get(acts_on="url")
                        results = import_method.run(url)
                    elif "file" in request.files:
                        target = AttachedFile.from_upload(request.files['file'])
                        import_method = ImportMethod.objects.get(
                            acts_on=target.content_type)
                        results = import_method.run(target)
                    else:
                        flash("You need to provide an input", "danger")
                        return redirect(request.referrer)
                    return redirect(
                        url_for(
                            'frontend.InvestigationView:import_wait',
                            id=results.id))
                except DoesNotExist:
                    flash("This file type is not supported.", "danger")
                    return render_template(
                        "{}/import.html".format(self.klass.__name__.lower()))