Skip to content

Instantly share code, notes, and snippets.

@operatorofhell
Created December 3, 2017 16:36
Show Gist options
  • Save operatorofhell/3e406d97362536cbf4a37033191ef8cb to your computer and use it in GitHub Desktop.
Save operatorofhell/3e406d97362536cbf4a37033191ef8cb to your computer and use it in GitHub Desktop.
PAC with tree evaluation
var domain = {
"com":{
"yammer":{
"bla":1,
"fasel":2
},
"microsoft":3
},
"de":{
"test":{
"*":4
}
},
"bla":5
};
var proxies = {
1: "DIRECT;",
"default": "PROXY default.host:8080;"
};
function FindProxyForURL(url, host) {
fqdn = host.split('.').reverse();
var root = domain;
var rval = 0
for( i = 0; i < fqdn.length; i++) {
node = fqdn[i];
hit = 0
rval = 0
for( var key in root) {
if( shExpMatch(node, key) ){
hit = 1;
if( root[key] > 0) {
rval = root[key];
} else {
root = root[key];
}
}
}
if (! hit)
break;
}
if (rval)
return(proxies[rval] );
return(proxies['default']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment