diff --git a/.gitignore b/.gitignore index 79badb9..8b77f0a 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ # vendor/ /bin + +*.conf diff --git a/Dockerfile b/Dockerfile index 4305538..305f16c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,6 +36,7 @@ RUN set -o pipefail && \ supervisor \ ca-certificates \ py3-setuptools \ + curl \ libcap \ you-get \ rtmpdump \ diff --git a/README.md b/README.md index 3dd8ce8..bb7c010 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ reduce the cost of running the `wayback` service, and providing additional anony #### WAYBACK_ARGS -wayback command-line arguments. +wayback command-line arguments, e.g. `-d web -d telegram`. #### WAYBACK_CONFIGURATIONS diff --git a/render.yaml b/render.yaml index b887b7a..f67bd3d 100644 --- a/render.yaml +++ b/render.yaml @@ -14,5 +14,9 @@ services: # see https://github.com/wabarc/wayback/blob/main/wayback.conf for more details. - key: WAYBACK_CONFIGURATIONS sync: false + - key: PORT + value: '8964' - key: PROXY_SERVER value: '' + - key: WIREPROXY_CONF + value: '' diff --git a/wireproxy.sh b/wireproxy.sh index 484c822..094c7cc 100644 --- a/wireproxy.sh +++ b/wireproxy.sh @@ -2,13 +2,53 @@ # # Perform wireproxy -# check dependency -command -v wireproxy > /dev/null || { echo "wireproxy is not installed in this system" 1>&2; exit 0; } -printenv WIREPROXY_CONF > /dev/null || { echo "environment variable WIREPROXY_CONF is not found in this system" 1>&2; exit 0; } +interval=60 +workdir=/wayback +debug="${DEBUG:-}" +if [ "$debug" = "true" ]; then + set -x + workdir=. +fi +config="${workdir}/wg0.conf" -homedir=/wayback -config="${homedir}/wireproxy.conf" +restart() { + pkill wireproxy -printenv WIREPROXY_CONF > "${config}" + # Run wireproxy with silent mode in backgound + wireproxy --daemon --silent --config $config + sleep 3 +} -wireproxy -c "${config}" +watch() { + endpoint='https://cp.cloudflare.com' + proxy="${PROXY_SERVER}" + code=204 + timeout=5 + while :; do + if [ -n "${PROXY_SERVER}" ]; then + echo 'Running wireproxy watchdog...' + resp=$(curl -sf --write-out '%{http_code}' --max-time $timeout --proxy "${proxy}" "${endpoint}") + if [ "${resp}" != "${code}" ]; then + echo 'Restarting wireproxy...' + restart + fi + fi + sleep $interval + done +} + +main() { + # check dependency + command -v wireproxy > /dev/null || { echo "wireproxy is not installed in this system" 1>&2; exit 0; } + + if [ "${debug}" != "true" ]; then + printenv WIREPROXY_CONF > /dev/null || { echo "environment variable WIREPROXY_CONF is not found in this system" 1>&2; exit 0; } + printenv WIREPROXY_CONF > "${config}" + fi + + restart + + watch +} + +main