Difference between revisions of "PAC file example"
From Tech-Wiki
Line 18: | Line 18: | ||
if (dnsDomainIs(host, "www.acme.com") || | if (dnsDomainIs(host, "www.acme.com") || | ||
dnsDomainIs(host, "webmail.acme.com")) | dnsDomainIs(host, "webmail.acme.com")) | ||
− | + | return "PROXY proxy.acme.com:3128; DIRECT"; | |
/*If the host is an internal IP range, send direct */ | /*If the host is an internal IP range, send direct */ | ||
Line 25: | Line 25: | ||
isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") || | isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") || | ||
isInNet(resolved_ip, "127.0.0.0", "255.255.255.0")) | isInNet(resolved_ip, "127.0.0.0", "255.255.255.0")) | ||
− | + | return "DIRECT"; | |
if (shExpMatch(host, "*.microsoft.com") || | if (shExpMatch(host, "*.microsoft.com") || | ||
shExpMatch(host, "*windowsupdate*")) | shExpMatch(host, "*windowsupdate*")) | ||
− | + | return "PROXY proxy.acme.com:3128; DIRECT"; | |
/* FTP goes directly */ | /* FTP goes directly */ | ||
Line 41: | Line 41: | ||
(dnsDomainIs(host, "sso.acme.com"))) | (dnsDomainIs(host, "sso.acme.com"))) | ||
return "DIRECT"; | return "DIRECT"; | ||
+ | |||
+ | // Load balancing | ||
+ | var myIp = myIpAddress(); | ||
+ | var ipBits = myIp.split("."); | ||
+ | var mySeg = parseInt(ipBits[3]); | ||
+ | |||
+ | // Modulus % 2 | ||
+ | if((mySeg % 2) == 0) // Even | ||
+ | return "PROXY proxy1:8080; PROXY proxy2:8080;"; | ||
+ | else | ||
+ | return "PROXY proxy2:8080; PROXY proxy1:8080;"; | ||
+ | |||
/* Default Traffic Forwarding */ | /* Default Traffic Forwarding */ | ||
− | return "PROXY | + | return "PROXY proxy1.acme.com:80; PROXY proxy2.acme.com:80; DIRECT"; |
} | } |
Revision as of 20:41, 3 May 2018
PAC file to use as proxy selector.
function FindProxyForURL(url, host) { var privateIP = /^(0|10|127|192\.168|172\.1[6789]|172\.2[0-9]|172\.3[01]|169\.254|192\.88\.99)\.[0-9.]+$/; var resolved_ip = dnsResolve(host); /* Don't send non-FQDN or private IP auths to us */ // note this will defeat host file entries for external systems if (isPlainHostName(host) || privateIP.test(host)) { return "DIRECT"; } if (dnsDomainIs(host, "www.acme.com") || dnsDomainIs(host, "webmail.acme.com")) return "PROXY proxy.acme.com:3128; DIRECT"; /*If the host is an internal IP range, send direct */ if (isInNet(resolved_ip, "10.0.0.0", "255.0.0.0") || isInNet(resolved_ip, "172.16.0.0", "255.240.0.0") || isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") || isInNet(resolved_ip, "127.0.0.0", "255.255.255.0")) return "DIRECT"; if (shExpMatch(host, "*.microsoft.com") || shExpMatch(host, "*windowsupdate*")) return "PROXY proxy.acme.com:3128; DIRECT"; /* FTP goes directly */ if (url.substring(0,4) == "ftp:") { return "DIRECT"; } // Domains to bypass if ((host == "webmail.acme.com") || (host == "www.acme.com") || (dnsDomainIs(host, "sso.acme.com"))) return "DIRECT"; // Load balancing var myIp = myIpAddress(); var ipBits = myIp.split("."); var mySeg = parseInt(ipBits[3]); // Modulus % 2 if((mySeg % 2) == 0) // Even return "PROXY proxy1:8080; PROXY proxy2:8080;"; else return "PROXY proxy2:8080; PROXY proxy1:8080;"; /* Default Traffic Forwarding */ return "PROXY proxy1.acme.com:80; PROXY proxy2.acme.com:80; DIRECT"; }