Browse Source

minor fixes

pull/1714/head
Bernd Storath 5 months ago
parent
commit
f6a32f202d
  1. 2
      src/app/components/Form/ArrayField.vue
  2. 4
      src/i18n/locales/en.json
  3. 24
      src/server/database/repositories/client/types.ts
  4. 10
      src/server/database/repositories/hooks/types.ts
  5. 4
      src/server/utils/types.ts
  6. 14
      src/server/utils/wgHelper.ts

2
src/app/components/Form/ArrayField.vue

@ -3,7 +3,7 @@
<div v-if="data?.length === 0">
{{ emptyText || $t('form.noItems') }}
</div>
<div v-for="(item, i) in data" :key="i">
<div v-for="(item, i) in data" v-else :key="i">
<div class="mt-1 flex flex-row gap-1">
<input
:value="item"

4
src/i18n/locales/en.json

@ -100,8 +100,8 @@
"mtuDesc": "Sets the maximum transmission unit (packet size) for the VPN tunnel",
"persistentKeepaliveDesc": "Sets the interval (in seconds) for keep-alive packets. 0 disables it",
"hooks": "Hooks",
"hooksDescription": "Hooks only works with wg-quick",
"hooksLeaveEmpty": "Only for wg-quick. Otherwise, please leave it empty"
"hooksDescription": "Hooks only work with wg-quick",
"hooksLeaveEmpty": "Only for wg-quick. Otherwise, leave it empty"
},
"dialog": {
"change": "Change",

24
src/server/database/repositories/client/types.ts

@ -39,22 +39,6 @@ const address6 = z
.min(1, { message: t('zod.client.address6') })
.pipe(safeStringRefine);
const preUp = z
.string({ message: t('zod.client.preUp') })
.pipe(safeStringRefine);
const postUp = z
.string({ message: t('zod.client.postUp') })
.pipe(safeStringRefine);
const preDown = z
.string({ message: t('zod.client.preDown') })
.pipe(safeStringRefine);
const postDown = z
.string({ message: t('zod.client.postDown') })
.pipe(safeStringRefine);
const serverAllowedIps = z.array(AddressSchema, {
message: t('zod.client.serverAllowedIps'),
});
@ -73,10 +57,10 @@ export const ClientUpdateSchema = schemaForType<UpdateClientType>()(
expiresAt: expiresAt,
ipv4Address: address4,
ipv6Address: address6,
preUp: preUp,
postUp: postUp,
preDown: preDown,
postDown: postDown,
preUp: HookSchema,
postUp: HookSchema,
preDown: HookSchema,
postDown: HookSchema,
allowedIps: AllowedIpsSchema,
serverAllowedIps: serverAllowedIps,
mtu: MtuSchema,

10
src/server/database/repositories/hooks/types.ts

@ -6,13 +6,11 @@ export type HooksType = InferSelectModel<typeof hooks>;
export type HooksUpdateType = Omit<HooksType, 'id' | 'createdAt' | 'updatedAt'>;
const hook = z.string({ message: t('zod.hook') }).pipe(safeStringRefine);
export const HooksUpdateSchema = schemaForType<HooksUpdateType>()(
z.object({
preUp: hook,
postUp: hook,
preDown: hook,
postDown: hook,
preUp: HookSchema,
postUp: HookSchema,
preDown: HookSchema,
postDown: HookSchema,
})
);

4
src/server/utils/types.ts

@ -52,6 +52,10 @@ export const FileSchema = z.object({
file: z.string({ message: t('zod.file') }),
});
export const HookSchema = z
.string({ message: t('zod.hook') })
.pipe(safeStringRefine);
export const schemaForType =
<T>() =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any

14
src/server/utils/wgHelper.ts

@ -49,17 +49,19 @@ PostDown = ${iptablesTemplate(hooks.postDown, wgInterface)}`;
const cidr4Block = parseCidr(wgInterface.ipv4Cidr).prefix;
const cidr6Block = parseCidr(wgInterface.ipv6Cidr).prefix;
const hookLines = [
client.preUp ? `PreUp = ${client.preUp}` : null,
client.postUp ? `PostUp = ${client.postUp}` : null,
client.preDown ? `PreDown = ${client.preDown}` : null,
client.postDown ? `PostDown = ${client.postDown}` : null,
].filter((v) => v !== null);
return `[Interface]
PrivateKey = ${client.privateKey}
Address = ${client.ipv4Address}/${cidr4Block}, ${client.ipv6Address}/${cidr6Block}
DNS = ${client.dns.join(', ')}
MTU = ${client.mtu}
${client.preUp ? `PreUp = ${client.preUp}\n` : ''}${
client.postUp ? `PostUp = ${client.postUp}\n` : ''
}${client.preDown ? `PreDown = ${client.preDown}\n` : ''}${
client.postDown ? `PostDown = ${client.postDown}\n` : ''
}
${hookLines.length ? `${hookLines.join('\n')}\n` : ''}
[Peer]
PublicKey = ${wgInterface.publicKey}
PresharedKey = ${client.preSharedKey}

Loading…
Cancel
Save