diff --git a/Dockerfile b/Dockerfile index ee72ff53..77c4388e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,6 +32,7 @@ ENV USER= \ EXTRA_SUBNETS= \ PROXY=on \ PROXY_LOG_LEVEL=Critical \ + PROXY_PORT=8888 \ PROXY_USER= \ PROXY_PASSWORD= ENTRYPOINT /entrypoint.sh diff --git a/README.md b/README.md index b11eeca0..9a779286 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,7 @@ docker run --rm --network=container:pia alpine:3.10 wget -qO- https://ipinfo.io | `EXTRA_SUBNETS` | | comma separated subnets allowed in the container firewall (i.e. `192.168.1.0/24,192.168.10.121,10.0.0.5/28`) | | `PROXY` | `on` | `on` or `off`, to switch the internal HTTP proxy | | `PROXY_LOG_LEVEL` | `Critical` | `Info`, `Warning`, `Error` or `Critical` | +| `PROXY_PORT` | `8888` | `1024` to `65535` internal port for HTTP proxy | | `PROXY_USER` | | Username to use to connect to the HTTP proxy | | `PROXY_PASSWORD` | | Passsword to use to connect to the HTTP proxy | diff --git a/entrypoint.sh b/entrypoint.sh index 194db529..42f9a9dd 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -81,6 +81,19 @@ if [ "$DOT" == "off" ]; then fi exitIfNotIn PROXY "on,off" exitIfNotIn PROXY_LOG_LEVEL "Info,Warning,Error,Critical" +if [ -z $PROXY_PORT ]; then + PROXY_PORT=8888 +fi +if [ `echo $PROXY_PORT | grep -E "^[0-9]+$"` != $PROXY_PORT ]; then + printf "PROXY_PORT is not a valid number\n" + exit 1 +elif [ $PROXY_PORT -lt 1024 ]; then + printf "PROXY_PORT cannot be a privileged port under port 1024\n" + exit 1 +elif [ $PROXY_PORT -gt 65535 ]; then + printf "PROXY_PORT cannot be a port higher than the maximum port 65535\n" + exit 1 +fi if [ ! -z "$PROXY_USER" ] && [ -z "$PROXY_PASSWORD" ]; then printf "PROXY_USER is set but PROXY_PASSWORD is unset\n" exit 1 @@ -108,6 +121,7 @@ fi printf "Local network parameters:\n" printf " * Extra subnets: $EXTRA_SUBNETS\n" printf " * Web proxy activated: $PROXY\n" +printf " * Web proxy port: $PROXY_PORT\n" proxy_auth=yes if [ -z $PROXY_USER ]; then proxy_auth=no @@ -362,6 +376,12 @@ if [ "$PROXY" == "on" ]; then sed -i "/LogLevel /c\LogLevel $PROXY_LOG_LEVEL" /etc/tinyproxy/tinyproxy.conf exitOnError $? printf "DONE\n" + if [ ! -z "$PROXY_PORT" ]; then + printf "[INFO] Setting TinyProxy port to $PROXY_PORT..." + sed -i "/Port /c\Port $PROXY_PORT" /etc/tinyproxy/tinyproxy.conf + exitOnError $? + printf "DONE\n" + fi if [ ! -z "$PROXY_USER" ]; then printf "[INFO] Setting TinyProxy credentials..." echo "BasicAuth $PROXY_USER $PROXY_PASSWORD" >> /etc/tinyproxy/tinyproxy.conf