commit 6d000c97f3d171b4d9d0c56ffebd07355b976569 Author: jahus Date: Mon Jan 26 22:52:48 2026 +0100 initial commit diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..9cc93d6 --- /dev/null +++ b/.env.example @@ -0,0 +1,15 @@ +# Generate secret with: head -c 16 /dev/urandom | xxd -ps +SECRET=your_secret_here + +# Tag from @MTProxybot (optional) +#PROXY_TAG=your_tag_here + +# Number of workers (default: 2) +WORKERS=2 + +# Client port (default: 443) +PORT=443 + +# Stats port (default: 8888) +STATS_PORT=8888 + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..53011b1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM ubuntu:24.04 + +LABEL maintainer="jahus" +LABEL description="Up-to-date MTProxy for Telegram" +LABEL version="1.0.0" + +RUN apt-get update && \ + apt-get install -y \ + git \ + curl \ + build-essential \ + libssl-dev \ + zlib1g-dev \ + xxd \ + cron && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /opt +RUN git clone https://github.com/TelegramMessenger/MTProxy && \ + cd MTProxy && \ + make && \ + cp objs/bin/mtproto-proxy /usr/local/bin/ && \ + cd .. && \ + rm -rf MTProxy + +WORKDIR /data + +COPY update-config.sh /usr/local/bin/ +COPY entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/update-config.sh /usr/local/bin/entrypoint.sh + +EXPOSE 443 8888 + +COPY healthcheck.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/healthcheck.sh + +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD /usr/local/bin/healthcheck.sh + +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..90c28d4 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +if [ ! -f /data/proxy-secret ] || [ ! -f /data/proxy-multi.conf ]; then + echo "Downloading initial configuration..." + /usr/local/bin/update-config.sh +fi + +echo "0 3 * * * /usr/local/bin/update-config.sh" | crontab - + +cron + +if [ -z "$SECRET" ]; then + echo "ERROR: SECRET environment variable is not set!" + exit 1 +fi + +WORKERS=${WORKERS:-1} +PORT=${PORT:-443} +STATS_PORT=${STATS_PORT:-8888} +USER=${USER:-nobody} + +TAG_OPTION="" +if [ -n "$PROXY_TAG" ]; then + TAG_OPTION="-P $PROXY_TAG" +fi + +echo "Starting MTProxy..." +echo "Port: $PORT" +echo "Stats port: $STATS_PORT" +echo "Workers: $WORKERS" +echo "Secret: ${SECRET:0:8}..." + +exec mtproto-proxy \ + -u $USER \ + -p $STATS_PORT \ + -H $PORT \ + -S $SECRET \ + $TAG_OPTION \ + --aes-pwd /data/proxy-secret \ + /data/proxy-multi.conf \ + -M $WORKERS \ + --address 0.0.0.0 diff --git a/healthcheck.sh b/healthcheck.sh new file mode 100644 index 0000000..4426018 --- /dev/null +++ b/healthcheck.sh @@ -0,0 +1,3 @@ +#!/bin/bash +curl -f http://localhost:${STATS_PORT:-8888}/stats || exit 1 + diff --git a/update-config.sh b/update-config.sh new file mode 100644 index 0000000..2a0da9e --- /dev/null +++ b/update-config.sh @@ -0,0 +1,8 @@ +#!/bin/bash +cd /data +curl -s https://core.telegram.org/getProxySecret -o proxy-secret +curl -s https://core.telegram.org/getProxyConfig -o proxy-multi.conf +echo "$(date): Configuration updated" >> /data/update.log + +pkill -HUP mtproto-proxy +