~proycon/MailyGo

439fc8ee1aff6fe80d9e7e1ca7589450fcfb474a — Maarten van Gompel 1 year, 1 month ago ecbf660
added control check
2 files changed, 15 insertions(+), 1 deletions(-)

M forms.go
M mail.go
M forms.go => forms.go +14 -0
@@ 4,6 4,8 @@ import (
	"html"
	"net/http"
	"net/url"
	"os"
	"strings"

	"github.com/microcosm-cc/bluemonday"
)


@@ 54,9 56,21 @@ func isBot(values *FormValues) bool {
			}
		}
	}
	controlref := os.Getenv("CONTROL")
	control := strings.TrimSpace(findControl(values))
	if strings.ToLower(controlref) != strings.ToLower(control) {
		return true
	}
	return checkValues(values)
}

func findControl(values *FormValues) string {
	if len((*values)["_control"]) == 1 && (*values)["_control"][0] != "" {
		return (*values)["_control"][0]
	}
	return ""
}

func sendResponse(values *FormValues, w http.ResponseWriter) {
	if len((*values)["_redirectTo"]) == 1 && (*values)["_redirectTo"][0] != "" {
		w.Header().Add("Location", (*values)["_redirectTo"][0])

M mail.go => mail.go +1 -1
@@ 37,7 37,7 @@ func buildMessage(recipient string, date time.Time, values *FormValues) string {
	}
	sort.Strings(keys)
	for _, key := range keys {
		value := (*bodyValues)[key];
		value := (*bodyValues)[key]
		if len(value) > 0 {
			_, _ = fmt.Fprint(msgBuffer, key)
			_, _ = fmt.Fprint(msgBuffer, ": ")