From e24f31bdeffa9c44ca23364cf9a397b0c6c6e712 Mon Sep 17 00:00:00 2001 From: Toby Chui Date: Sun, 28 Apr 2024 22:25:05 +0800 Subject: [PATCH] Fixed #126 - Added cert store hot reload to fix newly ssl cert not loaded - Optimized SMTP structure and UI --- src/acme.go | 5 +++++ src/emails.go | 7 ------- src/mod/email/email.go | 12 +++--------- src/web/components/utils.html | 30 +++--------------------------- 4 files changed, 11 insertions(+), 43 deletions(-) diff --git a/src/acme.go b/src/acme.go index f1b54c5..4dd7cd4 100644 --- a/src/acme.go +++ b/src/acme.go @@ -101,6 +101,7 @@ func AcmeCheckAndHandleRenewCertificate(w http.ResponseWriter, r *http.Request) } else { //This port do not support ACME utils.SendErrorResponse(w, "ACME renew only support web server listening on port 80 (http) or 443 (https)") + return } //Add a 3 second delay to make sure everything is settle down @@ -109,6 +110,10 @@ func AcmeCheckAndHandleRenewCertificate(w http.ResponseWriter, r *http.Request) // Pass over to the acmeHandler to deal with the communication acmeHandler.HandleRenewCertificate(w, r) + //Update the TLS cert store buffer + tlsCertManager.UpdateLoadedCertList() + + //Restore original settings if dynamicProxyRouter.Option.Port == 443 { if !isForceHttpsRedirectEnabledOriginally { //Default is off. Turn the redirection off diff --git a/src/emails.go b/src/emails.go index 9946d28..529d25d 100644 --- a/src/emails.go +++ b/src/emails.go @@ -25,12 +25,6 @@ func HandleSMTPSet(w http.ResponseWriter, r *http.Request) { return } - domain, err := utils.PostPara(r, "domain") - if err != nil { - //Assume domain is empty, raised by issue #129 - domain = "" - } - portString, err := utils.PostPara(r, "port") if err != nil { utils.SendErrorResponse(w, "port must be a valid integer") @@ -76,7 +70,6 @@ func HandleSMTPSet(w http.ResponseWriter, r *http.Request) { //Set the email sender properties thisEmailSender := email.Sender{ Hostname: strings.TrimSpace(hostname), - Domain: strings.TrimSpace(domain), Port: port, Username: strings.TrimSpace(username), Password: strings.TrimSpace(password), diff --git a/src/mod/email/email.go b/src/mod/email/email.go index 878b130..36946fc 100644 --- a/src/mod/email/email.go +++ b/src/mod/email/email.go @@ -13,7 +13,6 @@ import ( type Sender struct { Hostname string //E.g. mail.gandi.net - Domain string //E.g. arozos.com Port int //E.g. 587 Username string //Username of the email account Password string //Password of the email account @@ -21,10 +20,9 @@ type Sender struct { } // Create a new email sender object -func NewEmailSender(hostname string, domain string, port int, username string, password string, senderAddr string) *Sender { +func NewEmailSender(hostname string, port int, username string, password string, senderAddr string) *Sender { return &Sender{ Hostname: hostname, - Domain: domain, Port: port, Username: username, Password: password, @@ -52,12 +50,8 @@ func (s *Sender) SendEmail(to string, subject string, content string) error { content + "\n\n") //Login to the SMTP server - var auth smtp.Auth - if s.Domain == "" { - auth = smtp.PlainAuth("", s.Username, s.Password, s.Hostname) - } else { - auth = smtp.PlainAuth("", s.Username+"@"+s.Domain, s.Password, s.Hostname) - } + //Username can be username (e.g. admin) or email (e.g. admin@example.com), depending on SMTP service provider + auth := smtp.PlainAuth("", s.Username, s.Password, s.Hostname) err := smtp.SendMail(s.Hostname+":"+strconv.Itoa(s.Port), auth, s.SenderAddr, []string{to}, msg) if err != nil { diff --git a/src/web/components/utils.html b/src/web/components/utils.html index e4dc346..965d2b6 100644 --- a/src/web/components/utils.html +++ b/src/web/components/utils.html @@ -65,21 +65,9 @@

Credentials for SMTP server authentications

-
-
- - -
- -
- -
-
- @ -
- -
-
+
+ +
@@ -272,7 +260,6 @@ e.preventDefault(); var data = { hostname: $('input[name=hostname]').val(), - domain: $('input[name=domain]').val(), port: parseInt($('input[name=port]').val()), username: $('input[name=username]').val(), password: $('input[name=password]').val(), @@ -306,7 +293,6 @@ function initSMTPSettings(){ $.get("/api/tools/smtp/get", function(data){ $('#email-form input[name=hostname]').val(data.Hostname); - $('#email-form input[name=domain]').val(data.Domain); $('#email-form input[name=port]').val(data.Port); $('#email-form input[name=username]').val(data.Username); $('#email-form input[name=senderAddr]').val(data.SenderAddr); @@ -345,16 +331,6 @@ form.find('input[name="hostname"]').parent().removeClass('error'); } - // validate domain, now allow empty string (for smtp that dont use domain as input) - /* - const domain = form.find('input[name="domain"]').val().trim(); - if (!domainRegex.test(domain)) { - form.find('input[name="domain"]').parent().addClass('error'); - isValid = false; - } else { - form.find('input[name="domain"]').parent().removeClass('error'); - } - */ // validate username const username = form.find('input[name="username"]').val().trim();