From 3ef4798e09ef51fd6e960b1d12e23c752d66c345 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Tue, 12 Nov 2024 00:12:10 +0800 Subject: [PATCH 1/9] Update wgd.sh --- src/wgd.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/wgd.sh b/src/wgd.sh index 22e1d25..ac75b63 100755 --- a/src/wgd.sh +++ b/src/wgd.sh @@ -65,6 +65,8 @@ _determineOS(){ OS=$ID elif [ -f /etc/redhat-release ]; then OS="redhat" + elif [ "$(uname)" = "OpenBSD" ]; then + OS="openbsd" else printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" "$heavy_crossmark" printf "%s\n" "$helpMsg" @@ -491,6 +493,8 @@ else else start_wgd_debug fi + elif [ "$1" = "os" ]; then + _determineOS else help fi From e963788a81d01af4519dccc2c6a812b546cf2cf0 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Tue, 12 Nov 2024 17:58:51 +0800 Subject: [PATCH 2/9] Update wgd.sh --- src/wgd.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/wgd.sh b/src/wgd.sh index ac75b63..2714725 100755 --- a/src/wgd.sh +++ b/src/wgd.sh @@ -60,19 +60,19 @@ _check_and_set_venv(){ } _determineOS(){ - if [ -f /etc/os-release ]; then - . /etc/os-release - OS=$ID - elif [ -f /etc/redhat-release ]; then - OS="redhat" - elif [ "$(uname)" = "OpenBSD" ]; then - OS="openbsd" - else - printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" "$heavy_crossmark" - printf "%s\n" "$helpMsg" - kill $TOP_PID - fi - printf "[WGDashboard] OS: %s\n" "$OS" + if [ -f /etc/os-release ]; then + . /etc/os-release + OS=$ID + elif [ -f /etc/redhat-release ]; then + OS="redhat" + elif [ "$(uname)" = "OpenBSD" ] && [ "$(uname)" = "7.6" ]; then + OS="openbsd" + else + printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" "$heavy_crossmark" + printf "%s\n" "$helpMsg" + kill $TOP_PID + fi + printf "[WGDashboard] OS: %s\n" "$OS" } _installPython(){ @@ -267,7 +267,7 @@ install_wgd(){ _checkPythonVersion _installPythonVenv _installPythonPip - _checkWireguard + _checkWireguard sudo chmod -R 755 /etc/wireguard/ if [ ! -d "db" ] From b61c9bfc5ebc3a6241ad056a057afd6785421e40 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Tue, 12 Nov 2024 18:01:59 +0800 Subject: [PATCH 3/9] Update wgd.sh --- src/wgd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wgd.sh b/src/wgd.sh index 2714725..999a4b8 100755 --- a/src/wgd.sh +++ b/src/wgd.sh @@ -65,7 +65,7 @@ _determineOS(){ OS=$ID elif [ -f /etc/redhat-release ]; then OS="redhat" - elif [ "$(uname)" = "OpenBSD" ] && [ "$(uname)" = "7.6" ]; then + elif [ "$(uname)" = "OpenBSD" ] && [ "$(uname -r)" = "7.6" ]; then OS="openbsd" else printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" "$heavy_crossmark" From b37d889de9a1286665c2e46212d70fb823abad39 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Tue, 12 Nov 2024 18:21:27 +0800 Subject: [PATCH 4/9] Update wgd.sh --- src/wgd.sh | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/wgd.sh b/src/wgd.sh index 999a4b8..4112f6a 100755 --- a/src/wgd.sh +++ b/src/wgd.sh @@ -53,7 +53,7 @@ _check_and_set_venv(){ 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 + kill $TOP_PID fi . ${VIRTUAL_ENV}/bin/activate @@ -65,7 +65,7 @@ _determineOS(){ OS=$ID elif [ -f /etc/redhat-release ]; then OS="redhat" - elif [ "$(uname)" = "OpenBSD" ] && [ "$(uname -r)" = "7.6" ]; then + elif [ "$(uname)" = "OpenBSD" ]; then OS="openbsd" else printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" "$heavy_crossmark" @@ -88,8 +88,21 @@ _installPython(){ fi ;; alpine) - { sudo apk update; sudo apk add python3 net-tools --no-cache; printf "\n\n"; } >> ./log/install.txt - ;; + { sudo apk update; sudo apk add python3 net-tools --no-cache; printf "\n\n"; } >> ./log/install.txt + ;; + openbsd) + if [ "$(uname -r)" = "7.6" ]; then + { pkg_add -v python-3.11.10p0; printf "\n\n"; } >> ./log/install.txt + elif [ "$(uname -r)" = "7.5" ]; then + { pkg_add -v python-3.11.8; printf "\n\n"; } >> ./log/install.txt + elif [ "$(uname -r)" = "7.4" ]; then + { pkg_add -v python-3.11.5; printf "\n\n"; } >> ./log/install.txt + else + printf "[WGDashboard] %s Current OpenBSD version is not supported. Please install Python 3.10+ manually\n" "$heavy_crossmark" + printf "%s\n" "$helpMsg" + kill $TOP_PID + fi + ;; esac if ! python3 --version > /dev/null 2>&1 @@ -474,7 +487,10 @@ else elif [ "$1" = "update" ]; then update_wgd elif [ "$1" = "install" ]; then - printf "%s\n" "$dashes" + clear + printf "=================================================================================\n" + printf "+ by Donald Zou - https://github.com/donaldzou +\n" + printf "=================================================================================\n" install_wgd printf "%s\n" "$dashes" elif [ "$1" = "restart" ]; then From e1e147c8f051a8131fda1f7163462b6039ccde4a Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Tue, 12 Nov 2024 18:32:53 +0800 Subject: [PATCH 5/9] Adding support to OpenBSD --- src/wgd.sh | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/wgd.sh b/src/wgd.sh index 4112f6a..a598f93 100755 --- a/src/wgd.sh +++ b/src/wgd.sh @@ -76,9 +76,12 @@ _determineOS(){ } _installPython(){ + + { printf "\n\n [Installing Python] [%s] \n\n""$(date)"; } >> ./log/install.txt + case "$OS" in ubuntu|debian) - { sudo apt update ; sudo apt-get install -y python3 net-tools; printf "\n\n"; } &>> ./log/install.txt + { sudo apt update ; sudo apt-get install -y python3 net-tools; printf "\n\n"; } >> ./log/install.txt ;; centos|fedora|redhat|rhel|almalinux|rocky) if command -v dnf &> /dev/null; then @@ -116,6 +119,7 @@ _installPython(){ } _installPythonVenv(){ + { printf "\n\n [Installing Python Venv] [%s] \n\n""$(date)"; } >> ./log/install.txt if [ "$pythonExecutable" = "python3" ]; then case "$OS" in ubuntu|debian) @@ -131,6 +135,19 @@ _installPythonVenv(){ alpine) { sudo apk update; sudo apk add py3-virtualenv ; printf "\n\n"; } >> ./log/install.txt ;; + openbsd) + if [ "$(uname -r)" = "7.4" ]; then + { pkg_add -v py3-virtualenv-20.24.4; printf "\n\n"; } >> ./log/install.txt + elif [ "$(uname -r)" = "7.5" ]; then + { pkg_add -v py3-virtualenv-20.25.1; printf "\n\n"; } >> ./log/install.txt + elif [ "$(uname -r)" = "7.6" ]; then + { pkg_add -v py3-virtualenv-20.25.3; printf "\n\n"; } >> ./log/install.txt + else + printf "[WGDashboard] %s Current OpenBSD version is not supported. Please install Python 3 Virtual Environment manually\n" "$heavy_crossmark" + printf "%s\n" "$helpMsg" + kill $TOP_PID + fi + ;; *) printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" "$heavy_crossmark" printf "%s\n" "$helpMsg" @@ -155,6 +172,7 @@ _installPythonVenv(){ } _installPythonPip(){ + { printf "\n\n [Installing Python Pip] [%s] \n\n""$(date)"; } >> ./log/install.txt if ! $pythonExecutable -m pip -h > /dev/null 2>&1 then case "$OS" in @@ -175,6 +193,19 @@ _installPythonPip(){ alpine) { sudo apk update; sudo apk add py3-pip --no-cache; printf "\n\n"; } >> ./log/install.txt ;; + openbsd) + if [ "$(uname -r)" = "7.4" ]; then + { pkg_add -v py3-pip-23.2.1; printf "\n\n"; } >> ./log/install.txt + elif [ "$(uname -r)" = "7.5" ]; then + { pkg_add -v py3-pip-24.0; printf "\n\n"; } >> ./log/install.txt + elif [ "$(uname -r)" = "7.6" ]; then + { pkg_add -v py3-pip-24.2; printf "\n\n"; } >> ./log/install.txt + else + printf "[WGDashboard] %s Current OpenBSD version is not supported. Please install Python 3 Pip manually\n" "$heavy_crossmark" + printf "%s\n" "$helpMsg" + kill $TOP_PID + fi + ;; *) printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" "$heavy_crossmark" printf "%s\n" "$helpMsg" From 45fbbf921897ab52b35f17286042b5483ef0f645 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Sat, 23 Nov 2024 17:30:22 +0800 Subject: [PATCH 6/9] Update dashboard.py --- src/dashboard.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/dashboard.py b/src/dashboard.py index 2519991..0adb1cf 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -1303,6 +1303,15 @@ def regex_match(regex, text): pattern = re.compile(regex) return pattern.search(text) is not None +def get_remote_endpoint(): + # Thanks @NOXICS + import socket + + with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: + s.connect(("1.1.1.1", 80)) # Connecting to a public IP + wgd_remote_endpoint = s.getsockname()[0] + return str(wgd_remote_endpoint) + class DashboardAPIKey: def __init__(self, Key: str, CreatedAt: str, ExpiredAt: str): self.Key = Key @@ -1345,7 +1354,7 @@ class DashboardConfig: "peer_global_DNS": "1.1.1.1", "peer_endpoint_allowed_ip": "0.0.0.0/0", "peer_display_mode": "grid", - "remote_endpoint": ifcfg.default_interface()['inet'] if ifcfg.default_interface() else '', + "remote_endpoint": get_remote_endpoint(), "peer_MTU": "1420", "peer_keep_alive": "21" }, From 597528e9b7d160d3515c02762717762dc2b8b519 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Sat, 23 Nov 2024 17:30:34 +0800 Subject: [PATCH 7/9] Update dashboard.py --- src/dashboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dashboard.py b/src/dashboard.py index 0adb1cf..1d23333 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -16,7 +16,7 @@ import uuid from datetime import datetime, timedelta from typing import Any import bcrypt -import ifcfg +# import ifcfg import psutil import pyotp from flask import Flask, request, render_template, session, g From 71ee784003b365b81f0752939564b719ddcfe503 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Sat, 23 Nov 2024 17:51:48 +0800 Subject: [PATCH 8/9] Update dashboard.py --- src/dashboard.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index 1d23333..d057ec5 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -973,14 +973,13 @@ class WireguardConfiguration: self.getStatus() if self.Status: try: - check = subprocess.check_output(f"wg-quick down {self.Name}", + check = subprocess.call(f"wg-quick down {self.Name}", shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as exc: return False, str(exc.output.strip().decode("utf-8")) else: try: - check = subprocess.check_output(f"wg-quick up {self.Name}", - shell=True, stderr=subprocess.STDOUT) + check = subprocess.call(f"wg-quick up {self.Name}", shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as exc: return False, str(exc.output.strip().decode("utf-8")) self.getStatus() From 8e2934533ba5f783180bb794147fc61e2569bcf1 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Sat, 23 Nov 2024 18:08:14 +0800 Subject: [PATCH 9/9] Dropping support plan to OpenBSD --- src/dashboard.py | 4 ++-- src/wgd.sh | 41 ----------------------------------------- 2 files changed, 2 insertions(+), 43 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index d057ec5..120d286 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -973,13 +973,13 @@ class WireguardConfiguration: self.getStatus() if self.Status: try: - check = subprocess.call(f"wg-quick down {self.Name}", + check = subprocess.check_output(f"wg-quick down {self.Name}", shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as exc: return False, str(exc.output.strip().decode("utf-8")) else: try: - check = subprocess.call(f"wg-quick up {self.Name}", shell=True, stderr=subprocess.STDOUT) + check = subprocess.check_output(f"wg-quick up {self.Name}", shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as exc: return False, str(exc.output.strip().decode("utf-8")) self.getStatus() diff --git a/src/wgd.sh b/src/wgd.sh index a598f93..04c1c8d 100755 --- a/src/wgd.sh +++ b/src/wgd.sh @@ -65,8 +65,6 @@ _determineOS(){ OS=$ID elif [ -f /etc/redhat-release ]; then OS="redhat" - elif [ "$(uname)" = "OpenBSD" ]; then - OS="openbsd" else printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" "$heavy_crossmark" printf "%s\n" "$helpMsg" @@ -93,19 +91,6 @@ _installPython(){ alpine) { sudo apk update; sudo apk add python3 net-tools --no-cache; printf "\n\n"; } >> ./log/install.txt ;; - openbsd) - if [ "$(uname -r)" = "7.6" ]; then - { pkg_add -v python-3.11.10p0; printf "\n\n"; } >> ./log/install.txt - elif [ "$(uname -r)" = "7.5" ]; then - { pkg_add -v python-3.11.8; printf "\n\n"; } >> ./log/install.txt - elif [ "$(uname -r)" = "7.4" ]; then - { pkg_add -v python-3.11.5; printf "\n\n"; } >> ./log/install.txt - else - printf "[WGDashboard] %s Current OpenBSD version is not supported. Please install Python 3.10+ manually\n" "$heavy_crossmark" - printf "%s\n" "$helpMsg" - kill $TOP_PID - fi - ;; esac if ! python3 --version > /dev/null 2>&1 @@ -135,19 +120,6 @@ _installPythonVenv(){ alpine) { sudo apk update; sudo apk add py3-virtualenv ; printf "\n\n"; } >> ./log/install.txt ;; - openbsd) - if [ "$(uname -r)" = "7.4" ]; then - { pkg_add -v py3-virtualenv-20.24.4; printf "\n\n"; } >> ./log/install.txt - elif [ "$(uname -r)" = "7.5" ]; then - { pkg_add -v py3-virtualenv-20.25.1; printf "\n\n"; } >> ./log/install.txt - elif [ "$(uname -r)" = "7.6" ]; then - { pkg_add -v py3-virtualenv-20.25.3; printf "\n\n"; } >> ./log/install.txt - else - printf "[WGDashboard] %s Current OpenBSD version is not supported. Please install Python 3 Virtual Environment manually\n" "$heavy_crossmark" - printf "%s\n" "$helpMsg" - kill $TOP_PID - fi - ;; *) printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" "$heavy_crossmark" printf "%s\n" "$helpMsg" @@ -193,19 +165,6 @@ _installPythonPip(){ alpine) { sudo apk update; sudo apk add py3-pip --no-cache; printf "\n\n"; } >> ./log/install.txt ;; - openbsd) - if [ "$(uname -r)" = "7.4" ]; then - { pkg_add -v py3-pip-23.2.1; printf "\n\n"; } >> ./log/install.txt - elif [ "$(uname -r)" = "7.5" ]; then - { pkg_add -v py3-pip-24.0; printf "\n\n"; } >> ./log/install.txt - elif [ "$(uname -r)" = "7.6" ]; then - { pkg_add -v py3-pip-24.2; printf "\n\n"; } >> ./log/install.txt - else - printf "[WGDashboard] %s Current OpenBSD version is not supported. Please install Python 3 Pip manually\n" "$heavy_crossmark" - printf "%s\n" "$helpMsg" - kill $TOP_PID - fi - ;; *) printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" "$heavy_crossmark" printf "%s\n" "$helpMsg"