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
Fix Domainlist certificate renewal
lotk457589d97a63
diff --git a/core/internal/service/domains/ssl.go b/core/internal/service/domains/ssl.goindex 1af774e0..11b8eade 100644--- a/core/internal/service/domains/ssl.go+++ b/core/internal/service/domains/ssl.go@@ -351,6 +351,7 @@ func AutoRenewSSL(ctx context.Context) {}for _, domain := range domainList {+ domain = public.FormatMX(domain)certInfo, err = mail_service.NewCertificate().GetSSLInfo(domain)if err == nil && certInfo.Endtime > 0 {remain := certInfo.Endtime - int(time.Now().Unix())diff --git a/core/internal/service/mail_service/certificate.go b/core/internal/service/mail_service/certificate.goindex db4f8655..e4f9a6ac 100644--- a/core/internal/service/mail_service/certificate.go+++ b/core/internal/service/mail_service/certificate.go@@ -8,12 +8,14 @@ import ("billionmail-core/internal/service/public""context""fmt"+ "github.com/gogf/gf/v2/frame/g""github.com/gogf/gf/v2/text/gregex""github.com/gogf/gf/v2/util/gconv""os""path/filepath""strings""sync"+ "time")// Certificate manages SSL certificates for mail services@@ -468,7 +470,63 @@ func (c *Certificate) GetSSLStatus(domain string) (bool, error) {// GetSSLInfo retrieves SSL certificate informationfunc (c *Certificate) GetSSLInfo(domain string) (certInfo v1.CertInfo, err error) {- // Check Postfix certificate+ // First try to get certificate from database (acme managed certificates)++ certInfo, err = c.getSSLInfoFromDatabase(domain)+ if err == nil && certInfo.Endtime > 0 {+ return // Successfully got certificate info from database+ }++ // Fallback to file system (legacy certificates)+ return c.getSSLInfoFromFiles(domain)+}++// getSSLInfoFromDatabase retrieves SSL certificate from database+func (c *Certificate) getSSLInfoFromDatabase(domain string) (certInfo v1.CertInfo, err error) {+ // Query certificate from letsencrypts table+ var cert struct {+ Certificate string `json:"certificate"`+ PrivateKey string `json:"private_key"`+ Endtime int `json:"endtime"`+ Status int `json:"status"`+ Subject string `json:"subject"`+ Issuer string `json:"issuer"`+ NotAfter string `json:"not_after"`+ NotBefore string `json:"not_before"`+ Dns string `json:"dns"`+ }++ err = g.DB().Model("letsencrypts").+ Where("dns::jsonb ? $1", public.FormatMX(domain)).+ Where("status = 1").+ Where("endtime > ?", time.Now().Unix()).+ Order("endtime desc").+ Limit(1).+ Scan(&cert)++ if err != nil {+ return certInfo, fmt.Errorf("certificate not found in database: %v", err)+ }++ if cert.Certificate == "" {+ return certInfo, fmt.Errorf("certificate content is empty in database")+ }++ // Parse certificate information+ err = gconv.Struct(acme.GetCertInfo(cert.Certificate), &certInfo)+ if err != nil {+ return certInfo, fmt.Errorf("failed to parse certificate info: %v", err)+ }++ // Set certificate content+ certInfo.CertPem = cert.Certificate+ certInfo.KeyPem = cert.PrivateKey++ return certInfo, nil+}++// getSSLInfoFromFiles retrieves SSL certificate from file system (legacy method)+func (c *Certificate) getSSLInfoFromFiles(domain string) (certInfo v1.CertInfo, err error) {csrPath := filepath.Join(consts.SSL_PATH, domain, "/fullchain.pem")keyPath := filepath.Join(consts.SSL_PATH, domain, "/privkey.pem")