import React from "react"; import { Button, Checkbox, Form, Input, InputNumber, Space, Typography } from "antd"; import { t } from "../../i18n"; import { getStoredSecretPlaceholder } from "../../utils/connectionModalPresentation"; import { noAutoCapInputProps } from "../../utils/inputAutoCap"; const { Text } = Typography; const DEFAULT_KEEPALIVE_INTERVAL_MINUTES = 240; const MIN_KEEPALIVE_INTERVAL_MINUTES = 1; const MAX_KEEPALIVE_INTERVAL_MINUTES = 1440; type ConnectionModalNetworkSecuritySectionProps = Record; const ConnectionModalNetworkSecuritySection: React.FC = (props) => { const { activeNetworkConfig, darkMode, dbType, form, getConnectionOptionCardStyle, handleSelectCertificateFile, handleSelectSSHKeyFile, initialValues, isFileDb, isJVM, isSSLType, modalInnerSectionStyle, modalMutedTextStyle, renderChoiceCards, renderStoredSecretControls, proxyType, selectingCertificateField, selectingSSHKey, setActiveNetworkConfig, sslHintText, sslMode, supportsSSLCAPath, supportsSSLClientCertificate, tunnelSectionStyle, useHttpTunnel, useProxy, useSSH, useSSL, } = props; if (isFileDb || isJVM) { return null; } const effectiveUseSSL = useSSL || !!form.getFieldValue("useSSL"); const effectiveUseSSH = useSSH || !!form.getFieldValue("useSSH"); const effectiveUseHttpTunnel = useHttpTunnel || !!form.getFieldValue("useHttpTunnel"); const effectiveUseProxy = !effectiveUseHttpTunnel && (useProxy || !!form.getFieldValue("useProxy")); const keepAliveEnabled = !!Form.useWatch("keepAliveEnabled", form); const networkItems: Array<{ key: "ssl" | "ssh" | "proxy" | "httpTunnel"; title: string; description: string; enabled: boolean; }> = [ ...(isSSLType ? [ { key: "ssl" as const, title: t("connection.modal.network.ssl_tls"), description: t( "connection.modal.network.ssl.description", ), enabled: effectiveUseSSL, }, ] : []), { key: "ssh", title: t("connection.modal.network.ssh.title"), description: t("connection.modal.network.ssh.description"), enabled: effectiveUseSSH, }, { key: "proxy", title: t("connection.modal.network.proxy.title"), description: t("connection.modal.network.proxy.description"), enabled: effectiveUseProxy, }, { key: "httpTunnel", title: t("connection.modal.network.httpTunnel.title"), description: t( "connection.modal.network.httpTunnel.description", ), enabled: effectiveUseHttpTunnel, }, ]; const resolvedNetworkConfig = activeNetworkConfig === "ssl" && !effectiveUseSSL ? networkItems.find((item) => item.enabled)?.key || (networkItems.some((item) => item.key === activeNetworkConfig) ? activeNetworkConfig : networkItems[0]?.key || "ssh") : networkItems.some((item) => item.key === activeNetworkConfig) ? activeNetworkConfig : networkItems[0]?.key || "ssh"; const renderNetworkPanel = () => { if (resolvedNetworkConfig === "ssl") { return (
{t("connection.modal.network.ssl_tls")}
{t("connection.modal.network.ssl.panelDescription")}
{!effectiveUseSSL ? (
{t("connection.modal.network.ssl.disabledHint")}
{sslHintText}
) : (
{t("connection.modal.network.ssl.mode")} {renderChoiceCards({ fieldName: "sslMode", value: String(sslMode), options: [ { value: "preferred", label: t( "connection.modal.network.ssl_mode.preferred", ), description: t( "connection.modal.network.ssl.preferred.description", ), }, { value: "required", label: t( "connection.modal.network.ssl_mode.required", ), description: t( "connection.modal.network.ssl.required.description", ), }, { value: "skip-verify", label: t( "connection.modal.network.ssl_mode.skip_verify", ), description: t( "connection.modal.network.ssl.skipVerify.description", ), }, ], })}
{(supportsSSLCAPath || supportsSSLClientCertificate) && (
{supportsSSLCAPath && ( )} {supportsSSLClientCertificate && ( <> )}
)} {sslHintText}
)}
); } if (resolvedNetworkConfig === "ssh") { return (
{t("connection.modal.network.ssh.title")}
{t("connection.modal.network.ssh.panelDescription")}
{!effectiveUseSSH ? (
{t("connection.modal.network.ssh.disabledHint")}
) : (
{renderStoredSecretControls({ fieldName: "sshPassword", clearKey: "sshPassword", hasStoredSecret: initialValues?.hasSSHPassword, clearLabel: t( "connection.modal.network.ssh.clearPassword", ), description: t( "connection.modal.network.ssh.savedDescription", ), })}
)}
); } if (resolvedNetworkConfig === "proxy") { return (
{t("connection.modal.network.proxy.title")}
{t("connection.modal.network.proxy.panelDescription")}
{!effectiveUseProxy ? (
{t("connection.modal.network.proxy.disabledHint")}
) : (
{t("connection.modal.network.proxy.type")} {renderChoiceCards({ fieldName: "proxyType", value: String(proxyType), minWidth: 150, options: [ { value: "socks5", label: "SOCKS5", description: t( "connection.modal.network.proxy.socks5.description", ), }, { value: "http", label: "HTTP CONNECT", description: t( "connection.modal.network.proxy.http.description", ), }, ], })}
{renderStoredSecretControls({ fieldName: "proxyPassword", clearKey: "proxyPassword", hasStoredSecret: initialValues?.hasProxyPassword, clearLabel: t( "connection.modal.network.proxy.clearPassword", ), description: t( "connection.modal.network.proxy.savedDescription", ), })}
)}
); } return (
{t("connection.modal.network.httpTunnel.title")}
{t( "connection.modal.network.httpTunnel.panelDescription", )}
{!effectiveUseHttpTunnel ? (
{t("connection.modal.network.httpTunnel.disabledHint")}
) : (
{renderStoredSecretControls({ fieldName: "httpTunnelPassword", clearKey: "httpTunnelPassword", hasStoredSecret: initialValues?.hasHttpTunnelPassword, clearLabel: t( "connection.modal.network.httpTunnel.clearPassword", ), description: t( "connection.modal.network.httpTunnel.savedDescription", ), })} {t( "connection.modal.network.httpTunnel.exclusiveHint", )}
)}
); }; return (
{t("connection.modal.network.title")}
{t("connection.modal.network.description")}
{networkItems.map((item) => { const active = item.key === resolvedNetworkConfig; const activeColor = darkMode ? "#ffd666" : "#1677ff"; return (
setActiveNetworkConfig(item.key)} onKeyDown={(event) => { if (event.key === "Enter" || event.key === " ") { event.preventDefault(); setActiveNetworkConfig(item.key); } }} style={{ ...getConnectionOptionCardStyle(item.enabled), borderColor: active ? darkMode ? "rgba(255,214,102,0.46)" : "rgba(24,144,255,0.36)" : "transparent", background: active ? darkMode ? "linear-gradient(180deg, rgba(255,214,102,0.14) 0%, rgba(255,214,102,0.08) 100%)" : "linear-gradient(180deg, rgba(24,144,255,0.12) 0%, rgba(24,144,255,0.06) 100%)" : getConnectionOptionCardStyle(item.enabled) .background, boxShadow: active ? darkMode ? "0 0 0 1px rgba(255,214,102,0.18) inset, 0 12px 26px rgba(0,0,0,0.16)" : "0 0 0 1px rgba(24,144,255,0.14) inset, 0 12px 22px rgba(24,144,255,0.10)" : "none", cursor: "pointer", outline: "none", }} >
{item.title}
{active && ( {t( "connection.modal.network.currentEditing", )} )} {item.enabled ? t("connection.modal.network.enabled") : t( "connection.modal.network.notEnabled", )}
{item.description}
); })}
{renderNetworkPanel()}
{t("connection.modal.network.advanced.title")}
{t("connection.modal.network.keepAliveEnabled.checkbox")}
); }; export default ConnectionModalNetworkSecuritySection;