mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-06 07:38:46 +00:00
Fix cascading errors
This commit is contained in:
@@ -15,7 +15,7 @@ export default async function RdpPage() {
|
||||
const host = headersList.get("host") || "";
|
||||
const hostname = host.split(":")[0];
|
||||
|
||||
let target: { ip: string; port: number; authToken: string } | null = null;
|
||||
let target: GetBrowserTargetResponse | null = null;
|
||||
let error: string | null = null;
|
||||
|
||||
try {
|
||||
|
||||
@@ -82,7 +82,7 @@ export type InternalResourceRow = {
|
||||
ssl: boolean;
|
||||
// protocol: string | null;
|
||||
// proxyPort: number | null;
|
||||
destination: string;
|
||||
destination: string | null;
|
||||
destinationPort: number | null;
|
||||
alias: string | null;
|
||||
aliasAddress: string | null;
|
||||
|
||||
@@ -55,7 +55,7 @@ export default function CreateInternalResourceDialog({
|
||||
const currentAlias = data.alias?.trim() || "";
|
||||
if (!currentAlias) {
|
||||
let aliasValue = data.destination;
|
||||
if (data.destination.toLowerCase() === "localhost") {
|
||||
if (data.destination?.toLowerCase() === "localhost") {
|
||||
aliasValue = `${cleanForFQDN(data.name)}.internal`;
|
||||
}
|
||||
data = { ...data, alias: aliasValue };
|
||||
|
||||
@@ -59,7 +59,7 @@ export default function EditInternalResourceDialog({
|
||||
const currentAlias = data.alias?.trim() || "";
|
||||
if (!currentAlias) {
|
||||
let aliasValue = data.destination;
|
||||
if (data.destination.toLowerCase() === "localhost") {
|
||||
if (data.destination?.toLowerCase() === "localhost") {
|
||||
aliasValue = `${cleanForFQDN(data.name)}.internal`;
|
||||
}
|
||||
data = { ...data, alias: aliasValue };
|
||||
|
||||
@@ -124,8 +124,8 @@ export const getPortStringFromMode = (
|
||||
return customValue;
|
||||
};
|
||||
|
||||
export const isHostname = (destination: string): boolean =>
|
||||
/[a-zA-Z]/.test(destination);
|
||||
export const isHostname = (destination: string | null): boolean =>
|
||||
!!destination && /[a-zA-Z]/.test(destination);
|
||||
|
||||
export const cleanForFQDN = (name: string): string =>
|
||||
name
|
||||
@@ -147,7 +147,7 @@ export type InternalResourceData = {
|
||||
mode: InternalResourceMode;
|
||||
siteIds: number[];
|
||||
niceId: string;
|
||||
destination: string;
|
||||
destination: string | null;
|
||||
alias?: string | null;
|
||||
tcpPortRangeString?: string | null;
|
||||
udpPortRangeString?: string | null;
|
||||
@@ -179,7 +179,7 @@ export type InternalResourceFormValues = {
|
||||
name: string;
|
||||
siteIds: number[];
|
||||
mode: InternalResourceMode;
|
||||
destination: string;
|
||||
destination: string | null;
|
||||
alias?: string | null;
|
||||
niceId?: string;
|
||||
tcpPortRangeString?: string | null;
|
||||
@@ -309,7 +309,7 @@ export function InternalResourceForm({
|
||||
name: z.string().min(1, t(nameRequiredKey)).max(255, t(nameMaxKey)),
|
||||
siteIds: siteIdsSchema,
|
||||
mode: z.enum(["host", "cidr", "http", "ssh"]),
|
||||
destination: z.string(),
|
||||
destination: z.string().nullish(),
|
||||
alias: z.string().nullish(),
|
||||
destinationPort: z
|
||||
.number()
|
||||
@@ -352,9 +352,10 @@ export function InternalResourceForm({
|
||||
.superRefine((data, ctx) => {
|
||||
const isNativeSsh =
|
||||
data.mode === "ssh" && data.authDaemonMode === "native";
|
||||
const trimmedDestination = data.destination?.trim();
|
||||
if (
|
||||
!isNativeSsh &&
|
||||
(!data.destination || data.destination.length < 1)
|
||||
(!trimmedDestination || trimmedDestination.length < 1)
|
||||
) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
@@ -735,9 +736,14 @@ export function InternalResourceForm({
|
||||
<form
|
||||
onSubmit={form.handleSubmit((values) => {
|
||||
const siteIds = values.siteIds;
|
||||
const trimmedDestination = values.destination?.trim();
|
||||
onSubmit({
|
||||
...values,
|
||||
siteIds,
|
||||
destination:
|
||||
trimmedDestination && trimmedDestination.length > 0
|
||||
? trimmedDestination
|
||||
: null,
|
||||
clients: (values.clients ?? []).map((c) => ({
|
||||
id: c.clientId.toString(),
|
||||
text: c.name
|
||||
@@ -1097,10 +1103,25 @@ export function InternalResourceForm({
|
||||
<Input
|
||||
{...field}
|
||||
className="w-full"
|
||||
value={
|
||||
field.value ??
|
||||
""
|
||||
}
|
||||
disabled={
|
||||
isHttpMode &&
|
||||
httpSectionDisabled
|
||||
}
|
||||
onChange={(e) =>
|
||||
field.onChange(
|
||||
e.target
|
||||
.value ===
|
||||
""
|
||||
? null
|
||||
: e
|
||||
.target
|
||||
.value
|
||||
)
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
|
||||
@@ -68,7 +68,8 @@ function PrivateResourceMeta({ row }: { row: SiteResourceRow }) {
|
||||
const modeLabel: Record<SiteResourceRow["mode"], string> = {
|
||||
host: t("editInternalResourceDialogModeHost"),
|
||||
cidr: t("editInternalResourceDialogModeCidr"),
|
||||
http: t("editInternalResourceDialogModeHttp")
|
||||
http: t("editInternalResourceDialogModeHttp"),
|
||||
ssh: t("editInternalResourceDialogModeSsh")
|
||||
};
|
||||
const dest = formatSiteResourceDestinationDisplay({
|
||||
mode: row.mode,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export type SiteResourceDestinationInput = {
|
||||
mode: "host" | "cidr" | "http";
|
||||
destination: string;
|
||||
mode: "host" | "cidr" | "http" | "ssh";
|
||||
destination: string | null;
|
||||
destinationPort: number | null;
|
||||
scheme: "http" | "https" | null;
|
||||
};
|
||||
@@ -18,6 +18,9 @@ export function resolveHttpHttpsDisplayPort(
|
||||
export function formatSiteResourceDestinationDisplay(
|
||||
row: SiteResourceDestinationInput
|
||||
): string {
|
||||
if (!row.destination) {
|
||||
return "";
|
||||
}
|
||||
const { mode, destination, destinationPort, scheme } = row;
|
||||
if (mode !== "http") {
|
||||
return destination;
|
||||
|
||||
Reference in New Issue
Block a user