mirror of
https://github.com/alexbers/mtprotoproxy.git
synced 2026-03-19 00:55:49 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
446682521b | ||
|
|
b26873176a | ||
|
|
6e8e8b63b2 | ||
|
|
3b4f239cc1 | ||
|
|
0283d6264a | ||
|
|
15a8f607ca | ||
|
|
6076db9f8c | ||
|
|
6560a6c1d2 | ||
|
|
24479e68ab | ||
|
|
6ecf0ec9ac | ||
|
|
18a80e52cd | ||
|
|
ea3b8a44c3 |
14
Dockerfile
14
Dockerfile
@@ -1,16 +1,14 @@
|
|||||||
FROM python:3.8-slim-buster
|
FROM ubuntu:22.04
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y libcap2-bin && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install --no-install-recommends -y python3 python3-uvloop python3-cryptography python3-socks libcap2-bin ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||||
RUN setcap cap_net_bind_service=+ep /usr/local/bin/python3.8
|
RUN setcap cap_net_bind_service=+ep /usr/bin/python3.10
|
||||||
|
|
||||||
RUN pip3 --no-cache-dir install cryptography uvloop
|
|
||||||
|
|
||||||
COPY mtprotoproxy.py config.py /home/tgproxy/
|
|
||||||
|
|
||||||
RUN useradd tgproxy -u 10000
|
RUN useradd tgproxy -u 10000
|
||||||
RUN chown -R tgproxy:tgproxy /home/tgproxy
|
|
||||||
|
|
||||||
USER tgproxy
|
USER tgproxy
|
||||||
|
|
||||||
WORKDIR /home/tgproxy/
|
WORKDIR /home/tgproxy/
|
||||||
|
|
||||||
|
COPY --chown=tgproxy mtprotoproxy.py config.py /home/tgproxy/
|
||||||
|
|
||||||
CMD ["python3", "mtprotoproxy.py"]
|
CMD ["python3", "mtprotoproxy.py"]
|
||||||
|
|||||||
@@ -7,4 +7,10 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./config.py:/home/tgproxy/config.py
|
- ./config.py:/home/tgproxy/config.py
|
||||||
- ./mtprotoproxy.py:/home/tgproxy/mtprotoproxy.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
|
# mem_limit: 1024m
|
||||||
|
|||||||
@@ -196,6 +196,9 @@ def init_config():
|
|||||||
# the next host to forward bad clients
|
# the next host to forward bad clients
|
||||||
conf_dict.setdefault("MASK_HOST", conf_dict["TLS_DOMAIN"])
|
conf_dict.setdefault("MASK_HOST", conf_dict["TLS_DOMAIN"])
|
||||||
|
|
||||||
|
# set the home domain for the proxy, has an influence only on the log message
|
||||||
|
conf_dict.setdefault("MY_DOMAIN", False)
|
||||||
|
|
||||||
# the next host's port to forward bad clients
|
# the next host's port to forward bad clients
|
||||||
conf_dict.setdefault("MASK_PORT", 443)
|
conf_dict.setdefault("MASK_PORT", 443)
|
||||||
|
|
||||||
@@ -1722,6 +1725,7 @@ def make_metrics_pkt(metrics):
|
|||||||
|
|
||||||
pkt_header_list = []
|
pkt_header_list = []
|
||||||
pkt_header_list.append("HTTP/1.1 200 OK")
|
pkt_header_list.append("HTTP/1.1 200 OK")
|
||||||
|
pkt_header_list.append("Connection: close")
|
||||||
pkt_header_list.append("Content-Length: %d" % len(pkt_body))
|
pkt_header_list.append("Content-Length: %d" % len(pkt_body))
|
||||||
pkt_header_list.append("Content-Type: text/plain; version=0.0.4; charset=utf-8")
|
pkt_header_list.append("Content-Type: text/plain; version=0.0.4; charset=utf-8")
|
||||||
pkt_header_list.append("Date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()))
|
pkt_header_list.append("Date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()))
|
||||||
@@ -2082,6 +2086,10 @@ def init_ip_info():
|
|||||||
my_ip_info["ipv4"] = get_ip_from_url(IPV4_URL1) or get_ip_from_url(IPV4_URL2)
|
my_ip_info["ipv4"] = get_ip_from_url(IPV4_URL1) or get_ip_from_url(IPV4_URL2)
|
||||||
my_ip_info["ipv6"] = get_ip_from_url(IPV6_URL1) or get_ip_from_url(IPV6_URL2)
|
my_ip_info["ipv6"] = get_ip_from_url(IPV6_URL1) or get_ip_from_url(IPV6_URL2)
|
||||||
|
|
||||||
|
# the server can return ipv4 address instead of ipv6
|
||||||
|
if my_ip_info["ipv6"] and ":" not in my_ip_info["ipv6"]:
|
||||||
|
my_ip_info["ipv6"] = None
|
||||||
|
|
||||||
if my_ip_info["ipv6"] and (config.PREFER_IPV6 or not my_ip_info["ipv4"]):
|
if my_ip_info["ipv6"] and (config.PREFER_IPV6 or not my_ip_info["ipv4"]):
|
||||||
print_err("IPv6 found, using it for external communication")
|
print_err("IPv6 found, using it for external communication")
|
||||||
|
|
||||||
@@ -2103,9 +2111,12 @@ def print_tg_info():
|
|||||||
print("Since you have TLS only mode enabled the best port is 443", flush=True)
|
print("Since you have TLS only mode enabled the best port is 443", flush=True)
|
||||||
print_default_warning = True
|
print_default_warning = True
|
||||||
|
|
||||||
ip_addrs = [ip for ip in my_ip_info.values() if ip]
|
if not config.MY_DOMAIN:
|
||||||
if not ip_addrs:
|
ip_addrs = [ip for ip in my_ip_info.values() if ip]
|
||||||
ip_addrs = ["YOUR_IP"]
|
if not ip_addrs:
|
||||||
|
ip_addrs = ["YOUR_IP"]
|
||||||
|
else:
|
||||||
|
ip_addrs = [config.MY_DOMAIN]
|
||||||
|
|
||||||
proxy_links = []
|
proxy_links = []
|
||||||
|
|
||||||
@@ -2276,21 +2287,21 @@ def create_servers(loop):
|
|||||||
def create_utilitary_tasks(loop):
|
def create_utilitary_tasks(loop):
|
||||||
tasks = []
|
tasks = []
|
||||||
|
|
||||||
stats_printer_task = asyncio.Task(stats_printer())
|
stats_printer_task = asyncio.Task(stats_printer(), loop=loop)
|
||||||
tasks.append(stats_printer_task)
|
tasks.append(stats_printer_task)
|
||||||
|
|
||||||
if config.USE_MIDDLE_PROXY:
|
if config.USE_MIDDLE_PROXY:
|
||||||
middle_proxy_updater_task = asyncio.Task(update_middle_proxy_info())
|
middle_proxy_updater_task = asyncio.Task(update_middle_proxy_info(), loop=loop)
|
||||||
tasks.append(middle_proxy_updater_task)
|
tasks.append(middle_proxy_updater_task)
|
||||||
|
|
||||||
if config.GET_TIME_PERIOD:
|
if config.GET_TIME_PERIOD:
|
||||||
time_get_task = asyncio.Task(get_srv_time())
|
time_get_task = asyncio.Task(get_srv_time(), loop=loop)
|
||||||
tasks.append(time_get_task)
|
tasks.append(time_get_task)
|
||||||
|
|
||||||
get_cert_len_task = asyncio.Task(get_mask_host_cert_len())
|
get_cert_len_task = asyncio.Task(get_mask_host_cert_len(), loop=loop)
|
||||||
tasks.append(get_cert_len_task)
|
tasks.append(get_cert_len_task)
|
||||||
|
|
||||||
clear_resolving_cache_task = asyncio.Task(clear_ip_resolving_cache())
|
clear_resolving_cache_task = asyncio.Task(clear_ip_resolving_cache(), loop=loop)
|
||||||
tasks.append(clear_resolving_cache_task)
|
tasks.append(clear_resolving_cache_task)
|
||||||
|
|
||||||
return tasks
|
return tasks
|
||||||
@@ -2312,9 +2323,10 @@ def main():
|
|||||||
|
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
loop = asyncio.ProactorEventLoop()
|
loop = asyncio.ProactorEventLoop()
|
||||||
asyncio.set_event_loop(loop)
|
else:
|
||||||
|
loop = asyncio.new_event_loop()
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
asyncio.set_event_loop(loop)
|
||||||
loop.set_exception_handler(loop_exception_handler)
|
loop.set_exception_handler(loop_exception_handler)
|
||||||
|
|
||||||
utilitary_tasks = create_utilitary_tasks(loop)
|
utilitary_tasks = create_utilitary_tasks(loop)
|
||||||
|
|||||||
Reference in New Issue
Block a user