From e6e070d89ebd99d4911fbfc2a28a14861b752b63 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Thu, 11 Jan 2024 01:10:26 -0500 Subject: [PATCH] Continue to refactor the UI and APIs :) --- src/dashboard_new.py | 20 +++++++- src/requirements.txt | 3 +- .../app/src/components/configurationList.vue | 51 +++++++++++++++++++ src/static/app/src/components/navbar.vue | 27 ++++++---- src/static/app/src/router/index.js | 21 +++++++- src/static/app/src/stores/wgdashboardStore.js | 23 +++++++++ .../app/src/views/configurationList.vue | 13 ----- src/static/app/src/views/index.vue | 6 ++- src/static/app/src/views/settings.vue | 19 +++++++ src/static/app/vite.config.js | 2 +- src/static/css/dashboard.css | 23 +++++++-- 11 files changed, 174 insertions(+), 34 deletions(-) create mode 100644 src/static/app/src/components/configurationList.vue delete mode 100644 src/static/app/src/views/configurationList.vue create mode 100644 src/static/app/src/views/settings.vue diff --git a/src/dashboard_new.py b/src/dashboard_new.py index 7017956..171ea5b 100644 --- a/src/dashboard_new.py +++ b/src/dashboard_new.py @@ -16,6 +16,7 @@ from dataclasses import dataclass from datetime import datetime, timedelta from json import JSONEncoder from operator import itemgetter +from typing import Dict, Any import flask # PIP installed library @@ -114,6 +115,8 @@ class WireguardConfiguration: if self.PrivateKey: self.PublicKey = self.__getPublicKey() + self.Status = self.__getStatus() + # Create tables in database inspector = inspect(engine) existingTable = inspector.get_table_names() @@ -127,7 +130,11 @@ class WireguardConfiguration: def __getPublicKey(self) -> str: return subprocess.check_output(['wg', 'pubkey'], input=self.PrivateKey.encode()).decode().strip('\n') + def __getStatus(self) -> bool: + return self.Name in dict(ifcfg.interfaces().items()).keys() + def toJSON(self): + self.Status = self.__getStatus() return self.__dict__ @@ -190,6 +197,14 @@ class DashboardConfig: return True, self.__config[section][key] + def toJSON(self) -> dict[str, dict[Any, Any]]: + the_dict = {} + for section in self.__config.sections(): + the_dict[section] = {} + for key, val in self.__config.items(section): + the_dict[section][key] = val + return the_dict + def ResponseObject(status=True, message=None, data=None) -> Flask.response_class: response = Flask.make_response(app, { @@ -340,12 +355,13 @@ def API_AuthenticateLogin(): @app.route('/api/getWireguardConfigurations', methods=["GET"]) def API_getWireguardConfigurations(): - pass + WireguardConfigurations = _getConfigurationList() + return ResponseObject(data=[wc.toJSON() for wc in WireguardConfigurations]) @app.route('/api/getDashboardConfiguration', methods=["GET"]) def API_getDashboardConfiguration(): - pass + return ResponseObject(data=DashboardConfig.toJSON()) if __name__ == "__main__": diff --git a/src/requirements.txt b/src/requirements.txt index 5d3b347..83dc31f 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -3,4 +3,5 @@ ifcfg icmplib flask-qrcode gunicorn -certbot \ No newline at end of file +certbot +sqlalchemy \ No newline at end of file diff --git a/src/static/app/src/components/configurationList.vue b/src/static/app/src/components/configurationList.vue new file mode 100644 index 0000000..be10e2f --- /dev/null +++ b/src/static/app/src/components/configurationList.vue @@ -0,0 +1,51 @@ + + + + + \ No newline at end of file diff --git a/src/static/app/src/components/navbar.vue b/src/static/app/src/components/navbar.vue index ff978c4..3bb5312 100644 --- a/src/static/app/src/components/navbar.vue +++ b/src/static/app/src/components/navbar.vue @@ -1,34 +1,43 @@