|
|
|
@ -6,8 +6,8 @@ import signal
|
|
|
|
|
import psutil
|
|
|
|
|
#from win10toast import ToastNotifier
|
|
|
|
|
import telegram
|
|
|
|
|
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
|
|
|
|
|
|
|
|
|
|
from telegram.ext import Updater, CommandHandler, MessageHandler, filters
|
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logging.basicConfig(filename='osiris_listener.log', level=logging.DEBUG, format='%(asctime)s %(message)s')
|
|
|
|
@ -20,7 +20,7 @@ TELEGRAM_BOT_TOKEN = '5103145116:AAE_sVgkx8atxgizMuE38ClwbRLAyDUMSeM'
|
|
|
|
|
bot = telegram.Bot(token=TELEGRAM_BOT_TOKEN)
|
|
|
|
|
|
|
|
|
|
# File to store subscriber chat IDs
|
|
|
|
|
SUBSCRIBERS_FILE = 'subscribers.txt'
|
|
|
|
|
SUBSCRIBERS_FILE = 'telegramm_subscribers.txt'
|
|
|
|
|
|
|
|
|
|
# Global list to store process handles
|
|
|
|
|
processes = []
|
|
|
|
@ -73,18 +73,17 @@ def save_subscriber(chat_id):
|
|
|
|
|
with open(SUBSCRIBERS_FILE, 'a') as file:
|
|
|
|
|
file.write(f"{chat_id}\n")
|
|
|
|
|
|
|
|
|
|
def send_telegram_message(message):
|
|
|
|
|
async def send_telegram_message(message):
|
|
|
|
|
"""Send a message to all subscribers."""
|
|
|
|
|
subscribers = load_subscribers()
|
|
|
|
|
for chat_id in subscribers:
|
|
|
|
|
try:
|
|
|
|
|
prepped_message = f"[nuc_morroc]{message}"
|
|
|
|
|
bot.send_message(chat_id=chat_id, text=message)
|
|
|
|
|
prepped_message = f"[nuc_morroc]{message}"
|
|
|
|
|
await bot.send_message(chat_id=chat_id, text=prepped_message)
|
|
|
|
|
except telegram.error.TelegramError as e:
|
|
|
|
|
logging.error(f"Error sending message to {chat_id}: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/osiris_execute', methods=['POST'])
|
|
|
|
|
def execute_script():
|
|
|
|
|
logging.info("Commando zur Ausführung erhalten.")
|
|
|
|
@ -103,12 +102,12 @@ def execute_script():
|
|
|
|
|
match clean_command:
|
|
|
|
|
case 'testcommand':
|
|
|
|
|
try:
|
|
|
|
|
#toaster.show_toast("TestCommand", "Verbindung wurde getestet", duration=10)
|
|
|
|
|
send_telegram_message("Test command executed.")
|
|
|
|
|
#toaster.show_toast("TestCommand", "Verbindung wurde getestet", d)uration=10)
|
|
|
|
|
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}")
|
|
|
|
|
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':
|
|
|
|
@ -116,11 +115,11 @@ def execute_script():
|
|
|
|
|
try:
|
|
|
|
|
#toaster.show_toast("Shutdown", "Shutdown Command erhalten. Host wird heruntergefahren.", duration=10)
|
|
|
|
|
os.system("shutdown /s /t 1")
|
|
|
|
|
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}")
|
|
|
|
|
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':
|
|
|
|
@ -163,7 +162,7 @@ def execute_script():
|
|
|
|
|
"params": params,
|
|
|
|
|
"error": str(e)
|
|
|
|
|
})
|
|
|
|
|
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.'})
|
|
|
|
|
|
|
|
|
@ -182,7 +181,7 @@ def execute_script():
|
|
|
|
|
logging.error(f"Error sending SIGINT to process with PID {process.pid}")
|
|
|
|
|
processes = [] # clear process list
|
|
|
|
|
processes_info = []
|
|
|
|
|
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:
|
|
|
|
@ -246,7 +245,7 @@ def execute_script():
|
|
|
|
|
@app.route('/status', methods=['GET'])
|
|
|
|
|
def status():
|
|
|
|
|
logging.info("Status Check received.")
|
|
|
|
|
send_telegram_message(f"Bin da. Wer nohoch?")
|
|
|
|
|
asyncio.run(send_telegram_message(f"Bin da. Wer nohoch?"))
|
|
|
|
|
return jsonify({'status': 'online'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -258,7 +257,7 @@ def status_gameservers():
|
|
|
|
|
for process in processes_info:
|
|
|
|
|
running_servers.append(process['name'])
|
|
|
|
|
server_list = "\n - ".join(running_servers)
|
|
|
|
|
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}" })
|
|
|
|
|
|
|
|
|
@ -276,5 +275,5 @@ def subscribe():
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
#toaster.show_toast("Starte Osiris", "Osiris Listener wurde gestartet. Warte auf Befehle...", duration=30)
|
|
|
|
|
logging.info("Starte Server.")
|
|
|
|
|
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)
|