Пример #1
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")

    orig_filename = request.form['filename']
    msample = api.create_sample_and_run_analysis(mfile, orig_filename)
    if msample is None:
        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

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

    result = api.samplecontrol.schema_export(msample)

    return jsonify({'sample': result})
Пример #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
        family = None
        if family_id != 0:
            family = api.familycontrol.get_by_id(family_id)
            if family is None:
                flash("Could not find the family", "error")
                abort(404)

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

            sample = api.create_sample_and_run_analysis(
                file_data, file_name, g.user, upload_form.level.data, family)
            if sample:
                flash("Created sample "+ str(sample.id), "success")
            else:
                flash("Error during sample creation", "error")
    return redirect(url_for('index'))
Пример #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:
        return -1
    orig_filename = request.form['filename']
    sid = api.create_sample_and_run_analysis(mfile, orig_filename)
    if sid == -1:
        return redirect('404')

    result = api.samplecontrol.schema_export(sid)
    return jsonify({'sample': result})
Пример #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:
        return -1
    orig_filename = request.form['filename']
    sid = api.create_sample_and_run_analysis(mfile, orig_filename)
    if sid == -1:
        return redirect('404')

    result = api.samplecontrol.schema_export(sid)
    return jsonify({'sample': result})
Пример #5
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():
        file_data = upload_form.file.data
        family_id = upload_form.family.data
        family = None
        if family_id != 0:
            family = api.familycontrol.get_by_id(family_id)
            if family is None:
                abort(404)
        file_name = secure_filename(upload_form.file.data.filename)
        sample = api.create_sample_and_run_analysis(file_data, file_name,
                                                    g.user,
                                                    upload_form.level.data,
                                                    family)
        if sample:
            return redirect(url_for('view_sample', sample_id=sample.id))
    return redirect(url_for('index'))