File size: 2,094 Bytes
c99d2c6
 
 
f80fee9
c99d2c6
 
f80fee9
 
c99d2c6
f80fee9
c99d2c6
f80fee9
 
c99d2c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94ed8a9
 
 
 
 
c99d2c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f80fee9
c99d2c6
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh
set -e

# This script configures and runs the application with proxychains if STASTIC_PROXY is set.
# It is designed to be the ENTRYPOINT of a Docker container.

if [ -n "$STASTIC_PROXY" ]; then
    echo "STASTIC_PROXY is set. Configuring proxychains..."

    # Extract details from STASTIC_PROXY
    # Format: http://user:pass@host:port
    PROTO=$(echo "$STASTIC_PROXY" | grep :// | sed -e's,^\(.*://\).*,\1,g' | sed -e 's,://,,g')
    URL_NO_PROTO=$(echo "$STASTIC_PROXY" | sed -e 's,^.*://,,g')
    USER_PASS=$(echo "$URL_NO_PROTO" | grep -o '.*@' | sed 's/@//')
    HOST_PORT=$(echo "$URL_NO_PROTO" | sed -e "s,$USER_PASS@,,g")
    HOST=$(echo "$HOST_PORT" | cut -d: -f1)
    PORT=$(echo "$HOST_PORT" | cut -d: -f2)

    # Default to http if protocol is not supported by proxychains
    if [ "$PROTO" != "http" ] && [ "$PROTO" != "socks4" ] && [ "$PROTO" != "socks5" ]; then
        echo "Warning: Unsupported proxy type '$PROTO'. Defaulting to 'http'."
        PROTO="http"
    fi

    # Create proxychains config in the home directory of the 'node' user
    CONFIG_DIR="/home/node/.proxychains"
    mkdir -p "$CONFIG_DIR"
    CONFIG_FILE="$CONFIG_DIR/proxychains.conf"

    # Write base config
    cat > "$CONFIG_FILE" <<EOF
strict_chain
proxy_dns

# Exclude local traffic from proxying, so the app can talk to the local ProxyServer.
localnet 127.0.0.0/8
localnet ::1/128

[ProxyList]
EOF

    # Add proxy server entry
    if [ -n "$USER_PASS" ]; then
        USER=$(echo "$USER_PASS" | cut -d: -f1)
        PASS=$(echo "$USER_PASS" | cut -d: -f2)
        echo "$PROTO $HOST $PORT $USER $PASS" >> "$CONFIG_FILE"
        echo "Configured proxy: $PROTO://$USER_PASS@$HOST:$PORT"
    else
        echo "$PROTO $HOST $PORT" >> "$CONFIG_FILE"
        echo "Configured proxy: $PROTO://$HOST:$PORT"
    fi

    echo "Starting application with proxychains..."
    # Execute the command passed to the script, wrapped in proxychains
    exec proxychains4 "$@"
else
    echo "STASTIC_PROXY is not set. Starting application without proxy."
    # Execute the command as is
    exec "$@"
fi