diff --git a/Dockerfile b/Dockerfile index 3e8f7ba..31ab427 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,8 +8,6 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone COPY --from=chriswayg/tor-alpine:latest /usr/local/bin/obfs4proxy /usr/local/bin/obfs4proxy COPY --from=chriswayg/tor-alpine:latest /usr/local/bin/meek-server /usr/local/bin/meek-server -COPY /config/torrc /etc/tor/torrc - # Update and upgrade packages RUN apk update && apk upgrade \ # Install required packages @@ -23,6 +21,14 @@ RUN apk update && apk upgrade \ # Clear APK cache && rm -rf /var/cache/apk/* +COPY /config/torrc /etc/tor/torrc + +COPY /scripts /scripts +RUN chmod -R +x /scripts + +COPY /bin /usr/local/bin +RUN chmod -R +x /usr/local/bin + FROM base AS deps @@ -53,6 +59,7 @@ COPY --from=build /app/build build COPY --from=build /app/package.json . ENV NODE_ENV=production +ENV LOG_LEVEL=error COPY docker-entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh @@ -63,7 +70,7 @@ HEALTHCHECK --interval=60s --timeout=3s --start-period=20s --retries=3 \ RUN mkdir -p /data && chmod 700 /data RUN mkdir -p /etc/torrc.d && chmod -R 400 /etc/torrc.d -RUN mkdir -p /var/vlogs && chmod -R 600 /var/vlogs && touch /var/vlogs/web.log +RUN mkdir -p /var/vlogs && chmod -R 600 /var/vlogs && touch /var/vlogs/web VOLUME ["/etc/torrc.d", "/data", "/var/vlogs"] diff --git a/Dockerfile-Dev b/Dockerfile-Dev index f48f60f..c5a1d72 100644 --- a/Dockerfile-Dev +++ b/Dockerfile-Dev @@ -8,9 +8,6 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone COPY --from=chriswayg/tor-alpine:latest /usr/local/bin/obfs4proxy /usr/local/bin/obfs4proxy COPY --from=chriswayg/tor-alpine:latest /usr/local/bin/meek-server /usr/local/bin/meek-server -COPY /config/torrc /etc/tor/torrc -COPY /config/obfs4-bridges.conf /etc/torrc.d/obfs4-bridges.conf - # Update and upgrade packages RUN apk update && apk upgrade \ # Install required packages @@ -24,6 +21,15 @@ RUN apk update && apk upgrade \ # Clear APK cache && rm -rf /var/cache/apk/* +COPY /config/torrc /etc/tor/torrc +COPY /config/obfs4-bridges.conf /etc/torrc.d/obfs4-bridges.conf + +COPY /scripts /scripts +RUN chmod -R +x /scripts + +COPY /bin /usr/local/bin +RUN chmod -R +x /usr/local/bin + FROM base AS deps @@ -47,7 +53,7 @@ ENTRYPOINT ["/entrypoint.sh"] RUN mkdir -p /data && chmod 700 /data RUN mkdir -p /etc/torrc.d && chmod -R 400 /etc/torrc.d -RUN mkdir -p /var/vlogs && chmod -R 600 /var/vlogs && touch /var/vlogs/web.log +RUN mkdir -p /var/vlogs && chmod -R 600 /var/vlogs && touch /var/vlogs/web VOLUME ["/etc/torrc.d", "/data", "/var/vlogs"] diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index fe07509..7f1efbc 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -9,6 +9,6 @@ services: environment: - UI_PASSWORD=password - WG_HOST=192.168.1.102 - - TOR_SOCKS5_PROXY=host.docker.internal:1080 + - TOR_SOCKS5_PROXY=host.docker.internal:8080 extra_hosts: - "host.docker.internal:host-gateway" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 7c64f34..e02f009 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -4,46 +4,6 @@ set -e TOR_CONFIG="/etc/tor/torrc" ENV_FILE="/app/.env" -to_camel_case() { - echo "${1}" | awk -F_ '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2));}1' OFS="" -} - -generate_tor_config() { - # IP address of the container - local inet_address="$(hostname -i | awk '{print $1}')" - - sed -i "s/{{INET_ADDRESS}}/$inet_address/g" "${TOR_CONFIG}" - - # any other environment variables that start with TOR_ are added to the torrc - # file - env | grep ^TOR_ | sed -e 's/TOR_//' -e 's/=/ /' | while read -r line; do - key=$(echo "$line" | awk '{print $1}') - value=$(echo "$line" | awk '{print $2}') - key=$(to_camel_case "$key") - echo "$key $value" >>"${TOR_CONFIG}" - done - - # Removing duplicated tor options - awk -F= '!a[tolower($1)]++' "${TOR_CONFIG}" >"/tmp/$(basename "${TOR_CONFIG}")" && - mv "/tmp/$(basename "${TOR_CONFIG}")" "${TOR_CONFIG}" - - # Checking if there is /etc/torrc.d folder and if there is - # any file in it, adding them to the torrc file - local TORRC_DIR_FILES=$(find /etc/torrc.d -type f -name "*.conf") - if [ -n "$TORRC_DIR_FILES" ]; then - for file in $TORRC_DIR_FILES; do - cat "$file" >>"${TOR_CONFIG}" - done - fi - - # Remove comment line with single Hash - sed -i '/^#\([^#]\)/d' "${TOR_CONFIG}" - # Remove options with no value. (KEY[:space:]{...VALUE}) - sed -i '/^[^ ]* $/d' "${TOR_CONFIG}" - # Remove double empty lines - sed -i '/^$/N;/^\n$/D' "${TOR_CONFIG}" -} - echo " " echo " _ ___ ___ __ _ " echo "| | / (_)_______ / | ____/ /___ ___ (_)___ " @@ -69,7 +29,7 @@ fi if [ -n "$UI_PASSWORD" ]; then sed -i '/^HASHED_PASSWORD/d' "${ENV_FILE}" tee -a "${ENV_FILE}" &>/dev/null <"/tmp/$(basename "${ENV_FILE}")" && mv "/tmp/$(basename "${ENV_FILE}")" "${ENV_FILE}" +# Starting Redis server in detached mode +screen -L -Logfile /var/vlogs/redis -dmS "redis" \ + bash -c "redis-server --port 6479 --daemonize no --dir /data --appendonly yes" + +# Starting Tor +source /scripts/tord.sh + +# Generate Tor configuration generate_tor_config # Start Tor on the background -screen -L -Logfile /var/vlogs/tor -dmS tor \ - bash -c "tor -f ${TOR_CONFIG}" - -# Starting Redis server in detached mode -screen -L -Logfile /var/vlogs/redis -dmS redis \ - bash -c "redis-server --port 6479 --daemonize no --dir /data --appendonly yes" +screen -L -Logfile /var/vlogs/tor -dmS "tor" tor -f "${TOR_CONFIG}" sleep 1 echo -e "\n======================== Versions ========================" diff --git a/scripts/tord.sh b/scripts/tord.sh new file mode 100644 index 0000000..0f82d09 --- /dev/null +++ b/scripts/tord.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + + +to_camel_case() { + echo "${1}" | awk -F_ '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2));}1' OFS="" +} + +generate_tor_config() { + # IP address of the container + local inet_address="$(hostname -i | awk '{print $1}')" + + sed -i "s/{{INET_ADDRESS}}/$inet_address/g" "${TOR_CONFIG}" + + # any other environment variables that start with TOR_ are added to the torrc + # file + env | grep ^TOR_ | sed -e 's/TOR_//' -e 's/=/ /' | while read -r line; do + key=$(echo "$line" | awk '{print $1}') + value=$(echo "$line" | awk '{print $2}') + key=$(to_camel_case "$key") + echo "$key $value" >>"${TOR_CONFIG}" + done + + # Removing duplicated tor options + awk -F= '!a[tolower($1)]++' "${TOR_CONFIG}" >"/tmp/$(basename "${TOR_CONFIG}")" && + mv "/tmp/$(basename "${TOR_CONFIG}")" "${TOR_CONFIG}" + + # Checking if there is /etc/torrc.d folder and if there is + # any file in it, adding them to the torrc file + local torrc_files=$(find /etc/torrc.d -type f -name "*.conf") + if [ -n "${torrc_files}" ]; then + for file in ${torrc_files}; do + cat "$file" >>"${TOR_CONFIG}" + done + fi + + # Remove comment line with single Hash + sed -i '/^#\([^#]\)/d' "${TOR_CONFIG}" + # Remove options with no value. (KEY[:space:]{...VALUE}) + sed -i '/^[^ ]* $/d' "${TOR_CONFIG}" + # Remove double empty lines + sed -i '/^$/N;/^\n$/D' "${TOR_CONFIG}" +} +