1
0
mirror of https://github.com/donaldzou/WGDashboard.git synced 2024-11-22 07:10:09 +01:00

Merge pull request #447 from DaanSelen/workflow-change

This commit is contained in:
Donald Zou 2024-11-01 16:11:26 +08:00 committed by GitHub
commit efb9a34cb8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 231 additions and 208 deletions

View File

@ -1,8 +1,10 @@
name: Docker-Analyze
on:
schedule:
- cron: "0 0 * * *" # Daily at midnight UTC
#schedule:
# - cron: "0 0 * * *" # Daily at midnight UTC
push:
branches: [ main ]
workflow_dispatch:
inputs:
trigger-build:
@ -10,7 +12,7 @@ on:
default: 'true'
env:
DOCKER_IMAGE: dselen/wgdashboard
DOCKER_IMAGE: donaldzou/wgdashboard
jobs:
docker_analyze:

View File

@ -1,4 +1,4 @@
FROM alpine:latest AS build
FROM alpine:latest
LABEL maintainer="dselen@nerthus.nl"
# Declaring environment variables, change Peernet to an address you like, standard is a 24 bit subnet.
@ -9,14 +9,15 @@ ARG wg_port="51820"
ENV TZ="Europe/Amsterdam"
ENV global_dns="1.1.1.1"
ENV enable="none"
ENV isolate="wg0"
ENV isolate="none"
ENV public_ip="0.0.0.0"
# Doing package management operations, such as upgrading
RUN apk update \
&& apk add --no-cache bash git tzdata \
iptables ip6tables openrc curl wireguard-tools \
sudo py3-psutil py3-bcrypt
sudo py3-psutil py3-bcrypt \
&& 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
@ -24,12 +25,10 @@ ENV WGDASH=/opt/wireguarddashboard
# 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 -p /setup/conf && mkdir /setup/app && mkdir ${WGDASH}
COPY ./src /setup/app/src
# Set the volume to be used for WireGuard configuration persistency.
VOLUME /etc/wireguard
VOLUME ${WGDASH}
RUN mkdir /data \
&& mkdir /configs \
&& mkdir -p ${WGDASH}/src
COPY ./src ${WGDASH}/src
# Generate basic WireGuard interface. Echoing the WireGuard interface config for readability, adjust if you want it for efficiency.
# Also setting the pipefail option, verbose: https://github.com/hadolint/hadolint/wiki/DL4006.
@ -44,10 +43,10 @@ PreDown = iptables -t nat -D POSTROUTING -s ${wg_net}/24 -o ${out_adapt} -j MASQ
PreDown = iptables -D FORWARD -i wg0 -o wg0 -j DROP\n\
ListenPort = ${wg_port}\n\
SaveConfig = true\n\
DNS = ${global_dns}" > /setup/conf/wg0.conf \
&& chmod 600 /setup/conf/wg0.conf
DNS = ${global_dns}" > /configs/wg0.conf.template \
&& chmod 600 /configs/wg0.conf.template
# Defining a way for Docker to check the health of the container. In this case: checking the login URL.
# Defining a way for Docker to check the health of the container. In this case: checking the gunicorn process.
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD sh -c 'pgrep gunicorn > /dev/null && pgrep tail > /dev/null' || exit 1

View File

