mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-01 17:52:17 +00:00
Add port validation to database external ports
Co-authored-by: Siumauricio <[email protected]>
This commit is contained in:
co-authored by
Siumauricio
parent
999dc7d360
commit
139c06b63d
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
addNewService,
|
addNewService,
|
||||||
|
checkPortInUse,
|
||||||
checkServiceAccess,
|
checkServiceAccess,
|
||||||
createMariadb,
|
createMariadb,
|
||||||
createMount,
|
createMount,
|
||||||
@@ -172,6 +173,20 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
message: "You are not authorized to save this external port",
|
message: "You are not authorized to save this external port",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input.externalPort) {
|
||||||
|
const portCheck = await checkPortInUse(
|
||||||
|
input.externalPort,
|
||||||
|
mongo.serverId || undefined,
|
||||||
|
);
|
||||||
|
if (portCheck.isInUse) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "CONFLICT",
|
||||||
|
message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await updateMariadbById(input.mariadbId, {
|
await updateMariadbById(input.mariadbId, {
|
||||||
externalPort: input.externalPort,
|
externalPort: input.externalPort,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
addNewService,
|
addNewService,
|
||||||
|
checkPortInUse,
|
||||||
checkServiceAccess,
|
checkServiceAccess,
|
||||||
createMongo,
|
createMongo,
|
||||||
createMount,
|
createMount,
|
||||||
@@ -189,6 +190,20 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
message: "You are not authorized to save this external port",
|
message: "You are not authorized to save this external port",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input.externalPort) {
|
||||||
|
const portCheck = await checkPortInUse(
|
||||||
|
input.externalPort,
|
||||||
|
mongo.serverId || undefined,
|
||||||
|
);
|
||||||
|
if (portCheck.isInUse) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "CONFLICT",
|
||||||
|
message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await updateMongoById(input.mongoId, {
|
await updateMongoById(input.mongoId, {
|
||||||
externalPort: input.externalPort,
|
externalPort: input.externalPort,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
addNewService,
|
addNewService,
|
||||||
|
checkPortInUse,
|
||||||
checkServiceAccess,
|
checkServiceAccess,
|
||||||
createMount,
|
createMount,
|
||||||
createMysql,
|
createMysql,
|
||||||
@@ -187,6 +188,20 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
message: "You are not authorized to save this external port",
|
message: "You are not authorized to save this external port",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input.externalPort) {
|
||||||
|
const portCheck = await checkPortInUse(
|
||||||
|
input.externalPort,
|
||||||
|
mongo.serverId || undefined,
|
||||||
|
);
|
||||||
|
if (portCheck.isInUse) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "CONFLICT",
|
||||||
|
message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await updateMySqlById(input.mysqlId, {
|
await updateMySqlById(input.mysqlId, {
|
||||||
externalPort: input.externalPort,
|
externalPort: input.externalPort,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
addNewService,
|
addNewService,
|
||||||
|
checkPortInUse,
|
||||||
checkServiceAccess,
|
checkServiceAccess,
|
||||||
createMount,
|
createMount,
|
||||||
createPostgres,
|
createPostgres,
|
||||||
@@ -192,6 +193,20 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
message: "You are not authorized to save this external port",
|
message: "You are not authorized to save this external port",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input.externalPort) {
|
||||||
|
const portCheck = await checkPortInUse(
|
||||||
|
input.externalPort,
|
||||||
|
postgres.serverId || undefined,
|
||||||
|
);
|
||||||
|
if (portCheck.isInUse) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "CONFLICT",
|
||||||
|
message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await updatePostgresById(input.postgresId, {
|
await updatePostgresById(input.postgresId, {
|
||||||
externalPort: input.externalPort,
|
externalPort: input.externalPort,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
addNewService,
|
addNewService,
|
||||||
|
checkPortInUse,
|
||||||
checkServiceAccess,
|
checkServiceAccess,
|
||||||
createMount,
|
createMount,
|
||||||
createRedis,
|
createRedis,
|
||||||
@@ -211,6 +212,20 @@ export const redisRouter = createTRPCRouter({
|
|||||||
message: "You are not authorized to save this external port",
|
message: "You are not authorized to save this external port",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input.externalPort) {
|
||||||
|
const portCheck = await checkPortInUse(
|
||||||
|
input.externalPort,
|
||||||
|
mongo.serverId || undefined,
|
||||||
|
);
|
||||||
|
if (portCheck.isInUse) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "CONFLICT",
|
||||||
|
message: `Port ${input.externalPort} is already in use by ${portCheck.conflictingContainer}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await updateRedisById(input.redisId, {
|
await updateRedisById(input.redisId, {
|
||||||
externalPort: input.externalPort,
|
externalPort: input.externalPort,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user