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
Adjust the api for viewing service configuration
lotk7cbf4d424586
diff --git a/core/api/mail_services/v1/common.go b/core/api/mail_services/v1/common.goindex 90e65a69..65604fb2 100644--- a/core/api/mail_services/v1/common.go+++ b/core/api/mail_services/v1/common.go@@ -7,12 +7,6 @@ import (type ServiceType string-const (- ServiceTypePostfix ServiceType = "postfix"- ServiceTypeDovecot ServiceType = "dovecot"- ServiceTypeRspamd ServiceType = "rspamd"-)-const (ServiceType_Postfix = "/opt/Billion-Mail/conf/postfix/main.cf"ServiceType_Dovecot = "/opt/Billion-Mail/conf/dovecot/dovecot.conf"@@ -21,7 +15,7 @@ const (type GetConfigFileReq struct {g.Meta `path:"/services/get_config" method:"post" summary:"get config file"`- ServiceType ServiceType `json:"service_type" v:"required" desc:"service type"`+ ServiceType string `json:"service_type" v:"required" desc:"service type"`}type GetConfigFileRes struct {@@ -38,8 +32,8 @@ type GetConfigFileRes struct {type SaveConfigFileReq struct {g.Meta `path:"/services/save_config" method:"post" summary:"save config file"`- ServiceType ServiceType `json:"service_type" v:"required" desc:"service type"`- Content string `json:"content" v:"required" desc:"file content"`+ ServiceType string `json:"service_type" v:"required" desc:"service type"`+ Content string `json:"content" v:"required" desc:"file content"`}type SaveConfigFileRes struct {diff --git a/core/internal/controller/mail_services/mail_services.go b/core/internal/controller/mail_services/mail_services.goindex 40b15a42..56022cbe 100644--- a/core/internal/controller/mail_services/mail_services.go+++ b/core/internal/controller/mail_services/mail_services.go@@ -7,6 +7,7 @@ package mail_servicesimport ("billionmail-core/internal/model/entity"docker "billionmail-core/internal/service/dockerapi"+ "billionmail-core/internal/service/public""context""fmt""github.com/gogf/gf/v2/errors/gerror"@@ -46,7 +47,7 @@ func SyncBccToPostfix(ctx context.Context) error {mainCfFile := path.Join(postfixConfigDir, "main.cf")if !gfile.Exists(postfixConfigDir) {- return gerror.Newf("Postfix configuration directory does not exist : %s", postfixConfigDir)+ return gerror.Newf(public.LangCtx(ctx, "Postfix configuration directory does not exist : %s", postfixConfigDir))}diff --git a/core/internal/controller/mail_services/mail_services_v1_get_config_file.go b/core/internal/controller/mail_services/mail_services_v1_get_config_file.goindex 7dc955f1..7ba6b85b 100644--- a/core/internal/controller/mail_services/mail_services_v1_get_config_file.go+++ b/core/internal/controller/mail_services/mail_services_v1_get_config_file.go@@ -15,14 +15,14 @@ import (func (c *ControllerV1) GetConfigFile(ctx context.Context, req *v1.GetConfigFileReq) (res *v1.GetConfigFileRes, err error) {res = &v1.GetConfigFileRes{}- // get service config file pathe config file pathvar configPath string- switch req.ServiceType {- case v1.ServiceTypePostfix:- configPath = v1.ServiceType_Postfix- case v1.ServiceTypeDovecot:+ serviceType := strings.ToLower(req.ServiceType)+ switch {+ case strings.Contains(serviceType, "dovecot"):configPath = v1.ServiceType_Dovecot- case v1.ServiceTypeRspamd:+ case strings.Contains(serviceType, "postfix"):+ configPath = v1.ServiceType_Postfix+ case strings.Contains(serviceType, "rspamd"):configPath = v1.ServiceType_Rspamddefault:return nil, gerror.NewCode(gcode.CodeInvalidParameter, "invalid service type")diff --git a/core/internal/controller/mail_services/mail_services_v1_save_config_file.go b/core/internal/controller/mail_services/mail_services_v1_save_config_file.goindex 9fd1c0a9..bfeb404c 100644--- a/core/internal/controller/mail_services/mail_services_v1_save_config_file.go+++ b/core/internal/controller/mail_services/mail_services_v1_save_config_file.go@@ -18,17 +18,14 @@ func (c *ControllerV1) SaveConfigFile(ctx context.Context, req *v1.SaveConfigFilres = &v1.SaveConfigFileRes{}var configPath string- //var serviceNameForCheck string- switch req.ServiceType {- case v1.ServiceTypePostfix:- configPath = v1.ServiceType_Postfix- //serviceNameForCheck = "Postfix"- case v1.ServiceTypeDovecot:+ serviceType := strings.ToLower(req.ServiceType)+ switch {+ case strings.Contains(serviceType, "dovecot"):configPath = v1.ServiceType_Dovecot- //serviceNameForCheck = "Dovecot"- case v1.ServiceTypeRspamd:+ case strings.Contains(serviceType, "postfix"):+ configPath = v1.ServiceType_Postfix+ case strings.Contains(serviceType, "rspamd"):configPath = v1.ServiceType_Rspamd- //serviceNameForCheck = "Rspamd"default:res.SetError(gerror.New(public.LangCtx(ctx, "Invalid service type")))return nil, err@@ -66,52 +63,3 @@ func (c *ControllerV1) SaveConfigFile(ctx context.Context, req *v1.SaveConfigFilres.SetSuccess(public.LangCtx(ctx, "The configuration file was saved successfully"))return}--func getDockerCheckDetails(ctx context.Context, serviceType v1.ServiceType) (containerName string, commandAndArgs []string, execUser string, serviceDisplayName string) {- execUser = "root"-- switch serviceType {- case v1.ServiceTypePostfix:- containerName = "billionmail-postfix-billionmail-1"- commandAndArgs = []string{"postfix", "check"}- serviceDisplayName = "Postfix"- return- case v1.ServiceTypeDovecot:- containerName = "billionmail-dovecot-billionmail-1"- commandAndArgs = []string{"doveconf", "-n"}- serviceDisplayName = "Dovecot"- return- case v1.ServiceTypeRspamd:- containerName = "billionmail-rspamd-billionmail-1"- commandAndArgs = []string{"rspamd", "configtest", "--insecure"}- serviceDisplayName = "Rspamd"- return- default:- return "", nil, "", "Unknown service"- }-}--func extractCheckError(outputStr string, defaultError string) string {- if len(outputStr) == 0 {- return defaultError- }- lines := strings.Split(outputStr, "\n")- for _, line := range lines {- lowerLine := strings.ToLower(line)- if strings.Contains(lowerLine, "error") ||- strings.Contains(lowerLine, "fatal") ||- strings.Contains(lowerLine, "failed") {- if len(line) > 256 {- return line[:256] + "..."- }- return line- }- }- if len(lines) > 0 && len(lines[0]) > 0 {- if len(lines[0]) > 256 {- return lines[0][:256] + "..."- }- return lines[0]- }- return defaultError-}diff --git a/core/internal/service/database_initialization/mail_serv.go b/core/internal/service/database_initialization/mail_serv.goindex 34383bd9..a15f746c 100644--- a/core/internal/service/database_initialization/mail_serv.go+++ b/core/internal/service/database_initialization/mail_serv.go@@ -60,7 +60,21 @@ func init() {update_time int NOT NULL default 0,active smallint NOT NULL DEFAULT 1)`,-+ `-- bm_relay+ CREATE TABLE IF NOT EXISTS bm_relay (+ id BIGSERIAL PRIMARY KEY,+ remark varchar(255), -- Remarks+ sender_domain varchar(255) NOT NULL, -- Sender domain, e.g., "@example.com"+ relay_host varchar(255) NOT NULL, -- Relay server address"+ relay_port varchar(10) NOT NULL, -- Relay server port, e.g., "587"+ auth_user varchar(255) NOT NULL, -- SMTP authentication username+ auth_password varchar(255) NOT NULL, -- SMTP authentication password (consider encrypted storage)+ ip varchar(255), -- IP used to remind users to update SPF records (optional)+ host varchar(255), -- Host used to remind users to update SPF records (optional)+ create_time int NOT NULL default 0,+ update_time int NOT NULL default 0,+ active smallint NOT NULL DEFAULT 1 -- Whether this relay configuration is enabled+ )`,`-- alias_domainCREATE TABLE IF NOT EXISTS alias_domain (alias_domain varchar(255) NOT NULL,