feat: sync certificates to remote server #293, #363, #411

This commit is contained in:
Jacky 2024-06-18 17:39:05 +08:00
parent 11e460765a
commit b3486a42a5
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
41 changed files with 2429 additions and 1649 deletions

View file

@ -53,14 +53,14 @@ func autoCert(certModel *model.Cert) {
return
}
cert, err := GetCertInfo(certModel.SSLCertificatePath)
certInfo, err := GetCertInfo(certModel.SSLCertificatePath)
if err != nil {
// Get certificate info error, ignore this certificate
log.Error(errors.Wrap(err, "get certificate info error"))
notification.Error("Renew Certificate Error", strings.Join(certModel.Domains, ", "))
return
}
if int(time.Now().Sub(cert.NotBefore).Hours()/24) < settings.ServerSettings.GetCertRenewalInterval() {
if int(time.Now().Sub(certInfo.NotBefore).Hours()/24) < settings.ServerSettings.GetCertRenewalInterval() {
// not after settings.ServerSettings.CertRenewalInterval, ignore
return
}
@ -76,7 +76,7 @@ func autoCert(certModel *model.Cert) {
ChallengeMethod: certModel.ChallengeMethod,
DNSCredentialID: certModel.DnsCredentialID,
KeyType: certModel.GetKeyType(),
NotBefore: cert.NotBefore,
NotBefore: certInfo.NotBefore,
}
if certModel.Resource != nil {
@ -106,4 +106,9 @@ func autoCert(certModel *model.Cert) {
}
notification.Success("Renew Certificate Success", strings.Join(payload.ServerName, ", "))
err = SyncToRemoteServer(certModel)
if err != nil {
notification.Error("Sync Certificate Error", err.Error())
return
}
}