Working on updating targets

This commit is contained in:
Owen
2025-11-17 20:44:39 -05:00
parent dbb1e37033
commit 97c707248e
7 changed files with 149 additions and 187 deletions

View File

@@ -1,35 +1,30 @@
import { sendToClient } from "#dynamic/routers/ws";
import { SubnetProxyTarget } from "@server/lib/ip";
export async function addTargets(
newtId: string,
destinationIp: string,
destinationPort: number,
protocol: string,
port: number
) {
const target = `${port}:${destinationIp}:${destinationPort}`;
export async function addTarget(newtId: string, target: SubnetProxyTarget) {
await sendToClient(newtId, {
type: `newt/wg/${protocol}/add`,
data: {
targets: [target] // We can only use one target for WireGuard right now
}
type: `newt/wg/target/add`,
data: target
});
}
export async function removeTargets(
newtId: string,
destinationIp: string,
destinationPort: number,
protocol: string,
port: number
) {
const target = `${port}:${destinationIp}:${destinationPort}`;
export async function removeTarget(newtId: string, target: SubnetProxyTarget) {
await sendToClient(newtId, {
type: `newt/wg/${protocol}/remove`,
data: {
targets: [target] // We can only use one target for WireGuard right now
}
type: `newt/wg/target/remove`,
data: target
});
}
export async function updateTarget(
newtId: string,
oldTarget: SubnetProxyTarget,
newTarget: SubnetProxyTarget
) {
await sendToClient(newtId, {
type: `newt/wg/target/update`,
data: {
oldTarget,
newTarget
}
});
}