You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
181 lines
9.8 KiB
Python
181 lines
9.8 KiB
Python
from flask import Flask, request, jsonify
|
|
import subprocess
|
|
#from win10toast import ToastNotifier
|
|
import os
|
|
import logging
|
|
import signal
|
|
|
|
logging.basicConfig(filename='osiris_listener.log', level=logging.DEBUG, format='%(asctime)s %(message)s')
|
|
|
|
app = Flask(__name__)
|
|
#toaster = ToastNotifier()
|
|
|
|
# Global list to store process handles
|
|
processes = []
|
|
processes_info = []
|
|
|
|
# Define the scripts and their parameters
|
|
SCRIPTS = {
|
|
"start_gameservers_minecraft": [
|
|
# Vanilla (Port 25565)
|
|
{"name": "Minecraft Vanilla 1.21", "path": "C:\\Users\\4lexK\\Desktop\\GameServers\\Minecraft\\Vanilla_1-21\\start_server.py", "params": ["--java_path", "'C:\\Program Files\\Java\\jdk-22\\bin'", 'minecraft_server.1.21']},
|
|
# The 1.12.2 Pack (SanderPack) (Port 25566)
|
|
{"name": "Minecraft The 1.12.2 Pack (SanderPack)", "path": "C:\\Users\\4lexK\\Desktop\\GameServers\\Minecraft\\1-12-2-Pack\\start_server.py", "params": ["--java_path", "'C:\\Program Files\\OpenLogic\\jdk-8.0.412.08-hotspot\\bin'", 'forge-1.12.2-14.23.5.2860']},
|
|
# GT New Horizon (SanderHorizon) (Port 25567)
|
|
{"name": "Minecraft GT New Horizon 2.6.0 (SanderHorizon)", "path": "C:\\Users\\4lexK\\Desktop\\GameServers\\Minecraft\\gt_new_horizons_2.6.0\\start_server.py", "params": ["--java_path", "'C:\\Program Files\\OpenLogic\\jdk-8.0.412.08-hotspot\\bin'", 'forge-1.7.10-10.13.4.1614-1.7.10-universal']},
|
|
# rlcraft (SanderHardcore) (Port 25568)
|
|
{"name": "Minecraft rlcraft 2.9.3 (SanderHardcore)", "path": "C:\\Users\\4lexK\\Desktop\\GameServers\\Minecraft\\rlcraft\\start_server.py", "params": ["--java_path", "'C:\\Program Files\\OpenLogic\\jdk-8.0.412.08-hotspot\\\bin'", 'forge-1.12.2-14.23.5.2860']},
|
|
|
|
# Add more scripts and their parameters as needed
|
|
]
|
|
}
|
|
|
|
@app.route('/osiris_execute', methods=['POST'])
|
|
def execute_script():
|
|
logging.info("Commando zur Ausführung erhalten.")
|
|
global processes # Declare the global variable
|
|
global processes_info
|
|
data = request.get_json()
|
|
command = data.get('command')
|
|
|
|
if command:
|
|
logging.info(f"Commando: {command}")
|
|
# Hier neue Commands zur Prüfung einpflegen
|
|
clean_command = command.strip()
|
|
match clean_command:
|
|
case '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:
|
|
logging.error(f"Error executing test command: {exc}")
|
|
return jsonify({'message': f'Error: {str(exc)}'}), 500
|
|
|
|
case 'shutdown':
|
|
logging.info("Received request to shutdown.")
|
|
try:
|
|
#toaster.show_toast("Shutdown", "Shutdown Command erhalten. Host wird heruntergefahren.", duration=10)
|
|
os.system("shutdown /s /t 1")
|
|
return jsonify({'message': 'Shutdown command wurde ausgeführt. System fährt herunter.'})
|
|
except Exception as e:
|
|
logging.error(f"Error executing shutdown command: {exc}")
|
|
return jsonify({'error': str(e)}), 500
|
|
|
|
case 'start_gameservers_minecraft':
|
|
logging.info("Received request to start minecraft servers.")
|
|
#toaster.show_toast("start_gameservers_minecraft", "Starte Minecraft-Server", duration=10)
|
|
results = []
|
|
for script_info in SCRIPTS['start_gameservers_minecraft']:
|
|
path = script_info["path"]
|
|
params = script_info["params"]
|
|
script_name = script_info["name"]
|
|
try:
|
|
process = subprocess.Popen(['python', path] + params, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
|
processes.append(process)
|
|
processes_info.append({"process": process, "name": script_name})
|
|
results.append({
|
|
"script": path,
|
|
"params": params,
|
|
"pid": process.pid
|
|
#"returncode": result.returncode
|
|
})
|
|
except Exception as e:
|
|
logging.error(f"Error executing script {path}: {e}")
|
|
results.append({
|
|
"script": path,
|
|
"params": params,
|
|
"error": str(e)
|
|
})
|
|
return jsonify(results)
|
|
#return jsonify({'message': 'Minecraft-Server werden gestartet.'})
|
|
|
|
case 'stop_gameservers_minecraft':
|
|
logging.info("Received request to stop minecraft servers.")
|
|
for process in processes:
|
|
try:
|
|
#toaster.show_toast("stop_gameservers_minecraft", "Stoppe Minecraft-Server", duration=10)
|
|
process.send_signal(signal.SIGINT)
|
|
logging.info(f"Sent SIGINT to process with PID: {process.pid}")
|
|
except Exception as exc:
|
|
logging.error(f"Error sending DIGINT to process with PID {process.pid}")
|
|
processes = [] # clear process list
|
|
processes_info = []
|
|
return jsonify({'message': "Sent SIGINT to all running minecraft server scripts"})
|
|
case 'start_gameservers_dontstarve':
|
|
try:
|
|
#toaster.show_toast("start_gameservers_dontstarve", "Starte Dont Starve Together-Server", duration=10)
|
|
# hier pgm aufrufen
|
|
return jsonify({'message': 'Dont Starve Together-Server werden gestartet.'})
|
|
except Exception as exc:
|
|
logging.error(f"Error executing start_gameservers_dontstarve command: {exc}")
|
|
return jsonify({'error': str(exc)}), 500
|
|
case 'stop_gameservers_dontstarve':
|
|
try:
|
|
#toaster.show_toast("stop_gameservers_dontstarve", "Stoppe Dont Starve Together-Server", duration=10)
|
|
# hier pgm aufrufen
|
|
return jsonify({'message': 'Dont Starve Together-Server wurden angehalten.'})
|
|
except Exception as exc:
|
|
logging.error(f"Error executing stop_gameservers_dontstarve command: {exc}")
|
|
return jsonify({'error': str(exc)}), 500
|
|
case 'start_gameservers_ragnarokonline':
|
|
try:
|
|
#toaster.show_toast("start_gameservers_ragnarokonline", "Starte RO-Server", duration=10)
|
|
# hier pgm aufrufen
|
|
return jsonify({'message': 'RO-Server werden gestartet.'})
|
|
except Exception as exc:
|
|
logging.error(f"Error executing start_gameservers_ragnarokonline command: {exc}")
|
|
return jsonify({'error': str(exc)}), 500
|
|
case 'stop_gameservers_ragnarokonline':
|
|
try:
|
|
#toaster.show_toast("stop_gameservers_ragnarokonline", "Stoppe RO-Server", duration=10)
|
|
# hier pgm aufrufen
|
|
return jsonify({'message': 'RO-Server wurden angehalten.'})
|
|
except Exception as exc:
|
|
logging.error(f"Error executing stop_gameservers_ragnarokonline command: {exc}")
|
|
return jsonify({'error': str(exc)}), 500
|
|
case 'start_gameservers_wow':
|
|
try:
|
|
#toaster.show_toast("start_gameservers_wow", "Starte WoW-Server", duration=10)
|
|
# hier pgm aufrufen
|
|
return jsonify({'message': 'WoW-Server werden gestartet.'})
|
|
except Exception as exc:
|
|
logging.error(f"Error executing start_gameservers_wow command: {exc}")
|
|
return jsonify({'error': str(exc)}), 500
|
|
case 'stop_gameservers_wow':
|
|
try:
|
|
#toaster.show_toast("stop_gameservers_wow", "Stoppe WoW-Server", duration=10)
|
|
# hier pgm aufrufen
|
|
return jsonify({'message': 'WoW-Server wurden angehalten.'})
|
|
except Exception as exc:
|
|
logging.error(f"Error executing stop_gameservers_wow command: {exc}")
|
|
return jsonify({'error': str(exc)}), 500
|
|
|
|
case _:
|
|
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:
|
|
logging.error(f"Error executing command: {exc}")
|
|
return jsonify({'error': str(exc)}), 500
|
|
|
|
@app.route('/status', methods=['GET'])
|
|
def status():
|
|
logging.info("Status Check received.")
|
|
return jsonify({'status': 'online'})
|
|
|
|
|
|
@app.route('/status_servers', methods=['GET'])
|
|
def status_gameservers():
|
|
logging.info("Check Status der Server")
|
|
global processes_info
|
|
running_servers = []
|
|
for process in processes_info:
|
|
running_servers.append(process['name'])
|
|
server_list = "\n - ".join(running_servers)
|
|
return jsonify({"message": f"Aktuell laufende Server: {server_list}" })
|
|
|
|
|
|
if __name__ == '__main__':
|
|
#toaster.show_toast("Starte Osiris", "Osiris Listener wurde gestartet. Warte auf Befehle...", duration=30)
|
|
logging.info("Starte Server.")
|
|
app.run(host='0.0.0.0', port=9713) |