Created
December 3, 2017 16:36
-
-
Save operatorofhell/3e406d97362536cbf4a37033191ef8cb to your computer and use it in GitHub Desktop.
PAC with tree evaluation
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
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