mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-22 08:45:24 +00:00
Add internal api get for proxy information
This commit is contained in:
@@ -42,6 +42,8 @@ internalRouter.get("/idp", idp.listIdps);
|
|||||||
|
|
||||||
internalRouter.get("/idp/:idpId", idp.getIdp);
|
internalRouter.get("/idp/:idpId", idp.getIdp);
|
||||||
|
|
||||||
|
internalRouter.get("/resource/browser-target", resource.getBrowserTarget);
|
||||||
|
|
||||||
// Gerbil routes
|
// Gerbil routes
|
||||||
const gerbilRouter = Router();
|
const gerbilRouter = Router();
|
||||||
internalRouter.use("/gerbil", gerbilRouter);
|
internalRouter.use("/gerbil", gerbilRouter);
|
||||||
|
|||||||
76
server/routers/resource/getBrowserTarget.ts
Normal file
76
server/routers/resource/getBrowserTarget.ts
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { db } from "@server/db";
|
||||||
|
import { resources, targets } from "@server/db";
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
|
||||||
|
const getBrowserTargetSchema = z
|
||||||
|
.object({
|
||||||
|
fullDomain: z.string().min(1, "fullDomain is required")
|
||||||
|
})
|
||||||
|
.strict();
|
||||||
|
|
||||||
|
export type GetBrowserTargetResponse = {
|
||||||
|
ip: string;
|
||||||
|
port: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getBrowserTarget(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Promise<any> {
|
||||||
|
try {
|
||||||
|
const parsed = getBrowserTargetSchema.safeParse(req.query);
|
||||||
|
if (!parsed.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsed.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { fullDomain } = parsed.data;
|
||||||
|
|
||||||
|
const [row] = await db
|
||||||
|
.select({
|
||||||
|
ip: targets.ip,
|
||||||
|
port: targets.port
|
||||||
|
})
|
||||||
|
.from(targets)
|
||||||
|
.innerJoin(resources, eq(targets.resourceId, resources.resourceId))
|
||||||
|
.where(eq(resources.fullDomain, fullDomain))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!row) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
"No resource found for this domain"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response<GetBrowserTargetResponse>(res, {
|
||||||
|
data: { ip: row.ip, port: row.port },
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Browser target retrieved successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"An error occurred while retrieving the browser target"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,3 +33,4 @@ export * from "./removeUserFromResource";
|
|||||||
export * from "./listAllResourceNames";
|
export * from "./listAllResourceNames";
|
||||||
export * from "./removeEmailFromResourceWhitelist";
|
export * from "./removeEmailFromResourceWhitelist";
|
||||||
export * from "./getStatusHistory";
|
export * from "./getStatusHistory";
|
||||||
|
export * from "./getBrowserTarget";
|
||||||
|
|||||||
@@ -32,10 +32,14 @@ declare module "react" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Target = {
|
||||||
|
ip: string;
|
||||||
|
port: number;
|
||||||
|
};
|
||||||
|
|
||||||
type FormState = {
|
type FormState = {
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
hostname: string;
|
|
||||||
domain: string;
|
domain: string;
|
||||||
kdcProxyUrl: string;
|
kdcProxyUrl: string;
|
||||||
pcb: string;
|
pcb: string;
|
||||||
@@ -53,11 +57,16 @@ const isIronError = (error: unknown): error is IronError => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function RdpClient() {
|
export default function RdpClient({
|
||||||
|
target,
|
||||||
|
error
|
||||||
|
}: {
|
||||||
|
target: Target | null;
|
||||||
|
error: string | null;
|
||||||
|
}) {
|
||||||
const [form, setForm] = useState<FormState>({
|
const [form, setForm] = useState<FormState>({
|
||||||
username: "Administrator",
|
username: "",
|
||||||
password: "Password123!",
|
password: "",
|
||||||
hostname: "172.31.3.58:3389",
|
|
||||||
domain: "",
|
domain: "",
|
||||||
kdcProxyUrl: "",
|
kdcProxyUrl: "",
|
||||||
pcb: "",
|
pcb: "",
|
||||||
@@ -214,11 +223,15 @@ export default function RdpClient() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const destination = target
|
||||||
|
? `${target.ip}:${target.port}`
|
||||||
|
: "";
|
||||||
|
|
||||||
const builder = userInteraction
|
const builder = userInteraction
|
||||||
.configBuilder()
|
.configBuilder()
|
||||||
.withUsername(form.username)
|
.withUsername(form.username)
|
||||||
.withPassword(form.password)
|
.withPassword(form.password)
|
||||||
.withDestination(form.hostname)
|
.withDestination(destination)
|
||||||
.withProxyAddress(
|
.withProxyAddress(
|
||||||
`${window.location.protocol === "https:" ? "wss" : "ws"}://${window.location.host}/gateway/rdp`
|
`${window.location.protocol === "https:" ? "wss" : "ws"}://${window.location.host}/gateway/rdp`
|
||||||
)
|
)
|
||||||
@@ -283,6 +296,14 @@ export default function RdpClient() {
|
|||||||
setCursorOverrideActive((v) => !v);
|
setCursorOverrideActive((v) => !v);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-background flex items-center justify-center">
|
||||||
|
<p className="text-destructive">{error}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-background">
|
<div className="min-h-screen bg-background">
|
||||||
{showLogin && (
|
{showLogin && (
|
||||||
@@ -292,15 +313,6 @@ export default function RdpClient() {
|
|||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<Field label="Hostname" id="hostname">
|
|
||||||
<Input
|
|
||||||
id="hostname"
|
|
||||||
value={form.hostname}
|
|
||||||
onChange={(e) =>
|
|
||||||
update("hostname", e.target.value)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</Field>
|
|
||||||
<Field label="Domain" id="domain">
|
<Field label="Domain" id="domain">
|
||||||
<Input
|
<Input
|
||||||
id="domain"
|
id="domain"
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
import { headers } from "next/headers";
|
||||||
|
import { internal } from "@app/lib/api";
|
||||||
|
import { AxiosResponse } from "axios";
|
||||||
|
import { GetBrowserTargetResponse } from "@server/routers/resource";
|
||||||
import RdpClient from "./RdpClient";
|
import RdpClient from "./RdpClient";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
@@ -6,6 +10,22 @@ export const metadata = {
|
|||||||
title: "RDP Test"
|
title: "RDP Test"
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function RdpPage() {
|
export default async function RdpPage() {
|
||||||
return <RdpClient />;
|
const headersList = await headers();
|
||||||
|
const host = headersList.get("host") || "";
|
||||||
|
const hostname = host.split(":")[0];
|
||||||
|
|
||||||
|
let target: { ip: string; port: number } | null = null;
|
||||||
|
let error: string | null = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await internal.get<AxiosResponse<GetBrowserTargetResponse>>(
|
||||||
|
`/resource/browser-target?fullDomain=${encodeURIComponent(hostname)}`
|
||||||
|
);
|
||||||
|
target = res.data.data;
|
||||||
|
} catch {
|
||||||
|
error = "No resource found for this domain";
|
||||||
|
}
|
||||||
|
|
||||||
|
return <RdpClient target={target} error={error} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,24 +6,31 @@ import { Button } from "@/components/ui/button";
|
|||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
||||||
|
type Target = {
|
||||||
|
ip: string;
|
||||||
|
port: number;
|
||||||
|
};
|
||||||
|
|
||||||
type FormState = {
|
type FormState = {
|
||||||
hostname: string;
|
|
||||||
port: string;
|
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function SshClient() {
|
export default function SshClient({
|
||||||
|
target,
|
||||||
|
error
|
||||||
|
}: {
|
||||||
|
target: Target | null;
|
||||||
|
error: string | null;
|
||||||
|
}) {
|
||||||
const [form, setForm] = useState<FormState>({
|
const [form, setForm] = useState<FormState>({
|
||||||
hostname: "",
|
|
||||||
port: "22",
|
|
||||||
username: "",
|
username: "",
|
||||||
password: ""
|
password: ""
|
||||||
});
|
});
|
||||||
|
|
||||||
const [connected, setConnected] = useState(false);
|
const [connected, setConnected] = useState(false);
|
||||||
const [connecting, setConnecting] = useState(false);
|
const [connecting, setConnecting] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [connectError, setConnectError] = useState<string | null>(null);
|
||||||
|
|
||||||
const terminalRef = useRef<HTMLDivElement>(null);
|
const terminalRef = useRef<HTMLDivElement>(null);
|
||||||
const xtermRef = useRef<import("@xterm/xterm").Terminal | null>(null);
|
const xtermRef = useRef<import("@xterm/xterm").Terminal | null>(null);
|
||||||
@@ -115,18 +122,14 @@ export default function SshClient() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
setError(null);
|
setConnectError(null);
|
||||||
setConnecting(true);
|
setConnecting(true);
|
||||||
|
|
||||||
const proxyAddress = `${window.location.protocol === "https:" ? "wss" : "ws"}://${window.location.host}/gateway/ssh`;
|
const proxyAddress = `${window.location.protocol === "https:" ? "wss" : "ws"}://${window.location.host}/gateway/ssh`;
|
||||||
const url = new URL(proxyAddress);
|
const url = new URL(proxyAddress);
|
||||||
// Pass connection parameters as query params so the proxy can route
|
url.searchParams.set("host", target?.ip ?? "");
|
||||||
// before any application-level framing is needed.
|
url.searchParams.set("port", String(target?.port ?? 22));
|
||||||
url.searchParams.set("host", form.hostname);
|
|
||||||
url.searchParams.set("port", form.port);
|
|
||||||
url.searchParams.set("username", form.username);
|
url.searchParams.set("username", form.username);
|
||||||
// Auth token is sent as a query param; the proxy validates it before
|
|
||||||
// forwarding any data.
|
|
||||||
url.searchParams.set("authToken", "test-token");
|
url.searchParams.set("authToken", "test-token");
|
||||||
|
|
||||||
const ws = new WebSocket(url.toString(), ["ssh"]);
|
const ws = new WebSocket(url.toString(), ["ssh"]);
|
||||||
@@ -166,7 +169,7 @@ export default function SshClient() {
|
|||||||
ws.onerror = () => {
|
ws.onerror = () => {
|
||||||
setConnecting(false);
|
setConnecting(false);
|
||||||
setConnected(false);
|
setConnected(false);
|
||||||
setError("WebSocket connection failed");
|
setConnectError("WebSocket connection failed");
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = (evt) => {
|
ws.onclose = (evt) => {
|
||||||
@@ -185,6 +188,14 @@ export default function SshClient() {
|
|||||||
setConnected(false);
|
setConnected(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col h-screen bg-black text-white p-4 items-center justify-center">
|
||||||
|
<p className="text-red-400">{error}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-screen bg-black text-white p-4 gap-4">
|
<div className="flex flex-col h-screen bg-black text-white p-4 gap-4">
|
||||||
<h1 className="text-xl font-semibold text-white">SSH Terminal</h1>
|
<h1 className="text-xl font-semibold text-white">SSH Terminal</h1>
|
||||||
@@ -192,43 +203,7 @@ export default function SshClient() {
|
|||||||
{!connected && (
|
{!connected && (
|
||||||
<div className="bg-neutral-900 rounded-lg p-6 max-w-lg w-full mx-auto flex flex-col gap-4">
|
<div className="bg-neutral-900 rounded-lg p-6 max-w-lg w-full mx-auto flex flex-col gap-4">
|
||||||
<div className="grid grid-cols-2 gap-4">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1 col-span-2">
|
||||||
<Label
|
|
||||||
htmlFor="hostname"
|
|
||||||
className="text-neutral-300"
|
|
||||||
>
|
|
||||||
Host
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="hostname"
|
|
||||||
value={form.hostname}
|
|
||||||
onChange={(e) =>
|
|
||||||
setForm({
|
|
||||||
...form,
|
|
||||||
hostname: e.target.value
|
|
||||||
})
|
|
||||||
}
|
|
||||||
placeholder="192.168.1.1"
|
|
||||||
className="bg-neutral-800 border-neutral-700 text-white"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex flex-col gap-1">
|
|
||||||
<Label htmlFor="port" className="text-neutral-300">
|
|
||||||
Port
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="port"
|
|
||||||
value={form.port}
|
|
||||||
onChange={(e) =>
|
|
||||||
setForm({ ...form, port: e.target.value })
|
|
||||||
}
|
|
||||||
placeholder="22"
|
|
||||||
className="bg-neutral-800 border-neutral-700 text-white"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex flex-col gap-1">
|
|
||||||
<Label
|
<Label
|
||||||
htmlFor="username"
|
htmlFor="username"
|
||||||
className="text-neutral-300"
|
className="text-neutral-300"
|
||||||
@@ -249,7 +224,7 @@ export default function SshClient() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1 col-span-2">
|
||||||
<Label
|
<Label
|
||||||
htmlFor="password"
|
htmlFor="password"
|
||||||
className="text-neutral-300"
|
className="text-neutral-300"
|
||||||
@@ -271,13 +246,13 @@ export default function SshClient() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{error && <p className="text-red-400 text-sm">{error}</p>}
|
{connectError && (
|
||||||
|
<p className="text-red-400 text-sm">{connectError}</p>
|
||||||
|
)}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
onClick={connect}
|
onClick={connect}
|
||||||
disabled={
|
disabled={connecting || !form.username}
|
||||||
connecting || !form.hostname || !form.username
|
|
||||||
}
|
|
||||||
className="w-full"
|
className="w-full"
|
||||||
>
|
>
|
||||||
{connecting ? "Connecting…" : "Connect"}
|
{connecting ? "Connecting…" : "Connect"}
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
import { headers } from "next/headers";
|
||||||
|
import { internal } from "@app/lib/api";
|
||||||
|
import { AxiosResponse } from "axios";
|
||||||
|
import { GetBrowserTargetResponse } from "@server/routers/resource";
|
||||||
import SshClient from "./SshClient";
|
import SshClient from "./SshClient";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
@@ -6,6 +10,22 @@ export const metadata = {
|
|||||||
title: "SSH Terminal"
|
title: "SSH Terminal"
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function SshPage() {
|
export default async function SshPage() {
|
||||||
return <SshClient />;
|
const headersList = await headers();
|
||||||
|
const host = headersList.get("host") || "";
|
||||||
|
const hostname = host.split(":")[0];
|
||||||
|
|
||||||
|
let target: { ip: string; port: number } | null = null;
|
||||||
|
let error: string | null = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await internal.get<AxiosResponse<GetBrowserTargetResponse>>(
|
||||||
|
`/resource/browser-target?fullDomain=${encodeURIComponent(hostname)}`
|
||||||
|
);
|
||||||
|
target = res.data.data;
|
||||||
|
} catch {
|
||||||
|
error = "No resource found for this domain";
|
||||||
|
}
|
||||||
|
|
||||||
|
return <SshClient target={target} error={error} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,23 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { toast } from "@app/hooks/useToast";
|
import { toast } from "@app/hooks/useToast";
|
||||||
|
|
||||||
|
type Target = {
|
||||||
|
ip: string;
|
||||||
|
port: number;
|
||||||
|
};
|
||||||
|
|
||||||
type FormState = {
|
type FormState = {
|
||||||
host: string;
|
|
||||||
port: string;
|
|
||||||
password: string;
|
password: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function VncClient() {
|
export default function VncClient({
|
||||||
|
target,
|
||||||
|
error
|
||||||
|
}: {
|
||||||
|
target: Target | null;
|
||||||
|
error: string | null;
|
||||||
|
}) {
|
||||||
const [form, setForm] = useState<FormState>({
|
const [form, setForm] = useState<FormState>({
|
||||||
host: "",
|
|
||||||
port: "5900",
|
|
||||||
password: ""
|
password: ""
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -43,11 +50,11 @@ export default function VncClient() {
|
|||||||
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
const connect = async () => {
|
const connect = async () => {
|
||||||
if (!form.host) {
|
if (!target) {
|
||||||
toast({
|
toast({
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
title: "Missing host",
|
title: "No target",
|
||||||
description: "Enter the VNC server hostname or IP"
|
description: "No resource target is available"
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -78,12 +85,12 @@ export default function VncClient() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build the proxy WebSocket URL:
|
// Build the proxy WebSocket URL:
|
||||||
// ws://<proxyAddress>?authToken=<token>&host=<host>&port=<port>
|
// ws://<proxyAddress>?authToken=<token>&host=<ip>&port=<port>
|
||||||
const proxyAddress = `${window.location.protocol === "https:" ? "wss" : "ws"}://${window.location.host}/gateway/vnc`;
|
const proxyAddress = `${window.location.protocol === "https:" ? "wss" : "ws"}://${window.location.host}/gateway/vnc`;
|
||||||
const base = proxyAddress.replace(/\/$/, "");
|
const base = proxyAddress.replace(/\/$/, "");
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
host: form.host,
|
host: target.ip,
|
||||||
port: form.port,
|
port: String(target.port),
|
||||||
authToken: "test-token"
|
authToken: "test-token"
|
||||||
});
|
});
|
||||||
const wsUrl = `${base}?${params.toString()}`;
|
const wsUrl = `${base}?${params.toString()}`;
|
||||||
@@ -135,6 +142,14 @@ export default function VncClient() {
|
|||||||
rfbRef.current = rfb;
|
rfbRef.current = rfb;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-background flex items-center justify-center">
|
||||||
|
<p className="text-destructive">{error}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-background">
|
<div className="min-h-screen bg-background">
|
||||||
{!connected && (
|
{!connected && (
|
||||||
@@ -144,24 +159,6 @@ export default function VncClient() {
|
|||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<Field label="VNC Host" id="host">
|
|
||||||
<Input
|
|
||||||
id="host"
|
|
||||||
placeholder="192.168.1.100"
|
|
||||||
value={form.host}
|
|
||||||
onChange={(e) => update("host", e.target.value)}
|
|
||||||
/>
|
|
||||||
</Field>
|
|
||||||
|
|
||||||
<Field label="VNC Port" id="port">
|
|
||||||
<Input
|
|
||||||
id="port"
|
|
||||||
type="number"
|
|
||||||
value={form.port}
|
|
||||||
onChange={(e) => update("port", e.target.value)}
|
|
||||||
/>
|
|
||||||
</Field>
|
|
||||||
|
|
||||||
<Field label="Password (optional)" id="password">
|
<Field label="Password (optional)" id="password">
|
||||||
<Input
|
<Input
|
||||||
id="password"
|
id="password"
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
import { headers } from "next/headers";
|
||||||
|
import { internal } from "@app/lib/api";
|
||||||
|
import { AxiosResponse } from "axios";
|
||||||
|
import { GetBrowserTargetResponse } from "@server/routers/resource";
|
||||||
import VncClient from "./VncClient";
|
import VncClient from "./VncClient";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
@@ -6,6 +10,22 @@ export const metadata = {
|
|||||||
title: "VNC Test"
|
title: "VNC Test"
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function VncPage() {
|
export default async function VncPage() {
|
||||||
return <VncClient />;
|
const headersList = await headers();
|
||||||
|
const host = headersList.get("host") || "";
|
||||||
|
const hostname = host.split(":")[0];
|
||||||
|
|
||||||
|
let target: { ip: string; port: number } | null = null;
|
||||||
|
let error: string | null = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await internal.get<AxiosResponse<GetBrowserTargetResponse>>(
|
||||||
|
`/resource/browser-target?fullDomain=${encodeURIComponent(hostname)}`
|
||||||
|
);
|
||||||
|
target = res.data.data;
|
||||||
|
} catch {
|
||||||
|
error = "No resource found for this domain";
|
||||||
|
}
|
||||||
|
|
||||||
|
return <VncClient target={target} error={error} />;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user