Skip to content

Commit

Permalink
Added feature to disable SOCKS or HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
erikmagkekse committed Nov 15, 2024
1 parent d3cef4f commit 3ef6b95
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ ENV GID=23456
ENV USER_HOME=/app
ENV VIRTUAL_ENV=$USER_HOME/.venv

ENV SOCKS_ENABLED=TRUE
ENV HTTP_ENABLED=TRUE

ENV PROXY_HOST=127.0.0.1
ENV SOCKS_PORT=1080
ENV HTTP_PORT=1080
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ docker pull docker.io/erikmagkekse/ziti-edge-proxy:main
| Variable | Default Value | Usage |
| ---------------- | ----------------- | ----------------------------------------------------------- |
| PROXY_HOST | 127.0.0.1 | Where the SOCKS5 server should be attached |
| SOCKS_ENABLED | true | Enables SOCKS5 Server |
| HTTP_ENABLED | true | Enables HTTP Server |
| SOCKS_PORT | 1080 | Default port of the SOCKS5 server |
| HTTP_PORT | 8080 | Default port of the HTTP proxy server |
| PROXY_USERNAME | user | Username for the SOCKS5 server |
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
PROXY_HOST: 0.0.0.0
SOCKS_PORT: 1080
HTTP_PORT: 8080
HTTP_ENABLED: true
SOCKS_ENABLED: false
PROXY_USERNAME: user
PROXY_PASSWORD: 1234
ZITI_IDENTITIES: /app/identity.json
Expand Down
16 changes: 10 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ def validate_env():
http_port = os.getenv("HTTP_PORT")
username = os.getenv("PROXY_USERNAME")
password = os.getenv("PROXY_PASSWORD")
socks_enabled = os.getenv("SOCKS_ENABLED", "false").lower() == "true"
http_enabled = os.getenv("HTTP_ENABLED", "false").lower() == "true"

if not socks_host:
logging.error("PROXY_HOST environment variable is missing.")
Expand All @@ -234,13 +236,15 @@ def validate_env():
logging.error("Ports must be valid port numbers (1-65535).")
sys.exit(1)

return socks_host, socks_port, http_port, username, password
return socks_host, socks_port, http_port, username, password, socks_enabled, http_enabled

if __name__ == "__main__":
PROXY_HOST, SOCKS_PORT, HTTP_PORT, PROXY_USERNAME, PROXY_PASSWORD = validate_env()
PROXY_HOST, SOCKS_PORT, HTTP_PORT, PROXY_USERNAME, PROXY_PASSWORD, SOCKS_ENABLED, HTTP_ENABLED = validate_env()

socks_server = Socks5Server(PROXY_HOST=PROXY_HOST, PROXY_PORT=SOCKS_PORT, PROXY_USERNAME=PROXY_USERNAME, PROXY_PASSWORD=PROXY_PASSWORD)
http_server = HttpProxyServer(PROXY_HOST=PROXY_HOST, PROXY_PORT=HTTP_PORT, PROXY_USERNAME=PROXY_USERNAME, PROXY_PASSWORD=PROXY_PASSWORD)
if SOCKS_ENABLED:
socks_server = Socks5Server(PROXY_HOST=PROXY_HOST, PROXY_PORT=SOCKS_PORT, PROXY_USERNAME=PROXY_USERNAME, PROXY_PASSWORD=PROXY_PASSWORD)
threading.Thread(target=socks_server.start).start()

threading.Thread(target=socks_server.start).start()
threading.Thread(target=http_server.start).start()
if HTTP_ENABLED:
http_server = HttpProxyServer(PROXY_HOST=PROXY_HOST, PROXY_PORT=HTTP_PORT, PROXY_USERNAME=PROXY_USERNAME, PROXY_PASSWORD=PROXY_PASSWORD)
threading.Thread(target=http_server.start).start()

0 comments on commit 3ef6b95

Please sign in to comment.