diff --git a/routes/NextNet API/Forward/Get Inbound Connections.bru b/routes/NextNet API/Forward/Get Inbound Connections.bru new file mode 100644 index 0000000..7111803 --- /dev/null +++ b/routes/NextNet API/Forward/Get Inbound Connections.bru @@ -0,0 +1,18 @@ +meta { + name: Get Inbound Connections + type: http + seq: 6 +} + +post { + url: http://127.0.0.1:3000/api/v1/forward/start + body: json + auth: none +} + +body:json { + { + "token": "914abf2223f84375eed884671bfaefd7755d378af496b345f322214e75b51ed4465f11e26c944914c9b4fcc35c53250325fbc6530853ddfed8f72976d6fc5", + "id": "1" + } +} diff --git a/src/index.ts b/src/index.ts index 056e41a..03fb023 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ import { route as backendCreate } from "./routes/backends/create.js"; import { route as backendRemove } from "./routes/backends/remove.js"; import { route as backendLookup } from "./routes/backends/lookup.js"; +import { route as forwardConnections } from "./routes/forward/connections.js"; import { route as forwardCreate } from "./routes/forward/create.js"; import { route as forwardRemove } from "./routes/forward/remove.js"; import { route as forwardLookup } from "./routes/forward/lookup.js"; @@ -78,6 +79,7 @@ backendCreate(routeOptions); backendRemove(routeOptions); backendLookup(routeOptions); +forwardConnections(routeOptions); forwardCreate(routeOptions); forwardRemove(routeOptions); forwardLookup(routeOptions); diff --git a/src/libs/permissions.ts b/src/libs/permissions.ts index f82e282..92a7454 100644 --- a/src/libs/permissions.ts +++ b/src/libs/permissions.ts @@ -8,6 +8,7 @@ export const permissionListDisabled: Record = { "routes.stop": false, "routes.edit": false, "routes.visible": false, + "routes.visibleConn": false, "backends.add": false, "backends.remove": false, diff --git a/src/routes/forward/connections.ts b/src/routes/forward/connections.ts new file mode 100644 index 0000000..6cfafd0 --- /dev/null +++ b/src/routes/forward/connections.ts @@ -0,0 +1,62 @@ +import { hasPermissionByToken } from "../../libs/permissions.js"; +import type { RouteOptions } from "../../libs/types.js"; + +export function route(routeOptions: RouteOptions) { + const { + fastify, + prisma, + tokens, + backends + } = routeOptions; + + function hasPermission(token: string, permissionList: string[]): Promise { + return hasPermissionByToken(permissionList, token, tokens, prisma); + }; + + fastify.post("/api/v1/forward/connections", { + schema: { + body: { + type: "object", + required: ["token", "id"], + + properties: { + token: { type: "string" }, + id: { type: "number" } + } + } + } + }, async(req, res) => { + // @ts-ignore + const body: { + token: string, + id: number + } = req.body; + + if (!await hasPermission(body.token, [ + "routes.visibleConn" + ])) { + return res.status(403).send({ + error: "Unauthorized" + }); + }; + + const forward = await prisma.forwardRule.findUnique({ + where: { + id: body.id + } + }); + + if (!forward) return res.status(400).send({ + error: "Could not find forward entry" + }); + + if (!backends[forward.destProviderID]) return res.status(400).send({ + error: "Backend not found" + }); + + return { + success: true, + data: backends[forward.destProviderID].getAllConnections() + } + }) +} \ No newline at end of file diff --git a/src/routes/forward/start.ts b/src/routes/forward/start.ts index cb98afa..98bca45 100644 --- a/src/routes/forward/start.ts +++ b/src/routes/forward/start.ts @@ -35,8 +35,6 @@ export function route(routeOptions: RouteOptions) { id: number } = req.body; - console.log(body); - if (!await hasPermission(body.token, [ "routes.start" ])) {