From 2ccce6918058772038d5e3685ec0071be6fa72ba Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Sat, 2 Aug 2025 16:51:24 +0800 Subject: [PATCH] Adjusted OIDC template, continue working on building client side app --- src/dashboard.py | 2 +- src/modules/DashboardClients.py | 2 +- src/modules/DashboardConfig.py | 8 +++-- src/modules/DashboardOIDC.py | 21 ++++++++--- .../clientComponents/clientProfile.vue | 11 ++++++ .../clientComponents/clientSettings.vue | 36 +++++++++++++++++++ src/static/app/src/router/router.js | 13 +++---- src/static/app/src/views/clients.vue | 11 ++++-- 8 files changed, 86 insertions(+), 18 deletions(-) create mode 100644 src/static/app/src/components/clientComponents/clientProfile.vue create mode 100644 src/static/app/src/components/clientComponents/clientSettings.vue diff --git a/src/dashboard.py b/src/dashboard.py index 8addc8a..9ead71e 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -1127,7 +1127,7 @@ class Locale: def updateLanguage(self, lang_id): if not os.path.exists(os.path.join(f"{self.localePath}{lang_id}.json")): - DashboardConfig.SetConfig("Server", "dashboard_language", "en") + DashboardConfig.SetConfig("Server", "dashboard_language", "en-US") else: DashboardConfig.SetConfig("Server", "dashboard_language", lang_id) diff --git a/src/modules/DashboardClients.py b/src/modules/DashboardClients.py index fd7ee15..503e2d5 100644 --- a/src/modules/DashboardClients.py +++ b/src/modules/DashboardClients.py @@ -21,7 +21,7 @@ class DashboardClients: self.logger = DashboardLogger() self.engine = db.create_engine(ConnectionString("wgdashboard")) self.metadata = db.MetaData() - self.OIDC = DashboardOIDC() + self.OIDC = DashboardOIDC("Client") self.dashboardClientsTable = db.Table( 'DashboardClients', self.metadata, diff --git a/src/modules/DashboardConfig.py b/src/modules/DashboardConfig.py index 3e2f079..eb4c174 100644 --- a/src/modules/DashboardConfig.py +++ b/src/modules/DashboardConfig.py @@ -23,7 +23,7 @@ class DashboardConfig: def __init__(self): if not os.path.exists(DashboardConfig.ConfigurationFilePath): open(DashboardConfig.ConfigurationFilePath, "x") - self.__config = configparser.ConfigParser(strict=False) + self.__config = configparser.RawConfigParser(strict=False) self.__config.read_file(open(DashboardConfig.ConfigurationFilePath, "r+")) self.hiddenAttribute = ["totp_key", "auth_req"] self.__default = { @@ -76,6 +76,10 @@ class DashboardConfig: "send_from": "", "email_template": "" }, + "OIDC": { + "admin_enable": "false", + "client_enable": "false" + }, "WireGuardConfiguration": { "autostart": "" } @@ -236,7 +240,7 @@ class DashboardConfig: elif type(value) is list: self.__config[section][key] = "||".join(value).strip("||") else: - self.__config[section][key] = value + self.__config[section][key] = fr"{value}" return self.SaveConfig(), "" else: return False, f"{key} does not exist under {section}" diff --git a/src/modules/DashboardOIDC.py b/src/modules/DashboardOIDC.py index 9e08dd6..1ed6736 100644 --- a/src/modules/DashboardOIDC.py +++ b/src/modules/DashboardOIDC.py @@ -8,15 +8,25 @@ from flask import current_app class DashboardOIDC: ConfigurationPath = os.getenv('CONFIGURATION_PATH', '.') ConfigurationFilePath = os.path.join(ConfigurationPath, 'wg-dashboard-oidc-providers.json') - def __init__(self): + def __init__(self, mode): + self.mode = mode self.providers: dict[str, dict] = {} self.provider_secret: dict[str, str] = {} self.__default = { - 'Provider': { - 'client_id': '', - 'client_secret': '', - 'issuer': '', + "Admin": { + 'Provider': { + 'client_id': '', + 'client_secret': '', + 'issuer': '', + }, }, + "Client": { + 'Provider': { + 'client_id': '', + 'client_secret': '', + 'issuer': '', + }, + } } if not os.path.exists(DashboardOIDC.ConfigurationFilePath): @@ -109,6 +119,7 @@ class DashboardOIDC: providers = decoder.decode( open(DashboardOIDC.ConfigurationFilePath, 'r').read() ) + providers = providers[self.mode] for k in providers.keys(): if all([providers[k]['client_id'], providers[k]['client_secret'], providers[k]['issuer']]): try: diff --git a/src/static/app/src/components/clientComponents/clientProfile.vue b/src/static/app/src/components/clientComponents/clientProfile.vue new file mode 100644 index 0000000..96c0baf --- /dev/null +++ b/src/static/app/src/components/clientComponents/clientProfile.vue @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/src/static/app/src/components/clientComponents/clientSettings.vue b/src/static/app/src/components/clientComponents/clientSettings.vue new file mode 100644 index 0000000..9896465 --- /dev/null +++ b/src/static/app/src/components/clientComponents/clientSettings.vue @@ -0,0 +1,36 @@ + + + + + \ No newline at end of file diff --git a/src/static/app/src/router/router.js b/src/static/app/src/router/router.js index 252157b..24a81fb 100644 --- a/src/static/app/src/router/router.js +++ b/src/static/app/src/router/router.js @@ -91,7 +91,10 @@ const router = createRouter({ { name: "Client Viewer", path: ':id', - component: () => import('@/components/clientComponents/clientViewer.vue') + component: () => import('@/components/clientComponents/clientViewer.vue'), + meta: { + title: "Clients" + }, } ] }, @@ -155,11 +158,9 @@ router.beforeEach(async (to, from, next) => { const dashboardConfigurationStore = DashboardConfigurationStore(); if (to.meta.title){ - if (to.params.id){ - document.title = to.params.id + " | WGDashboard"; - }else{ - document.title = to.meta.title + " | WGDashboard"; - } + document.title = to.meta.title + " | WGDashboard"; + }else if(to.params.id){ + document.title = to.params.id + " | WGDashboard"; }else{ document.title = "WGDashboard" } diff --git a/src/static/app/src/views/clients.vue b/src/static/app/src/views/clients.vue index ae3eed1..f3ee729 100644 --- a/src/static/app/src/views/clients.vue +++ b/src/static/app/src/views/clients.vue @@ -7,13 +7,14 @@ import {GetLocale} from "@/utilities/locale.js"; import ClientGroup from "@/components/clientComponents/clientGroup.vue"; import { fetchGet } from "@/utilities/fetch.js" import {useRoute} from "vue-router"; +import ClientSettings from "@/components/clientComponents/clientSettings.vue"; await assignmentStore.getClients(); assignmentStore.getAllConfigurationsPeers(); const searchString = ref("") const route = useRoute() - +const settings = ref(false) const oidc = computed(() => { return Object.fromEntries( Object.entries(assignmentStore.clients).filter( @@ -24,8 +25,12 @@ const oidc = computed(() => {