From 5a8deddc6304f295c4c5923e8508cc6d3eec1901 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Sat, 6 May 2023 16:51:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20ssl=20=E8=AE=BE=E7=BD=AE=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=87=8D=E5=90=AF=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=20(#905)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/utils/ssl/ssl.go | 4 +-- frontend/src/lang/modules/en.ts | 1 + frontend/src/lang/modules/zh.ts | 1 + frontend/src/views/setting/safe/ssl/index.vue | 36 +++++++++++-------- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/backend/utils/ssl/ssl.go b/backend/utils/ssl/ssl.go index 34f59792d..15a48f0fc 100644 --- a/backend/utils/ssl/ssl.go +++ b/backend/utils/ssl/ssl.go @@ -90,7 +90,7 @@ func GenerateSSL(domain string) error { pemBytes = append(pemBytes, pem.EncodeToMemory(clientCertBlock)...) pemBytes = append(pemBytes, pem.EncodeToMemory(interCertBlock)...) pemBytes = append(pemBytes, pem.EncodeToMemory(rootCertBlock)...) - certOut, err := os.OpenFile(global.CONF.System.BaseDir+"/1panel/secret/server.crt", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) + certOut, err := os.OpenFile(global.CONF.System.BaseDir+"/1panel/secret/server.crt.tmp", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { return err } @@ -99,7 +99,7 @@ func GenerateSSL(domain string) error { return err } - keyOut, err := os.OpenFile(global.CONF.System.BaseDir+"/1panel/secret/server.key", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) + keyOut, err := os.OpenFile(global.CONF.System.BaseDir+"/1panel/secret/server.key.tmp", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { return err } diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index ae76434d1..cb1e03609 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -896,6 +896,7 @@ const message = { mfaHelper2: 'Scan the following QR code using the mobile app to obtain the 6-digit verification code', mfaHelper3: 'Enter six digits from the app', mfaCode: 'Code', + sslChangeHelper: 'Modify the https setting and restart the service. Do you want to continue?', sslDisable: 'Disable', sslDisableHelper: 'If the https service is disabled, you need to restart the panel for it to take effect. Do you want to continue?', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index d23e8a8c8..77b4a474f 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -931,6 +931,7 @@ const message = { mfaHelper2: '使用手机应用扫描以下二维码,获取 6 位验证码', mfaHelper3: '输入手机应用上的 6 位数字', mfaCode: '验证码', + sslChangeHelper: 'https 设置修改需要重启服务,是否继续?', sslDisable: '禁用', sslDisableHelper: '禁用 https 服务,需要重启面板才能生效,是否继续?', diff --git a/frontend/src/views/setting/safe/ssl/index.vue b/frontend/src/views/setting/safe/ssl/index.vue index 89a595149..19aec650d 100644 --- a/frontend/src/views/setting/safe/ssl/index.vue +++ b/frontend/src/views/setting/safe/ssl/index.vue @@ -110,7 +110,7 @@ import { MsgSuccess } from '@/utils/message'; import { updateSSL } from '@/api/modules/setting'; import { DownloadByPath } from '@/api/modules/files'; import { Rules } from '@/global/form-rules'; -import { FormInstance } from 'element-plus'; +import { ElMessageBox, FormInstance } from 'element-plus'; import { Setting } from '@/api/interface/setting'; const loading = ref(); @@ -189,21 +189,27 @@ const onSaveSSL = async (formEl: FormInstance | undefined) => { if (!formEl) return; formEl.validate(async (valid) => { if (!valid) return; - let param = { - ssl: 'enable', - sslType: form.sslType, - domain: '', - sslID: form.sslID, - cert: form.cert, - key: form.key, - }; - let href = window.location.href; - param.domain = href.split('//')[1].split(':')[0]; - await updateSSL(param).then(() => { - MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); + ElMessageBox.confirm(i18n.global.t('setting.sslChangeHelper'), 'https', { + confirmButtonText: i18n.global.t('commons.button.confirm'), + cancelButtonText: i18n.global.t('commons.button.cancel'), + type: 'info', + }).then(async () => { + let param = { + ssl: 'enable', + sslType: form.sslType, + domain: '', + sslID: form.sslID, + cert: form.cert, + key: form.key, + }; let href = window.location.href; - let address = href.split('://')[1]; - window.open(`https://${address}/`, '_self'); + param.domain = href.split('//')[1].split(':')[0]; + await updateSSL(param).then(() => { + MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); + let href = window.location.href; + let address = href.split('://')[1]; + window.open(`https://${address}/`, '_self'); + }); }); }); };