mirror of
https://github.com/WGDashboard/WGDashboard-PRW.git
synced 2026-08-03 22:42:57 +00:00
chore: rename and remap api endpoints
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
# Defined routes:
|
||||||
|
|
||||||
|
## Inplemented routes:
|
||||||
|
|
||||||
|
| Endpoint | Method | File |
|
||||||
|
| -------------------------------- | ----------------------------- | ---------------------------- |
|
||||||
|
| `/api/welcome/Finish` | `POST` | `routes_welcome.py` |
|
||||||
|
| `/api/welcome/verifytotp` | `POST` | `routes_welcome.py` |
|
||||||
|
| `/api/welcome/totplink` | `GET` | `routes_welcome.py` |
|
||||||
|
|
||||||
|
| Endpoint | Method | File |
|
||||||
|
| ------------------------------------------- | ----------------------------- | ---------------------------- |
|
||||||
|
| `/` | `GET` | `routes.py` |
|
||||||
|
| `/api/auth` | `POST` | `routes.py` |
|
||||||
|
| `/api/auth/validate` | `GET` | `routes.py` |
|
||||||
|
|
||||||
|
| Endpoint | Method | File |
|
||||||
|
| ------------------------------------------- | ----------------------------- | ---------------------------- |
|
||||||
|
| `/api/dashboard/locale` | `GET` | `routes.py` |
|
||||||
|
| `/api/dashboard/version` | `GET` | `routes.py` |
|
||||||
|
| `/api/dashboard/theme` | `GET` | `routes.py` |
|
||||||
|
| `/api/dashboard/update` | `GET` | `routes.py` |
|
||||||
|
| `/api/dashboard/configuration` | `GET` | `routes.py` |
|
||||||
|
| `/api/dashboard/totpenabled` | `GET` | `routes.py` |
|
||||||
|
| `/api/dashboard/statistics` | `GET` | `routes.py` |
|
||||||
|
|
||||||
|
| Endpoint | Method | File |
|
||||||
|
| ------------------------------------------- | ----------------------------- | ---------------------------- |
|
||||||
|
| `/health` & `/healthz` | `GET` | `routes.py` |
|
||||||
|
|
||||||
|
| Endpoint | Method | File |
|
||||||
|
| ------------------------------------------- | ----------------------------- | ---------------------------- |
|
||||||
|
| `/api/dashboard/Wireguard/Interface` | `GET` | `routes.py` |
|
||||||
|
|
||||||
|
## Uninplemented routes:
|
||||||
@@ -18,7 +18,7 @@ from ..database.functions import functions
|
|||||||
from ..config.config import config
|
from ..config.config import config
|
||||||
|
|
||||||
from ..utilities.utilities import utilities
|
from ..utilities.utilities import utilities
|
||||||
from ..utilities.system_status import system_status
|
from ..utilities.statistics import statistics
|
||||||
|
|
||||||
routes = flask.Blueprint("routes", __name__)
|
routes = flask.Blueprint("routes", __name__)
|
||||||
|
|
||||||
@@ -62,7 +62,11 @@ def authentication_required():
|
|||||||
|
|
||||||
return make_resp_obj(False, "Unauthorized access", {}, 401)
|
return make_resp_obj(False, "Unauthorized access", {}, 401)
|
||||||
|
|
||||||
@routes.route('/api/authenticate', methods=["POST"])
|
@routes.route('/', methods=["GET"])
|
||||||
|
def index_handler():
|
||||||
|
return flask.render_template("index.html")
|
||||||
|
|
||||||
|
@routes.route('/api/auth', methods=["POST"])
|
||||||
def api_authenticate():
|
def api_authenticate():
|
||||||
ok, config_server = config.filter(flask.current_app.wgd_config, 'SERVER')
|
ok, config_server = config.filter(flask.current_app.wgd_config, 'SERVER')
|
||||||
if not ok:
|
if not ok:
|
||||||
@@ -165,18 +169,7 @@ def api_authenticate():
|
|||||||
else:
|
else:
|
||||||
return make_resp_obj(False, "Sorry, your username or password is incorrect.", {}, 401)
|
return make_resp_obj(False, "Sorry, your username or password is incorrect.", {}, 401)
|
||||||
|
|
||||||
@routes.route('/')
|
@routes.route('/api/auth/validate', methods=["GET"])
|
||||||
def index_handler():
|
|
||||||
return flask.render_template("index.html")
|
|
||||||
|
|
||||||
@routes.route('/api/locale')
|
|
||||||
def api_locale_handler():
|
|
||||||
locale_manager = localeman()
|
|
||||||
locale_data = locale_manager.get_language()
|
|
||||||
|
|
||||||
return make_resp_obj(True, "", locale_data, 200)
|
|
||||||
|
|
||||||
@routes.route('/api/validateAuthentication')
|
|
||||||
def api_validate_auth():
|
def api_validate_auth():
|
||||||
ok, config_server = config.filter(flask.current_app.wgd_config, 'SERVER')
|
ok, config_server = config.filter(flask.current_app.wgd_config, 'SERVER')
|
||||||
if not ok:
|
if not ok:
|
||||||
@@ -191,7 +184,14 @@ def api_validate_auth():
|
|||||||
return make_resp_obj(False, "Invalid authentication", {}, 200)
|
return make_resp_obj(False, "Invalid authentication", {}, 200)
|
||||||
return make_resp_obj()
|
return make_resp_obj()
|
||||||
|
|
||||||
@routes.route('/api/getDashboardVersion')
|
@routes.route('/api/dashboard/locale', methods=["GET"])
|
||||||
|
def api_locale_handler():
|
||||||
|
locale_manager = localeman()
|
||||||
|
locale_data = locale_manager.get_language()
|
||||||
|
|
||||||
|
return make_resp_obj(True, "", locale_data, 200)
|
||||||
|
|
||||||
|
@routes.route('/api/dashboard/version', methods=["GET"])
|
||||||
def api_retrieve_dashboard_version():
|
def api_retrieve_dashboard_version():
|
||||||
ok, config_server = config.filter(flask.current_app.wgd_config, 'SERVER')
|
ok, config_server = config.filter(flask.current_app.wgd_config, 'SERVER')
|
||||||
if not ok:
|
if not ok:
|
||||||
@@ -200,7 +200,7 @@ def api_retrieve_dashboard_version():
|
|||||||
|
|
||||||
return make_resp_obj(True, "", config_server.get("version"))
|
return make_resp_obj(True, "", config_server.get("version"))
|
||||||
|
|
||||||
@routes.route('/api/getDashboardTheme')
|
@routes.route('/api/dashboard/theme', methods=["GET"])
|
||||||
def api_retrieve_dashboard_theme():
|
def api_retrieve_dashboard_theme():
|
||||||
ok, config_server = config.filter(flask.current_app.wgd_config, 'SERVER')
|
ok, config_server = config.filter(flask.current_app.wgd_config, 'SERVER')
|
||||||
if not ok:
|
if not ok:
|
||||||
@@ -209,16 +209,16 @@ def api_retrieve_dashboard_theme():
|
|||||||
|
|
||||||
return make_resp_obj(True, "", config_server.get("wgdashboard_theme"), 200)
|
return make_resp_obj(True, "", config_server.get("wgdashboard_theme"), 200)
|
||||||
|
|
||||||
@routes.route('/api/getDashboardUpdate')
|
@routes.route('/api/dashboard/update', methods=["GET"])
|
||||||
def api_retrieve_dashboard_update():
|
def api_retrieve_dashboard_update():
|
||||||
utilities.update_available()
|
utilities.update_available()
|
||||||
return make_resp_obj()
|
return make_resp_obj()
|
||||||
|
|
||||||
@routes.route('/api/getDashboardConfiguration')
|
@routes.route('/api/dashboard/configuration', methods=["GET"])
|
||||||
def api_retrieve_dashboard_config():
|
def api_retrieve_dashboard_config():
|
||||||
return make_resp_obj(data=flask.current_app.wgd_config)
|
return make_resp_obj(data=flask.current_app.wgd_config)
|
||||||
|
|
||||||
@routes.route('/api/isTotpEnabled')
|
@routes.route('/api/dashboard/totpenabled')
|
||||||
def api_totp_status():
|
def api_totp_status():
|
||||||
ok, config_account = config.filter(flask.current_app.wgd_config, 'ACCOUNT')
|
ok, config_account = config.filter(flask.current_app.wgd_config, 'ACCOUNT')
|
||||||
if not ok:
|
if not ok:
|
||||||
@@ -248,9 +248,9 @@ def api_retrieve_wireguard_configurations():
|
|||||||
|
|
||||||
return make_resp_obj(True, 'Wireguard', {}, 200)
|
return make_resp_obj(True, 'Wireguard', {}, 200)
|
||||||
|
|
||||||
@routes.route('/api/systemStatus')
|
@routes.route('/api/dashboard/statistics')
|
||||||
def api_system_status():
|
def api_system_status():
|
||||||
status = system_status()
|
status = statistics()
|
||||||
return make_resp_obj(True, "", status.to_json(), 200)
|
return make_resp_obj(True, "", status.to_json(), 200)
|
||||||
|
|
||||||
@routes.route('/health', methods=["GET"])
|
@routes.route('/health', methods=["GET"])
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from ..config.config import config
|
|||||||
|
|
||||||
routes_welcome = flask.Blueprint("routes_welcome", __name__)
|
routes_welcome = flask.Blueprint("routes_welcome", __name__)
|
||||||
|
|
||||||
@routes_welcome.route('/api/Welcome_Finish', methods=["POST"])
|
@routes_welcome.route('/api/welcome/Finish', methods=["POST"])
|
||||||
def api_welcome_finish():
|
def api_welcome_finish():
|
||||||
ok, config_other = config.filter(flask.current_app.wgd_config, 'OTHER')
|
ok, config_other = config.filter(flask.current_app.wgd_config, 'OTHER')
|
||||||
if not ok:
|
if not ok:
|
||||||
@@ -57,7 +57,7 @@ def api_welcome_finish():
|
|||||||
|
|
||||||
return make_resp_obj()
|
return make_resp_obj()
|
||||||
|
|
||||||
@routes_welcome.route('/api/Welcome_GetTotpLink')
|
@routes_welcome.route('/api/welcome/totplink')
|
||||||
def api_welcome_get_totp():
|
def api_welcome_get_totp():
|
||||||
ok, config_account = config.filter(flask.current_app.wgd_config, 'ACCOUNT')
|
ok, config_account = config.filter(flask.current_app.wgd_config, 'ACCOUNT')
|
||||||
if not ok:
|
if not ok:
|
||||||
@@ -82,7 +82,7 @@ def api_welcome_get_totp():
|
|||||||
|
|
||||||
return make_resp_obj(False, 'Internal error', {}, 500)
|
return make_resp_obj(False, 'Internal error', {}, 500)
|
||||||
|
|
||||||
@routes_welcome.route('/api/Welcome_VerifyTotpLink', methods=["POST"])
|
@routes_welcome.route('/api/welcome/verifytotplink', methods=["POST"])
|
||||||
def api_welcome_verify_totp():
|
def api_welcome_verify_totp():
|
||||||
ok, config_account = config.filter(flask.current_app.wgd_config, 'ACCOUNT')
|
ok, config_account = config.filter(flask.current_app.wgd_config, 'ACCOUNT')
|
||||||
if not ok:
|
if not ok:
|
||||||
|
|||||||
@@ -10,18 +10,18 @@ import psutil, shutil, subprocess, time
|
|||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
|
||||||
|
|
||||||
class system_status:
|
class statistics:
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
return {
|
return {
|
||||||
"CPU": self.get_cpu(),
|
"CPU": self.retrieve_cpu_stats(),
|
||||||
"Memory": self.get_memory(),
|
"Memory": self.retrieve_memory_stats(),
|
||||||
"Disks": self.get_disks(),
|
"Disks": self.retrieve_disk_stats(),
|
||||||
"NetworkInterfaces": self.get_network(),
|
"NetworkInterfaces": self.retrieve_network_stats(),
|
||||||
"NetworkInterfacesPriority": self.get_interface_priorities(),
|
"NetworkInterfacesPriority": self.retrieve_interface_priorities(),
|
||||||
"Processes": self.get_processes()
|
"Processes": self.retrieve_processes()
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_cpu(self):
|
def retrieve_cpu_stats(self):
|
||||||
try:
|
try:
|
||||||
return {
|
return {
|
||||||
"cpu_percent": psutil.cpu_percent(interval=1),
|
"cpu_percent": psutil.cpu_percent(interval=1),
|
||||||
@@ -31,7 +31,7 @@ class system_status:
|
|||||||
current_app.logger.error("CPU error %s", e)
|
current_app.logger.error("CPU error %s", e)
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_memory(self):
|
def retrieve_memory_stats(self):
|
||||||
try:
|
try:
|
||||||
v = psutil.virtual_memory()
|
v = psutil.virtual_memory()
|
||||||
s = psutil.swap_memory()
|
s = psutil.swap_memory()
|
||||||
@@ -52,7 +52,7 @@ class system_status:
|
|||||||
current_app.logger.error("Memory error %s", e)
|
current_app.logger.error("Memory error %s", e)
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_disks(self):
|
def retrieve_disk_stats(self):
|
||||||
disks = []
|
disks = []
|
||||||
try:
|
try:
|
||||||
for p in psutil.disk_partitions():
|
for p in psutil.disk_partitions():
|
||||||
@@ -70,7 +70,7 @@ class system_status:
|
|||||||
|
|
||||||
return disks
|
return disks
|
||||||
|
|
||||||
def get_network(self):
|
def retrieve_network_stats(self):
|
||||||
try:
|
try:
|
||||||
first = psutil.net_io_counters(pernic=True)
|
first = psutil.net_io_counters(pernic=True)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
@@ -96,7 +96,7 @@ class system_status:
|
|||||||
current_app.logger.error("Network error %s", e)
|
current_app.logger.error("Network error %s", e)
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_interface_priorities(self):
|
def retrieve_interface_priorities(self):
|
||||||
try:
|
try:
|
||||||
if not shutil.which("ip"):
|
if not shutil.which("ip"):
|
||||||
return {}
|
return {}
|
||||||
@@ -119,7 +119,7 @@ class system_status:
|
|||||||
current_app.logger.error("Interface priority error %s", e)
|
current_app.logger.error("Interface priority error %s", e)
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_processes(self):
|
def retrieve_processes(self):
|
||||||
cpu_list = []
|
cpu_list = []
|
||||||
mem_list = []
|
mem_list = []
|
||||||
|
|
||||||
@@ -4,6 +4,7 @@ import logging as log
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
import json
|
||||||
|
|
||||||
class utilities():
|
class utilities():
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user