From 67ca7e3097173d982e7a31b6fa5dae14f4228d7b Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Tue, 29 Oct 2024 21:43:20 +0800 Subject: [PATCH 1/2] feat: add netsh preset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增本地Windows下使用netsh绑定证书的预设 --- ui/src/components/certimate/DeployToLocal.tsx | 34 +++++++++++++++++++ ui/src/i18n/locales/en/nls.domain.json | 1 + ui/src/i18n/locales/zh/nls.domain.json | 1 + 3 files changed, 36 insertions(+) diff --git a/ui/src/components/certimate/DeployToLocal.tsx b/ui/src/components/certimate/DeployToLocal.tsx index 672cf52c..bd808f82 100644 --- a/ui/src/components/certimate/DeployToLocal.tsx +++ b/ui/src/components/certimate/DeployToLocal.tsx @@ -199,6 +199,37 @@ $binding = Get-WebBinding -Name "$siteName" -Protocol "https" -Port $port -IPAdd # 绑定 SSL 证书 $binding.AddSslCertificate($thumbprint, "My") # 删除目录下的证书文件 +Remove-Item -Path "$pfxPath" -Force + `.trim(); + }); + setDeploy(newData); + } + break; + + case "binding_netsh": + { + const newData = produce(data, (draft) => { + draft.config ??= {}; + draft.config.shell = "powershell"; + draft.config.command = ` +# 请将以下变量替换为实际值 +$pfxPath = "" # PFX 文件路径 +$pfxPassword = "" # PFX 密码 +$ipaddr = "" # 绑定 IP,“0.0.0.0”表示所有 IP 绑定,可填入域名。 +$port = "" # 绑定端口 + +$addr = $ipaddr + ":" + $port + +# 导入证书到本地计算机的个人存储区 +$cert = Import-PfxCertificate -FilePath "$pfxPath" -CertStoreLocation Cert:\LocalMachine\My -Password (ConvertTo-SecureString -String "$pfxPassword" -AsPlainText -Force) -Exportable +# 获取 Thumbprint +$thumbprint = $cert.Thumbprint +# 检测端口是否绑定证书,如绑定则删除绑定 +$isExist = netsh http show sslcert ipport=$addr +if ($isExist -like "*$addr*"){ netsh http delete sslcert ipport=$addr } +# 绑定到端口 +netsh http add sslcert ipport=$addr certhash=$thumbprint +# 删除目录下的证书文件 Remove-Item -Path "$pfxPath" -Force `.trim(); }); @@ -425,6 +456,9 @@ Remove-Item -Path "$pfxPath" -Force handleUsePresetScript("binding_iis")}> {t("domain.deployment.form.shell_preset_scripts.option.binding_iis.label")} + handleUsePresetScript("binding_netsh")}> + {t("domain.deployment.form.shell_preset_scripts.option.binding_netsh.label")} + diff --git a/ui/src/i18n/locales/en/nls.domain.json b/ui/src/i18n/locales/en/nls.domain.json index 06e78c6d..3ea712ab 100644 --- a/ui/src/i18n/locales/en/nls.domain.json +++ b/ui/src/i18n/locales/en/nls.domain.json @@ -146,6 +146,7 @@ "domain.deployment.form.shell_preset_scripts.trigger": "Use Preset Scripts", "domain.deployment.form.shell_preset_scripts.option.reload_nginx.label": "Bash - Reload Nginx", "domain.deployment.form.shell_preset_scripts.option.binding_iis.label": "PowerShell - Binding IIS", + "domain.deployment.form.shell_preset_scripts.option.binding_netsh.label": "PowerShell - Binding netsh(Windows)", "domain.deployment.form.k8s_namespace.label": "Namespace", "domain.deployment.form.k8s_namespace.placeholder": "Please enter namespace", "domain.deployment.form.k8s_secret_name.label": "Secret Name", diff --git a/ui/src/i18n/locales/zh/nls.domain.json b/ui/src/i18n/locales/zh/nls.domain.json index 7ccf94ba..1df7795b 100644 --- a/ui/src/i18n/locales/zh/nls.domain.json +++ b/ui/src/i18n/locales/zh/nls.domain.json @@ -143,6 +143,7 @@ "domain.deployment.form.shell_preset_scripts.trigger": "使用预设脚本", "domain.deployment.form.shell_preset_scripts.option.reload_nginx.label": "Bash - 重启 nginx", "domain.deployment.form.shell_preset_scripts.option.binding_iis.label": "PowerShell - 导入并绑定到 IIS(需管理员权限)", + "domain.deployment.form.shell_preset_scripts.option.binding_netsh.label": "PowerShell - 导入并绑定到netsh(需管理员权限)", "domain.deployment.form.k8s_namespace.label": "命名空间", "domain.deployment.form.k8s_namespace.placeholder": "请输入 K8S 命名空间", "domain.deployment.form.k8s_secret_name.label": "Secret 名称", From b4599df6c6194116497e0ea00a3b600c337ace4d Mon Sep 17 00:00:00 2001 From: yoan <536464346@qq.com> Date: Wed, 30 Oct 2024 12:28:59 +0800 Subject: [PATCH 2/2] code format --- ui/src/components/certimate/DeployToLocal.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/src/components/certimate/DeployToLocal.tsx b/ui/src/components/certimate/DeployToLocal.tsx index bd808f82..ae60e75d 100644 --- a/ui/src/components/certimate/DeployToLocal.tsx +++ b/ui/src/components/certimate/DeployToLocal.tsx @@ -206,7 +206,7 @@ Remove-Item -Path "$pfxPath" -Force } break; - case "binding_netsh": + case "binding_netsh": { const newData = produce(data, (draft) => { draft.config ??= {}; @@ -221,7 +221,7 @@ $port = "" # 绑定端口 $addr = $ipaddr + ":" + $port # 导入证书到本地计算机的个人存储区 -$cert = Import-PfxCertificate -FilePath "$pfxPath" -CertStoreLocation Cert:\LocalMachine\My -Password (ConvertTo-SecureString -String "$pfxPassword" -AsPlainText -Force) -Exportable +$cert = Import-PfxCertificate -FilePath "$pfxPath" -CertStoreLocation Cert:\\LocalMachine\\My -Password (ConvertTo-SecureString -String "$pfxPassword" -AsPlainText -Force) -Exportable # 获取 Thumbprint $thumbprint = $cert.Thumbprint # 检测端口是否绑定证书,如绑定则删除绑定