diff --git a/config/db/db.sqlite.bak b/config/db/db.sqlite.bak new file mode 100644 index 00000000..9d0b3db3 Binary files /dev/null and b/config/db/db.sqlite.bak differ diff --git a/server/routers/site/createSite.ts b/server/routers/site/createSite.ts index 391b6234..60e34465 100644 --- a/server/routers/site/createSite.ts +++ b/server/routers/site/createSite.ts @@ -148,7 +148,7 @@ export async function createSite( ) ); } - + if (!isIpInCidr(address, org.subnet)) { return next( createHttpError( @@ -157,35 +157,45 @@ export async function createSite( ) ); } - + updatedAddress = `${address}/${org.subnet.split("/")[1]}`; // we want the block size of the whole org - + // make sure the subnet is unique const addressExistsSites = await db .select() .from(sites) - .where(eq(sites.address, updatedAddress)) + .where( + and( + eq(sites.address, updatedAddress), + eq(sites.orgId, orgId) + ) + ) .limit(1); - + if (addressExistsSites.length > 0) { return next( createHttpError( HttpCode.CONFLICT, - `Subnet ${subnet} already exists` + `Subnet ${updatedAddress} already exists in sites` ) ); } - + const addressExistsClients = await db .select() .from(clients) - .where(eq(clients.subnet, updatedAddress)) + .where( + and( + eq(clients.subnet, updatedAddress), + eq(clients.orgId, orgId) + ) + ) .limit(1); if (addressExistsClients.length > 0) { return next( createHttpError( HttpCode.CONFLICT, - `Subnet ${subnet} already exists` + `Subnet ${updatedAddress} already exists in clients` ) ); }