mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-12 10:27:06 +00:00
Ssh session closed card
This commit is contained in:
@@ -122,6 +122,9 @@ export default function SshClient({
|
|||||||
const [connected, setConnected] = useState(false);
|
const [connected, setConnected] = useState(false);
|
||||||
const [connecting, setConnecting] = useState(false);
|
const [connecting, setConnecting] = useState(false);
|
||||||
const [connectError, setConnectError] = useState<string | null>(null);
|
const [connectError, setConnectError] = useState<string | null>(null);
|
||||||
|
const [sessionClosedCode, setSessionClosedCode] = useState<number | 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);
|
||||||
@@ -222,6 +225,8 @@ export default function SshClient({
|
|||||||
authMethod: AuthTab = "password"
|
authMethod: AuthTab = "password"
|
||||||
) {
|
) {
|
||||||
setConnecting(true);
|
setConnecting(true);
|
||||||
|
setSessionClosedCode(null);
|
||||||
|
setConnectError(null);
|
||||||
|
|
||||||
if (!target) {
|
if (!target) {
|
||||||
setConnectError(t("sshErrorNoTarget"));
|
setConnectError(t("sshErrorNoTarget"));
|
||||||
@@ -257,8 +262,10 @@ export default function SshClient({
|
|||||||
|
|
||||||
let authConfirmed = false;
|
let authConfirmed = false;
|
||||||
let authErrorShown = false;
|
let authErrorShown = false;
|
||||||
|
let socketOpened = false;
|
||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
|
socketOpened = true;
|
||||||
ws.send(
|
ws.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: "auth",
|
type: "auth",
|
||||||
@@ -331,13 +338,18 @@ export default function SshClient({
|
|||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = (evt) => {
|
ws.onclose = (evt) => {
|
||||||
|
wsRef.current = null;
|
||||||
setConnecting(false);
|
setConnecting(false);
|
||||||
|
const isCleanClose = evt.wasClean || evt.code === 1000;
|
||||||
|
if (isCleanClose && (authConfirmed || socketOpened)) {
|
||||||
|
xtermRef.current?.dispose();
|
||||||
|
xtermRef.current = null;
|
||||||
|
setConnected(false);
|
||||||
|
setSessionClosedCode(evt.code);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (authConfirmed) {
|
if (authConfirmed) {
|
||||||
setConnected(false);
|
setConnected(false);
|
||||||
if (evt.wasClean || evt.code === 1000) {
|
|
||||||
window.close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
xtermRef.current?.writeln(
|
xtermRef.current?.writeln(
|
||||||
`\r\n\x1b[33m${t("sshConnectionClosedCode", { code: evt.code })}\x1b[0m\r\n`
|
`\r\n\x1b[33m${t("sshConnectionClosedCode", { code: evt.code })}\x1b[0m\r\n`
|
||||||
);
|
);
|
||||||
@@ -457,6 +469,40 @@ export default function SshClient({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sessionClosedCode !== null) {
|
||||||
|
return (
|
||||||
|
<BrandedAuthSurface primaryColor={primaryColor}>
|
||||||
|
<PoweredByPangolin />
|
||||||
|
<Card className="w-full max-w-md">
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>{t("sshTitle")}</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
{t("sshConnectionClosedCode", {
|
||||||
|
code: sessionClosedCode
|
||||||
|
})}
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
<Alert>
|
||||||
|
<AlertDescription>
|
||||||
|
This session has ended. You can close this tab
|
||||||
|
now.
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
className="w-full"
|
||||||
|
onClick={() => window.close()}
|
||||||
|
>
|
||||||
|
{t("close")}
|
||||||
|
</Button>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
<AuthPageFooterNotices />
|
||||||
|
</BrandedAuthSurface>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{!connected && (
|
{!connected && (
|
||||||
|
|||||||
Reference in New Issue
Block a user