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()))
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()))
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()))