#!/usr/bin/env bash set -eu TMP_FILE=$(mktemp -q /tmp/server.XXXXXX) stop() { trap - SIGINT EXIT { pkill -f socat || true; } 2>/dev/null [ -f "$TMP_FILE" ] && rm -f "$TMP_FILE" } trap 'stop' EXIT SIGINT SIGTERM SIGHUP if [[ "$2" == "/"* ]]; then 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=\"