Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e5fb6ff3a6 | |||
| fcb5049dab |
@@ -6,7 +6,7 @@
|
||||
class="fixed inset-0 z-30 bg-gray-500 opacity-75 dark:bg-black dark:opacity-50"
|
||||
/>
|
||||
<DialogContent
|
||||
class="fixed left-1/2 top-1/2 z-[100] max-h-[85vh] w-[90vw] max-w-md -translate-x-1/2 -translate-y-1/2 rounded-md p-6 shadow-2xl focus:outline-none dark:bg-neutral-700"
|
||||
class="fixed left-1/2 top-1/2 z-[100] max-h-[85vh] w-[90vw] max-w-md -translate-x-1/2 -translate-y-1/2 rounded-md bg-white p-6 shadow-2xl focus:outline-none dark:bg-neutral-700"
|
||||
>
|
||||
<DialogTitle
|
||||
class="m-0 text-lg font-semibold text-gray-900 dark:text-neutral-200"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<template>
|
||||
<div class="flex flex-col gap-2">
|
||||
<div v-if="data?.length === 0">
|
||||
{{ emptyText || $t('form.noItems') }}
|
||||
</div>
|
||||
<div v-else class="flex flex-col gap-2">
|
||||
<div v-for="(item, i) in data" :key="i">
|
||||
<div class="flex flex-row gap-1">
|
||||
<div v-for="(item, i) in data" v-else :key="i">
|
||||
<div class="mt-1 flex flex-row gap-1">
|
||||
<input
|
||||
:value="item"
|
||||
:name="name"
|
||||
@@ -12,13 +12,20 @@
|
||||
class="rounded-lg border-2 border-gray-100 text-gray-500 focus:border-red-800 focus:outline-0 focus:ring-0 dark:border-neutral-800 dark:bg-neutral-700 dark:text-neutral-200 dark:placeholder:text-neutral-400"
|
||||
@input="update($event, i)"
|
||||
/>
|
||||
<BaseButton as="input" type="button" value="-" @click="del(i)" />
|
||||
<BaseButton
|
||||
as="input"
|
||||
type="button"
|
||||
class="rounded-lg"
|
||||
value="-"
|
||||
@click="del(i)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<BaseButton
|
||||
as="input"
|
||||
type="button"
|
||||
class="rounded-lg"
|
||||
:value="$t('form.add')"
|
||||
@click="add"
|
||||
/>
|
||||
|
||||
@@ -2,10 +2,26 @@
|
||||
<main v-if="data">
|
||||
<FormElement @submit.prevent="submit">
|
||||
<FormGroup>
|
||||
<FormTextField id="PreUp" v-model="data.preUp" label="PreUp" />
|
||||
<FormTextField id="PostUp" v-model="data.postUp" label="PostUp" />
|
||||
<FormTextField id="PreDown" v-model="data.preDown" label="PreDown" />
|
||||
<FormTextField id="PostDown" v-model="data.postDown" label="PostDown" />
|
||||
<FormTextField
|
||||
id="PreUp"
|
||||
v-model="data.preUp"
|
||||
:label="$t('hooks.preUp')"
|
||||
/>
|
||||
<FormTextField
|
||||
id="PostUp"
|
||||
v-model="data.postUp"
|
||||
:label="$t('hooks.postUp')"
|
||||
/>
|
||||
<FormTextField
|
||||
id="PreDown"
|
||||
v-model="data.preDown"
|
||||
:label="$t('hooks.preDown')"
|
||||
/>
|
||||
<FormTextField
|
||||
id="PostDown"
|
||||
v-model="data.postDown"
|
||||
:label="$t('hooks.postDown')"
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<FormHeading>{{ $t('form.actions') }}</FormHeading>
|
||||
|
||||
@@ -71,6 +71,35 @@
|
||||
:label="$t('general.persistentKeepalive')"
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<FormHeading :description="$t('client.hooksDescription')">
|
||||
{{ $t('client.hooks') }}
|
||||
</FormHeading>
|
||||
<FormTextField
|
||||
id="PreUp"
|
||||
v-model="data.preUp"
|
||||
:description="$t('client.hooksLeaveEmpty')"
|
||||
:label="$t('hooks.preUp')"
|
||||
/>
|
||||
<FormTextField
|
||||
id="PostUp"
|
||||
v-model="data.postUp"
|
||||
:description="$t('client.hooksLeaveEmpty')"
|
||||
:label="$t('hooks.postUp')"
|
||||
/>
|
||||
<FormTextField
|
||||
id="PreDown"
|
||||
v-model="data.preDown"
|
||||
:description="$t('client.hooksLeaveEmpty')"
|
||||
:label="$t('hooks.preDown')"
|
||||
/>
|
||||
<FormTextField
|
||||
id="PostDown"
|
||||
v-model="data.postDown"
|
||||
:description="$t('client.hooksLeaveEmpty')"
|
||||
:label="$t('hooks.postDown')"
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<FormHeading>{{ $t('form.actions') }}</FormHeading>
|
||||
<FormActionField type="submit" :label="$t('form.save')" />
|
||||
|
||||
@@ -98,7 +98,10 @@
|
||||
"allowedIpsDesc": "Which IPs will be routed through the VPN",
|
||||
"serverAllowedIpsDesc": "Which IPs the server will route to the client",
|
||||
"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"
|
||||
"persistentKeepaliveDesc": "Sets the interval (in seconds) for keep-alive packets. 0 disables it",
|
||||
"hooks": "Hooks",
|
||||
"hooksDescription": "Hooks only work with wg-quick",
|
||||
"hooksLeaveEmpty": "Only for wg-quick. Otherwise, leave it empty"
|
||||
},
|
||||
"dialog": {
|
||||
"change": "Change",
|
||||
@@ -208,5 +211,11 @@
|
||||
"dns": "DNS",
|
||||
"allowedIps": "Allowed IPs",
|
||||
"file": "File"
|
||||
},
|
||||
"hooks": {
|
||||
"preUp": "PreUp",
|
||||
"postUp": "PostUp",
|
||||
"preDown": "PreDown",
|
||||
"postDown": "PostDown"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,10 @@ CREATE TABLE `clients_table` (
|
||||
`name` text NOT NULL,
|
||||
`ipv4_address` text NOT NULL,
|
||||
`ipv6_address` text NOT NULL,
|
||||
`pre_up` text DEFAULT '' NOT NULL,
|
||||
`post_up` text DEFAULT '' NOT NULL,
|
||||
`pre_down` text DEFAULT '' NOT NULL,
|
||||
`post_down` text DEFAULT '' NOT NULL,
|
||||
`private_key` text NOT NULL,
|
||||
`public_key` text NOT NULL,
|
||||
`pre_shared_key` text NOT NULL,
|
||||
@@ -60,13 +64,12 @@ CREATE TABLE `interfaces_table` (
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `interfaces_table_port_unique` ON `interfaces_table` (`port`);--> statement-breakpoint
|
||||
CREATE TABLE `one_time_links_table` (
|
||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`id` integer PRIMARY KEY NOT NULL,
|
||||
`one_time_link` text NOT NULL,
|
||||
`expires_at` text NOT NULL,
|
||||
`client_id` integer NOT NULL,
|
||||
`created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
|
||||
`updated_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
|
||||
FOREIGN KEY (`client_id`) REFERENCES `clients_table`(`id`) ON UPDATE cascade ON DELETE cascade
|
||||
FOREIGN KEY (`id`) REFERENCES `clients_table`(`id`) ON UPDATE cascade ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `one_time_links_table_one_time_link_unique` ON `one_time_links_table` (`one_time_link`);--> statement-breakpoint
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "b1dde023-d141-4eab-9226-89a832b2ed2b",
|
||||
"id": "383501e4-f8de-4413-847f-a9082f6dc398",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"tables": {
|
||||
"clients_table": {
|
||||
@@ -42,6 +42,38 @@
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"pre_up": {
|
||||
"name": "pre_up",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "''"
|
||||
},
|
||||
"post_up": {
|
||||
"name": "post_up",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "''"
|
||||
},
|
||||
"pre_down": {
|
||||
"name": "pre_down",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "''"
|
||||
},
|
||||
"post_down": {
|
||||
"name": "post_down",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "''"
|
||||
},
|
||||
"private_key": {
|
||||
"name": "private_key",
|
||||
"type": "text",
|
||||
@@ -420,7 +452,7 @@
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
"autoincrement": false
|
||||
},
|
||||
"one_time_link": {
|
||||
"name": "one_time_link",
|
||||
@@ -436,13 +468,6 @@
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"client_id": {
|
||||
"name": "client_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "text",
|
||||
@@ -470,12 +495,12 @@
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"one_time_links_table_client_id_clients_table_id_fk": {
|
||||
"name": "one_time_links_table_client_id_clients_table_id_fk",
|
||||
"one_time_links_table_id_clients_table_id_fk": {
|
||||
"name": "one_time_links_table_id_clients_table_id_fk",
|
||||
"tableFrom": "one_time_links_table",
|
||||
"tableTo": "clients_table",
|
||||
"columnsFrom": [
|
||||
"client_id"
|
||||
"id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "720d420c-361f-4427-a45b-db0ca613934d",
|
||||
"prevId": "b1dde023-d141-4eab-9226-89a832b2ed2b",
|
||||
"id": "bf316694-e2ce-4e29-bd66-ce6c0a9d3c90",
|
||||
"prevId": "383501e4-f8de-4413-847f-a9082f6dc398",
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"tables": {
|
||||
@@ -42,6 +42,38 @@
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"pre_up": {
|
||||
"name": "pre_up",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "''"
|
||||
},
|
||||
"post_up": {
|
||||
"name": "post_up",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "''"
|
||||
},
|
||||
"pre_down": {
|
||||
"name": "pre_down",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "''"
|
||||
},
|
||||
"post_down": {
|
||||
"name": "post_down",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "''"
|
||||
},
|
||||
"private_key": {
|
||||
"name": "private_key",
|
||||
"type": "text",
|
||||
@@ -420,7 +452,7 @@
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
"autoincrement": false
|
||||
},
|
||||
"one_time_link": {
|
||||
"name": "one_time_link",
|
||||
@@ -436,13 +468,6 @@
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"client_id": {
|
||||
"name": "client_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "text",
|
||||
@@ -470,11 +495,11 @@
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"one_time_links_table_client_id_clients_table_id_fk": {
|
||||
"name": "one_time_links_table_client_id_clients_table_id_fk",
|
||||
"one_time_links_table_id_clients_table_id_fk": {
|
||||
"name": "one_time_links_table_id_clients_table_id_fk",
|
||||
"tableFrom": "one_time_links_table",
|
||||
"columnsFrom": [
|
||||
"client_id"
|
||||
"id"
|
||||
],
|
||||
"tableTo": "clients_table",
|
||||
"columnsTo": [
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "6",
|
||||
"when": 1739266828300,
|
||||
"when": 1741335144499,
|
||||
"tag": "0000_short_skin",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "6",
|
||||
"when": 1739266837347,
|
||||
"when": 1741335153054,
|
||||
"tag": "0001_classy_the_stranger",
|
||||
"breakpoints": true
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@ export const client = sqliteTable('clients_table', {
|
||||
name: text().notNull(),
|
||||
ipv4Address: text('ipv4_address').notNull().unique(),
|
||||
ipv6Address: text('ipv6_address').notNull().unique(),
|
||||
preUp: text('pre_up').default('').notNull(),
|
||||
postUp: text('post_up').default('').notNull(),
|
||||
preDown: text('pre_down').default('').notNull(),
|
||||
postDown: text('post_down').default('').notNull(),
|
||||
privateKey: text('private_key').notNull(),
|
||||
publicKey: text('public_key').notNull(),
|
||||
preSharedKey: text('pre_shared_key').notNull(),
|
||||
@@ -38,7 +42,7 @@ export const client = sqliteTable('clients_table', {
|
||||
export const clientsRelations = relations(client, ({ one }) => ({
|
||||
oneTimeLink: one(oneTimeLink, {
|
||||
fields: [client.id],
|
||||
references: [oneTimeLink.clientId],
|
||||
references: [oneTimeLink.id],
|
||||
}),
|
||||
user: one(user, {
|
||||
fields: [client.userId],
|
||||
|
||||
@@ -57,6 +57,10 @@ export const ClientUpdateSchema = schemaForType<UpdateClientType>()(
|
||||
expiresAt: expiresAt,
|
||||
ipv4Address: address4,
|
||||
ipv6Address: address6,
|
||||
preUp: HookSchema,
|
||||
postUp: HookSchema,
|
||||
preDown: HookSchema,
|
||||
postDown: HookSchema,
|
||||
allowedIps: AllowedIpsSchema,
|
||||
serverAllowedIps: serverAllowedIps,
|
||||
mtu: MtuSchema,
|
||||
|
||||
@@ -4,6 +4,7 @@ import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
|
||||
import { wgInterface } from '../../schema';
|
||||
|
||||
export const hooks = sqliteTable('hooks_table', {
|
||||
/** same as `wgInterface.name` */
|
||||
id: text()
|
||||
.primaryKey()
|
||||
.references(() => wgInterface.name, {
|
||||
|
||||
@@ -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,12 +4,15 @@ import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core';
|
||||
import { client } from '../../schema';
|
||||
|
||||
export const oneTimeLink = sqliteTable('one_time_links_table', {
|
||||
id: int().primaryKey({ autoIncrement: true }),
|
||||
/** same as `client.id` */
|
||||
id: int()
|
||||
.primaryKey()
|
||||
.references(() => client.id, {
|
||||
onDelete: 'cascade',
|
||||
onUpdate: 'cascade',
|
||||
}),
|
||||
oneTimeLink: text('one_time_link').notNull().unique(),
|
||||
expiresAt: text('expires_at').notNull(),
|
||||
clientId: int('client_id')
|
||||
.notNull()
|
||||
.references(() => client.id, { onDelete: 'cascade', onUpdate: 'cascade' }),
|
||||
createdAt: text('created_at')
|
||||
.notNull()
|
||||
.default(sql`(CURRENT_TIMESTAMP)`),
|
||||
@@ -21,7 +24,7 @@ export const oneTimeLink = sqliteTable('one_time_links_table', {
|
||||
|
||||
export const oneTimeLinksRelations = relations(oneTimeLink, ({ one }) => ({
|
||||
client: one(client, {
|
||||
fields: [oneTimeLink.clientId],
|
||||
fields: [oneTimeLink.id],
|
||||
references: [client.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
@@ -12,7 +12,7 @@ function createPreparedStatement(db: DBType) {
|
||||
create: db
|
||||
.insert(oneTimeLink)
|
||||
.values({
|
||||
clientId: sql.placeholder('id'),
|
||||
id: sql.placeholder('id'),
|
||||
oneTimeLink: sql.placeholder('oneTimeLink'),
|
||||
expiresAt: sql.placeholder('expiresAt'),
|
||||
})
|
||||
@@ -20,7 +20,12 @@ function createPreparedStatement(db: DBType) {
|
||||
erase: db
|
||||
.update(oneTimeLink)
|
||||
.set({ expiresAt: sql.placeholder('expiresAt') as never as string })
|
||||
.where(eq(oneTimeLink.clientId, sql.placeholder('id')))
|
||||
.where(eq(oneTimeLink.id, sql.placeholder('id')))
|
||||
.prepare(),
|
||||
findByOneTimeLink: db.query.oneTimeLink
|
||||
.findFirst({
|
||||
where: eq(oneTimeLink.oneTimeLink, sql.placeholder('oneTimeLink')),
|
||||
})
|
||||
.prepare(),
|
||||
};
|
||||
}
|
||||
@@ -36,6 +41,10 @@ export class OneTimeLinkService {
|
||||
return this.#statements.delete.execute({ id });
|
||||
}
|
||||
|
||||
getByOtl(oneTimeLink: string) {
|
||||
return this.#statements.findByOneTimeLink.execute({ oneTimeLink });
|
||||
}
|
||||
|
||||
generate(id: ID) {
|
||||
const key = `${id}-${Math.floor(Math.random() * 1000)}`;
|
||||
const oneTimeLink = Math.abs(CRC32.str(key)).toString(16);
|
||||
@@ -45,7 +54,7 @@ export class OneTimeLinkService {
|
||||
}
|
||||
|
||||
erase(id: ID) {
|
||||
const expiresAt = Date.now() + 10 * 1000;
|
||||
const expiresAt = new Date(Date.now() + 10 * 1000).toISOString();
|
||||
return this.#statements.erase.execute({ id, expiresAt });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { wgInterface } from '../../schema';
|
||||
|
||||
// default* means clients store it themselves
|
||||
export const userConfig = sqliteTable('user_configs_table', {
|
||||
/** same as `wgInterface.name` */
|
||||
id: text()
|
||||
.primaryKey()
|
||||
.references(() => wgInterface.name, {
|
||||
|
||||
@@ -5,20 +5,28 @@ export default defineEventHandler(async (event) => {
|
||||
event,
|
||||
validateZod(OneTimeLinkGetSchema, event)
|
||||
);
|
||||
const clients = await WireGuard.getAllClients();
|
||||
// TODO: filter on the database level
|
||||
const client = clients.find(
|
||||
(client) => client.oneTimeLink?.oneTimeLink === oneTimeLink
|
||||
);
|
||||
|
||||
const otl = await Database.oneTimeLinks.getByOtl(oneTimeLink);
|
||||
if (!otl) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: 'Invalid One Time Link',
|
||||
});
|
||||
}
|
||||
|
||||
const client = await Database.clients.get(otl.id);
|
||||
if (!client) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
statusMessage: 'Invalid One Time Link',
|
||||
});
|
||||
}
|
||||
const clientId = client.id;
|
||||
const config = await WireGuard.getClientConfiguration({ clientId });
|
||||
await Database.oneTimeLinks.erase(clientId);
|
||||
|
||||
const config = await WireGuard.getClientConfiguration({
|
||||
clientId: client.id,
|
||||
});
|
||||
await Database.oneTimeLinks.erase(otl.id);
|
||||
|
||||
setHeader(
|
||||
event,
|
||||
'Content-Disposition',
|
||||
|
||||
@@ -212,8 +212,8 @@ class WireGuard {
|
||||
client.oneTimeLink !== null &&
|
||||
new Date() > new Date(client.oneTimeLink.expiresAt)
|
||||
) {
|
||||
WG_DEBUG(`Client ${client.id} One Time Link expired.`);
|
||||
await Database.oneTimeLinks.delete(client.oneTimeLink.id);
|
||||
WG_DEBUG(`OneTimeLink for Client ${client.id} expired.`);
|
||||
await Database.oneTimeLinks.delete(client.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,11 +222,10 @@ class WireGuard {
|
||||
}
|
||||
|
||||
if (OLD_ENV.PASSWORD || OLD_ENV.PASSWORD_HASH) {
|
||||
// TODO: change url before release
|
||||
throw new Error(
|
||||
`
|
||||
You are using an invalid Configuration for wg-easy
|
||||
Please follow the instructions on https://wg-easy.github.io/wg-easy/ to migrate
|
||||
Please follow the instructions on https://wg-easy.github.io/wg-easy/latest/advanced/migrate/from-14-to-15/ to migrate
|
||||
`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -49,12 +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}
|
||||
|
||||
${hookLines.length ? `${hookLines.join('\n')}\n` : ''}
|
||||
[Peer]
|
||||
PublicKey = ${wgInterface.publicKey}
|
||||
PresharedKey = ${client.preSharedKey}
|
||||
|
||||
Reference in New Issue
Block a user