mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2024-11-06 16:00:28 +01:00
Added app prefix for URL
This commit is contained in:
parent
3a34a0eb40
commit
a30843cff9
114
src/dashboard.py
114
src/dashboard.py
@ -20,7 +20,7 @@ import bcrypt
|
|||||||
import ifcfg
|
import ifcfg
|
||||||
import psutil
|
import psutil
|
||||||
import pyotp
|
import pyotp
|
||||||
from flask import Flask, request, render_template, session, g
|
from flask import Flask, request, render_template, session, g, Blueprint
|
||||||
from json import JSONEncoder
|
from json import JSONEncoder
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
|
|
||||||
@ -44,14 +44,13 @@ WG_CONF_PATH = None
|
|||||||
# Upgrade Required
|
# Upgrade Required
|
||||||
UPDATE = None
|
UPDATE = None
|
||||||
# Flask App Configuration
|
# Flask App Configuration
|
||||||
|
|
||||||
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": "*",
|
|
||||||
"methods": "DELETE, POST, GET, OPTIONS",
|
|
||||||
"allow_headers": ["Content-Type", "wg-dashboard-apikey"]
|
|
||||||
}})
|
|
||||||
|
|
||||||
class ModelEncoder(JSONEncoder):
|
class ModelEncoder(JSONEncoder):
|
||||||
def default(self, o: Any) -> Any:
|
def default(self, o: Any) -> Any:
|
||||||
@ -140,8 +139,6 @@ class DashboardLogger:
|
|||||||
print(e)
|
print(e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PeerJobLogger:
|
class PeerJobLogger:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.loggerdb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard_log.db'),
|
self.loggerdb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard_log.db'),
|
||||||
@ -1029,7 +1026,6 @@ PersistentKeepalive = {str(self.keepalive)}
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
# Regex Match
|
# Regex Match
|
||||||
def regex_match(regex, text):
|
def regex_match(regex, text):
|
||||||
pattern = re.compile(regex)
|
pattern = re.compile(regex)
|
||||||
@ -1067,6 +1063,7 @@ class DashboardConfig:
|
|||||||
},
|
},
|
||||||
"Server": {
|
"Server": {
|
||||||
"wg_conf_path": "/etc/wireguard",
|
"wg_conf_path": "/etc/wireguard",
|
||||||
|
"app_prefix": "",
|
||||||
"app_ip": "0.0.0.0",
|
"app_ip": "0.0.0.0",
|
||||||
"app_port": "10086",
|
"app_port": "10086",
|
||||||
"auth_req": "true",
|
"auth_req": "true",
|
||||||
@ -1344,11 +1341,25 @@ def _getWireguardConfigurationAvailableIP(configName: str) -> tuple[bool, list[s
|
|||||||
return False, None
|
return False, None
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
_, APP_PREFIX = DashboardConfig.GetConfig("Server", "app_prefix")
|
||||||
|
cors = CORS(app, resources={rf"{APP_PREFIX}/api/*": {
|
||||||
|
"origins": "*",
|
||||||
|
"methods": "DELETE, POST, GET, OPTIONS",
|
||||||
|
"allow_headers": ["Content-Type", "wg-dashboard-apikey"]
|
||||||
|
}})
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
API Routes
|
API Routes
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def auth_req():
|
def auth_req():
|
||||||
if request.method.lower() == 'options':
|
if request.method.lower() == 'options':
|
||||||
@ -1383,12 +1394,16 @@ def auth_req():
|
|||||||
DashboardConfig.APIAccessed = True
|
DashboardConfig.APIAccessed = True
|
||||||
else:
|
else:
|
||||||
DashboardConfig.APIAccessed = False
|
DashboardConfig.APIAccessed = False
|
||||||
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 (f"{(APP_PREFIX if len(APP_PREFIX) > 0 else '')}/" != request.path
|
||||||
|
and f"{(APP_PREFIX if len(APP_PREFIX) > 0 else '')}" != 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
|
||||||
and "sharePeer/get" not in request.path
|
and "sharePeer/get" not in request.path
|
||||||
and "isTotpEnabled" not in request.path
|
and "isTotpEnabled" not in request.path
|
||||||
):
|
):
|
||||||
|
print(request.path)
|
||||||
|
print(f"{(APP_PREFIX if len(APP_PREFIX) > 0 else '')}")
|
||||||
response = Flask.make_response(app, {
|
response = Flask.make_response(app, {
|
||||||
"status": False,
|
"status": False,
|
||||||
"message": "Unauthorized access.",
|
"message": "Unauthorized access.",
|
||||||
@ -1398,12 +1413,12 @@ def auth_req():
|
|||||||
response.status_code = 401
|
response.status_code = 401
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@app.route('/api/handshake', methods=["GET", "OPTIONS"])
|
@app.route(f'{APP_PREFIX}/api/handshake', methods=["GET", "OPTIONS"])
|
||||||
def API_ValidateAPIKey():
|
def API_ValidateAPIKey():
|
||||||
return ResponseObject(True)
|
return ResponseObject(True)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/validateAuthentication', methods=["GET"])
|
@app.route(f'{APP_PREFIX}/api/validateAuthentication', methods=["GET"])
|
||||||
def API_ValidateAuthentication():
|
def API_ValidateAuthentication():
|
||||||
token = request.cookies.get("authToken") + ""
|
token = request.cookies.get("authToken") + ""
|
||||||
if token == "" or "username" not in session or session["username"] != token:
|
if token == "" or "username" not in session or session["username"] != token:
|
||||||
@ -1411,7 +1426,7 @@ def API_ValidateAuthentication():
|
|||||||
return ResponseObject(True)
|
return ResponseObject(True)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/authenticate', methods=['POST'])
|
@app.route(f'{APP_PREFIX}/api/authenticate', methods=['POST'])
|
||||||
def API_AuthenticateLogin():
|
def API_AuthenticateLogin():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
if DashboardConfig.APIAccessed:
|
if DashboardConfig.APIAccessed:
|
||||||
@ -1452,20 +1467,20 @@ def API_AuthenticateLogin():
|
|||||||
return ResponseObject(False, "Sorry, your username or password is incorrect.")
|
return ResponseObject(False, "Sorry, your username or password is incorrect.")
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/signout')
|
@app.route(f'{APP_PREFIX}/api/signout')
|
||||||
def API_SignOut():
|
def API_SignOut():
|
||||||
resp = ResponseObject(True, "")
|
resp = ResponseObject(True, "")
|
||||||
resp.delete_cookie("authToken")
|
resp.delete_cookie("authToken")
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/getWireguardConfigurations', methods=["GET"])
|
@app.route(f'{APP_PREFIX}/api/getWireguardConfigurations', methods=["GET"])
|
||||||
def API_getWireguardConfigurations():
|
def API_getWireguardConfigurations():
|
||||||
# WireguardConfigurations = _getConfigurationList()
|
# WireguardConfigurations = _getConfigurationList()
|
||||||
return ResponseObject(data=[wc for wc in WireguardConfigurations.values()])
|
return ResponseObject(data=[wc for wc in WireguardConfigurations.values()])
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/addWireguardConfiguration', methods=["POST"])
|
@app.route(f'{APP_PREFIX}/api/addWireguardConfiguration', methods=["POST"])
|
||||||
def API_addWireguardConfiguration():
|
def API_addWireguardConfiguration():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
keys = [
|
keys = [
|
||||||
@ -1508,7 +1523,7 @@ def API_addWireguardConfiguration():
|
|||||||
return ResponseObject()
|
return ResponseObject()
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/toggleWireguardConfiguration/')
|
@app.route(f'{APP_PREFIX}/api/toggleWireguardConfiguration/')
|
||||||
def API_toggleWireguardConfiguration():
|
def API_toggleWireguardConfiguration():
|
||||||
configurationName = request.args.get('configurationName')
|
configurationName = request.args.get('configurationName')
|
||||||
|
|
||||||
@ -1521,12 +1536,12 @@ def API_toggleWireguardConfiguration():
|
|||||||
return ResponseObject(toggleStatus, msg, WireguardConfigurations[configurationName].Status)
|
return ResponseObject(toggleStatus, msg, WireguardConfigurations[configurationName].Status)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/getDashboardConfiguration', methods=["GET"])
|
@app.route(f'{APP_PREFIX}/api/getDashboardConfiguration', methods=["GET"])
|
||||||
def API_getDashboardConfiguration():
|
def API_getDashboardConfiguration():
|
||||||
return ResponseObject(data=DashboardConfig.toJson())
|
return ResponseObject(data=DashboardConfig.toJson())
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/updateDashboardConfiguration', methods=["POST"])
|
@app.route(f'{APP_PREFIX}/api/updateDashboardConfiguration', methods=["POST"])
|
||||||
def API_updateDashboardConfiguration():
|
def API_updateDashboardConfiguration():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
for section in data['DashboardConfiguration'].keys():
|
for section in data['DashboardConfiguration'].keys():
|
||||||
@ -1536,7 +1551,7 @@ def API_updateDashboardConfiguration():
|
|||||||
return ResponseObject()
|
return ResponseObject()
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/updateDashboardConfigurationItem', methods=["POST"])
|
@app.route(f'{APP_PREFIX}/api/updateDashboardConfigurationItem', methods=["POST"])
|
||||||
def API_updateDashboardConfigurationItem():
|
def API_updateDashboardConfigurationItem():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
if "section" not in data.keys() or "key" not in data.keys() or "value" not in data.keys():
|
if "section" not in data.keys() or "key" not in data.keys() or "value" not in data.keys():
|
||||||
@ -1550,13 +1565,13 @@ def API_updateDashboardConfigurationItem():
|
|||||||
|
|
||||||
return ResponseObject()
|
return ResponseObject()
|
||||||
|
|
||||||
@app.route('/api/getDashboardAPIKeys', methods=['GET'])
|
@app.route(f'{APP_PREFIX}/api/getDashboardAPIKeys', methods=['GET'])
|
||||||
def API_getDashboardAPIKeys():
|
def API_getDashboardAPIKeys():
|
||||||
if DashboardConfig.GetConfig('Server', 'dashboard_api_key'):
|
if DashboardConfig.GetConfig('Server', 'dashboard_api_key'):
|
||||||
return ResponseObject(data=DashboardConfig.DashboardAPIKeys)
|
return ResponseObject(data=DashboardConfig.DashboardAPIKeys)
|
||||||
return ResponseObject(False, "Dashboard API Keys function is disbaled")
|
return ResponseObject(False, "Dashboard API Keys function is disbaled")
|
||||||
|
|
||||||
@app.route('/api/newDashboardAPIKey', methods=['POST'])
|
@app.route(f'{APP_PREFIX}/api/newDashboardAPIKey', methods=['POST'])
|
||||||
def API_newDashboardAPIKey():
|
def API_newDashboardAPIKey():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
if DashboardConfig.GetConfig('Server', 'dashboard_api_key'):
|
if DashboardConfig.GetConfig('Server', 'dashboard_api_key'):
|
||||||
@ -1571,7 +1586,7 @@ def API_newDashboardAPIKey():
|
|||||||
return ResponseObject(False, str(e))
|
return ResponseObject(False, str(e))
|
||||||
return ResponseObject(False, "Dashboard API Keys function is disbaled")
|
return ResponseObject(False, "Dashboard API Keys function is disbaled")
|
||||||
|
|
||||||
@app.route('/api/deleteDashboardAPIKey', methods=['POST'])
|
@app.route(f'{APP_PREFIX}/api/deleteDashboardAPIKey', methods=['POST'])
|
||||||
def API_deleteDashboardAPIKey():
|
def API_deleteDashboardAPIKey():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
if DashboardConfig.GetConfig('Server', 'dashboard_api_key'):
|
if DashboardConfig.GetConfig('Server', 'dashboard_api_key'):
|
||||||
@ -1581,7 +1596,7 @@ def API_deleteDashboardAPIKey():
|
|||||||
return ResponseObject(False, "Dashboard API Keys function is disbaled")
|
return ResponseObject(False, "Dashboard API Keys function is disbaled")
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/updatePeerSettings/<configName>', methods=['POST'])
|
@app.route(f'{APP_PREFIX}/api/updatePeerSettings/<configName>', methods=['POST'])
|
||||||
def API_updatePeerSettings(configName):
|
def API_updatePeerSettings(configName):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
id = data['id']
|
id = data['id']
|
||||||
@ -1601,7 +1616,7 @@ def API_updatePeerSettings(configName):
|
|||||||
allowed_ip, endpoint_allowed_ip, mtu, keepalive)
|
allowed_ip, endpoint_allowed_ip, mtu, keepalive)
|
||||||
return ResponseObject(False, "Peer does not exist")
|
return ResponseObject(False, "Peer does not exist")
|
||||||
|
|
||||||
@app.route('/api/resetPeerData/<configName>', methods=['POST'])
|
@app.route(f'{APP_PREFIX}/api/resetPeerData/<configName>', methods=['POST'])
|
||||||
def API_resetPeerData(configName):
|
def API_resetPeerData(configName):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
id = data['id']
|
id = data['id']
|
||||||
@ -1616,7 +1631,7 @@ def API_resetPeerData(configName):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/deletePeers/<configName>', methods=['POST'])
|
@app.route(f'{APP_PREFIX}/api/deletePeers/<configName>', methods=['POST'])
|
||||||
def API_deletePeers(configName: str) -> ResponseObject:
|
def API_deletePeers(configName: str) -> ResponseObject:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
peers = data['peers']
|
peers = data['peers']
|
||||||
@ -1629,7 +1644,7 @@ def API_deletePeers(configName: str) -> ResponseObject:
|
|||||||
return ResponseObject(False, "Configuration does not exist")
|
return ResponseObject(False, "Configuration does not exist")
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/restrictPeers/<configName>', methods=['POST'])
|
@app.route(f'{APP_PREFIX}/api/restrictPeers/<configName>', methods=['POST'])
|
||||||
def API_restrictPeers(configName: str) -> ResponseObject:
|
def API_restrictPeers(configName: str) -> ResponseObject:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
peers = data['peers']
|
peers = data['peers']
|
||||||
@ -1640,7 +1655,7 @@ def API_restrictPeers(configName: str) -> ResponseObject:
|
|||||||
return configuration.restrictPeers(peers)
|
return configuration.restrictPeers(peers)
|
||||||
return ResponseObject(False, "Configuration does not exist")
|
return ResponseObject(False, "Configuration does not exist")
|
||||||
|
|
||||||
@app.route('/api/sharePeer/create', methods=['POST'])
|
@app.route(f'{APP_PREFIX}/api/sharePeer/create', methods=['POST'])
|
||||||
def API_sharePeer_create():
|
def API_sharePeer_create():
|
||||||
data: dict[str, str] = request.get_json()
|
data: dict[str, str] = request.get_json()
|
||||||
Configuration = data.get('Configuration')
|
Configuration = data.get('Configuration')
|
||||||
@ -1656,7 +1671,7 @@ def API_sharePeer_create():
|
|||||||
return ResponseObject(status, message)
|
return ResponseObject(status, message)
|
||||||
return ResponseObject(data=AllPeerShareLinks.getLinkByID(message))
|
return ResponseObject(data=AllPeerShareLinks.getLinkByID(message))
|
||||||
|
|
||||||
@app.route('/api/sharePeer/update', methods=['POST'])
|
@app.route(f'{APP_PREFIX}/api/sharePeer/update', methods=['POST'])
|
||||||
def API_sharePeer_update():
|
def API_sharePeer_update():
|
||||||
data: dict[str, str] = request.get_json()
|
data: dict[str, str] = request.get_json()
|
||||||
ShareID: str = data.get("ShareID")
|
ShareID: str = data.get("ShareID")
|
||||||
@ -1675,7 +1690,7 @@ def API_sharePeer_update():
|
|||||||
return ResponseObject(status, message)
|
return ResponseObject(status, message)
|
||||||
return ResponseObject(data=AllPeerShareLinks.getLinkByID(ShareID))
|
return ResponseObject(data=AllPeerShareLinks.getLinkByID(ShareID))
|
||||||
|
|
||||||
@app.route('/api/sharePeer/get', methods=['GET'])
|
@app.route(f'{APP_PREFIX}/api/sharePeer/get', methods=['GET'])
|
||||||
def API_sharePeer_get():
|
def API_sharePeer_get():
|
||||||
data = request.args
|
data = request.args
|
||||||
ShareID = data.get("ShareID")
|
ShareID = data.get("ShareID")
|
||||||
@ -1696,7 +1711,7 @@ def API_sharePeer_get():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/allowAccessPeers/<configName>', methods=['POST'])
|
@app.route(f'{APP_PREFIX}/api/allowAccessPeers/<configName>', methods=['POST'])
|
||||||
def API_allowAccessPeers(configName: str) -> ResponseObject:
|
def API_allowAccessPeers(configName: str) -> ResponseObject:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
peers = data['peers']
|
peers = data['peers']
|
||||||
@ -1708,7 +1723,7 @@ def API_allowAccessPeers(configName: str) -> ResponseObject:
|
|||||||
return ResponseObject(False, "Configuration does not exist")
|
return ResponseObject(False, "Configuration does not exist")
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/addPeers/<configName>', methods=['POST'])
|
@app.route(f'{APP_PREFIX}/api/addPeers/<configName>', methods=['POST'])
|
||||||
def API_addPeers(configName):
|
def API_addPeers(configName):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
bulkAdd = data['bulkAdd']
|
bulkAdd = data['bulkAdd']
|
||||||
@ -1817,7 +1832,7 @@ def API_getAvailableIPs(configName):
|
|||||||
return ResponseObject(status=status, data=ips)
|
return ResponseObject(status=status, data=ips)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/getWireguardConfigurationInfo', methods=["GET"])
|
@app.route(f'{APP_PREFIX}/api/getWireguardConfigurationInfo', methods=["GET"])
|
||||||
def API_getConfigurationInfo():
|
def API_getConfigurationInfo():
|
||||||
configurationName = request.args.get("configurationName")
|
configurationName = request.args.get("configurationName")
|
||||||
if not configurationName or configurationName not in WireguardConfigurations.keys():
|
if not configurationName or configurationName not in WireguardConfigurations.keys():
|
||||||
@ -1829,12 +1844,12 @@ def API_getConfigurationInfo():
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/getDashboardTheme')
|
@app.route(f'{APP_PREFIX}/api/getDashboardTheme')
|
||||||
def API_getDashboardTheme():
|
def API_getDashboardTheme():
|
||||||
return ResponseObject(data=DashboardConfig.GetConfig("Server", "dashboard_theme")[1])
|
return ResponseObject(data=DashboardConfig.GetConfig("Server", "dashboard_theme")[1])
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/savePeerScheduleJob/', methods=["POST"])
|
@app.route(f'{APP_PREFIX}/api/savePeerScheduleJob/', methods=["POST"])
|
||||||
def API_savePeerScheduleJob():
|
def API_savePeerScheduleJob():
|
||||||
data = request.json
|
data = request.json
|
||||||
if "Job" not in data.keys() not in WireguardConfigurations.keys():
|
if "Job" not in data.keys() not in WireguardConfigurations.keys():
|
||||||
@ -1855,7 +1870,7 @@ def API_savePeerScheduleJob():
|
|||||||
return ResponseObject(s, message=p)
|
return ResponseObject(s, message=p)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/deletePeerScheduleJob/', methods=['POST'])
|
@app.route(f'{APP_PREFIX}/api/deletePeerScheduleJob/', methods=['POST'])
|
||||||
def API_deletePeerScheduleJob():
|
def API_deletePeerScheduleJob():
|
||||||
data = request.json
|
data = request.json
|
||||||
if "Job" not in data.keys() not in WireguardConfigurations.keys():
|
if "Job" not in data.keys() not in WireguardConfigurations.keys():
|
||||||
@ -1875,7 +1890,7 @@ def API_deletePeerScheduleJob():
|
|||||||
return ResponseObject(s, data=p)
|
return ResponseObject(s, data=p)
|
||||||
return ResponseObject(s, message=p)
|
return ResponseObject(s, message=p)
|
||||||
|
|
||||||
@app.route('/api/getPeerScheduleJobLogs/<configName>', methods=['GET'])
|
@app.route(f'{APP_PREFIX}/api/getPeerScheduleJobLogs/<configName>', methods=['GET'])
|
||||||
def API_getPeerScheduleJobLogs(configName):
|
def API_getPeerScheduleJobLogs(configName):
|
||||||
if configName not in WireguardConfigurations.keys():
|
if configName not in WireguardConfigurations.keys():
|
||||||
return ResponseObject(False, "Configuration does not exist")
|
return ResponseObject(False, "Configuration does not exist")
|
||||||
@ -1892,7 +1907,7 @@ Tools
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/ping/getAllPeersIpAddress')
|
@app.route(f'{APP_PREFIX}/api/ping/getAllPeersIpAddress')
|
||||||
def API_ping_getAllPeersIpAddress():
|
def API_ping_getAllPeersIpAddress():
|
||||||
ips = {}
|
ips = {}
|
||||||
for c in WireguardConfigurations.values():
|
for c in WireguardConfigurations.values():
|
||||||
@ -1919,7 +1934,7 @@ def API_ping_getAllPeersIpAddress():
|
|||||||
return ResponseObject(data=ips)
|
return ResponseObject(data=ips)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/ping/execute')
|
@app.route(f'{APP_PREFIX}/api/ping/execute')
|
||||||
def API_ping_execute():
|
def API_ping_execute():
|
||||||
if "ipAddress" in request.args.keys() and "count" in request.args.keys():
|
if "ipAddress" in request.args.keys() and "count" in request.args.keys():
|
||||||
ip = request.args['ipAddress']
|
ip = request.args['ipAddress']
|
||||||
@ -1945,7 +1960,7 @@ def API_ping_execute():
|
|||||||
return ResponseObject(False, "Please provide ipAddress and count")
|
return ResponseObject(False, "Please provide ipAddress and count")
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/traceroute/execute')
|
@app.route(f'{APP_PREFIX}/api/traceroute/execute')
|
||||||
def API_traceroute_execute():
|
def API_traceroute_execute():
|
||||||
if "ipAddress" in request.args.keys() and len(request.args.get("ipAddress")) > 0:
|
if "ipAddress" in request.args.keys() and len(request.args.get("ipAddress")) > 0:
|
||||||
ipAddress = request.args.get('ipAddress')
|
ipAddress = request.args.get('ipAddress')
|
||||||
@ -1987,13 +2002,13 @@ Sign Up
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/isTotpEnabled')
|
@app.route(f'{APP_PREFIX}/api/isTotpEnabled')
|
||||||
def API_isTotpEnabled():
|
def API_isTotpEnabled():
|
||||||
return (
|
return (
|
||||||
ResponseObject(data=DashboardConfig.GetConfig("Account", "enable_totp")[1] and DashboardConfig.GetConfig("Account", "totp_verified")[1]))
|
ResponseObject(data=DashboardConfig.GetConfig("Account", "enable_totp")[1] and DashboardConfig.GetConfig("Account", "totp_verified")[1]))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/Welcome_GetTotpLink')
|
@app.route(f'{APP_PREFIX}/api/Welcome_GetTotpLink')
|
||||||
def API_Welcome_GetTotpLink():
|
def API_Welcome_GetTotpLink():
|
||||||
if not DashboardConfig.GetConfig("Account", "totp_verified")[1]:
|
if not DashboardConfig.GetConfig("Account", "totp_verified")[1]:
|
||||||
DashboardConfig.SetConfig("Account", "totp_key", pyotp.random_base32())
|
DashboardConfig.SetConfig("Account", "totp_key", pyotp.random_base32())
|
||||||
@ -2003,7 +2018,7 @@ def API_Welcome_GetTotpLink():
|
|||||||
return ResponseObject(False)
|
return ResponseObject(False)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/Welcome_VerifyTotpLink', methods=["POST"])
|
@app.route(f'{APP_PREFIX}/api/Welcome_VerifyTotpLink', methods=["POST"])
|
||||||
def API_Welcome_VerifyTotpLink():
|
def API_Welcome_VerifyTotpLink():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
totp = pyotp.TOTP(DashboardConfig.GetConfig("Account", "totp_key")[1]).now()
|
totp = pyotp.TOTP(DashboardConfig.GetConfig("Account", "totp_key")[1]).now()
|
||||||
@ -2013,7 +2028,7 @@ def API_Welcome_VerifyTotpLink():
|
|||||||
return ResponseObject(totp == data['totp'])
|
return ResponseObject(totp == data['totp'])
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/Welcome_Finish', methods=["POST"])
|
@app.route(f'{APP_PREFIX}/api/Welcome_Finish', methods=["POST"])
|
||||||
def API_Welcome_Finish():
|
def API_Welcome_Finish():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
if DashboardConfig.GetConfig("Other", "welcome_session")[1]:
|
if DashboardConfig.GetConfig("Other", "welcome_session")[1]:
|
||||||
@ -2040,12 +2055,13 @@ def API_Welcome_Finish():
|
|||||||
return ResponseObject()
|
return ResponseObject()
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET'])
|
@app.route(f'{APP_PREFIX}/', methods=['GET'])
|
||||||
def index():
|
def index():
|
||||||
"""
|
"""
|
||||||
Index page related
|
Index page related
|
||||||
@return: Template
|
@return: Template
|
||||||
"""
|
"""
|
||||||
|
print(APP_PREFIX)
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
|
||||||
|
|
||||||
@ -2086,10 +2102,7 @@ if sys.version_info < (3, 10):
|
|||||||
else:
|
else:
|
||||||
from typing import ParamSpec
|
from typing import ParamSpec
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
AllPeerShareLinks: PeerShareLinks = PeerShareLinks()
|
AllPeerShareLinks: PeerShareLinks = PeerShareLinks()
|
||||||
AllPeerJobs: PeerJobs = PeerJobs()
|
AllPeerJobs: PeerJobs = PeerJobs()
|
||||||
@ -2099,10 +2112,11 @@ _, app_ip = DashboardConfig.GetConfig("Server", "app_ip")
|
|||||||
_, app_port = DashboardConfig.GetConfig("Server", "app_port")
|
_, app_port = DashboardConfig.GetConfig("Server", "app_port")
|
||||||
_, WG_CONF_PATH = DashboardConfig.GetConfig("Server", "wg_conf_path")
|
_, WG_CONF_PATH = DashboardConfig.GetConfig("Server", "wg_conf_path")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WireguardConfigurations: dict[str, WireguardConfiguration] = {}
|
WireguardConfigurations: dict[str, WireguardConfiguration] = {}
|
||||||
WireguardConfigurations = _getConfigurationList()
|
WireguardConfigurations = _getConfigurationList()
|
||||||
|
|
||||||
|
|
||||||
def startThreads():
|
def startThreads():
|
||||||
bgThread = threading.Thread(target=backGroundThread)
|
bgThread = threading.Thread(target=backGroundThread)
|
||||||
bgThread.daemon = True
|
bgThread.daemon = True
|
||||||
|
2
src/static/app/dist/assets/index.js
vendored
2
src/static/app/dist/assets/index.js
vendored
File diff suppressed because one or more lines are too long
@ -19,7 +19,7 @@ const getUrl = (url) => {
|
|||||||
if (apiKey){
|
if (apiKey){
|
||||||
return `${apiKey.host}${url}`
|
return `${apiKey.host}${url}`
|
||||||
}
|
}
|
||||||
return url
|
return `//${window.location.host}${window.location.pathname}${url}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchGet = async (url, params=undefined, callback=undefined) => {
|
export const fetchGet = async (url, params=undefined, callback=undefined) => {
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
<link rel="apple-touch-icon" sizes="192x192" href="{{ url_for('static',filename='img/192x192ios.png') }}">
|
<link rel="apple-touch-icon" sizes="192x192" href="{{ url_for('static',filename='img/192x192ios.png') }}">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
<link rel="icon" href="{{ url_for('static',filename='img/logo.png') }}"/>
|
<link rel="icon" href="{{ url_for('static',filename='img/logo.png') }}"/>
|
||||||
<link rel="stylesheet" href="../static/app/dist/assets/index.css">
|
<link rel="stylesheet" href="{{ url_for('static',filename='app/dist/assets/index.css') }}">
|
||||||
<script src="../static/app/dist/assets/index.js" type="module"></script>
|
<script src="{{ url_for('static',filename='app/dist/assets/index.js') }}" type="module"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app" class="w-100 vh-100"></div>
|
<div id="app" class="w-100 vh-100"></div>
|
||||||
|
Loading…
Reference in New Issue
Block a user