1
0
mirror of https://github.com/donaldzou/WGDashboard.git synced 2024-11-21 14:51:45 +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
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
with:
context: .
push: true
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.
ENV TZ="Europe/Amsterdam"
ENV global_dns="1.1.1.1"
ENV enable="none"
ENV isolate="none"
ENV public_ip="0.0.0.0"

View File

@ -3,14 +3,9 @@ services:
image: donaldzou/wgdashboard:latest
restart: unless-stopped
container_name: wgdashboard
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.
#environment:
#- tz= # <--- Set container timezone, default: Europe/Amsterdam.
#- 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'.
#- public_ip= # <--- Set public IP to ensure the correct one is chosen, defaulting to the IP give by ifconfig.me.
ports:

View File

@ -1,5 +1,8 @@
#!/bin/bash
# Path to the configuration file (exists because of previous function).
config_file="/data/wg-dashboard.ini"
echo "------------------------- START ----------------------------"
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.
echo "Quick-installing..."
[ ! -d "/data/db" ] && echo "Creating database dir" && mkdir /data/db
ln -s /data/db "${WGDASH}/src/db"
if [ ! -d "/data/db" ]; then
echo "Creating database dir"
mkdir /data/db
fi
[ ! -f "/data/wg-dashboard.ini" ] && echo "Creating wg-dashboard.ini file" && touch /data/wg-dashboard.ini
ln -s /data/wg-dashboard.ini "${WGDASH}/src/wg-dashboard.ini"
if [ ! -d "${WGDASH}/src/db" ]; then
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
. "${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
[ ! -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
[ ! -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
echo "Moving PIP dependency from ephemerality to runtime environment: bcrypt"
mv /usr/lib/python3.12/site-packages/bcrypt* "${WGDASH}"/src/venv/lib/python3.12/site-packages
chmod +x "${WGDASH}"/src/wgd.sh
cd "${WGDASH}"/src || exit
./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 is done so WGDashboard it works out of the box
@ -50,52 +66,45 @@ ensure_installation() {
set_envvars() {
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
if [ ! -s "$config_file" ]; then
if [ ! -s "${config_file}" ]; then
echo "Config file is empty. Creating [Peers] section."
# Create [Peers] section with initial values
{
echo "[Peers]"
echo "remote_endpoint = ${public_ip}"
echo "peer_global_dns = ${global_dns}"
} > "$config_file"
echo "remote_endpoint = ${public_ip}"
#echo -e "\n[Server]"
} > "${config_file}"
else
echo "Config file is not empty, enforcing environment 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 "Changing default DNS."
sed -i "s/^peer_global_dns = .*/peer_global_dns = ${global_dns}/" "$config_file"
else
echo "DNS is set correctly."
echo "Config file is not empty, using pre-existing."
fi
# Determine the public IP and update if necessary
echo "{$public_ip}"
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
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"
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"
echo "Public-IP is correct, moving on."
fi
fi
fi
}
# === CORE SERVICES ===
@ -140,13 +149,16 @@ start_core() {
done
# Isolating the matches.
noneFound=0
for interface in "${do_isolate[@]}"; do
if [ "$interface" = "none" ] || [ "$interface" = "" ]; then
echo "Found: $interface, stopping isolation checking."
echo "Found none, stopping isolation checking."
noneFound=1
break
else
else
if [ ! -f "/etc/wireguard/${interface}.conf" ]; then
echo "Ignoring ${interface}"
@ -176,12 +188,13 @@ start_core() {
for interface in "${non_isolate[@]}"; do
if [ ! -f "/etc/wireguard/${interface}.conf" ]; then
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

View File

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

View File

@ -59,7 +59,7 @@
"Turning Off...": "Uitzetten...",
"Address": "Adres",
"Listen Port": "Luisterpoort",
"Public Key": "Public key",
"Public Key": "Publieke Sleutel",
"Connected Peers": "Verbonden Peers",
"Total Usage": "Totaal Gebruik",
"Total Received": "Totaal Ontvangen",
@ -85,7 +85,7 @@
"Active Jobs": "Actieve Taken",
"All Active Jobs": "Alle Actieve Taken",
"Logs": "Logboeken",
"Private Key": "Private Key",
"Private Key": "Privé Sleutel",
"(Required for QR Code and Download)": "(Vereist voor QR-code en Download)",
"(Required)": "(Vereist)",
"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.",
"How many peers you want to add?": "Hoeveel peers wil je 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",
"IP Address/CIDR": "IP-adres/CIDR",
"or": "of",