from flask import * import libtmux app = Flask("Terradash") server = libtmux.Server() session = None def initialize_tmux_session(): global session # Versuche, die bestehende Session zu finden if server.has_session("terradash"): session = server.sessions.get(session_name="terradash") def get_term(): print(session) try: if not session: print(session) return ["No Terminal is running"] window = session.active_window #rpane = window.panes[1] lpane = window.panes[0] return lpane.capture_pane() except Exception as e: return f"Error: {e}" def enter_command(command): print(session) try: if not session: print(session) return ["No Terminal is running"] window = session.active_window #rpane = window.panes[1] lpane = window.panes[0] lpane.send_keys(command) except Exception as e: return f"Error: {e}" @app.route('/term', methods=['GET',"POST"]) def get_terminal_output(): if request.method == "POST": data = list(request.data.decode()) print(type(data),data,len(data)) if data == "bla": print("test") enter_command("bla") return ["sucessful"] elif request.method == "GET": return get_term() @app.route("/") def root(): return render_template("index.html") if __name__ == "__main__": initialize_tmux_session() app.run(host="0.0.0.0",debug=True)