From ff59bcf52483637d002a3c2528856a1259d38d2b Mon Sep 17 00:00:00 2001 From: Bernd Storath <999999bst@gmail.com> Date: Thu, 13 Mar 2025 10:58:24 +0100 Subject: [PATCH] change userconfig and interface port on setup, note users afterwards --- src/i18n/locales/en.json | 6 ++-- .../repositories/userConfig/service.ts | 30 +++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 14633e3a..a4203365 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -46,7 +46,7 @@ "createAccount": "Create Account", "successful": "Setup successful", "hostDesc": "Public hostname clients will connect to", - "portDesc": "Public UDP port clients will connect to (same as port mapping)" + "portDesc": "Public UDP port clients will connect to and WireGuard will listen on" }, "update": { "updateAvailable": "There is an update available!", @@ -143,7 +143,7 @@ "config": { "connection": "Connection", "hostDesc": "Public hostname clients will connect to (invalidates config)", - "portDesc": "Public UDP port clients will connect to (invalidates config)", + "portDesc": "Public UDP port clients will connect to (invalidates config, you probably want to change Interface Port too)", "allowedIpsDesc": "Allowed IPs clients will use (global config)", "dnsDesc": "DNS server clients will use (global config)", "mtuDesc": "MTU clients will use (only for new clients)", @@ -155,7 +155,7 @@ "device": "Device", "deviceDesc": "Ethernet device the wireguard traffic should be forwarded through", "mtuDesc": "MTU WireGuard will use", - "portDesc": "UDP Port WireGuard will listen on (could invalidate config)", + "portDesc": "UDP Port WireGuard will listen on (you probably want to change Config Port too)", "changeCidr": "Change CIDR" }, "introText": "Welcome to the admin panel.\n\nHere you can manage the general settings, the configuration, the interface settings and the hooks.\n\nStart by choosing one of the sections in the sidebar." diff --git a/src/server/database/repositories/userConfig/service.ts b/src/server/database/repositories/userConfig/service.ts index 791c7fc7..4004d60e 100644 --- a/src/server/database/repositories/userConfig/service.ts +++ b/src/server/database/repositories/userConfig/service.ts @@ -1,6 +1,7 @@ import { eq, sql } from 'drizzle-orm'; import { userConfig } from './schema'; import type { UserConfigUpdateType } from './types'; +import { wgInterface } from '#db/schema'; import type { DBType } from '#db/sqlite'; function createPreparedStatement(db: DBType) { @@ -8,14 +9,6 @@ function createPreparedStatement(db: DBType) { get: db.query.userConfig .findFirst({ where: eq(userConfig.id, sql.placeholder('interface')) }) .prepare(), - updateHostPort: db - .update(userConfig) - .set({ - host: sql.placeholder('host') as never as string, - port: sql.placeholder('port') as never as number, - }) - .where(eq(userConfig.id, sql.placeholder('interface'))) - .prepare(), }; } @@ -40,11 +33,24 @@ export class UserConfigService { // TODO: wrap ipv6 host in square brackets + /** + * sets host of user config + * + * sets port of user config and interface + */ updateHostPort(host: string, port: number) { - return this.#statements.updateHostPort.execute({ - interface: 'wg0', - host, - port, + return this.#db.transaction(async (tx) => { + await tx + .update(userConfig) + .set({ host, port }) + .where(eq(userConfig.id, 'wg0')) + .execute(); + + await tx + .update(wgInterface) + .set({ port }) + .where(eq(wgInterface.name, 'wg0')) + .execute(); }); }