Skip to content

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

Added get ssl info by domain. Using g.Log() instead of glog to ensure application logs correct output to log files. Fixed some bugs.

Jack2ddbaa69247c
diff --git a/core/api/domains/domains.go b/core/api/domains/domains.go
index 135ec905..f344b276 100644
--- a/core/api/domains/domains.go
+++ b/core/api/domains/domains.go
@@ -17,6 +17,7 @@ type IDomainsV1 interface {
GetDomain(ctx context.Context, req *v1.GetDomainReq) (res *v1.GetDomainRes, err error)
GetDomainAll(ctx context.Context, req *v1.GetDomainAllReq) (res *v1.GetDomainAllRes, err error)
SetSSL(ctx context.Context, req *v1.SetSSLReq) (res *v1.SetSSLRes, err error)
+ GetSSL(ctx context.Context, req *v1.GetSSLReq) (res *v1.GetSSLRes, err error)
ApplyCert(ctx context.Context, req *v1.ApplyCertReq) (res *v1.ApplyCertRes, err error)
GetCertList(ctx context.Context, req *v1.GetCertListReq) (res *v1.GetCertListRes, err error)
}
diff --git a/core/api/domains/v1/domains.go b/core/api/domains/v1/domains.go
index 49f7d6b8..a426cc6d 100644
--- a/core/api/domains/v1/domains.go
+++ b/core/api/domains/v1/domains.go
@@ -123,3 +123,14 @@ type SetSSLReq struct {
type SetSSLRes struct {
api_v1.StandardRes
}
+
+type GetSSLReq struct {
+ g.Meta `path:"/domains/get_ssl" tags:"Domain" method:"get" sm:"Get SSL" in:"query"`
+ Authorization string `json:"authorization" dc:"Authorization" in:"header"`
+ Domain string `json:"domain" v:"required|domain" dc:"Domain"`
+}
+
+type GetSSLRes struct {
+ api_v1.StandardRes
+ Data CertInfo `json:"data" dc:"Certificate information"`
+}
diff --git a/core/api/mail_boxes/v1/mailboxes.go b/core/api/mail_boxes/v1/mailboxes.go
index 0460ce1b..919bcefa 100644
--- a/core/api/mail_boxes/v1/mailboxes.go
+++ b/core/api/mail_boxes/v1/mailboxes.go
@@ -25,8 +25,8 @@ type AddMailboxReq struct {
g.Meta `path:"/mailbox/create" tags:"MailBox" method:"post" summary:"Create mailbox" in:"body"`
Authorization string `json:"authorization" dc:"Authorization" in:"header"`
Domain string `json:"domain" v:"required|domain" dc:"Domain"`
- FullName string `json:"full_name" v:"required|passport" dc:"username"`
- Password string `json:"password" v:"required|password" dc:"Password"`
+ FullName string `json:"full_name" v:"required|min-length:1|regex:[\\w-]{1,}" dc:"username"`
+ Password string `json:"password" v:"required|min-length:8" dc:"Password"`
Active int `json:"active" v:"required" dc:"Status" d:"1"`
IsAdmin int `json:"isAdmin" v:"required" dc:"IsAdmin" d:"0"`
Quota int `json:"quota" v:"required|min:1" dc:"Quota" d:"5242880"`
@@ -40,8 +40,8 @@ type UpdateMailboxReq struct {
g.Meta `path:"/mailbox/update" tags:"MailBox" method:"post" summary:"Update mailbox" in:"body"`
Authorization string `json:"authorization" dc:"Authorization" in:"header"`
Domain string `json:"domain" v:"required|domain" dc:"Domain"`
- FullName string `json:"full_name" v:"required|passport" dc:"username"`
- Password string `json:"password" v:"password" dc:"Password"`
+ FullName string `json:"full_name" v:"required|min-length:1|regex:[\\w-]{1,}" dc:"username"`
+ Password string `json:"password" v:"required|min-length:8" dc:"Password"`
Active int `json:"active" v:"required" dc:"Status" d:"1"`
IsAdmin int `json:"isAdmin" v:"required" dc:"IsAdmin" d:"0"`
Quota int `json:"quota" v:"required|min:1" dc:"Quota" d:"5242880"`
diff --git a/core/internal/cmd/cmd.go b/core/internal/cmd/cmd.go
index 635c08ce..66b18a41 100644
--- a/core/internal/cmd/cmd.go
+++ b/core/internal/cmd/cmd.go
@@ -19,7 +19,6 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gcmd"
- "github.com/gogf/gf/v2/os/glog"
"net/http/httputil"
"net/url"
"path/filepath"
@@ -36,7 +35,7 @@ var (
err = database_initialization.InitDatabase()
if err != nil {
- glog.Error(ctx, "initialize databases failed ", err)
+ g.Log().Error(ctx, "initialize databases failed ", err)
return err
}
@@ -44,7 +43,7 @@ var (
err = redis_initialization.InitRedis()
if err != nil {
- glog.Error(ctx, "initialize redis failed ", err)
+ g.Log().Error(ctx, "initialize redis failed ", err)
return err
}
@@ -52,7 +51,7 @@ var (
err = timers.Start(ctx)
if err != nil {
- glog.Error(ctx, "start timers failed ", err)
+ g.Log().Error(ctx, "start timers failed ", err)
return err
}
@@ -60,7 +59,7 @@ var (
dk, err := docker.NewDockerAPI()
if err != nil {
- glog.Error(ctx, "failed to connect to docker-api ", err)
+ g.Log().Error(ctx, "failed to connect to docker-api ", err)
return err
}
diff --git a/core/internal/controller/domains/domains_v1_get_ssl.go b/core/internal/controller/domains/domains_v1_get_ssl.go
new file mode 100644
index 00000000..18f13a6d
--- /dev/null
+++ b/core/internal/controller/domains/domains_v1_get_ssl.go
@@ -0,0 +1,27 @@
+package domains
+
+import (
+ "billionmail-core/internal/service/mail_service"
+ "context"
+ "fmt"
+
+ "billionmail-core/api/domains/v1"
+)
+
+func (c *ControllerV1) GetSSL(ctx context.Context, req *v1.GetSSLReq) (res *v1.GetSSLRes, err error) {
+ res = &v1.GetSSLRes{}
+
+ crt := mail_service.NewCertificate()
+ defer crt.Close()
+
+ // Get SSL certificate information
+ res.Data, err = crt.GetSSLInfo(req.Domain)
+
+ if err != nil {
+ res.SetError(fmt.Errorf("error getting certificate: %v", err))
+ return
+ }
+
+ res.SetSuccess("Success")
+ return
+}
diff --git a/core/internal/service/domains/domains.go b/core/internal/service/domains/domains.go
index efad3cc3..0e5b65d0 100644
--- a/core/internal/service/domains/domains.go
+++ b/core/internal/service/domains/domains.go
@@ -10,7 +10,6 @@ import (
"context"
"fmt"
"github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/os/glog"
"os"
"path/filepath"
"strings"
@@ -47,7 +46,7 @@ func Delete(ctx context.Context, domainName string) error {
}
func Get(ctx context.Context, keyword string, page, pageSize int) ([]v1.Domain, int, error) {
- m := g.DB().Model("domain")
+ m := g.DB().Model("domain").Order("create_time", "desc")
if keyword != "" {
m = m.WhereLike("domain", fmt.Sprintf("%%%s%%", keyword))
@@ -158,7 +157,7 @@ func buildCacheKey(domain, recordType string) string {
}
func FreshRecords(ctx context.Context) {
- glog.Debug(ctx, "Fresh DNS records...")
+ g.Log().Debug(ctx, "Fresh DNS records...")
domains, err := All(ctx)
@@ -179,7 +178,7 @@ func FreshRecords(ctx context.Context) {
defer wg.Done()
dr, err := GetARecord(domain.Domain)
if err != nil {
- glog.Error(ctx, "Failed to get A record for domain %s: %v", domain.Domain, err)
+ g.Log().Error(ctx, "Failed to get A record for domain %s: %v", domain.Domain, err)
} else {
public.SetCache(buildCacheKey(domain.Domain, "A"), dr, cacheSeconds)
}
@@ -190,7 +189,7 @@ func FreshRecords(ctx context.Context) {
defer wg.Done()
dr, err := GetMXRecord(domain.Domain)
if err != nil {
- glog.Error(ctx, "Failed to get MX record for domain %s: %v", domain.Domain, err)
+ g.Log().Error(ctx, "Failed to get MX record for domain %s: %v", domain.Domain, err)
} else {
public.SetCache(buildCacheKey(domain.Domain, "MX"), dr, cacheSeconds)
}
@@ -201,7 +200,7 @@ func FreshRecords(ctx context.Context) {
defer wg.Done()
dr, err := GetSPFRecord(domain.Domain)
if err != nil {
- glog.Error(ctx, "Failed to get SPF record for domain %s: %v", domain.Domain, err)
+ g.Log().Error(ctx, "Failed to get SPF record for domain %s: %v", domain.Domain, err)
} else {
public.SetCache(buildCacheKey(domain.Domain, "SPF"), dr, cacheSeconds)
}
@@ -212,7 +211,7 @@ func FreshRecords(ctx context.Context) {
defer wg.Done()
dr, err := GetDKIMRecord(domain.Domain)
if err != nil {
- glog.Error(ctx, "Failed to get DKIM record for domain %s: %v", domain.Domain, err)
+ g.Log().Error(ctx, "Failed to get DKIM record for domain %s: %v", domain.Domain, err)
} else {
public.SetCache(buildCacheKey(domain.Domain, "DKIM"), dr, cacheSeconds)
}
@@ -223,7 +222,7 @@ func FreshRecords(ctx context.Context) {
defer wg.Done()
dr, err := GetDMARCRecord(domain.Domain)
if err != nil {
- glog.Error(ctx, "Failed to get DMARC record for domain %s: %v", domain.Domain, err)
+ g.Log().Error(ctx, "Failed to get DMARC record for domain %s: %v", domain.Domain, err)
} else {
public.SetCache(buildCacheKey(domain.Domain, "DMARC"), dr, cacheSeconds)
}
@@ -234,7 +233,7 @@ func FreshRecords(ctx context.Context) {
defer wg.Done()
dr, err := GetPTRRecord(domain.Domain)
if err != nil {
- glog.Error(ctx, "Failed to get PTR record for domain %s: %v", domain.Domain, err)
+ g.Log().Error(ctx, "Failed to get PTR record for domain %s: %v", domain.Domain, err)
} else {
public.SetCache(buildCacheKey(domain.Domain, "PTR"), dr, cacheSeconds)
}
@@ -243,7 +242,7 @@ func FreshRecords(ctx context.Context) {
wg.Wait()
- glog.Debug(ctx, "Fresh DNS records completed.")
+ g.Log().Debug(ctx, "Fresh DNS records completed.")
}
// GetDKIMRecord retrieves the DKIM record for a given domain.
diff --git a/core/internal/service/mail_service/certificate.go b/core/internal/service/mail_service/certificate.go
index 27df419f..48f1e045 100644
--- a/core/internal/service/mail_service/certificate.go
+++ b/core/internal/service/mail_service/certificate.go
@@ -13,10 +13,12 @@ import (
"os"
"path/filepath"
"strings"
+ "sync"
)
// Certificate manages SSL certificates for mail services
type Certificate struct {
+ mutex sync.Mutex
dk *docker.DockerAPI
PostfixMainConf string
PostfixMasterConf string
@@ -28,13 +30,6 @@ type Certificate struct {
// NewCertificate creates a new certificate management service instance
func NewCertificate() *Certificate {
- // Create DockerAPI instance
- dk, err := docker.NewDockerAPI()
-
- if err != nil {
- panic(fmt.Sprintf("failed to create docker API: %v", err))
- }
-
return &Certificate{
PostfixMainConf: public.AbsPath(consts.POSTFIX_MAIN_CONF),
PostfixMasterConf: public.AbsPath(consts.POSTFIX_MASTER_CONF),
@@ -42,10 +37,30 @@ func NewCertificate() *Certificate {
DovecotConfPath: public.AbsPath(consts.DOVECOT_CONF_D_PATH),
PostfixConfPath: public.AbsPath(consts.POSTFIX_CONF_PATH),
PostfixSNIPath: public.AbsPath(filepath.Join(consts.POSTFIX_CONF_PATH, "vmail_ssl.map")),
- dk: dk,
}
}
+func (c *Certificate) dockerApiClient() *docker.DockerAPI {
+ if c.dk == nil {
+ c.mutex.Lock()
+ defer c.mutex.Unlock()
+
+ if c.dk != nil {
+ return c.dk
+ }
+
+ var err error
+
+ c.dk, err = docker.NewDockerAPI()
+
+ if err != nil {
+ panic(fmt.Sprintf("failed to create docker API: %v", err))
+ }
+ }
+
+ return c.dk
+}
+
// Close closes the certificate management service
func (c *Certificate) Close() error {
if c.dk != nil {
@@ -318,7 +333,7 @@ func (c *Certificate) updatePostfixSNIMap(domain, certPath, keyPath string) erro
}
// Rehash configuration
- if _, err := c.dk.ExecCommandByName(context.Background(), "billionmail-postfix-billionmail-1", []string{"postmap", "/etc/postfix/conf/vmail_ssl.map"}, "root"); err != nil {
+ if _, err := c.dockerApiClient().ExecCommandByName(context.Background(), "billionmail-postfix-billionmail-1", []string{"postmap", "/etc/postfix/conf/vmail_ssl.map"}, "root"); err != nil {
return fmt.Errorf("failed to hash postfix config: %v", err)
}
@@ -421,7 +436,7 @@ func (c *Certificate) updateConfigLine(config, key, value string) string {
// restartPostfix restarts Postfix service
func (c *Certificate) restartPostfix() error {
// Restart Postfix container
- if err := c.dk.RestartContainerByName(context.Background(), "billionmail-postfix-billionmail-1"); err != nil {
+ if err := c.dockerApiClient().RestartContainerByName(context.Background(), "billionmail-postfix-billionmail-1"); err != nil {
return fmt.Errorf("failed to restart postfix container: %v", err)
}
@@ -431,7 +446,7 @@ func (c *Certificate) restartPostfix() error {
// restartDovecot restarts Dovecot service
func (c *Certificate) restartDovecot() error {
// Restart Dovecot container
- if err := c.dk.RestartContainerByName(context.Background(), "billionmail-dovecot-billionmail-1"); err != nil {
+ if err := c.dockerApiClient().RestartContainerByName(context.Background(), "billionmail-dovecot-billionmail-1"); err != nil {
return fmt.Errorf("failed to restart dovecot container: %v", err)
}
diff --git a/core/internal/service/maillog_stat/maillog_stat.go b/core/internal/service/maillog_stat/maillog_stat.go
index 00887407..163a89ac 100644
--- a/core/internal/service/maillog_stat/maillog_stat.go
+++ b/core/internal/service/maillog_stat/maillog_stat.go
@@ -6,7 +6,6 @@ import (
"fmt"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/os/glog"
"os"
"regexp"
"strconv"
@@ -630,7 +629,7 @@ func (ms *MaillogStat) AnalysisAndSaveToDatabase(ctx context.Context) error {
"log_time_millis": gdb.Raw("case when excluded.log_time_millis > log_time_millis then excluded.log_time_millis else log_time_millis end"),
}).Insert(sendRecords)
if err != nil {
- glog.Error(context.Background(), err.Error())
+ g.Log().Error(context.Background(), err.Error())
}
}
@@ -645,35 +644,35 @@ func (ms *MaillogStat) AnalysisAndSaveToDatabase(ctx context.Context) error {
"log_time_millis": gdb.Raw("case when excluded.log_time_millis > log_time_millis then excluded.log_time_millis else log_time_millis end"),
}).Insert(receiveRecords)
if err != nil {
- glog.Error(context.Background(), err.Error())
+ g.Log().Error(context.Background(), err.Error())
}
}
if len(senderRecords) > 0 {
_, err = g.DB().Model("mailstat_senders").Insert(senderRecords)
if err != nil {
- glog.Error(context.Background(), err.Error())
+ g.Log().Error(context.Background(), err.Error())
}
}
if len(removedRecords) > 0 {
_, err = g.DB().Model("mailstat_removed").Insert(removedRecords)
if err != nil {
- glog.Error(context.Background(), err.Error())
+ g.Log().Error(context.Background(), err.Error())
}
}
if len(messageIDRecords) > 0 {
_, err = g.DB().Model("mailstat_message_ids").Insert(messageIDRecords)
if err != nil {
- glog.Error(context.Background(), err.Error())
+ g.Log().Error(context.Background(), err.Error())
}
}
if len(deferredRecords) > 0 {
_, err = g.DB().Model("mailstat_deferred").Insert(deferredRecords)
if err != nil {
- glog.Error(context.Background(), err.Error())
+ g.Log().Error(context.Background(), err.Error())
}
}
diff --git a/core/internal/service/phpfpm/phpfpm.go b/core/internal/service/phpfpm/phpfpm.go
index 47be899f..24ff838f 100644
--- a/core/internal/service/phpfpm/phpfpm.go
+++ b/core/internal/service/phpfpm/phpfpm.go
@@ -2,8 +2,8 @@ package phpfpm
import (
"context"
+ "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/os/glog"
"github.com/gogf/gf/v2/util/gconv"
"io"
"net"
@@ -81,7 +81,7 @@ func PHPFpmHandlerFactory(config PHPFpmHandlerConfig) ghttp.HandlerFunc {
// Connect to FastCGI server
fc, err := fcgiclient.Dial(config.Network, config.Addr)
if err != nil {
- glog.Error(context.Background(), "FastCGI connection failed:", err)
+ g.Log().Error(context.Background(), "FastCGI connection failed:", err)
return
}
defer fc.Close()
@@ -89,7 +89,7 @@ func PHPFpmHandlerFactory(config PHPFpmHandlerConfig) ghttp.HandlerFunc {
// Send request to FastCGI server
resp, err := fc.Request(env, r.Body)
if err != nil {
- glog.Error(context.Background(), "FastCGI request failed:", err)
+ g.Log().Error(context.Background(), "FastCGI request failed:", err)
return
}
defer resp.Body.Close()
@@ -107,7 +107,7 @@ func PHPFpmHandlerFactory(config PHPFpmHandlerConfig) ghttp.HandlerFunc {
// Copy response body
_, err = io.Copy(r.Response.BufferWriter, resp.Body)
if err != nil {
- glog.Error(context.Background(), "FastCGI response failed:", err)
+ g.Log().Error(context.Background(), "FastCGI response failed:", err)
return
}
}
diff --git a/core/internal/service/public/common.go b/core/internal/service/public/common.go
index 2e236ae2..6ce69eea 100644
--- a/core/internal/service/public/common.go
+++ b/core/internal/service/public/common.go
@@ -37,7 +37,6 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcache"
"github.com/gogf/gf/v2/os/gctx"
- "github.com/gogf/gf/v2/os/glog"
"github.com/g0rbe/go-chattr"
@@ -2171,7 +2170,7 @@ func AllowPort(port int) (err error) {
if FileExists("/usr/sbin/ufw") || FileExists("/usr/bin/ufw") {
s, err = ExecShell(fmt.Sprintf("ufw allow %d/tcp", port))
if err != nil {
- glog.Error(context.Background(), "AllowPort error: ", err, " ", s)
+ g.Log().Error(context.Background(), "AllowPort error: ", err, " ", s)
}
return
@@ -2181,7 +2180,7 @@ func AllowPort(port int) (err error) {
if FileExists("/usr/sbin/firewalld") || FileExists("/usr/bin/firewalld") {
s, err = ExecShell(fmt.Sprintf("firewall-cmd --permanent --zone=public --add-port=%d/tcp", port))
if err != nil {
- glog.Error(context.Background(), "AllowPort error: ", err, " ", s)
+ g.Log().Error(context.Background(), "AllowPort error: ", err, " ", s)
return
}
}
@@ -2189,7 +2188,7 @@ func AllowPort(port int) (err error) {
// Use iptables
s, err = ExecShell(fmt.Sprintf("iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport %d -j ACCEPT", port))
if err != nil {
- glog.Error(context.Background(), "AllowPort error: ", err, " ", s)
+ g.Log().Error(context.Background(), "AllowPort error: ", err, " ", s)
return
}
@@ -2217,7 +2216,7 @@ func DeniedPort(port int) (err error) {
if FileExists("/usr/sbin/ufw") || FileExists("/usr/bin/ufw") {
s, err = ExecShell(fmt.Sprintf("ufw delete allow %d/tcp", port))
if err != nil {
- glog.Error(context.Background(), "DeniedPort error: ", err, " ", s)
+ g.Log().Error(context.Background(), "DeniedPort error: ", err, " ", s)
}
return
@@ -2227,7 +2226,7 @@ func DeniedPort(port int) (err error) {
if FileExists("/usr/sbin/firewalld") || FileExists("/usr/bin/firewalld") {
s, err = ExecShell(fmt.Sprintf("firewall-cmd --permanent --zone=public --remove-port=%d/tcp", port))
if err != nil {
- glog.Error(context.Background(), "DeniedPort error: ", err, " ", s)
+ g.Log().Error(context.Background(), "DeniedPort error: ", err, " ", s)
return
}
}
@@ -2235,7 +2234,7 @@ func DeniedPort(port int) (err error) {
// Use iptables
s, err = ExecShell(fmt.Sprintf("iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport %d -j ACCEPT", port))
if err != nil {
- glog.Error(context.Background(), "DeniedPort error: ", err, " ", s)
+ g.Log().Error(context.Background(), "DeniedPort error: ", err, " ", s)
return
}
@@ -2251,7 +2250,7 @@ func ReloadFirewall() (err error) {
if FileExists("/usr/sbin/ufw") || FileExists("/usr/bin/ufw") {
s, err = ExecShell("ufw reload")
if err != nil {
- glog.Error(context.Background(), "ReloadFirewall error: ", err, " ", s)
+ g.Log().Error(context.Background(), "ReloadFirewall error: ", err, " ", s)
}
return
@@ -2261,7 +2260,7 @@ func ReloadFirewall() (err error) {
if FileExists("/usr/sbin/firewalld") || FileExists("/usr/bin/firewalld") {
s, err = ExecShell("firewall-cmd --reload")
if err != nil {
- glog.Error(context.Background(), "ReloadFirewall error: ", err, " ", s)
+ g.Log().Error(context.Background(), "ReloadFirewall error: ", err, " ", s)
return
}
}
@@ -2269,7 +2268,7 @@ func ReloadFirewall() (err error) {
// Use iptables
s, err = ExecShell("/etc/init.d/iptables save && /etc/init.d/iptables restart")
if err != nil {
- glog.Error(context.Background(), "ReloadFirewall error: ", err, " ", s)
+ g.Log().Error(context.Background(), "ReloadFirewall error: ", err, " ", s)
return
}
diff --git a/core/internal/service/public/self_signed_cert.go b/core/internal/service/public/self_signed_cert.go
index 62270686..2a9ca5c3 100644
--- a/core/internal/service/public/self_signed_cert.go
+++ b/core/internal/service/public/self_signed_cert.go
@@ -8,7 +8,7 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
- "github.com/gogf/gf/v2/os/glog"
+ "github.com/gogf/gf/v2/frame/g"
"io/fs"
"math/big"
random "math/rand"
@@ -41,13 +41,13 @@ func (sp *selfSignedCertProvider) Generate() {
return
}
- glog.Debug(context.Background(), "No SSL certificate configured, generating self-signed certificate...")
+ g.Log().Debug(context.Background(), "No SSL certificate configured, generating self-signed certificate...")
if err := sp.createOffline(); err != nil {
return
}
- glog.Debug(context.Background(), "Self-signed certificate generated successfully")
+ g.Log().Debug(context.Background(), "Self-signed certificate generated successfully")
}
// createOffline creates self-signed certificate offline
@@ -56,28 +56,28 @@ func (sp *selfSignedCertProvider) createOffline() error {
err := os.MkdirAll(filepath.Dir(sp.certFile), 0644)
if err != nil {
- glog.Error(context.Background(), "Failed to generate self-signed certificate:", err)
+ g.Log().Error(context.Background(), "Failed to generate self-signed certificate:", err)
return err
}
csr, key, err := sp.createCertWithDynamic()
if err != nil {
- glog.Error(context.Background(), "Failed to generate self-signed certificate:", err)
+ g.Log().Error(context.Background(), "Failed to generate self-signed certificate:", err)
return err
}
err = os.WriteFile(sp.certFile, csr, fs.ModePerm)
if err != nil {
- glog.Error(context.Background(), "Failed to generate self-signed certificate:", err)
+ g.Log().Error(context.Background(), "Failed to generate self-signed certificate:", err)
return err
}
err = os.WriteFile(sp.privateKeyFile, key, fs.ModePerm)
if err != nil {
- glog.Error(context.Background(), "Failed to generate self-signed certificate:", err)
+ g.Log().Error(context.Background(), "Failed to generate self-signed certificate:", err)
return err
}
@@ -90,7 +90,7 @@ func (sp *selfSignedCertProvider) createCertWithRoot(rootCa, rootKey []byte) ([]
ca, caKey, err := sp.loadRootCertificate(rootCa, rootKey)
if err != nil {
- glog.Error(context.Background(), "Failed to load CA certificate:", err)
+ g.Log().Error(context.Background(), "Failed to load CA certificate:", err)
return []byte{}, []byte{}, err
}
@@ -101,7 +101,7 @@ func (sp *selfSignedCertProvider) createCertWithRoot(rootCa, rootKey []byte) ([]
csr, key, err := sp.generateCert(ca, templateCsr, caKey)
if err != nil {
- glog.Error(context.Background(), "Failed to issue certificate:", err)
+ g.Log().Error(context.Background(), "Failed to issue certificate:", err)
return []byte{}, []byte{}, err
}
@@ -173,7 +173,7 @@ func (sp *selfSignedCertProvider) generateCertTemplate() *x509.Certificate {
serverIp, localIp, err := GetServerIPAndLocalIP()
if err != nil {
- glog.Error(context.Background(), "Failed to get server IP:", err)
+ g.Log().Error(context.Background(), "Failed to get server IP:", err)
return nil
}
diff --git a/core/internal/service/timers/timers.go b/core/internal/service/timers/timers.go
index 9a50e0db..3b1c91a1 100644
--- a/core/internal/service/timers/timers.go
+++ b/core/internal/service/timers/timers.go
@@ -4,19 +4,24 @@ import (
"billionmail-core/internal/service/domains"
"context"
"github.com/gogf/gf/os/gtimer"
- "github.com/gogf/gf/v2/os/glog"
+ "github.com/gogf/gf/v2/frame/g"
"time"
)
func Start(ctx context.Context) (err error) {
- glog.Debug(ctx, "Staring timers...")
+ g.Log().Debug(ctx, "Staring timers...")
// Start DNS Records checking
+ // Ensure the DNS records are fresh on startup
+ gtimer.AddOnce(5*time.Second, func() {
+ domains.FreshRecords(ctx)
+ })
+ // Check DNS Records every 5 minutes
gtimer.Add(5*time.Minute, func() {
domains.FreshRecords(ctx)
})
- glog.Debug(ctx, "Start timers complete")
+ g.Log().Debug(ctx, "Start timers complete")
return
}
diff --git a/core/manifest/config/config.yaml b/core/manifest/config/config.yaml
index 3d36763b..16ef4c48 100644
--- a/core/manifest/config/config.yaml
+++ b/core/manifest/config/config.yaml
@@ -57,7 +57,7 @@ logger:
timeFormat: "2006-01-02T15:04:05" # Custom log output time format, using Golang standard time format configuration
ctxKeys: [] # Custom Context variable name, automatically print Context variables to the log. Default is empty
header: true # Whether to print the header information of the log. Default is true
- stdout: true # Whether the log is output to the terminal at the same time. Default is true
+ stdout: false # Whether the log is output to the terminal at the same time. Default is true
rotateSize: 0 # According to the size of the log file, the file is rolled and cut. Default is 0, indicating that the rolling cutting feature is turned off
rotateExpire: 0 # According to the time interval of the log file, the file is rolled and cut. Default is 0, indicating that the rolling cutting feature is turned off
rotateBackupLimit: 0 # According to the number of split files, clean up the split files, when the rolling cutting feature is turned on. Default is 0, indicating no backup, and the split is deleted