Skip to content

Instantly share code, notes, and snippets.

@kepocnhh
Last active April 19, 2026 11:22
Show Gist options
  • Select an option

  • Save kepocnhh/da5d1dbec861e98febe58174b3f310d7 to your computer and use it in GitHub Desktop.

Select an option

Save kepocnhh/da5d1dbec861e98febe58174b3f310d7 to your computer and use it in GitHub Desktop.
teleproxy_start.sh
#!/usr/local/bin/bash
TELEPROXY_PORT=443
###
MTPROTO_SECRETS_PATH="${HOME}/.config/mtproto/mtproto_secrets.txt"
ISSUER="${MTPROTO_SECRETS_PATH}"
if [[ ! -f "${ISSUER}" ]]; then
echo "No file \"${ISSUER}\"!"; exit 1
elif [[ ! -s "${ISSUER}" ]]; then
echo "File \"${ISSUER}\" is empty!"; exit 1
fi
MTPROTO_SECRETS=($(cat "${ISSUER}"))
TELEPROXY_SECRETS_FLAGS=''
if test $? -ne 0; then
echo 'Read secrets error!'; exit 1
elif test ${#MTPROTO_SECRETS[@]} == 0; then
echo 'No secrets!'; exit 1
else
for it in ${MTPROTO_SECRETS[@]}; do
if test "${#it}" != '32'; then
echo 'Wrong secret!'; exit 1; fi
TELEPROXY_SECRETS_FLAGS+=" -S ${it}"
done
fi
###
MTPROTO_PROXY_SECRET_PATH="${HOME}/.config/mtproto/mtproto_secret.bin"
MTPROTO_PROXY_SECRET_URL='https://core.telegram.org/getProxySecret'
ISSUER='/tmp/mtproto_secret.bin'
rm "${ISSUER}"
curl -m 4 -s "${MTPROTO_PROXY_SECRET_URL}" -o "${ISSUER}"
if test $? -ne 0; then
echo "Get proxy secret error!"
elif [[ ! -f "${ISSUER}" ]]; then
echo "No file \"${ISSUER}\"!"
elif [[ ! -s "${ISSUER}" ]]; then
echo "File \"${ISSUER}\" is empty!"
else
mv "${ISSUER}" "${MTPROTO_PROXY_SECRET_PATH}"
fi
ISSUER="${MTPROTO_PROXY_SECRET_PATH}"
if [[ ! -f "${ISSUER}" ]]; then
echo "No file \"${ISSUER}\"!"; exit 1
elif [[ ! -s "${ISSUER}" ]]; then
echo "File \"${ISSUER}\" is empty!"; exit 1
fi
###
MTPROTO_PROXY_CONFIG_PATH="${HOME}/.config/mtproto/mtproto_config.txt"
MTPROTO_PROXY_CONFIG_URL='https://core.telegram.org/getProxyConfig'
ISSUER='/tmp/mtproto_config.txt'
rm "${ISSUER}"
curl -m 4 -s "${MTPROTO_PROXY_CONFIG_URL}" -o "${ISSUER}"
if test $? -ne 0; then
echo "Get proxy secret error!"
elif [[ ! -f "${ISSUER}" ]]; then
echo "No file \"${ISSUER}\"!"
elif [[ ! -s "${ISSUER}" ]]; then
echo "File \"${ISSUER}\" is empty!"
else
mv "${ISSUER}" "${MTPROTO_PROXY_CONFIG_PATH}"
fi
ISSUER="${MTPROTO_PROXY_CONFIG_PATH}"
if [[ ! -f "${ISSUER}" ]]; then
echo "No file \"${ISSUER}\"!"; exit 1
elif [[ ! -s "${ISSUER}" ]]; then
echo "File \"${ISSUER}\" is empty!"; exit 1
fi
###
${HOME}/.local/bin/teleproxy \
-u "${USER}" \
-p 8888 --http-stats \
-H $TELEPROXY_PORT \
${TELEPROXY_SECRETS_FLAGS} \
--aes-pwd "${MTPROTO_PROXY_SECRET_PATH}" "${MTPROTO_PROXY_CONFIG_PATH}" \
--random-padding-only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment