From 12760b038da06e90be896ab417aedf70227340f5 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 9 May 2023 01:16:49 +0200 Subject: [PATCH] Generate page --- run/server.sh | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/run/server.sh b/run/server.sh index 26c7722..950c9a1 100644 --- a/run/server.sh +++ b/run/server.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eu -TMP_FILE="" +TMP_FILE=$(mktemp -q /tmp/server.XXXXXX) stop() { trap - SIGINT EXIT @@ -13,17 +13,34 @@ trap 'stop' EXIT SIGINT SIGTERM SIGHUP if [[ "$2" == "/"* ]]; then - socat TCP4-LISTEN:"${1:-5000}",reuseaddr,fork,crlf SYSTEM:"$2" 2> /dev/null & wait $! + if [[ "$2" == "/run/ip.sh" ]]; then + + { echo "#!/bin/bash" + echo "INFO=\$(curl -s -m 5 -S http://127.0.0.1:2210/read?command=10 2>/dev/null)" + echo "rest=\${INFO#*http_port}; rest=\${rest#*:}; rest=\${rest%%,*}; PORT=\${rest%%\\\"*}" + echo "rest=\${INFO#*eth0}; rest=\${rest#*ip}; rest=\${rest#*:}; rest=\${rest#*\\\"}; IP=\${rest%%\\\"*}" + echo "BODY=\"The location of DSM is http://\${IP}:\${PORT}\"" + echo "HTML=\"VirtualDSM

\$BODY

\"" + echo "echo -e \"\HTTP/1.1 200 OK\\nContent-Length: \${#HTML}\\nConnection: close\\n\\n\$HTML\"" + } > "$TMP_FILE" + + else + + cp "$2" "$TMP_FILE" + + fi + + chmod +x "$TMP_FILE" + socat TCP4-LISTEN:"${1:-5000}",reuseaddr,fork,crlf SYSTEM:"$TMP_FILE" 2> /dev/null & wait $! else HTML="VirtualDSM

$2

" - LENGTH="${#HTML}" - TMP_FILE=$(mktemp -q /tmp/server.XXXXXX) - - echo -en "HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\nConnection: close\n\n$HTML" > "$TMP_FILE" + echo -en "HTTP/1.1 200 OK\nContent-Length: ${#HTML}\nConnection: close\n\n$HTML" > "$TMP_FILE" socat TCP4-LISTEN:"${1:-5000}",reuseaddr,fork,crlf SYSTEM:"cat ${TMP_FILE}" 2> /dev/null & wait $! fi