Browse Source

consistent allowedips

pull/1572/head
Bernd Storath 5 months ago
parent
commit
7b7133c1c8
  1. 2
      src/app/pages/clients/[id].vue
  2. 6
      src/i18n/locales/en.json
  3. 2
      src/server/api/setup/migrate.post.ts
  4. 4
      src/server/utils/WireGuard.ts
  5. 10
      src/server/utils/types.ts
  6. 6
      src/server/utils/wgHelper.ts
  7. 2
      src/services/database/repositories/client.ts

2
src/app/pages/clients/[id].vue

@ -37,7 +37,7 @@
</FormGroup> </FormGroup>
<FormGroup> <FormGroup>
<FormHeading>Allowed IPs</FormHeading> <FormHeading>Allowed IPs</FormHeading>
<FormArrayField v-model="data.allowedIPs" name="allowedIPs" /> <FormArrayField v-model="data.allowedIps" name="allowedIps" />
</FormGroup> </FormGroup>
<FormGroup> <FormGroup>
<FormHeading>Server Allowed IPs</FormHeading> <FormHeading>Server Allowed IPs</FormHeading>

6
src/i18n/locales/en.json

@ -47,9 +47,9 @@
"address4Min": "IPv4 Address must be a be at least 1 Character", "address4Min": "IPv4 Address must be a be at least 1 Character",
"address6": "IPv6 Address must be a valid string", "address6": "IPv6 Address must be a valid string",
"address6Min": "IPv6 Address must be a be at least 1 Character", "address6Min": "IPv6 Address must be a be at least 1 Character",
"allowedIPs": "Allowed IPs must be a valid array of strings", "allowedIps": "Allowed IPs must be a valid array of strings",
"allowedIPsMin": "Allowed IPs must have at least 1 item", "allowedIpsMin": "Allowed IPs must have at least 1 item",
"serverAllowedIPs": "Allowed IPs must be a valid array of strings", "serverAllowedIps": "Allowed IPs must be a valid array of strings",
"name": "Name must be a valid string", "name": "Name must be a valid string",
"nameMin": "Name must be at least 1 Character", "nameMin": "Name must be at least 1 Character",
"mtu": "MTU must be a valid number", "mtu": "MTU must be a valid number",

2
src/server/api/setup/migrate.post.ts

