mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-07-05 20:56:57 +00:00
HTTPS workflow
This commit is contained in:
parent
4524a55b23
commit
e012e94901
@ -1,15 +1,15 @@
|
|||||||
import dashboard
|
import os.path
|
||||||
|
|
||||||
|
import dashboard, configparser
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
global sqldb, cursor, DashboardConfig, WireguardConfigurations, AllPeerJobs, JobLogger
|
global sqldb, cursor, DashboardConfig, WireguardConfigurations, AllPeerJobs, JobLogger
|
||||||
app_host, app_port = dashboard.gunicornConfig()
|
app_host, app_port = dashboard.gunicornConfig()
|
||||||
date = datetime.today().strftime('%Y_%m_%d_%H_%M_%S')
|
date = datetime.today().strftime('%Y_%m_%d_%H_%M_%S')
|
||||||
|
|
||||||
|
|
||||||
def post_worker_init(worker):
|
def post_worker_init(worker):
|
||||||
dashboard.startThreads()
|
dashboard.startThreads()
|
||||||
|
|
||||||
|
|
||||||
worker_class = 'gthread'
|
worker_class = 'gthread'
|
||||||
workers = 1
|
workers = 1
|
||||||
threads = 1
|
threads = 1
|
||||||
@ -21,6 +21,19 @@ accesslog = f"./log/access_{date}.log"
|
|||||||
log_level = "debug"
|
log_level = "debug"
|
||||||
capture_output = True
|
capture_output = True
|
||||||
errorlog = f"./log/error_{date}.log"
|
errorlog = f"./log/error_{date}.log"
|
||||||
|
|
||||||
|
if os.path.exists("./ssl.ini"):
|
||||||
|
sslConfig = configparser.ConfigParser()
|
||||||
|
sslConfig.read_file(open('./ssl.ini', 'r'))
|
||||||
|
if sslConfig.has_section('SSL'):
|
||||||
|
cert = sslConfig.get('SSL', 'certificate_path')
|
||||||
|
pem = sslConfig.get('SSL', 'private_key_path')
|
||||||
|
if cert and pem and len(cert) > 0 and len(pem) > 0:
|
||||||
|
certfile = cert
|
||||||
|
keyfile = pem
|
||||||
|
print(f"[WGDashboard] HTTPS enable", flush=True)
|
||||||
|
|
||||||
|
|
||||||
print(f"[WGDashboard] WGDashboard w/ Gunicorn will be running on {bind}", flush=True)
|
print(f"[WGDashboard] WGDashboard w/ Gunicorn will be running on {bind}", flush=True)
|
||||||
print(f"[WGDashboard] Access log file is at {accesslog}", flush=True)
|
print(f"[WGDashboard] Access log file is at {accesslog}", flush=True)
|
||||||
print(f"[WGDashboard] Error log file is at {errorlog}", flush=True)
|
print(f"[WGDashboard] Error log file is at {errorlog}", flush=True)
|
||||||
|
45
src/wgd.sh
45
src/wgd.sh
@ -11,8 +11,9 @@ venv_python="./venv/bin/python3"
|
|||||||
venv_gunicorn="./venv/bin/gunicorn"
|
venv_gunicorn="./venv/bin/gunicorn"
|
||||||
pythonExecutable="python3"
|
pythonExecutable="python3"
|
||||||
|
|
||||||
heavy_checkmark=$(printf "\xE2\x9C\x94")
|
heavy_checkmark=$(printf "\xE2\x9C\x85")
|
||||||
heavy_crossmark=$(printf "\xE2\x9C\x97")
|
heavy_crossmark=$(printf "\xE2\x9D\x8C")
|
||||||
|
install=$(printf "\xF0\x9F\x92\xBF")
|
||||||
|
|
||||||
PID_FILE=./gunicorn.pid
|
PID_FILE=./gunicorn.pid
|
||||||
environment=$(if [[ $ENVIRONMENT ]]; then echo $ENVIRONMENT; else echo 'develop'; fi)
|
environment=$(if [[ $ENVIRONMENT ]]; then echo $ENVIRONMENT; else echo 'develop'; fi)
|
||||||
@ -46,7 +47,7 @@ help () {
|
|||||||
_check_and_set_venv(){
|
_check_and_set_venv(){
|
||||||
VIRTUAL_ENV="./venv"
|
VIRTUAL_ENV="./venv"
|
||||||
if [ ! -d $VIRTUAL_ENV ]; then
|
if [ ! -d $VIRTUAL_ENV ]; then
|
||||||
printf "[WGDashboard] Creating Python Virtual Environment under ./venv\n"
|
printf "[WGDashboard] %s Creating Python Virtual Environment under ./venv\n" "$install"
|
||||||
{ $pythonExecutable -m venv $VIRTUAL_ENV; } >> ./log/install.txt
|
{ $pythonExecutable -m venv $VIRTUAL_ENV; } >> ./log/install.txt
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -142,6 +143,7 @@ _installPythonVenv(){
|
|||||||
_installPythonPip(){
|
_installPythonPip(){
|
||||||
if ! $pythonExecutable -m pip -h > /dev/null 2>&1
|
if ! $pythonExecutable -m pip -h > /dev/null 2>&1
|
||||||
then
|
then
|
||||||
|
printf "[WGDashboard] %s Installing Python Package Manager (PIP)\n" "$install"
|
||||||
case "$OS" in
|
case "$OS" in
|
||||||
ubuntu|debian)
|
ubuntu|debian)
|
||||||
if [ "$pythonExecutable" = "python3" ]; then
|
if [ "$pythonExecutable" = "python3" ]; then
|
||||||
@ -181,24 +183,28 @@ _installPythonPip(){
|
|||||||
_checkWireguard(){
|
_checkWireguard(){
|
||||||
if ! command -v wg > /dev/null 2>&1 || ! command -v wg-quick > /dev/null 2>&1
|
if ! command -v wg > /dev/null 2>&1 || ! command -v wg-quick > /dev/null 2>&1
|
||||||
then
|
then
|
||||||
|
printf "[WGDashboard] %s Installing WireGuard\n" "$install"
|
||||||
case "$OS" in
|
case "$OS" in
|
||||||
ubuntu|debian)
|
ubuntu|debian)
|
||||||
{
|
{
|
||||||
sudo apt update && sudo apt-get install -y wireguard;
|
sudo apt update && sudo apt-get install -y wireguard;
|
||||||
printf "\n[WGDashboard] WireGuard installed on %s.\n\n" "$OS";
|
printf "\n[WGDashboard] WireGuard installed on %s.\n\n" "$OS";
|
||||||
} &>> ./log/install.txt
|
} &>> ./log/install.txt
|
||||||
|
printf "[WGDashboard] %s WireGuard is successfully installed.\n" "$heavy_checkmark"
|
||||||
;;
|
;;
|
||||||
centos|fedora|redhat|rhel|almalinux|rocky)
|
centos|fedora|redhat|rhel|almalinux|rocky)
|
||||||
{
|
{
|
||||||
sudo dnf install -y wireguard-tools;
|
sudo dnf install -y wireguard-tools;
|
||||||
printf "\n[WGDashboard] WireGuard installed on %s.\n\n" "$OS";
|
printf "\n[WGDashboard] WireGuard installed on %s.\n\n" "$OS";
|
||||||
} &>> ./log/install.txt
|
} &>> ./log/install.txt
|
||||||
|
printf "[WGDashboard] %s WireGuard is successfully installed.\n" "$heavy_checkmark"
|
||||||
;;
|
;;
|
||||||
alpine)
|
alpine)
|
||||||
{
|
{
|
||||||
sudo apk update && sudo apk add wireguard-tools --no-cache;
|
sudo apk update && sudo apk add wireguard-tools --no-cache;
|
||||||
printf "\n[WGDashboard] WireGuard installed on %s.\n\n" "$OS";
|
printf "\n[WGDashboard] WireGuard installed on %s.\n\n" "$OS";
|
||||||
} &>> ./log/install.txt
|
} &>> ./log/install.txt
|
||||||
|
printf "[WGDashboard] %s WireGuard is successfully installed.\n" "$heavy_checkmark"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
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 "[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"
|
||||||
@ -207,7 +213,7 @@ _checkWireguard(){
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
printf "[WGDashboard] WireGuard is already installed.\n"
|
printf "[WGDashboard] %s WireGuard is already installed.\n" "$heavy_checkmark"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,6 +225,7 @@ _checkPythonVersion(){
|
|||||||
version=$($pythonExecutable --version)
|
version=$($pythonExecutable --version)
|
||||||
if [ $version_pass == "1" ]
|
if [ $version_pass == "1" ]
|
||||||
then
|
then
|
||||||
|
printf "[WGDashboard] %s Found compatible version of Python. Will be using %s to install WGDashboard.\n" "$heavy_checkmark" "$($pythonExecutable --version)"
|
||||||
return;
|
return;
|
||||||
elif python3.10 --version > /dev/null 2>&1
|
elif python3.10 --version > /dev/null 2>&1
|
||||||
then
|
then
|
||||||
@ -267,19 +274,29 @@ install_wgd(){
|
|||||||
_installPythonPip
|
_installPythonPip
|
||||||
_checkWireguard
|
_checkWireguard
|
||||||
sudo chmod -R 755 /etc/wireguard/
|
sudo chmod -R 755 /etc/wireguard/
|
||||||
|
|
||||||
|
_check_and_set_venv
|
||||||
|
printf "[WGDashboard] %s Upgrading Python Package Manage (PIP)\n" "$install"
|
||||||
|
{ date; python3 -m ensurepip --upgrade; printf "\n\n"; } >> ./log/install.txt
|
||||||
|
{ date; python3 -m pip install --upgrade pip -i "$selected_url"; printf "\n\n"; } >> ./log/install.txt
|
||||||
|
printf "[WGDashboard] %s Installing latest Python dependencies\n" "$install"
|
||||||
|
{ date; python3 -m pip install -r requirements.txt -i "$selected_url"; printf "\n\n"; } >> ./log/install.txt #This all works on the default installation.
|
||||||
|
|
||||||
if [ ! -d "db" ]
|
if [ ! -d "db" ]
|
||||||
then
|
then
|
||||||
printf "[WGDashboard] Creating ./db folder\n"
|
|
||||||
mkdir "db"
|
mkdir "db"
|
||||||
fi
|
printf "[WGDashboard] %s Created ./db folder\n" "$heavy_checkmark"
|
||||||
_check_and_set_venv
|
else
|
||||||
printf "[WGDashboard] Upgrading Python Package Manage (PIP)\n"
|
printf "[WGDashboard] %s Found existing ./db folder\n" "$heavy_checkmark"
|
||||||
{ date; python3 -m ensurepip --upgrade; printf "\n\n"; } >> ./log/install.txt
|
fi
|
||||||
{ date; python3 -m pip install --upgrade pip; printf "\n\n"; } >> ./log/install.txt
|
if [ ! -f "ssl.ini" ]
|
||||||
printf "[WGDashboard] Installing latest Python dependencies\n"
|
then
|
||||||
{ date; python3 -m pip install -r requirements.txt ; printf "\n\n"; } >> ./log/install.txt #This all works on the default installation.
|
printf "[SSL]\ncertificate_path = \nprivate_key_path = \n" >> ssl.ini
|
||||||
printf "[WGDashboard] WGDashboard installed successfully!\n"
|
printf "[WGDashboard] %s Created ssl.ini\n" "$heavy_checkmark"
|
||||||
|
else
|
||||||
|
printf "[WGDashboard] %s Found existing ssl.ini\n" "$heavy_checkmark"
|
||||||
|
fi
|
||||||
|
printf "[WGDashboard] %s WGDashboard installed successfully!\n" "$heavy_checkmark"
|
||||||
printf "[WGDashboard] Enter ./wgd.sh start to start the dashboard\n"
|
printf "[WGDashboard] Enter ./wgd.sh start to start the dashboard\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user