mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
创建服务和修改服务HTTPS设置时也支持批量上传证书
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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: "",
|
||||
|
||||
@@ -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", {
|
||||
</div>
|
||||
<div v-if="buttonsVisible()">
|
||||
<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="uploadBatch()">批量上传证书</button>
|
||||
</div>
|
||||
</div>`
|
||||
})
|
||||
@@ -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", {
|
||||
<div class="ui divider"></div>
|
||||
</div>
|
||||
<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="uploadBatch()">批量上传证书</button>
|
||||
<span class="disabled">|</span>
|
||||
<button class="ui button tiny" type="button" @click.prevent="requestCert()" v-if="vServerId != null && vServerId > 0">申请免费证书</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<tr>
|
||||
<td>所属用户</td>
|
||||
<td>
|
||||
<user-selector @change="changeUserId"></user-selector>
|
||||
<user-selector @change="changeUserId" :v-user-id="userId"></user-selector>
|
||||
<p class="comment">可选项,指定证书所属的用户;指定用户后,上传的证书管理员无法在管理系统查看,只能在用户系统查看。</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
Tea.context(function () {
|
||||
this.isRequesting = false
|
||||
this.userId = 0
|
||||
|
||||
this.before = function () {
|
||||
this.isRequesting = true
|
||||
|
||||
@@ -12,8 +12,15 @@
|
||||
<p class="comment">可以简单说明证书的用途。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>所属用户</td>
|
||||
<td>
|
||||
<user-selector :v-user-id="userId"></user-selector>
|
||||
<p class="comment">可选项,当前证书所属用户。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>证书类型</td>
|
||||
<td>证书类型 *</td>
|
||||
<td>
|
||||
<select class="ui dropdown auto-width" name="isCA" v-model="isCA">
|
||||
<option value="0">加密证书</option>
|
||||
|
||||
Reference in New Issue
Block a user