// handlePACFile serves an automatically-generated PAC (Proxy Auto-Config) file
// pointing to this proxy server.
handlePACFile serves an automatically-generated PAC (Proxy Auto-Config) file
pointing to this proxy server.
// handlePACFile serves an automatically - generated PAC ( Proxy Auto - Config ) file // pointing to this proxy server .
func handlePACFile(w http.ResponseWriter, r *http.Request) {
	proxyAddr := r.Host
	conf := getConfig()
	if a := r.FormValue("a"); a != "" {
		if user, pass, ok := decodeBase64Credentials(a); ok {
			if conf.ValidCredentials(user, pass) {
				port := conf.CustomPorts[user].Port
				customPortLock.RLock()
				p := customPorts[port]
				customPortLock.RUnlock()
				if p != nil {
					client := r.RemoteAddr
					host, _, err := net.SplitHostPort(client)
					if err == nil {
						client = host
					}
					p.AllowIP(client)
					proxyHost, _, err := net.SplitHostPort(proxyAddr)
					if err == nil {
						proxyAddr = net.JoinHostPort(proxyHost, strconv.Itoa(p.Port))
					}
				}
			}
		}
	}
	pacTemplate := conf.PACTemplate
	if pacTemplate == "" {
		pacTemplate = standardPACTemplate
	}
	w.Header().Set("Content-Type", "application/x-ns-proxy-autoconfig")
	if strings.Contains(pacTemplate, "%s") {
		fmt.Fprintf(w, pacTemplate, proxyAddr)
	} else {
		fmt.Fprint(w, pacTemplate)
	}
}
func handlePACFile ( w http . ResponseWriter , r * http . Request ) { proxyAddr := r . Host conf := getConfig ( ) if a := r . FormValue ( " " ) ; a != " " { if user , pass , ok := decodeBase64Credentials ( a ) ; ok { if conf . ValidCredentials ( user , pass ) { port := conf . CustomPorts [ user ] . Port customPortLock . RLock ( ) p := customPorts [ port ] customPortLock . RUnlock ( ) if p != nil { client := r . RemoteAddr host , _ , err := net . SplitHostPort ( client ) if err == nil { client = host } p . AllowIP ( client ) proxyHost , _ , err := net . SplitHostPort ( proxyAddr ) if err == nil { proxyAddr = net . JoinHostPort ( proxyHost , strconv . Itoa ( p . Port ) ) } } } } } pacTemplate := conf . PACTemplate if pacTemplate == " " { pacTemplate = standardPACTemplate } w . Header ( ) . Set ( " " , " " ) if strings . Contains ( pacTemplate , " " ) { fmt . Fprintf ( w , pacTemplate , proxyAddr ) } else { fmt . Fprint ( w , pacTemplate ) } }
handlePACFile serves an automatically-generated PAC (Proxy Auto-Config) file
pointing to this proxy server.
handlePACFile serves an automatically - generated PAC ( Proxy Auto - Config ) file pointing to this proxy server .