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
Add an optional time zone
lotk678d629f6dc8
diff --git a/core/api/settings/v1/settings.go b/core/api/settings/v1/settings.goindex c820fda3..f766c032 100644--- a/core/api/settings/v1/settings.go+++ b/core/api/settings/v1/settings.go@@ -64,8 +64,9 @@ type SystemConfig struct {// Time zone configurationManageTimeZone struct {- TimeZone string `json:"timezone" dc:"time zone"`- Command string `json:"command" dc:"command"`+ TimeZone string `json:"timezone" dc:"time zone"`+ Command string `json:"command" dc:"command"`+ AllTimeZones map[string][]string `json:"zones" dc:"available time zones"`} `json:"manage_timezone" dc:"time zone configuration"`// IPv4 network configurationdiff --git a/core/internal/controller/settings/settings.go b/core/internal/controller/settings/settings.goindex 4fae6a1e..9cfa496d 100644--- a/core/internal/controller/settings/settings.go+++ b/core/internal/controller/settings/settings.go@@ -9,10 +9,13 @@ import ("billionmail-core/internal/consts""billionmail-core/internal/service/public""crypto/x509"+ "encoding/json""encoding/pem""fmt"+ "github.com/gogf/gf/v2/os/gfile""os""path/filepath"+ "sort""strconv""strings""time"@@ -22,6 +25,7 @@ var (//envPath = "../.env"envPath = public.AbsPath("../.env")projectPath = public.AbsPath("../")+ zoneFile = public.AbsPath("../core/data/zoneinfo_list.json"))// loadEnvFile .env@@ -183,6 +187,13 @@ func convertEnvToConfig(envMap map[string]string) *v1.SystemConfig {config.ManageTimeZone.TimeZone = envMap["TZ"]config.ManageTimeZone.Command = fmt.Sprintf("cd %s && echo \"TIME ZONE\" | bash bm.sh change-tz", projectPath)+ group, err := loadTimeZoneGroupFromFile(zoneFile)+ if err != nil || len(group.ZoneList) == 0 {+ group, _ = getTimeZoneGroup()+ err = saveTimeZoneGroupToFile(group, zoneFile)+ }+ config.ManageTimeZone.AllTimeZones = group.Zones+// Network configurationconfig.IPv4Network = envMap["IPV4_NETWORK"]config.Fail2ban = envMap["FAIL2BAN_INIT"] == "y"@@ -190,6 +201,55 @@ func convertEnvToConfig(envMap map[string]string) *v1.SystemConfig {return config}+type TimeZoneGroup struct {+ ZoneList []string `json:"zoneList"`+ Zones map[string][]string `json:"zones"`+}++func getTimeZoneGroup() (TimeZoneGroup, error) {+ zoneList := []string{"Asia", "Africa", "America", "Antarctica", "Arctic", "Atlantic", "Australia", "Europe", "Indian", "Pacific"}+ zones := make(map[string][]string)+ root := "/usr/share/zoneinfo"++ for _, mainZone := range zoneList {+ dir := filepath.Join(root, mainZone)+ files, err := os.ReadDir(dir)+ if err != nil {+ continue+ }+ for _, f := range files {+ if !f.IsDir() {+ zones[mainZone] = append(zones[mainZone], f.Name())+ }+ }+ sort.Strings(zones[mainZone])+ }+ return TimeZoneGroup{+ ZoneList: zoneList,+ Zones: zones,+ }, nil+}++func saveTimeZoneGroupToFile(group TimeZoneGroup, filePath string) error {+ data, err := json.Marshal(group)+ if err != nil {+ return err+ }+ return gfile.PutContents(filePath, string(data))+}++func loadTimeZoneGroupFromFile(filePath string) (TimeZoneGroup, error) {+ var group TimeZoneGroup+ if !gfile.Exists(filePath) {+ return group, os.ErrNotExist+ }+ data := gfile.GetContents(filePath)+ if err := json.Unmarshal([]byte(data), &group); err != nil {+ return group, err+ }+ return group, nil+}+// parseInt Safely convert string to integerfunc parseInt(s string, defaultValue int) int {if v, err := strconv.Atoi(s); err == nil {