mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-06-28 09:16:55 +00:00
Merge pull request #521 from donaldzou/bsd-support
Replace `ifcfg` with socket to get default interface address
This commit is contained in:
commit
94337a33d4
@ -16,7 +16,7 @@ import uuid
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Any
|
from typing import Any
|
||||||
import bcrypt
|
import bcrypt
|
||||||
import ifcfg
|
# import ifcfg
|
||||||
import psutil
|
import psutil
|
||||||
import pyotp
|
import pyotp
|
||||||
from flask import Flask, request, render_template, session, g
|
from flask import Flask, request, render_template, session, g
|
||||||
@ -979,8 +979,7 @@ class WireguardConfiguration:
|
|||||||
return False, str(exc.output.strip().decode("utf-8"))
|
return False, str(exc.output.strip().decode("utf-8"))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
check = subprocess.check_output(f"wg-quick up {self.Name}",
|
check = subprocess.check_output(f"wg-quick up {self.Name}", shell=True, stderr=subprocess.STDOUT)
|
||||||
shell=True, stderr=subprocess.STDOUT)
|
|
||||||
except subprocess.CalledProcessError as exc:
|
except subprocess.CalledProcessError as exc:
|
||||||
return False, str(exc.output.strip().decode("utf-8"))
|
return False, str(exc.output.strip().decode("utf-8"))
|
||||||
self.getStatus()
|
self.getStatus()
|
||||||
@ -1303,6 +1302,15 @@ def regex_match(regex, text):
|
|||||||
pattern = re.compile(regex)
|
pattern = re.compile(regex)
|
||||||
return pattern.search(text) is not None
|
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:
|
class DashboardAPIKey:
|
||||||
def __init__(self, Key: str, CreatedAt: str, ExpiredAt: str):
|
def __init__(self, Key: str, CreatedAt: str, ExpiredAt: str):
|
||||||
self.Key = Key
|
self.Key = Key
|
||||||
@ -1345,7 +1353,7 @@ class DashboardConfig:
|
|||||||
"peer_global_DNS": "1.1.1.1",
|
"peer_global_DNS": "1.1.1.1",
|
||||||
"peer_endpoint_allowed_ip": "0.0.0.0/0",
|
"peer_endpoint_allowed_ip": "0.0.0.0/0",
|
||||||
"peer_display_mode": "grid",
|
"peer_display_mode": "grid",
|
||||||
"remote_endpoint": ifcfg.default_interface()['inet'] if ifcfg.default_interface() else '',
|
"remote_endpoint": get_remote_endpoint(),
|
||||||
"peer_MTU": "1420",
|
"peer_MTU": "1420",
|
||||||
"peer_keep_alive": "21"
|
"peer_keep_alive": "21"
|
||||||
},
|
},
|
||||||
|
44
src/wgd.sh
44
src/wgd.sh
@ -53,30 +53,33 @@ _check_and_set_venv(){
|
|||||||
if ! $venv_python --version > /dev/null 2>&1
|
if ! $venv_python --version > /dev/null 2>&1
|
||||||
then
|
then
|
||||||
printf "[WGDashboard] %s Python Virtual Environment under ./venv failed to create. Halting now.\n" "$heavy_crossmark"
|
printf "[WGDashboard] %s Python Virtual Environment under ./venv failed to create. Halting now.\n" "$heavy_crossmark"
|
||||||
kill $TOP_PID
|
kill $TOP_PID
|
||||||
fi
|
fi
|
||||||
|
|
||||||
. ${VIRTUAL_ENV}/bin/activate
|
. ${VIRTUAL_ENV}/bin/activate
|
||||||
}
|
}
|
||||||
|
|
||||||
_determineOS(){
|
_determineOS(){
|
||||||
if [ -f /etc/os-release ]; then
|
if [ -f /etc/os-release ]; then
|
||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
OS=$ID
|
OS=$ID
|
||||||
elif [ -f /etc/redhat-release ]; then
|
elif [ -f /etc/redhat-release ]; then
|
||||||
OS="redhat"
|
OS="redhat"
|
||||||
else
|
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 "[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"
|
printf "%s\n" "$helpMsg"
|
||||||
kill $TOP_PID
|
kill $TOP_PID
|
||||||
fi
|
fi
|
||||||
printf "[WGDashboard] OS: %s\n" "$OS"
|
printf "[WGDashboard] OS: %s\n" "$OS"
|
||||||
}
|
}
|
||||||
|
|
||||||
_installPython(){
|
_installPython(){
|
||||||
|
|
||||||
|
{ printf "\n\n [Installing Python] [%s] \n\n""$(date)"; } >> ./log/install.txt
|
||||||
|
|
||||||
case "$OS" in
|
case "$OS" in
|
||||||
ubuntu|debian)
|
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)
|
centos|fedora|redhat|rhel|almalinux|rocky)
|
||||||
if command -v dnf &> /dev/null; then
|
if command -v dnf &> /dev/null; then
|
||||||
@ -86,8 +89,8 @@ _installPython(){
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
alpine)
|
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
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if ! python3 --version > /dev/null 2>&1
|
if ! python3 --version > /dev/null 2>&1
|
||||||
@ -101,6 +104,7 @@ _installPython(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
_installPythonVenv(){
|
_installPythonVenv(){
|
||||||
|
{ printf "\n\n [Installing Python Venv] [%s] \n\n""$(date)"; } >> ./log/install.txt
|
||||||
if [ "$pythonExecutable" = "python3" ]; then
|
if [ "$pythonExecutable" = "python3" ]; then
|
||||||
case "$OS" in
|
case "$OS" in
|
||||||
ubuntu|debian)
|
ubuntu|debian)
|
||||||
@ -140,6 +144,7 @@ _installPythonVenv(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
_installPythonPip(){
|
_installPythonPip(){
|
||||||
|
{ printf "\n\n [Installing Python Pip] [%s] \n\n""$(date)"; } >> ./log/install.txt
|
||||||
if ! $pythonExecutable -m pip -h > /dev/null 2>&1
|
if ! $pythonExecutable -m pip -h > /dev/null 2>&1
|
||||||
then
|
then
|
||||||
case "$OS" in
|
case "$OS" in
|
||||||
@ -265,7 +270,7 @@ install_wgd(){
|
|||||||
_checkPythonVersion
|
_checkPythonVersion
|
||||||
_installPythonVenv
|
_installPythonVenv
|
||||||
_installPythonPip
|
_installPythonPip
|
||||||
_checkWireguard
|
_checkWireguard
|
||||||
sudo chmod -R 755 /etc/wireguard/
|
sudo chmod -R 755 /etc/wireguard/
|
||||||
|
|
||||||
if [ ! -d "db" ]
|
if [ ! -d "db" ]
|
||||||
@ -472,7 +477,10 @@ else
|
|||||||
elif [ "$1" = "update" ]; then
|
elif [ "$1" = "update" ]; then
|
||||||
update_wgd
|
update_wgd
|
||||||
elif [ "$1" = "install" ]; then
|
elif [ "$1" = "install" ]; then
|
||||||
printf "%s\n" "$dashes"
|
clear
|
||||||
|
printf "=================================================================================\n"
|
||||||
|
printf "+ <WGDashboard> by Donald Zou - https://github.com/donaldzou +\n"
|
||||||
|
printf "=================================================================================\n"
|
||||||
install_wgd
|
install_wgd
|
||||||
printf "%s\n" "$dashes"
|
printf "%s\n" "$dashes"
|
||||||
elif [ "$1" = "restart" ]; then
|
elif [ "$1" = "restart" ]; then
|
||||||
@ -491,6 +499,8 @@ else
|
|||||||
else
|
else
|
||||||
start_wgd_debug
|
start_wgd_debug
|
||||||
fi
|
fi
|
||||||
|
elif [ "$1" = "os" ]; then
|
||||||
|
_determineOS
|
||||||
else
|
else
|
||||||
help
|
help
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user