1
0
mirror of https://github.com/donaldzou/WGDashboard.git synced 2024-11-21 23:01:39 +01:00

Squash Docker progress: (#1)

* Version 4.1 Docker image tested.

    Fixed kinks in Docker image.
    Updated Dutch language
    Removed remaining "enable" parameter from Docker-related files
    Made the symlink system more reliable
    Improved updatability.

    Added multiplatform docker build (arm,arm64 and amd64)
    More verbose logging from the Docker image.
This commit is contained in:
dselen 2024-11-09 00:18:01 +01:00 committed by GitHub
parent f6e0d330ac
commit e437284980
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 72 additions and 66 deletions

View File

@ -30,9 +30,10 @@ jobs:
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Build and export - name: Build and export (linux/amd64, linux/arm64, linux/arm/v7)
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
context: . context: .
push: true push: true
tags: ${{ env.DOCKER_IMAGE }}:latest tags: ${{ env.DOCKER_IMAGE }}:latest
platforms: linux/amd64,linux/arm64,linux/arm/v7

View File

@ -8,9 +8,6 @@ ARG wg_port="51820"
# Following ENV variables are changable on container runtime because /entrypoint.sh handles that. See compose.yaml for more info. # Following ENV variables are changable on container runtime because /entrypoint.sh handles that. See compose.yaml for more info.
ENV TZ="Europe/Amsterdam" ENV TZ="Europe/Amsterdam"
ENV global_dns="1.1.1.1" ENV global_dns="1.1.1.1"
ENV enable="none"
ENV isolate="none" ENV isolate="none"
ENV public_ip="0.0.0.0" ENV public_ip="0.0.0.0"

View File

@ -3,14 +3,9 @@ services:
image: donaldzou/wgdashboard:latest image: donaldzou/wgdashboard:latest
restart: unless-stopped restart: unless-stopped
container_name: wgdashboard container_name: wgdashboard
environment: #environment:
- tz=Europe/Amsterdam # <--- Set container timezone, default: Europe/Amsterdam.
- global_dns=9.9.9.9 # <--- Set global DNS address, default: 1.1.1.1.
#- tz= # <--- Set container timezone, default: Europe/Amsterdam. #- tz= # <--- Set container timezone, default: Europe/Amsterdam.
#- global_dns= # <--- Set global DNS address, default: 1.1.1.1. #- global_dns= # <--- Set global DNS address, default: 1.1.1.1.
#- enable= # <--- Set the interfaces that will be enabled on startup, default: 'none'.
#- isolate= # <--- Set the interfaces that will disallow peer communication, default: 'none'. #- 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. #- public_ip= # <--- Set public IP to ensure the correct one is chosen, defaulting to the IP give by ifconfig.me.
ports: ports:

View File

@ -1,5 +1,8 @@
#!/bin/bash #!/bin/bash
# Path to the configuration file (exists because of previous function).
config_file="/data/wg-dashboard.ini"
echo "------------------------- START ----------------------------" echo "------------------------- START ----------------------------"
echo "Starting the WireGuard Dashboard Docker container." echo "Starting the WireGuard Dashboard Docker container."
@ -7,26 +10,39 @@ ensure_installation() {
# When using a custom directory to store the files, this part moves over and makes sure the installation continues. # When using a custom directory to store the files, this part moves over and makes sure the installation continues.
echo "Quick-installing..." echo "Quick-installing..."
[ ! -d "/data/db" ] && echo "Creating database dir" && mkdir /data/db if [ ! -d "/data/db" ]; then
ln -s /data/db "${WGDASH}/src/db" echo "Creating database dir"
mkdir /data/db
fi
[ ! -f "/data/wg-dashboard.ini" ] && echo "Creating wg-dashboard.ini file" && touch /data/wg-dashboard.ini if [ ! -d "${WGDASH}/src/db" ]; then
ln -s /data/wg-dashboard.ini "${WGDASH}/src/wg-dashboard.ini" ln -s /data/db "${WGDASH}/src/db"
fi
if [ ! -f "${config_file}" ]; then
echo "Creating wg-dashboard.ini file"
touch "${config_file}"
fi
if [ ! -f "${WGDASH}/src/wg-dashboard.ini" ]; then
ln -s "${config_file}" "${WGDASH}/src/wg-dashboard.ini"
fi
python3 -m venv "${WGDASH}"/src/venv python3 -m venv "${WGDASH}"/src/venv
. "${WGDASH}/src/venv/bin/activate" . "${WGDASH}/src/venv/bin/activate"
echo "Moving PIP dependency from ephemerality to runtime environment: psutil"
mv /usr/lib/python3.12/site-packages/psutil* "${WGDASH}"/src/venv/lib/python3.12/site-packages
echo "Moving PIP dependency from ephemerality to runtime environment: bcrypt"
[ ! -d "${WGDASH}/src/venv/lib/python3.12/site-packages/psutil" ] && echo "Moving PIP dependency: psutil" && mv /usr/lib/python3.12/site-packages/psutil* "${WGDASH}"/src/venv/lib/python3.12/site-packages mv /usr/lib/python3.12/site-packages/bcrypt* "${WGDASH}"/src/venv/lib/python3.12/site-packages
[ ! -d "${WGDASH}/src/venv/lib/python3.12/site-packages/bcrypt" ] && echo "Moving PIP dependency: bcrypt" && mv /usr/lib/python3.12/site-packages/bcrypt* "${WGDASH}"/src/venv/lib/python3.12/site-packages
chmod +x "${WGDASH}"/src/wgd.sh chmod +x "${WGDASH}"/src/wgd.sh
cd "${WGDASH}"/src || exit cd "${WGDASH}"/src || exit
./wgd.sh install ./wgd.sh install
echo "Looks like the installation succeeded." echo "Looks like the installation succeeded. Moving on."
# This first step is to ensure the wg0.conf file exists, and if not, then its copied over from the ephemeral container storage. # This first step is to ensure the wg0.conf file exists, and if not, then its copied over from the ephemeral container storage.
# This is done so WGDashboard it works out of the box # This is done so WGDashboard it works out of the box
@ -50,52 +66,45 @@ ensure_installation() {
set_envvars() { set_envvars() {
printf "\n------------- SETTING ENVIRONMENT VARIABLES ----------------\n" printf "\n------------- SETTING ENVIRONMENT VARIABLES ----------------\n"
# Path to the configuration file (exists because of previous function).
local config_file="/opt/wireguarddashboard/src/wg-dashboard.ini"
# Check if the file is empty # Check if the file is empty
if [ ! -s "$config_file" ]; then if [ ! -s "${config_file}" ]; then
echo "Config file is empty. Creating [Peers] section." echo "Config file is empty. Creating [Peers] section."
# Create [Peers] section with initial values # Create [Peers] section with initial values
{ {
echo "[Peers]" echo "[Peers]"
echo "remote_endpoint = ${public_ip}"
echo "peer_global_dns = ${global_dns}" echo "peer_global_dns = ${global_dns}"
} > "$config_file" echo "remote_endpoint = ${public_ip}"
#echo -e "\n[Server]"
} > "${config_file}"
else else
echo "Config file is not empty, enforcing environment variables." echo "Config file is not empty, using pre-existing."
# 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 "Changing default DNS."
sed -i "s/^peer_global_dns = .*/peer_global_dns = ${global_dns}/" "$config_file"
else
echo "DNS is set correctly."
fi
# Determine the public IP and update if necessary
echo "{$public_ip}"
if [ "${public_ip}" = "0.0.0.0" ]; 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"
else
current_ip=$(grep "remote_endpoint = " "$config_file" | awk '{print $NF}')
if [ "${public_ip}" != "$current_ip" ]; then
echo "Setting the Public-IP using given variable: ${public_ip}"
sed -i "s/^remote_endpoint = .*/remote_endpoint = ${public_ip}/" "$config_file"
fi
fi
fi fi
echo "Verifying current variables..."
# 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."
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
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}"
else
echo "Public-IP is correct, moving on."
fi
} }
# === CORE SERVICES === # === CORE SERVICES ===
@ -140,13 +149,16 @@ start_core() {
done done
# Isolating the matches. # Isolating the matches.
noneFound=0
for interface in "${do_isolate[@]}"; do for interface in "${do_isolate[@]}"; do
if [ "$interface" = "none" ] || [ "$interface" = "" ]; then if [ "$interface" = "none" ] || [ "$interface" = "" ]; then
echo "Found: $interface, stopping isolation checking." echo "Found none, stopping isolation checking."
noneFound=1
break break
else
else
if [ ! -f "/etc/wireguard/${interface}.conf" ]; then if [ ! -f "/etc/wireguard/${interface}.conf" ]; then
echo "Ignoring ${interface}" echo "Ignoring ${interface}"
@ -176,12 +188,13 @@ start_core() {
for interface in "${non_isolate[@]}"; do for interface in "${non_isolate[@]}"; do
if [ ! -f "/etc/wireguard/${interface}.conf" ]; then if [ $noneFound -eq 1 ]; then
echo "Ignoring ${interface}" break
elif [ ! -f "/etc/wireguard/${interface}.conf" ]; then
echo "Ignoring ${interface}"
elif [ -f "/etc/wireguard/${interface}.conf" ]; then elif [ -f "/etc/wireguard/${interface}.conf" ]; then
echo "Removing isolation, if isolation is present for:" "$interface" 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 "/PostUp = iptables -I FORWARD -i ${interface} -o ${interface} -j DROP/d" /etc/wireguard/"${interface}".conf

View File

@ -1881,8 +1881,8 @@ def API_getAllWireguardConfigurationBackup():
files.sort(key=lambda x: x[1], reverse=True) files.sort(key=lambda x: x[1], reverse=True)
for f, ct in files: for f, ct in files:
if _regexMatch(f"^(.*)_(.*)\.(conf)$", f): if _regexMatch(r"^(.*)_(.*)\.(conf)$", f):
s = re.search(f"^(.*)_(.*)\.(conf)$", f) s = re.search(r"^(.*)_(.*)\.(conf)$", f)
name = s.group(1) name = s.group(1)
if name not in existingConfiguration: if name not in existingConfiguration:
if name not in data['NonExistingConfigurations'].keys(): if name not in data['NonExistingConfigurations'].keys():

View File

@ -59,7 +59,7 @@
"Turning Off...": "Uitzetten...", "Turning Off...": "Uitzetten...",
"Address": "Adres", "Address": "Adres",
"Listen Port": "Luisterpoort", "Listen Port": "Luisterpoort",
"Public Key": "Public key", "Public Key": "Publieke Sleutel",
"Connected Peers": "Verbonden Peers", "Connected Peers": "Verbonden Peers",
"Total Usage": "Totaal Gebruik", "Total Usage": "Totaal Gebruik",
"Total Received": "Totaal Ontvangen", "Total Received": "Totaal Ontvangen",
@ -85,7 +85,7 @@
"Active Jobs": "Actieve Taken", "Active Jobs": "Actieve Taken",
"All Active Jobs": "Alle Actieve Taken", "All Active Jobs": "Alle Actieve Taken",
"Logs": "Logboeken", "Logs": "Logboeken",
"Private Key": "Private Key", "Private Key": "Privé Sleutel",
"(Required for QR Code and Download)": "(Vereist voor QR-code en Download)", "(Required for QR Code and Download)": "(Vereist voor QR-code en Download)",
"(Required)": "(Vereist)", "(Required)": "(Vereist)",
"Endpoint Allowed IPs": "Allowed-IPs voor Eindpunt", "Endpoint Allowed IPs": "Allowed-IPs voor Eindpunt",
@ -144,7 +144,7 @@
"By adding peers by bulk, each peer's name will be auto generated, and Allowed IP will be assign to the next available IP.": "Bij het bulk toevoegen wordt de naam van elke peer automatisch gegenereerd en wordt de Allowed-IPs aan het volgende beschikbare IP toegewezen.", "By adding peers by bulk, each peer's name will be auto generated, and Allowed IP will be assign to the next available IP.": "Bij het bulk toevoegen wordt de naam van elke peer automatisch gegenereerd en wordt de Allowed-IPs aan het volgende beschikbare IP toegewezen.",
"How many peers you want to add?": "Hoeveel peers wil je toevoegen?", "How many peers you want to add?": "Hoeveel peers wil je toevoegen?",
"You can add up to (.*) peers": "Je kunt tot $1 peers toevoegen", "You can add up to (.*) peers": "Je kunt tot $1 peers toevoegen",
"Use your own Private and Public Key": "Gebruik je eigen private- en public key", "Use your own Private and Public Key": "Gebruik je eigen Privé- en Publieke Sleutel",
"Enter IP Address/CIDR": "Voer IP-adres/CIDR in", "Enter IP Address/CIDR": "Voer IP-adres/CIDR in",
"IP Address/CIDR": "IP-adres/CIDR", "IP Address/CIDR": "IP-adres/CIDR",
"or": "of", "or": "of",