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.
51
app.py
51
app.py
|
@ -1,52 +1,59 @@
|
|||
from flask import *
|
||||
from main import launchserver
|
||||
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():
|
||||
lpane = getlpane()
|
||||
return lpane.capture_pane(), lpane.pane_current_command
|
||||
|
||||
|
||||
def getlpane() -> libtmux.Pane:
|
||||
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}"
|
||||
return lpane
|
||||
|
||||
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"])
|
||||
@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))
|
||||
data = request.data.decode()
|
||||
print(data)
|
||||
|
||||
if data == "bla":
|
||||
print("test")
|
||||
enter_command("bla")
|
||||
getlpane().send_keys("test")
|
||||
elif data == "start":
|
||||
launchserver(getlpane())
|
||||
|
||||
elif data == "stop":
|
||||
getlpane().send_keys("exit")
|
||||
|
||||
return ["sucessful"]
|
||||
elif request.method == "GET":
|
||||
return get_term()
|
||||
term = get_term()
|
||||
if term[1] == "mono":
|
||||
return term[0]
|
||||
else:
|
||||
return ["Server not running."]
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def root():
|
||||
return render_template("index.html")
|
||||
|
|
24
main.py
24
main.py
|
@ -1,24 +1,34 @@
|
|||
import libtmux
|
||||
from os import path
|
||||
import settings
|
||||
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__":
|
||||
try:
|
||||
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
|
||||
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")
|
||||
lpane.send_keys("clear")
|
||||
|
||||
#rpane.send_keys("cd TerrariaServer")
|
||||
#rpane.send_keys("mono --server --gc=sgen -O=all ./TerrariaServer.exe")
|
||||
rpane.send_keys("cowsay huhu")
|
||||
launchserver(rpane)
|
||||
lpane.send_keys("python3 app.py")
|
||||
|
||||
server.attach_session("terradash")
|
||||
|
|
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 {
|
||||
background-color: black;
|
||||
color: chartreuse;
|
||||
}
|
||||
|
||||
#dash {
|
||||
display: flex;
|
||||
align-content: center;
|
||||
|
@ -18,7 +18,16 @@ body {
|
|||
border-color: chartreuse;
|
||||
padding: 10px;
|
||||
border-radius: 20px;
|
||||
border-style:hidden;
|
||||
margin-bottom: 10px;
|
||||
|
||||
}
|
||||
#buttons {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
|
||||
.input {
|
||||
color: chartreuse;
|
||||
|
@ -31,16 +40,21 @@ body {
|
|||
}
|
||||
|
||||
#terminal {
|
||||
background-color: #000; /* Schwarzer Hintergrund für das Terminal */
|
||||
color: chartreuse; /* Grüne Schriftfarbe */
|
||||
background-color: #0001002a;
|
||||
color: chartreuse;
|
||||
border-style: solid;
|
||||
border-color: chartreuse; /* Grüne Umrandung */
|
||||
border-radius: 20px; /* Abgerundete Ecken */
|
||||
padding: 15px; /* Innenabstand */
|
||||
font-family: 'Courier New', Courier, monospace; /* Monospace-Schriftart */
|
||||
font-size: 16px; /* Schriftgröße */
|
||||
border-color: chartreuse;
|
||||
border-radius: 20px;
|
||||
padding: 15px;
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
font-size: 16px;
|
||||
width: 100%;
|
||||
height: 100%; /* Höhe des Terminalfensters */
|
||||
overflow-y: auto; /* Scrollen bei zu viel Inhalt */
|
||||
box-shadow: 0 0 10px rgba(0, 255, 0, 0.5); /* Glüheffekt der grünen Umrandung */
|
||||
height: 100%;
|
||||
overflow-y: auto;
|
||||
box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
|
||||
flex-grow: 1;
|
||||
}
|
||||
#dash {
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
}
|
||||
|
|
|
@ -4,27 +4,30 @@
|
|||
<script>
|
||||
let termdiv;
|
||||
|
||||
function button() {
|
||||
function sendcommand(list) {
|
||||
fetch("/term",{
|
||||
method:"POST",
|
||||
body: JSON.stringify("bla"),
|
||||
body: list,
|
||||
headers: {"Content-type":"application/json; charset=UTF-8"}
|
||||
});
|
||||
getterm();
|
||||
};
|
||||
|
||||
function getterm() {
|
||||
termdiv.innerHTML = "";
|
||||
let tmpterm = "";
|
||||
fetch("/term", { method: "GET" })
|
||||
.then(response => response.json())
|
||||
.then(termarray => {
|
||||
console.log(termarray);
|
||||
for (let line of termarray) {
|
||||
termdiv.innerHTML += `
|
||||
${line}<br>`;
|
||||
tmpterm += `${line}<br>`;
|
||||
}
|
||||
});
|
||||
termdiv.innerHTML = tmpterm;
|
||||
})
|
||||
.catch(termdiv.innerHTML = 'Fehler beim Abrufen der Daten');
|
||||
}
|
||||
|
||||
|
||||
function initstuff() {
|
||||
termdiv = document.getElementById("terminal");
|
||||
getterm();
|
||||
|
@ -41,11 +44,12 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Terradash</title>
|
||||
</head>
|
||||
<body >
|
||||
<h1>Dash</h1>
|
||||
<body style="background-size: cover; background-image: url({{ url_for('static', filename='background.png') }});">
|
||||
<img src="{{ url_for('static', filename='logo.png') }}" alt="Terra-Dash">
|
||||
<div id="dash">
|
||||
<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 id="terminal">
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue