added AllowedHosts configuration

This commit is contained in:
Philippe Beaulieu 2020-04-09 09:18:50 -04:00
parent 567755e257
commit fd213dd450
4 changed files with 11 additions and 8 deletions

View File

@ -25,7 +25,8 @@ On local PC (192.168.1.54) create file `/etc/mailrelay.json` with contents:
"smtp_username": "username@fastmail.com", "smtp_username": "username@fastmail.com",
"smtp_password": "secretAppPassword", "smtp_password": "secretAppPassword",
"local_listen_ip": "0.0.0.0", "local_listen_ip": "0.0.0.0",
"local_listen_port": 2525 "local_listen_port": 2525,
"allowed_hosts": ["*"]
} }
``` ```

View File

@ -5,4 +5,5 @@
"smtp_password": "secret_app_password", "smtp_password": "secret_app_password",
"local_listen_port": 2525, "local_listen_port": 2525,
"local_listen_ip": "0.0.0.0" "local_listen_ip": "0.0.0.0"
"allowed_hosts": ["*"]
} }

13
main.go
View File

@ -15,12 +15,13 @@ type loggerLevels struct {
} }
type mailRelayConfig struct { type mailRelayConfig struct {
SMTPServer string `json:"smtp_server"` SMTPServer string `json:"smtp_server"`
SMTPPort int `json:"smtp_port"` SMTPPort int `json:"smtp_port"`
SMTPUsername string `json:"smtp_username"` SMTPUsername string `json:"smtp_username"`
SMTPPassword string `json:"smtp_password"` SMTPPassword string `json:"smtp_password"`
LocalListenIP string `json:"local_listen_ip"` LocalListenIP string `json:"local_listen_ip"`
LocalListenPort int `json:"local_listen_port"` LocalListenPort int `json:"local_listen_port"`
AllowedHosts []string `json:"allowed_hosts"`
} }
// Logger provides application logging. // Logger provides application logging.

View File

@ -14,7 +14,7 @@ func Start(appConfig *mailRelayConfig) (err error) {
listen := fmt.Sprintf("%s:%d", appConfig.LocalListenIP, appConfig.LocalListenPort) listen := fmt.Sprintf("%s:%d", appConfig.LocalListenIP, appConfig.LocalListenPort)
cfg := &guerrilla.AppConfig{LogFile: log.OutputStdout.String(), AllowedHosts: []string{"warpmail.net"}} cfg := &guerrilla.AppConfig{LogFile: log.OutputStdout.String(), AllowedHosts: appConfig.AllowedHosts}
sc := guerrilla.ServerConfig{ sc := guerrilla.ServerConfig{
ListenInterface: listen, ListenInterface: listen,
IsEnabled: true, IsEnabled: true,