Update the remote subnets

This commit is contained in:
Owen
2025-11-20 15:17:48 -05:00
parent 3750c36aa7
commit 9420b41e39
4 changed files with 113 additions and 11 deletions

View File

@@ -1,5 +1,7 @@
import { sendToClient } from "#dynamic/routers/ws";
import { db, olms } from "@server/db";
import { SubnetProxyTarget } from "@server/lib/ip";
import { eq } from "drizzle-orm";
export async function addTargets(newtId: string, targets: SubnetProxyTarget[]) {
await sendToClient(newtId, {
@@ -21,8 +23,8 @@ export async function removeTargets(
export async function updateTargets(
newtId: string,
targets: {
oldTargets: SubnetProxyTarget[],
newTargets: SubnetProxyTarget[]
oldTargets: SubnetProxyTarget[];
newTargets: SubnetProxyTarget[];
}
) {
await sendToClient(newtId, {
@@ -30,3 +32,57 @@ export async function updateTargets(
data: targets
});
}
export async function addRemoteSubnets(
clientId: number,
siteId: number,
remoteSubnets: string[],
olmId?: string
) {
if (!olmId) {
const [olm] = await db
.select()
.from(olms)
.where(eq(olms.clientId, clientId))
.limit(1);
if (!olm) {
throw new Error(`Olm with ID ${clientId} not found`);
}
olmId = olm.olmId;
}
await sendToClient(olmId, {
type: `olm/wg/peer/add-remote-subnets`,
data: {
siteId: siteId,
remoteSubnets: remoteSubnets
}
});
}
export async function removeRemoteSubnets(
clientId: number,
siteId: number,
remoteSubnets: string[],
olmId?: string
) {
if (!olmId) {
const [olm] = await db
.select()
.from(olms)
.where(eq(olms.clientId, clientId))
.limit(1);
if (!olm) {
throw new Error(`Olm with ID ${clientId} not found`);
}
olmId = olm.olmId;
}
await sendToClient(olmId, {
type: `olm/wg/peer/remove-remote-subnets`,
data: {
siteId: siteId,
remoteSubnets: remoteSubnets
}
});
}