BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr
Fixed automatic certificate renewal
lotk481bef0478bd
diff --git a/core/internal/service/domains/ssl.go b/core/internal/service/domains/ssl.goindex 81a3bbaf..bd0e7a92 100644--- a/core/internal/service/domains/ssl.go+++ b/core/internal/service/domains/ssl.go@@ -318,7 +318,6 @@ func AutoRenewSSL(ctx context.Context) {certInfo, err := GetConsoleSSLInfo()if err == nil && certInfo.Endtime > 0 {remain := certInfo.Endtime - int(time.Now().Unix())- g.Log().Debug(ctx, "Remaining time for console certificate: ", remain, " seconds")if remain < 3*24*3600 {err = ApplyConsoleCert(ctx)if err != nil {@@ -329,8 +328,18 @@ func AutoRenewSSL(ctx context.Context) {}}+ // admin account+ adminAccount := &model.Account{}+ adminUsername, err := public.DockerEnv("ADMIN_USERNAME")+ err = g.DB().Model("account").Where("username = ?", adminUsername).Scan(adminAccount)+ if err != nil {+ g.Log().Error(ctx, "Failed to get admin account for SSL renewal: ", err)+ return+ }+var domainList []string- rows, err := g.DB().Model("domains").Fields("domain").All()+ rows, err := g.DB().Model("domain").Fields("domain").All()+if err == nil {for _, row := range rows {domain := row["domain"].String()@@ -339,21 +348,20 @@ func AutoRenewSSL(ctx context.Context) {}}}- g.Log().Debug(ctx, "List of domains that need renewal: ", domainList)+for _, domain := range domainList {- certInfo, err := mail_service.NewCertificate().GetSSLInfo(domain)+ certInfo, err = mail_service.NewCertificate().GetSSLInfo(domain)if err == nil && certInfo.Endtime > 0 {remain := certInfo.Endtime - int(time.Now().Unix())- g.Log().Debug(ctx, "Remaining time for domain certificate: ", remain, " seconds", domain)+ //g.Log().Warningf(ctx, "Remaining time for domain certificate: %d seconds, domain: %s", remain, domain)if remain < 3*24*3600 {- g.Log().Info(ctx, "Domain certificate is about to expire, auto-renewing: ", domain)- accountInfo, accErr := rbac.GetCurrentAccount(ctx)- if accErr == nil {- certErr := ApplyLetsEncryptCertWithHttp(ctx, domain, accountInfo)- if certErr != nil {- g.Log().Warningf(ctx, "Domain name [%s] added successfully, but auto-request certificate failed: %v", domain, certErr)- }+ //g.Log().Info(ctx, "Domain certificate is about to expire, auto-renewing: ", domain)++ certErr := ApplyLetsEncryptCertWithHttp(ctx, domain, adminAccount)+ if certErr != nil {+ g.Log().Warningf(ctx, "Domain name [%s] auto-request certificate failed: %v", domain, certErr)}+}}// Skip if no certificate exists (endtime=0)