import type { ReactNode } from "react"; import { useI18n } from "../i18n"; import { HOP_VENDORS, defaultHopTemplate, expandBastionHopFields, isAutoHopTemplate, isBastionHopVendor, isLinuxHopVendor, patchHopVendorChange, type HopTargetAuthMode, type HopVendor, } from "../utils/hopProxy"; export type HopProxyFieldsState = { hop_vendor: HopVendor; hop_host: string; hop_port: number; hop_protocol: string; hop_username: string; hop_password: string; hop_command_template: string; hop_vrf: string; hop_target_auth_mode: HopTargetAuthMode; hop_enter_system_view: boolean; }; export const emptyHopProxyFields = (): HopProxyFieldsState => ({ hop_vendor: "zte", hop_host: "", hop_port: 22, hop_protocol: "ssh", hop_username: "", hop_password: "", hop_command_template: defaultHopTemplate("zte", "ssh", ""), hop_vrf: "", hop_target_auth_mode: "bastion_managed", hop_enter_system_view: false, }); function FormLabel({ children, required }: { children: ReactNode; required?: boolean }) { return ( {children} {required ? ( ) : null} ); } function applyHopTemplate( prev: HopProxyFieldsState, protocol: string, vrf: string, force = false, ): Partial { if (!force && !isAutoHopTemplate(prev.hop_command_template, prev.hop_vendor, prev.hop_protocol, prev.hop_vrf)) { return {}; } return { hop_command_template: defaultHopTemplate(prev.hop_vendor, protocol, vrf) }; } function hopHintKey(vendor: string): string { const v = String(vendor || "").toLowerCase(); if (v === "bastion") return "managedNe.hop.bastionHint"; if (v === "linux") return "managedNe.hop.linuxHint"; if (v === "huawei") return "managedNe.hop.huaweiHint"; if (v === "cisco") return "managedNe.hop.ciscoHint"; return "managedNe.hop.zteHint"; } function templateHintKey(vendor: string): string { const v = String(vendor || "").toLowerCase(); if (v === "bastion") return "managedNe.hop.templateHintBastion"; if (v === "huawei") return "managedNe.hop.templateHintHuawei"; if (v === "cisco") return "managedNe.hop.templateHintCisco"; return "managedNe.hop.templateHint"; } function vrfLabelKey(vendor: string): string { const v = String(vendor || "").toLowerCase(); if (v === "huawei") return "managedNe.hop.vpnInstance"; if (v === "cisco") return "managedNe.hop.vrfCisco"; return "managedNe.hop.vrf"; } type Props = { value: HopProxyFieldsState; onChange: (patch: Partial) => void; hopPasswordRequired?: boolean; hopPasswordOptional?: boolean; }; export function HopProxyFields({ value, onChange, hopPasswordRequired = true, hopPasswordOptional = false, }: Props) { const { t } = useI18n(); const linux = isLinuxHopVendor(value.hop_vendor); const bastion = isBastionHopVendor(value.hop_vendor); const huawei = value.hop_vendor === "huawei"; const cliHop = !linux && !bastion; const set = (patch: Partial) => onChange(patch); return (
{bastion ? ( ) : null} {cliHop ? ( ) : null} {bastion ? ( ) : null} {cliHop ? ( <> {huawei ? ( ) : null} ) : null}
); }