diff --git a/internal/web/actions/default/servers/certs/uploadBatchPopup.go b/internal/web/actions/default/servers/certs/uploadBatchPopup.go index 68350b5f..6bec420e 100644 --- a/internal/web/actions/default/servers/certs/uploadBatchPopup.go +++ b/internal/web/actions/default/servers/certs/uploadBatchPopup.go @@ -15,6 +15,7 @@ import ( "strings" ) +// UploadBatchPopupAction 批量上传证书 type UploadBatchPopupAction struct { actionutils.ParentAction } @@ -23,7 +24,24 @@ func (this *UploadBatchPopupAction) Init() { this.Nav("", "", "") } -func (this *UploadBatchPopupAction) RunGet(params struct{}) { +func (this *UploadBatchPopupAction) RunGet(params struct { + ServerId int64 + UserId int64 +}) { + // 读取服务用户 + if params.ServerId > 0 { + serverResp, err := this.RPC().ServerRPC().FindEnabledUserServerBasic(this.AdminContext(), &pb.FindEnabledUserServerBasicRequest{ServerId: params.ServerId}) + if err != nil { + this.ErrorPage(err) + return + } + var server = serverResp.Server + if server != nil { + params.UserId = server.UserId + } + } + + this.Data["userId"] = params.UserId this.Data["maxFiles"] = this.maxFiles() this.Show() @@ -128,6 +146,7 @@ func (this *UploadBatchPopupAction) RunPost(params struct { // 组织 CertConfig var pbCerts = []*pb.CreateSSLCertsRequestCert{} + var certConfigs = []*sslconfigs.SSLCertConfig{} for _, pair := range pairs { certData, keyData := pair[0], pair[1] @@ -142,6 +161,8 @@ func (this *UploadBatchPopupAction) RunPost(params struct { return } + certConfigs = append(certConfigs, certConfig) + var certName = "" if len(certConfig.DNSNames) > 0 { certName = certConfig.DNSNames[0] @@ -149,6 +170,7 @@ func (this *UploadBatchPopupAction) RunPost(params struct { certName += "等" + types.String(len(certConfig.DNSNames)) + "个域名" } } + certConfig.Name = certName pbCerts = append(pbCerts, &pb.CreateSSLCertsRequestCert{ IsOn: true, @@ -165,7 +187,7 @@ func (this *UploadBatchPopupAction) RunPost(params struct { }) } - _, err := this.RPC().SSLCertRPC().CreateSSLCerts(this.AdminContext(), &pb.CreateSSLCertsRequest{ + createResp, err := this.RPC().SSLCertRPC().CreateSSLCerts(this.AdminContext(), &pb.CreateSSLCertsRequest{ UserId: params.UserId, SSLCerts: pbCerts, }) @@ -173,7 +195,31 @@ func (this *UploadBatchPopupAction) RunPost(params struct { this.ErrorPage(err) return } + var certIds = createResp.SslCertIds + if len(certIds) != len(certConfigs) { + this.Fail("上传成功但API返回的证书ID数量错误,请反馈给开发者") + return + } + // 返回数据 this.Data["count"] = len(pbCerts) + + var certRefs = []*sslconfigs.SSLCertRef{} + for index, cert := range certConfigs { + // ID + cert.Id = certIds[index] + + // 减少不必要的数据 + cert.CertData = nil + cert.KeyData = nil + + certRefs = append(certRefs, &sslconfigs.SSLCertRef{ + IsOn: true, + CertId: cert.Id, + }) + } + this.Data["certs"] = certConfigs + this.Data["certRefs"] = certRefs + this.Success() } diff --git a/internal/web/actions/default/servers/certs/uploadPopup.go b/internal/web/actions/default/servers/certs/uploadPopup.go index 3dc2a9bd..9f29d25d 100644 --- a/internal/web/actions/default/servers/certs/uploadPopup.go +++ b/internal/web/actions/default/servers/certs/uploadPopup.go @@ -18,11 +18,30 @@ func (this *UploadPopupAction) Init() { this.Nav("", "", "") } -func (this *UploadPopupAction) RunGet(params struct{}) { +func (this *UploadPopupAction) RunGet(params struct { + ServerId int64 + UserId int64 +}) { + // 读取服务用户 + if params.ServerId > 0 { + serverResp, err := this.RPC().ServerRPC().FindEnabledUserServerBasic(this.AdminContext(), &pb.FindEnabledUserServerBasicRequest{ServerId: params.ServerId}) + if err != nil { + this.ErrorPage(err) + return + } + var server = serverResp.Server + if server != nil { + params.UserId = server.UserId + } + } + this.Data["userId"] = params.UserId + this.Show() } func (this *UploadPopupAction) RunPost(params struct { + UserId int64 + TextMode bool Name string IsCA bool @@ -107,6 +126,7 @@ func (this *UploadPopupAction) RunPost(params struct { // 保存 createResp, err := this.RPC().SSLCertRPC().CreateSSLCert(this.AdminContext(), &pb.CreateSSLCertRequest{ IsOn: params.IsOn, + UserId: params.UserId, Name: params.Name, Description: params.Description, ServerName: "", diff --git a/web/public/js/components/server/ssl-certs-box.js b/web/public/js/components/server/ssl-certs-box.js index 0e9354cb..8c1993d8 100644 --- a/web/public/js/components/server/ssl-certs-box.js +++ b/web/public/js/components/server/ssl-certs-box.js @@ -97,16 +97,46 @@ Vue.component("ssl-certs-box", { // 上传证书 uploadCert: function () { let that = this - teaweb.popup("/servers/certs/uploadPopup", { + let userId = this.vUserId + if (typeof userId != "number" && typeof userId != "string") { + userId = 0 + } + teaweb.popup("/servers/certs/uploadPopup?userId=" + userId, { height: "28em", callback: function (resp) { teaweb.success("上传成功", function () { - that.certs.push(resp.data.cert) + if (resp.data.cert != null) { + that.certs.push(resp.data.cert) + } + if (resp.data.certs != null) { + that.certs.$pushAll(resp.data.certs) + } + that.$forceUpdate() }) } }) }, + // 批量上传 + uploadBatch: function () { + let that = this + let userId = this.vUserId + if (typeof userId != "number" && typeof userId != "string") { + userId = 0 + } + teaweb.popup("/servers/certs/uploadBatchPopup?userId=" + userId, { + callback: function (resp) { + if (resp.data.cert != null) { + that.certs.push(resp.data.cert) + } + if (resp.data.certs != null) { + that.certs.$pushAll(resp.data.certs) + } + that.$forceUpdate() + } + }) + }, + // 格式化时间 formatTime: function (timestamp) { return new Date(timestamp * 1000).format("Y-m-d") @@ -132,7 +162,9 @@ Vue.component("ssl-certs-box", {
可选项,指定证书所属的用户;指定用户后,上传的证书管理员无法在管理系统查看,只能在用户系统查看。
可以简单说明证书的用途。
+可选项,当前证书所属用户。
+