feature: Adds removing API.
This commit is contained in:
parent
68b5a9ff77
commit
2ae917acd9
13 changed files with 165 additions and 8 deletions
23
routes/NextNet API/Backend API/Remove Backend.bru
Normal file
23
routes/NextNet API/Backend API/Remove Backend.bru
Normal file
|
@ -0,0 +1,23 @@
|
|||
meta {
|
||||
name: Remove Backend
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://127.0.0.1:3000/api/v1/backends/create
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"token": "f1b89cc337073476289ade17ffbe7a6419b4bd52aa7ede26114bffd76fa263b5cb1bcaf389462e1d9e7acb7f4b6a7c28152a9cc9af83e3ec862f1892b1",
|
||||
"name": "PortCopier Route",
|
||||
"description": "This is a test route for portcopier.",
|
||||
"backend": "PortCopier",
|
||||
"connectionDetails": {
|
||||
"funny": true
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
meta {
|
||||
name: Create Forward
|
||||
type: http
|
||||
seq: 4
|
||||
seq: 1
|
||||
}
|
||||
|
||||
post {
|
26
routes/NextNet API/Forward API/Remove Forward.bru
Normal file
26
routes/NextNet API/Forward API/Remove Forward.bru
Normal file
|
@ -0,0 +1,26 @@
|
|||
meta {
|
||||
name: Remove Forward
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://127.0.0.1:3000/api/v1/forward/create
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"token": "f1b89cc337073476289ade17ffbe7a6419b4bd52aa7ede26114bffd76fa263b5cb1bcaf389462e1d9e7acb7f4b6a7c28152a9cc9af83e3ec862f1892b1",
|
||||
"name": "Test Route",
|
||||
"description": "This is a test route for portcopier.",
|
||||
|
||||
"sourceIP": "127.0.0.1",
|
||||
"sourcePort": "8000",
|
||||
|
||||
"destinationPort": "9000",
|
||||
|
||||
"providerID": "1"
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
meta {
|
||||
name: Get Permissions
|
||||
type: http
|
||||
seq: 5
|
||||
seq: 1
|
||||
}
|
||||
|
||||
post {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
meta {
|
||||
name: Log In User
|
||||
type: http
|
||||
seq: 1
|
||||
seq: 2
|
||||
}
|
||||
|
||||
post {
|
|
@ -1,7 +1,7 @@
|
|||
meta {
|
||||
name: Lookup User
|
||||
type: http
|
||||
seq: 7
|
||||
seq: 4
|
||||
}
|
||||
|
||||
post {
|
|
@ -1,7 +1,7 @@
|
|||
meta {
|
||||
name: Remove User
|
||||
type: http
|
||||
seq: 6
|
||||
seq: 3
|
||||
}
|
||||
|
||||
post {
|
|
@ -8,8 +8,10 @@ import { ServerOptions, SessionToken } from "./libs/types.js";
|
|||
import { route as getPermissions } from "./routes/getPermissions.js";
|
||||
|
||||
import { route as backendCreate } from "./routes/backends/create.js";
|
||||
import { route as backendRemove } from "./routes/backends/remove.js";
|
||||
|
||||
import { route as forwardCreate } from "./routes/forward/create.js";
|
||||
import { route as forwardRemove } from "./routes/forward/remove.js";
|
||||
|
||||
import { route as userCreate } from "./routes/user/create.js";
|
||||
import { route as userRemove } from "./routes/user/remove.js";
|
||||
|
@ -43,8 +45,10 @@ const fastify = Fastify({
|
|||
getPermissions(fastify, prisma, sessionTokens, serverOptions);
|
||||
|
||||
backendCreate(fastify, prisma, sessionTokens, serverOptions);
|
||||
backendRemove(fastify, prisma, sessionTokens, serverOptions);
|
||||
|
||||
forwardCreate(fastify, prisma, sessionTokens, serverOptions);
|
||||
forwardRemove(fastify, prisma, sessionTokens, serverOptions);
|
||||
|
||||
userCreate(fastify, prisma, sessionTokens, serverOptions);
|
||||
userRemove(fastify, prisma, sessionTokens, serverOptions);
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
- [x] /api/v1/users/login
|
||||
- [x] /api/v1/users/remove
|
||||
- [ ] /api/v1/users/modify
|
||||
- [ ] /api/v1/users/search
|
||||
- [x] /api/v1/users/search
|
||||
- [x] /api/v1/backends/create
|
||||
- [ ] /api/v1/backends/remove
|
||||
- [x] /api/v1/backends/remove
|
||||
- [ ] /api/v1/backends/modify
|
||||
- [ ] /api/v1/backends/search
|
||||
- [x] /api/v1/routes/create
|
||||
- [ ] /api/v1/routes/remove
|
||||
- [x] /api/v1/routes/remove
|
||||
- [ ] /api/v1/routes/modify
|
||||
- [ ] /api/v1/routes/search
|
||||
- [x] /api/v1/getPermissions
|
52
src/routes/backends/remove.ts
Normal file
52
src/routes/backends/remove.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import type { PrismaClient } from "@prisma/client";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
|
||||
import { ServerOptions, SessionToken } from "../../libs/types.js";
|
||||
import { hasPermissionByToken } from "../../libs/permissions.js";
|
||||
|
||||
export function route(fastify: FastifyInstance, prisma: PrismaClient, tokens: Record<number, SessionToken[]>, options: ServerOptions) {
|
||||
function hasPermission(token: string, permissionList: string[]): Promise<boolean> {
|
||||
return hasPermissionByToken(permissionList, token, tokens, prisma);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new route to use
|
||||
*/
|
||||
fastify.post("/api/v1/backends/remove", {
|
||||
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, [
|
||||
"backends.remove"
|
||||
])) {
|
||||
return res.status(403).send({
|
||||
error: "Unauthorized"
|
||||
});
|
||||
};
|
||||
|
||||
await prisma.desinationProvider.delete({
|
||||
where: {
|
||||
id: body.id
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
});
|
||||
}
|
52
src/routes/forward/remove.ts
Normal file
52
src/routes/forward/remove.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import type { PrismaClient } from "@prisma/client";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
|
||||
import { ServerOptions, SessionToken } from "../../libs/types.js";
|
||||
import { hasPermissionByToken } from "../../libs/permissions.js";
|
||||
|
||||
export function route(fastify: FastifyInstance, prisma: PrismaClient, tokens: Record<number, SessionToken[]>, options: ServerOptions) {
|
||||
function hasPermission(token: string, permissionList: string[]): Promise<boolean> {
|
||||
return hasPermissionByToken(permissionList, token, tokens, prisma);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new route to use
|
||||
*/
|
||||
fastify.post("/api/v1/forward/remove", {
|
||||
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.remove"
|
||||
])) {
|
||||
return res.status(403).send({
|
||||
error: "Unauthorized"
|
||||
});
|
||||
};
|
||||
|
||||
await prisma.forwardRule.delete({
|
||||
where: {
|
||||
id: body.id
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
success: true
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue