From 31df9660797988a541643c0dbc697d97d78ec410 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 3 Jul 2024 16:55:48 +0200 Subject: [PATCH] Add skeleton flask server --- osiris_listener.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 osiris_listener.py diff --git a/osiris_listener.py b/osiris_listener.py new file mode 100644 index 0000000..f8b4b7e --- /dev/null +++ b/osiris_listener.py @@ -0,0 +1,21 @@ +from flask import Flask, request, jsonify +import subprocess + +app = Flask(__name__) + +@app.route('/osiris_execute', methods=['POST']) +def execute_script(): + data = request.get_json() + command = data.get('command') + if command: + try: + result = subprocess.run(['python','-c', command], capture_output=True, text=True, shell=True) + return jsonify({'output': result.stdout, 'error': result.stderr, 'returncode': result.returncode}) + except Exception as exc: + return jsonify({'error': str(exc)}), 500 + + return jsonify({'error': 'Keinen gültigen Befehl gesendet.'}), 400 + + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=9713) \ No newline at end of file