diff --git a/backend/setup-sigma-versions.sh b/backend/setup-sigma-versions.sh index 552afde..fb218d3 100755 --- a/backend/setup-sigma-versions.sh +++ b/backend/setup-sigma-versions.sh @@ -17,5 +17,12 @@ for VERSION in $SIGMA_VERSIONS; do # remove if installed because of https://github.com/redsand/pySigma-backend-hawk/issues/1 uv -q remove pySigma-backend-hawk + + # TODO: some problems with kusto backend, disable for now + uv -q remove pySigma-backend-kusto + + # remove unused pyparsing imports in older version, see https://github.com/SigmaHQ/pySigma/pull/289#issuecomment-2410153076 + find ./ -iwholename "*sigma/conversion/base.py" -exec sed -i "/from pyparsing import Set/d" {} + + find ./ -iwholename "*sigma/exceptions.py" -exec sed -i "/from pyparsing import List/d" {} + cd .. done diff --git a/frontend/frontend.py b/frontend/frontend.py index 4c2bd06..4de282c 100755 --- a/frontend/frontend.py +++ b/frontend/frontend.py @@ -6,52 +6,63 @@ from flask import Flask, render_template, request, jsonify app = Flask(__name__) -sigma_versions = [os.path.basename(it.path) for it in os.scandir('../backend/') if it.is_dir()] +sigma_versions = [ + os.path.basename(it.path) for it in os.scandir("../backend/") if it.is_dir() +] + + +def version_key(version): + return tuple(map(int, version.split("."))) + def get_port_from_version(version): - pattern = r'^\d+\.\d+\.\d+$' + pattern = r"^\d+\.\d+\.\d+$" if re.match(pattern, version): - return int(f'8{version.replace(".","")}') + return int(f'8{version.replace(".", "")}') else: return None + @app.route("/") def home(): - versions = sigma_versions - latest_version = sigma_versions[-1:][0] - port = get_port_from_version(latest_version) - targets = requests.get(f'http://localhost:{port}/api/v1/targets').json() - formats = requests.get(f'http://localhost:{port}/api/v1/formats').json() - pipelines = requests.get(f'http://localhost:{port}/api/v1/pipelines').json() + return render_template("index.html") - return render_template( - "index.html" - ) @app.route("/api/v1/sigma-versions", methods=["GET"]) def get_versions(): - return jsonify(sigma_versions[::-1]) + return jsonify(sorted(sigma_versions, key=version_key, reverse=True)) + @app.route("/api/v1//targets", methods=["GET"]) def get_targets(version): port = get_port_from_version(version) - return requests.get(f'http://localhost:{port}/api/v1/targets', params=dict(request.args)).json() + return requests.get( + f"http://localhost:{port}/api/v1/targets", params=dict(request.args) + ).json() + @app.route("/api/v1//formats", methods=["GET"]) def get_formats(version): port = get_port_from_version(version) - return requests.get(f'http://localhost:{port}/api/v1/formats', params=dict(request.args)).json() + return requests.get( + f"http://localhost:{port}/api/v1/formats", params=dict(request.args) + ).json() + @app.route("/api/v1//pipelines", methods=["GET"]) def get_pipelines(version): port = get_port_from_version(version) - return requests.get(f'http://localhost:{port}/api/v1/pipelines', params=dict(request.args)).json() + return requests.get( + f"http://localhost:{port}/api/v1/pipelines", params=dict(request.args) + ).json() + @app.route("/api/v1//convert", methods=["POST"]) def convert(version): port = get_port_from_version(version) payload = request.json - return requests.post(f'http://localhost:{port}/api/v1/convert', json=payload).text + return requests.post(f"http://localhost:{port}/api/v1/convert", json=payload).text + if __name__ == "__main__": app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 8000)))