Terra-Dash/app.py

86 lines
2.1 KiB
Python
Raw Normal View History

2024-09-16 21:01:46 +02:00
<<<<<<< HEAD
2024-09-16 13:04:46 +02:00
#!/usr/bin/python3
2024-09-16 21:01:46 +02:00
=======
#!/usr/bi/python3
>>>>>>> 079d2a0 (terminal intigration)
2024-09-13 15:07:56 +02:00
from flask import *
from main import launchserver
2024-09-13 15:07:56 +02:00
import libtmux
2024-09-13 15:07:56 +02:00
app = Flask("Terradash")
server = libtmux.Server()
session = None
2024-09-13 15:07:56 +02:00
def initialize_tmux_session():
global session
# Versuche, die bestehende Session zu finden
if server.has_session("terradash"):
session = server.sessions.get(session_name="terradash")
2024-09-13 15:07:56 +02:00
def get_term():
lpane = getlpane()
return lpane.capture_pane(), lpane.pane_current_command
def getlpane() -> libtmux.Pane:
2024-09-13 15:07:56 +02:00
print(session)
if not session:
print(session)
return ["No Terminal is running"]
window = session.active_window
lpane = window.panes[0]
return lpane
@app.route("/term", methods=["GET", "POST"])
2024-09-13 15:07:56 +02:00
def get_terminal_output():
if request.method == "POST":
2024-09-16 21:01:46 +02:00
<<<<<<< HEAD
data = request.data.decode()
print(data)
2024-09-13 15:07:56 +02:00
if data == "bla":
print("test")
getlpane().send_keys("test")
elif data == "start":
launchserver(getlpane())
elif data == "stop":
getlpane().send_keys("exit")
2024-09-13 15:07:56 +02:00
return ["sucessful"]
2024-09-16 21:01:46 +02:00
=======
data = request.get_json()#json.loads(request.data.decode())
print(data,type(data))
content = data["content"]
if content[0] == "command":
if content[1] == "start" and getlpane().pane_current_command == "bash":
launchserver(getlpane())
elif content[1] == "stop" and getlpane().pane_current_command == "mono":
getlpane().send_keys("\nexit")
elif content[1] == "terminal-command" and getlpane().pane_current_command == "mono":
getlpane().send_keys(content[2])
return ["sucessful"]
>>>>>>> 079d2a0 (terminal intigration)
2024-09-13 15:07:56 +02:00
elif request.method == "GET":
term = get_term()
if term[1] == "mono":
return term[0]
else:
return ["Server not running."]
2024-09-13 15:07:56 +02:00
@app.route("/")
def root():
return render_template("index.html")
if __name__ == "__main__":
initialize_tmux_session()
app.run(host="0.0.0.0", debug=True)