Fixed log

This commit is contained in:
2025-09-24 14:03:42 +02:00
parent 0800c8f700
commit 1444c24b0d
2 changed files with 15 additions and 18 deletions

View File

@@ -1,10 +1,8 @@
FROM alpine:latest FROM alpine:latest
# Install socat and netcat in a single RUN command and clean up cache
RUN apk add --no-cache socat netcat-openbsd \ RUN apk add --no-cache socat netcat-openbsd \
&& rm -rf /var/cache/apk/* /tmp/* && rm -rf /var/cache/apk/* /tmp/*
# Create socket directory and copy/set permissions in single layers
COPY entrypoint.sh VERSION / COPY entrypoint.sh VERSION /
RUN mkdir -p /socket \ RUN mkdir -p /socket \
&& chmod +x /entrypoint.sh && chmod +x /entrypoint.sh

View File

@@ -1,7 +1,9 @@
#!/bin/sh #!/bin/sh
set -e set -e
# Set default values if not provided CYAN="\033[1;36m"
NC="\033[0m"
TARGET_HOST=${TARGET_HOST} TARGET_HOST=${TARGET_HOST}
TARGET_PORT=${TARGET_PORT} TARGET_PORT=${TARGET_PORT}
UNIX_SOCKET_NAME=${UNIX_SOCKET_NAME} UNIX_SOCKET_NAME=${UNIX_SOCKET_NAME}
@@ -17,14 +19,12 @@ FULL_UNIX_SOCKET_PATH="$UNIX_SOCKET_PATH/$UNIX_SOCKET_NAME"
VERSION=$(cat VERSION) VERSION=$(cat VERSION)
echo -e "${CYAN}╭────────────────────────────────────────────╮${NC}" echo -e "${CYAN}╭───────────────────────────────────────────────${NC}"
echo -e "${CYAN}${NC} Socat-proxy - Version ${VERSION}${NC} ${CYAN}${NC}" echo -e "${CYAN}${NC} Socat-proxy - Version ${VERSION}${NC} ${CYAN}${NC}"
echo -e "${CYAN}├────────────────────────────────────────────┤${NC}" echo -e "${CYAN}├───────────────────────────────────────────────${NC}"
echo -e "${CYAN}${NC} Source: https://git.djeex.fr/Djeex/socat-proxy ${CYAN}${NC}" echo -e "${CYAN}${NC} Source: https://git.djeex.fr/Djeex/socat-proxy ${CYAN}${NC}"
echo -e "${CYAN}${NC} Mirror: https://github.com/Djeex/socat-proxy ${CYAN}${NC}" echo -e "${CYAN}${NC} Mirror: https://github.com/Djeex/socat-proxy ${CYAN}${NC}"
echo -e "${CYAN}╰────────────────────────────────────────────╯${NC}" echo -e "${CYAN}╰───────────────────────────────────────────────${NC}"
copy_default_config
start_server
# Validate required environment variables # Validate required environment variables
@@ -56,7 +56,6 @@ fi
echo "[~] Starting socat proxy..." echo "[~] Starting socat proxy..."
echo "[i] TCP target: $TARGET_HOST:$TARGET_PORT" echo "[i] TCP target: $TARGET_HOST:$TARGET_PORT"
echo "[i] HOST path: $HOST_SOCKET_PATH" echo "[i] HOST path: $HOST_SOCKET_PATH"
# Calculate full socket path
echo "[i] Full host socket path: $FULL_HOST_SOCKET_PATH" echo "[i] Full host socket path: $FULL_HOST_SOCKET_PATH"
echo "[i] Full socket path: $FULL_UNIX_SOCKET_PATH" echo "[i] Full socket path: $FULL_UNIX_SOCKET_PATH"
@@ -71,7 +70,7 @@ if [ -e "$FULL_UNIX_SOCKET_PATH" ]; then
fi fi
fi fi
echo "Creating socket directory structure..." [~] Creating socket directory structure...
# Create directory if needed # Create directory if needed
if mkdir -p "$UNIX_SOCKET_PATH"; then if mkdir -p "$UNIX_SOCKET_PATH"; then
echo "[✓] Created directory $UNIX_SOCKET_PATH" echo "[✓] Created directory $UNIX_SOCKET_PATH"
@@ -80,7 +79,7 @@ else
exit 1 exit 1
fi fi
echo "Creating socket with netcat..." echo "[~] Creating socket with netcat..."
# Create socket with nc -lU in background and then kill it to create the socket file # Create socket with nc -lU in background and then kill it to create the socket file
if timeout 1 nc -lU "$FULL_UNIX_SOCKET_PATH" 2>/dev/null || true; then if timeout 1 nc -lU "$FULL_UNIX_SOCKET_PATH" 2>/dev/null || true; then
echo "[✓] Socket created at $FULL_UNIX_SOCKET_PATH" echo "[✓] Socket created at $FULL_UNIX_SOCKET_PATH"
@@ -88,7 +87,7 @@ else
echo "[!] Socket creation with netcat had issues, but continuing..." echo "[!] Socket creation with netcat had issues, but continuing..."
fi fi
echo "Testing connection to target..." echo "[~] Testing connection to target..."
# Test if we can reach the target before starting socat # Test if we can reach the target before starting socat
if ! nc -z "$TARGET_HOST" "$TARGET_PORT" 2>/dev/null; then if ! nc -z "$TARGET_HOST" "$TARGET_PORT" 2>/dev/null; then
echo "[!] Cannot connect to $TARGET_HOST:$TARGET_PORT - socat will retry automatically" echo "[!] Cannot connect to $TARGET_HOST:$TARGET_PORT - socat will retry automatically"
@@ -104,14 +103,14 @@ cleanup() {
kill "$SOCAT_PID" 2>/dev/null || true kill "$SOCAT_PID" 2>/dev/null || true
wait "$SOCAT_PID" 2>/dev/null || true wait "$SOCAT_PID" 2>/dev/null || true
fi fi
echo "[ ] Cleanup completed, exiting..." echo "[~] Cleanup completed, exiting..."
exit 0 exit 0
} }
# Set up signal trap # Set up signal trap
trap cleanup SIGTERM SIGINT trap cleanup SIGTERM SIGINT
echo "Starting socat proxy..." echo "[~] Starting socat proxy..."
# Start socat with verbose logging and redirect to stdout/stderr # Start socat with verbose logging and redirect to stdout/stderr
if socat -d -d UNIX-LISTEN:$FULL_UNIX_SOCKET_PATH,fork,unlink-early TCP:$TARGET_HOST:$TARGET_PORT & then if socat -d -d UNIX-LISTEN:$FULL_UNIX_SOCKET_PATH,fork,unlink-early TCP:$TARGET_HOST:$TARGET_PORT & then
SOCAT_PID=$! SOCAT_PID=$!
@@ -127,6 +126,6 @@ while kill -0 "$SOCAT_PID" 2>/dev/null; do
sleep 1 sleep 1
done done
echo "[] Socat process has stopped" echo "[] Socat process has stopped"
exit 1 exit 1