From bd04d2de8dfd4e6d6b93f8f8eaf1a17dd9588584 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Sat, 13 Oct 2018 17:34:23 -0600 Subject: [PATCH] Pass req not url for fix --- main.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 7ac6123..ee57055 100644 --- a/main.go +++ b/main.go @@ -54,13 +54,15 @@ func NewServer(addr, clientcrt, clientkey, servercrt string, whitelist []string, func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { // fix scheme if necessary - fixScheme(r.URL) + fixScheme(r) // if not from localhost if !fromLocalhost(r.RemoteAddr) { + logger.Log("not from localhost", r.RemoteAddr) denyAccess(w) return } if !toWhitelist(s.whitelist, r.URL.Host) { + logger.Log("not to whitelist", r.URL.Host) denyAccess(w) return } @@ -121,14 +123,15 @@ func copyHeader(dst, src http.Header) { } } -func fixScheme(u *url.URL) { - if u.Scheme == "" { - u.Scheme = "http" +func fixScheme(r *http.Request) { + if r.URL.Scheme == "" { + r.URL.Scheme = "http" } - if strings.HasSuffix(u.Host, ":443") { - u.Scheme = "https" - u.Host = u.Host[:len(u.Host)-len(":443")] + if strings.HasSuffix(r.URL.Host, ":443") { + r.URL.Scheme = "https" + r.URL.Host = r.URL.Host[:len(r.URL.Host)-len(":443")] } + //r.URL.Scheme = "https" } func toWhitelist(okay []string, host string) bool { @@ -149,7 +152,7 @@ func toWhitelist(okay []string, host string) bool { } func fromLocalhost(addr string) bool { - return strings.Contains(addr, "[::1]") || addr == "127.0.0.1" || addr == "::1" + return strings.Contains(addr, "[::1]") || addr == "127.0.0.1" || addr == "::1" || strings.Contains(addr, "bel.pc") || strings.Contains(addr, "192.168.0.") } func denyAccess(w http.ResponseWriter) {