@ -74,7 +74,7 @@ export default defineEventHandler(async (event) => {
publicKey: oldClient.publicKey, publicKey: oldClient.publicKey,
expiresAt: null, expiresAt: null,
oneTimeLink: null, oneTimeLink: null,
allowedIPs: [...db.system.userConfig.allowedIps], allowedIps: [...db.system.userConfig.allowedIps],
serverAllowedIPs: [], serverAllowedIPs: [],
persistentKeepalive: 0, persistentKeepalive: 0,
address6: address6, address6: address6,

4
src/server/utils/WireGuard.ts

@ -61,7 +61,7 @@ class WireGuard {
createdAt: new Date(client.createdAt), createdAt: new Date(client.createdAt),
updatedAt: new Date(client.updatedAt), updatedAt: new Date(client.updatedAt),
expiresAt: client.expiresAt, expiresAt: client.expiresAt,
allowedIPs: client.allowedIPs, allowedIps: client.allowedIps,
oneTimeLink: client.oneTimeLink, oneTimeLink: client.oneTimeLink,
persistentKeepalive: null as string | null, persistentKeepalive: null as string | null,
latestHandshakeAt: null as Date | null, latestHandshakeAt: null as Date | null,
@ -156,7 +156,7 @@ class WireGuard {
oneTimeLink: null, oneTimeLink: null,
expiresAt: null, expiresAt: null,
enabled: true, enabled: true,
allowedIPs: [...system.userConfig.allowedIps], allowedIps: [...system.userConfig.allowedIps],
serverAllowedIPs: [], serverAllowedIPs: [],
persistentKeepalive: system.userConfig.persistentKeepalive, persistentKeepalive: system.userConfig.persistentKeepalive,
mtu: system.userConfig.mtu, mtu: system.userConfig.mtu,

10
src/server/utils/types.ts

@ -143,9 +143,9 @@ const address6 = z
.min(1, { message: 'zod.address6Min' }) .min(1, { message: 'zod.address6Min' })
.pipe(safeStringRefine); .pipe(safeStringRefine);
const allowedIPs = z const allowedIps = z
.array(address, { message: 'zod.allowedIPs' }) .array(address, { message: 'zod.allowedIps' })
.min(1, { message: 'zod.allowedIPsMin' }); .min(1, { message: 'zod.allowedIpsMin' });
const mtu = z const mtu = z
.number({ message: 'zod.mtu' }) .number({ message: 'zod.mtu' })
@ -163,7 +163,7 @@ export const clientUpdateType = z.object({
expiresAt: expireDate, expiresAt: expireDate,
address4: address4, address4: address4,
address6: address6, address6: address6,
allowedIPs: allowedIPs, allowedIps: allowedIps,
serverAllowedIPs: z.array(address, { message: 'zod.serverAllowedIPs' }), serverAllowedIPs: z.array(address, { message: 'zod.serverAllowedIPs' }),
mtu: mtu, mtu: mtu,
persistentKeepalive: persistentKeepalive, persistentKeepalive: persistentKeepalive,
@ -182,7 +182,7 @@ export const interfaceUpdateType = z.object({
export const userConfigUpdateType = z.object({ export const userConfigUpdateType = z.object({
host: host, host: host,
port: port, port: port,
allowedIps: allowedIPs, allowedIps: allowedIps,
defaultDns: z.array(address, { message: 'zod.dns' }), defaultDns: z.array(address, { message: 'zod.dns' }),
mtu: mtu, mtu: mtu,
persistentKeepalive: persistentKeepalive, persistentKeepalive: persistentKeepalive,

6
src/server/utils/wgHelper.ts

@ -55,7 +55,7 @@ MTU = ${client.mtu}
[Peer] [Peer]
PublicKey = ${system.interface.publicKey} PublicKey = ${system.interface.publicKey}
PresharedKey = ${client.preSharedKey} PresharedKey = ${client.preSharedKey}
AllowedIPs = ${client.allowedIPs.join(', ')} AllowedIPs = ${client.allowedIps.join(', ')}
PersistentKeepalive = ${client.persistentKeepalive} PersistentKeepalive = ${client.persistentKeepalive}
Endpoint = ${system.userConfig.host}:${system.userConfig.port}`; Endpoint = ${system.userConfig.host}:${system.userConfig.port}`;
}, },
@ -112,7 +112,7 @@ Endpoint = ${system.userConfig.host}:${system.userConfig.port}`;
publicKey, publicKey,
preSharedKey, preSharedKey,
endpoint, endpoint,
allowedIPs, allowedIps,
latestHandshakeAt, latestHandshakeAt,
transferRx, transferRx,
transferTx, transferTx,
@ -123,7 +123,7 @@ Endpoint = ${system.userConfig.host}:${system.userConfig.port}`;
publicKey, publicKey,
preSharedKey, preSharedKey,
endpoint: endpoint === '(none)' ? null : endpoint, endpoint: endpoint === '(none)' ? null : endpoint,
allowedIPs, allowedIps,
latestHandshakeAt: latestHandshakeAt:
latestHandshakeAt === '0' latestHandshakeAt === '0'
? null ? null

2
src/services/database/repositories/client.ts

@ -16,7 +16,7 @@ export type Client = {
preSharedKey: string; preSharedKey: string;
/** ISO String */ /** ISO String */
expiresAt: string | null; expiresAt: string | null;
allowedIPs: string[]; allowedIps: string[];
serverAllowedIPs: string[]; serverAllowedIPs: string[];
oneTimeLink: OneTimeLink | null; oneTimeLink: OneTimeLink | null;
/** ISO String */ /** ISO String */

Loading…
Cancel
Save