Browse Source
Feat: show client endpoint (#2058)
* show client endpoint
* improve
* fix status code
pull/2037/merge
Bernd Storath
1 week ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with
54 additions and
2 deletions
-
src/app/components/Form/InfoField.vue
-
src/app/pages/clients/[id].vue
-
src/i18n/locales/en.json
-
src/server/api/client/[clientId]/index.get.ts
-
src/server/utils/WireGuard.ts
|
|
@ -0,0 +1,20 @@ |
|
|
|
<template> |
|
|
|
<div class="flex items-center"> |
|
|
|
<FormLabel :for="id"> |
|
|
|
{{ label }} |
|
|
|
</FormLabel> |
|
|
|
<BaseTooltip v-if="description" :text="description"> |
|
|
|
<IconsInfo class="size-4" /> |
|
|
|
</BaseTooltip> |
|
|
|
</div> |
|
|
|
<span :id="id">{{ data }}</span> |
|
|
|
</template> |
|
|
|
|
|
|
|
<script lang="ts" setup> |
|
|
|
defineProps<{ |
|
|
|
id: string; |
|
|
|
label: string; |
|
|
|
description?: string; |
|
|
|
data?: string; |
|
|
|
}>(); |
|
|
|
</script> |
|
|
@ -39,6 +39,12 @@ |
|
|
|
v-model="data.ipv6Address" |
|
|
|
label="IPv6" |
|
|
|
/> |
|
|
|
<FormInfoField |
|
|
|
id="endpoint" |
|
|
|
:data="data.endpoint ?? $t('client.notConnected')" |
|
|
|
:label="$t('client.endpoint')" |
|
|
|
:description="$t('client.endpointDesc')" |
|
|
|
/> |
|
|
|
</FormGroup> |
|
|
|
<FormGroup> |
|
|
|
<FormHeading :description="$t('client.allowedIpsDesc')"> |
|
|
|
|
|
@ -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", |
|
|
|
|
|
@ -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, |
|
|
|
}; |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
@ -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(); |
|
|
|