Skip to content

Commit

Permalink
Fixed Gunicorn global variable issue
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldzou committed Aug 3, 2024
1 parent 461ae99 commit b64ba2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import ifcfg
import psutil
import pyotp
from flask import Flask, request, render_template, session
from flask import Flask, request, render_template, session, g
from json import JSONEncoder
from flask_cors import CORS

Expand Down Expand Up @@ -1245,7 +1245,6 @@ def API_ValidateAuthentication():
token = request.cookies.get("authToken") + ""
if token == "" or "username" not in session or session["username"] != token:
return ResponseObject(False, "Invalid authentication")

return ResponseObject(True)


Expand Down Expand Up @@ -1286,7 +1285,9 @@ def API_SignOut():

@app.route('/api/getWireguardConfigurations', methods=["GET"])
def API_getWireguardConfigurations():
WireguardConfigurations = _getConfigurationList()
# WireguardConfigurations = _getConfigurationList()
print("in request::::")
print(list(WireguardConfigurations.keys()))
return ResponseObject(data=[wc for wc in WireguardConfigurations.values()])


Expand Down Expand Up @@ -1838,18 +1839,20 @@ def gunicornConfig():
_, app_port = DashboardConfig.GetConfig("Server", "app_port")
return app_ip, app_port

# global sqldb, cursor, DashboardConfig, WireguardConfigurations, AllPeerJobs, JobLogger


sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'), check_same_thread=False)
sqldb.row_factory = sqlite3.Row
cursor = sqldb.cursor()
DashboardConfig = DashboardConfig()
WireguardConfigurations: dict[str, WireguardConfiguration] = {}

AllPeerJobs: PeerJobs = PeerJobs()
JobLogger: Logger = Logger()
_, app_ip = DashboardConfig.GetConfig("Server", "app_ip")
_, app_port = DashboardConfig.GetConfig("Server", "app_port")
_, WG_CONF_PATH = DashboardConfig.GetConfig("Server", "wg_conf_path")

WireguardConfigurations: dict[str, WireguardConfiguration] = {}
WireguardConfigurations = _getConfigurationList()
bgThread = threading.Thread(target=backGroundThread)
bgThread.daemon = True
Expand Down
4 changes: 2 additions & 2 deletions src/gunicorn.conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
app_host, app_port = dashboard.gunicornConfig()

worker_class = 'gthread'
workers = 4
threads = 2
workers = 1
threads = 1
bind = f"{app_host}:{app_port}"
daemon = True
pidfile = './gunicorn.pid'

0 comments on commit b64ba2e

Please sign in to comment.