mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 12:40:25 +08:00
feat: 支持签发自签名证书
This commit is contained in:
@@ -37,6 +37,7 @@ type CertRepo interface {
|
||||
Delete(id uint) error
|
||||
ObtainAuto(id uint) (*acme.Certificate, error)
|
||||
ObtainManual(id uint) (*acme.Certificate, error)
|
||||
ObtainSelfSigned(id uint) error
|
||||
Renew(id uint) (*acme.Certificate, error)
|
||||
ManualDNS(id uint) ([]acme.DNSRecord, error)
|
||||
Deploy(ID, WebsiteID uint) error
|
||||
|
||||
@@ -207,6 +207,30 @@ func (r *certRepo) ObtainManual(id uint) (*acme.Certificate, error) {
|
||||
return &ssl, nil
|
||||
}
|
||||
|
||||
func (r *certRepo) ObtainSelfSigned(id uint) error {
|
||||
cert, err := r.Get(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
crt, key, err := pkgcert.GenerateSelfSigned(cert.Domains)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cert.Cert = string(crt)
|
||||
cert.Key = string(key)
|
||||
if err = app.Orm.Save(cert).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cert.Website != nil {
|
||||
return r.Deploy(cert.ID, cert.WebsiteID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *certRepo) Renew(id uint) (*acme.Certificate, error) {
|
||||
cert, err := r.Get(id)
|
||||
if err != nil {
|
||||
|
||||
@@ -88,6 +88,7 @@ func Http(r chi.Router) {
|
||||
r.Delete("/{id}", cert.Delete)
|
||||
r.Post("/{id}/obtainAuto", cert.ObtainAuto)
|
||||
r.Post("/{id}/obtainManual", cert.ObtainManual)
|
||||
r.Post("/{id}/obtainSelfSigned", cert.ObtainSelfSigned)
|
||||
r.Post("/{id}/renew", cert.Renew)
|
||||
r.Post("/{id}/manualDNS", cert.ManualDNS)
|
||||
r.Post("/{id}/deploy", cert.Deploy)
|
||||
|
||||
@@ -224,6 +224,21 @@ func (s *CertService) ObtainManual(w http.ResponseWriter, r *http.Request) {
|
||||
Success(w, nil)
|
||||
}
|
||||
|
||||
func (s *CertService) ObtainSelfSigned(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := Bind[request.ID](r)
|
||||
if err != nil {
|
||||
Error(w, http.StatusUnprocessableEntity, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = s.certRepo.ObtainSelfSigned(req.ID); err != nil {
|
||||
Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
Success(w, nil)
|
||||
}
|
||||
|
||||
func (s *CertService) Renew(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := Bind[request.ID](r)
|
||||
if err != nil {
|
||||
|
||||
@@ -53,6 +53,9 @@ export default {
|
||||
// 证书手动签发
|
||||
obtainManual: (id: number): Promise<AxiosResponse<any>> =>
|
||||
request.post(`/cert/cert/${id}/obtainManual`, { id }),
|
||||
// 证书自签名签发
|
||||
obtainSelfSigned: (id: number): Promise<AxiosResponse<any>> =>
|
||||
request.post(`/cert/cert/${id}/obtainSelfSigned`, { id }),
|
||||
// 续签
|
||||
renew: (id: number): Promise<AxiosResponse<any>> =>
|
||||
request.post(`/cert/cert/${id}/renew`, { id }),
|
||||
|
||||
@@ -181,7 +181,7 @@ const columns: any = [
|
||||
resizable: true,
|
||||
render(row: any) {
|
||||
return [
|
||||
row.type != 'upload' && row.account_id != 0 && row.cert == '' && row.key == ''
|
||||
row.type != 'upload' && row.cert == '' && row.key == ''
|
||||
? h(
|
||||
NButton,
|
||||
{
|
||||
|
||||
@@ -13,8 +13,9 @@ const model = ref({
|
||||
})
|
||||
|
||||
const options = [
|
||||
{ label: '自动验证', value: 'auto' },
|
||||
{ label: '手动 DNS 验证', value: 'manual' }
|
||||
{ label: '自动', value: 'auto' },
|
||||
{ label: '手动', value: 'manual' },
|
||||
{ label: '自签名', value: 'self-signed' }
|
||||
]
|
||||
|
||||
const handleSubmit = async () => {
|
||||
@@ -33,7 +34,7 @@ const handleSubmit = async () => {
|
||||
window.$bus.emit('cert:refresh-cert')
|
||||
window.$bus.emit('cert:refresh-async')
|
||||
})
|
||||
} else {
|
||||
} else if (model.value.type == 'manual') {
|
||||
const { data } = await cert.manualDNS(id.value)
|
||||
messageReactive.destroy()
|
||||
window.$message.info('请先前往域名处设置 DNS 解析,再继续签发')
|
||||
@@ -78,6 +79,18 @@ const handleSubmit = async () => {
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
await cert
|
||||
.obtainSelfSigned(id.value)
|
||||
.then(() => {
|
||||
window.$message.success('签发成功')
|
||||
show.value = false
|
||||
})
|
||||
.finally(() => {
|
||||
messageReactive?.destroy()
|
||||
window.$bus.emit('cert:refresh-cert')
|
||||
window.$bus.emit('cert:refresh-async')
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user