mirror of
https://github.com/dokploy/dokploy.git
synced 2026-06-14 03:19:49 +00:00
282d358d04
- Modified the regex pattern in the `readValidDirectory` function to allow for a wider range of characters, including colons, improving the validation of directory names. - This change enhances input integrity by ensuring valid directory formats are accepted.
57 lines
1.1 KiB
TypeScript
57 lines
1.1 KiB
TypeScript
import os from "node:os";
|
|
import path from "node:path";
|
|
import { paths } from "@dokploy/server/constants";
|
|
import { publicIpv4, publicIpv6 } from "public-ip";
|
|
|
|
export const getShell = () => {
|
|
switch (os.platform()) {
|
|
case "win32":
|
|
return "powershell.exe";
|
|
case "darwin":
|
|
return "zsh";
|
|
default:
|
|
return "bash";
|
|
}
|
|
};
|
|
|
|
export const getPublicIpWithFallback = async () => {
|
|
// @ts-ignore
|
|
let ip = null;
|
|
try {
|
|
ip = await publicIpv4();
|
|
} catch (error) {
|
|
console.log(
|
|
"Error obtaining public IPv4 address, falling back to IPv6",
|
|
// @ts-ignore
|
|
error.message,
|
|
);
|
|
try {
|
|
ip = await publicIpv6();
|
|
} catch (error) {
|
|
// @ts-ignore
|
|
console.error("Error obtaining public IPv6 address", error.message);
|
|
ip = null;
|
|
}
|
|
}
|
|
return ip;
|
|
};
|
|
|
|
export const readValidDirectory = (
|
|
directory: string,
|
|
serverId?: string | null,
|
|
) => {
|
|
if (!/^[\w/. :-]{1,500}$/.test(directory)) {
|
|
return false;
|
|
}
|
|
|
|
const { BASE_PATH } = paths(!!serverId);
|
|
|
|
const resolvedBase = path.resolve(BASE_PATH);
|
|
const resolvedDir = path.resolve(directory);
|
|
|
|
return (
|
|
resolvedDir === resolvedBase ||
|
|
resolvedDir.startsWith(resolvedBase + path.sep)
|
|
);
|
|
};
|