From 7200ecad969c83ed7d4404d35c75b63d2da46dd0 Mon Sep 17 00:00:00 2001 From: Paramtamtam <7326800+tarampampam@users.noreply.github.com> Date: Tue, 16 Aug 2022 10:08:19 +0400 Subject: [PATCH] dns resolvers changing using environment variables --- 3proxy.cfg | 5 +++-- CHANGELOG.md | 6 ++++++ Dockerfile | 2 +- README.md | 13 ++++++++----- docker-entrypoint.sh | 12 ++++++++++++ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/3proxy.cfg b/3proxy.cfg index 6a4ffe8..ab8f3d9 100644 --- a/3proxy.cfg +++ b/3proxy.cfg @@ -4,11 +4,12 @@ config /etc/3proxy/3proxy.cfg # you may use system to execute some external command if proxy starts system "echo `which 3proxy`': Starting 3proxy'" -# We can configure nservers to avoid unsafe gethostbyname() usage +# We can configure nservers to avoid unsafe gethostbyname() usage (max 5 servers) +#NSERVER1 +#NSERVER2 nserver 1.0.0.1 nserver 1.1.1.1 nserver 8.8.4.4 -nserver 8.8.8.8 # nscache is good to save speed, traffic and bandwidth nscache 65536 diff --git a/CHANGELOG.md b/CHANGELOG.md index e2aad69..6687eb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver]. +## v1.6.0 + +### Added + +- Possibility of changing DNS resolvers using environment variables `NAME_SERVER_1` (primary) and `NAME_SERVER_2` (secondary) + ## v1.5.0 ### Fixed diff --git a/Dockerfile b/Dockerfile index e225bb0..03d0874 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ARG Z3PROXY_VERSION=0.9.4 # Fetch 3proxy sources RUN set -x \ - && git clone --branch "${Z3PROXY_VERSION}" https://github.com/z3APA3A/3proxy.git /tmp/3proxy + && git -c advice.detachedHead=false clone --depth 1 --branch "${Z3PROXY_VERSION}" https://github.com/z3APA3A/3proxy.git /tmp/3proxy WORKDIR /tmp/3proxy diff --git a/README.md b/README.md index 1ec1908..c8763ee 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,12 @@ All supported image tags [can be found here][link_docker_tags]. ## Supported environment variables -| Variable name | Description | Example | -|------------------|------------------------|------------| -| `PROXY_LOGIN` | Authorization login | `username` | -| `PROXY_PASSWORD` | Authorization password | `password` | +| Variable name | Description | Example | +|------------------|-------------------------------------|------------------------| +| `PROXY_LOGIN` | Authorization login | `username` | +| `PROXY_PASSWORD` | Authorization password | `password` | +| `NAME_SERVER_1` | Primary nameserver (dns resolver) | `8.8.8.8` | +| `NAME_SERVER_2` | Secondary nameserver (dns resolver) | `2001:4860:4860::8844` | ## How can I use this? @@ -47,7 +49,7 @@ $ docker run --rm -d \ tarampampam/3proxy:latest ``` -Or with auth settings: +Or with auth & resolver settings: ```bash $ docker run --rm -d \ @@ -55,6 +57,7 @@ $ docker run --rm -d \ -p "1080:1080/tcp" \ -e "PROXY_LOGIN=evil" \ -e "PROXY_PASSWORD=live" \ + -e "NAME_SERVER_1=2001:4860:4860::8888" \ tarampampam/3proxy:latest ``` diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 5829308..d303e87 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -3,10 +3,22 @@ set -e PROXY_LOGIN=${PROXY_LOGIN:-} # string PROXY_PASSWORD=${PROXY_PASSWORD:-} # string +NAME_SERVER_1=${NAME_SERVER_1:-} # string +NAME_SERVER_2=${NAME_SERVER_2:-} # string if [ -n "$PROXY_LOGIN" ] && [ -n "$PROXY_PASSWORD" ]; then echo "$0: setup '${PROXY_LOGIN}:${PROXY_PASSWORD}' as proxy user"; sed -i "s~#AUTH_SETTINGS~users ${PROXY_LOGIN}:CL:${PROXY_PASSWORD}\nauth strong\nallow ${PROXY_LOGIN}~" /etc/3proxy/3proxy.cfg fi; +if [ -n "$NAME_SERVER_1" ]; then + echo "$0: setup '${NAME_SERVER_1}' as the first nameserver"; + sed -i "s~#NSERVER1~nserver ${NAME_SERVER_1}~" /etc/3proxy/3proxy.cfg +fi; + +if [ -n "$NAME_SERVER_2" ]; then + echo "$0: setup '${NAME_SERVER_2}' as the second nameserver"; + sed -i "s~#NSERVER2~nserver ${NAME_SERVER_2}~" /etc/3proxy/3proxy.cfg +fi; + exec "$@"