Skip to content

Instantly share code, notes, and snippets.

@perguth
Created April 27, 2015 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perguth/88c4f90490a86d7de897 to your computer and use it in GitHub Desktop.
Save perguth/88c4f90490a86d7de897 to your computer and use it in GitHub Desktop.
Proxy auto configuration file w/ network and domain whitelisting.
/**
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