mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-17 02:25:02 +03:00
97e2c9e7ba
The auth-kind dropdown in the VLESS "Generate Key" block was hardcoded to x25519 on mount, while the "Already selected" text next to it was derived independently from settings.encryption. Editing an inbound whose encryption uses another kind (e.g. ML-KEM-768) showed a mismatched dropdown, and clicking Generate without noticing would produce a keypair of the wrong kind for the inbound. Extract the encryption-string parsing into a shared pure helper (lib/xray/vless-encryption), use it both for the selected-auth label and to initialize/sync the dropdown, so the two can no longer diverge. When the encryption is none or unparseable the dropdown keeps its x25519 default. Closes #5744
79 lines
2.6 KiB
TypeScript
79 lines
2.6 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { Button, Form, Input, InputNumber, Select, Space, Typography } from 'antd';
|
|
|
|
import { VLESS_AUTH_LABEL_KEYS, type VlessAuthKind } from '@/lib/xray/vless-encryption';
|
|
|
|
interface VlessFieldsProps {
|
|
saving: boolean;
|
|
selectedVlessAuth: string;
|
|
vlessAuthKind: VlessAuthKind | null;
|
|
network: string;
|
|
security: string;
|
|
getNewVlessEnc: (kind: VlessAuthKind) => void;
|
|
clearVlessEnc: () => void;
|
|
}
|
|
|
|
export default function VlessFields({
|
|
saving,
|
|
selectedVlessAuth,
|
|
vlessAuthKind,
|
|
network,
|
|
security,
|
|
getNewVlessEnc,
|
|
clearVlessEnc,
|
|
}: VlessFieldsProps) {
|
|
const { t } = useTranslation();
|
|
const [authKind, setAuthKind] = useState<VlessAuthKind>(vlessAuthKind ?? 'x25519');
|
|
|
|
useEffect(() => {
|
|
setAuthKind(vlessAuthKind ?? 'x25519');
|
|
}, [vlessAuthKind]);
|
|
|
|
const authOptions = (Object.entries(VLESS_AUTH_LABEL_KEYS) as [VlessAuthKind, string][]).map(
|
|
([value, labelKey]) => ({ value, label: t(labelKey) }),
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<Form.Item name={['settings', 'decryption']} label={t('pages.inbounds.decryption')}>
|
|
<Input />
|
|
</Form.Item>
|
|
<Form.Item name={['settings', 'encryption']} label={t('pages.inbounds.encryption')}>
|
|
<Input />
|
|
</Form.Item>
|
|
<Form.Item label={t('pages.inbounds.vlessAuthGenerate')}>
|
|
<Space size={8} wrap>
|
|
<Select
|
|
value={authKind}
|
|
onChange={(v) => setAuthKind(v)}
|
|
options={authOptions}
|
|
style={{ width: 240 }}
|
|
/>
|
|
<Button type="primary" loading={saving} onClick={() => getNewVlessEnc(authKind)}>
|
|
{t('pages.inbounds.vlessAuthGenerateButton')}
|
|
</Button>
|
|
<Button danger onClick={clearVlessEnc}>{t('clear')}</Button>
|
|
</Space>
|
|
<Typography.Text type="secondary" className="vless-auth-state">
|
|
{t('pages.inbounds.vlessAuthSelected', { auth: selectedVlessAuth })}
|
|
</Typography.Text>
|
|
</Form.Item>
|
|
{network === 'tcp' && (security === 'tls' || security === 'reality') && (
|
|
<Form.Item
|
|
label={t('pages.inbounds.form.visionTestseed')}
|
|
extra="Applies only to clients using the xtls-rprx-vision flow; ignored otherwise."
|
|
>
|
|
<Space.Compact block>
|
|
{[900, 500, 900, 256].map((def, i) => (
|
|
<Form.Item key={i} name={['settings', 'testseed', i]} noStyle initialValue={def}>
|
|
<InputNumber min={1} style={{ width: '25%' }} />
|
|
</Form.Item>
|
|
))}
|
|
</Space.Compact>
|
|
</Form.Item>
|
|
)}
|
|
</>
|
|
);
|
|
}
|