From 0c5033ff79d9d031138b5997cc592021de95b87c Mon Sep 17 00:00:00 2001 From: Dselen Date: Thu, 3 Oct 2024 08:23:17 -0500 Subject: [PATCH] fixed issues with commits --- docker/README.md | 2 -- docker/alpine/builder.sh | 43 ---------------------------------- docker/alpine/requirements.txt | 2 -- entrypoint.sh | 2 +- src/entrypoint.sh | 34 --------------------------- src/iptable-rules/postdown.sh | 13 ---------- src/iptable-rules/postup.sh | 26 -------------------- src/wgd.sh | 33 -------------------------- 8 files changed, 1 insertion(+), 154 deletions(-) delete mode 100644 docker/alpine/builder.sh delete mode 100644 docker/alpine/requirements.txt delete mode 100644 src/entrypoint.sh delete mode 100644 src/iptable-rules/postdown.sh delete mode 100644 src/iptable-rules/postup.sh diff --git a/docker/README.md b/docker/README.md index e31933e..2160e7e 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,5 +1,4 @@ # WGDashboard Docker Explanation: - Author: DaanSelen
This document delves into how the WGDashboard Docker container has been built.
@@ -100,7 +99,6 @@ dselen/wgdashboard latest c96fd96ee3b3 42 minutes ago 314MB ## Closing remarks: -Excuse the large image size, whoops! Debian's big... sometimes.
For feedback please submit an issue to the repository. Or message dselen@nerthus.nl. ## In Progress: diff --git a/docker/alpine/builder.sh b/docker/alpine/builder.sh deleted file mode 100644 index 5511413..0000000 --- a/docker/alpine/builder.sh +++ /dev/null @@ -1,43 +0,0 @@ -venv_python="./venv/bin/python3" -venv_gunicorn="./venv/bin/gunicorn" -pythonExecutable="python3" - - -_check_and_set_venv(){ - VIRTUAL_ENV="./venv" - if [ ! -d $VIRTUAL_ENV ]; then - printf "[WGDashboard] Creating Python Virtual Environment under ./venv\n" - { $pythonExecutable -m venv $VIRTUAL_ENV; } >> ./log/install.txt - fi - - if ! $venv_python --version > /dev/null 2>&1 - then - printf "[WGDashboard] %s Python Virtual Environment under ./venv failed to create. Halting now.\n" "$heavy_crossmark" - kill $TOP_PID - fi - - source ${VIRTUAL_ENV}/bin/activate - -} - -build_core () { - if [ ! -d "log" ] - then - printf "[WGDashboard] Creating ./log folder\n" - mkdir "log" - fi - - - apk add --no-cache python3 net-tools python3-dev py3-virtualenv - _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] Building Bcrypt & Psutil\n" - { date; python3 -m pip install -r requirements.txt ; printf "\n\n"; } >> ./log/install.txt - printf "[WGDashboard] Build Successfull!\n" - printf "[WGDashboard] Clean Up Pip!\n" - { date; rm -rf /opt/wireguarddashboard/src/venv/lib/python3.12/site-packages/pip* ; printf "\n\n"; } >> ./log/install.txt - -} - -build_core diff --git a/docker/alpine/requirements.txt b/docker/alpine/requirements.txt deleted file mode 100644 index 074ed2f..0000000 --- a/docker/alpine/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -bcrypt -psutil diff --git a/entrypoint.sh b/entrypoint.sh index e9e6afa..bf5e20c 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -31,7 +31,7 @@ ensure_installation() { # 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 - echo "Standard wg0 Configuration file not found, grabbing template. And adjusting permissions." + echo "Standard wg0 Configuration file not found, grabbing template." cp -a "/setup/conf/wg0.conf" "/etc/wireguard/wg0.conf" echo "Setting a secure private key." diff --git a/src/entrypoint.sh b/src/entrypoint.sh deleted file mode 100644 index c8056f2..0000000 --- a/src/entrypoint.sh +++ /dev/null @@ -1,34 +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 -} -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/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) - tail -f "${latestErrLog}" "${latestAccLog}" - fi - - # Blocking command in case of erroring. So the container does not quit. - sleep infinity -} - -{ date; clean_up; printf "\n\n"; } >> ./log/install.txt - -chmod u+x /opt/wireguarddashboard/src/wgd.sh -/opt/wireguarddashboard/src/wgd.sh install -/opt/wireguarddashboard/src/wgd.sh docker_start -ensure_blocking diff --git a/src/iptable-rules/postdown.sh b/src/iptable-rules/postdown.sh deleted file mode 100644 index 962772a..0000000 --- a/src/iptable-rules/postdown.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -WIREGUARD_INTERFACE=ADMINS -WIREGUARD_LAN=10.0.0.1/24 -MASQUERADE_INTERFACE=eth0 - -CHAIN_NAME="WIREGUARD_$WIREGUARD_INTERFACE" - -iptables -t nat -D POSTROUTING -o $MASQUERADE_INTERFACE -j MASQUERADE -s $WIREGUARD_LAN - -# Remove and delete the WIREGUARD_wg0 chain -iptables -D FORWARD -j $CHAIN_NAME -iptables -F $CHAIN_NAME -iptables -X $CHAIN_NAME \ No newline at end of file diff --git a/src/iptable-rules/postup.sh b/src/iptable-rules/postup.sh deleted file mode 100644 index 0fc8b87..0000000 --- a/src/iptable-rules/postup.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -WIREGUARD_INTERFACE=ADMINS -WIREGUARD_LAN=10.0.0.1/24 -MASQUERADE_INTERFACE=eth0 - -iptables -t nat -I POSTROUTING -o $MASQUERADE_INTERFACE -j MASQUERADE -s $WIREGUARD_LAN - -# Add a WIREGUARD_wg0 chain to the FORWARD chain -CHAIN_NAME="WIREGUARD_$WIREGUARD_INTERFACE" -iptables -N $CHAIN_NAME -iptables -A FORWARD -j $CHAIN_NAME - -# Accept related or established traffic -iptables -A $CHAIN_NAME -o $WIREGUARD_INTERFACE -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT - -# Accept traffic from any Wireguard IP address connected to the Wireguard server -iptables -A $CHAIN_NAME -s $WIREGUARD_LAN -i $WIREGUARD_INTERFACE -j ACCEPT - -# Allow traffic to the local loopback interface -iptables -A $CHAIN_NAME -o lo -j ACCEPT - -# Drop everything else coming through the Wireguard interface -iptables -A $CHAIN_NAME -i $WIREGUARD_INTERFACE -j DROP - -# Return to FORWARD chain -iptables -A $CHAIN_NAME -j RETURN \ No newline at end of file diff --git a/src/wgd.sh b/src/wgd.sh index d080e70..8e4db79 100755 --- a/src/wgd.sh +++ b/src/wgd.sh @@ -341,22 +341,7 @@ stop_wgd() { fi } -startwgd_docker() { - _checkWireguard - printf "[WGDashboard][Docker] WireGuard configuration started\n" - { date; start_core ; printf "\n\n"; } >> ./log/install.txt - gunicorn_start -} - start_core() { - local iptable_dir="/opt/wireguarddashboard/src/iptable-rules" - # Check if wg0.conf exists in /etc/wireguard - if [[ ! -f /etc/wireguard/wg0.conf ]]; then - echo "[WGDashboard][Docker] wg0.conf not found. Running generate configuration." - newconf_wgd - else - echo "[WGDashboard][Docker] wg0.conf already exists. Skipping WireGuard configuration generation." - fi # Re-assign config_files to ensure it includes any newly created configurations local config_files=$(find /etc/wireguard -type f -name "*.conf") @@ -371,24 +356,6 @@ start_core() { done } - - -newconf_wgd() { - local wg_port_listen=$wg_port - local wg_addr_range=$wg_net - private_key=$(wg genkey) - public_key=$(echo "$private_key" | wg pubkey) - cat <"/etc/wireguard/wg0.conf" -[Interface] -PrivateKey = $private_key -Address = $wg_addr_range -ListenPort = $wg_port_listen -SaveConfig = true -PostUp = /opt/wireguarddashboard/src/iptable-rules/postup.sh -PreDown = /opt/wireguarddashboard/src/iptable-rules/postdown.sh -EOF -} - start_wgd_debug() { printf "%s\n" "$dashes" _checkWireguard