mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2024-11-06 07:50:13 +01:00
Fixed Docker Vulnerability
+ Switched Base Image to Alpine + Simplified Docker Build + Added Alpine support to wgd.sh script. + Maintained Project Layout.
This commit is contained in:
parent
dc7140d486
commit
8378030c70
24
Dockerfile
Normal file
24
Dockerfile
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Pull from small Debian stable image.
|
||||||
|
FROM alpine:latest
|
||||||
|
LABEL maintainer="dselen@nerthus.nl"
|
||||||
|
ENV PYTHONPATH="/usr/bin/python"
|
||||||
|
|
||||||
|
WORKDIR /home/app
|
||||||
|
RUN apk update && \
|
||||||
|
apk add --no-cache py3-bcrypt py3-psutil && \
|
||||||
|
apk add --no-cache wireguard-tools && \
|
||||||
|
apk add --no-cache net-tools iproute2 iptables ip6tables && \
|
||||||
|
apk add --no-cache inotify-tools procps openresolv && \
|
||||||
|
mkdir /home/app/master-key
|
||||||
|
|
||||||
|
COPY ./src /home/app
|
||||||
|
COPY ./docker/wgd.sh /home/app/
|
||||||
|
COPY ./docker/requirements.txt /home/app/
|
||||||
|
|
||||||
|
RUN chmod u+x /home/app/entrypoint.sh
|
||||||
|
|
||||||
|
|
||||||
|
# Defining a way for Docker to check the health of the container. In this case: checking the login URL.
|
||||||
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD curl -f http://localhost:10086/signin || exit 1
|
||||||
|
|
||||||
|
ENTRYPOINT ["/home/app/entrypoint.sh"]
|
23
compose.yaml
Normal file
23
compose.yaml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
services:
|
||||||
|
|
||||||
|
wireguard-dashboard:
|
||||||
|
build: ./
|
||||||
|
container_name: wiregate
|
||||||
|
cap_add:
|
||||||
|
- NET_ADMIN
|
||||||
|
- SYS_MODULE
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- wgd_configs:/etc/wireguard
|
||||||
|
- wgd_app:/home/app
|
||||||
|
ports:
|
||||||
|
- 10086:10086/tcp
|
||||||
|
- 51820:51820/udp
|
||||||
|
sysctls:
|
||||||
|
- net.ipv4.ip_forward=1
|
||||||
|
- net.ipv4.conf.all.src_valid_mark=1
|
||||||
|
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
wgd_configs:
|
||||||
|
wgd_app:
|
@ -1,77 +0,0 @@
|
|||||||
# Pull from small Debian stable image.
|
|
||||||
FROM debian:stable-slim
|
|
||||||
LABEL maintainer="dselen@nerthus.nl"
|
|
||||||
|
|
||||||
# Declaring environment variables, change Peernet to an address you like, standard is a 24 bit subnet.
|
|
||||||
ENV wg_net="10.0.0.1"
|
|
||||||
# wg_net is used functionally as an ARG for its environment variable nature, do not change unless you know what you are doing.
|
|
||||||
|
|
||||||
# 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_wg0="false"
|
|
||||||
ENV isolated_peers="true"
|
|
||||||
ENV public_ip="0.0.0.0"
|
|
||||||
|
|
||||||
# Doing basic system maintenance. Change the timezone to the desired timezone.
|
|
||||||
RUN ln -sf /usr/share/zoneinfo/${tz} /etc/localtime
|
|
||||||
|
|
||||||
# Doing package management operations, such as upgrading
|
|
||||||
RUN apt-get update && apt-get upgrade -y \
|
|
||||||
&& apt-get install -y --no-install-recommends curl \
|
|
||||||
git \
|
|
||||||
iproute2 \
|
|
||||||
iptables \
|
|
||||||
iputils-ping \
|
|
||||||
openresolv \
|
|
||||||
procps \
|
|
||||||
python3 \
|
|
||||||
python3-pip \
|
|
||||||
python3-venv \
|
|
||||||
traceroute \
|
|
||||||
wireguard \
|
|
||||||
wireguard-tools \
|
|
||||||
&& apt-get remove linux-image-* --autoremove -y \
|
|
||||||
&& apt-get clean \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
# 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
|
|
||||||
RUN python3 -m venv ${WGDASH}/venv
|
|
||||||
|
|
||||||
# Doing WireGuard Dashboard installation measures. Modify the git clone command to get the preferred version, with a specific branch for example.
|
|
||||||
RUN . ${WGDASH}/venv/bin/activate \
|
|
||||||
&& git clone https://github.com/donaldzou/WGDashboard.git ${WGDASH}/app \
|
|
||||||
&& pip3 install -r ${WGDASH}/app/src/requirements.txt \
|
|
||||||
&& chmod +x ${WGDASH}/app/src/wgd.sh \
|
|
||||||
&& .${WGDASH}/app/src/wgd.sh install
|
|
||||||
|
|
||||||
# Set the volume to be used for persistency.
|
|
||||||
VOLUME /etc/wireguard
|
|
||||||
|
|
||||||
# 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.
|
|
||||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
|
||||||
RUN wg genkey | tee /etc/wireguard/wg0_privatekey \
|
|
||||||
&& echo "[Interface]" > /wg0.conf \
|
|
||||||
&& echo "SaveConfig = true" >> /wg0.conf \
|
|
||||||
&& echo "Address = ${wg_net}/24" >> /wg0.conf \
|
|
||||||
&& echo "PrivateKey = $(cat /etc/wireguard/wg0_privatekey)" >> /wg0.conf \
|
|
||||||
&& echo "PostUp = iptables -t nat -I POSTROUTING 1 -s ${wg_net}/24 -o $(ip -o -4 route show to default | awk '{print $NF}') -j MASQUERADE" >> /wg0.conf \
|
|
||||||
&& echo "PostUp = iptables -I FORWARD -i wg0 -o wg0 -j DROP" >> /wg0.conf \
|
|
||||||
&& echo "PreDown = iptables -t nat -D POSTROUTING 1" >> /wg0.conf \
|
|
||||||
&& echo "PreDown = iptables -D FORWARD -i wg0 -o wg0 -j DROP" >> /wg0.conf \
|
|
||||||
&& echo "ListenPort = 51820" >> /wg0.conf \
|
|
||||||
#&& echo "DNS = ${global_dns}" >> /wg0.conf \
|
|
||||||
&& rm /etc/wireguard/wg0_privatekey
|
|
||||||
|
|
||||||
# Defining a way for Docker to check the health of the container. In this case: checking the login URL.
|
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD curl -f http://localhost:10086/signin || exit 1
|
|
||||||
|
|
||||||
# Copy the basic entrypoint.sh script.
|
|
||||||
COPY entrypoint.sh /entrypoint.sh
|
|
||||||
|
|
||||||
# Exposing the default WireGuard Dashboard port for web access.
|
|
||||||
EXPOSE 10086
|
|
||||||
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
|
|
@ -1,23 +0,0 @@
|
|||||||
services:
|
|
||||||
wireguard-dashboard:
|
|
||||||
image: repo.nerthus.nl/app/wireguard-dashboard:latest
|
|
||||||
restart: unless-stopped
|
|
||||||
container_name: wire-dash
|
|
||||||
environment:
|
|
||||||
#- tz= # <--- Set container timezone, default: Europe/Amsterdam.
|
|
||||||
#- global_dns= # <--- Set global DNS address, default: 1.1.1.1.
|
|
||||||
- enable_wg0=true # <--- If true, wg0 will be started on container startup. default: false.
|
|
||||||
- isolated_peers=false # <--- 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.
|
|
||||||
ports:
|
|
||||||
- 10086:10086/tcp
|
|
||||||
- 51820:51820/udp
|
|
||||||
volumes:
|
|
||||||
- conf:/etc/wireguard
|
|
||||||
- app:/opt/wireguarddashboard/app
|
|
||||||
cap_add:
|
|
||||||
- NET_ADMIN
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
conf:
|
|
||||||
app:
|
|
@ -1,109 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
echo "Starting the WireGuard Dashboard Docker container."
|
|
||||||
|
|
||||||
clean_up() {
|
|
||||||
# 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..."
|
|
||||||
if [ -f "/opt/wireguarddashboard/app/src/gunicorn.pid" ]; then
|
|
||||||
echo "Found old .pid file, removing."
|
|
||||||
rm /opt/wireguarddashboard/app/src/gunicorn.pid
|
|
||||||
else
|
|
||||||
echo "No remains found, continuing."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
start_core() {
|
|
||||||
# This first step is to ensure the wg0.conf file exists, and if not, then its copied over from the ephemeral container storage.
|
|
||||||
if [ ! -f "/etc/wireguard/wg0.conf" ]; then
|
|
||||||
cp "/wg0.conf" "/etc/wireguard/wg0.conf"
|
|
||||||
echo "WireGuard interface file copied over."
|
|
||||||
else
|
|
||||||
echo "WireGuard interface file looks to already be existing."
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Activating Python venv and executing the WireGuard Dashboard service."
|
|
||||||
|
|
||||||
. "${WGDASH}"/venv/bin/activate
|
|
||||||
cd "${WGDASH}"/app/src || return # If changing the directory fails (permission or presence error), then bash will exist this function, causing the WireGuard Dashboard to not be succesfully launched.
|
|
||||||
bash wgd.sh start
|
|
||||||
|
|
||||||
# The following section takes care of the firewall rules regarding the 'isolated_peers' feature, which allows or drops packets destined from the wg0 to the wg0 interface.
|
|
||||||
if [ "${isolated_peers,,}" = "false" ]; then
|
|
||||||
echo "Isolated peers disabled, adjusting."
|
|
||||||
|
|
||||||
sed -i '/PostUp = iptables -I FORWARD -i wg0 -o wg0 -j DROP/d' /etc/wireguard/wg0.conf
|
|
||||||
sed -i '/PreDown = iptables -D FORWARD -i wg0 -o wg0 -j DROP/d' /etc/wireguard/wg0.conf
|
|
||||||
elif [ "${isolated_peers,,}" = "true" ]; then
|
|
||||||
upblocking=$(grep -c "PostUp = iptables -I FORWARD -i wg0 -o wg0 -j DROP" /etc/wireguard/wg0.conf)
|
|
||||||
downblocking=$(grep -c "PreDown = iptables -D FORWARD -i wg0 -o wg0 -j DROP" /etc/wireguard/wg0.conf)
|
|
||||||
if [ "$upblocking" -lt 1 ] && [ "$downblocking" -lt 1 ]; then
|
|
||||||
echo "Isolated peers enabled, adjusting."
|
|
||||||
|
|
||||||
sed -i '/PostUp = iptables -t nat -I POSTROUTING 1 -s/a PostUp = iptables -I FORWARD -i wg0 -o wg0 -j DROP' /etc/wireguard/wg0.conf
|
|
||||||
sed -i '/PreDown = iptables -t nat -D POSTROUTING 1 -s/a PreDown = iptables -D FORWARD -i wg0 -o wg0 -j DROP' /etc/wireguard/wg0.conf
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
# The following section takes care of
|
|
||||||
if [ "${enable_wg0,,}" = "true" ]; then
|
|
||||||
echo "Preference for wg0 to be turned on found."
|
|
||||||
|
|
||||||
wg-quick up wg0
|
|
||||||
else
|
|
||||||
echo "Preference for wg0 to be turned off found."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
set_envvars() {
|
|
||||||
echo "Setting relevant variables for operation."
|
|
||||||
|
|
||||||
# If the timezone is different, for example in North-America or Asia.
|
|
||||||
if [ "${tz}" != "$(cat /etc/timezone)" ]; then
|
|
||||||
echo "Changing timezone."
|
|
||||||
|
|
||||||
ln -sf /usr/share/zoneinfo/"${tz}" /etc/localtime
|
|
||||||
echo "${tz}" > /etc/timezone
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Changing the DNS used for clients and the dashboard itself.
|
|
||||||
if [ "${global_dns}" != "$(grep "peer_global_dns = " /opt/wireguarddashboard/app/src/wg-dashboard.ini | awk '{print $NF}')" ]; then
|
|
||||||
echo "Changing default dns."
|
|
||||||
|
|
||||||
#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/app/src/wg-dashboard.ini
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 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}"
|
|
||||||
|
|
||||||
sed -i "s/^remote_endpoint = .*/remote_endpoint = ${default_ip}/" /opt/wireguarddashboard/app/src/wg-dashboard.ini
|
|
||||||
elif [ "${public_ip}" != "$(grep "remote_endpoint = " /opt/wireguarddashboard/app/src/wg-dashboard.ini | awk '{print $NF}')" ]; then
|
|
||||||
echo "Setting the Public-IP using given variable: ${public_ip}"
|
|
||||||
|
|
||||||
sed -i "s/^remote_endpoint = .*/remote_endpoint = ${public_ip}/" /opt/wireguarddashboard/app/src/wg-dashboard.ini
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
ensure_blocking() {
|
|
||||||
sleep 1s
|
|
||||||
echo "Ensuring container continuation."
|
|
||||||
|
|
||||||
# This function checks if the latest error log is created and tails it for docker logs uses.
|
|
||||||
if find "/opt/wireguarddashboard/app/src/log" -mindepth 1 -maxdepth 1 -type f | read -r; then
|
|
||||||
latestErrLog=$(find /opt/wireguarddashboard/app/src/log -name "error_*.log" | head -n 1)
|
|
||||||
latestAccLog=$(find /opt/wireguarddashboard/app/src/log -name "access_*.log" | head -n 1)
|
|
||||||
tail -f "${latestErrLog}" "${latestAccLog}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Blocking command in case of erroring. So the container does not quit.
|
|
||||||
sleep infinity
|
|
||||||
}
|
|
||||||
|
|
||||||
# Execute functions for the WireGuard Dashboard services, then set the environment variables
|
|
||||||
clean_up
|
|
||||||
start_core
|
|
||||||
set_envvars
|
|
||||||
ensure_blocking
|
|
8
docker/requirements.txt
Normal file
8
docker/requirements.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#bcrypt
|
||||||
|
ifcfg
|
||||||
|
#psutil
|
||||||
|
pyotp
|
||||||
|
Flask
|
||||||
|
flask-cors
|
||||||
|
icmplib
|
||||||
|
gunicorn
|
397
docker/wgd.sh
Normal file
397
docker/wgd.sh
Normal file
@ -0,0 +1,397 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# wgd.sh - Copyright(C) 2024 Donald Zou [https://github.com/donaldzou]
|
||||||
|
# Under Apache-2.0 License
|
||||||
|
app_name="dashboard.py"
|
||||||
|
app_official_name="WGDashboard"
|
||||||
|
venv_python="./venv/bin/python3"
|
||||||
|
venv_gunicorn="./venv/bin/gunicorn"
|
||||||
|
|
||||||
|
PID_FILE=./gunicorn.pid
|
||||||
|
environment=$(if [[ $ENVIRONMENT ]]; then echo $ENVIRONMENT; else echo 'develop'; fi)
|
||||||
|
if [[ $CONFIGURATION_PATH ]]; then
|
||||||
|
cb_work_dir=$CONFIGURATION_PATH/letsencrypt/work-dir
|
||||||
|
cb_config_dir=$CONFIGURATION_PATH/letsencrypt/config-dir
|
||||||
|
else
|
||||||
|
cb_work_dir=/etc/letsencrypt
|
||||||
|
cb_config_dir=/var/lib/letsencrypt
|
||||||
|
fi
|
||||||
|
|
||||||
|
dashes='------------------------------------------------------------'
|
||||||
|
equals='============================================================'
|
||||||
|
helpMsg="[WGDashboard] Please check ./log/install.txt for more details. For further assistance, please open a ticket on https://github.com/donaldzou/WGDashboard/issues/new/choose, I'm more than happy to help :)"
|
||||||
|
help () {
|
||||||
|
printf "=================================================================================\n"
|
||||||
|
printf "+ <WGDashboard> by Donald Zou - https://github.com/donaldzou +\n"
|
||||||
|
printf "=================================================================================\n"
|
||||||
|
printf "| Usage: ./wgd.sh <option> |\n"
|
||||||
|
printf "| |\n"
|
||||||
|
printf "| Available options: |\n"
|
||||||
|
printf "| start: To start WGDashboard. |\n"
|
||||||
|
printf "| stop: To stop WGDashboard. |\n"
|
||||||
|
printf "| debug: To start WGDashboard in debug mode (i.e run in foreground). |\n"
|
||||||
|
printf "| update: To update WGDashboard to the newest version from GitHub. |\n"
|
||||||
|
printf "| install: To install WGDashboard. |\n"
|
||||||
|
printf "| Thank you for using! Your support is my motivation ;) |\n"
|
||||||
|
printf "=================================================================================\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
_check_and_set_venv(){
|
||||||
|
VIRTUAL_ENV="./venv"
|
||||||
|
if [ ! -d $VIRTUAL_ENV ]; then
|
||||||
|
printf "[WGDashboard] Creating Python Virtual Environment under ./venv\n"
|
||||||
|
{ python3 -m venv --system-site-packages $VIRTUAL_ENV; } >> ./log/install.txt
|
||||||
|
fi
|
||||||
|
printf "[WGDashboard] Activate Python Virtual Environment under ./venv\n"
|
||||||
|
. ${VIRTUAL_ENV}/bin/activate
|
||||||
|
}
|
||||||
|
|
||||||
|
_determineOS() {
|
||||||
|
if [ -f /etc/os-release ]; then
|
||||||
|
. /etc/os-release
|
||||||
|
OS=$ID
|
||||||
|
elif [ -f /etc/redhat-release ]; then
|
||||||
|
OS="redhat"
|
||||||
|
elif [ -f /etc/alpine-release ]; then
|
||||||
|
OS="alpine"
|
||||||
|
else
|
||||||
|
printf "[WGDashboard] Sorry, your OS is not supported. Currently, the install script only supports Debian-based, Red Hat-based, and Alpine OS.\n"
|
||||||
|
printf "%s\n" "$helpMsg"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_installPython() {
|
||||||
|
case "$OS" in
|
||||||
|
ubuntu|debian)
|
||||||
|
{ apt update; apt-get install -y python3; printf "\n\n"; } &>> ./log/install.txt
|
||||||
|
;;
|
||||||
|
centos|fedora|redhat)
|
||||||
|
if command -v dnf &> /dev/null; then
|
||||||
|
{ dnf install -y python3; printf "\n\n"; } >> ./log/install.txt
|
||||||
|
else
|
||||||
|
{ yum install -y python3; printf "\n\n"; } >> ./log/install.txt
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
alpine)
|
||||||
|
{ apk add --no-cache python3; printf "\n\n"; } &>> ./log/install.txt
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf "[WGDashboard] Sorry, your OS is not supported. Currently, the install script only supports Debian-based, Red Hat-based, and Alpine OS.\n"
|
||||||
|
printf "%s\n" "$helpMsg"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if ! python3 --version > /dev/null 2>&1; then
|
||||||
|
printf "[WGDashboard] Python is still not installed, halting script now.\n"
|
||||||
|
printf "%s\n" "$helpMsg"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
printf "[WGDashboard] \xE2\x9C\x94 Python is installed\n"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_installPythonVenv(){
|
||||||
|
case "$OS" in
|
||||||
|
ubuntu|debian)
|
||||||
|
{
|
||||||
|
apt update
|
||||||
|
apt-get install -y python3-venv
|
||||||
|
printf "\n\n"
|
||||||
|
} &>> ./log/install.txt
|
||||||
|
;;
|
||||||
|
centos|fedora|redhat)
|
||||||
|
if command -v dnf &> /dev/null; then
|
||||||
|
{
|
||||||
|
dnf install -y python3-virtualenv
|
||||||
|
printf "\n\n"
|
||||||
|
} >> ./log/install.txt
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yum install -y python3-virtualenv
|
||||||
|
printf "\n\n"
|
||||||
|
} >> ./log/install.txt
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
alpine)
|
||||||
|
{
|
||||||
|
apk update
|
||||||
|
apk add --no-cache python3 py3-virtualenv
|
||||||
|
printf "\n\n"
|
||||||
|
} >> ./log/install.txt
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf "[WGDashboard] Sorry, your OS is not supported. Currently the install script only supports Debian-based, Red Hat-based, and Alpine OS.\n"
|
||||||
|
printf "%s\n" "$helpMsg"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if ! python3 -m venv -h > /dev/null 2>&1
|
||||||
|
then
|
||||||
|
printf "[WGDashboard] Python Virtual Environment is still not installed, halting script now.\n"
|
||||||
|
printf "%s\n" "$helpMsg"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
printf "[WGDashboard] \xE2\x9C\x94 Python Virtual Environment is installed\n"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_installPythonPip() {
|
||||||
|
case "$OS" in
|
||||||
|
ubuntu|debian)
|
||||||
|
{ apt update; apt-get install -y python3-pip; printf "\n\n"; } &>> ./log/install.txt
|
||||||
|
;;
|
||||||
|
centos|fedora|redhat)
|
||||||
|
if command -v dnf &> /dev/null; then
|
||||||
|
{ dnf install -y python3-pip; printf "\n\n"; } >> ./log/install.txt
|
||||||
|
else
|
||||||
|
{ yum install -y python3-pip; printf "\n\n"; } >> ./log/install.txt
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
alpine)
|
||||||
|
{ apk add --no-cache py3-pip; printf "\n\n"; } &>> ./log/install.txt
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf "[WGDashboard] Sorry, your OS is not supported for auto install. Currently, the install script only supports Debian-based, Red Hat-based, and Alpine OS.\n"
|
||||||
|
printf "%s\n" "$helpMsg"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if ! python3 -m pip -h > /dev/null 2>&1; then
|
||||||
|
printf "[WGDashboard] Python Package Manager (PIP) is still not installed, halting script now.\n"
|
||||||
|
printf "%s\n" "$helpMsg"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
printf "[WGDashboard] \xE2\x9C\x94 Python Package Manager (PIP) is installed\n"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_checkWireguard(){
|
||||||
|
if ! wg -h > /dev/null 2>&1
|
||||||
|
then
|
||||||
|
printf "[WGDashboard] WireGuard is not installed. Please follow instruction on https://www.wireguard.com/install/ to install. \n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! wg-quick -h > /dev/null 2>&1
|
||||||
|
then
|
||||||
|
printf "[WGDashboard] WireGuard is not installed. Please follow instruction on https://www.wireguard.com/install/ to install. \n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install_wgd(){
|
||||||
|
printf "[WGDashboard] Starting to install WGDashboard\n"
|
||||||
|
_checkWireguard
|
||||||
|
chmod -R 755 /etc/wireguard/
|
||||||
|
|
||||||
|
if [ ! -d "log" ]
|
||||||
|
then
|
||||||
|
printf "[WGDashboard] Creating ./log folder\n"
|
||||||
|
mkdir "log"
|
||||||
|
fi
|
||||||
|
_determineOS
|
||||||
|
if ! python3 --version > /dev/null 2>&1
|
||||||
|
then
|
||||||
|
printf "[WGDashboard] Python is not installed, trying to install now\n"
|
||||||
|
_installPython
|
||||||
|
else
|
||||||
|
printf "[WGDashboard] \xE2\x9C\x94 Python is installed\n"
|
||||||
|
fi
|
||||||
|
_installPythonVenv
|
||||||
|
_installPythonPip
|
||||||
|
|
||||||
|
version_pass=$(python3 -c 'import sys; print("1") if (sys.version_info.major == 3 and sys.version_info.minor >= 10) else print("0");')
|
||||||
|
if [ $version_pass == "0" ]
|
||||||
|
then
|
||||||
|
printf "[WGDashboard] WGDashboard required Python 3.7 or above\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "db" ]
|
||||||
|
then
|
||||||
|
printf "[WGDashboard] Creating ./db folder\n"
|
||||||
|
mkdir "db"
|
||||||
|
fi
|
||||||
|
_check_and_set_venv
|
||||||
|
printf "[WGDashboard] Upgrading Python Package Manage (PIP)\n"
|
||||||
|
{ date; python3 -m pip install --upgrade pip; printf "\n\n"; } >> ./log/install.txt
|
||||||
|
printf "[WGDashboard] Installing latest Python dependencies\n"
|
||||||
|
{ date; python3 -m pip install -r requirements.txt ; printf "\n\n"; } >> ./log/install.txt
|
||||||
|
printf "[WGDashboard] WGDashboard installed successfully!\n"
|
||||||
|
printf "[WGDashboard] Enter ./wgd.sh start to start the dashboard\n"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
check_wgd_status(){
|
||||||
|
if test -f "$PID_FILE"; then
|
||||||
|
if ps aux | grep -v grep | grep $(cat ./gunicorn.pid) > /dev/null; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if ps aux | grep -v grep | grep '[p]ython3 '$app_name > /dev/null; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
certbot_create_ssl () {
|
||||||
|
certbot certonly --config ./certbot.ini --email "$EMAIL" --work-dir $cb_work_dir --config-dir $cb_config_dir --domain "$SERVERURL"
|
||||||
|
}
|
||||||
|
|
||||||
|
certbot_renew_ssl () {
|
||||||
|
certbot renew --work-dir $cb_work_dir --config-dir $cb_config_dir
|
||||||
|
}
|
||||||
|
|
||||||
|
gunicorn_start () {
|
||||||
|
printf "%s\n" "$dashes"
|
||||||
|
printf "[WGDashboard] Starting WGDashboard with Gunicorn in the background.\n"
|
||||||
|
d=$(date '+%Y%m%d%H%M%S')
|
||||||
|
|
||||||
|
is_alpine() {
|
||||||
|
grep -q "Alpine" /etc/os-release 2>/dev/null
|
||||||
|
}
|
||||||
|
if [[ $USER == root ]]; then
|
||||||
|
if is_alpine; then
|
||||||
|
export PATH=$PATH:/usr/local/bin:$HOME/.local/bin:/sbin:/usr/sbin
|
||||||
|
else
|
||||||
|
export PATH=$PATH:/usr/local/bin:$HOME/.local/bin
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
_check_and_set_venv
|
||||||
|
|
||||||
|
if [ ! -x "$venv_gunicorn" ]; then
|
||||||
|
printf "[ERROR] Gunicorn executable not found or not executable.\n"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
gunicorn -c ./gunicorn.conf.py
|
||||||
|
# line below exsits after execution when using docker
|
||||||
|
#"$venv_gunicorn" --config ./gunicorn.conf.py &
|
||||||
|
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
checkPIDExist=0
|
||||||
|
while [ $checkPIDExist -eq 0 ]; do
|
||||||
|
if test -f './gunicorn.pid'; then
|
||||||
|
checkPIDExist=1
|
||||||
|
printf "[WGDashboard] Checking if WGDashboard w/ Gunicorn started successfully\n"
|
||||||
|
else
|
||||||
|
printf "[INFO] Waiting for Gunicorn PID file to be created...\n"
|
||||||
|
fi
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
printf "[WGDashboard] WGDashboard w/ Gunicorn started successfully\n"
|
||||||
|
printf "%s\n" "$dashes"
|
||||||
|
}
|
||||||
|
|
||||||
|
gunicorn_stop () {
|
||||||
|
kill $(cat ./gunicorn.pid)
|
||||||
|
}
|
||||||
|
|
||||||
|
start_wgd () {
|
||||||
|
_checkWireguard
|
||||||
|
gunicorn_start
|
||||||
|
}
|
||||||
|
|
||||||
|
stop_wgd() {
|
||||||
|
if test -f "$PID_FILE"; then
|
||||||
|
gunicorn_stop
|
||||||
|
else
|
||||||
|
kill "$(ps aux | grep "[p]ython3 $app_name" | awk '{print $2}')"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
start_wgd_debug() {
|
||||||
|
printf "%s\n" "$dashes"
|
||||||
|
_checkWireguard
|
||||||
|
printf "[WGDashboard] Starting WGDashboard in the foreground.\n"
|
||||||
|
"$venv_python" "$app_name"
|
||||||
|
printf "%s\n" "$dashes"
|
||||||
|
}
|
||||||
|
|
||||||
|
update_wgd() {
|
||||||
|
new_ver=$(python3 -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 [ "$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
|
||||||
|
./wgd.sh install
|
||||||
|
printf "[WGDashboard] Update completed!\n"
|
||||||
|
printf "%s\n" "$dashes"
|
||||||
|
rm wgd.sh.old
|
||||||
|
else
|
||||||
|
printf "%s\n" "$dashes"
|
||||||
|
printf "| Update Canceled. |\n"
|
||||||
|
printf "%s\n" "$dashes"
|
||||||
|
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
|
||||||
|
fi
|
@ -1073,9 +1073,17 @@ def regex_match(regex, text):
|
|||||||
return pattern.search(text) is not None
|
return pattern.search(text) is not None
|
||||||
|
|
||||||
def iPv46RegexCheck(ip):
|
def iPv46RegexCheck(ip):
|
||||||
return re.match(
|
pattern = r'(^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$|' \
|
||||||
'((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))',
|
r'^\s*((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)' \
|
||||||
ip)
|
r'(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)' \
|
||||||
|
r'(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)' \
|
||||||
|
r'(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)' \
|
||||||
|
r'(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)' \
|
||||||
|
r'(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)' \
|
||||||
|
r'(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)' \
|
||||||
|
r'(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$)'
|
||||||
|
|
||||||
|
return re.match(pattern, ip)
|
||||||
|
|
||||||
class DashboardAPIKey:
|
class DashboardAPIKey:
|
||||||
def __init__(self, Key: str, CreatedAt: str, ExpiredAt: str):
|
def __init__(self, Key: str, CreatedAt: str, ExpiredAt: str):
|
||||||
|
41
src/entrypoint.sh
Normal file
41
src/entrypoint.sh
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
echo "Starting the WireGuard Dashboard Docker container."
|
||||||
|
|
||||||
|
clean_up() {
|
||||||
|
# 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..."
|
||||||
|
if [ -f "/opt/wireguarddashboard/app/src/gunicorn.pid" ]; then
|
||||||
|
echo "Found old .pid file, removing."
|
||||||
|
rm /opt/wireguarddashboard/app/src/gunicorn.pid
|
||||||
|
else
|
||||||
|
echo "No remains found, continuing."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ensure_blocking() {
|
||||||
|
sleep 1s
|
||||||
|
echo "Ensuring container continuation."
|
||||||
|
|
||||||
|
# This function checks if the latest error log is created and tails it for docker logs uses.
|
||||||
|
if find "/home/app/wireguarddashboard/app/log" -mindepth 1 -maxdepth 1 -type f | read -r; then
|
||||||
|
latestErrLog=$(find /home/app/wireguarddashboard/app/log -name "error_*.log" | head -n 1)
|
||||||
|
latestAccLog=$(find /home/app/wireguarddashboard/app/log -name "access_*.log" | head -n 1)
|
||||||
|
tail -f "${latestErrLog}" "${latestAccLog}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Blocking command in case of erroring. So the container does not quit.
|
||||||
|
sleep infinity
|
||||||
|
}
|
||||||
|
|
||||||
|
# Execute functions for the WireGuard Dashboard services, then set the environment variables
|
||||||
|
clean_up
|
||||||
|
|
||||||
|
chmod u+x /home/app/wgd.sh
|
||||||
|
if [ ! -f "/home/app/wg-dashboard.ini" ]; then
|
||||||
|
/home/app/wgd.sh install
|
||||||
|
|
||||||
|
fi
|
||||||
|
/home/app/wgd.sh start
|
||||||
|
ensure_blocking
|
Loading…
Reference in New Issue
Block a user