funktionsfähing und mit schöneren design
This commit is contained in:
parent
fadf7b15c5
commit
8be81d7421
10 changed files with 110 additions and 58 deletions
Binary file not shown.
BIN
__pycache__/settings.cpython-312.pyc
Normal file
BIN
__pycache__/settings.cpython-312.pyc
Normal file
Binary file not shown.
65
app.py
65
app.py
|
@ -1,52 +1,59 @@
|
||||||
from flask import *
|
from flask import *
|
||||||
|
from main import launchserver
|
||||||
import libtmux
|
import libtmux
|
||||||
|
|
||||||
app = Flask("Terradash")
|
app = Flask("Terradash")
|
||||||
|
|
||||||
server = libtmux.Server()
|
server = libtmux.Server()
|
||||||
session = None
|
session = None
|
||||||
|
|
||||||
|
|
||||||
def initialize_tmux_session():
|
def initialize_tmux_session():
|
||||||
global session
|
global session
|
||||||
# Versuche, die bestehende Session zu finden
|
# Versuche, die bestehende Session zu finden
|
||||||
if server.has_session("terradash"):
|
if server.has_session("terradash"):
|
||||||
session = server.sessions.get(session_name="terradash")
|
session = server.sessions.get(session_name="terradash")
|
||||||
|
|
||||||
|
|
||||||
def get_term():
|
def get_term():
|
||||||
print(session)
|
lpane = getlpane()
|
||||||
try:
|
return lpane.capture_pane(), lpane.pane_current_command
|
||||||
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 getlpane() -> libtmux.Pane:
|
||||||
|
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"])
|
||||||
def get_terminal_output():
|
def get_terminal_output():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
data = list(request.data.decode())
|
data = request.data.decode()
|
||||||
print(type(data),data,len(data))
|
print(data)
|
||||||
|
|
||||||
if data == "bla":
|
if data == "bla":
|
||||||
print("test")
|
print("test")
|
||||||
enter_command("bla")
|
getlpane().send_keys("test")
|
||||||
|
elif data == "start":
|
||||||
|
launchserver(getlpane())
|
||||||
|
|
||||||
|
elif data == "stop":
|
||||||
|
getlpane().send_keys("exit")
|
||||||
|
|
||||||
return ["sucessful"]
|
return ["sucessful"]
|
||||||
elif request.method == "GET":
|
elif request.method == "GET":
|
||||||
return get_term()
|
term = get_term()
|
||||||
|
if term[1] == "mono":
|
||||||
|
return term[0]
|
||||||
|
else:
|
||||||
|
return ["Server not running."]
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def root():
|
def root():
|
||||||
return render_template("index.html")
|
return render_template("index.html")
|
||||||
|
@ -54,4 +61,4 @@ def root():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
initialize_tmux_session()
|
initialize_tmux_session()
|
||||||
app.run(host="0.0.0.0",debug=True)
|
app.run(host="0.0.0.0", debug=True)
|
||||||
|
|
28
main.py
28
main.py
|
@ -1,27 +1,37 @@
|
||||||
import libtmux
|
import libtmux
|
||||||
from os import path
|
import settings
|
||||||
import libtmux.constants
|
import libtmux.constants
|
||||||
|
|
||||||
path = path.dirname(__file__)+"/"
|
|
||||||
|
def launchserver(lpane: libtmux.Pane):
|
||||||
|
lpane.send_keys(settings.RUN_SERVER_COMMAND)
|
||||||
|
lpane.enter()
|
||||||
|
lpane.send_keys(settings.LAUNCH_WORLD)
|
||||||
|
lpane.send_keys(settings.MAX_PLAYERS)
|
||||||
|
lpane.send_keys(settings.PORT)
|
||||||
|
lpane.send_keys(settings.FORWARD_PORT)
|
||||||
|
lpane.send_keys(settings.PASSWORD)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
server = libtmux.Server()
|
server = libtmux.Server()
|
||||||
session = server.new_session("terradash",start_directory=path)
|
session = server.new_session("terradash", start_directory=settings.SERVER_PATH)
|
||||||
|
|
||||||
window = session.active_window
|
window = session.active_window
|
||||||
rpane = window.active_pane
|
rpane = window.active_pane
|
||||||
lpane = window.split(direction=libtmux.constants.PaneDirection.Right,start_directory=path)
|
lpane = window.split(
|
||||||
|
direction=libtmux.constants.PaneDirection.Right,
|
||||||
|
start_directory=settings.path,
|
||||||
|
)
|
||||||
|
|
||||||
rpane.send_keys("clear")
|
rpane.send_keys("clear")
|
||||||
lpane.send_keys("clear")
|
lpane.send_keys("clear")
|
||||||
|
|
||||||
#rpane.send_keys("cd TerrariaServer")
|
launchserver(rpane)
|
||||||
#rpane.send_keys("mono --server --gc=sgen -O=all ./TerrariaServer.exe")
|
|
||||||
rpane.send_keys("cowsay huhu")
|
|
||||||
lpane.send_keys("python3 app.py")
|
lpane.send_keys("python3 app.py")
|
||||||
|
|
||||||
server.attach_session("terradash")
|
server.attach_session("terradash")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}")
|
print(f"Error: {e}")
|
||||||
|
|
17
settings.py
Normal file
17
settings.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
from os import path
|
||||||
|
|
||||||
|
path = (
|
||||||
|
path.dirname(__file__) + "/"
|
||||||
|
) # Path ist das Verzeichnis wo Terradash lokalisiert ist.
|
||||||
|
|
||||||
|
|
||||||
|
## Settings
|
||||||
|
LAUNCH_WORLD = "1"
|
||||||
|
MAX_PLAYERS = ""
|
||||||
|
PORT = ""
|
||||||
|
FORWARD_PORT = "y"
|
||||||
|
PASSWORD = ""
|
||||||
|
|
||||||
|
|
||||||
|
RUN_SERVER_COMMAND = "clear & mono --server --gc=sgen -O=all ./TerrariaServer.exe"
|
||||||
|
SERVER_PATH = path + "/TerrariaServer"
|
BIN
static/background.png
Normal file
BIN
static/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 73 KiB |
BIN
static/logo.png
Normal file
BIN
static/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
|
@ -3,9 +3,9 @@ a {
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background-color: black;
|
|
||||||
color: chartreuse;
|
color: chartreuse;
|
||||||
}
|
}
|
||||||
|
|
||||||
#dash {
|
#dash {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-content: center;
|
align-content: center;
|
||||||
|
@ -18,7 +18,16 @@ body {
|
||||||
border-color: chartreuse;
|
border-color: chartreuse;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
|
border-style:hidden;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#buttons {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.input {
|
.input {
|
||||||
color: chartreuse;
|
color: chartreuse;
|
||||||
|
@ -31,16 +40,21 @@ body {
|
||||||
}
|
}
|
||||||
|
|
||||||
#terminal {
|
#terminal {
|
||||||
background-color: #000; /* Schwarzer Hintergrund für das Terminal */
|
background-color: #0001002a;
|
||||||
color: chartreuse; /* Grüne Schriftfarbe */
|
color: chartreuse;
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
border-color: chartreuse; /* Grüne Umrandung */
|
border-color: chartreuse;
|
||||||
border-radius: 20px; /* Abgerundete Ecken */
|
border-radius: 20px;
|
||||||
padding: 15px; /* Innenabstand */
|
padding: 15px;
|
||||||
font-family: 'Courier New', Courier, monospace; /* Monospace-Schriftart */
|
font-family: 'Courier New', Courier, monospace;
|
||||||
font-size: 16px; /* Schriftgröße */
|
font-size: 16px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%; /* Höhe des Terminalfensters */
|
height: 100%;
|
||||||
overflow-y: auto; /* Scrollen bei zu viel Inhalt */
|
overflow-y: auto;
|
||||||
box-shadow: 0 0 10px rgba(0, 255, 0, 0.5); /* Glüheffekt der grünen Umrandung */
|
box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
#dash {
|
||||||
|
display: flex;
|
||||||
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,27 +4,30 @@
|
||||||
<script>
|
<script>
|
||||||
let termdiv;
|
let termdiv;
|
||||||
|
|
||||||
function button() {
|
function sendcommand(list) {
|
||||||
fetch("/term",{
|
fetch("/term",{
|
||||||
method:"POST",
|
method:"POST",
|
||||||
body: JSON.stringify("bla"),
|
body: list,
|
||||||
headers: {"Content-type":"application/json; charset=UTF-8"}
|
headers: {"Content-type":"application/json; charset=UTF-8"}
|
||||||
});
|
});
|
||||||
|
getterm();
|
||||||
};
|
};
|
||||||
|
|
||||||
function getterm() {
|
function getterm() {
|
||||||
termdiv.innerHTML = "";
|
let tmpterm = "";
|
||||||
fetch("/term", { method: "GET" })
|
fetch("/term", { method: "GET" })
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(termarray => {
|
.then(termarray => {
|
||||||
console.log(termarray);
|
console.log(termarray);
|
||||||
for (let line of termarray) {
|
for (let line of termarray) {
|
||||||
termdiv.innerHTML += `
|
tmpterm += `${line}<br>`;
|
||||||
${line}<br>`;
|
|
||||||
}
|
}
|
||||||
});
|
termdiv.innerHTML = tmpterm;
|
||||||
|
})
|
||||||
|
.catch(termdiv.innerHTML = 'Fehler beim Abrufen der Daten');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function initstuff() {
|
function initstuff() {
|
||||||
termdiv = document.getElementById("terminal");
|
termdiv = document.getElementById("terminal");
|
||||||
getterm();
|
getterm();
|
||||||
|
@ -41,11 +44,12 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Terradash</title>
|
<title>Terradash</title>
|
||||||
</head>
|
</head>
|
||||||
<body >
|
<body style="background-size: cover; background-image: url({{ url_for('static', filename='background.png') }});">
|
||||||
<h1>Dash</h1>
|
<img src="{{ url_for('static', filename='logo.png') }}" alt="Terra-Dash">
|
||||||
<div id="dash">
|
<div id="dash">
|
||||||
<div id="buttons">
|
<div id="buttons">
|
||||||
<button class="button" onclick="button()">test</button>
|
<button class="button" onclick="sendcommand([`start`])">start</button>
|
||||||
|
<button style="background-color: rgb(186, 0, 0);" class="button" onclick="sendcommand([`stop`])">stop</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="terminal">
|
<div id="terminal">
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue