1
0
mirror of https://github.com/donaldzou/WGDashboard.git synced 2024-11-06 16:00:28 +01:00

New build

This commit is contained in:
Donald Zou 2024-07-31 02:27:44 -04:00
parent 881d62d69d
commit 85970f8c96
4 changed files with 62 additions and 47 deletions

View File

@ -22,6 +22,7 @@ import psutil
import pyotp import pyotp
from flask import Flask, request, render_template, session from flask import Flask, request, render_template, session
from json import JSONEncoder from json import JSONEncoder
from flask_cors import CORS
from icmplib import ping, traceroute from icmplib import ping, traceroute
@ -46,7 +47,7 @@ UPDATE = None
app = Flask("WGDashboard") app = Flask("WGDashboard")
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 5206928 app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 5206928
app.secret_key = secrets.token_urlsafe(32) app.secret_key = secrets.token_urlsafe(32)
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
class ModelEncoder(JSONEncoder): class ModelEncoder(JSONEncoder):
def default(self, o: Any) -> Any: def default(self, o: Any) -> Any:
@ -1209,8 +1210,22 @@ API Routes
@app.before_request @app.before_request
def auth_req(): def auth_req():
authenticationRequired = DashboardConfig.GetConfig("Server", "auth_req")[1] authenticationRequired = DashboardConfig.GetConfig("Server", "auth_req")[1]
d = request.args
if authenticationRequired: if authenticationRequired:
apiKey = d.get('apiKey')
apiKeyEnabled = DashboardConfig.GetConfig("Server", "dashboard_api_key")[1]
if apiKey is not None and len(apiKey) > 0 and apiKeyEnabled:
apiKeyExist = len(list(filter(lambda x : x.Key == apiKey, DashboardConfig.DashboardAPIKeys))) == 1
if not apiKeyExist:
response = Flask.make_response(app, {
"status": False,
"message": "API Key does not exist",
"data": None
})
response.content_type = "application/json"
response.status_code = 401
return response
else:
if ('/static/' not in request.path and "username" not in session and "/" != request.path if ('/static/' not in request.path and "username" not in session and "/" != request.path
and "validateAuthentication" not in request.path and "authenticate" not in request.path and "validateAuthentication" not in request.path and "authenticate" not in request.path
and "getDashboardConfiguration" not in request.path and "getDashboardTheme" not in request.path and "getDashboardConfiguration" not in request.path and "getDashboardTheme" not in request.path
@ -1218,7 +1233,7 @@ def auth_req():
): ):
response = Flask.make_response(app, { response = Flask.make_response(app, {
"status": False, "status": False,
"message": None, "message": "Unauthorized access.",
"data": None "data": None
}) })
response.content_type = "application/json" response.content_type = "application/json"

View File

@ -6,4 +6,4 @@ flask
icmplib icmplib
sqlalchemy sqlalchemy
flask[async] flask[async]
aiosqlite flask-cors

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long