From 057f306ed92072abaf8025493ca57e5556afee97 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Mon, 17 May 2021 01:16:59 +0100 Subject: [PATCH] hide/ignore ssl_cert when on windows x509.SystemCertPool is unavailable on windows, so any value is ignored and the setting is hidden on the web UI. --- api.go | 10 ++++++++++ email.go | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/api.go b/api.go index f56267f..6888868 100644 --- a/api.go +++ b/api.go @@ -1398,6 +1398,16 @@ func (app *appContext) GetConfig(gc *gin.Context) { } } } + if PLATFORM == "windows" { + delete(resp.Sections["smtp"].Settings, "ssl_cert") + for i, v := range resp.Sections["smtp"].Order { + if v == "ssl_cert" { + sect := resp.Sections["smtp"] + sect.Order = append(sect.Order[:i], sect.Order[i+1:]...) + resp.Sections["smtp"] = sect + } + } + } for sectName, section := range resp.Sections { for settingName, setting := range section.Settings { val := app.config.Section(sectName).Key(settingName) diff --git a/email.go b/email.go index 4a14bc3..a1316b4 100644 --- a/email.go +++ b/email.go @@ -177,11 +177,26 @@ func (emailer *Emailer) NewMailgun(url, key string) { // NewSMTP returns an SMTP emailClient. func (emailer *Emailer) NewSMTP(server string, port int, username, password string, sslTLS bool, certPath string) (err error) { + // x509.SystemCertPool is unavailable on windows + if PLATFORM == "windows" { + emailer.sender = &SMTP{ + auth: smtp.PlainAuth("", username, password, server), + server: server, + port: port, + sslTLS: sslTLS, + tlsConfig: &tls.Config{ + InsecureSkipVerify: false, + ServerName: server, + }, + } + return + } rootCAs, err := x509.SystemCertPool() if rootCAs == nil || err != nil { rootCAs = x509.NewCertPool() } if certPath != "" { + fmt.Println("RUN") var cert []byte cert, err = os.ReadFile(certPath) if rootCAs.AppendCertsFromPEM(cert) == false {