From f63c74cf9329858a4424798708ee4b14bdba00ec Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 3 Jul 2024 17:07:08 +0200 Subject: [PATCH] Add testcommand notification --- osiris_listener.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/osiris_listener.py b/osiris_listener.py index f8b4b7e..c6160b0 100644 --- a/osiris_listener.py +++ b/osiris_listener.py @@ -1,18 +1,28 @@ from flask import Flask, request, jsonify import subprocess +from win10toast import ToastNotifier app = Flask(__name__) +toaster = ToastNotifier() @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 + # Hier neue Commands zur Prüfung einpflegen + if command.strip() == 'testcommand': + try: + toaster.show_toast("TestCommand", "Verbindung wurde getestet", duration=10) + return jsonify({'message': 'Test Command abgesetzt und Notification auf bei Host erstellt.'}) + except Exception as exc: + return jsonify({'error': str(exc)}), 500 + else: + 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