-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplicated.pac
77 lines (67 loc) · 2.71 KB
/
complicated.pac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function FindProxyForURL(url, host) {
// SETTINGS
// your proxy hostname (myproxy.mynetwork.local)
var proxyHostname = "${asg_hostname}";
var proxyPort = 8080;
// regex patterns to exclude from proxy (put your internal networks here)
var directRegexPatterns = [
"*.local/*",
"*.lan/*",
"*192.168.0.*",
"*172.16.*",
"*172.30.0.*"
];
// networks that should use proxies with optional proxy to use override (put your internal networks that should be proxied here)
var nets = [
{ addr: "172.16.0.0", subnet: "255.255.0.0" },
{ addr: "172.30.0.0", subnet: "255.255.255.0", proxy: "172.30.0.1:" + proxyPort },
{ addr: "192.168.0.0", subnet: "255.255.255.0" }
];
var p = "DIRECT";
var defaultproxyurl = "PROXY " + proxyHostname + ":" + proxyPort;
// ACTIONS
//Don't proxy connections to the proxy web interface
if (shExpMatch(url, "https://${asg_hostname}*")) { p = "DIRECT"; }
else if (shExpMatch(url, "https://" + dnsResolve(host) + "*")) { p = "DIRECT"; }
//Exclude non-fqdn hosts from being proxied
else if (isPlainHostName(host)) { p = "DIRECT"; }
else {
var hasRegexMatch = false;
// check proxy exclusion regex patterns
for (var i = 0; i < directRegexPatterns.length; i++) {
var pattern = directRegexPatterns[i];
if (shExpMatch(url, pattern)) {
p = "DIRECT";
hasRegexMatch = true;
break;
}
}
if (!hasRegexMatch) {
// check if client is in proxy network
var ipstr = "";
if (typeof myIpAddressEx === "undefined") {
alert("myIpAddressEx is undefined!"); // this will print to a specific log in the browser
ipstr = myIpAddress(); // only one ip, not all, but FF does not support the "Ex" version...
} else {
ipstr = myIpAddressEx(); // IP1;IP2;IP3
}
var ips = ipstr.split(";");
for (var j = 0; j < nets.length; j++) {
var net = nets[j];
for (var i = 0; i < ips.length; i++) {
var ip = ips[i];
if (isInNet(ip, net.addr, net.subnet)) {
var proxyToUse = defaultproxyurl;
if(net.proxy){
proxyToUse = "PROXY " + net.proxy;
}
p = proxyToUse;
// alert("found " + proxyToUse + " because: " + ip + " is in net " + net.addr + " / " + net.subnet);
break;
}
}
}
}
}
return p;
}