feature: Adds protocol feidld.
This commit is contained in:
parent
0bb66098b7
commit
569016711a
7 changed files with 46 additions and 13 deletions
|
@ -0,0 +1,8 @@
|
||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- Added the required column `protocol` to the `ForwardRule` table without a default value. This is not possible if the table is not empty.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "ForwardRule" ADD COLUMN "protocol" TEXT NOT NULL;
|
|
@ -24,6 +24,7 @@ model ForwardRule {
|
||||||
|
|
||||||
name String
|
name String
|
||||||
description String?
|
description String?
|
||||||
|
protocol String
|
||||||
sourceIP String
|
sourceIP String
|
||||||
sourcePort Int
|
sourcePort Int
|
||||||
destPort Int
|
destPort Int
|
||||||
|
|
|
@ -12,9 +12,11 @@ post {
|
||||||
|
|
||||||
body:json {
|
body:json {
|
||||||
{
|
{
|
||||||
"token": "5e2cb92a338a832d385790861312eb85d69f46f82317bfa984ac5e3517368ab5a827897b0f9775a9181b02fa3b9cffed7e59e5b3111d5bdc37f729156caf5f",
|
"token": "535c80825631c04b9add7a8682e06799d62ba57b5089b557f5bab2183fc9926b187b3b8d96da8ef16c67ec80f2917cf81bc21337f47728534f58ac9c4ed5f3fe",
|
||||||
"name": "Test Route",
|
"name": "Test Route",
|
||||||
"description": "This is a test route for portcopier.",
|
"description": "This is a test route for portcopier.",
|
||||||
|
|
||||||
|
"protocol": "tcp",
|
||||||
|
|
||||||
"sourceIP": "127.0.0.1",
|
"sourceIP": "127.0.0.1",
|
||||||
"sourcePort": "8000",
|
"sourcePort": "8000",
|
||||||
|
|
|
@ -5,14 +5,14 @@ meta {
|
||||||
}
|
}
|
||||||
|
|
||||||
post {
|
post {
|
||||||
url: http://127.0.0.1:3000/api/v1/forward/remove
|
url: http://127.0.0.1:3000/api/v1/forward/lookup
|
||||||
body: json
|
body: json
|
||||||
auth: none
|
auth: none
|
||||||
}
|
}
|
||||||
|
|
||||||
body:json {
|
body:json {
|
||||||
{
|
{
|
||||||
"token": "f1b89cc337073476289ade17ffbe7a6419b4bd52aa7ede26114bffd76fa263b5cb1bcaf389462e1d9e7acb7f4b6a7c28152a9cc9af83e3ec862f1892b1",
|
"token": "535c80825631c04b9add7a8682e06799d62ba57b5089b557f5bab2183fc9926b187b3b8d96da8ef16c67ec80f2917cf81bc21337f47728534f58ac9c4ed5f3fe",
|
||||||
"id": "2"
|
"protocol": "tcp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ meta {
|
||||||
}
|
}
|
||||||
|
|
||||||
post {
|
post {
|
||||||
url: http://127.0.0.1:3000/api/v1/forward/create
|
url: http://127.0.0.1:3000/api/v1/forward/remove
|
||||||
body: json
|
body: json
|
||||||
auth: none
|
auth: none
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ export function route(routeOptions: RouteOptions) {
|
||||||
schema: {
|
schema: {
|
||||||
body: {
|
body: {
|
||||||
type: "object",
|
type: "object",
|
||||||
required: ["token", "name", "sourceIP", "sourcePort", "destinationPort", "providerID"],
|
required: ["token", "name", "protocol", "sourceIP", "sourcePort", "destinationPort", "providerID"],
|
||||||
|
|
||||||
properties: {
|
properties: {
|
||||||
token: { type: "string" },
|
token: { type: "string" },
|
||||||
|
@ -27,6 +27,8 @@ export function route(routeOptions: RouteOptions) {
|
||||||
name: { type: "string" },
|
name: { type: "string" },
|
||||||
description: { type: "string" },
|
description: { type: "string" },
|
||||||
|
|
||||||
|
protocol: { type: "string" },
|
||||||
|
|
||||||
sourceIP: { type: "string" },
|
sourceIP: { type: "string" },
|
||||||
sourcePort: { type: "number" },
|
sourcePort: { type: "number" },
|
||||||
|
|
||||||
|
@ -45,6 +47,8 @@ export function route(routeOptions: RouteOptions) {
|
||||||
name: string,
|
name: string,
|
||||||
description?: string,
|
description?: string,
|
||||||
|
|
||||||
|
protocol: "tcp" | "udp",
|
||||||
|
|
||||||
sourceIP: string,
|
sourceIP: string,
|
||||||
sourcePort: number,
|
sourcePort: number,
|
||||||
|
|
||||||
|
@ -55,6 +59,12 @@ export function route(routeOptions: RouteOptions) {
|
||||||
autoStart?: boolean
|
autoStart?: boolean
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
|
if (body.protocol != "tcp" && body.protocol != "udp") {
|
||||||
|
return res.status(400).send({
|
||||||
|
error: "Body protocol field must be either tcp or udp"
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
if (!await hasPermission(body.token, [
|
if (!await hasPermission(body.token, [
|
||||||
"routes.add"
|
"routes.add"
|
||||||
])) {
|
])) {
|
||||||
|
@ -73,11 +83,13 @@ export function route(routeOptions: RouteOptions) {
|
||||||
error: "Could not find provider"
|
error: "Could not find provider"
|
||||||
});
|
});
|
||||||
|
|
||||||
await prisma.forwardRule.create({
|
const forwardRule = await prisma.forwardRule.create({
|
||||||
data: {
|
data: {
|
||||||
name: body.name,
|
name: body.name,
|
||||||
description: body.description,
|
description: body.description,
|
||||||
|
|
||||||
|
protocol: body.protocol,
|
||||||
|
|
||||||
sourceIP: body.sourceIP,
|
sourceIP: body.sourceIP,
|
||||||
sourcePort: body.sourcePort,
|
sourcePort: body.sourcePort,
|
||||||
|
|
||||||
|
@ -90,7 +102,8 @@ export function route(routeOptions: RouteOptions) {
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true
|
success: true,
|
||||||
|
id: forwardRule.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -26,14 +26,15 @@ export function route(routeOptions: RouteOptions) {
|
||||||
id: { type: "number" },
|
id: { type: "number" },
|
||||||
|
|
||||||
name: { type: "string" },
|
name: { type: "string" },
|
||||||
|
protocol: { type: "string" },
|
||||||
description: { type: "string" },
|
description: { type: "string" },
|
||||||
|
|
||||||
sourceIP: { type: "string" },
|
sourceIP: { type: "string" },
|
||||||
sourcePort: { type: "number" },
|
sourcePort: { type: "number" },
|
||||||
destPort: { type: "number" },
|
destPort: { type: "number" },
|
||||||
|
|
||||||
providerID: { type: "number" },
|
providerID: { type: "number" },
|
||||||
autoStart: { type: "boolean" }
|
autoStart: { type: "boolean" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +47,8 @@ export function route(routeOptions: RouteOptions) {
|
||||||
name?: string,
|
name?: string,
|
||||||
description?: string,
|
description?: string,
|
||||||
|
|
||||||
|
protocol?: "tcp" | "udp",
|
||||||
|
|
||||||
sourceIP?: string,
|
sourceIP?: string,
|
||||||
sourcePort?: number,
|
sourcePort?: number,
|
||||||
|
|
||||||
|
@ -55,6 +58,12 @@ export function route(routeOptions: RouteOptions) {
|
||||||
autoStart?: boolean
|
autoStart?: boolean
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
|
if (body.protocol && body.protocol != "tcp" && body.protocol != "udp") {
|
||||||
|
return res.status(400).send({
|
||||||
|
error: "Protocol specified in body must be either 'tcp' or 'udp'"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (!await hasPermission(body.token, [
|
if (!await hasPermission(body.token, [
|
||||||
"routes.visible" // wtf?
|
"routes.visible" // wtf?
|
||||||
])) {
|
])) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue