mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-20 23:20:46 +00:00
* fix: support bare IPv6 addresses in quick connect and fix IPv6 display - Accept un-bracketed IPv6 addresses (e.g. 2607:f130::4f06) in quick connect input. The main regex requires brackets for IPv6+port, but now falls back to detecting bare IPv6 (2+ colons, hex-only) when the primary pattern fails. - Add formatHostPort() helper that wraps IPv6 addresses in brackets when appending a port, preventing ambiguous displays like "2607:f130::4f06:22" - Apply formatHostPort in QuickConnectWizard, TerminalConnectionDialog, and SftpSidePanel - Fix hop label formatting in sshBridge and sftpBridge for IPv6 jump hosts Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: truncate long hostnames in connection dialog Add truncate to the host label and protocol subtitle in the connection dialog so long IPv6 addresses don't overflow into the action buttons. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: constrain connection dialog header so truncate works correctly Add min-w-0/flex-1 to the left side of the header flex container and shrink-0 to the avatar so long hostnames truncate instead of pushing into the Show logs / close buttons. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: prevent action buttons from being squeezed by long hostname Add shrink-0 and left margin to the right-side button group so truncated text doesn't crowd into Show logs / close buttons. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: tighten bare IPv6 detection to avoid MAC address false positives Only accept bare (un-bracketed) hex:colon strings as IPv6 if they contain '::' (unambiguously IPv6) or have exactly 7 colons (full 8-group notation). This rejects MAC addresses like aa:bb:cc:dd:ee:ff (5 colons) which would otherwise trigger quick-connect mode. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: avoid double-wrapping already-bracketed IPv6 hop labels Add !startsWith('[') guard so hostnames that are already bracketed (e.g. from URL-imported hosts) don't produce malformed labels like [[2607:f130::4f06]]:22. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
209 lines
9.7 KiB
TypeScript
209 lines
9.7 KiB
TypeScript
/**
|
|
* Terminal Connection Dialog
|
|
* Full connection overlay with host info, progress indicator, and auth/progress content
|
|
*/
|
|
import { Loader2, Plug, TerminalSquare, X } from 'lucide-react';
|
|
import React from 'react';
|
|
import { useI18n } from '../../application/i18n/I18nProvider';
|
|
import { cn } from '../../lib/utils';
|
|
import { Host, SSHKey } from '../../types';
|
|
import { formatHostPort } from '../../domain/host';
|
|
import { DistroAvatar } from '../DistroAvatar';
|
|
import { Button } from '../ui/button';
|
|
import { TerminalAuthDialog, TerminalAuthDialogProps } from './TerminalAuthDialog';
|
|
import { TerminalConnectionProgress, TerminalConnectionProgressProps } from './TerminalConnectionProgress';
|
|
|
|
export interface ChainProgress {
|
|
currentHop: number;
|
|
totalHops: number;
|
|
currentHostLabel: string;
|
|
}
|
|
|
|
export interface TerminalConnectionDialogProps {
|
|
host: Host;
|
|
status: 'connecting' | 'connected' | 'disconnected';
|
|
error: string | null;
|
|
progressValue: number;
|
|
chainProgress: ChainProgress | null;
|
|
needsAuth: boolean;
|
|
showLogs: boolean;
|
|
_setShowLogs: (show: boolean) => void;
|
|
// Auth dialog props
|
|
authProps: Omit<TerminalAuthDialogProps, 'keys'>;
|
|
keys: SSHKey[];
|
|
onDismissDisconnected?: () => void;
|
|
// Progress props
|
|
progressProps: Omit<TerminalConnectionProgressProps, 'status' | 'error' | 'showLogs'>;
|
|
}
|
|
|
|
// Helper to get protocol display info
|
|
const getProtocolInfo = (host: Host): { i18nKey: string; showPort: boolean; port: number } => {
|
|
// Check moshEnabled first since mosh uses protocol: "ssh" with moshEnabled: true
|
|
if (host.moshEnabled) {
|
|
return { i18nKey: 'terminal.connection.protocol.mosh', showPort: true, port: host.port || 22 };
|
|
}
|
|
const protocol = host.protocol || 'ssh';
|
|
switch (protocol) {
|
|
case 'local':
|
|
return { i18nKey: 'terminal.connection.protocol.local', showPort: false, port: 0 };
|
|
case 'telnet':
|
|
// Telnet uses telnetPort, not port (which is SSH port)
|
|
return { i18nKey: 'terminal.connection.protocol.telnet', showPort: true, port: host.telnetPort ?? host.port ?? 23 };
|
|
case 'mosh':
|
|
return { i18nKey: 'terminal.connection.protocol.mosh', showPort: true, port: host.port || 22 };
|
|
case 'serial':
|
|
return { i18nKey: 'terminal.connection.protocol.serial', showPort: false, port: 0 };
|
|
case 'ssh':
|
|
default:
|
|
return { i18nKey: 'terminal.connection.protocol.ssh', showPort: true, port: host.port || 22 };
|
|
}
|
|
};
|
|
|
|
export const TerminalConnectionDialog: React.FC<TerminalConnectionDialogProps> = ({
|
|
host,
|
|
status,
|
|
error,
|
|
progressValue,
|
|
chainProgress,
|
|
needsAuth,
|
|
showLogs,
|
|
_setShowLogs: setShowLogs, // Rename back to setShowLogs for internal use
|
|
authProps,
|
|
keys,
|
|
onDismissDisconnected,
|
|
progressProps,
|
|
}) => {
|
|
const { t } = useI18n();
|
|
const hasError = Boolean(error);
|
|
const isConnecting = status === 'connecting';
|
|
const canDismissDisconnected = status === 'disconnected' && !needsAuth && !!onDismissDisconnected;
|
|
const protocolInfo = getProtocolInfo(host);
|
|
|
|
return (
|
|
<div className={cn(
|
|
"absolute inset-0 z-20 flex items-center justify-center",
|
|
needsAuth ? "bg-black" : "bg-black/30"
|
|
)}>
|
|
<div className="w-[560px] max-w-[90vw] bg-background/95 border border-border/60 rounded-xl shadow-xl p-6 space-y-4">
|
|
<div className="flex items-center justify-between">
|
|
<div className="flex items-center gap-3 min-w-0 flex-1">
|
|
<DistroAvatar host={host} fallback={host.label.slice(0, 2).toUpperCase()} className="h-10 w-10 rounded-lg shrink-0" />
|
|
<div className="min-w-0">
|
|
{chainProgress ? (
|
|
<>
|
|
<div className="text-sm font-semibold truncate">
|
|
<span className="text-muted-foreground">
|
|
{t('terminal.connection.chainOf', {
|
|
current: chainProgress.currentHop,
|
|
total: chainProgress.totalHops,
|
|
})}
|
|
{': '}
|
|
</span>
|
|
<span>{chainProgress.currentHostLabel}</span>
|
|
</div>
|
|
<div className="text-[11px] text-muted-foreground font-mono truncate">
|
|
{t(protocolInfo.i18nKey)} {protocolInfo.showPort ? formatHostPort(host.hostname, protocolInfo.port) : host.hostname}
|
|
</div>
|
|
</>
|
|
) : (
|
|
<>
|
|
<div className="text-lg font-semibold truncate">{host.label}</div>
|
|
<div className="text-[11px] text-muted-foreground font-mono truncate">
|
|
{t(protocolInfo.i18nKey)} {protocolInfo.showPort ? formatHostPort(host.hostname, protocolInfo.port) : host.hostname}
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
<div className="flex items-center gap-2 shrink-0 ml-3">
|
|
{!needsAuth && (
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
className="h-8 text-xs"
|
|
onClick={() => setShowLogs(!showLogs)}
|
|
>
|
|
{showLogs ? t('terminal.connection.hideLogs') : t('terminal.connection.showLogs')}
|
|
</Button>
|
|
)}
|
|
{status === 'connecting' && !needsAuth && (
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
className="h-8 text-xs"
|
|
onClick={progressProps.onCancelConnect}
|
|
disabled={progressProps.isCancelling}
|
|
>
|
|
{progressProps.isCancelling ? t('terminal.progress.cancelling') : t('common.close')}
|
|
</Button>
|
|
)}
|
|
{canDismissDisconnected && (
|
|
<Button
|
|
size="icon"
|
|
variant="ghost"
|
|
className="h-8 w-8"
|
|
aria-label={t('terminal.connection.dismissDisconnectedDialog')}
|
|
title={t('terminal.connection.dismissDisconnectedDialog')}
|
|
onClick={onDismissDisconnected}
|
|
>
|
|
<X size={14} />
|
|
</Button>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<div className="flex items-center gap-3">
|
|
<div className={cn(
|
|
"h-8 w-8 rounded-lg flex items-center justify-center flex-shrink-0",
|
|
needsAuth
|
|
? "bg-primary text-primary-foreground"
|
|
: hasError
|
|
? "bg-destructive/20 text-destructive"
|
|
: isConnecting
|
|
? "bg-primary/15 text-primary"
|
|
: "bg-muted text-muted-foreground"
|
|
)}>
|
|
<Plug size={14} />
|
|
</div>
|
|
<div className="flex-1 h-1.5 rounded-full bg-border/60 overflow-hidden relative">
|
|
<div
|
|
className={cn(
|
|
"absolute inset-y-0 left-0 rounded-full transition-all duration-300",
|
|
error ? "bg-destructive" : "bg-primary"
|
|
)}
|
|
style={{
|
|
width: needsAuth ? '0%' : status === 'connecting' ? `${progressValue}%` : error ? '100%' : '100%',
|
|
}}
|
|
/>
|
|
</div>
|
|
<div className={cn(
|
|
"h-8 w-8 rounded-lg flex items-center justify-center flex-shrink-0",
|
|
hasError ? "bg-destructive/20 text-destructive" : "bg-muted text-muted-foreground"
|
|
)}>
|
|
{isConnecting ? (
|
|
<Loader2 size={14} className="animate-spin" />
|
|
) : (
|
|
<TerminalSquare size={14} />
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{needsAuth ? (
|
|
<TerminalAuthDialog {...authProps} keys={keys} />
|
|
) : (
|
|
<TerminalConnectionProgress
|
|
status={status}
|
|
error={error}
|
|
showLogs={showLogs}
|
|
{...progressProps}
|
|
/>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default TerminalConnectionDialog;
|