Beispiel #1
0
def manualurlanalysisrequest():
    # jsondata = request.form.get("dna_config");

    # 파일 로드
    if request.method == 'POST':
        urldata = request.form.get('_manualurlRequest')
        if urldata:
            datenowstr = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
            file_name = "request_" + datenowstr + ".txt"
            pathandFilename = "/usr/gsp/nfs/user/url/" + file_name
            try:
                text_file = open(pathandFilename, "w")
                text_file.write(urldata)
                text_file.close()
            except IOError as e:
                raise InvalidUsage("File write error " + e.message)
        else:
            raise InvalidUsage("No url received! ")

    else:
        raise InvalidUsage("No Post method received")

    return json.dumps({'success': True}), 200, {
        'ContentType': 'application/json'
    }
Beispiel #2
0
def addreanalysisfiledata():

    # 파일 로드
    if request.method == 'POST':
        file = request.files['file']
        if file:
            file_name = secure_filename(file.filename)

            try:
                file.save(os.path.join("/usr/gsp/nfs/user/file", file_name))
            except IOError as e:
                raise InvalidUsage("File write failure " + e.message)
            except Exception as e:
                raise InvalidUsage("Unknown failure " + e.message)
    else:
        raise InvalidUsage("No file name found ")

    return json.dumps({'success': True}), 200, {
        'ContentType': 'application/json'
    }
Beispiel #3
0
def setMaxWindowValueSetNP():
    max_window = CommonCode.query.filter_by(
        GroupCode='max_window_value').first()
    max_window.EXT1 = request.form.get('max_window_value')
    try:
        db_session.commit()
    except Exception as e:
        db_session.rollback()
        raise InvalidUsage('DB 저장 오류', status_code=501)

    return json.dumps({'success': True}), 200, {
        'ContentType': 'application/json'
    }
Beispiel #4
0
def deleteSingleElement():
    logList = None

    _index = request.form.get('_index')
    _id = request.form.get('_id')

    es = Elasticsearch([{
        'host': app.config['ELASTICSEARCH_URI'],
        'port': app.config['ELASTICSEARCH_PORT']
    }])

    deleteDoc = {
        "query": {
            "bool": {
                "must": [{
                    "match": {
                        "analysis_info_id": {
                            "query": _id,
                            "type": "phrase"
                        }
                    }
                }]
            }
        }
    }

    try:
        res = es.delete(index=_index, doc_type="analysis_info", id=_id)
    except Exception as e:
        raise InvalidUsage('Elastic error ' + e.message, status_code=501)

    try:
        res = es.delete_by_query(index=_index,
                                 body=deleteDoc,
                                 doc_type="analysis_file_detail_info",
                                 request_timeout=360)
        #res = es.delete(index=_index, doc_type="analysis_file_detail_info", id=_id)
    except Exception as e:
        pass

    try:
        res = es.delete_by_query(index=_index,
                                 body=deleteDoc,
                                 doc_type="analysis_url_detail_info",
                                 request_timeout=360)
    except Exception as e:
        pass

    return json.dumps({'success': True}), 200, {
        'ContentType': 'application/json'
    }
Beispiel #5
0
def reanalysisRequest():
    logList = None

    _index = request.form.get('_index')
    _id = request.form.get('_id')

    es = Elasticsearch([{
        'host': app.config['ELASTICSEARCH_URI'],
        'port': app.config['ELASTICSEARCH_PORT']
    }])
    query_type = "analysis_info"
    docupdate = reanalysisRequestQuery(request, query_type)
    try:
        res = es.update(index=_index,
                        doc_type="analysis_info",
                        id=_id,
                        body=docupdate,
                        request_timeout=360)
    except Exception as e:
        raise InvalidUsage("error " + e.message, status_code=501)

    return json.dumps({'success': True}), 200, {
        'ContentType': 'application/json'
    }
Beispiel #6
0
def maliciouscodedownload():
    # jsondata = request.form.get("dna_config");

    filePathsList = []
    zipfileNameStr = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S")

    # 파일 로드
    if request.method == 'POST':
        filepathnfs = request.form.get('_filepath')
        if filepathnfs:
            filePathsList = filepathnfs.split(",")
            zip_filename = "%s.zip" % zipfileNameStr

            data = io.BytesIO()

            with zipfile.ZipFile(data, mode="w") as z:
                for f_name in filePathsList:
                    z.write(f_name, basename(f_name))

            data.seek(0)

            return send_file(data,
                             mimetype='application/zip',
                             as_attachment=True,
                             attachment_filename=zip_filename)

            # s = StringIO.StringIO()
            #
            # zf = zipfile.ZipFile(s, "w")
            #
            #
            # for fpath in filePathsList:
            #     fdir, fname = os.path.split(fpath)
            #     zip_path = os.path.join(zipfileNameStr, fname)
            #
            #     zf.write(fpath, zip_path)
            #
            # zf.close()
            #
            # try:
            #     headers = Headers()
            #     headers.add('Content-Disposition', 'attachment', filename=zip_filename)
            #     download_obj = open(s.getvalue(), "rb")
            #     headers['Content-Length'] = os.path.getsize(s.getvalue())
            # except IOError as e:
            #     raise InvalidUsage("File not found" + e.message)
            #
            # def generate():
            #     for block in iter(lambda: download_obj.read(4096), b""):
            #         yield block
            #
            #     download_obj.close()
            #
            # return Response(generate(), mimetype="application/octet-stream", headers=headers)

    else:
        raise InvalidUsage("No Post method received")

    return json.dumps({'success': True}), 200, {
        'ContentType': 'application/json'
    }