mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-07-17 10:36:57 +00:00
Update
This commit is contained in:
parent
a619e7f571
commit
241fbd6be5
@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
import random, shutil, sqlite3, configparser, hashlib, ipaddress, json, os, secrets, subprocess
|
import random, shutil, sqlite3, configparser, hashlib, ipaddress, json, os, secrets, subprocess
|
||||||
import time, re, uuid, bcrypt, psutil, pyotp, threading
|
import time, re, uuid, bcrypt, psutil, pyotp, threading
|
||||||
import traceback
|
import traceback
|
||||||
@ -30,6 +31,18 @@ from modules.AmneziaWireguardConfiguration import AmneziaWireguardConfiguration
|
|||||||
|
|
||||||
from client import createClientBlueprint
|
from client import createClientBlueprint
|
||||||
|
|
||||||
|
from logging.config import dictConfig
|
||||||
|
|
||||||
|
dictConfig({
|
||||||
|
'version': 1,
|
||||||
|
'formatters': {'default': {
|
||||||
|
'format': '[%(asctime)s] [%(levelname)s] in [%(module)s] %(message)s',
|
||||||
|
}},
|
||||||
|
'root': {
|
||||||
|
'level': 'INFO'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
SystemStatus = SystemStatus()
|
SystemStatus = SystemStatus()
|
||||||
|
|
||||||
CONFIGURATION_PATH = os.getenv('CONFIGURATION_PATH', '.')
|
CONFIGURATION_PATH = os.getenv('CONFIGURATION_PATH', '.')
|
||||||
@ -634,8 +647,9 @@ def API_allowAccessPeers(configName: str) -> ResponseObject:
|
|||||||
@app.post(f'{APP_PREFIX}/api/addPeers/<configName>')
|
@app.post(f'{APP_PREFIX}/api/addPeers/<configName>')
|
||||||
def API_addPeers(configName):
|
def API_addPeers(configName):
|
||||||
if configName in WireguardConfigurations.keys():
|
if configName in WireguardConfigurations.keys():
|
||||||
|
data: dict = request.get_json()
|
||||||
try:
|
try:
|
||||||
data: dict = request.get_json()
|
|
||||||
|
|
||||||
bulkAdd: bool = data.get("bulkAdd", False)
|
bulkAdd: bool = data.get("bulkAdd", False)
|
||||||
bulkAddAmount: int = data.get('bulkAddAmount', 0)
|
bulkAddAmount: int = data.get('bulkAddAmount', 0)
|
||||||
@ -764,7 +778,7 @@ def API_addPeers(configName):
|
|||||||
)
|
)
|
||||||
return ResponseObject(status=status, message=result['message'], data=result['peers'])
|
return ResponseObject(status=status, message=result['message'], data=result['peers'])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e, str(e.__traceback__))
|
app.logger.error("Add peers failed", data, exc_info=e)
|
||||||
return ResponseObject(False, "Add peers failed. Please see data for specific issue")
|
return ResponseObject(False, "Add peers failed. Please see data for specific issue")
|
||||||
|
|
||||||
return ResponseObject(False, "Configuration does not exist")
|
return ResponseObject(False, "Configuration does not exist")
|
||||||
@ -913,7 +927,7 @@ def API_ping_getAllPeersIpAddress():
|
|||||||
try:
|
try:
|
||||||
ip = ipaddress.ip_network(x, strict=False)
|
ip = ipaddress.ip_network(x, strict=False)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print(f"{p.id} - {c.Name}")
|
app.logger.error(f"Failed to parse IP address of {p.id} - {c.Name}")
|
||||||
if len(list(ip.hosts())) == 1:
|
if len(list(ip.hosts())) == 1:
|
||||||
parsed.append(str(ip.hosts()[0]))
|
parsed.append(str(ip.hosts()[0]))
|
||||||
endpoint = p.endpoint.replace(" ", "").replace("(none)", "")
|
endpoint = p.endpoint.replace(" ", "").replace("(none)", "")
|
||||||
@ -1183,12 +1197,14 @@ def API_ProtocolsEnabled():
|
|||||||
|
|
||||||
@app.get(f'{APP_PREFIX}/')
|
@app.get(f'{APP_PREFIX}/')
|
||||||
def index():
|
def index():
|
||||||
|
app.logger.info('hi')
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
|
||||||
def peerInformationBackgroundThread():
|
def peerInformationBackgroundThread():
|
||||||
global WireguardConfigurations
|
global WireguardConfigurations
|
||||||
print(f"[WGDashboard] Background Thread #1 Started", flush=True)
|
app.logger.info("Background Thread #1 Started")
|
||||||
print(f"[WGDashboard] Background Thread #1 PID:" + str(threading.get_native_id()), flush=True)
|
app.logger.info("Background Thread #1 PID:" + str(threading.get_native_id()))
|
||||||
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
while True:
|
while True:
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
@ -1203,8 +1219,8 @@ def peerInformationBackgroundThread():
|
|||||||
|
|
||||||
def peerJobScheduleBackgroundThread():
|
def peerJobScheduleBackgroundThread():
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
print(f"[WGDashboard] Background Thread #2 Started", flush=True)
|
app.logger.info(f"Background Thread #2 Started")
|
||||||
print(f"[WGDashboard] Background Thread #2 PID:" + str(threading.get_native_id()), flush=True)
|
app.logger.info(f"Background Thread #2 PID:" + str(threading.get_native_id()))
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
while True:
|
while True:
|
||||||
AllPeerJobs.runJob()
|
AllPeerJobs.runJob()
|
||||||
@ -1278,4 +1294,6 @@ def startThreads():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
startThreads()
|
startThreads()
|
||||||
|
# logging.getLogger().addHandler(logging.StreamHandler())
|
||||||
|
app.logger.addHandler(logging.StreamHandler())
|
||||||
app.run(host=app_ip, debug=False, port=app_port)
|
app.run(host=app_ip, debug=False, port=app_port)
|
@ -16,7 +16,7 @@ daemon = True
|
|||||||
pidfile = './gunicorn.pid'
|
pidfile = './gunicorn.pid'
|
||||||
wsgi_app = "dashboard:app"
|
wsgi_app = "dashboard:app"
|
||||||
accesslog = f"./log/access_{date}.log"
|
accesslog = f"./log/access_{date}.log"
|
||||||
log_level = "debug"
|
loglevel = "info"
|
||||||
capture_output = True
|
capture_output = True
|
||||||
errorlog = f"./log/error_{date}.log"
|
errorlog = f"./log/error_{date}.log"
|
||||||
pythonpath = "., ./modules"
|
pythonpath = "., ./modules"
|
||||||
|
@ -74,6 +74,7 @@ class DashboardOIDC:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return False, str(e)
|
return False, str(e)
|
||||||
|
|
||||||
|
access_token = tokens.get('access_token')
|
||||||
id_token = tokens.get('id_token')
|
id_token = tokens.get('id_token')
|
||||||
jwks_uri = oidc_config.get("jwks_uri")
|
jwks_uri = oidc_config.get("jwks_uri")
|
||||||
issuer = oidc_config.get("issuer")
|
issuer = oidc_config.get("issuer")
|
||||||
@ -84,12 +85,15 @@ class DashboardOIDC:
|
|||||||
|
|
||||||
key = next(k for k in jwks["keys"] if k["kid"] == kid)
|
key = next(k for k in jwks["keys"] if k["kid"] == kid)
|
||||||
|
|
||||||
|
print(key)
|
||||||
|
|
||||||
payload = jwt.decode(
|
payload = jwt.decode(
|
||||||
id_token,
|
id_token,
|
||||||
key,
|
key,
|
||||||
algorithms=[key["alg"]],
|
algorithms=[key["alg"]],
|
||||||
audience=provider.get('client_id'),
|
audience=provider.get('client_id'),
|
||||||
issuer=issuer
|
issuer=issuer,
|
||||||
|
access_token=access_token
|
||||||
)
|
)
|
||||||
|
|
||||||
return True, payload
|
return True, payload
|
||||||
|
Loading…
x
Reference in New Issue
Block a user