mirror of
https://github.com/wireadmin/wireadmin
synced 2025-02-26 05:48:44 +00:00
fix(chore): code split
This commit is contained in:
parent
8488858c46
commit
3fdb21d8d7
13
Dockerfile
13
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/obfs4proxy /usr/local/bin/obfs4proxy
|
||||||
COPY --from=chriswayg/tor-alpine:latest /usr/local/bin/meek-server /usr/local/bin/meek-server
|
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
|
# Update and upgrade packages
|
||||||
RUN apk update && apk upgrade \
|
RUN apk update && apk upgrade \
|
||||||
# Install required packages
|
# Install required packages
|
||||||
@ -23,6 +21,14 @@ RUN apk update && apk upgrade \
|
|||||||
# Clear APK cache
|
# Clear APK cache
|
||||||
&& rm -rf /var/cache/apk/*
|
&& 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
|
FROM base AS deps
|
||||||
|
|
||||||
@ -53,6 +59,7 @@ COPY --from=build /app/build build
|
|||||||
COPY --from=build /app/package.json .
|
COPY --from=build /app/package.json .
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
ENV LOG_LEVEL=error
|
||||||
|
|
||||||
COPY docker-entrypoint.sh /entrypoint.sh
|
COPY docker-entrypoint.sh /entrypoint.sh
|
||||||
RUN chmod +x /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 /data && chmod 700 /data
|
||||||
RUN mkdir -p /etc/torrc.d && chmod -R 400 /etc/torrc.d
|
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"]
|
VOLUME ["/etc/torrc.d", "/data", "/var/vlogs"]
|
||||||
|
|
||||||
|
@ -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/obfs4proxy /usr/local/bin/obfs4proxy
|
||||||
COPY --from=chriswayg/tor-alpine:latest /usr/local/bin/meek-server /usr/local/bin/meek-server
|
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
|
# Update and upgrade packages
|
||||||
RUN apk update && apk upgrade \
|
RUN apk update && apk upgrade \
|
||||||
# Install required packages
|
# Install required packages
|
||||||
@ -24,6 +21,15 @@ RUN apk update && apk upgrade \
|
|||||||
# Clear APK cache
|
# Clear APK cache
|
||||||
&& rm -rf /var/cache/apk/*
|
&& 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
|
FROM base AS deps
|
||||||
|
|
||||||
@ -47,7 +53,7 @@ ENTRYPOINT ["/entrypoint.sh"]
|
|||||||
|
|
||||||
RUN mkdir -p /data && chmod 700 /data
|
RUN mkdir -p /data && chmod 700 /data
|
||||||
RUN mkdir -p /etc/torrc.d && chmod -R 400 /etc/torrc.d
|
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"]
|
VOLUME ["/etc/torrc.d", "/data", "/var/vlogs"]
|
||||||
|
|
||||||
|
@ -9,6 +9,6 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- UI_PASSWORD=password
|
- UI_PASSWORD=password
|
||||||
- WG_HOST=192.168.1.102
|
- WG_HOST=192.168.1.102
|
||||||
- TOR_SOCKS5_PROXY=host.docker.internal:1080
|
- TOR_SOCKS5_PROXY=host.docker.internal:8080
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
- "host.docker.internal:host-gateway"
|
- "host.docker.internal:host-gateway"
|
||||||
|
@ -4,46 +4,6 @@ set -e
|
|||||||
TOR_CONFIG="/etc/tor/torrc"
|
TOR_CONFIG="/etc/tor/torrc"
|
||||||
ENV_FILE="/app/.env"
|
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 " _ ___ ___ __ _ "
|
echo " _ ___ ___ __ _ "
|
||||||
echo "| | / (_)_______ / | ____/ /___ ___ (_)___ "
|
echo "| | / (_)_______ / | ____/ /___ ___ (_)___ "
|
||||||
@ -69,7 +29,7 @@ fi
|
|||||||
if [ -n "$UI_PASSWORD" ]; then
|
if [ -n "$UI_PASSWORD" ]; then
|
||||||
sed -i '/^HASHED_PASSWORD/d' "${ENV_FILE}"
|
sed -i '/^HASHED_PASSWORD/d' "${ENV_FILE}"
|
||||||
tee -a "${ENV_FILE}" &>/dev/null <<EOF
|
tee -a "${ENV_FILE}" &>/dev/null <<EOF
|
||||||
HASHED_PASSWORD=$(echo -n "$UI_PASSWORD" | xxd -ps -u)
|
HASHED_PASSWORD=$(printf "%s" "${UI_PASSWORD}" | od -A n -t x1 | tr -d ' \n')
|
||||||
EOF
|
EOF
|
||||||
unset UI_PASSWORD
|
unset UI_PASSWORD
|
||||||
else
|
else
|
||||||
@ -81,15 +41,18 @@ fi
|
|||||||
awk -F= '!a[$1]++' "${ENV_FILE}" >"/tmp/$(basename "${ENV_FILE}")" &&
|
awk -F= '!a[$1]++' "${ENV_FILE}" >"/tmp/$(basename "${ENV_FILE}")" &&
|
||||||
mv "/tmp/$(basename "${ENV_FILE}")" "${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
|
generate_tor_config
|
||||||
|
|
||||||
# Start Tor on the background
|
# Start Tor on the background
|
||||||
screen -L -Logfile /var/vlogs/tor -dmS tor \
|
screen -L -Logfile /var/vlogs/tor -dmS "tor" tor -f "${TOR_CONFIG}"
|
||||||
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"
|
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
echo -e "\n======================== Versions ========================"
|
echo -e "\n======================== Versions ========================"
|
||||||
|
43
scripts/tord.sh
Normal file
43
scripts/tord.sh
Normal file
@ -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}"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user