feat: Added option to paste private key
This commit is contained in:
@@ -425,6 +425,8 @@
|
|||||||
"dsa": "DSA",
|
"dsa": "DSA",
|
||||||
"rsaSha2256": "RSA SHA2-256",
|
"rsaSha2256": "RSA SHA2-256",
|
||||||
"rsaSha2512": "RSA SHA2-512",
|
"rsaSha2512": "RSA SHA2-512",
|
||||||
|
"uploadFile": "Upload File",
|
||||||
|
"pasteKey": "Paste Key",
|
||||||
"updateKey": "Update Key",
|
"updateKey": "Update Key",
|
||||||
"addTagsSpaceToAdd": "add tags (space to add)",
|
"addTagsSpaceToAdd": "add tags (space to add)",
|
||||||
"terminalBadge": "Terminal",
|
"terminalBadge": "Terminal",
|
||||||
@@ -809,6 +811,7 @@
|
|||||||
"folder": "folder",
|
"folder": "folder",
|
||||||
"password": "password",
|
"password": "password",
|
||||||
"keyPassword": "key password",
|
"keyPassword": "key password",
|
||||||
|
"pastePrivateKey": "Paste your private key here...",
|
||||||
"credentialName": "My SSH Server",
|
"credentialName": "My SSH Server",
|
||||||
"description": "SSH credential description",
|
"description": "SSH credential description",
|
||||||
"searchCredentials": "Search credentials by name, username, or tags...",
|
"searchCredentials": "Search credentials by name, username, or tags...",
|
||||||
|
|||||||
@@ -463,6 +463,8 @@
|
|||||||
"dsa": "DSA",
|
"dsa": "DSA",
|
||||||
"rsaSha2256": "RSA SHA2-256",
|
"rsaSha2256": "RSA SHA2-256",
|
||||||
"rsaSha2512": "RSA SHA2-512",
|
"rsaSha2512": "RSA SHA2-512",
|
||||||
|
"uploadFile": "上传文件",
|
||||||
|
"pasteKey": "粘贴密钥",
|
||||||
"updateKey": "更新密钥",
|
"updateKey": "更新密钥",
|
||||||
"addTagsSpaceToAdd": "添加标签(空格添加)",
|
"addTagsSpaceToAdd": "添加标签(空格添加)",
|
||||||
"terminalBadge": "终端",
|
"terminalBadge": "终端",
|
||||||
@@ -849,6 +851,7 @@
|
|||||||
"description": "SSH凭据描述",
|
"description": "SSH凭据描述",
|
||||||
"searchCredentials": "按名称、用户名或标签搜索凭据...",
|
"searchCredentials": "按名称、用户名或标签搜索凭据...",
|
||||||
"keyPassword": "密钥密码",
|
"keyPassword": "密钥密码",
|
||||||
|
"pastePrivateKey": "在此粘贴您的私钥...",
|
||||||
"sshConfig": "端点 SSH 配置",
|
"sshConfig": "端点 SSH 配置",
|
||||||
"homePath": "/home",
|
"homePath": "/home",
|
||||||
"clientId": "您的客户端 ID",
|
"clientId": "您的客户端 ID",
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ export function HostManagerHostEditor({editingHost, onFormSubmit}: SSHManagerHos
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const [authTab, setAuthTab] = useState<'password' | 'key' | 'credential'>('password');
|
const [authTab, setAuthTab] = useState<'password' | 'key' | 'credential'>('password');
|
||||||
|
const [keyInputMethod, setKeyInputMethod] = useState<'upload' | 'paste'>('upload');
|
||||||
|
|
||||||
// Ref for the IP address input to manage focus
|
// Ref for the IP address input to manage focus
|
||||||
const ipInputRef = useRef<HTMLInputElement>(null);
|
const ipInputRef = useRef<HTMLInputElement>(null);
|
||||||
@@ -696,40 +697,79 @@ export function HostManagerHostEditor({editingHost, onFormSubmit}: SSHManagerHos
|
|||||||
/>
|
/>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
<TabsContent value="key">
|
<TabsContent value="key">
|
||||||
<div className="grid grid-cols-15 gap-4">
|
<Tabs
|
||||||
<Controller
|
value={keyInputMethod}
|
||||||
control={form.control}
|
onValueChange={(value) => {
|
||||||
name="key"
|
setKeyInputMethod(value as 'upload' | 'paste');
|
||||||
render={({field}) => (
|
// Clear the other field when switching
|
||||||
<FormItem className="col-span-4 overflow-hidden min-w-0">
|
if (value === 'upload') {
|
||||||
<FormLabel>{t('hosts.sshPrivateKey')}</FormLabel>
|
form.setValue('key', null);
|
||||||
<FormControl>
|
} else {
|
||||||
<div className="relative min-w-0">
|
form.setValue('key', '');
|
||||||
<input
|
}
|
||||||
id="key-upload"
|
}}
|
||||||
type="file"
|
className="w-full"
|
||||||
accept=".pem,.key,.txt,.ppk"
|
>
|
||||||
onChange={(e) => {
|
<TabsList className="inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground">
|
||||||
const file = e.target.files?.[0];
|
<TabsTrigger value="upload">{t('hosts.uploadFile')}</TabsTrigger>
|
||||||
field.onChange(file || null);
|
<TabsTrigger value="paste">{t('hosts.pasteKey')}</TabsTrigger>
|
||||||
}}
|
</TabsList>
|
||||||
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
|
<TabsContent value="upload" className="mt-4">
|
||||||
|
<Controller
|
||||||
|
control={form.control}
|
||||||
|
name="key"
|
||||||
|
render={({field}) => (
|
||||||
|
<FormItem className="mb-4">
|
||||||
|
<FormLabel>{t('hosts.sshPrivateKey')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<div className="relative inline-block">
|
||||||
|
<input
|
||||||
|
id="key-upload"
|
||||||
|
type="file"
|
||||||
|
accept=".pem,.key,.txt,.ppk"
|
||||||
|
onChange={(e) => {
|
||||||
|
const file = e.target.files?.[0];
|
||||||
|
field.onChange(file || null);
|
||||||
|
}}
|
||||||
|
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
className="justify-start text-left"
|
||||||
|
>
|
||||||
|
<span className="truncate"
|
||||||
|
title={field.value?.name || t('hosts.upload')}>
|
||||||
|
{field.value ? (editingHost ? t('hosts.updateKey') : field.value.name) : t('hosts.upload')}
|
||||||
|
</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="paste" className="mt-4">
|
||||||
|
<Controller
|
||||||
|
control={form.control}
|
||||||
|
name="key"
|
||||||
|
render={({field}) => (
|
||||||
|
<FormItem className="mb-4">
|
||||||
|
<FormLabel>{t('hosts.sshPrivateKey')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<textarea
|
||||||
|
placeholder={t('placeholders.pastePrivateKey')}
|
||||||
|
className="flex min-h-[120px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
|
value={typeof field.value === 'string' ? field.value : ''}
|
||||||
|
onChange={(e) => field.onChange(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<Button
|
</FormControl>
|
||||||
type="button"
|
</FormItem>
|
||||||
variant="outline"
|
)}
|
||||||
className="w-full min-w-0 overflow-hidden px-3 py-2 text-left"
|
/>
|
||||||
>
|
</TabsContent>
|
||||||
<span className="block w-full truncate"
|
</Tabs>
|
||||||
title={field.value?.name || t('hosts.upload')}>
|
<div className="grid grid-cols-15 gap-4 mt-4">
|
||||||
{field.value ? (editingHost ? t('hosts.updateKey') : field.value.name) : t('hosts.upload')}
|
|
||||||
</span>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</FormControl>
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="keyPassword"
|
name="keyPassword"
|
||||||
|
|||||||
Reference in New Issue
Block a user