Loading run/server.sh +21 −10 Original line number Diff line number Diff line Loading @@ -11,20 +11,27 @@ stop() { trap 'stop' EXIT SIGINT SIGTERM SIGHUP html() { local h="<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE>" h="${h} <STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,Arial,sans-serif; }" h="${h} a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD>" h="${h}<BODY><BR><BR><H1><CENTER>$1</CENTER></H1></BODY></HTML>" echo "$h" } if [[ "$2" != "/"* ]]; then BODY="$2" if [[ "$BODY" == "install" ]]; then BODY="Please wait while Virtual DSM is installing...<script>setTimeout(() => { document.location.reload(); }, 9999);</script>" fi HTML="<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE><STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,\ Arial,sans-serif; } a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD><BODY><BR><BR><H1><CENTER>$BODY</CENTER></H1></BODY></HTML>" HTML=$(html "$BODY") printf '%b' "HTTP/1.1 200 OK\nContent-Length: ${#HTML}\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 $! else Loading @@ -35,15 +42,19 @@ else else BODY="The location of DSM is <a href='http://\${IP}:\${PORT}'>http://\${IP}:\${PORT}</a><script>" BODY="${BODY}setTimeout(function(){ window.location.assign('http://\${IP}:\${PORT}'); }, 3000);</script>" printf -v BODY "%q" "$BODY" HTML=$(html "xxx") printf -v HTML "%q" "$HTML" { 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 <a href=\"http://\${IP}:\${PORT}\">http://\${IP}:\${PORT}</a><script>\\" echo "setTimeout(function(){ window.location.assign('http://\${IP}:\${PORT}'); }, 3000);</script>\"" echo "HTML=\"<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE><STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,\\" echo "Arial,sans-serif; } a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD><BODY><BR><BR><H1><CENTER>\$BODY</CENTER></H1></BODY></HTML>\"" echo "echo -e \"\HTTP/1.1 200 OK\\nContent-Length: \${#HTML}\\nConnection: close\\n\\n\$HTML\"" echo "HTML=\"$HTML\"; BODY=\"$BODY\"; HTML=\${HTML/xxx/\$BODY}" echo "printf '%b' \"HTTP/1.1 200 OK\\nContent-Length: \${#HTML}\\nConnection: close\\n\\n\$HTML\"" } > "$TMP_FILE" fi Loading Loading
run/server.sh +21 −10 Original line number Diff line number Diff line Loading @@ -11,20 +11,27 @@ stop() { trap 'stop' EXIT SIGINT SIGTERM SIGHUP html() { local h="<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE>" h="${h} <STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,Arial,sans-serif; }" h="${h} a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD>" h="${h}<BODY><BR><BR><H1><CENTER>$1</CENTER></H1></BODY></HTML>" echo "$h" } if [[ "$2" != "/"* ]]; then BODY="$2" if [[ "$BODY" == "install" ]]; then BODY="Please wait while Virtual DSM is installing...<script>setTimeout(() => { document.location.reload(); }, 9999);</script>" fi HTML="<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE><STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,\ Arial,sans-serif; } a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD><BODY><BR><BR><H1><CENTER>$BODY</CENTER></H1></BODY></HTML>" HTML=$(html "$BODY") printf '%b' "HTTP/1.1 200 OK\nContent-Length: ${#HTML}\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 $! else Loading @@ -35,15 +42,19 @@ else else BODY="The location of DSM is <a href='http://\${IP}:\${PORT}'>http://\${IP}:\${PORT}</a><script>" BODY="${BODY}setTimeout(function(){ window.location.assign('http://\${IP}:\${PORT}'); }, 3000);</script>" printf -v BODY "%q" "$BODY" HTML=$(html "xxx") printf -v HTML "%q" "$HTML" { 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 <a href=\"http://\${IP}:\${PORT}\">http://\${IP}:\${PORT}</a><script>\\" echo "setTimeout(function(){ window.location.assign('http://\${IP}:\${PORT}'); }, 3000);</script>\"" echo "HTML=\"<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE><STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,\\" echo "Arial,sans-serif; } a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD><BODY><BR><BR><H1><CENTER>\$BODY</CENTER></H1></BODY></HTML>\"" echo "echo -e \"\HTTP/1.1 200 OK\\nContent-Length: \${#HTML}\\nConnection: close\\n\\n\$HTML\"" echo "HTML=\"$HTML\"; BODY=\"$BODY\"; HTML=\${HTML/xxx/\$BODY}" echo "printf '%b' \"HTTP/1.1 200 OK\\nContent-Length: \${#HTML}\\nConnection: close\\n\\n\$HTML\"" } > "$TMP_FILE" fi Loading