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", {
  + |     +  
` }) \ No newline at end of file diff --git a/web/public/js/components/server/ssl-config-box.js b/web/public/js/components/server/ssl-config-box.js index e8ba3493..45e5cccb 100644 --- a/web/public/js/components/server/ssl-config-box.js +++ b/web/public/js/components/server/ssl-config-box.js @@ -1,5 +1,9 @@ Vue.component("ssl-config-box", { - props: ["v-ssl-policy", "v-protocol", "v-server-id"], + props: [ + "v-ssl-policy", + "v-protocol", + "v-server-id" + ], created: function () { let that = this setTimeout(function () { @@ -131,8 +135,12 @@ Vue.component("ssl-config-box", { // 上传证书 uploadCert: function () { let that = this - teaweb.popup("/servers/certs/uploadPopup", { - height: "28em", + let serverId = this.vServerId + if (typeof serverId != "number" && typeof serverId != "string") { + serverId = 0 + } + teaweb.popup("/servers/certs/uploadPopup?serverId=" + serverId, { + height: "30em", callback: function (resp) { teaweb.success("上传成功", function () { that.policy.certRefs.push(resp.data.certRef) @@ -142,6 +150,28 @@ Vue.component("ssl-config-box", { }) }, + // 批量上传 + uploadBatch: function () { + let that = this + let serverId = this.vServerId + if (typeof serverId != "number" && typeof serverId != "string") { + serverId = 0 + } + teaweb.popup("/servers/certs/uploadBatchPopup?serverId=" + serverId, { + callback: function (resp) { + if (resp.data.cert != null) { + that.policy.certRefs.push(resp.data.certRef) + that.policy.certs.push(resp.data.cert) + } + if (resp.data.certs != null) { + that.policy.certRefs.$pushAll(resp.data.certRefs) + that.policy.certs.$pushAll(resp.data.certs) + } + that.$forceUpdate() + } + }) + }, + // 申请证书 requestCert: function () { // 已经在证书中的域名 @@ -387,7 +417,10 @@ Vue.component("ssl-config-box", {
  + |     +   + |   diff --git a/web/views/@default/servers/certs/uploadBatchPopup.html b/web/views/@default/servers/certs/uploadBatchPopup.html index 154772bf..a4ed0ef4 100644 --- a/web/views/@default/servers/certs/uploadBatchPopup.html +++ b/web/views/@default/servers/certs/uploadBatchPopup.html @@ -15,7 +15,7 @@ 所属用户 - +

可选项,指定证书所属的用户;指定用户后,上传的证书管理员无法在管理系统查看,只能在用户系统查看。

diff --git a/web/views/@default/servers/certs/uploadBatchPopup.js b/web/views/@default/servers/certs/uploadBatchPopup.js index 8330bce1..9846719c 100644 --- a/web/views/@default/servers/certs/uploadBatchPopup.js +++ b/web/views/@default/servers/certs/uploadBatchPopup.js @@ -1,6 +1,5 @@ Tea.context(function () { this.isRequesting = false - this.userId = 0 this.before = function () { this.isRequesting = true diff --git a/web/views/@default/servers/certs/uploadPopup.html b/web/views/@default/servers/certs/uploadPopup.html index c745ffba..d24fbe84 100644 --- a/web/views/@default/servers/certs/uploadPopup.html +++ b/web/views/@default/servers/certs/uploadPopup.html @@ -12,8 +12,15 @@

可以简单说明证书的用途。

+ + 所属用户 + + +

可选项,当前证书所属用户。

+ + - 证书类型 + 证书类型 *