From 02f806ab99b8e31ebde7af8ecfdd0452e17307e1 Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Thu, 20 Mar 2025 23:35:37 +0800 Subject: [PATCH] feat: preset script for backup files on deployment to local and ssh --- .../node/DeployNodeConfigFormLocalConfig.tsx | 72 +++++++++++++++---- .../node/DeployNodeConfigFormSSHConfig.tsx | 52 ++++++++++++-- .../i18n/locales/en/nls.workflow.nodes.json | 2 + .../i18n/locales/zh/nls.workflow.nodes.json | 2 + 4 files changed, 111 insertions(+), 17 deletions(-) diff --git a/ui/src/components/workflow/node/DeployNodeConfigFormLocalConfig.tsx b/ui/src/components/workflow/node/DeployNodeConfigFormLocalConfig.tsx index bd1cced6..1ca2fe8c 100644 --- a/ui/src/components/workflow/node/DeployNodeConfigFormLocalConfig.tsx +++ b/ui/src/components/workflow/node/DeployNodeConfigFormLocalConfig.tsx @@ -134,7 +134,24 @@ const DeployNodeConfigFormLocalConfig = ({ form: formInst, formName, disabled, i } }; - const handlePresetScriptClick = (key: string) => { + const handlePresetPreScriptClick = (key: string) => { + switch (key) { + case "backup_files": + { + formInst.setFieldValue("shellEnv", SHELLENV_SH); + formInst.setFieldValue( + "preCommand", + `# 请将以下路径替换为实际值 +cp "${formInst.getFieldValue("certPath")}" "${formInst.getFieldValue("certPath")}.bak" 2>/dev/null || : +cp "${formInst.getFieldValue("keyPath")}" "${formInst.getFieldValue("keyPath")}.bak" 2>/dev/null || : + `.trim() + ); + } + break; + } + }; + + const handlePresetPostScriptClick = (key: string) => { switch (key) { case "reload_nginx": { @@ -149,8 +166,8 @@ const DeployNodeConfigFormLocalConfig = ({ form: formInst, formName, disabled, i formInst.setFieldValue( "postCommand", `# 请将以下变量替换为实际值 -$pfxPath = "" # PFX 文件路径 -$pfxPassword = "" # PFX 密码 +$pfxPath = "${formInst.getFieldValue("certPath")}" # PFX 文件路径 +$pfxPassword = "${formInst.getFieldValue("pfxPassword")}" # PFX 密码 $siteName = "" # IIS 网站名称 $domain = "" # 域名 $ipaddr = "" # 绑定 IP,“*”表示所有 IP 绑定 @@ -186,8 +203,8 @@ Remove-Item -Path "$pfxPath" -Force formInst.setFieldValue( "postCommand", `# 请将以下变量替换为实际值 -$pfxPath = "" # PFX 文件路径 -$pfxPassword = "" # PFX 密码 +$pfxPath = "${formInst.getFieldValue("certPath")}" # PFX 文件路径 +$pfxPassword = "${formInst.getFieldValue("pfxPassword")}" # PFX 密码 $ipaddr = "" # 绑定 IP,“0.0.0.0”表示所有 IP 绑定,可填入域名。 $port = "" # 绑定端口 @@ -208,14 +225,15 @@ Remove-Item -Path "$pfxPath" -Force ); } break; + case "binding_rdp": { formInst.setFieldValue("shellEnv", SHELLENV_POWERSHELL); formInst.setFieldValue( "postCommand", `# 请将以下变量替换为实际值 -$pfxPath = "" # PFX 文件路径 -$pfxPassword = "" # PFX 密码 +$pfxPath = "${formInst.getFieldValue("certPath")}" # PFX 文件路径 +$pfxPassword = "${formInst.getFieldValue("pfxPassword")}" # PFX 密码 # 导入证书到本地计算机的个人存储区 $cert = Import-PfxCertificate -FilePath "$pfxPath" -CertStoreLocation Cert:\\LocalMachine\\My -Password (ConvertTo-SecureString -String "$pfxPassword" -AsPlainText -Force) -Exportable @@ -332,8 +350,36 @@ Set-ItemProperty -Path $rdpCertPath -Name "SSLCertificateSHA1Hash" -Value "$thum - - + + + + + @@ -349,22 +395,22 @@ Set-ItemProperty -Path $rdpCertPath -Name "SSLCertificateSHA1Hash" -Value "$thum { key: "reload_nginx", label: t("workflow_node.deploy.form.local_preset_scripts.option.reload_nginx.label"), - onClick: () => handlePresetScriptClick("reload_nginx"), + onClick: () => handlePresetPostScriptClick("reload_nginx"), }, { key: "binding_iis", label: t("workflow_node.deploy.form.local_preset_scripts.option.binding_iis.label"), - onClick: () => handlePresetScriptClick("binding_iis"), + onClick: () => handlePresetPostScriptClick("binding_iis"), }, { key: "binding_netsh", label: t("workflow_node.deploy.form.local_preset_scripts.option.binding_netsh.label"), - onClick: () => handlePresetScriptClick("binding_netsh"), + onClick: () => handlePresetPostScriptClick("binding_netsh"), }, { key: "binding_rdp", label: t("workflow_node.deploy.form.local_preset_scripts.option.binding_rdp.label"), - onClick: () => handlePresetScriptClick("binding_rdp"), + onClick: () => handlePresetPostScriptClick("binding_rdp"), }, ], }} diff --git a/ui/src/components/workflow/node/DeployNodeConfigFormSSHConfig.tsx b/ui/src/components/workflow/node/DeployNodeConfigFormSSHConfig.tsx index 1e176d7b..65a7df7b 100644 --- a/ui/src/components/workflow/node/DeployNodeConfigFormSSHConfig.tsx +++ b/ui/src/components/workflow/node/DeployNodeConfigFormSSHConfig.tsx @@ -127,7 +127,23 @@ const DeployNodeConfigFormSSHConfig = ({ form: formInst, formName, disabled, ini } }; - const handlePresetScriptClick = (key: string) => { + const handlePresetPreScriptClick = (key: string) => { + switch (key) { + case "backup_files": + { + formInst.setFieldValue( + "preCommand", + `# 请将以下路径替换为实际值 +cp "${formInst.getFieldValue("certPath")}" "${formInst.getFieldValue("certPath")}.bak" 2>/dev/null || : +cp "${formInst.getFieldValue("keyPath")}" "${formInst.getFieldValue("keyPath")}.bak" 2>/dev/null || : + `.trim() + ); + } + break; + } + }; + + const handlePresetPostScriptClick = (key: string) => { switch (key) { case "reload_nginx": { @@ -228,8 +244,36 @@ const DeployNodeConfigFormSSHConfig = ({ form: formInst, formName, disabled, ini