Browse Source

consistent allowedips

pull/1572/head
Bernd Storath 3 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>
<FormHeading>Allowed IPs</FormHeading>
<FormArrayField v-model="data.allowedIPs" name="allowedIPs" />
<FormArrayField v-model="data.allowedIps" name="allowedIps" />
</FormGroup>
<FormGroup>
<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",
"address6": "IPv6 Address must be a valid string",
"address6Min": "IPv6 Address must be a be at least 1 Character",
"allowedIPs": "Allowed IPs must be a valid array of strings",
"allowedIPsMin": "Allowed IPs must have at least 1 item",
"serverAllowedIPs": "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",
"serverAllowedIps": "Allowed IPs must be a valid array of strings",
"name": "Name must be a valid string",
"nameMin": "Name must be at least 1 Character",
"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,
expiresAt: null,
oneTimeLink: null,
allowedIPs: [...db.system.userConfig.allowedIps],
allowedIps: [...db.system.userConfig.allowedIps],
serverAllowedIPs: [],
persistentKeepalive: 0,
address6: address6,

4
src/server/utils/WireGuard.ts

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

10
src/server/utils/types.ts

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

6
src/server/utils/wgHelper.ts

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

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

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

Loading…
Cancel
Save