Skip to content

Commit

Permalink
dns resolvers changing using environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
tarampampam committed Aug 16, 2022
1 parent 93902a6 commit 7200eca
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
5 changes: 3 additions & 2 deletions 3proxy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -47,14 +49,15 @@ $ docker run --rm -d \
tarampampam/3proxy:latest
```

Or with auth settings:
Or with auth & resolver settings:

```bash
$ docker run --rm -d \
-p "3128:3128/tcp" \
-p "1080:1080/tcp" \
-e "PROXY_LOGIN=evil" \
-e "PROXY_PASSWORD=live" \
-e "NAME_SERVER_1=2001:4860:4860::8888" \
tarampampam/3proxy:latest
```

Expand Down
12 changes: 12 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"

0 comments on commit 7200eca

Please sign in to comment.