Selaa lähdekoodia

auto update script executed

Toby Chui 1 vuosi sitten
vanhempi
commit
8c3de5531c
2 muutettua tiedostoa jossa 9 lisäystä ja 3 poistoa
  1. 2 2
      mod/dynamicproxy/Server.go
  2. 7 1
      mod/dynamicproxy/basicAuth.go

+ 2 - 2
mod/dynamicproxy/Server.go

@@ -74,7 +74,7 @@ func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		sep := h.Parent.getSubdomainProxyEndpointFromHostname(domainOnly)
 		if sep != nil {
 			if sep.RequireBasicAuth {
-				err := handleBasicAuthRouting(w, r, sep)
+				err := h.handleBasicAuthRouting(w, r, sep)
 				if err != nil {
 					return
 				}
@@ -92,7 +92,7 @@ func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	targetProxyEndpoint := h.Parent.getTargetProxyEndpointFromRequestURI(proxyingPath)
 	if targetProxyEndpoint != nil {
 		if targetProxyEndpoint.RequireBasicAuth {
-			err := handleBasicAuthRouting(w, r, targetProxyEndpoint)
+			err := h.handleBasicAuthRouting(w, r, targetProxyEndpoint)
 			if err != nil {
 				return
 			}

+ 7 - 1
mod/dynamicproxy/basicAuth.go

@@ -14,7 +14,11 @@ import (
 	if RequireBasicAuth is set to true
 */
 
-func handleBasicAuthRouting(w http.ResponseWriter, r *http.Request, pe *ProxyEndpoint) error {
+func (h *ProxyHandler) handleBasicAuthRouting(w http.ResponseWriter, r *http.Request, pe *ProxyEndpoint) error {
+	proxyType := "vdir-auth"
+	if pe.ProxyType == ProxyType_Subdomain {
+		proxyType = "subd-auth"
+	}
 	u, p, ok := r.BasicAuth()
 	if !ok {
 		w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
@@ -33,9 +37,11 @@ func handleBasicAuthRouting(w http.ResponseWriter, r *http.Request, pe *ProxyEnd
 	}
 
 	if !matchingFound {
+		h.logRequest(r, false, 401, proxyType, pe.Domain)
 		w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
 		w.WriteHeader(401)
 		return errors.New("unauthorized")
 	}
+
 	return nil
 }