Created
April 27, 2015 16:26
-
-
Save perguth/88c4f90490a86d7de897 to your computer and use it in GitHub Desktop.
Proxy auto configuration file w/ network and domain whitelisting.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
References: | |
- *Foremost:* http://askubuntu.com/a/263596/207593 | |
- http://www.boinklabs.com/wpad.html#20101213 | |
- https://www.websense.com/content/support/library/web/v76/pac_file_best_practices$ | |
*/ | |
function FindProxyForURL (url, host) { | |
// >> CONFIG >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
var bypassString = "DIRECT"; | |
var proxyString = "PROXY proxy.company.de:3128"; | |
// Subdomains included automatically: | |
var urlWhitelist = [ | |
"eff.org", | |
"internetdefenseleague.org" | |
]; | |
var netWhitelist = [ | |
["10.0.0.0", "255.0.0.0"], | |
["127.0.0.0", "255.0.0.0"], | |
["169.254.0.0", "255.255.0.0"], | |
["172.16.0.0", "255.240.0.0"], | |
["192.168.0.0", "255.255.0.0"] | |
]; | |
// << CONFIG <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | |
var host = host.toLowerCase(); | |
var hostIP = undefined; | |
// whitelist URLs: | |
for (var i = 0; i < urlWhitelist.length; i++) { | |
var url = urlWhitelist[i] | |
if (dnsDomainIs(host, "." + url)) return bypassString; | |
} | |
// whitelist nets: | |
if (isResolvable(host)) { | |
hostIP = dnsResolve(host); | |
for (var i = 0; i < netWhitelist.length; i++) { | |
var net = netWhitelist[i]; | |
if (isInNet(hostIP, net[0], net[1])) return bypassString; | |
} | |
} | |
return proxyString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment