diff --git a/src/app/components/Form/InfoField.vue b/src/app/components/Form/InfoField.vue new file mode 100644 index 00000000..595dcbfa --- /dev/null +++ b/src/app/components/Form/InfoField.vue @@ -0,0 +1,20 @@ + + + diff --git a/src/app/pages/clients/[id].vue b/src/app/pages/clients/[id].vue index 70d836d6..c07e1342 100644 --- a/src/app/pages/clients/[id].vue +++ b/src/app/pages/clients/[id].vue @@ -39,6 +39,12 @@ v-model="data.ipv6Address" label="IPv6" /> + diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 060f4f91..73dba722 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -113,7 +113,10 @@ "hooks": "Hooks", "hooksDescription": "Hooks only work with wg-quick", "hooksLeaveEmpty": "Only for wg-quick. Otherwise, leave it empty", - "dnsDesc": "DNS server clients will use (overrides global config)" + "dnsDesc": "DNS server clients will use (overrides global config)", + "notConnected": "Client not connected", + "endpoint": "Endpoint", + "endpointDesc": "IP of the client from which the WireGuard connection is established" }, "dialog": { "change": "Change", diff --git a/src/server/api/client/[clientId]/index.get.ts b/src/server/api/client/[clientId]/index.get.ts index 13941671..703a2d26 100644 --- a/src/server/api/client/[clientId]/index.get.ts +++ b/src/server/api/client/[clientId]/index.get.ts @@ -18,6 +18,18 @@ export default definePermissionEventHandler( statusMessage: 'Client not found', }); } - return result; + + const data = await WireGuard.dumpByPublicKey(result.publicKey); + if (!data) { + throw createError({ + statusCode: 500, + statusMessage: 'Failed to dump client data', + }); + } + + return { + ...result, + endpoint: data.endpoint, + }; } ); diff --git a/src/server/utils/WireGuard.ts b/src/server/utils/WireGuard.ts index 22132371..034561c4 100644 --- a/src/server/utils/WireGuard.ts +++ b/src/server/utils/WireGuard.ts @@ -93,6 +93,17 @@ class WireGuard { return clients; } + async dumpByPublicKey(publicKey: string) { + const wgInterface = await Database.interfaces.get(); + + const dump = await wg.dump(wgInterface.name); + const clientDump = dump.find( + ({ publicKey: dumpPublicKey }) => dumpPublicKey === publicKey + ); + + return clientDump; + } + async getAllClients() { const wgInterface = await Database.interfaces.get(); const dbClients = await Database.clients.getAllPublic();