31 lines
1.1 KiB
Bash
Executable File
31 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
NAME="${1:?instance name missing}"
|
|
CONFIG_FILE="${CONFIG_FILE:-/etc/relaydock/config.json}"
|
|
|
|
command -v jq >/dev/null 2>&1 || { echo "Fehlt: jq" >&2; exit 1; }
|
|
command -v socat >/dev/null 2>&1 || { echo "Fehlt: socat" >&2; exit 1; }
|
|
[[ -f "$CONFIG_FILE" ]] || { echo "Config fehlt: $CONFIG_FILE" >&2; exit 1; }
|
|
|
|
ROLE=$(jq -r '.role' "$CONFIG_FILE")
|
|
RULE=$(jq -e --arg name "$NAME" '.rules[] | select(.name == $name)' "$CONFIG_FILE")
|
|
PROTO=$(jq -r '.proto' <<<"$RULE")
|
|
LISTEN_PORT=$(jq -r '.listen_port' <<<"$RULE")
|
|
TARGET_HOST=$(jq -r '.target_host' <<<"$RULE")
|
|
TARGET_PORT=$(jq -r '.target_port' <<<"$RULE")
|
|
|
|
if [[ "$ROLE" == "oracle" ]]; then
|
|
if [[ "$PROTO" == "udp" ]]; then
|
|
exec socat "UDP4-LISTEN:${LISTEN_PORT},fork,reuseaddr" "UDP6:[${TARGET_HOST}]:${TARGET_PORT}"
|
|
else
|
|
exec socat "TCP4-LISTEN:${LISTEN_PORT},fork,reuseaddr" "TCP6:[${TARGET_HOST}]:${TARGET_PORT}"
|
|
fi
|
|
else
|
|
if [[ "$PROTO" == "udp" ]]; then
|
|
exec socat "UDP6-LISTEN:${LISTEN_PORT},fork,reuseaddr" "UDP4:${TARGET_HOST}:${TARGET_PORT}"
|
|
else
|
|
exec socat "TCP6-LISTEN:${LISTEN_PORT},fork,reuseaddr" "TCP4:${TARGET_HOST}:${TARGET_PORT}"
|
|
fi
|
|
fi
|