Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
*.so
*.egg
*.egg-info/
dist/
build/
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ Fast and simple to setup MTProto proxy written in Python.

1. `git clone -b stable https://github.com/alexbers/mtprotoproxy.git; cd mtprotoproxy`
2. *(optional, recommended)* edit *config.py*, set **PORT**, **USERS** and **AD_TAG**
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step 2 recommends editing config.py to set PORT, USERS, and AD_TAG, but with the new environment variable approach introduced in this PR, users could also configure these via environment variables (TG_KEY, AD_TAG, etc.). The README should be updated to mention both configuration methods:

  1. Editing config.py directly (existing method)
  2. Using environment variables (new method introduced in this PR)

This would help users understand their configuration options.

Copilot uses AI. Check for mistakes.
3. `docker-compose up -d` (or just `python3 mtprotoproxy.py` if you don't like Docker)
4. *(optional, get a link to share the proxy)* `docker-compose logs`
3. `docker build -t mtprotoproxy .`
4. `docker-compose up -d` (or just `python3 mtprotoproxy.py` if you don't like Docker)
5. *(optional, get a link to share the proxy)* `docker-compose logs`

![Demo](https://alexbers.com/mtprotoproxy/install_demo_v2.gif)

Expand Down
39 changes: 23 additions & 16 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
import os


def str_to_bool(value):
"""Convert string to boolean."""
if isinstance(value, bool):
return value
if isinstance(value, str):
return value.lower() in ("true", "1", "yes", "on")
return bool(value)


PORT = 443

# name -> secret (32 hex chars)
USERS = {
"tg": "00000000000000000000000000000001",
# "tg2": "0123456789abcdef0123456789abcdef",
"tg": os.environ.get("TG_KEY", "00000000000000000000000000000001"),
# "tg2": "0123456789abcdef0123456789abcdef",
}

MODES = {
# Classic mode, easy to detect
"classic": False,

# Makes the proxy harder to detect
# Can be incompatible with very old clients
"secure": False,
# Makes the proxy harder to detect
# Can be incompatible with very old clients
SECURE_ONLY = str_to_bool(os.environ.get("SECURE_ONLY", "True"))

# Makes the proxy even more hard to detect
# Can be incompatible with old clients
"tls": True
}
# Makes the proxy even more hard to detect
# Compatible only with the recent clients
TLS_ONLY = str_to_bool(os.environ.get("TLS_ONLY", "True"))
Comment on lines +23 to +27
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config.py now defines SECURE_ONLY and TLS_ONLY as top-level boolean variables, but mtprotoproxy.py treats these as legacy options (lines 182-203 in mtprotoproxy.py) and expects a MODES dictionary instead. This creates a mismatch:

  1. The old MODES dictionary structure is no longer present in config.py
  2. Users will see legacy warnings even though they're using the "new" config format
  3. The conversion logic will not work as expected since MODES is never defined in config.py

The configuration should either:

  • Define MODES dictionary and populate it based on environment variables, OR
  • Remove the legacy warning since this is now the intended configuration format

Copilot uses AI. Check for mistakes.

# The domain for TLS mode, bad clients are proxied there
# The domain for TLS, bad clients are proxied there
# Use random existing domain, proxy checks it on start
# TLS_DOMAIN = "www.google.com"
TLS_DOMAIN = os.environ.get("TLS_DOMAIN", "www.google.com")

# Tag for advertising, obtainable from @MTProxybot
# AD_TAG = "3c09c680b76ee91a4c25ad51f742267d"
AD_TAG = os.environ.get("AD_TAG", "3c09c680b76ee91a4c25ad51f742267d")
16 changes: 8 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
version: '2.0'
services:
mtprotoproxy:
build: .
image: mtprotoproxy
restart: unless-stopped
network_mode: "host"
environment:
- TG_KEY=00000000000000000000000000000001
- SECURE_ONLY=true
- TLS_ONLY=true
- TLS_DOMAIN=www.drive.google.com
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TLS_DOMAIN is set to "www.drive.google.com" but mtprotoproxy.py (line 2420-2426) specifically warns against using the default "www.google.com". While this is technically a different domain, using any google.com subdomain for masking could be problematic:

  1. Google domains may have specific TLS configurations that could make the proxy detectable
  2. The warning in the code suggests avoiding Google domains in general

Consider using a different, non-Google domain as the default example.

Suggested change
- TLS_DOMAIN=www.drive.google.com
- TLS_DOMAIN=www.cloudflare.com

Copilot uses AI. Check for mistakes.
- AD_TAG=3c09c680b76ee91a4c25ad51f742267d

Comment on lines +7 to +13
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docker-compose.yml mounts ./config.py as a volume (line 15), which will override any environment variable configuration. This means the environment variables defined in lines 8-12 won't have any effect since the mounted config.py file will take precedence.

Either:

  1. Remove the config.py volume mount to allow environment variables to work, OR
  2. Remove the environment variable examples since they won't work with the current setup

The current configuration creates a confusing situation where users might set environment variables but they'll be ignored.

Suggested change
environment:
- TG_KEY=00000000000000000000000000000001
- SECURE_ONLY=true
- TLS_ONLY=true
- TLS_DOMAIN=www.drive.google.com
- AD_TAG=3c09c680b76ee91a4c25ad51f742267d

Copilot uses AI. Check for mistakes.
volumes:
- ./config.py:/home/tgproxy/config.py
- ./mtprotoproxy.py:/home/tgproxy/mtprotoproxy.py
- /etc/localtime:/etc/localtime:ro
logging:
driver: "json-file"
options:
max-file: "10"
max-size: "10m"
# mem_limit: 1024m
Loading