enhance: auto obtain cert

This commit is contained in:
0xJacky 2023-02-15 11:20:43 +08:00
parent e260860adc
commit e9d26ded1c
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0
4 changed files with 70 additions and 74 deletions

View file

@ -29,14 +29,10 @@ const columns = [{
},
search: true
}, {
title: () => $gettext('Domain'),
dataIndex: 'domain',
title: () => $gettext('Config Name'),
dataIndex: 'filename',
sorter: true,
pithy: true,
edit: {
type: input
},
search: true
pithy: true
}, {
title: () => $gettext('Auto Cert'),
dataIndex: 'auto_cert',

View file

@ -364,6 +364,7 @@ func AddDomainToAutoCert(c *gin.Context) {
}
err = certModel.Updates(&model.Cert{
Name: name,
AutoCert: model.AutoCertEnabled,
})

View file

@ -89,5 +89,9 @@ func (c *Cert) Updates(n *Cert) error {
}
func (c *Cert) Remove() error {
if c.Filename == "" {
return db.Delete(c).Error
}
return db.Where("filename", c.Filename).Delete(c).Error
}

View file

@ -81,12 +81,7 @@ func AutoObtain() {
continue
}
if certModel.SSLCertificatePath == "" {
errLog.Exit(confName, errors.New("ssl_certificate_path is empty, "+
"try to reopen auto-cert for this config:"+confName))
continue
}
if certModel.SSLCertificatePath != "" {
cert, err := GetCertInfo(certModel.SSLCertificatePath)
if err != nil {
errLog.Push("get cert info", err)
@ -97,7 +92,7 @@ func AutoObtain() {
if time.Now().Sub(cert.NotBefore).Hours()/24 < 7 {
continue
}
//
}
// after 1 mo, reissue certificate
logChan := make(chan string, 1)
errChan := make(chan error, 1)
@ -108,7 +103,7 @@ func AutoObtain() {
go handleIssueCertLogChan(logChan)
// block, unless errChan closed
for err = range errChan {
for err := range errChan {
errLog.Push("issue cert", err)
}
// store error log to db