From 4df4aa07f49b60c7bb7a70417f9c4b676279044d Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Mon, 21 Jul 2025 17:00:33 +0800 Subject: [PATCH] Assign peers from client settings is done --- src/dashboard.py | 2 +- src/modules/DashboardClients.py | 9 +- src/modules/DashboardClientsPeerAssignment.py | 1 + .../clientComponents/availablePeersGroup.vue | 78 ++++++++++++ .../clientComponents/clientAssignedPeers.vue | 112 +++++++++++------- .../clientComponents/clientViewer.vue | 4 +- .../stores/DashboardClientAssignmentStore.js | 6 +- 7 files changed, 162 insertions(+), 50 deletions(-) create mode 100644 src/static/app/src/components/clientComponents/availablePeersGroup.vue diff --git a/src/dashboard.py b/src/dashboard.py index 41571da4..fbdc3120 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -1277,7 +1277,7 @@ def API_Clients_AssignedPeers(): if not clientId: return ResponseObject(False, "Please provide ClientID") - d = DashboardClients.GetClientAssignedPeers(clientId) + d = DashboardClients.GetClientAssignedPeersGrouped(clientId) if d is None: return ResponseObject(False, "Client does not exist") return ResponseObject(data=d) diff --git a/src/modules/DashboardClients.py b/src/modules/DashboardClients.py index 7820110a..8ca770a8 100644 --- a/src/modules/DashboardClients.py +++ b/src/modules/DashboardClients.py @@ -330,10 +330,15 @@ class DashboardClients: a.Client = self.GetClient(a.ClientID) return c - def GetClientAssignedPeers(self, ClientID): + def GetClientAssignedPeersGrouped(self, ClientID): client = self.GetClient(ClientID) if client is not None: - return self.DashboardClientsPeerAssignment.GetAssignedPeers(ClientID) + p = self.DashboardClientsPeerAssignment.GetAssignedPeers(ClientID) + configs = set(map(lambda x : x['configuration_name'], p)) + d = {} + for i in configs: + d[i] = list(filter(lambda x : x['configuration_name'] == i, p)) + return d return None def AssignClient(self, ConfigurationName, PeerID, ClientID) -> tuple[bool, dict[str, str]] | tuple[bool, None]: diff --git a/src/modules/DashboardClientsPeerAssignment.py b/src/modules/DashboardClientsPeerAssignment.py index 6edb6cce..c10b9937 100644 --- a/src/modules/DashboardClientsPeerAssignment.py +++ b/src/modules/DashboardClientsPeerAssignment.py @@ -127,6 +127,7 @@ class DashboardClientsPeerAssignment: self.wireguardConfigurations[a.ConfigurationName].Peers) for p in peer: peers.append({ + 'assignment_id': a.AssignmentID, 'protocol': self.wireguardConfigurations[a.ConfigurationName].Protocol, 'id': p.id, 'private_key': p.private_key, diff --git a/src/static/app/src/components/clientComponents/availablePeersGroup.vue b/src/static/app/src/components/clientComponents/availablePeersGroup.vue new file mode 100644 index 00000000..04cc5986 --- /dev/null +++ b/src/static/app/src/components/clientComponents/availablePeersGroup.vue @@ -0,0 +1,78 @@ + + + + + \ No newline at end of file diff --git a/src/static/app/src/components/clientComponents/clientAssignedPeers.vue b/src/static/app/src/components/clientComponents/clientAssignedPeers.vue index 3cead24e..c60a84fe 100644 --- a/src/static/app/src/components/clientComponents/clientAssignedPeers.vue +++ b/src/static/app/src/components/clientComponents/clientAssignedPeers.vue @@ -1,62 +1,92 @@ \ No newline at end of file diff --git a/src/static/app/src/components/clientComponents/clientViewer.vue b/src/static/app/src/components/clientComponents/clientViewer.vue index 74e83f25..c1f12738 100644 --- a/src/static/app/src/components/clientComponents/clientViewer.vue +++ b/src/static/app/src/components/clientComponents/clientViewer.vue @@ -34,9 +34,7 @@ const client = computed(() => {
-
- -
+
diff --git a/src/static/app/src/stores/DashboardClientAssignmentStore.js b/src/static/app/src/stores/DashboardClientAssignmentStore.js index 9b3e01a0..7c7a6232 100644 --- a/src/static/app/src/stores/DashboardClientAssignmentStore.js +++ b/src/static/app/src/stores/DashboardClientAssignmentStore.js @@ -37,7 +37,7 @@ export const DashboardClientAssignmentStore = }) } - const assignClient = async (ConfigurationName, Peer, ClientID) => { + const assignClient = async (ConfigurationName, Peer, ClientID, get=true) => { assigning.value = ClientID; await fetchPost('/api/clients/assignClient', { ConfigurationName: ConfigurationName, @@ -45,7 +45,7 @@ export const DashboardClientAssignmentStore = ClientID: ClientID }, async (res) => { if (res.status){ - await getAssignedClients(ConfigurationName, Peer) + if (get) await getAssignedClients(ConfigurationName, Peer) assigning.value = ""; }else{ assigning.value = ""; @@ -59,7 +59,7 @@ export const DashboardClientAssignmentStore = AssignmentID: AssignmentID }, async (res) => { if (res.status){ - await getAssignedClients(ConfigurationName, Peer) + if (ConfigurationName && Peer) await getAssignedClients(ConfigurationName, Peer) } unassigning.value = false; })