ui, server handling improvements

This commit is contained in:
2024-12-23 18:47:22 -08:00
parent 32927dfd55
commit 03fb89dc8b
12 changed files with 106 additions and 115 deletions

View File

@@ -140,7 +140,7 @@ export async function createClient(params: {
username: params.user.username,
pubkey: keys.pubkey,
psk: keys.psk,
allowedIps: getIpsFromIndex(ipAllocationId - 1).join(','),
allowedIps: getIpsFromIndex(ipAllocationId).join(','),
});
const opnsenseResJson = await opnsenseRes.json();
if (opnsenseResJson['result'] !== 'saved') {
@@ -178,6 +178,7 @@ async function getKeys() {
}
export function getIpsFromIndex(ipIndex: number) {
ipIndex -= 1; // 1-indexed in the db
const v4StartingAddr = new Address4(IPV4_STARTING_ADDR);
const v6StartingAddr = new Address6(IPV6_STARTING_ADDR);
const v4Allowed = Address4.fromBigInt(v4StartingAddr.bigInt() + BigInt(ipIndex));

View File

@@ -26,7 +26,7 @@ export const ipAllocations = sqliteTable('ip_allocations', {
// unique for now, only allowing one allocation per client
clientId: integer('client_id')
.unique()
.references(() => wgClients.id),
.references(() => wgClients.id, { onDelete: 'set null' }),
});
export const wgClients = sqliteTable('wg_clients', {