2020-10-04 14:27:05 +08:00
|
|
|
|
Vue.component("ssl-certs-box", {
|
2020-12-03 21:07:08 +08:00
|
|
|
|
props: [
|
|
|
|
|
|
"v-certs", // 证书列表
|
2022-01-16 19:51:26 +08:00
|
|
|
|
"v-cert", // 单个证书
|
2020-12-03 21:07:08 +08:00
|
|
|
|
"v-protocol", // 协议:https|tls
|
2022-01-16 19:51:26 +08:00
|
|
|
|
"v-view-size", // 弹窗尺寸:normal, mini
|
|
|
|
|
|
"v-single-mode", // 单证书模式
|
2023-03-25 20:50:27 +08:00
|
|
|
|
"v-description", // 描述文字
|
|
|
|
|
|
"v-domains" // 搜索的域名列表或者函数
|
2020-12-03 21:07:08 +08:00
|
|
|
|
],
|
2020-10-04 14:27:05 +08:00
|
|
|
|
data: function () {
|
|
|
|
|
|
let certs = this.vCerts
|
|
|
|
|
|
if (certs == null) {
|
|
|
|
|
|
certs = []
|
|
|
|
|
|
}
|
2022-01-16 19:51:26 +08:00
|
|
|
|
if (this.vCert != null) {
|
|
|
|
|
|
certs.push(this.vCert)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let description = this.vDescription
|
|
|
|
|
|
if (description == null || typeof (description) != "string") {
|
|
|
|
|
|
description = ""
|
|
|
|
|
|
}
|
2020-12-03 21:07:08 +08:00
|
|
|
|
|
2020-10-04 14:27:05 +08:00
|
|
|
|
return {
|
2022-01-16 19:51:26 +08:00
|
|
|
|
certs: certs,
|
|
|
|
|
|
description: description
|
2020-10-04 14:27:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
certIds: function () {
|
|
|
|
|
|
return this.certs.map(function (v) {
|
|
|
|
|
|
return v.id
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
// 删除证书
|
|
|
|
|
|
removeCert: function (index) {
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
teaweb.confirm("确定删除此证书吗?证书数据仍然保留,只是当前服务不再使用此证书。", function () {
|
|
|
|
|
|
that.certs.$remove(index)
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 选择证书
|
|
|
|
|
|
selectCert: function () {
|
|
|
|
|
|
let that = this
|
2023-03-25 20:50:27 +08:00
|
|
|
|
let width = "54em"
|
|
|
|
|
|
let height = "32em"
|
2020-10-15 16:41:32 +08:00
|
|
|
|
let viewSize = this.vViewSize
|
|
|
|
|
|
if (viewSize == null) {
|
|
|
|
|
|
viewSize = "normal"
|
|
|
|
|
|
}
|
|
|
|
|
|
if (viewSize == "mini") {
|
|
|
|
|
|
width = "35em"
|
|
|
|
|
|
height = "20em"
|
|
|
|
|
|
}
|
2023-03-25 20:50:27 +08:00
|
|
|
|
|
|
|
|
|
|
let searchingDomains = []
|
|
|
|
|
|
if (this.vDomains != null) {
|
|
|
|
|
|
if (typeof this.vDomains == "function") {
|
|
|
|
|
|
let resultDomains = this.vDomains()
|
|
|
|
|
|
if (resultDomains != null && typeof resultDomains == "object" && (resultDomains instanceof Array)) {
|
|
|
|
|
|
searchingDomains = resultDomains
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (typeof this.vDomains == "object" && (this.vDomains instanceof Array)) {
|
|
|
|
|
|
searchingDomains = this.vDomains
|
|
|
|
|
|
}
|
|
|
|
|
|
if (searchingDomains.length > 10000) {
|
|
|
|
|
|
searchingDomains = searchingDomains.slice(0, 10000)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let selectedCertIds = this.certs.map(function (cert) {
|
|
|
|
|
|
return cert.id
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
teaweb.popup("/servers/certs/selectPopup?viewSize=" + viewSize + "&searchingDomains=" + window.encodeURIComponent(searchingDomains.join(",")) + "&selectedCertIds=" + selectedCertIds.join(","), {
|
2020-10-15 16:41:32 +08:00
|
|
|
|
width: width,
|
|
|
|
|
|
height: height,
|
2020-10-04 14:27:05 +08:00
|
|
|
|
callback: function (resp) {
|
2023-03-25 20:50:27 +08:00
|
|
|
|
if (resp.data.cert != null) {
|
|
|
|
|
|
that.certs.push(resp.data.cert)
|
|
|
|
|
|
}
|
|
|
|
|
|
if (resp.data.certs != null) {
|
|
|
|
|
|
that.certs.$pushAll(resp.data.certs)
|
|
|
|
|
|
}
|
|
|
|
|
|
that.$forceUpdate()
|
2020-10-04 14:27:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 上传证书
|
|
|
|
|
|
uploadCert: function () {
|
|
|
|
|
|
let that = this
|
2020-11-24 17:36:42 +08:00
|
|
|
|
teaweb.popup("/servers/certs/uploadPopup", {
|
2020-10-04 14:27:05 +08:00
|
|
|
|
height: "28em",
|
|
|
|
|
|
callback: function (resp) {
|
|
|
|
|
|
teaweb.success("上传成功", function () {
|
|
|
|
|
|
that.certs.push(resp.data.cert)
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 格式化时间
|
|
|
|
|
|
formatTime: function (timestamp) {
|
|
|
|
|
|
return new Date(timestamp * 1000).format("Y-m-d")
|
2020-10-15 16:41:32 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否显示选择|上传按钮
|
|
|
|
|
|
buttonsVisible: function () {
|
|
|
|
|
|
return this.vSingleMode == null || !this.vSingleMode || this.certs == null || this.certs.length == 0
|
2020-10-04 14:27:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
template: `<div>
|
|
|
|
|
|
<input type="hidden" name="certIdsJSON" :value="JSON.stringify(certIds())"/>
|
|
|
|
|
|
<div v-if="certs != null && certs.length > 0">
|
2022-01-16 19:51:26 +08:00
|
|
|
|
<div class="ui label small basic" v-for="(cert, index) in certs">
|
2021-04-28 14:56:47 +08:00
|
|
|
|
{{cert.name}} / {{cert.dnsNames}} / 有效至{{formatTime(cert.timeEndAt)}} <a href="" title="删除" @click.prevent="removeCert(index)"><i class="icon remove"></i></a>
|
2020-10-04 14:27:05 +08:00
|
|
|
|
</div>
|
2020-10-15 16:41:32 +08:00
|
|
|
|
<div class="ui divider" v-if="buttonsVisible()"></div>
|
2020-10-04 14:27:05 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div v-else>
|
2022-01-16 19:51:26 +08:00
|
|
|
|
<span class="red" v-if="description.length == 0">选择或上传证书后<span v-if="vProtocol == 'https'">HTTPS</span><span v-if="vProtocol == 'tls'">TLS</span>服务才能生效。</span>
|
|
|
|
|
|
<span class="grey" v-if="description.length > 0">{{description}}</span>
|
2020-10-15 16:41:32 +08:00
|
|
|
|
<div class="ui divider" v-if="buttonsVisible()"></div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div v-if="buttonsVisible()">
|
|
|
|
|
|
<button class="ui button tiny" type="button" @click.prevent="selectCert()">选择已有证书</button>
|
2020-12-03 21:07:08 +08:00
|
|
|
|
<button class="ui button tiny" type="button" @click.prevent="uploadCert()">上传新证书</button>
|
2020-10-04 14:27:05 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>`
|
|
|
|
|
|
})
|