mirror of
https://github.com/WGDashboard/WGDashboard-PRW.git
synced 2026-08-03 14:32:56 +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 ..utilities.utilities import utilities
|
||||
from ..utilities.system_status import system_status
|
||||
from ..utilities.statistics import statistics
|
||||
|
||||
routes = flask.Blueprint("routes", __name__)
|
||||
|
||||
@@ -62,7 +62,11 @@ def authentication_required():
|
||||
|
||||
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():
|
||||
ok, config_server = config.filter(flask.current_app.wgd_config, 'SERVER')
|
||||
if not ok:
|
||||
@@ -165,18 +169,7 @@ def api_authenticate():
|
||||
else:
|
||||
return make_resp_obj(False, "Sorry, your username or password is incorrect.", {}, 401)
|
||||
|
||||
@routes.route('/')
|
||||
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')
|
||||
@routes.route('/api/auth/validate', methods=["GET"])
|
||||
def api_validate_auth():
|
||||
ok, config_server = config.filter(flask.current_app.wgd_config, 'SERVER')
|
||||
if not ok:
|
||||
@@ -191,7 +184,14 @@ def api_validate_auth():
|
||||
return make_resp_obj(False, "Invalid authentication", {}, 200)
|
||||
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():
|
||||
ok, config_server = config.filter(flask.current_app.wgd_config, 'SERVER')
|
||||
if not ok:
|
||||
@@ -200,7 +200,7 @@ def api_retrieve_dashboard_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():
|
||||
ok, config_server = config.filter(flask.current_app.wgd_config, 'SERVER')
|
||||
if not ok:
|
||||
@@ -209,16 +209,16 @@ def api_retrieve_dashboard_theme():
|
||||
|
||||
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():
|
||||
utilities.update_available()
|
||||
return make_resp_obj()
|
||||
|
||||
@routes.route('/api/getDashboardConfiguration')
|
||||
@routes.route('/api/dashboard/configuration', methods=["GET"])
|
||||
def api_retrieve_dashboard_config():
|
||||
return make_resp_obj(data=flask.current_app.wgd_config)
|
||||
|
||||
@routes.route('/api/isTotpEnabled')
|
||||
@routes.route('/api/dashboard/totpenabled')
|
||||
def api_totp_status():
|
||||
ok, config_account = config.filter(flask.current_app.wgd_config, 'ACCOUNT')
|
||||
if not ok:
|
||||
@@ -248,9 +248,9 @@ def api_retrieve_wireguard_configurations():
|
||||
|
||||
return make_resp_obj(True, 'Wireguard', {}, 200)
|
||||
|
||||
@routes.route('/api/systemStatus')
|
||||
@routes.route('/api/dashboard/statistics')
|
||||
def api_system_status():
|
||||
status = system_status()
|
||||
status = statistics()
|
||||
return make_resp_obj(True, "", status.to_json(), 200)
|
||||
|
||||
@routes.route('/health', methods=["GET"])
|
||||
|
||||
@@ -18,7 +18,7 @@ from ..config.config import config
|
||||
|
||||
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():
|
||||
ok, config_other = config.filter(flask.current_app.wgd_config, 'OTHER')
|
||||
if not ok:
|
||||
@@ -57,7 +57,7 @@ def api_welcome_finish():
|
||||
|
||||
return make_resp_obj()
|
||||
|
||||
@routes_welcome.route('/api/Welcome_GetTotpLink')
|
||||
@routes_welcome.route('/api/welcome/totplink')
|
||||
def api_welcome_get_totp():
|
||||
ok, config_account = config.filter(flask.current_app.wgd_config, 'ACCOUNT')
|
||||
if not ok:
|
||||
@@ -82,7 +82,7 @@ def api_welcome_get_totp():
|
||||
|
||||
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():
|
||||
ok, config_account = config.filter(flask.current_app.wgd_config, 'ACCOUNT')
|
||||
if not ok:
|
||||
|
||||
@@ -10,18 +10,18 @@ import psutil, shutil, subprocess, time
|
||||
from flask import current_app
|
||||
|
||||
|
||||
class system_status:
|
||||
class statistics:
|
||||
def to_json(self):
|
||||
return {
|
||||
"CPU": self.get_cpu(),
|
||||
"Memory": self.get_memory(),
|
||||
"Disks": self.get_disks(),
|
||||
"NetworkInterfaces": self.get_network(),
|
||||
"NetworkInterfacesPriority": self.get_interface_priorities(),
|
||||
"Processes": self.get_processes()
|
||||
"CPU": self.retrieve_cpu_stats(),
|
||||
"Memory": self.retrieve_memory_stats(),
|
||||
"Disks": self.retrieve_disk_stats(),
|
||||
"NetworkInterfaces": self.retrieve_network_stats(),
|
||||
"NetworkInterfacesPriority": self.retrieve_interface_priorities(),
|
||||
"Processes": self.retrieve_processes()
|
||||
}
|
||||
|
||||
def get_cpu(self):
|
||||
def retrieve_cpu_stats(self):
|
||||
try:
|
||||
return {
|
||||
"cpu_percent": psutil.cpu_percent(interval=1),
|
||||
@@ -31,7 +31,7 @@ class system_status:
|
||||
current_app.logger.error("CPU error %s", e)
|
||||
return {}
|
||||
|
||||
def get_memory(self):
|
||||
def retrieve_memory_stats(self):
|
||||
try:
|
||||
v = psutil.virtual_memory()
|
||||
s = psutil.swap_memory()
|
||||
@@ -52,7 +52,7 @@ class system_status:
|
||||
current_app.logger.error("Memory error %s", e)
|
||||
return {}
|
||||
|
||||
def get_disks(self):
|
||||
def retrieve_disk_stats(self):
|
||||
disks = []
|
||||
try:
|
||||
for p in psutil.disk_partitions():
|
||||
@@ -70,7 +70,7 @@ class system_status:
|
||||
|
||||
return disks
|
||||
|
||||
def get_network(self):
|
||||
def retrieve_network_stats(self):
|
||||
try:
|
||||
first = psutil.net_io_counters(pernic=True)
|
||||
time.sleep(1)
|
||||
@@ -96,7 +96,7 @@ class system_status:
|
||||
current_app.logger.error("Network error %s", e)
|
||||
return {}
|
||||
|
||||
def get_interface_priorities(self):
|
||||
def retrieve_interface_priorities(self):
|
||||
try:
|
||||
if not shutil.which("ip"):
|
||||
return {}
|
||||
@@ -119,7 +119,7 @@ class system_status:
|
||||
current_app.logger.error("Interface priority error %s", e)
|
||||
return {}
|
||||
|
||||
def get_processes(self):
|
||||
def retrieve_processes(self):
|
||||
cpu_list = []
|
||||
mem_list = []
|
||||
|
||||
@@ -4,6 +4,7 @@ import logging as log
|
||||
|
||||
import os
|
||||
import urllib.request
|
||||
import json
|
||||
|
||||
class utilities():
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user