-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathwhitelist_template.pac
75 lines (62 loc) · 1.67 KB
/
whitelist_template.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
/**
* This PAC was generated by CIDR2PAC ver-{#version}
* Last updated at {#date}
* More informations: https://github.com/wspl/CIDR2PAC
*/
var ipRepo = [{#ipRepo}];
function ipToLong(ip) {
var ipl = 0;
var ipParts = ip.split('.');
for (var i = 0; i < ipParts.length; i += 1) {
ipl <<= 8;
ipl += parseInt(ipParts[i]);
}
return ipl >>> 0;
}
function isInside(host) {
var ip = dnsResolve(host);
if (!ip) {
return false;
}
var testIpLong = ipToLong(ip);
var startRange = 0;
var endRange = ipRepo.length;
var leftPot = parseInt((startRange + endRange) / 2);
var rightPot = leftPot + 1;
var leftLong = ipRepo[leftPot][1];
var rightLong = ipRepo[rightPot][0];
while (1) {
if (testIpLong <= leftLong) {
endRange = leftPot;
var leftMin = ipRepo[leftPot][0];
var leftMax = ipRepo[leftPot][1];
if (testIpLong >= leftMin && testIpLong <= leftMax) {
return true;
}
leftPot = parseInt((startRange + endRange) / 2);
rightPot = leftPot + 1;
leftLong = ipRepo[leftPot][1];
rightLong = ipRepo[rightPot][0];
} else if (testIpLong >= rightLong) {
startRange = rightPot;
var rightMin = ipRepo[rightPot][0];
var rightMax = ipRepo[rightPot][1];
if (testIpLong >= rightMin && testIpLong <= rightMax) {
return true;
}
leftPot = parseInt((startRange + endRange) / 2);
rightPot = leftPot + 1;
leftLong = ipRepo[leftPot][1];
rightLong = ipRepo[rightPot][0];
} else {
return false;
}
}
}
function FindProxyForURL(url, host) {
if (isInside(host)) {
return 'DIRECT';
} else {
return '{#proxy}';
}
}