mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-08-27 23:41:14 +00:00
Merge branch 'main' into v4.1-dev
This commit is contained in:
@@ -1500,7 +1500,9 @@ def _regexMatch(regex, text):
|
||||
return pattern.search(text) is not None
|
||||
|
||||
def _getConfigurationList(startup: bool = False):
|
||||
for i in os.listdir(DashboardConfig.GetConfig("Server", "wg_conf_path")[1]):
|
||||
confs = os.listdir(DashboardConfig.GetConfig("Server", "wg_conf_path")[1])
|
||||
confs.sort()
|
||||
for i in confs:
|
||||
if _regexMatch("^(.{1,}).(conf)$", i):
|
||||
i = i.replace('.conf', '')
|
||||
try:
|
||||
@@ -1618,8 +1620,11 @@ def sqlSelect(statement: str, paramters: tuple = ()) -> sqlite3.Cursor:
|
||||
try:
|
||||
cursor = sqldb.cursor()
|
||||
return cursor.execute(statement, paramters)
|
||||
|
||||
except sqlite3.OperationalError as error:
|
||||
print("[WGDashboard] SQLite Error:" + str(error) + " | Statement: " + statement)
|
||||
return []
|
||||
|
||||
|
||||
def sqlUpdate(statement: str, paramters: tuple = ()) -> sqlite3.Cursor:
|
||||
with sqldb:
|
||||
|
@@ -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
|
@@ -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
|
206
src/wgd.sh
206
src/wgd.sh
@@ -66,7 +66,7 @@ _determineOS(){
|
||||
elif [ -f /etc/redhat-release ]; then
|
||||
OS="redhat"
|
||||
else
|
||||
printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS." "$heavy_crossmark"
|
||||
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
|
||||
@@ -78,7 +78,7 @@ _installPython(){
|
||||
ubuntu|debian)
|
||||
{ sudo apt update ; sudo apt-get install -y python3 net-tools; printf "\n\n"; } &>> ./log/install.txt
|
||||
;;
|
||||
centos|fedora|redhat|rehl)
|
||||
centos|fedora|redhat|rhel|almalinux|rocky)
|
||||
if command -v dnf &> /dev/null; then
|
||||
{ sudo dnf install -y python3 net-tools; printf "\n\n"; } >> ./log/install.txt
|
||||
else
|
||||
@@ -86,8 +86,8 @@ _installPython(){
|
||||
fi
|
||||
;;
|
||||
alpine)
|
||||
{ apk update; apk add python3 net-tools; printf "\n\n"; } &>> ./log/install.txt
|
||||
;;
|
||||
{ sudo apk update; sudo apk add python3 net-tools --no-cache; printf "\n\n"; } >> ./log/install.txt
|
||||
;;
|
||||
esac
|
||||
|
||||
if ! python3 --version > /dev/null 2>&1
|
||||
@@ -106,7 +106,7 @@ _installPythonVenv(){
|
||||
ubuntu|debian)
|
||||
{ sudo apt update ; sudo apt-get install -y python3-venv; printf "\n\n"; } &>> ./log/install.txt
|
||||
;;
|
||||
centos|fedora|redhat|rhel)
|
||||
centos|fedora|redhat|rhel|almalinux|rocky)
|
||||
if command -v dnf &> /dev/null; then
|
||||
{ sudo dnf install -y python3-virtualenv; printf "\n\n"; } >> ./log/install.txt
|
||||
else
|
||||
@@ -114,10 +114,10 @@ _installPythonVenv(){
|
||||
fi
|
||||
;;
|
||||
alpine)
|
||||
{ apk add python3 py3-virtualenv; printf "\n\n"; } &>> ./log/install.txt
|
||||
{ sudo apk update; sudo apk add py3-virtualenv ; printf "\n\n"; } >> ./log/install.txt
|
||||
;;
|
||||
*)
|
||||
printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS.\n" "$heavy_crossmark"
|
||||
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
|
||||
;;
|
||||
@@ -140,7 +140,6 @@ _installPythonVenv(){
|
||||
}
|
||||
|
||||
_installPythonPip(){
|
||||
|
||||
if ! $pythonExecutable -m pip -h > /dev/null 2>&1
|
||||
then
|
||||
case "$OS" in
|
||||
@@ -151,7 +150,7 @@ _installPythonPip(){
|
||||
{ sudo apt update ; sudo apt-get install -y ${pythonExecutable}-distutil python3-pip; printf "\n\n"; } &>> ./log/install.txt
|
||||
fi
|
||||
;;
|
||||
centos|fedora|redhat|rhel)
|
||||
centos|fedora|redhat|rhel|almalinux|rocky)
|
||||
if [ "$pythonExecutable" = "python3" ]; then
|
||||
{ sudo dnf install -y python3-pip; printf "\n\n"; } >> ./log/install.txt
|
||||
else
|
||||
@@ -159,10 +158,10 @@ _installPythonPip(){
|
||||
fi
|
||||
;;
|
||||
alpine)
|
||||
{ apk add py3-pip; printf "\n\n"; } &>> ./log/install.txt
|
||||
{ sudo apk update; sudo apk add py3-pip --no-cache; printf "\n\n"; } >> ./log/install.txt
|
||||
;;
|
||||
*)
|
||||
printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS.\n" "$heavy_crossmark"
|
||||
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
|
||||
;;
|
||||
@@ -180,20 +179,41 @@ _installPythonPip(){
|
||||
}
|
||||
|
||||
_checkWireguard(){
|
||||
if ! wg -h > /dev/null 2>&1
|
||||
then
|
||||
printf "[WGDashboard] %s WireGuard is not installed. Please follow instruction on https://www.wireguard.com/install/ to install. \n" "$heavy_crossmark"
|
||||
kill $TOP_PID
|
||||
fi
|
||||
if ! wg-quick -h > /dev/null 2>&1
|
||||
then
|
||||
printf "[WGDashboard] %s WireGuard is not installed. Please follow instruction on https://www.wireguard.com/install/ to install. \n" "$heavy_crossmark"
|
||||
kill $TOP_PID
|
||||
fi
|
||||
if ! command -v wg > /dev/null 2>&1 || ! command -v wg-quick > /dev/null 2>&1
|
||||
then
|
||||
case "$OS" in
|
||||
ubuntu|debian)
|
||||
{
|
||||
sudo apt update && sudo apt-get install -y wireguard;
|
||||
printf "\n[WGDashboard] WireGuard installed on %s.\n\n" "$OS";
|
||||
} &>> ./log/install.txt
|
||||
;;
|
||||
centos|fedora|redhat|rhel|almalinux|rocky)
|
||||
{
|
||||
sudo dnf install -y wireguard-tools;
|
||||
printf "\n[WGDashboard] WireGuard installed on %s.\n\n" "$OS";
|
||||
} &>> ./log/install.txt
|
||||
;;
|
||||
alpine)
|
||||
{
|
||||
sudo apk update && sudo apk add wireguard-tools --no-cache;
|
||||
printf "\n[WGDashboard] WireGuard installed on %s.\n\n" "$OS";
|
||||
} &>> ./log/install.txt
|
||||
;;
|
||||
*)
|
||||
printf "[WGDashboard] %s Sorry, your OS is not supported. Currently, the install script only supports Debian-based, Red Hat-based, and Alpine Linux.\n" "$heavy_crossmark"
|
||||
printf "%s\n" "$helpMsg"
|
||||
kill $TOP_PID
|
||||
;;
|
||||
esac
|
||||
else
|
||||
printf "[WGDashboard] WireGuard is already installed.\n"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
_checkPythonVersion(){
|
||||
version_pass=$($pythonExecutable -c 'import sys; print("1") if (sys.version_info.major == 3 and sys.version_info.minor >= 10) else print("0");')
|
||||
version=$($pythonExecutable --version)
|
||||
@@ -221,8 +241,6 @@ _checkPythonVersion(){
|
||||
|
||||
install_wgd(){
|
||||
printf "[WGDashboard] Starting to install WGDashboard\n"
|
||||
_checkWireguard
|
||||
sudo chmod -R 755 /etc/wireguard/
|
||||
|
||||
if [ ! -d "/etc/wireguard/WGDashboard_Backup" ]
|
||||
then
|
||||
@@ -247,6 +265,8 @@ install_wgd(){
|
||||
_checkPythonVersion
|
||||
_installPythonVenv
|
||||
_installPythonPip
|
||||
_checkWireguard
|
||||
sudo chmod -R 755 /etc/wireguard/
|
||||
|
||||
if [ ! -d "db" ]
|
||||
then
|
||||
@@ -258,7 +278,7 @@ install_wgd(){
|
||||
{ date; python3 -m ensurepip --upgrade; printf "\n\n"; } >> ./log/install.txt
|
||||
{ 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
|
||||
{ date; python3 -m pip install -r requirements.txt ; printf "\n\n"; } >> ./log/install.txt #This all works on the default installation.
|
||||
printf "[WGDashboard] WGDashboard installed successfully!\n"
|
||||
printf "[WGDashboard] Enter ./wgd.sh start to start the dashboard\n"
|
||||
}
|
||||
@@ -336,14 +356,6 @@ startwgd_docker() {
|
||||
}
|
||||
|
||||
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")
|
||||
|
||||
@@ -400,20 +412,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"
|
||||
@@ -422,56 +443,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" = "docker_start" ]; then
|
||||
printf "%s\n" "$dashes"
|
||||
startwgd_docker
|
||||
printf "%s\n" "$dashes"
|
||||
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] WGDashboard is stopped.\n"
|
||||
sleep 4
|
||||
start_wgd
|
||||
else
|
||||
start_wgd
|
||||
fi
|
||||
elif [ "$1" = "debug" ]; then
|
||||
if check_wgd_status; then
|
||||
printf "[WGDashboard] WGDashboard is already running.\n"
|
||||
else
|
||||
start_wgd_debug
|
||||
fi
|
||||
else
|
||||
help
|
||||
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
|
||||
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
|
||||
|
Reference in New Issue
Block a user