From b8d3ab4f61f57582b654bcdeab285966b088a427 Mon Sep 17 00:00:00 2001
From: ssongliu <73214554+ssongliu@users.noreply.github.com>
Date: Thu, 7 Dec 2023 17:32:07 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E9=9D=A2=E6=9D=BF=E8=AE=BE=E7=BD=AE=20?=
=?UTF-8?q?SSL=20=E6=94=AF=E6=8C=81=E9=80=89=E6=8B=A9=E6=9C=AC=E5=9C=B0?=
=?UTF-8?q?=E8=AF=81=E4=B9=A6=20(#3219)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
backend/app/dto/setting.go | 2 +-
backend/app/service/setting.go | 15 +++++-
frontend/src/views/setting/safe/index.vue | 2 +-
frontend/src/views/setting/safe/ssl/index.vue | 47 +++++++++++++++++--
4 files changed, 60 insertions(+), 6 deletions(-)
diff --git a/backend/app/dto/setting.go b/backend/app/dto/setting.go
index 866734261..5da1a3dc0 100644
--- a/backend/app/dto/setting.go
+++ b/backend/app/dto/setting.go
@@ -60,7 +60,7 @@ type SettingUpdate struct {
}
type SSLUpdate struct {
- SSLType string `json:"sslType"`
+ SSLType string `json:"sslType" validate:"required,oneof=self select import-paste import-local"`
Domain string `json:"domain"`
SSL string `json:"ssl" validate:"required,oneof=enable disable"`
Cert string `json:"cert"`
diff --git a/backend/app/service/setting.go b/backend/app/service/setting.go
index 6c5cf55b4..d7192145f 100644
--- a/backend/app/service/setting.go
+++ b/backend/app/service/setting.go
@@ -174,6 +174,7 @@ func (u *SettingService) UpdatePort(port uint) error {
return err
}
go func() {
+ time.Sleep(1 * time.Second)
_, err := cmd.Exec("systemctl restart 1panel.service")
if err != nil {
global.LOG.Errorf("restart system port failed, err: %v", err)
@@ -249,9 +250,20 @@ func (u *SettingService) UpdateSSL(c *gin.Context, req dto.SSLUpdate) error {
if err := settingRepo.Update("SSLID", strconv.Itoa(int(req.SSLID))); err != nil {
return err
}
- case "import":
+ case "import-paste":
secret = req.Cert
key = req.Key
+ case "import-local":
+ keyFile, err := os.ReadFile(req.Key)
+ if err != nil {
+ return err
+ }
+ key = string(keyFile)
+ certFile, err := os.ReadFile(req.Cert)
+ if err != nil {
+ return err
+ }
+ secret = string(certFile)
}
fileOp := files.NewFileOp()
@@ -274,6 +286,7 @@ func (u *SettingService) UpdateSSL(c *gin.Context, req dto.SSLUpdate) error {
return err
}
go func() {
+ time.Sleep(1 * time.Second)
_, err := cmd.Exec("systemctl restart 1panel.service")
if err != nil {
global.LOG.Errorf("restart system failed, err: %v", err)
diff --git a/frontend/src/views/setting/safe/index.vue b/frontend/src/views/setting/safe/index.vue
index b04a1ade4..3f43b2746 100644
--- a/frontend/src/views/setting/safe/index.vue
+++ b/frontend/src/views/setting/safe/index.vue
@@ -299,7 +299,7 @@ const handleSSL = async () => {
type: 'info',
})
.then(async () => {
- await updateSSL({ ssl: 'disable', domain: '', sslType: '', key: '', cert: '', sslID: 0 });
+ await updateSSL({ ssl: 'disable', domain: '', sslType: form.sslType, key: '', cert: '', sslID: 0 });
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
let href = window.location.href;
globalStore.isLogin = false;
diff --git a/frontend/src/views/setting/safe/ssl/index.vue b/frontend/src/views/setting/safe/ssl/index.vue
index b110ec287..efc5c0dde 100644
--- a/frontend/src/views/setting/safe/ssl/index.vue
+++ b/frontend/src/views/setting/safe/ssl/index.vue
@@ -30,6 +30,12 @@
{{ $t('setting.selfSignedHelper') }}
+