feature: Adds protocol feidld.
This commit is contained in:
parent
0bb66098b7
commit
569016711a
7 changed files with 46 additions and 13 deletions
|
@ -19,7 +19,7 @@ export function route(routeOptions: RouteOptions) {
|
|||
schema: {
|
||||
body: {
|
||||
type: "object",
|
||||
required: ["token", "name", "sourceIP", "sourcePort", "destinationPort", "providerID"],
|
||||
required: ["token", "name", "protocol", "sourceIP", "sourcePort", "destinationPort", "providerID"],
|
||||
|
||||
properties: {
|
||||
token: { type: "string" },
|
||||
|
@ -27,6 +27,8 @@ export function route(routeOptions: RouteOptions) {
|
|||
name: { type: "string" },
|
||||
description: { type: "string" },
|
||||
|
||||
protocol: { type: "string" },
|
||||
|
||||
sourceIP: { type: "string" },
|
||||
sourcePort: { type: "number" },
|
||||
|
||||
|
@ -45,6 +47,8 @@ export function route(routeOptions: RouteOptions) {
|
|||
name: string,
|
||||
description?: string,
|
||||
|
||||
protocol: "tcp" | "udp",
|
||||
|
||||
sourceIP: string,
|
||||
sourcePort: number,
|
||||
|
||||
|
@ -55,6 +59,12 @@ export function route(routeOptions: RouteOptions) {
|
|||
autoStart?: boolean
|
||||
} = 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, [
|
||||
"routes.add"
|
||||
])) {
|
||||
|
@ -73,11 +83,13 @@ export function route(routeOptions: RouteOptions) {
|
|||
error: "Could not find provider"
|
||||
});
|
||||
|
||||
await prisma.forwardRule.create({
|
||||
const forwardRule = await prisma.forwardRule.create({
|
||||
data: {
|
||||
name: body.name,
|
||||
description: body.description,
|
||||
|
||||
protocol: body.protocol,
|
||||
|
||||
sourceIP: body.sourceIP,
|
||||
sourcePort: body.sourcePort,
|
||||
|
||||
|
@ -90,7 +102,8 @@ export function route(routeOptions: RouteOptions) {
|
|||
});
|
||||
|
||||
return {
|
||||
success: true
|
||||
success: true,
|
||||
id: forwardRule.id
|
||||
}
|
||||
});
|
||||
}
|
|
@ -26,14 +26,15 @@ export function route(routeOptions: RouteOptions) {
|
|||
id: { type: "number" },
|
||||
|
||||
name: { type: "string" },
|
||||
protocol: { type: "string" },
|
||||
description: { type: "string" },
|
||||
|
||||
sourceIP: { type: "string" },
|
||||
sourcePort: { type: "number" },
|
||||
destPort: { type: "number" },
|
||||
sourceIP: { type: "string" },
|
||||
sourcePort: { type: "number" },
|
||||
destPort: { type: "number" },
|
||||
|
||||
providerID: { type: "number" },
|
||||
autoStart: { type: "boolean" }
|
||||
providerID: { type: "number" },
|
||||
autoStart: { type: "boolean" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +47,8 @@ export function route(routeOptions: RouteOptions) {
|
|||
name?: string,
|
||||
description?: string,
|
||||
|
||||
protocol?: "tcp" | "udp",
|
||||
|
||||
sourceIP?: string,
|
||||
sourcePort?: number,
|
||||
|
||||
|
@ -55,6 +58,12 @@ export function route(routeOptions: RouteOptions) {
|
|||
autoStart?: boolean
|
||||
} = 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, [
|
||||
"routes.visible" // wtf?
|
||||
])) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue