Feat: show client endpoint (#2058)

* show client endpoint

* improve

* fix status code
This commit is contained in:
Bernd Storath
2025-07-25 12:00:42 +02:00
committed by GitHub
parent b5318086d2
commit 07f89d15a9
5 changed files with 54 additions and 2 deletions
+20
View File
@@ -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>
+6
View File
@@ -39,6 +39,12 @@
v-model="data.ipv6Address" v-model="data.ipv6Address"
label="IPv6" label="IPv6"
/> />
<FormInfoField
id="endpoint"
:data="data.endpoint ?? $t('client.notConnected')"
:label="$t('client.endpoint')"
:description="$t('client.endpointDesc')"
/>
</FormGroup> </FormGroup>
<FormGroup> <FormGroup>
<FormHeading :description="$t('client.allowedIpsDesc')"> <FormHeading :description="$t('client.allowedIpsDesc')">
+4 -1
View File
@@ -113,7 +113,10 @@
"hooks": "Hooks", "hooks": "Hooks",
"hooksDescription": "Hooks only work with wg-quick", "hooksDescription": "Hooks only work with wg-quick",
"hooksLeaveEmpty": "Only for wg-quick. Otherwise, leave it empty", "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": { "dialog": {
"change": "Change", "change": "Change",
+13 -1
View File
@@ -18,6 +18,18 @@ export default definePermissionEventHandler(
statusMessage: 'Client not found', 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,
};
} }
); );
+11
View File
@@ -93,6 +93,17 @@ class WireGuard {
return clients; 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() { async getAllClients() {
const wgInterface = await Database.interfaces.get(); const wgInterface = await Database.interfaces.get();
const dbClients = await Database.clients.getAllPublic(); const dbClients = await Database.clients.getAllPublic();