mirror of
https://github.com/donaldzou/WGDashboard
synced 2025-02-26 05:58:47 +00:00
Updated docker configuration.
This commit is contained in:
parent
3ec97021bd
commit
db9d0be6c7
@ -38,7 +38,8 @@ ARG wg_port="51820"
|
||||
ENV TZ="Europe/Amsterdam"
|
||||
ENV global_dns="1.1.1.1"
|
||||
ENV isolate="none"
|
||||
ENV public_ip="0.0.0.0"
|
||||
ENV public_ip=""
|
||||
ENV wgd_port="10086"
|
||||
|
||||
# Doing package management operations, such as upgrading
|
||||
RUN apk update \
|
||||
@ -48,14 +49,15 @@ RUN apk update \
|
||||
&& apk upgrade
|
||||
|
||||
# Using WGDASH -- like wg_net functionally as a ARG command. But it is needed in entrypoint.sh so it needs to be exported as environment variable.
|
||||
ENV WGDASH=/opt/wireguarddashboard
|
||||
ENV WGDASH=/opt/wgdashboard
|
||||
|
||||
# Removing the Linux Image package to preserve space on the image, for this reason also deleting apt lists, to be able to install packages: run apt update.
|
||||
|
||||
# Doing WireGuard Dashboard installation measures. Modify the git clone command to get the preferred version, with a specific branch for example.
|
||||
RUN mkdir /data \
|
||||
&& mkdir /configs \
|
||||
&& mkdir -p ${WGDASH}/src
|
||||
&& mkdir -p ${WGDASH}/src \
|
||||
&& mkdir -p /etc/amnezia/amneziawg
|
||||
COPY ./src ${WGDASH}/src
|
||||
|
||||
# Generate basic WireGuard interface. Echoing the WireGuard interface config for readability, adjust if you want it for efficiency.
|
||||
|
@ -8,8 +8,9 @@ services:
|
||||
#- global_dns= # <--- Set global DNS address, default: 1.1.1.1.
|
||||
#- isolate= # <--- Set the interfaces that will disallow peer communication, default: 'none'.
|
||||
#- public_ip= # <--- Set public IP to ensure the correct one is chosen, defaulting to the IP give by ifconfig.me.
|
||||
#- wgd_port= # <--- Set the port WGDashboard will use for its web-server.
|
||||
ports:
|
||||
- 10086:10086/tcp
|
||||
- 10086:10069/tcp
|
||||
- 51820:51820/udp
|
||||
volumes:
|
||||
- conf:/etc/wireguard
|
||||
|
108
entrypoint.sh
108
entrypoint.sh
@ -75,7 +75,8 @@ set_envvars() {
|
||||
echo "[Peers]"
|
||||
echo "peer_global_dns = ${global_dns}"
|
||||
echo "remote_endpoint = ${public_ip}"
|
||||
#echo -e "\n[Server]"
|
||||
echo -e "\n[Server]"
|
||||
echo "app_port = ${wgd_port}"
|
||||
} > "${config_file}"
|
||||
|
||||
else
|
||||
@ -87,24 +88,32 @@ set_envvars() {
|
||||
# Check and update the DNS if it has changed
|
||||
current_dns=$(grep "peer_global_dns = " "${config_file}" | awk '{print $NF}')
|
||||
if [ "${global_dns}" == "$current_dns" ]; then
|
||||
echo "DNS is correct, moving on."
|
||||
echo "DNS is set correctly, moving on."
|
||||
|
||||
else
|
||||
echo "Changing default DNS..."
|
||||
sed -i "s/^peer_global_dns = .*/peer_global_dns = ${global_dns}/" "${config_file}"
|
||||
fi
|
||||
|
||||
if [ "${public_ip}" == "0.0.0.0" ]; then
|
||||
|
||||
current_public_ip=$(grep "remote_endpoint = " "${config_file}" | awk '{print $NF}')
|
||||
if [ "${public_ip}" == "" ]; then
|
||||
default_ip=$(curl -s ifconfig.me)
|
||||
|
||||
echo "Trying to fetch the Public-IP using ifconfig.me: ${default_ip}"
|
||||
sed -i "s/^remote_endpoint = .*/remote_endpoint = ${default_ip}/" "${config_file}"
|
||||
|
||||
elif [ "${current_public_ip}" != "${public_ip}" ]; then
|
||||
sed -i "s/^remote_endpoint = .*/remote_endpoint = ${public_ip}/" "${config_file}"
|
||||
else
|
||||
echo "Public-IP is correct, moving on."
|
||||
fi
|
||||
|
||||
current_wgd_port=$(grep "app_port = " "${config_file}" | awk '{print $NF}')
|
||||
if [ "${current_wgd_port}" == "${wgd_port}" ]; then
|
||||
echo "Current WGD port is set correctly, moving on."
|
||||
else
|
||||
echo "Changing default WGD port..."
|
||||
sed -i "s/^app_port = .*/app_port = ${wgd_port}/" "${config_file}"
|
||||
fi
|
||||
}
|
||||
|
||||
# === CORE SERVICES ===
|
||||
@ -116,95 +125,6 @@ start_core() {
|
||||
. "${WGDASH}"/src/venv/bin/activate
|
||||
cd "${WGDASH}"/src || return
|
||||
bash wgd.sh start
|
||||
|
||||
# Isolated peers feature, first converting the existing configuration files and the given names to arrays.
|
||||
#
|
||||
# WILL BE REMOVED IN FUTURE WHEN WGDASHBOARD ITSELF SUPPORTS THIS!!
|
||||
#
|
||||
|
||||
local configurations=(/etc/wireguard/*)
|
||||
IFS=',' read -r -a do_isolate <<< "${isolate}"
|
||||
non_isolate=()
|
||||
|
||||
# Checking if there are matches between the two arrays.
|
||||
for config in "${configurations[@]}"; do
|
||||
config=$(echo "$config" | sed -e 's|.*/etc/wireguard/||' -e 's|\.conf$||')
|
||||
|
||||
local found
|
||||
found=false
|
||||
|
||||
for interface in "${do_isolate[@]}"; do
|
||||
|
||||
if [[ "$config" == "$interface" ]]; then
|
||||
found=true
|
||||
break
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
if [ "$found" = false ]; then
|
||||
non_isolate+=("$config")
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
# Isolating the matches.
|
||||
noneFound=0
|
||||
|
||||
for interface in "${do_isolate[@]}"; do
|
||||
|
||||
if [ "$interface" = "none" ] || [ "$interface" = "" ]; then
|
||||
echo "Found none, stopping isolation checking."
|
||||
noneFound=1
|
||||
break
|
||||
|
||||
else
|
||||
|
||||
if [ ! -f "/etc/wireguard/${interface}.conf" ]; then
|
||||
echo "Ignoring ${interface}"
|
||||
|
||||
elif [ -f "/etc/wireguard/${interface}.conf" ]; then
|
||||
|
||||
|
||||
echo "Isolating interface:" "$interface"
|
||||
|
||||
upblocking=$(grep -c "PostUp = iptables -I FORWARD -i ${interface} -o ${interface} -j DROP" /etc/wireguard/"${interface}".conf)
|
||||
downblocking=$(grep -c "PreDown = iptables -D FORWARD -i ${interface} -o ${interface} -j DROP" /etc/wireguard/"${interface}".conf)
|
||||
|
||||
if [ "$upblocking" -lt 1 ] && [ "$downblocking" -lt 1 ]; then
|
||||
sed -i "/PostUp =/a PostUp = iptables -I FORWARD -i ${interface} -o ${interface} -j DROP" /etc/wireguard/"${interface}".conf
|
||||
sed -i "/PreDown =/a PreDown = iptables -D FORWARD -i ${interface} -o ${interface} -j DROP" /etc/wireguard/"${interface}".conf
|
||||
fi
|
||||
|
||||
else
|
||||
echo "Configuration for $interface in enforce isolation does not seem to exist, continuing."
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
# Removing isolation for the configurations that did not match.
|
||||
|
||||
|
||||
for interface in "${non_isolate[@]}"; do
|
||||
if [ $noneFound -eq 1 ]; then
|
||||
break
|
||||
|
||||
elif [ ! -f "/etc/wireguard/${interface}.conf" ]; then
|
||||
echo "Ignoring ${interface}"
|
||||
|
||||
elif [ -f "/etc/wireguard/${interface}.conf" ]; then
|
||||
echo "Removing isolation, if isolation is present for:" "$interface"
|
||||
|
||||
sed -i "/PostUp = iptables -I FORWARD -i ${interface} -o ${interface} -j DROP/d" /etc/wireguard/"${interface}".conf
|
||||
sed -i "/PreDown = iptables -D FORWARD -i ${interface} -o ${interface} -j DROP/d" /etc/wireguard/"${interface}".conf
|
||||
else
|
||||
echo "Configuration for $interface in removing isolation does not seem to exist, continuing."
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
ensure_blocking() {
|
||||
|
@ -1,58 +0,0 @@
|
||||
# Compiler: Build AmneziaWG (Obfuscated Wireguard)
|
||||
FROM golang:1.23.4-bookworm@sha256:ef30001eeadd12890c7737c26f3be5b3a8479ccdcdc553b999c84879875a27ce AS compiler
|
||||
WORKDIR /go
|
||||
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
git make bash build-essential \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
|
||||
RUN git clone --depth=1 https://github.com/amnezia-vpn/amneziawg-tools.git && \
|
||||
git clone --depth=1 https://github.com/amnezia-vpn/amneziawg-go.git
|
||||
RUN cd /go/amneziawg-tools/src && make
|
||||
RUN cd /go/amneziawg-go && \
|
||||
go get -u ./... && \
|
||||
go mod tidy && \
|
||||
make && \
|
||||
chmod +x /go/amneziawg-go/amneziawg-go /go/amneziawg-tools/src/wg /go/amneziawg-tools/src/wg-quick/linux.bash
|
||||
RUN echo "DONE AmneziaWG"
|
||||
|
||||
|
||||
FROM scratch AS bins
|
||||
COPY --from=compiler /go/amneziawg-go/amneziawg-go /amneziawg-go
|
||||
COPY --from=compiler /go/amneziawg-tools/src/wg /awg
|
||||
COPY --from=compiler /go/amneziawg-tools/src/wg-quick/linux.bash /awg-quick
|
||||
|
||||
|
||||
|
||||
|
||||
FROM ubuntu:latest
|
||||
WORKDIR /WGDashboard
|
||||
ENV TZ=UTC
|
||||
EXPOSE 10086
|
||||
COPY ./src /WGDashboard/
|
||||
|
||||
RUN apt-get update -y && \
|
||||
apt-get upgrade -y && \
|
||||
apt-get install wireguard sudo python3 python3-venv python3-pip net-tools -y && \
|
||||
apt install iproute2 -y && \
|
||||
mkdir -p /etc/amnezia/amneziawg
|
||||
|
||||
# Copy AmneziaWG binaries
|
||||
COPY entrypoint.sh /WGDashboard/entrypoint.sh
|
||||
COPY --from=bins /amneziawg-go /usr/bin/amneziawg-go
|
||||
COPY --from=bins /awg /usr/bin/awg
|
||||
COPY --from=bins /awg-quick /usr/bin/awg-quick
|
||||
|
||||
# Install necessary tools and libraries in the final image
|
||||
RUN chmod +x /WGDashboard/wgd.sh && chmod +x /WGDashboard/entrypoint.sh
|
||||
|
||||
RUN if [ ! -c /dev/net/tun ]; then \
|
||||
mkdir -p /dev/net && mknod /dev/net/tun c 10 200; \
|
||||
fi
|
||||
|
||||
|
||||
RUN ./wgd.sh install
|
||||
# Start the script and keep it alive by tailing the logs
|
||||
CMD ["/bin/bash", "-c", "/WGDashboard/wgd.sh start && tail -f /dev/null"]
|
Loading…
Reference in New Issue
Block a user