mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 13:10:26 +08:00 
			
		
		
		
	创建服务和修改服务HTTPS设置时也支持批量上传证书
This commit is contained in:
		@@ -15,6 +15,7 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// UploadBatchPopupAction 批量上传证书
 | 
				
			||||||
type UploadBatchPopupAction struct {
 | 
					type UploadBatchPopupAction struct {
 | 
				
			||||||
	actionutils.ParentAction
 | 
						actionutils.ParentAction
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -23,7 +24,24 @@ func (this *UploadBatchPopupAction) Init() {
 | 
				
			|||||||
	this.Nav("", "", "")
 | 
						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.Data["maxFiles"] = this.maxFiles()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	this.Show()
 | 
						this.Show()
 | 
				
			||||||
@@ -128,6 +146,7 @@ func (this *UploadBatchPopupAction) RunPost(params struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// 组织 CertConfig
 | 
						// 组织 CertConfig
 | 
				
			||||||
	var pbCerts = []*pb.CreateSSLCertsRequestCert{}
 | 
						var pbCerts = []*pb.CreateSSLCertsRequestCert{}
 | 
				
			||||||
 | 
						var certConfigs = []*sslconfigs.SSLCertConfig{}
 | 
				
			||||||
	for _, pair := range pairs {
 | 
						for _, pair := range pairs {
 | 
				
			||||||
		certData, keyData := pair[0], pair[1]
 | 
							certData, keyData := pair[0], pair[1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -142,6 +161,8 @@ func (this *UploadBatchPopupAction) RunPost(params struct {
 | 
				
			|||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							certConfigs = append(certConfigs, certConfig)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		var certName = ""
 | 
							var certName = ""
 | 
				
			||||||
		if len(certConfig.DNSNames) > 0 {
 | 
							if len(certConfig.DNSNames) > 0 {
 | 
				
			||||||
			certName = certConfig.DNSNames[0]
 | 
								certName = certConfig.DNSNames[0]
 | 
				
			||||||
@@ -149,6 +170,7 @@ func (this *UploadBatchPopupAction) RunPost(params struct {
 | 
				
			|||||||
				certName += "等" + types.String(len(certConfig.DNSNames)) + "个域名"
 | 
									certName += "等" + types.String(len(certConfig.DNSNames)) + "个域名"
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							certConfig.Name = certName
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		pbCerts = append(pbCerts, &pb.CreateSSLCertsRequestCert{
 | 
							pbCerts = append(pbCerts, &pb.CreateSSLCertsRequestCert{
 | 
				
			||||||
			IsOn:        true,
 | 
								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,
 | 
							UserId:   params.UserId,
 | 
				
			||||||
		SSLCerts: pbCerts,
 | 
							SSLCerts: pbCerts,
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
@@ -173,7 +195,31 @@ func (this *UploadBatchPopupAction) RunPost(params struct {
 | 
				
			|||||||
		this.ErrorPage(err)
 | 
							this.ErrorPage(err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						var certIds = createResp.SslCertIds
 | 
				
			||||||
 | 
						if len(certIds) != len(certConfigs) {
 | 
				
			||||||
 | 
							this.Fail("上传成功但API返回的证书ID数量错误,请反馈给开发者")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 返回数据
 | 
				
			||||||
	this.Data["count"] = len(pbCerts)
 | 
						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()
 | 
						this.Success()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,11 +18,30 @@ func (this *UploadPopupAction) Init() {
 | 
				
			|||||||
	this.Nav("", "", "")
 | 
						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()
 | 
						this.Show()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (this *UploadPopupAction) RunPost(params struct {
 | 
					func (this *UploadPopupAction) RunPost(params struct {
 | 
				
			||||||
 | 
						UserId int64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	TextMode    bool
 | 
						TextMode    bool
 | 
				
			||||||
	Name        string
 | 
						Name        string
 | 
				
			||||||
	IsCA        bool
 | 
						IsCA        bool
 | 
				
			||||||
@@ -107,6 +126,7 @@ func (this *UploadPopupAction) RunPost(params struct {
 | 
				
			|||||||
	// 保存
 | 
						// 保存
 | 
				
			||||||
	createResp, err := this.RPC().SSLCertRPC().CreateSSLCert(this.AdminContext(), &pb.CreateSSLCertRequest{
 | 
						createResp, err := this.RPC().SSLCertRPC().CreateSSLCert(this.AdminContext(), &pb.CreateSSLCertRequest{
 | 
				
			||||||
		IsOn:        params.IsOn,
 | 
							IsOn:        params.IsOn,
 | 
				
			||||||
 | 
							UserId:      params.UserId,
 | 
				
			||||||
		Name:        params.Name,
 | 
							Name:        params.Name,
 | 
				
			||||||
		Description: params.Description,
 | 
							Description: params.Description,
 | 
				
			||||||
		ServerName:  "",
 | 
							ServerName:  "",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -97,16 +97,46 @@ Vue.component("ssl-certs-box", {
 | 
				
			|||||||
		// 上传证书
 | 
							// 上传证书
 | 
				
			||||||
		uploadCert: function () {
 | 
							uploadCert: function () {
 | 
				
			||||||
			let that = this
 | 
								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",
 | 
									height: "28em",
 | 
				
			||||||
				callback: function (resp) {
 | 
									callback: function (resp) {
 | 
				
			||||||
					teaweb.success("上传成功", function () {
 | 
										teaweb.success("上传成功", function () {
 | 
				
			||||||
 | 
											if (resp.data.cert != null) {
 | 
				
			||||||
							that.certs.push(resp.data.cert)
 | 
												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) {
 | 
							formatTime: function (timestamp) {
 | 
				
			||||||
			return new Date(timestamp * 1000).format("Y-m-d")
 | 
								return new Date(timestamp * 1000).format("Y-m-d")
 | 
				
			||||||
@@ -132,7 +162,9 @@ Vue.component("ssl-certs-box", {
 | 
				
			|||||||
	</div>
 | 
						</div>
 | 
				
			||||||
	<div v-if="buttonsVisible()">
 | 
						<div v-if="buttonsVisible()">
 | 
				
			||||||
		<button class="ui button tiny" type="button" @click.prevent="selectCert()">选择已有证书</button>  
 | 
							<button class="ui button tiny" type="button" @click.prevent="selectCert()">选择已有证书</button>  
 | 
				
			||||||
 | 
							<span class="disabled">|</span>  
 | 
				
			||||||
		<button class="ui button tiny" type="button" @click.prevent="uploadCert()">上传新证书</button>  
 | 
							<button class="ui button tiny" type="button" @click.prevent="uploadCert()">上传新证书</button>  
 | 
				
			||||||
 | 
							<button class="ui button tiny" type="button" @click.prevent="uploadBatch()">批量上传证书</button>  
 | 
				
			||||||
	</div>
 | 
						</div>
 | 
				
			||||||
</div>`
 | 
					</div>`
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
@@ -1,5 +1,9 @@
 | 
				
			|||||||
Vue.component("ssl-config-box", {
 | 
					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 () {
 | 
						created: function () {
 | 
				
			||||||
		let that = this
 | 
							let that = this
 | 
				
			||||||
		setTimeout(function () {
 | 
							setTimeout(function () {
 | 
				
			||||||
@@ -131,8 +135,12 @@ Vue.component("ssl-config-box", {
 | 
				
			|||||||
		// 上传证书
 | 
							// 上传证书
 | 
				
			||||||
		uploadCert: function () {
 | 
							uploadCert: function () {
 | 
				
			||||||
			let that = this
 | 
								let that = this
 | 
				
			||||||
			teaweb.popup("/servers/certs/uploadPopup", {
 | 
								let serverId = this.vServerId
 | 
				
			||||||
				height: "28em",
 | 
								if (typeof serverId != "number" && typeof serverId != "string") {
 | 
				
			||||||
 | 
									serverId = 0
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								teaweb.popup("/servers/certs/uploadPopup?serverId=" + serverId, {
 | 
				
			||||||
 | 
									height: "30em",
 | 
				
			||||||
				callback: function (resp) {
 | 
									callback: function (resp) {
 | 
				
			||||||
					teaweb.success("上传成功", function () {
 | 
										teaweb.success("上传成功", function () {
 | 
				
			||||||
						that.policy.certRefs.push(resp.data.certRef)
 | 
											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 () {
 | 
							requestCert: function () {
 | 
				
			||||||
			// 已经在证书中的域名
 | 
								// 已经在证书中的域名
 | 
				
			||||||
@@ -387,7 +417,10 @@ Vue.component("ssl-config-box", {
 | 
				
			|||||||
						<div class="ui divider"></div>
 | 
											<div class="ui divider"></div>
 | 
				
			||||||
					</div>
 | 
										</div>
 | 
				
			||||||
					<button class="ui button tiny" type="button" @click.prevent="selectCert()">选择已有证书</button>  
 | 
										<button class="ui button tiny" type="button" @click.prevent="selectCert()">选择已有证书</button>  
 | 
				
			||||||
 | 
										<span class="disabled">|</span>  
 | 
				
			||||||
					<button class="ui button tiny" type="button" @click.prevent="uploadCert()">上传新证书</button>  
 | 
										<button class="ui button tiny" type="button" @click.prevent="uploadCert()">上传新证书</button>  
 | 
				
			||||||
 | 
										<button class="ui button tiny" type="button" @click.prevent="uploadBatch()">批量上传证书</button>  
 | 
				
			||||||
 | 
										<span class="disabled">|</span>  
 | 
				
			||||||
					<button class="ui button tiny" type="button" @click.prevent="requestCert()" v-if="vServerId != null && vServerId > 0">申请免费证书</button>
 | 
										<button class="ui button tiny" type="button" @click.prevent="requestCert()" v-if="vServerId != null && vServerId > 0">申请免费证书</button>
 | 
				
			||||||
				</td>
 | 
									</td>
 | 
				
			||||||
			</tr>
 | 
								</tr>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,7 @@
 | 
				
			|||||||
        <tr>
 | 
					        <tr>
 | 
				
			||||||
            <td>所属用户</td>
 | 
					            <td>所属用户</td>
 | 
				
			||||||
            <td>
 | 
					            <td>
 | 
				
			||||||
                <user-selector @change="changeUserId"></user-selector>
 | 
					                <user-selector @change="changeUserId" :v-user-id="userId"></user-selector>
 | 
				
			||||||
                <p class="comment">可选项,指定证书所属的用户;指定用户后,上传的证书管理员无法在管理系统查看,只能在用户系统查看。</p>
 | 
					                <p class="comment">可选项,指定证书所属的用户;指定用户后,上传的证书管理员无法在管理系统查看,只能在用户系统查看。</p>
 | 
				
			||||||
            </td>
 | 
					            </td>
 | 
				
			||||||
        </tr>
 | 
					        </tr>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,5 @@
 | 
				
			|||||||
Tea.context(function () {
 | 
					Tea.context(function () {
 | 
				
			||||||
	this.isRequesting = false
 | 
						this.isRequesting = false
 | 
				
			||||||
	this.userId = 0
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	this.before = function () {
 | 
						this.before = function () {
 | 
				
			||||||
		this.isRequesting = true
 | 
							this.isRequesting = true
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,7 +13,14 @@
 | 
				
			|||||||
			</td>
 | 
								</td>
 | 
				
			||||||
		</tr>
 | 
							</tr>
 | 
				
			||||||
        <tr>
 | 
					        <tr>
 | 
				
			||||||
			<td>证书类型</td>
 | 
					            <td>所属用户</td>
 | 
				
			||||||
 | 
					            <td>
 | 
				
			||||||
 | 
					                <user-selector :v-user-id="userId"></user-selector>
 | 
				
			||||||
 | 
					                <p class="comment">可选项,当前证书所属用户。</p>
 | 
				
			||||||
 | 
					            </td>
 | 
				
			||||||
 | 
					        </tr>
 | 
				
			||||||
 | 
							<tr>
 | 
				
			||||||
 | 
								<td>证书类型 *</td>
 | 
				
			||||||
			<td>
 | 
								<td>
 | 
				
			||||||
				<select class="ui dropdown auto-width" name="isCA" v-model="isCA">
 | 
									<select class="ui dropdown auto-width" name="isCA" v-model="isCA">
 | 
				
			||||||
					<option value="0">加密证书</option>
 | 
										<option value="0">加密证书</option>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user