feature: Adds way to get inbound connections.
This commit is contained in:
parent
18b13d4aa3
commit
1a4ba1921f
5 changed files with 83 additions and 2 deletions
18
routes/NextNet API/Forward/Get Inbound Connections.bru
Normal file
18
routes/NextNet API/Forward/Get Inbound Connections.bru
Normal file
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -8,6 +8,7 @@ export const permissionListDisabled: Record<string, boolean> = {
|
|||
"routes.stop": false,
|
||||
"routes.edit": false,
|
||||
"routes.visible": false,
|
||||
"routes.visibleConn": false,
|
||||
|
||||
"backends.add": false,
|
||||
"backends.remove": false,
|
||||
|
|
62
src/routes/forward/connections.ts
Normal file
62
src/routes/forward/connections.ts
Normal file
|
@ -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<boolean> {
|
||||
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()
|
||||
}
|
||||
})
|
||||
}
|
|
@ -35,8 +35,6 @@ export function route(routeOptions: RouteOptions) {
|
|||
id: number
|
||||
} = req.body;
|
||||
|
||||
console.log(body);
|
||||
|
||||
if (!await hasPermission(body.token, [
|
||||
"routes.start"
|
||||
])) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue