|
|
|
@ -2,7 +2,7 @@ import os
|
|
|
|
|
import logging
|
|
|
|
|
from flask import Flask, request, jsonify
|
|
|
|
|
#from win10toast import ToastNotifier
|
|
|
|
|
import asyncio
|
|
|
|
|
#import asyncio
|
|
|
|
|
import subprocess
|
|
|
|
|
import signal
|
|
|
|
|
import psutil
|
|
|
|
@ -115,11 +115,11 @@ def execute_script():
|
|
|
|
|
case 'testcommand':
|
|
|
|
|
try:
|
|
|
|
|
#toaster.show_toast("TestCommand", "Verbindung wurde getestet", d)uration=10)
|
|
|
|
|
asyncio.run(send_telegram_message("Test command executed."))
|
|
|
|
|
#asyncio.run(send_telegram_message("Test command executed."))
|
|
|
|
|
return jsonify({'message': 'Test Command abgesetzt und Notification auf bei Host erstellt.'})
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
logging.error(f"Error executing test command: {exc}")
|
|
|
|
|
asyncio.run(send_telegram_message(f"Error executing test command: {e}"))
|
|
|
|
|
#asyncio.run(send_telegram_message(f"Error executing test command: {e}"))
|
|
|
|
|
return jsonify({'message': f'Error: {str(exc)}'}), 500
|
|
|
|
|
|
|
|
|
|
case 'shutdown':
|
|
|
|
@ -127,11 +127,11 @@ def execute_script():
|
|
|
|
|
try:
|
|
|
|
|
#toaster.show_toast("Shutdown", "Shutdown Command erhalten. Host wird heruntergefahren.", duration=10)
|
|
|
|
|
os.system("shutdown /s /t 1")
|
|
|
|
|
asyncio.run(send_telegram_message("Ich schlafe dann weiter. Bis demnächst :-)"))
|
|
|
|
|
#asyncio.run(send_telegram_message("Ich schlafe dann weiter. Bis demnächst :-)"))
|
|
|
|
|
return jsonify({'message': 'Shutdown command wurde ausgeführt. System fährt herunter.'})
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logging.error(f"Error executing shutdown command: {exc}")
|
|
|
|
|
asyncio.run(send_telegram_message(f"Error executing shutdown command: {e}"))
|
|
|
|
|
#asyncio.run(send_telegram_message(f"Error executing shutdown command: {e}"))
|
|
|
|
|
return jsonify({"message": "Fehler beim veranlassen des Shutdowns", 'error': str(e)}), 500
|
|
|
|
|
|
|
|
|
|
case 'start_gameservers_minecraft':
|
|
|
|
@ -174,7 +174,7 @@ def execute_script():
|
|
|
|
|
"params": params,
|
|
|
|
|
"error": str(e)
|
|
|
|
|
})
|
|
|
|
|
asyncio.run(send_telegram_message("Minecraft-Server wurden gestartet."))
|
|
|
|
|
#asyncio.run(send_telegram_message("Minecraft-Server wurden gestartet."))
|
|
|
|
|
return jsonify({"message": "Start der Server wurde veranlasst", "results": results})
|
|
|
|
|
#return jsonify({'message': 'Minecraft-Server werden gestartet.'})
|
|
|
|
|
|
|
|
|
@ -193,7 +193,7 @@ def execute_script():
|
|
|
|
|
logging.error(f"Error sending SIGINT to process with PID {process.pid}")
|
|
|
|
|
processes = [] # clear process list
|
|
|
|
|
processes_info = []
|
|
|
|
|
asyncio.run(send_telegram_message("Minecraft-Server wurden heruntergefahren."))
|
|
|
|
|
#asyncio.run(send_telegram_message("Minecraft-Server wurden heruntergefahren."))
|
|
|
|
|
return jsonify({'message': "SIGINT (CTRL-C an alle laufenden Minecraft server gesendet."})
|
|
|
|
|
case 'start_gameservers_dontstarve':
|
|
|
|
|
try:
|
|
|
|
@ -247,18 +247,18 @@ def execute_script():
|
|
|
|
|
case _:
|
|
|
|
|
try:
|
|
|
|
|
result = subprocess.run(['python','-c', command], capture_output=True, text=True, shell=True)
|
|
|
|
|
send_telegram_message(f"Script executed with output: {result.stdout}")
|
|
|
|
|
#send_telegram_message(f"Script executed with output: {result.stdout}")
|
|
|
|
|
return jsonify({'output': result.stdout, 'error': result.stderr, 'returncode': result.returncode})
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
logging.error(f"Error executing command: {exc}")
|
|
|
|
|
send_telegram_message(f"Error executing script: {e}")
|
|
|
|
|
#send_telegram_message(f"Error executing script: {e}")
|
|
|
|
|
return jsonify({'error': str(exc)}), 500
|
|
|
|
|
|
|
|
|
|
@app.route('/status', methods=['GET'])
|
|
|
|
|
def status():
|
|
|
|
|
logging.info("Status Check received.")
|
|
|
|
|
asyncio.run(send_telegram_message(f"Bin da. Wer nohoch?"))
|
|
|
|
|
return jsonify({'status': 'online'})
|
|
|
|
|
#asyncio.run(send_telegram_message(f"Bin da. Wer nohoch?"))
|
|
|
|
|
return jsonify({'message': 'status = online'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/status_servers', methods=['GET'])
|
|
|
|
@ -270,7 +270,7 @@ def status_gameservers():
|
|
|
|
|
for process in processes_info:
|
|
|
|
|
running_servers.append(process['name'])
|
|
|
|
|
server_list = "\n - ".join(running_servers)
|
|
|
|
|
asyncio.run(send_telegram_message(f"Aktuell laufende Server: {server_list}"))
|
|
|
|
|
#asyncio.run(send_telegram_message(f"Aktuell laufende Server: {server_list}"))
|
|
|
|
|
|
|
|
|
|
return jsonify({"message": f"Aktuell laufende Server: {server_list}" })
|
|
|
|
|
|
|
|
|
@ -278,6 +278,6 @@ def status_gameservers():
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
#toaster.show_toast("Starte Osiris", "Osiris Listener wurde gestartet. Warte auf Befehle...", duration=30)
|
|
|
|
|
logging.info("Starte Server.")
|
|
|
|
|
asyncio.run(send_telegram_message(f"Nuc_Morroc hier. Bin jetzt wach ;-)"))
|
|
|
|
|
#asyncio.run(send_telegram_message(f"Nuc_Morroc hier. Bin jetzt wach ;-)"))
|
|
|
|
|
|
|
|
|
|
app.run(host='0.0.0.0', port=9713)
|