-
Notifications
You must be signed in to change notification settings - Fork 54
/
bricks
executable file
·250 lines (226 loc) · 6.1 KB
/
bricks
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/bin/sh
# BRICKS the Gfwed domains list by @leaskh
listDomain() {
cat $brickFile
}
searchDomain() {
grep "$1" $brickFile
}
addDomain() {
if [ "$1" = '' ]; then
echo 'Domain can not be empty!';
exit 1
fi
echo $1 >> $brickFile
cleanList
}
removeDomain() {
grep -v "$1" $brickFile > $brickFile.temp
mv $brickFile.temp $brickFile
cleanList
}
cleanList() {
sort -u $brickFile -o $brickFile
echo 'Done :)'
}
makePac() {
if [ "$*" = '' ]; then
echo 'Proxy configurations can not be empty!';
exit 1
fi
bricks=''
length=0
opFile=bricks.pac
while read line; do
if [ "$line" != '' ]; then
bricks+="'$line' : 1,"
length=$(( length + 1 ))
fi
done < $brickFile
strPac=$(cat <<EOF
// BRICKS Pac by @leaskh
// www.leaskh.com, [email protected]\n
function FindProxyForURL(url, host) {
var bricks = {
$bricks
'localhost' : 1
};
\n// see https://github.com/clowwindy/ChinaDNS/blob/master/chinadns/dnsrelay.py\n
var fakeIps = {
'74.125.127.102' : 1,
'74.125.155.102' : 1,
'74.125.39.102' : 1,
'74.125.39.113' : 1,
'209.85.229.138' : 1,
'128.121.126.139' : 1,
'159.106.121.75' : 1,
'169.132.13.103' : 1,
'192.67.198.6' : 1,
'202.106.1.2' : 1,
'202.181.7.85' : 1,
'203.161.230.171' : 1,
'203.98.7.65' : 1,
'207.12.88.98' : 1,
'208.56.31.43' : 1,
'209.145.54.50' : 1,
'209.220.30.174' : 1,
'209.36.73.33' : 1,
'211.94.66.147' : 1,
'213.169.251.35' : 1,
'216.221.188.182' : 1,
'216.234.179.13' : 1,
'243.185.187.39' : 1,
'37.61.54.158' : 1,
'4.36.66.178' : 1,
'46.82.174.68' : 1,
'59.24.3.173' : 1,
'64.33.88.161' : 1,
'64.33.99.47' : 1,
'64.66.163.251' : 1,
'65.104.202.252' : 1,
'65.160.219.113' : 1,
'66.45.252.237' : 1,
'72.14.205.104' : 1,
'72.14.205.99' : 1,
'78.16.49.15' : 1,
'8.7.198.45' : 1,
'93.46.8.89' : 1
};
var safePorts = {
5223 : 1,
3478 : 1,
3479 : 1,
3480 : 1,
3481 : 1,
3482 : 1,
3483 : 1,
3484 : 1,
3485 : 1,
3486 : 1,
3487 : 1,
3488 : 1,
3489 : 1,
3490 : 1,
3491 : 1,
3492 : 1,
3493 : 1,
3494 : 1,
3495 : 1,
3496 : 1,
3497 : 1,
16384 : 1,
16385 : 1,
16386 : 1,
16387 : 1,
16393 : 1,
16394 : 1,
16395 : 1,
16396 : 1,
16397 : 1,
16398 : 1,
16399 : 1,
16400 : 1,
16401 : 1,
16402 : 1
};
var proxy = '$*';
function testDomain(target, domains, cnRootIncluded) {
var idxA = target.lastIndexOf('.');
var idxB = target.lastIndexOf('.', idxA - 1);
var hasOwnProperty = Object.hasOwnProperty;
var suffix = cnRootIncluded ? target.substring(idxA + 1) : '';
if (suffix === 'cn') {
return true;
}
while (true) {
if (idxB === -1) {
if (hasOwnProperty.call(domains, target)) {
return true;
} else {
return false;
}
}
suffix = target.substring(idxB + 1);
if (hasOwnProperty.call(domains, suffix)) {
return true;
}
idxB = target.lastIndexOf('.', idxB - 1);
}
}
if (isPlainHostName(host)
|| host === '127.0.0.1'
|| host === 'localhost') {
return 'DIRECT';
}
if (testDomain(host, bricks)) {
return proxy;
}
if (safePorts[host.split(':')[1]]) {
return 'DIRECT';
}
var strIp = dnsResolve(host);
if (!strIp) {
return proxy;
}
if (fakeIps[strIp]) {
return proxy;
}
return DIRECT;
}
EOF)
echo $strPac > $opFile
echo 'Done :)'
echo "Rules: $length items."
echo "Usage: Use the newly created $opFile as your web browser's automatic"
echo 'PAC(Proxy auto-config) file.'
}
pacServer() {
makePac $*
echo 'PAC is now serving at: 0.0.0.0:8000'
echo 'Check it out with: $ curl http://127.0.0.1:8000/bricks.pac'
python -m SimpleHTTPServer
}
showHelp() {
echo ' ____________________________________________ '
echo '| Twitter|________|________|________|__Vimeo_|'
echo '|________|Facebook|________|________|________|'
echo '|________|________|________|________|________|'
echo '|________|________|________|_Google_|________|'
echo '|YouTube_| |________|________|________|'
echo '| |'
echo '| * |'
echo '| |'
echo '| _______ |'
echo '| |_______| |'
echo '|____________________________________________|'
echo ''
echo 'BRICKS is a list for all the domains blocked by the Chinese GFW (Great-Fire-Wall).'
echo ''
echo '- list : List all the domains in BRICKS'
echo '- search : Search for domains in BRICKS'
echo '- add : Add domain into BRICKS'
echo '- remove : Remove domain from BRICKS'
echo '- clean : Sort & uniq domains in BRICKS'
echo '- makpac : Make PAC file with BRICKS'
echo '- pacsrv : Make PAC file and launch HTTP server'
echo '- helps : Show this infos'
}
unknowCommand() {
showHelp
exit 1
}
# BlackBox configurations
brickFile=./gfw.bricks
# Main logic
case "$1" in
'list' ) listDomain ;;
'search') searchDomain $2;;
'add' ) addDomain $2;;
'remove') removeDomain $2;;
'clean' ) cleanList ;;
'makpac') makePac $2;;
'pacsrv') pacServer $2;;
'help' ) showHelp ;;
* ) unknowCommand ;;
esac
exit 0