Browse Source

Add configurable server ports

- Add possibility to configure Web interface and SASL authentication
  server ports
Alexey Edelev 3 years ago
parent
commit
83a3c0ce19
4 changed files with 25 additions and 2 deletions
  1. 16 0
      config/config.go
  2. 6 0
      config/main.ini.default
  3. 2 1
      sasl/sasl.go
  4. 1 1
      web/server.go

+ 16 - 0
config/config.go

@@ -37,6 +37,8 @@ import (
 const configPath = "data/main.ini"
 const configPath = "data/main.ini"
 
 
 const (
 const (
+	KeyWebPort             = "web_port"
+	KeySASLPort            = "sasl_port"
 	KeyPostfixConfig       = "postfix_config"
 	KeyPostfixConfig       = "postfix_config"
 	KeyMongoAddress        = "mongo_address"
 	KeyMongoAddress        = "mongo_address"
 	KeyMongoUser           = "mongo_user"
 	KeyMongoUser           = "mongo_user"
@@ -71,6 +73,8 @@ func ConfigInstance() *GostfixConfig {
 }
 }
 
 
 type gostfixConfig struct {
 type gostfixConfig struct {
+	WebPort             string
+	SASLPort            string
 	MyDomain            string
 	MyDomain            string
 	VMailboxMaps        string
 	VMailboxMaps        string
 	VMailboxBase        string
 	VMailboxBase        string
@@ -161,7 +165,19 @@ func newConfig() (config *gostfixConfig, err error) {
 
 
 	registrationEnabled := cfg.Section("").Key(KeyRegistrationEnabled).String()
 	registrationEnabled := cfg.Section("").Key(KeyRegistrationEnabled).String()
 
 
+	webPort := cfg.Section("").Key(KeyWebPort).String()
+	if webPort == "" {
+		webPort = "65200"
+	}
+
+	saslPort := cfg.Section("").Key(KeySASLPort).String()
+	if saslPort == "" {
+		saslPort = "65201"
+	}
+
 	config = &gostfixConfig{
 	config = &gostfixConfig{
+		WebPort:             webPort,
+		SASLPort:            saslPort,
 		MyDomain:            myDomain,
 		MyDomain:            myDomain,
 		VMailboxBase:        baseDir,
 		VMailboxBase:        baseDir,
 		VMailboxMaps:        mapsList[1] + ".db",
 		VMailboxMaps:        mapsList[1] + ".db",

+ 6 - 0
config/main.ini.default

@@ -1,3 +1,9 @@
+# Port used by web interface server
+web_port = 65200
+
+# Port used by SASL authentication server
+sasl_port = 65201
+
 # Path to postfix service configuration.
 # Path to postfix service configuration.
 # Usualy placed in /etc/postfix/main.cf
 # Usualy placed in /etc/postfix/main.cf
 # If not set cause critical error.
 # If not set cause critical error.

+ 2 - 1
sasl/sasl.go

@@ -41,6 +41,7 @@ import (
 	"time"
 	"time"
 
 
 	"git.semlanik.org/semlanik/gostfix/auth"
 	"git.semlanik.org/semlanik/gostfix/auth"
+	"git.semlanik.org/semlanik/gostfix/config"
 	"github.com/google/uuid"
 	"github.com/google/uuid"
 )
 )
 
 
@@ -83,7 +84,7 @@ func NewSaslServer() (*SaslServer, error) {
 
 
 func (s *SaslServer) Run() {
 func (s *SaslServer) Run() {
 	go func() {
 	go func() {
-		l, err := net.Listen("tcp", "127.0.0.1:65201")
+		l, err := net.Listen("tcp", "127.0.0.1:"+config.ConfigInstance().SASLPort)
 		if err != nil {
 		if err != nil {
 			log.Fatalf("Coulf not start SASL server: %s\n", err)
 			log.Fatalf("Coulf not start SASL server: %s\n", err)
 			return
 			return

+ 1 - 1
web/server.go

@@ -100,7 +100,7 @@ func NewServer(scanner common.Scanner) *Server {
 
 
 func (s *Server) Run() {
 func (s *Server) Run() {
 	http.Handle("/", s)
 	http.Handle("/", s)
-	log.Fatal(http.ListenAndServe(":65200", nil))
+	log.Fatal(http.ListenAndServe(":"+config.ConfigInstance().WebPort, nil))
 }
 }
 
 
 func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {