From bd94feb26d54ca9a3a801f67695de25c04add691 Mon Sep 17 00:00:00 2001 From: Jeremy Andrews Date: Fri, 9 Jun 2017 13:15:13 +1200 Subject: [PATCH 1/8] Integrated tinyproxy to allow private trackers to see us browsing from the same ip address --- tinyproxy/run.sh | 121 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100755 tinyproxy/run.sh diff --git a/tinyproxy/run.sh b/tinyproxy/run.sh new file mode 100755 index 000000000..76eb34171 --- /dev/null +++ b/tinyproxy/run.sh @@ -0,0 +1,121 @@ +#!/bin/bash + +# Global vars +PROG_NAME='DockerTinyproxy' +PROXY_CONF='/etc/tinyproxy.conf' +TAIL_LOG='/var/log/tinyproxy/tinyproxy.log' + +# Usage: screenOut STATUS message +screenOut() { + timestamp=$(date +"%H:%M:%S") + + if [ "$#" -ne 2 ]; then + status='INFO' + message="$1" + else + status="$1" + message="$2" + fi + + echo -e "[$PROG_NAME][$status][$timestamp]: $message" +} + +# Usage: checkStatus $? "Error message" "Success message" +checkStatus() { + case $1 in + 0) + screenOut "SUCCESS" "$3" + ;; + 1) + screenOut "ERROR" "$2 - Exiting..." + exit 1 + ;; + *) + screenOut "ERROR" "Unrecognised return code." + ;; + esac +} + +stopService() { + screenOut "Checking for running Tinyproxy service..." + if [ "$(pidof tinyproxy)" ]; then + screenOut "Found. Stopping Tinyproxy service for pre-configuration..." + killall tinyproxy + checkStatus $? "Could not stop Tinyproxy service." \ + "Tinyproxy service stopped successfully." + else + screenOut "Tinyproxy service not running." + fi +} + +parseAccessRules() { + list='' + for ARG in $@; do + line="Allow\t$ARG\n" + list+=$line + done + echo "$list" | sed 's/.\{2\}$//' +} + +setMiscConfig() { + sed -i -e"s,^MinSpareServers ,MinSpareServers\t1 ," $PROXY_CONF + checkStatus $? "Set MinSpareServers - Could not edit $PROXY_CONF" \ + "Set MinSpareServers - Edited $PROXY_CONF successfully." + + sed -i -e"s,^MaxSpareServers ,MaxSpareServers\t1 ," $PROXY_CONF + checkStatus $? "Set MinSpareServers - Could not edit $PROXY_CONF" \ + "Set MinSpareServers - Edited $PROXY_CONF successfully." + + sed -i -e"s,^StartServers ,StartServers\t1 ," $PROXY_CONF + checkStatus $? "Set MinSpareServers - Could not edit $PROXY_CONF" \ + "Set MinSpareServers - Edited $PROXY_CONF successfully." +} + +enableLogFile() { + touch /var/log/tinyproxy/tinyproxy.log + sed -i -e"s,^#LogFile,LogFile," $PROXY_CONF +} + +setAccess() { + if [[ "$1" == *ANY* ]]; then + sed -i -e"s/^Allow /#Allow /" $PROXY_CONF + checkStatus $? "Allowing ANY - Could not edit $PROXY_CONF" \ + "Allowed ANY - Edited $PROXY_CONF successfully." + else + sed -i "s,^Allow 127.0.0.1,$1," $PROXY_CONF + checkStatus $? "Allowing IPs - Could not edit $PROXY_CONF" \ + "Allowed IPs - Edited $PROXY_CONF successfully." + fi +} + +startService() { + screenOut "Starting Tinyproxy service..." + /usr/sbin/tinyproxy + checkStatus $? "Could not start Tinyproxy service." \ + "Tinyproxy service started successfully." +} + +tailLog() { + screenOut "Tailing Tinyproxy log..." + tail -f $TAIL_LOG + checkStatus $? "Could not tail $TAIL_LOG" \ + "Stopped tailing $TAIL_LOG" +} + +# Start script +echo && screenOut "$PROG_NAME script started..." +# Stop Tinyproxy if running +stopService +# Parse ACL from args +export rawRules="$@" && parsedRules=$(parseAccessRules $rawRules) && unset rawRules +# Set ACL in Tinyproxy config +setAccess $parsedRules +# Enable log to file +#enableLogFile +# Start Tinyproxy +startService +# Tail Tinyproxy log +#tailLog +# End +screenOut "$PROG_NAME script ended." && echo +exit 0 From bf1a7c81950ea01eb55e0fda2f08333ecaf49ebe Mon Sep 17 00:00:00 2001 From: Jeremy Andrews Date: Fri, 9 Jun 2017 13:20:40 +1200 Subject: [PATCH 2/8] Integrated tinyproxy to allow private trackers to see us browsing from the same ip address --- Dockerfile | 3 +++ openvpn/start.sh | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Dockerfile b/Dockerfile index a28e7e88d..404869240 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,7 @@ RUN apt-get update \ && apt-get update \ && apt-get install -y transmission-cli transmission-common transmission-daemon \ && apt-get install -y openvpn curl rar unrar zip unzip wget \ + && apt-get install -y tinyproxy telnet\ && curl -sLO https://github.com/Yelp/dumb-init/releases/download/v1.0.1/dumb-init_1.0.1_amd64.deb \ && dpkg -i dumb-init_*.deb \ && rm -rf dumb-init_*.deb \ @@ -27,6 +28,7 @@ RUN apt-get update \ ADD openvpn/ /etc/openvpn/ ADD transmission/ /etc/transmission/ +ADD tinyproxy /opt/tinyproxy/ ENV OPENVPN_USERNAME=**None** \ OPENVPN_PASSWORD=**None** \ @@ -108,4 +110,5 @@ ENV OPENVPN_USERNAME=**None** \ # Expose port and run EXPOSE 9091 +EXPOSE 8888 CMD ["dumb-init", "/etc/openvpn/start.sh"] diff --git a/openvpn/start.sh b/openvpn/start.sh index f37159cdb..0c5812755 100755 --- a/openvpn/start.sh +++ b/openvpn/start.sh @@ -54,4 +54,7 @@ if [ -n "${LOCAL_NETWORK-}" ]; then fi fi +/opt/tinyproxy/run.sh ANY +/etc/init.d/tinyproxy start + exec openvpn $TRANSMISSION_CONTROL_OPTS $OPENVPN_OPTS --config "$OPENVPN_CONFIG" From 894d36e4afb11b7e545af545ce92ccc91e7fb037 Mon Sep 17 00:00:00 2001 From: Jeremy Andrews Date: Sat, 17 Jun 2017 15:05:00 +1200 Subject: [PATCH 3/8] Tidied up the tinyproxy integration and added env vars and documentation --- tinyproxy/setport.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 tinyproxy/setport.sh diff --git a/tinyproxy/setport.sh b/tinyproxy/setport.sh new file mode 100755 index 000000000..4df1c8b37 --- /dev/null +++ b/tinyproxy/setport.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +PROXY_CONF='/etc/tinyproxy.conf' + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "Port: Not a number" >&2; exit 1 +fi + +# Port: Specify the port which tinyproxy will listen on. Please note +# that should you choose to run on a port lower than 1024 you will need +# to start tinyproxy using root. + +if [ $1 \< 1024 ]; +then + echo "$1 is lower than 1024. Ports below 1024 are not permitted."; + exit 1 +fi; + +sed -i -e"s,^Port .*,Port $1," $PROXY_CONF + +exit 0 From af699006c756bda32c7483cda6c1b00dee0df431 Mon Sep 17 00:00:00 2001 From: Jeremy Andrews Date: Sat, 17 Jun 2017 15:09:17 +1200 Subject: [PATCH 4/8] Tidied up the tinyproxy integration and added env vars and documentation --- DockerEnv | 4 +- README.md | 12 ++++ docker-compose-armhf.yml | 4 +- docker-compose.yml | 4 +- openvpn/start.sh | 12 +++- tinyproxy/run.sh | 121 --------------------------------------- tinyproxy/setport.sh | 3 +- 7 files changed, 33 insertions(+), 127 deletions(-) delete mode 100755 tinyproxy/run.sh diff --git a/DockerEnv b/DockerEnv index ef6310375..c783ec2f7 100644 --- a/DockerEnv +++ b/DockerEnv @@ -75,4 +75,6 @@ #TRANSMISSION_UTP_ENABLED=true #TRANSMISSION_WATCH_DIR=/data/watch #TRANSMISSION_WATCH_DIR_ENABLED=true -#TRANSMISSION_HOME=/data/transmission-home \ No newline at end of file +#TRANSMISSION_HOME=/data/transmission-home +#WEBPROXY_ENABLED=true +#WEBPROXY_PORT=8888 \ No newline at end of file diff --git a/README.md b/README.md index 32016b4fd..bd51bee3d 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,18 @@ As you can see the variables are prefixed with `TRANSMISSION_`, the variable is PS: `TRANSMISSION_BIND_ADDRESS_IPV4` will be overridden to the IP assigned to your OpenVPN tunnel interface. This is to prevent leaking the host IP. +### Web proxy configuration options + +This container also contains a web-proxy server to allow you to tunnel your web-browser traffic through the same OpenVPN tunnel. +This is useful if you are using a private tracker that needs to see you login from the same IP address you are torrenting from. +The default listening port is 8888. Note that only ports above 1024 can be specified as all ports below 1024 are privileged +and would otherwise require root permissions to run. + +| Variable | Function | Example | +|----------|----------|-------| +|`WEBPROXY_ENABLED` | Enables the web proxy | `WEBPROXY_ENABLED=true`| +|`WEBPROXY_PORT` | Sets the listening port | `WEBPROXY_PORT=8888` | + ### User configuration options By default everything will run as the root user. However, it is possible to change who runs the transmission process. diff --git a/docker-compose-armhf.yml b/docker-compose-armhf.yml index fb4583750..ea8e79fe3 100644 --- a/docker-compose-armhf.yml +++ b/docker-compose-armhf.yml @@ -10,6 +10,7 @@ services: restart: always ports: - "9091:9091" + - "8888:8888" dns: - 8.8.8.8 - 8.8.4.4 @@ -22,7 +23,8 @@ services: - OPENVPN_PASSWORD=password - OPENVPN_OPTS=--inactive 3600 --ping 10 --ping-exit 60 - LOCAL_NETWORK=192.168.0.0/24 - + - WEBPROXY_ENABLED=true + - WEBPROXY_PORT=8888 proxy: build: context: ./proxy diff --git a/docker-compose.yml b/docker-compose.yml index a0d169ab0..13de835a1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: restart: always ports: - "9091:9091" + - "8888:8888" dns: - 8.8.8.8 - 8.8.4.4 @@ -18,7 +19,8 @@ services: - OPENVPN_PASSWORD=password - OPENVPN_OPTS="--inactive 3600 --ping 10 --ping-exit 60" - LOCAL_NETWORK=192.168.0.0/24 - + - WEBPROXY_ENABLED=true + - WEBPROXY_PORT=8888 proxy: image: haugene/transmission-openvpn-proxy links: diff --git a/openvpn/start.sh b/openvpn/start.sh index 0c5812755..d42655b0b 100755 --- a/openvpn/start.sh +++ b/openvpn/start.sh @@ -54,7 +54,15 @@ if [ -n "${LOCAL_NETWORK-}" ]; then fi fi -/opt/tinyproxy/run.sh ANY -/etc/init.d/tinyproxy start + +if [ "${WEBPROXY_ENABLED}" = "true" ]; then + if [ -z "$WEBPROXY_PORT" ] ; then + /opt/tinyproxy/setport.sh $WEBPROXY_PORT + else + # Alway default back to port 8888 + /opt/tinyproxy/setport.sh 8888 + fi + /etc/init.d/tinyproxy start +fi exec openvpn $TRANSMISSION_CONTROL_OPTS $OPENVPN_OPTS --config "$OPENVPN_CONFIG" diff --git a/tinyproxy/run.sh b/tinyproxy/run.sh deleted file mode 100755 index 76eb34171..000000000 --- a/tinyproxy/run.sh +++ /dev/null @@ -1,121 +0,0 @@ -#!/bin/bash - -# Global vars -PROG_NAME='DockerTinyproxy' -PROXY_CONF='/etc/tinyproxy.conf' -TAIL_LOG='/var/log/tinyproxy/tinyproxy.log' - -# Usage: screenOut STATUS message -screenOut() { - timestamp=$(date +"%H:%M:%S") - - if [ "$#" -ne 2 ]; then - status='INFO' - message="$1" - else - status="$1" - message="$2" - fi - - echo -e "[$PROG_NAME][$status][$timestamp]: $message" -} - -# Usage: checkStatus $? "Error message" "Success message" -checkStatus() { - case $1 in - 0) - screenOut "SUCCESS" "$3" - ;; - 1) - screenOut "ERROR" "$2 - Exiting..." - exit 1 - ;; - *) - screenOut "ERROR" "Unrecognised return code." - ;; - esac -} - -stopService() { - screenOut "Checking for running Tinyproxy service..." - if [ "$(pidof tinyproxy)" ]; then - screenOut "Found. Stopping Tinyproxy service for pre-configuration..." - killall tinyproxy - checkStatus $? "Could not stop Tinyproxy service." \ - "Tinyproxy service stopped successfully." - else - screenOut "Tinyproxy service not running." - fi -} - -parseAccessRules() { - list='' - for ARG in $@; do - line="Allow\t$ARG\n" - list+=$line - done - echo "$list" | sed 's/.\{2\}$//' -} - -setMiscConfig() { - sed -i -e"s,^MinSpareServers ,MinSpareServers\t1 ," $PROXY_CONF - checkStatus $? "Set MinSpareServers - Could not edit $PROXY_CONF" \ - "Set MinSpareServers - Edited $PROXY_CONF successfully." - - sed -i -e"s,^MaxSpareServers ,MaxSpareServers\t1 ," $PROXY_CONF - checkStatus $? "Set MinSpareServers - Could not edit $PROXY_CONF" \ - "Set MinSpareServers - Edited $PROXY_CONF successfully." - - sed -i -e"s,^StartServers ,StartServers\t1 ," $PROXY_CONF - checkStatus $? "Set MinSpareServers - Could not edit $PROXY_CONF" \ - "Set MinSpareServers - Edited $PROXY_CONF successfully." -} - -enableLogFile() { - touch /var/log/tinyproxy/tinyproxy.log - sed -i -e"s,^#LogFile,LogFile," $PROXY_CONF -} - -setAccess() { - if [[ "$1" == *ANY* ]]; then - sed -i -e"s/^Allow /#Allow /" $PROXY_CONF - checkStatus $? "Allowing ANY - Could not edit $PROXY_CONF" \ - "Allowed ANY - Edited $PROXY_CONF successfully." - else - sed -i "s,^Allow 127.0.0.1,$1," $PROXY_CONF - checkStatus $? "Allowing IPs - Could not edit $PROXY_CONF" \ - "Allowed IPs - Edited $PROXY_CONF successfully." - fi -} - -startService() { - screenOut "Starting Tinyproxy service..." - /usr/sbin/tinyproxy - checkStatus $? "Could not start Tinyproxy service." \ - "Tinyproxy service started successfully." -} - -tailLog() { - screenOut "Tailing Tinyproxy log..." - tail -f $TAIL_LOG - checkStatus $? "Could not tail $TAIL_LOG" \ - "Stopped tailing $TAIL_LOG" -} - -# Start script -echo && screenOut "$PROG_NAME script started..." -# Stop Tinyproxy if running -stopService -# Parse ACL from args -export rawRules="$@" && parsedRules=$(parseAccessRules $rawRules) && unset rawRules -# Set ACL in Tinyproxy config -setAccess $parsedRules -# Enable log to file -#enableLogFile -# Start Tinyproxy -startService -# Tail Tinyproxy log -#tailLog -# End -screenOut "$PROG_NAME script ended." && echo -exit 0 diff --git a/tinyproxy/setport.sh b/tinyproxy/setport.sh index 4df1c8b37..1ef53aad6 100755 --- a/tinyproxy/setport.sh +++ b/tinyproxy/setport.sh @@ -13,10 +13,11 @@ fi if [ $1 \< 1024 ]; then - echo "$1 is lower than 1024. Ports below 1024 are not permitted."; + echo "tinyproxy: $1 is lower than 1024. Ports below 1024 are not permitted."; exit 1 fi; +echo "Setting tinyproxy port to $1"; sed -i -e"s,^Port .*,Port $1," $PROXY_CONF exit 0 From 0ba1bc6af7bd17b0ebfbfd1e71172bd3fc65f71b Mon Sep 17 00:00:00 2001 From: Jeremy Andrews Date: Mon, 1 Jan 2018 13:04:15 +1300 Subject: [PATCH 5/8] Abstracted the transmission up and down events to seperate scripts --- openvpn/start.sh | 13 +------------ openvpn/tunnelDown.sh | 3 +++ openvpn/tunnelUp.sh | 4 ++++ tinyproxy/setport.sh | 23 ----------------------- tinyproxy/start.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 35 deletions(-) create mode 100755 openvpn/tunnelDown.sh create mode 100755 openvpn/tunnelUp.sh delete mode 100755 tinyproxy/setport.sh create mode 100755 tinyproxy/start.sh diff --git a/openvpn/start.sh b/openvpn/start.sh index d42655b0b..89fac5089 100755 --- a/openvpn/start.sh +++ b/openvpn/start.sh @@ -44,7 +44,7 @@ echo $TRANSMISSION_RPC_PASSWORD >> /config/transmission-credentials.txt # Persist transmission settings for use by transmission-daemon dockerize -template /etc/transmission/environment-variables.tmpl:/etc/transmission/environment-variables.sh /bin/true -TRANSMISSION_CONTROL_OPTS="--script-security 2 --up /etc/transmission/start.sh --down /etc/transmission/stop.sh" +TRANSMISSION_CONTROL_OPTS="--script-security 2 --up /etc/openvpn/tunnelUp.sh --down /etc/openvpn/tunnelDown.sh" if [ -n "${LOCAL_NETWORK-}" ]; then eval $(/sbin/ip r l m 0.0.0.0 | awk '{if($5!="tun0"){print "GW="$3"\nINT="$5; exit}}') @@ -54,15 +54,4 @@ if [ -n "${LOCAL_NETWORK-}" ]; then fi fi - -if [ "${WEBPROXY_ENABLED}" = "true" ]; then - if [ -z "$WEBPROXY_PORT" ] ; then - /opt/tinyproxy/setport.sh $WEBPROXY_PORT - else - # Alway default back to port 8888 - /opt/tinyproxy/setport.sh 8888 - fi - /etc/init.d/tinyproxy start -fi - exec openvpn $TRANSMISSION_CONTROL_OPTS $OPENVPN_OPTS --config "$OPENVPN_CONFIG" diff --git a/openvpn/tunnelDown.sh b/openvpn/tunnelDown.sh new file mode 100755 index 000000000..b6a7f4ad4 --- /dev/null +++ b/openvpn/tunnelDown.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +/etc/transmission/stop.sh diff --git a/openvpn/tunnelUp.sh b/openvpn/tunnelUp.sh new file mode 100755 index 000000000..a7fb03ade --- /dev/null +++ b/openvpn/tunnelUp.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +/etc/transmission/start.sh +/etc/tinyproxy/start.sh diff --git a/tinyproxy/setport.sh b/tinyproxy/setport.sh deleted file mode 100755 index 1ef53aad6..000000000 --- a/tinyproxy/setport.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -PROXY_CONF='/etc/tinyproxy.conf' - -re='^[0-9]+$' -if ! [[ $1 =~ $re ]] ; then - echo "Port: Not a number" >&2; exit 1 -fi - -# Port: Specify the port which tinyproxy will listen on. Please note -# that should you choose to run on a port lower than 1024 you will need -# to start tinyproxy using root. - -if [ $1 \< 1024 ]; -then - echo "tinyproxy: $1 is lower than 1024. Ports below 1024 are not permitted."; - exit 1 -fi; - -echo "Setting tinyproxy port to $1"; -sed -i -e"s,^Port .*,Port $1," $PROXY_CONF - -exit 0 diff --git a/tinyproxy/start.sh b/tinyproxy/start.sh new file mode 100755 index 000000000..349a52d28 --- /dev/null +++ b/tinyproxy/start.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +PROXY_CONF='/etc/tinyproxy.conf' + +if [ "${WEBPROXY_ENABLED}" = "true" ]; then + + echo "STARTING TINYPROXY" + + if [ -z "$WEBPROXY_PORT" ] ; then + set_port $WEBPROXY_PORT + else + # Always default back to port 8888 + set_port 8888 + fi + + /etc/init.d/tinyproxy start + echo "Tinyproxy startup script complete." + +fi + + +set_port () { + + re='^[0-9]+$' + if ! [[ $1 =~ $re ]] ; then + echo "Port: Not a number" >&2; exit 1 + fi + + # Port: Specify the port which tinyproxy will listen on. Please note + # that should you choose to run on a port lower than 1024 you will need + # to start tinyproxy using root. + + if [ $1 \< 1024 ]; + then + echo "tinyproxy: $1 is lower than 1024. Ports below 1024 are not permitted."; + exit 1 + fi; + + echo "Setting tinyproxy port to $1"; + sed -i -e"s,^Port .*,Port $1," $PROXY_CONF + +} From ef66e85f348e65b084e78376afd7911fa78c59f7 Mon Sep 17 00:00:00 2001 From: Jeremy Andrews Date: Mon, 1 Jan 2018 13:38:25 +1300 Subject: [PATCH 6/8] tweaks --- Dockerfile | 2 +- docker-compose-armhf.yml | 2 -- docker-compose.yml | 2 -- openvpn/tunnelDown.sh | 1 + openvpn/tunnelUp.sh | 2 +- tinyproxy/stop.sh | 7 +++++++ 6 files changed, 10 insertions(+), 6 deletions(-) create mode 100755 tinyproxy/stop.sh diff --git a/Dockerfile b/Dockerfile index 45823b311..35545802b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ RUN apt-get update \ && apt-get update \ && apt-get install -y transmission-cli transmission-common transmission-daemon \ && apt-get install -y openvpn curl rar unrar zip unzip wget \ - && apt-get install -y tinyproxy telnet\ + && apt-get install -y tinyproxy telnet \ && curl -sLO https://github.com/Yelp/dumb-init/releases/download/v1.0.1/dumb-init_1.0.1_amd64.deb \ && dpkg -i dumb-init_*.deb \ && rm -rf dumb-init_*.deb \ diff --git a/docker-compose-armhf.yml b/docker-compose-armhf.yml index e1de87725..4192916ed 100644 --- a/docker-compose-armhf.yml +++ b/docker-compose-armhf.yml @@ -26,8 +26,6 @@ services: - OPENVPN_PASSWORD=password - OPENVPN_OPTS=--inactive 3600 --ping 10 --ping-exit 60 - LOCAL_NETWORK=192.168.0.0/24 - - WEBPROXY_ENABLED=true - - WEBPROXY_PORT=8888 proxy: build: context: ./proxy diff --git a/docker-compose.yml b/docker-compose.yml index 9b4e4b748..d950eb203 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,8 +22,6 @@ services: - OPENVPN_PASSWORD=password - OPENVPN_OPTS="--inactive 3600 --ping 10 --ping-exit 60" - LOCAL_NETWORK=192.168.0.0/24 - - WEBPROXY_ENABLED=true - - WEBPROXY_PORT=8888 proxy: image: haugene/transmission-openvpn-proxy links: diff --git a/openvpn/tunnelDown.sh b/openvpn/tunnelDown.sh index b6a7f4ad4..371aa024d 100755 --- a/openvpn/tunnelDown.sh +++ b/openvpn/tunnelDown.sh @@ -1,3 +1,4 @@ #!/bin/sh /etc/transmission/stop.sh +/opt/tinyproxy/stop.sh diff --git a/openvpn/tunnelUp.sh b/openvpn/tunnelUp.sh index a7fb03ade..5b238ddc2 100755 --- a/openvpn/tunnelUp.sh +++ b/openvpn/tunnelUp.sh @@ -1,4 +1,4 @@ #!/bin/sh /etc/transmission/start.sh -/etc/tinyproxy/start.sh +/opt/tinyproxy/start.sh diff --git a/tinyproxy/stop.sh b/tinyproxy/stop.sh new file mode 100755 index 000000000..12677c38e --- /dev/null +++ b/tinyproxy/stop.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if [ "${WEBPROXY_ENABLED}" = "true" ]; then + + /etc/init.d/tinyproxy stop + +fi From f03778866ccc32e7f20fde0735d164d402f807b3 Mon Sep 17 00:00:00 2001 From: Jeremy Andrews Date: Tue, 2 Jan 2018 08:39:17 +1300 Subject: [PATCH 7/8] fix the tinyproxy start script --- DockerEnv | 2 +- Dockerfile | 2 + tinyproxy/start.sh | 60 +++++++++++++------------ transmission/environment-variables.tmpl | 4 ++ 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/DockerEnv b/DockerEnv index 6edf8a6ea..14fa4ef77 100644 --- a/DockerEnv +++ b/DockerEnv @@ -77,5 +77,5 @@ #TRANSMISSION_WATCH_DIR=/data/watch #TRANSMISSION_WATCH_DIR_ENABLED=true #TRANSMISSION_HOME=/data/transmission-home -#WEBPROXY_ENABLED=true +#WEBPROXY_ENABLED=false #WEBPROXY_PORT=8888 diff --git a/Dockerfile b/Dockerfile index 35545802b..05aba80b3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -106,6 +106,8 @@ ENV OPENVPN_USERNAME=**None** \ "TRANSMISSION_WATCH_DIR_ENABLED=true" \ "TRANSMISSION_HOME=/data/transmission-home" \ "ENABLE_UFW=false" \ + WEBPROXY_ENABLED=false \ + WEBPROXY_PORT=8888 \ PUID=\ PGID= diff --git a/tinyproxy/start.sh b/tinyproxy/start.sh index 349a52d28..18156e391 100755 --- a/tinyproxy/start.sh +++ b/tinyproxy/start.sh @@ -1,42 +1,46 @@ -#!/bin/bash +#!/bin/sh + +# Source our persisted env variables from container startup +. /etc/transmission/environment-variables.sh PROXY_CONF='/etc/tinyproxy.conf' +DEFAULT_PORT=8888 -if [ "${WEBPROXY_ENABLED}" = "true" ]; then - - echo "STARTING TINYPROXY" - - if [ -z "$WEBPROXY_PORT" ] ; then - set_port $WEBPROXY_PORT - else - # Always default back to port 8888 - set_port 8888 - fi - - /etc/init.d/tinyproxy start - echo "Tinyproxy startup script complete." - -fi - - -set_port () { - - re='^[0-9]+$' - if ! [[ $1 =~ $re ]] ; then - echo "Port: Not a number" >&2; exit 1 +set_port() +{ + expr $1 + 0 1>/dev/null 2>&1 + statut=$? + if test $statut -gt 1 + then + echo "Port [$1]: Not a number" >&2; exit 1 fi # Port: Specify the port which tinyproxy will listen on. Please note # that should you choose to run on a port lower than 1024 you will need # to start tinyproxy using root. - if [ $1 \< 1024 ]; - then + if test $1 -lt 1024 + then echo "tinyproxy: $1 is lower than 1024. Ports below 1024 are not permitted."; exit 1 - fi; + fi echo "Setting tinyproxy port to $1"; - sed -i -e"s,^Port .*,Port $1," $PROXY_CONF - + sed -i -e"s,^Port .*,Port $1," $2 } + +if [ "${WEBPROXY_ENABLED}" = "true" ]; then + + echo "STARTING TINYPROXY" + + if [ -z "$WEBPROXY_PORT" ] ; then + set_port ${WEBPROXY_PORT} ${PROXY_CONF} + else + # Always default back to port 8888 + set_port ${DEFAULT_PORT} ${PROXY_CONF} + fi + + /etc/init.d/tinyproxy start + echo "Tinyproxy startup script complete." + +fi diff --git a/transmission/environment-variables.tmpl b/transmission/environment-variables.tmpl index 0e78a0133..d04dfb33a 100644 --- a/transmission/environment-variables.tmpl +++ b/transmission/environment-variables.tmpl @@ -79,3 +79,7 @@ export ENABLE_UFW={{ .Env.ENABLE_UFW }} export PUID={{ .Env.PUID }} export PGID={{ .Env.PGID }} + +# Need to pass through our tinyproxy settings +export WEBPROXY_ENABLED={{ .Env.WEBPROXY_ENABLED }} +export WEBPROXY_PORT={{ .Env.WEBPROXY_PORT }} From ad0e33a4633c1cf3c796243e09fffe3d3370cf4b Mon Sep 17 00:00:00 2001 From: Jeremy Andrews Date: Tue, 2 Jan 2018 09:06:42 +1300 Subject: [PATCH 8/8] typo --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7dd6b7906..782bc09a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -110,7 +110,7 @@ ENV OPENVPN_USERNAME=**None** \ TRANSMISSION_WEB_UI= \ PUID= \ PGID= \ - TRANSMISSION_WEB_HOME= + TRANSMISSION_WEB_HOME= \ WEBPROXY_ENABLED=false \ WEBPROXY_PORT=8888