Exemplo n.º 1
0
def ui_sample_upload():
    """
    Sample creation from binary file.
    """
    upload_form = UploadSampleForm()
    families_choices = [(0, "None")]
    families_choices += [(f.id, f.name) for f in Family.query.order_by('name')]
    upload_form.family.choices = families_choices

    if upload_form.validate_on_submit():
        family_id = upload_form.family.data
        zipflag = upload_form.zipflag.data
        family = None
        if family_id != 0:
            family = api.get_elem_by_type("family", family_id)

        for mfile in upload_form.files.raw_data:
            file_data = mfile.stream
            file_name = secure_filename(mfile.filename)

            samples = api.dispatch_sample_creation(
                file_data,
                file_name,
                g.user,
                upload_form.level.data,
                family,
                zipflag)
            if not samples:
                flash("Error during sample creation", "error")
            else:
                for sample in samples:
                    flash("Created sample " + str(sample.id), "success")
    return redirect(url_for('webuiview.index'))
Exemplo n.º 2
0
def ui_sample_upload():
    """
    Sample creation from binary file.
    """
    upload_form = UploadSampleForm()
    families_choices = [(0, "None")]
    families_choices += [(f.id, f.name) for f in Family.query.order_by('name')]
    upload_form.family.choices = families_choices

    if upload_form.validate_on_submit():
        family_id = upload_form.family.data
        zipflag = upload_form.zipflag.data
        family = None
        if family_id != 0:
            family = api.get_elem_by_type("family", family_id)

        for mfile in upload_form.files.raw_data:
            file_data = mfile.stream
            file_name = secure_filename(mfile.filename)

            samples = api.dispatch_sample_creation(
                file_data,
                file_name,
                g.user,
                upload_form.level.data,
                family,
                zipflag)
            if len(samples) == 0:
                flash("Error during sample creation", "error")
            else:
                for sample in samples:
                    flash("Created sample " + str(sample.id), "success")
    return redirect(url_for('index'))
Exemplo n.º 3
0
def api_post_samples():
    """
    @description : Insert a new sample in database, launch analysis
    @arg: string filename
    @arg: binary data : the sample content
    @return : the sample ID
    """

    mfile = request.files['file']
    if not mfile:
        abort(400, "You must provide a file object")

    tlp_level = TLPLevel.TLPAMBER
    try:
        tlp_level = int(request.form["tlp_level"])
    except KeyError:
        app.logger.debug("Could not find the tlp_level key")

    try:
        orig_filename = request.form['filename']
    except KeyError:
        app.logger.debug("No filename provided")
        orig_filename = ""

    samples = api.dispatch_sample_creation(mfile, orig_filename)
    if len(samples) == 0:
        abort(500, "Cannot create sample")

    if tlp_level not in range(1, 6):
        app.logger.warning("Incorrect TLP level, defaulting to AMBER")
        tlp_level = TLPLevel.TLPAMBER

    for sample in samples:
        result = api.samplecontrol.set_tlp_level(sample, tlp_level)
        if result is False:
            app.logger.warning("Cannot set TLP level for sample %d" %
                               sample.id)
    result = api.samplecontrol.schema_export_many(samples)

    return jsonify({'sample': result})
Exemplo n.º 4
0
def api_post_samples():
    """
    @description : Insert a new sample in database, launch analysis
    @arg: string filename
    @arg: binary data : the sample content
    @return : the sample ID
    """

    mfile = request.files['file']
    if not mfile:
        abort(400, "You must provide a file object")

    tlp_level = TLPLevel.TLPAMBER
    try:
        tlp_level = int(request.form["tlp_level"])
    except KeyError:
        current_app.logger.debug("Could not find the tlp_level key")

    try:
        orig_filename = request.form['filename']
    except KeyError:
        current_app.logger.debug("No filename provided")
        orig_filename = ""

    samples = api.dispatch_sample_creation(mfile, orig_filename)
    if len(samples) == 0:
        abort(500, "Cannot create sample")

    if tlp_level not in range(1, 6):
        current_app.logger.warning("Incorrect TLP level, defaulting to AMBER")
        tlp_level = TLPLevel.TLPAMBER

    for sample in samples:
        result = api.samplecontrol.set_tlp_level(sample, tlp_level)
        if result is False:
            current_app.logger.warning(
                "Cannot set TLP level for sample %d" % sample.id)
    result = api.samplecontrol.schema_export_many(samples)

    return jsonify({'sample': result})