diff --git a/agent/app/dto/request/website.go b/agent/app/dto/request/website.go index c97d64078..b713dcc2d 100644 --- a/agent/app/dto/request/website.go +++ b/agent/app/dto/request/website.go @@ -33,6 +33,7 @@ type WebsiteCreate struct { RuntimeConfig FtpConfig DataBaseConfig + SSLConfig } type RuntimeConfig struct { @@ -54,6 +55,11 @@ type DataBaseConfig struct { DBFormat string `json:"dbFormat"` } +type SSLConfig struct { + EnableSSL bool `json:"enableSSL"` + WebsiteSSLID uint `json:"websiteSSLID"` +} + type NewAppInstall struct { Name string `json:"name"` AppDetailId uint `json:"appDetailID"` diff --git a/agent/app/service/website.go b/agent/app/service/website.go index a17938f42..705f8544a 100644 --- a/agent/app/service/website.go +++ b/agent/app/service/website.go @@ -442,6 +442,35 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error) createTask.AddSubTask(i18n.GetMsgByKey("ConfigOpenresty"), configNginx, deleteWebsite) + if create.EnableSSL { + enableSSL := func(t *task.Task) error { + websiteModel, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(create.WebsiteSSLID)) + if err != nil { + return err + } + website.Protocol = constant.ProtocolHTTPS + website.WebsiteSSLID = create.WebsiteSSLID + appSSLReq := request.WebsiteHTTPSOp{ + WebsiteID: website.ID, + Enable: true, + WebsiteSSLID: websiteModel.ID, + Type: "existed", + HttpConfig: "HTTPToHTTPS", + SSLProtocol: []string{"TLSv1.3", "TLSv1.2", "TLSv1.1", "TLSv1"}, + Algorithm: "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK:!KRB5:!SRP:!CAMELLIA:!SEED", + Hsts: true, + } + if err = applySSL(*website, *websiteModel, appSSLReq); err != nil { + return err + } + if err = websiteRepo.Save(context.Background(), website); err != nil { + return err + } + return nil + } + createTask.AddSubTaskWithIgnoreErr(i18n.GetMsgByKey("EnableSSL"), enableSSL) + } + return createTask.Execute() } diff --git a/agent/app/task/task.go b/agent/app/task/task.go index 5b69fe147..d5ac3b269 100644 --- a/agent/app/task/task.go +++ b/agent/app/task/task.go @@ -31,13 +31,14 @@ type Task struct { } type SubTask struct { - RootTask *Task - Name string - Retry int - Timeout time.Duration - Action ActionFunc - Rollback RollbackFunc - Error error + RootTask *Task + Name string + Retry int + Timeout time.Duration + Action ActionFunc + Rollback RollbackFunc + Error error + IgnoreErr bool } const ( @@ -111,6 +112,11 @@ func (t *Task) AddSubTaskWithOps(name string, action ActionFunc, rollback Rollba t.SubTasks = append(t.SubTasks, subTask) } +func (t *Task) AddSubTaskWithIgnoreErr(name string, action ActionFunc) { + subTask := &SubTask{RootTask: t, Name: name, Retry: 0, Timeout: 10 * time.Minute, Action: action, Rollback: nil, IgnoreErr: true} + t.SubTasks = append(t.SubTasks, subTask) +} + func (s *SubTask) Execute() error { s.RootTask.Log(s.Name) var err error @@ -166,6 +172,10 @@ func (t *Task) Execute() error { t.Rollbacks = append(t.Rollbacks, subTask.Rollback) } } else { + if subTask.IgnoreErr { + err = nil + continue + } t.Task.ErrorMsg = err.Error() t.Task.Status = constant.StatusFailed for _, rollback := range t.Rollbacks { diff --git a/agent/i18n/lang/en.yaml b/agent/i18n/lang/en.yaml index 9356f7217..bc3e74667 100644 --- a/agent/i18n/lang/en.yaml +++ b/agent/i18n/lang/en.yaml @@ -233,4 +233,5 @@ Run: "Run" Stop: 'Stop', Image: 'Image', AppLink: 'Associated Application' +EnableSSL: "Enable HTTPS" diff --git a/agent/i18n/lang/zh-Hant.yaml b/agent/i18n/lang/zh-Hant.yaml index 2032e1fc1..2855947dc 100644 --- a/agent/i18n/lang/zh-Hant.yaml +++ b/agent/i18n/lang/zh-Hant.yaml @@ -235,4 +235,5 @@ Run: "啟動" Stop: '停止', Image: '鏡像', AppLink: '關聯應用' +EnableSSL: "開啟 HTTPS" diff --git a/agent/i18n/lang/zh.yaml b/agent/i18n/lang/zh.yaml index c55769d49..d46500947 100644 --- a/agent/i18n/lang/zh.yaml +++ b/agent/i18n/lang/zh.yaml @@ -237,3 +237,4 @@ Run: "启动" Stop: "停止" Image: "镜像" AppLink: "关联应用" +EnableSSL: "开启 HTTPS" diff --git a/frontend/src/api/interface/website.ts b/frontend/src/api/interface/website.ts index fddf41a7a..53056653d 100644 --- a/frontend/src/api/interface/website.ts +++ b/frontend/src/api/interface/website.ts @@ -80,6 +80,14 @@ export namespace Website { ftpUser: string; ftpPassword: string; taskID: string; + SSLID?: number; + enableSSL: boolean; + createDB?: boolean; + dbName?: string; + dbPassword?: string; + dbFormat?: string; + dbUser?: string; + dbHost?: string; } export interface WebSiteUpdateReq { diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 188b29854..42cfa2457 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -2128,6 +2128,7 @@ const message = { sniHelper: "When the reverse proxy backend is HTTPS, you might need to set the origin SNI. Please refer to the CDN service provider's documentation for details.", createDb: 'Create Database', + enableSSLHelper: 'Failure to enable will not affect the creation of the website', }, php: { short_open_tag: 'Short tag support', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 22163613b..11954a080 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -1978,6 +1978,7 @@ const message = { sni: '回源 SNI', sniHelper: '反代後端為 https 的時候可能需要設置回源 SNI,具體需要看 CDN 服務商文檔', createDb: '建立資料庫', + enableSSLHelper: '開啟失敗不會影響網站創建', }, php: { short_open_tag: '短標簽支持', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 3ded6bdd0..022d3391a 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -1980,6 +1980,7 @@ const message = { sni: '回源 SNI', sniHelper: '反代后端为 https 的时候可能需要设置回源 SNI,具体需要看 CDN 服务商文档', createDb: '创建数据库', + enableSSLHelper: '开启失败不会影响网站创建', }, php: { short_open_tag: '短标签支持', diff --git a/frontend/src/views/website/website/config/basic/https/index.vue b/frontend/src/views/website/website/config/basic/https/index.vue index bb49b820b..067022a9f 100644 --- a/frontend/src/views/website/website/config/basic/https/index.vue +++ b/frontend/src/views/website/website/config/basic/https/index.vue @@ -16,7 +16,7 @@ {{ $t('website.ipWebsiteWarn') }} {{ $t('website.SSLConfig') }} - + diff --git a/frontend/src/views/website/website/create/index.vue b/frontend/src/views/website/website/create/index.vue index 5cae87cff..d7eae4630 100644 --- a/frontend/src/views/website/website/create/index.vue +++ b/frontend/src/views/website/website/create/index.vue @@ -351,7 +351,7 @@ + + + {{ $t('website.enableSSLHelper') }} + + +
+ + + + + + {{ acme.email }} + {{ getAccountName(acme.type) }} + + + + + + + + + + + + + {{ websiteSSL.primaryDomain }} + + + {{ websiteSSL.domains }} + + + {{ websiteSSL.organization }} + + + {{ getProvider(websiteSSL.provider) }} + + + {{ websiteSSL.acmeAccount.email }} + + + {{ dateFormatSimple(websiteSSL.expireDate) }} + + + {{ websiteSSL.description }} + + + +
@@ -441,7 +510,7 @@