@ -13,7 +13,7 @@ I have tried to embed some new features such as `isolate` and interface startup
## Getting the container running:
To get the container running you either pull the image from the repository, `dselen/wgdashboard:latest`.<br>
To get the container running you either pull the image from the repository, `donaldzou/wgdashboard:latest`.<br>
From there either use the environment variables describe below as parameters or use the Docker Compose file: `compose.yaml`.<br>
Be careful, the default generated WireGuard configuration file uses port 51820/udp. So use this port if you want to use it out of the box.<br>
Otherwise edit the configuration file in `/etc/wireguard/wg0.conf`.
@ -22,14 +22,14 @@ An example of a simple command to get the container running is show below:<br>
```shell
docker run -d \
--name wireguard-dashboard \
--name wgdashboard \
--restart unless-stopped \
-e enable=wg0 \
-e isolate=wg0 \
-p 10086:10086/tcp \
-p 51820:51820/udp \
--cap-add NET_ADMIN \
dselen/wgdashboard:latest
donaldzou/wgdashboard:latest
```
<br>
If you want to use Compose instead of a raw Docker command, refer to the example in the `compose.yaml` or the one pasted below:
@ -37,34 +37,38 @@ If you want to use Compose instead of a raw Docker command, refer to the example
```yaml
services:
wireguard-dashboard:
image: dselen/wgdashboard:latest
wgdashboard:
image: donaldzou/wgdashboard:latest
restart: unless-stopped
container_name: wire-dash
container_name: wgdashboard
environment:
#- tz=
#- global_dns=
- enable=none
- isolate=wg0
#- enable=
#- isolate=
#- public_ip=
ports:
- 10086:10086/tcp
- 51820:51820/udp
volumes:
- conf:/etc/wireguard
- app:/opt/wireguarddashboard/app
- data:/data
cap_add:
- NET_ADMIN
volumes:
conf:
app:
data:
```
If you want to customize the yaml, make sure the core stays the same, but for example volume PATHs can be freely changed.<br>
If you want to customize the yaml, make sure the core stays the same, but for example volume PATHs (ON THE HOST) can be freely changed.<br>
This setup is just generic and will use the Docker volumes.
## Updating the container:
Updating is right now in Alpha stage. I have got it to work, testing methods.
## Working with the container and environment variables:
Once the container is running, the installation process is essentially the same as running it on bare-metal.<br>
@ -75,8 +79,8 @@ So go to the assign TCP port in this case HTTP, like the default 10086 one in th
| tz | Europe/Amsterdam or any confirming timezone notation. | `Europe/Amsterdam` | `America/New_York` | Sets the timezone of the Docker container. This is to timesync the container to any other processes which would need it. |
| global_dns | Any IPv4 address, such as my personal recommendation: 9.9.9.9 (QUAD9). | `1.1.1.1` | `8.8.8.8` or any IP-Address that resolves DNS-names, and of course is reachable | Set the default DNS given to clients once they connect to the WireGuard tunnel, and for new peers, set to Cloudflare DNS for reliability.
| enable | Anything, preferably an existing WireGuard interface name. | `none` | `wg0,wg2,wg13` | Enables or disables the starting of the WireGuard interface on container 'boot-up'.
| isolate | Anything, preferably an existing WireGuard interface name. | `wg0` | `wg1,wg0` | For security premade `wg0` interface comes with this feature enabled by default. Declaring `isolate=none` in the Docker Compose file will remove this. The WireGuard interface itself IS able to reach the peers (Done through the `iptables` package).
| public_ip | Any IPv4 (public recommended) address, such as the one returned by default | Default uses the return of `curl ifconfig.me` | `23.50.131.156` | To reach your VPN from outside your own network, you need WG-Dashboard to know what your public IP-address is, otherwise it will generate faulty config files for clients. This happends because it is inside a Docker/Kubernetes container. In or outside of NAT is not relevant as long as the given IP-address is reachable from the internet or the target network.
| isolate | Anything, preferably an existing WireGuard interface name. | `none` | `wg1,wg0` | The Wireguard interface itself IS able to reach the peers (Done through the `iptables` package).
| public_ip | Any IPv4 (public recommended) address, such as the one returned by default | Default uses the return of `curl ifconfig.me` | `89.20.83.118` | To reach your VPN from outside your own network, you need WG-Dashboard to know what your public IP-address is, otherwise it will generate faulty config files for clients. This happends because it is inside a Docker/Kubernetes container. In or outside of NAT is not relevant as long as the given IP-address is reachable from the internet or the target network.
## Be careful with:
@ -87,8 +91,9 @@ The latter opens up UDP ports from 51820 to 51830, so all ports in between as we
To build the image yourself, you need to do a couple things:<br>
1. Clone the Github repository containing the source code of WGDashboard including the docker directory. For example do: `git clone https://github.com/donaldzou/WGDashboard.git`
1. Navigate into the docker directory.
1. (Make sure you have Docker correctly installed, if not: [Click here](https://docs.docker.com/engine/install/)) and run: `docker build . -t <Image name>:<Image tag>` as an example: `docker build . -t dselen/wgdashboard:latest`.<br>This will make Docker compile the image from the resources in the directory you mention, in this case the current one. Let it compile, it takes about a minute or maximally two.
1. Navigate into the cloned repository.
1. (Make sure you have Docker correctly installed, if not: [Click here](https://docs.docker.com/engine/install/)) and run: `docker build . -t <Image name>:<Image tag>` as an example: `docker build . -t dselen/wgdashboard:latest`.<br>
This will make Docker compile the image from the resources in the directory you mention, in this case the source/root one. Let it compile, it takes only a couple seconds with a minute at most.
1. If all went well, see your image with `docker images`. Example below:
```shell
@ -100,7 +105,3 @@ dselen/wgdashboard latest c96fd96ee3b3 42 minutes ago 314MB
## Closing remarks:
For feedback please submit an issue to the repository. Or message dselen@nerthus.nl.
## In Progress:
Auto-Updating Capabilities, together with Donald I am working on it.

View File

@ -1,23 +1,23 @@
services:
wireguard-dashboard:
image: test:latest
image: donaldzou/wgdashboard:latest
restart: unless-stopped
container_name: wgdashboard
environment:
#- tz= # <--- Set container timezone, default: Europe/Amsterdam.
- global_dns=9.9.9.9 # <--- Set global DNS address, default: 1.1.1.1.
- enable=wg0 # <--- Set the interfaces that will be enabled on startup, default: none. The option "off" is also allowed.
- isolate=wg0 # <--- When set to true, it disallows peers to talk to eachother, setting to false, allows it, default: true.
#- public_ip= # <--- Set public IP to ensure the correct one is chosen, defaulting to the IP give by ifconfig.me.
#- 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:
- 10086:10086/tcp
- 51820:51820/udp
volumes: # Can be customized to only the /opt/wireguarddashboard/src/db folder with the /opt/wireguarddashboard/src/wg-dashboard.ini file.
- ./app:/opt/wireguarddashboard
- ./conf:/etc/wireguard
volumes:
- conf:/etc/wireguard
- data:/data
cap_add:
- NET_ADMIN
volumes:
app:
conf:
data:

View File

@ -5,107 +5,91 @@ echo "Starting the WireGuard Dashboard Docker container."
ensure_installation() {
# When using a custom directory to store the files, this part moves over and makes sure the installation continues.
echo "Checking if everything is present."
echo "Quick-installing..."
if [ -z "$(ls -A "${WGDASH}")" ]; then
echo "Detected empty directory, moving over..."
[ ! -d "/data/db" ] && echo "Creating database dir" && mkdir /data/db
ln -s /data/db "${WGDASH}/src/db"
mv /setup/app/* "${WGDASH}"
#mv /setup/app/.* "${WGDASH}"
[ ! -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"
python3 -m venv "${WGDASH}"/src/venv
. "${WGDASH}/src/venv/bin/activate"
python3 -m venv "${WGDASH}"/src/venv
. "${WGDASH}/src/venv/bin/activate"
# Extra step for Alpine
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
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
chmod +x "${WGDASH}"/src/wgd.sh
cd "${WGDASH}"/src || exit
./wgd.sh install
chmod +x "${WGDASH}"/src/wgd.sh
cd "${WGDASH}"/src || exit
./wgd.sh install
echo "Looks like the installation succesfully moved over."
else
echo "Looks like everything is present. Or the directory is not empty."
fi
echo "Looks like the installation succeeded."
# 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
if [ ! -f "/etc/wireguard/wg0.conf" ]; then
echo "Standard wg0 Configuration file not found, grabbing template."
cp -a "/setup/conf/wg0.conf" "/etc/wireguard/wg0.conf"
cp -a "/configs/wg0.conf.template" "/etc/wireguard/wg0.conf"
echo "Setting a secure private key."
echo "Setting a secure private key." # SORRY 4 BE4 - Daan
local privateKey
privateKey=$(wg genkey)
sed -i "s|^PrivateKey =$|PrivateKey = ${privateKey}|g" /etc/wireguard/wg0.conf
sed -i "s|^PrivateKey *=.*$|PrivateKey = ${privateKey}|g" /etc/wireguard/wg0.conf
echo "Done setting template."
else
echo "Existing wg0 configuration file found, using that."
fi
}
# === CLEAN UP ===
clean_up() {
printf "\n------------------------ CLEAN UP --------------------------\n"
# Cleaning out previous data such as the .pid file and starting the WireGuard Dashboard. Making sure to use the python venv.
echo "Looking for remains of previous instances..."
local pid_file="${WGDASH}/src/gunicorn.pid"
if [ -f "$pid_file" ]; then
echo "Found old pid file, removing."
rm $pid_file
else
echo "No pid remains found, continuing."
fi
# Also check for Python caches (pycache) inspired by https://github.com/shuricksumy
local pycache="${WGDASH}/src/__pycache__"
if [ -d "$pycache" ]; then
local pycache_filecount=$(find "$pycache" -maxdepth 1 -type f | wc -l)
if [ "$pycache_filecount" -gt 0 ]; then
echo "Found old pycaches, removing."
rm -rf "$pycache"/*
else
echo "No pycaches found, continuing."
fi
else
echo "No pycaches found, continuing."
fi
local logdir="${WGDASH}/src/log"
echo "Cleaning log directory."
find /opt/wireguarddashboard/src/log -name 'access_*.log' -exec rm {} +
find /opt/wireguarddashboard/src/log -name 'error_*.log' -exec rm {} +
echo "Removed unneeded logs!"
}
# === SET ENV VARS ===
set_envvars() {
#printf "\n------------- SETTING ENVIRONMENT VARIABLES ----------------\n"
printf "\n------------- SETTING ENVIRONMENT VARIABLES ----------------\n"
# Changing the DNS used for clients and the dashboard itself.
if [ "${global_dns}" != "$(grep "peer_global_dns = " /opt/wireguarddashboard/src/wg-dashboard.ini | awk '{print $NF}')" ]; then
echo "Changing default dns."
# 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
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"
#sed -i "s/^DNS = .*/DNS = ${global_dns}/" /etc/wireguard/wg0.conf # Uncomment if you want to have DNS on server-level.
sed -i "s/^peer_global_dns = .*/peer_global_dns = ${global_dns}/" /opt/wireguarddashboard/src/wg-dashboard.ini
else
echo "DNS is set correctly."
fi
echo "Config file is not empty, enforcing environment variables."
# Setting the public IP of the WireGuard Dashboard container host. If not defined, it will trying fetching it using a curl to ifconfig.me.
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}"
# 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
sed -i "s/^remote_endpoint = .*/remote_endpoint = ${default_ip}/" /opt/wireguarddashboard/src/wg-dashboard.ini
elif [ "${public_ip}" != "$(grep "remote_endpoint = " /opt/wireguarddashboard/src/wg-dashboard.ini | awk '{print $NF}')" ]; then
echo "Setting the Public-IP using given variable: ${public_ip}"
# Determine the public IP and update if necessary
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
sed -i "s/^remote_endpoint = .*/remote_endpoint = ${public_ip}/" /opt/wireguarddashboard/src/wg-dashboard.ini
fi
}
@ -114,113 +98,138 @@ start_core() {
printf "\n---------------------- STARTING CORE -----------------------\n"
echo "Activating Python venv and executing the WireGuard Dashboard service."
. "${WGDASH}"/src/venv/bin/activate
cd "${WGDASH}"/src || return
bash wgd.sh start &>> /dev/null
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
local config=$(echo "$config" | sed -e 's|.*/etc/wireguard/||' -e 's|\.conf$||')
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.
for interface in "${do_isolate[@]}"; do
if [ "$interface" = "none" ]; then
if [ "$interface" = "none" ] || [ "$interface" = "" ]; then
echo "Found: $interface, stopping isolation checking."
break
else
if [ -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)
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
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 does not seem to exist, continuing."
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 [ -f "/etc/wireguard/${interface}.conf" ]; then
echo "Removing Isolation if 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
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 does not seem to exist, continuing."
echo "Configuration for $interface in removing isolation does not seem to exist, continuing."
fi
done
# The following section takes care of enabling wireguard interfaces on startup. Using arrays and given arguments.
#
# WILL BE REMOVED IN FUTURE WHEN WGDASHBOARD ITSELF SUPPORTS THIS!!
#
IFS=',' read -r -a enable_array <<< "${enable}"
for interface in "${enable_array[@]}"; do
if [ "$interface" = "none" ]; then
echo "Found: $interface, stopping enabling checking."
break
else
echo "Enabling interface:" $interface
echo "Enabling interface:" "$interface"
local fileperms=$(stat -c "%a" /etc/wireguard/${interface}.conf)
if [ $fileperms -eq 644 ]; then
local fileperms
fileperms=$(stat -c "%a" /etc/wireguard/"${interface}".conf)
if [ "$fileperms" -eq 644 ]; then
echo "Configuration is world accessible, adjusting."
chmod 600 "/etc/wireguard/${interface}.conf"
fi
if [ -f "/etc/wireguard/${interface}.conf" ]; then
wg-quick up $interface
wg-quick up "$interface"
else
echo "No corresponding configuration file found for $interface doing nothing."
fi
fi
done
}
# === CLEAN UP ===
ensure_blocking() {
#printf "\n-------------- ENSURING CONTAINER CONTINUATION -------------\n"
. "${WGDASH}"/src/venv/bin/activate
cd "${WGDASH}"/src || return
bash wgd.sh restart
sleep 1s
echo "Ensuring container continuation."
echo -e "\nEnsuring container continuation."
# This function checks if the latest error log is created and tails it for docker logs uses.
if find "/opt/wireguarddashboard/src/log" -mindepth 1 -maxdepth 1 -type f | read -r; then
latestErrLog=$(find /opt/wireguarddashboard/src/log -name "error_*.log" | head -n 1)
latestAccLog=$(find /opt/wireguarddashboard/src/log -name "access_*.log" | head -n 1)
# Find and tail the latest error and access logs if they exist
local logdir="/opt/wireguarddashboard/src/log"
tail -f "${latestErrLog}" "${latestAccLog}"
latestErrLog=$(find "$logdir" -name "error_*.log" -type f -print | sort -r | head -n 1)
latestAccLog=$(find "$logdir" -name "access_*.log" -type f -print | sort -r | head -n 1)
# Only tail the logs if they are found
if [ -n "$latestErrLog" ] || [ -n "$latestAccLog" ]; then
tail -f "$latestErrLog" "$latestAccLog"
else
echo "No log files found to tail."
fi
# Blocking command in case of erroring. So the container does not quit.
# Blocking command to keep the container running as a last resort.
sleep infinity
}
# Execute functions for the WireGuard Dashboard services, then set the environment variables
ensure_installation
clean_up
start_core
set_envvars
start_core
ensure_blocking

View File

@ -380,20 +380,29 @@ update_wgd() {
new_ver=$($venv_python -c "import json; import urllib.request; data = urllib.request.urlopen('https://api.github.com/repos/donaldzou/WGDashboard/releases/latest').read(); output = json.loads(data);print(output['tag_name'])")
printf "%s\n" "$dashes"
printf "[WGDashboard] Are you sure you want to update to the %s? (Y/N): " "$new_ver"
read up
if [ "$commandConfirmed" = "true" ]; then
printf "[WGDashboard] Confirmation granted.\n"
up="Y"
else
printf "[WGDashboard] Are you sure you want to update to the %s? (Y/N): " "$new_ver"
read up
fi
if [ "$up" = "Y" ] || [ "$up" = "y" ]; then
printf "[WGDashboard] Shutting down WGDashboard\n"
if check_wgd_status; then
stop_wgd
fi
mv wgd.sh wgd.sh.old
printf "[WGDashboard] Downloading %s from GitHub..." "$new_ver"
{ date; git stash; git pull https://github.com/donaldzou/WGDashboard.git $new_ver --force; } >> ./log/update.txt
chmod +x ./wgd.sh
sudo ./wgd.sh install
printf "[WGDashboard] Update completed!\n"
printf "%s\n" "$dashes"
mv wgd.sh wgd.sh.old && \
printf "[WGDashboard] Downloading %s from GitHub..." "$new_ver" && \
{ date; git stash; git pull https://github.com/donaldzou/WGDashboard.git $new_ver --force; } >> ./log/update.txt && \
chmod +x ./wgd.sh && \
sudo ./wgd.sh install && \
printf "[WGDashboard] Update completed!\n" && \
printf "%s\n" "$dashes"; \
rm wgd.sh.old
else
printf "%s\n" "$dashes"
@ -402,52 +411,55 @@ update_wgd() {
fi
}
if [ "$#" != 1 ];
then
help
else
if [ "$1" = "start" ]; then
if check_wgd_status; then
printf "%s\n" "$dashes"
printf "[WGDashboard] WGDashboard is already running.\n"
printf "%s\n" "$dashes"
else
start_wgd
fi
elif [ "$1" = "stop" ]; then
if check_wgd_status; then
printf "%s\n" "$dashes"
stop_wgd
printf "[WGDashboard] WGDashboard is stopped.\n"
printf "%s\n" "$dashes"
else
printf "%s\n" "$dashes"
printf "[WGDashboard] WGDashboard is not running.\n"
printf "%s\n" "$dashes"
fi
elif [ "$1" = "update" ]; then
update_wgd
elif [ "$1" = "install" ]; then
printf "%s\n" "$dashes"
install_wgd
printf "%s\n" "$dashes"
elif [ "$1" = "restart" ]; then
if check_wgd_status; then
printf "%s\n" "$dashes"
stop_wgd
printf "| WGDashboard is stopped. |\n"
sleep 4
start_wgd
else
start_wgd
fi
elif [ "$1" = "debug" ]; then
if check_wgd_status; then
printf "| WGDashboard is already running. |\n"
else
start_wgd_debug
fi
else
help
fi
if [ "$#" -lt 1 ]; then
help
else
if [ "$2" = "-y" ] || [ "$2" = "-Y" ]; then
commandConfirmed="true"
fi
if [ "$1" = "start" ]; then
if check_wgd_status; then
printf "%s\n" "$dashes"
printf "[WGDashboard] WGDashboard is already running.\n"
printf "%s\n" "$dashes"
else
start_wgd
fi
elif [ "$1" = "stop" ]; then
if check_wgd_status; then
printf "%s\n" "$dashes"
stop_wgd
printf "[WGDashboard] WGDashboard is stopped.\n"
printf "%s\n" "$dashes"
else
printf "%s\n" "$dashes"
printf "[WGDashboard] WGDashboard is not running.\n"
printf "%s\n" "$dashes"
fi
elif [ "$1" = "update" ]; then
update_wgd
elif [ "$1" = "install" ]; then
printf "%s\n" "$dashes"
install_wgd
printf "%s\n" "$dashes"
elif [ "$1" = "restart" ]; then
if check_wgd_status; then
printf "%s\n" "$dashes"
stop_wgd
printf "| WGDashboard is stopped. |\n"
sleep 4
start_wgd
else
start_wgd
fi
elif [ "$1" = "debug" ]; then
if check_wgd_status; then
printf "| WGDashboard is already running. |\n"
else
start_wgd_debug
fi
else
help
fi
fi