diff --git a/src/gunicorn.conf.py b/src/gunicorn.conf.py index c3d08e8..9e69329 100644 --- a/src/gunicorn.conf.py +++ b/src/gunicorn.conf.py @@ -1,15 +1,15 @@ -import dashboard +import os.path + +import dashboard, configparser from datetime import datetime global sqldb, cursor, DashboardConfig, WireguardConfigurations, AllPeerJobs, JobLogger app_host, app_port = dashboard.gunicornConfig() date = datetime.today().strftime('%Y_%m_%d_%H_%M_%S') - def post_worker_init(worker): dashboard.startThreads() - worker_class = 'gthread' workers = 1 threads = 1 @@ -21,6 +21,19 @@ accesslog = f"./log/access_{date}.log" log_level = "debug" capture_output = True 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] Access log file is at {accesslog}", flush=True) print(f"[WGDashboard] Error log file is at {errorlog}", flush=True) diff --git a/src/wgd.sh b/src/wgd.sh index 22e1d25..7fa55d4 100755 --- a/src/wgd.sh +++ b/src/wgd.sh @@ -11,8 +11,9 @@ venv_python="./venv/bin/python3" venv_gunicorn="./venv/bin/gunicorn" pythonExecutable="python3" -heavy_checkmark=$(printf "\xE2\x9C\x94") -heavy_crossmark=$(printf "\xE2\x9C\x97") +heavy_checkmark=$(printf "\xE2\x9C\x85") +heavy_crossmark=$(printf "\xE2\x9D\x8C") +install=$(printf "\xF0\x9F\x92\xBF") PID_FILE=./gunicorn.pid environment=$(if [[ $ENVIRONMENT ]]; then echo $ENVIRONMENT; else echo 'develop'; fi) @@ -46,7 +47,7 @@ help () { _check_and_set_venv(){ VIRTUAL_ENV="./venv" 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 fi @@ -142,6 +143,7 @@ _installPythonVenv(){ _installPythonPip(){ if ! $pythonExecutable -m pip -h > /dev/null 2>&1 then + printf "[WGDashboard] %s Installing Python Package Manager (PIP)\n" "$install" case "$OS" in ubuntu|debian) if [ "$pythonExecutable" = "python3" ]; then @@ -181,24 +183,28 @@ _installPythonPip(){ _checkWireguard(){ if ! command -v wg > /dev/null 2>&1 || ! command -v wg-quick > /dev/null 2>&1 then + printf "[WGDashboard] %s Installing WireGuard\n" "$install" 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 + printf "[WGDashboard] %s WireGuard is successfully installed.\n" "$heavy_checkmark" ;; 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 + printf "[WGDashboard] %s WireGuard is successfully installed.\n" "$heavy_checkmark" ;; 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 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" @@ -207,7 +213,7 @@ _checkWireguard(){ ;; esac else - printf "[WGDashboard] WireGuard is already installed.\n" + printf "[WGDashboard] %s WireGuard is already installed.\n" "$heavy_checkmark" fi } @@ -219,6 +225,7 @@ _checkPythonVersion(){ version=$($pythonExecutable --version) if [ $version_pass == "1" ] then + printf "[WGDashboard] %s Found compatible version of Python. Will be using %s to install WGDashboard.\n" "$heavy_checkmark" "$($pythonExecutable --version)" return; elif python3.10 --version > /dev/null 2>&1 then @@ -267,19 +274,29 @@ install_wgd(){ _installPythonPip _checkWireguard 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" ] then - printf "[WGDashboard] Creating ./db folder\n" mkdir "db" - fi - _check_and_set_venv - printf "[WGDashboard] Upgrading Python Package Manage (PIP)\n" - { 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 #This all works on the default installation. - printf "[WGDashboard] WGDashboard installed successfully!\n" + printf "[WGDashboard] %s Created ./db folder\n" "$heavy_checkmark" + else + printf "[WGDashboard] %s Found existing ./db folder\n" "$heavy_checkmark" + fi + if [ ! -f "ssl.ini" ] + then + printf "[SSL]\ncertificate_path = \nprivate_key_path = \n" >> ssl.ini + 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" }