First commit
This commit is contained in:
88
server/backend/app/blueprints/config.py
Normal file
88
server/backend/app/blueprints/config.py
Normal file
@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from flask import Blueprint, request, jsonify, send_file
|
||||
from app.decorators import *
|
||||
from app.classes.config import Config
|
||||
import sys
|
||||
|
||||
config_bp = Blueprint("config", __name__)
|
||||
config = Config()
|
||||
|
||||
@config_bp.route('/switch/<cat>/<key>', methods=['GET'])
|
||||
@require_header_token
|
||||
def switch(cat, key):
|
||||
"""
|
||||
Switch the Boolean value of a configuration key.
|
||||
:return: status in JSON
|
||||
"""
|
||||
try:
|
||||
value = config.read_config((cat, key))
|
||||
if value:
|
||||
config.write_config(cat, key, False)
|
||||
res = { "status" : True,
|
||||
"message" : "Key switched to false" }
|
||||
else:
|
||||
config.write_config(cat, key, True)
|
||||
res = { "status" : True,
|
||||
"message" : "Key switched to true" }
|
||||
except:
|
||||
res = { "status" : True,
|
||||
"message" : "Issue while changing value" }
|
||||
|
||||
return jsonify(res)
|
||||
|
||||
@config_bp.route('/edit/<cat>/<key>/<path:value>', methods=['GET'])
|
||||
@require_header_token
|
||||
def edit(cat, key, value):
|
||||
"""
|
||||
Edit the string (or array) value of a configuration key.
|
||||
:return: status in JSON
|
||||
"""
|
||||
value = value.split("|") if "|" in value else value
|
||||
if config.write_config(cat, key, value):
|
||||
res = { "status" : True,
|
||||
"message" : "Configuration updated" }
|
||||
else:
|
||||
res = { "status" : False,
|
||||
"message" : "Can't edit this configuration key" }
|
||||
|
||||
return jsonify(res)
|
||||
|
||||
@config_bp.route('/db/export', methods=['GET'])
|
||||
@require_get_token
|
||||
def export_db():
|
||||
"""
|
||||
Export the database.
|
||||
:return: current database as attachment
|
||||
"""
|
||||
return config.export_db()
|
||||
|
||||
@config_bp.route('/db/import', methods=['POST'])
|
||||
@require_header_token
|
||||
def import_db():
|
||||
"""
|
||||
Import a database and replace the existant.
|
||||
:return: status in JSON
|
||||
"""
|
||||
try:
|
||||
f = request.files["file"]
|
||||
assert f.read(15) == b"SQLite format 3"
|
||||
d = "/".join(sys.path[0].split("/")[:-2])
|
||||
f.save("/{}/tinycheck.sqlite3".format(d))
|
||||
res = { "status" : True,
|
||||
"message" : "Database updated" }
|
||||
except:
|
||||
res = { "status" : False,
|
||||
"message" : "Error while database upload" }
|
||||
return jsonify(res)
|
||||
|
||||
@config_bp.route('/list', methods=['GET'])
|
||||
def list():
|
||||
"""
|
||||
List key, values of the configuration
|
||||
:return: configuration in JSON
|
||||
"""
|
||||
res = config.export_config()
|
||||
res["backend"]["password"] = ""
|
||||
return jsonify(res)
|
80
server/backend/app/blueprints/ioc.py
Normal file
80
server/backend/app/blueprints/ioc.py
Normal file
@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from flask import Blueprint, jsonify, Response
|
||||
from app.decorators import require_header_token, require_get_token
|
||||
from app.classes.iocs import IOCs
|
||||
|
||||
import json
|
||||
|
||||
ioc_bp = Blueprint("ioc", __name__)
|
||||
ioc = IOCs()
|
||||
|
||||
|
||||
@ioc_bp.route('/add/<ioc_type>/<ioc_tag>/<ioc_tlp>/<path:ioc_value>', methods=['GET'])
|
||||
@require_header_token
|
||||
def add(ioc_type, ioc_tag, ioc_tlp, ioc_value):
|
||||
"""
|
||||
Parse and add an IOC to the database.
|
||||
:return: status of the operation in JSON
|
||||
"""
|
||||
source = "backend"
|
||||
res = IOCs.add(ioc_type, ioc_tag, ioc_tlp, ioc_value, source)
|
||||
return jsonify(res)
|
||||
|
||||
|
||||
@ioc_bp.route('/delete/<ioc_id>', methods=['GET'])
|
||||
@require_header_token
|
||||
def delete(ioc_id):
|
||||
"""
|
||||
Delete an IOC by its id to the database.
|
||||
:return: status of the operation in JSON
|
||||
"""
|
||||
res = IOCs.delete(ioc_id)
|
||||
return jsonify(res)
|
||||
|
||||
|
||||
@ioc_bp.route('/search/<term>', methods=['GET'])
|
||||
@require_header_token
|
||||
def search(term):
|
||||
"""
|
||||
Search IOCs in the database.
|
||||
:return: potential results in JSON.
|
||||
"""
|
||||
res = IOCs.search(term)
|
||||
return jsonify({"results": [i for i in res]})
|
||||
|
||||
|
||||
@ioc_bp.route('/get/types')
|
||||
@require_header_token
|
||||
def get_types():
|
||||
"""
|
||||
Retreive a list of IOCs types.
|
||||
:return: list of types in JSON.
|
||||
"""
|
||||
res = IOCs.get_types()
|
||||
return jsonify({"types": [t for t in res]})
|
||||
|
||||
|
||||
@ioc_bp.route('/get/tags')
|
||||
@require_header_token
|
||||
def get_tags():
|
||||
"""
|
||||
Retreive a list of IOCs tags.
|
||||
:return: list of types in JSON.
|
||||
"""
|
||||
res = IOCs.get_tags()
|
||||
return jsonify({"tags": [t for t in res]})
|
||||
|
||||
|
||||
@ioc_bp.route('/export')
|
||||
@require_get_token
|
||||
def get_all():
|
||||
"""
|
||||
Retreive a list of all IOCs.
|
||||
:return: list of iocs in JSON.
|
||||
"""
|
||||
res = IOCs.get_all()
|
||||
return Response(json.dumps({"iocs": [i for i in res]}),
|
||||
mimetype='application/json',
|
||||
headers={'Content-Disposition': 'attachment;filename=iocs-export.json'})
|
68
server/backend/app/blueprints/whitelist.py
Normal file
68
server/backend/app/blueprints/whitelist.py
Normal file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from flask import Blueprint, jsonify, Response
|
||||
from app.decorators import require_header_token, require_get_token
|
||||
from app.classes.whitelist import WhiteList
|
||||
import json
|
||||
|
||||
whitelist_bp = Blueprint("whitelist", __name__)
|
||||
whitelist = WhiteList()
|
||||
|
||||
|
||||
@whitelist_bp.route('/add/<elem_type>/<path:elem_value>', methods=['GET'])
|
||||
@require_header_token
|
||||
def add(elem_type, elem_value):
|
||||
"""
|
||||
Parse and add an element to be whitelisted.
|
||||
:return: status of the operation in JSON
|
||||
"""
|
||||
source = "backend"
|
||||
res = whitelist.add(elem_type, elem_value, source)
|
||||
return jsonify(res)
|
||||
|
||||
|
||||
@whitelist_bp.route('/delete/<elem_id>', methods=['GET'])
|
||||
@require_header_token
|
||||
def delete(elem_id):
|
||||
"""
|
||||
Delete an element by its id to the database.
|
||||
:return: status of the operation in JSON
|
||||
"""
|
||||
res = whitelist.delete(elem_id)
|
||||
return jsonify(res)
|
||||
|
||||
|
||||
@whitelist_bp.route('/search/<element>', methods=['GET'])
|
||||
@require_header_token
|
||||
def search(element):
|
||||
"""
|
||||
Search elements in the database.
|
||||
:return: potential results in JSON.
|
||||
"""
|
||||
res = whitelist.search(element)
|
||||
return jsonify({"results": [e for e in res]})
|
||||
|
||||
|
||||
@whitelist_bp.route('/get/types')
|
||||
@require_header_token
|
||||
def get_types():
|
||||
"""
|
||||
Retrieve a list of whitelisted elements types.
|
||||
:return: list of types in JSON.
|
||||
"""
|
||||
res = whitelist.get_types()
|
||||
return jsonify({"types": [t for t in res]})
|
||||
|
||||
|
||||
@whitelist_bp.route('/export')
|
||||
@require_get_token
|
||||
def get_all():
|
||||
"""
|
||||
Retreive a list of all elements.
|
||||
:return: list of elements in JSON.
|
||||
"""
|
||||
res = whitelist.get_all()
|
||||
return Response(json.dumps({"elements": [e for e in res]}),
|
||||
mimetype='application/json',
|
||||
headers={'Content-Disposition': 'attachment;filename=whitelist-export.json'})
|
Reference in New Issue
Block a user