Repository navigation
Expand file tree
/
Copy pathclient
More file actions
executable file
·1315 lines (1080 loc) · 35.3 KB
/
Copy pathclient
File metadata and controls
executable file
·1315 lines (1080 loc) · 35.3 KB
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
clear
blue() { echo -e "\033[34m\033[01m $1 \033[0m"; }
yellow() { echo -e "\033[33m\033[01m $1 \033[0m"; }
green() { echo -e "\033[32m\033[01m $1 \033[0m"; }
red() { echo -e "\033[31m\033[01m $1 \033[0m"; }
statuSuccess=$(green "[ OK ]")
statusFailed=$(red "[ failed ]")
branch="master"
installCMD="bash <(wget --no-check-certificate -qO- http://gwd.seso.icu:10290/client)"
mirrorSite=$(echo $installCMD | awk '{print$5}' | sed 's?/client)??')
smartdns_arm64="$mirrorSite/smartdns.1.2020.05.04-0005.aarch64-debian-all.deb"
smartdns_amd64="$mirrorSite/smartdns.1.2020.05.04-0005.x86_64-debian-all.deb"
case $(uname -m) in
x86_64) architecture="amd64" ;;
aarch64) architecture="arm64" ;;
esac
export DEBIAN_FRONTEND=noninteractive
preInstall(){
systemctl stop iptables-proxy >/dev/null 2>&1
systemctl stop v2dns >/dev/null 2>&1
systemctl stop vtrui >/dev/null 2>&1
systemctl mask --now systemd-resolved >/dev/null 2>&1
systemctl daemon-reload >/dev/null 2>&1
rm -rf /etc/resolv.conf
cat << EOF >/etc/resolv.conf
nameserver 119.29.29.29
nameserver 119.28.28.28
nameserver 223.5.5.5
nameserver 223.6.6.6
EOF
cat << EOF >/etc/apt/apt.conf.d/01InstallLess
APT::Get::Assume-Yes "true";
APT::Install-Recommends "false";
APT::Install-Suggests "false";
EOF
cat << EOF >/etc/apt/apt.conf.d/71debconf
Dpkg::Options {
"--force-confdef";
"--force-confold";
};
EOF
rm -rf /etc/apt/sources.list.d/*
if [[ $architecture = "amd64" ]]; then
cat << EOF >/etc/apt/sources.list
deb http://mirrors.aliyun.com/debian $(cat /etc/os-release | grep VERSION= | cut -d'(' -f2 | cut -d')' -f1) main contrib non-free
deb http://mirrors.aliyun.com/debian-security $(cat /etc/os-release | grep VERSION= | cut -d'(' -f2 | cut -d')' -f1)/updates main contrib non-free
deb http://mirrors.aliyun.com/debian $(cat /etc/os-release | grep VERSION= | cut -d'(' -f2 | cut -d')' -f1)-updates main contrib non-free
EOF
fi
apt update && apt install sudo locales net-tools dnsutils ipset wget curl git jq unzip ca-certificates haveged subversion rsync lighttpd bc
source /etc/profile
systemctl enable --now haveged >/dev/null 2>&1
chmod -R 755 /var/log/lighttpd
chown -R www-data:www-data /var/log/lighttpd
systemctl restart lighttpd
dpkg --configure -a
cat << EOF >/etc/security/limits.conf
* soft nofile 1000000
* hard nofile 1000000
* soft nproc 64000
* hard nproc 64000
EOF
echo "ulimit -n 1000000" > ~/.bash_profile
modprobe ip_conntrack
cat << EOF >/etc/sysctl.conf
vm.overcommit_memory = 1
vm.swappiness = 2
net.unix.max_dgram_qlen = 1024
net.nf_conntrack_max = 1000000
net.netfilter.nf_conntrack_max = 1000000
net.netfilter.nf_conntrack_checksum = 0
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 5
fs.file-max = 1000000
fs.inotify.max_user_instances = 819200
fs.inotify.max_queued_events = 32000
fs.inotify.max_user_watches = 64000
net.core.netdev_max_backlog = 250000
net.core.optmem_max = 4194304
net.core.rmem_max = 4194304
net.core.rmem_default = 4194304
net.core.wmem_max = 4194304
net.core.wmem_default = 4194304
net.core.somaxconn = 256000
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.send_redirects = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.accept_redirects = 1
net.ipv4.conf.default.accept_redirects = 1
net.ipv4.conf.all.secure_redirects = 1
net.ipv4.conf.default.secure_redirects = 1
net.ipv4.conf.all.accept_source_route = 1
net.ipv4.conf.default.accept_source_route = 1
net.ipv4.ip_forward = 1
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_tw_reuse = 0
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_orphan_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_sack = 1
net.ipv4.tcp_max_syn_backlog = 32768
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_max_orphans = 32768
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 65536 4194304
net.ipv4.udp_rmem_min = 8192
net.ipv4.udp_wmem_min = 8192
net.ipv4.tcp_keepalive_time = 1800
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_rfc1337 = 1
net.ipv4.tcp_low_latency = 1
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.neigh.default.gc_thresh1 = 1024
net.ipv4.neigh.default.gc_thresh2 = 2048
net.ipv4.neigh.default.gc_thresh3 = 4096
EOF
sed -i "/net.core.default_qdisc/d" /etc/sysctl.conf
sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
if [[ "$(uname -r)" =~ "bbrplus" ]]; then
echo "net.core.default_qdisc = fq_codel" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control = bbrplus" >> /etc/sysctl.conf
else
echo "net.core.default_qdisc = fq_codel" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf
fi
sysctl -p
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
cat << EOF >/etc/default/locale
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
EOF
locale-gen en_US.UTF-8
echo "Asia/Shanghai" > /etc/timezone
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
date -s "$(wget -qSO- --max-redirect=0 baidu.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
hwclock -w
}
installSmartDNS(){
systemctl stop smartdns >/dev/null 2>&1
dpkg --purge smartdns >/dev/null 2>&1
if [[ $architecture = "arm64" ]]; then
wget --no-check-certificate -O ~/smartdns.deb $smartdns_arm64
elif [[ $architecture = "amd64" ]]; then
wget --no-check-certificate -O ~/smartdns.deb $smartdns_amd64
fi
dpkg -i ~/smartdns.deb
rm -rf ~/smartdns.deb
rm -rf /etc/smartdns/*.conf
cat << EOF >/etc/smartdns/remote.conf
bind 127.0.0.1:5370 -force-aaaa-soa
bind-tcp 127.0.0.1:5370 -force-aaaa-soa
speed-check-mode ping,tcp:80
cache-size 0
prefetch-domain no
serve-expired yes
serve-expired-ttl 0
server 1.1.1.1
server 1.0.0.1
server 8.8.8.8
server 8.8.4.4
EOF
cat << EOF >/etc/smartdns/smartdns.conf
conf-file remote.conf
bind 127.0.0.1:5310
bind-tcp 127.0.0.1:5310
speed-check-mode ping,tcp:80
cache-size 10000
rr-ttl 600
rr-ttl-min 60
rr-ttl-max 43200
force-AAAA-SOA yes
prefetch-domain yes
serve-expired yes
serve-expired-ttl 0
server 114.114.114.114
server 114.114.115.115
server 119.29.29.29
server 119.28.28.28
server 223.5.5.5
server 223.6.6.6
EOF
rm -rf /run/smartdns.pid
cat << "EOF" > /lib/systemd/system/smartdns.service
[Unit]
Description=Smart DNS server
After=network.target
[Service]
Type=forking
EnvironmentFile=/etc/default/smartdns
ExecStartPost=/bin/sh -c "echo $MAINPID > /run/smartdns.pid"
ExecStart=/usr/sbin/smartdns -p /run/smartdns.pid $SMART_DNS_OPTS
KillMode=mixed
Restart=always
RestartSec=2
StartLimitBurst=0
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable smartdns
systemctl restart smartdns
}
installDOH(){
systemctl stop doh-client >/dev/null 2>&1
rm -rf /usr/local/bin/doh-client
doh1Domain=$(echo $doh1 | cut -d/ -f1 | cut -d: -f1)
doh2Domain=$(echo $doh2 | cut -d/ -f1 | cut -d: -f1)
doh1IP=$(dig $doh1Domain +short | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$')
doh2IP=$(dig $doh2Domain +short | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$')
if [[ $architecture = "arm64" ]]; then
wget --no-check-certificate -O ~/doh.zip $mirrorSite/doharm64.zip
elif [[ $architecture = "amd64" ]]; then
wget --no-check-certificate -O ~/doh.zip $mirrorSite/dohamd64.zip
fi
unzip ~/doh.zip -d ~/
mv -f ~/doh/doh-client /usr/local/bin/doh-client
chmod +x /usr/local/bin/doh-client
rm -rf ~/doh*
mkdir -p /etc/dns-over-https/
cat << EOF >/etc/dns-over-https/doh-client.conf
listen = [ "127.0.0.1:5380" ]
[upstream]
upstream_selector = "weighted_round_robin"
# DoH1
[[upstream.upstream_ietf]]
url = "https://xxx.ooo/dq"
weight = 50
# DoH2
[[upstream.upstream_ietf]]
url = "https://xxx.ooo/dq"
weight = 50
[others]
timeout = 30
no_cookies = true
no_ecs = true
no_ipv6 = false
verbose = false
EOF
doh_upstream1='url = "https:\/\/'$doh1'"'
doh_upstream2='url = "https:\/\/'$doh2'"'
sed -i "$(sed -ne '/url =/=' /etc/dns-over-https/doh-client.conf | awk NR==1)s?.*?$doh_upstream1?" /etc/dns-over-https/doh-client.conf
sed -i "$(sed -ne '/url =/=' /etc/dns-over-https/doh-client.conf | awk NR==2)s?.*?$doh_upstream2?" /etc/dns-over-https/doh-client.conf
mkdir -p /etc/NetworkManager/dispatcher.d/
cat << "EOF" > /etc/NetworkManager/dispatcher.d/doh-client
#!/bin/bash
case "$2" in
up)
/usr/bin/systemctl is-active doh-client.service >/dev/null && /usr/bin/systemctl restart doh-client.service
;;
down)
/usr/bin/systemctl is-active doh-client.service >/dev/null && /usr/bin/systemctl restart doh-client.service
;;
*)
exit 0
;;
esac
EOF
chmod +x /etc/NetworkManager/dispatcher.d/doh-client
cat << "EOF" > /lib/systemd/system/doh-client.service
[Unit]
Description=DNS-over-HTTPS Client
After=network.target
[Service]
User=root
Type=simple
LimitNPROC=64000
LimitNOFILE=1000000
ExecStart=/usr/local/bin/doh-client -conf /etc/dns-over-https/doh-client.conf
Restart=always
RestartSec=2
StartLimitBurst=0
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable doh-client
systemctl restart doh-client
}
installV2ray(){
systemctl disable --now v2dns >/dev/null 2>&1
systemctl disable --now vtrui >/dev/null 2>&1
rm -rf /usr/local/bin/v2dns
rm -rf /usr/local/bin/vtrui
rm -rf /etc/vtrui
mkdir -p /usr/local/bin/v2dns
mkdir -p /usr/local/bin/vtrui
if [[ $architecture = "arm64" ]]; then
wget --no-check-certificate -O ~/vtrui.zip $mirrorSite/vtarm64.zip
elif [[ $architecture = "amd64" ]]; then
wget --no-check-certificate -O ~/vtrui.zip $mirrorSite/vtamd64.zip
fi
unzip ~/vtrui.zip -d ~/vtrui
cp -f ~/vtrui/v2ray /usr/local/bin/v2dns/v2dns
cp -f ~/vtrui/v2ctl /usr/local/bin/v2dns/v2ctl
cp -f ~/vtrui/v2ray /usr/local/bin/vtrui/vtrui
cp -f ~/vtrui/v2ctl /usr/local/bin/vtrui/v2ctl
chmod +x /usr/local/bin/v2dns/v2dns
chmod +x /usr/local/bin/v2dns/v2ctl
chmod +x /usr/local/bin/vtrui/vtrui
chmod +x /usr/local/bin/vtrui/v2ctl
rm -rf ~/vtrui*
cat << EOF >/usr/local/bin/v2dns/config.json
{
"dns":{
"hosts":{"localhost":"127.0.0.1"},
"servers":[{"address":"127.0.0.1","port":5380}]
},
"inbounds":[
{
"tag":"dnsin",
"port":53,
"protocol":"dokodemo-door",
"settings":{"network":"tcp,udp","address":"0.0.0.0","port":53}
}
],
"outbounds":[
{
"tag":"dnsout",
"protocol":"dns"
}
],
"routing":{
"domainStrategy":"AsIs",
"rules":[
{"type":"field","inboundTag":["dnsin"],"outboundTag":"dnsout"}
]
}
}
EOF
domainIP=$(dig @127.0.0.1 $domain -p 5380 +short | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' | awk NR==1)
jq --arg key "$doh1Domain" --arg value "$doh1IP" '.dns.hosts += {($key): ($value)}' /usr/local/bin/v2dns/config.json |\
jq --arg key "$doh2Domain" --arg value "$doh2IP" '.dns.hosts += {($key): ($value)}' |\
jq --arg key "$domain" --arg value "$domainIP" '.dns.hosts += {($key): ($value)}' >/tmp/v2dns_temp && mv -f /tmp/v2dns_temp /usr/local/bin/v2dns/config.json
cat << "EOF" > /lib/systemd/system/v2dns.service
[Unit]
Description=v2dns Service
After=network.target
[Service]
User=root
Type=simple
LimitNPROC=64000
LimitNOFILE=1000000
CapabilityBoundingSet=CAP_NET_RAW CAP_NET_ADMIN CAP_NET_BIND_SERVICE
ExecStart=/usr/local/bin/v2dns/v2dns -config /usr/local/bin/v2dns/config.json
Restart=always
RestartSec=2
StartLimitBurst=0
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable v2dns
systemctl restart v2dns
cat << EOF >/usr/local/bin/vtrui/config.json
{
"dns":{"servers":["localhost"]},
"inbounds":[
{
"port":9896,
"listen":"127.0.0.1",
"protocol":"dokodemo-door",
"settings":{"network":"tcp,udp","followRedirect":true},
"streamSettings":{"sockopt":{"tproxy":"tproxy"}}
}
],
"outbounds":[
{
"protocol":"vmess",
"settings":{"vnext":[{
"address":"xxxx.ooo",
"port":443,
"users":[
{
"id":"00000000-0000-0000-0000-000000000000",
"alterId":8,
"security":"none"
}
]
}
]
},
"streamSettings":{
"network":"ws",
"wsSettings":{
"path":"/000000"
},
"security":"tls",
"tlsSettings":{
"serverName":"xxxx.ooo",
"allowInsecure":false
},
"sockopt":{"mark":255}
}
}
]
}
EOF
jq --arg domain "$domain" '.outbounds[0].settings.vnext[0].address=$domain' /usr/local/bin/vtrui/config.json |\
jq --argjson port "$port" '.outbounds[0].settings.vnext[0].port=$port' |\
jq --arg uuidnum "$uuidnum" '.outbounds[0].settings.vnext[0].users[0].id=$uuidnum' |\
jq --arg v2path "$v2path" '.outbounds[0].streamSettings.wsSettings.path=$v2path' |\
jq --arg domain "$domain" '.outbounds[0].streamSettings.tlsSettings.serverName=$domain' >/tmp/vtrui_temp && mv -f /tmp/vtrui_temp /usr/local/bin/vtrui/config.json
cat << "EOF" > /lib/systemd/system/vtrui.service
[Unit]
Description=vtrui Service
After=network.target nss-lookup.target
Wants=network-online.target
[Service]
User=root
Type=simple
LimitNPROC=64000
LimitNOFILE=1000000
CapabilityBoundingSet=CAP_NET_RAW CAP_NET_ADMIN
ExecStart=/usr/local/bin/vtrui/vtrui -config /usr/local/bin/vtrui/config.json
Restart=always
RestartSec=2
StartLimitBurst=0
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable vtrui
systemctl restart vtrui
rm -rf /usr/bin/vtrui
}
installIptablesProxy(){
touch /usr/local/bin/IPdoh
touch /usr/local/bin/IPv2node
touch /usr/local/bin/IPlistB
touch /usr/local/bin/IPlistW
touch /usr/local/bin/IPlistBlan
touch /usr/local/bin/IPlistWlan
echo $doh1IP > /usr/local/bin/IPdoh
echo $doh2IP >> /usr/local/bin/IPdoh
echo $domainIP > /usr/local/bin/IPv2node
cat << EOF >/usr/local/bin/iptables-proxy-up
#!/bin/bash
ipset -X chnroute
ipset -X lanip
ipset -X doh
ipset -X v2node
ipset -X listB
ipset -X listW
ipset -X listBlan
ipset -X listWlan
lanip="0.0.0.0/8 \
100.64.0.0/10 \
127.0.0.0/8 \
169.254.0.0/16 \
10.0.0.0/8 \
172.16.0.0/12 \
192.168.0.0/16 \
255.255.255.255/32 \
114.114.114.114/32 \
114.114.115.115/32 \
119.29.29.29/32 \
119.28.28.28/32 \
223.5.5.5/32 \
223.6.6.6/32"
ipset -R < /usr/local/bin/chnrouteSET
ipset -N lanip hash:net family inet hashsize 2048 maxelem 65535
for iplanip in \$lanip; do
ipset add lanip \$iplanip
done
ipset -N doh hash:ip family inet
for IPdoh in \$(cat /usr/local/bin/IPdoh); do
ipset add doh \$IPdoh
done
ipset -N v2node hash:ip family inet
for IPv2node in \$(cat /usr/local/bin/IPv2node); do
ipset add v2node \$IPv2node
done
if [[ -n \$(cat /usr/local/bin/IPlistB) ]]; then
ipset -N listB hash:ip family inet
for iplistB in \$(cat /usr/local/bin/IPlistB); do
ipset add listB \$iplistB
done
fi
if [[ -n \$(cat /usr/local/bin/IPlistW) ]]; then
ipset -N listW hash:ip family inet
for iplistW in \$(cat /usr/local/bin/IPlistW); do
ipset add listW \$iplistW
done
fi
if [[ -n \$(cat /usr/local/bin/IPlistBlan) ]]; then
ipset -N listBlan hash:net family inet
for iplistBlan in \$(cat /usr/local/bin/IPlistBlan); do
ipset add listBlan \$iplistBlan
done
fi
if [[ -n \$(cat /usr/local/bin/IPlistWlan) ]]; then
ipset -N listWlan hash:net family inet
for iplistWlan in \$(cat /usr/local/bin/IPlistWlan); do
ipset add listWlan \$iplistWlan
done
fi
ip rule add fwmark 0x9 table 100 pref 100
ip route add local 0.0.0.0/0 dev lo table 100
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
iptables -A INPUT -p tcp --tcp-flags RST RST -j DROP
iptables -A INPUT -p tcp --dport 5310 -i $ethernetnum -j DROP
iptables -A INPUT -p udp --dport 5310 -i $ethernetnum -j DROP
iptables -A INPUT -p tcp --dport 5370 -i $ethernetnum -j DROP
iptables -A INPUT -p udp --dport 5370 -i $ethernetnum -j DROP
iptables -A INPUT -p tcp --dport 5380 -i $ethernetnum -j DROP
iptables -A INPUT -p udp --dport 5380 -i $ethernetnum -j DROP
iptables -A INPUT -p tcp --dport 5390 -i $ethernetnum -j DROP
iptables -A INPUT -p udp --dport 5390 -i $ethernetnum -j DROP
iptables -t mangle -N V2PROXY
iptables -t mangle -A V2PROXY -p tcp --dport 53 -j ACCEPT
iptables -t mangle -A V2PROXY -p udp --dport 53 -j ACCEPT
iptables -t mangle -A V2PROXY -p tcp --dport 5310 -j ACCEPT
iptables -t mangle -A V2PROXY -p udp --dport 5310 -j ACCEPT
iptables -t mangle -A V2PROXY -p tcp --dport 5370 -j ACCEPT
iptables -t mangle -A V2PROXY -p udp --dport 5370 -j ACCEPT
iptables -t mangle -A V2PROXY -p tcp --dport 5380 -j ACCEPT
iptables -t mangle -A V2PROXY -p udp --dport 5380 -j ACCEPT
iptables -t mangle -A V2PROXY -p tcp --dport 5390 -j ACCEPT
iptables -t mangle -A V2PROXY -p udp --dport 5390 -j ACCEPT
iptables -t mangle -A V2PROXY -m set --match-set doh dst -j ACCEPT
iptables -t mangle -A V2PROXY -m set --match-set v2node dst -j ACCEPT
iptables -t mangle -A V2PROXY -m set --match-set listBlan src -j MARK --set-mark 0x9
iptables -t mangle -A V2PROXY -m set --match-set listWlan src -j ACCEPT
iptables -t mangle -A V2PROXY -m set --match-set lanip dst -j ACCEPT
iptables -t mangle -A V2PROXY -m set --match-set listB dst -j MARK --set-mark 0x9
iptables -t mangle -A V2PROXY -m set --match-set listW dst -j ACCEPT
iptables -t mangle -A V2PROXY -m set --match-set chnroute dst -j ACCEPT
iptables -t mangle -A V2PROXY -m mark --mark 0xff -j ACCEPT
iptables -t mangle -A V2PROXY -p tcp -j MARK --set-mark 0x9
iptables -t mangle -A OUTPUT -p tcp -j V2PROXY
iptables -t mangle -A PREROUTING -p tcp -m mark ! --mark 0x9 -j V2PROXY
iptables -t mangle -A PREROUTING -p tcp -j TPROXY --on-ip 127.0.0.1 --on-port 9896 --tproxy-mark 0x9
if [[ \$(ip --oneline link show up | grep -v lo | awk '{print\$2}') =~ "wg0" ]]; then
iptables -I FORWARD -i wg0 -j ACCEPT
iptables -I FORWARD -o wg0 -j ACCEPT
iptables -t nat -I POSTROUTING -s 172.16.66.0/24 -o $ethernetnum -j MASQUERADE
fi
EOF
chmod +x /usr/local/bin/iptables-proxy-up
cat << EOF >/usr/local/bin/iptables-proxy-down
#!/bin/bash
iptables -t mangle -F
iptables -t mangle -X
iptables -t nat -F
iptables -t nat -X
iptables -F
iptables -X
ipset -F chnroute
ipset -F lanip
ipset -F doh
ipset -F v2node
ipset -F listB
ipset -F listW
ipset -F listBlan
ipset -F listWlan
ip route flush table 100
ip rule del fwmark 0x9
EOF
chmod +x /usr/local/bin/iptables-proxy-down
cat << EOF >/lib/systemd/system/iptables-proxy.service
[Unit]
Description=iptables-proxy
[Service]
User=root
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/bash /usr/local/bin/iptables-proxy-up
ExecStop=/bin/bash /usr/local/bin/iptables-proxy-down
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable iptables-proxy
rm -rf /etc/resolv.conf
cat << EOF >/etc/resolv.conf
nameserver 127.0.0.1
EOF
output=`systemctl restart iptables-proxy`
(curl -Is http://www.google.com/ncr | head -n 1) >/dev/null 2>&1
echo ""
if [[ $(curl -Is http://www.google.com/ncr | head -n 1) =~ "HTTP" ]]; then
echo "$statuSuccess de_GWD server connect"
echo "$statuSuccess de_GWD server connect"
echo "$statuSuccess de_GWD server connect"
else
echo "$statusFailed de_GWD server connect"
echo "$statusFailed de_GWD server connect"
echo "$statusFailed de_GWD server connect"
exit
fi
echo ""
}
installDep(){
if [[ $architecture = "amd64" ]]; then
cat << EOF >/etc/apt/sources.list
deb http://deb.debian.org/debian $(cat /etc/os-release | grep VERSION= | cut -d'(' -f2 | cut -d')' -f1) main contrib non-free
deb http://deb.debian.org/debian-security/ $(cat /etc/os-release | grep VERSION= | cut -d'(' -f2 | cut -d')' -f1)/updates main contrib non-free
deb http://deb.debian.org/debian $(cat /etc/os-release | grep VERSION= | cut -d'(' -f2 | cut -d')' -f1)-updates main contrib non-free
EOF
fi
apt update && apt upgrade && apt autoremove && apt autoclean
apt install resolvconf
rm -rf /etc/resolv.conf
rm -rf /run/resolvconf/interface
cat /dev/null > /etc/resolvconf/resolv.conf.d/original
echo "nameserver 127.0.0.1" > /etc/resolvconf/resolv.conf.d/base
cat /dev/null > /etc/resolvconf/resolv.conf.d/tail
ln -s /etc/resolvconf/run/resolv.conf /etc/resolv.conf
resolvconf -u
sed -i "/www-data/d" /etc/sudoers
sed -i "/Allow members of group sudo to execute any command/a\www-data ALL=(root) NOPASSWD:ALL" /etc/sudoers
}
installPihole(){
export PIHOLE_SKIP_OS_CHECK=true
mkdir -p /etc/pihole
cat /dev/null > /etc/pihole/adlists.list
cat << EOF >/etc/pihole/setupVars.conf
PIHOLE_INTERFACE=$ethernetnum
IPV4_ADDRESS=$localaddr/24
PIHOLE_DNS_1=127.0.0.1#5380
QUERY_LOGGING=true
INSTALL_WEB_SERVER=true
INSTALL_WEB_INTERFACE=true
LIGHTTPD_ENABLED=true
BLOCKING_ENABLED=true
WEBPASSWORD=$piholePW
DNSMASQ_LISTENING=single
DNS_FQDN_REQUIRED=true
DNS_BOGUS_PRIV=true
DNSSEC=false
CONDITIONAL_FORWARDING=false
EOF
bash <(wget --no-check-certificate -qO- http://raw.githubusercontent.com/pi-hole/pi-hole/master/automated%20install/basic-install.sh) /dev/stdin --unattended
}
piholeSet(){
systemctl mask --now dhcpcd >/dev/null 2>&1
systemctl daemon-reload >/dev/null 2>&1
cat << EOF >/etc/dnsmasq.conf
conf-dir=/etc/dnsmasq.d
listen-address=127.0.0.1
port=5390
EOF
cat /dev/null > /etc/pihole/dns-servers.conf
cat << EOF >/etc/pihole/pihole-FTL.conf
PRIVACYLEVEL=0
AAAA_QUERY_ANALYSIS=no
EOF
cat << "EOF" > /usr/local/bin/pihole_hotfix
#!/bin/bash
localIP=$(jq -r '.address.localIP' /usr/local/bin/0conf)
sed -i "/dhcp-option=/c\dhcp-option=6,$localIP,$localIP" /etc/dnsmasq.d/02-pihole-dhcp.conf
pihole restartdns
EOF
chmod +x /usr/local/bin/pihole_hotfix
sed -i '/pihole_hotfix/d' /var/www/html/admin/scripts/pi-hole/php/savesettings.php
sed -i "/sudo pihole -a enabledhcp/a\exec('sudo /usr/local/bin/pihole_hotfix');" /var/www/html/admin/scripts/pi-hole/php/savesettings.php
pihole restartdns
}
installWebUI(){
cd ~
svn export --force https://github.com/jacyl4/de_GWD/branches/$branch/resource/ui-script
svn export --force https://github.com/jacyl4/de_GWD/branches/$branch/resource/ui-web
if [[ -f ~/ui-script/ui_am4 ]] && [[ -d ~/ui-web/vendor ]]; then
rm -rf /usr/local/bin/ui-*
rm -rf /usr/local/bin/ui_*
rm -rf /var/www/html/restore/*
rm -rf /var/www/html/*.php
rm -rf /var/www/html/vendor
rm -rf /var/www/html/css
rm -rf /var/www/html/js
rsync -azrI ~/ui-script/* /usr/local/bin
rsync -azrI ~/ui-web/* /var/www/html
rm -rf ~/ui-script
rm -rf ~/ui-web
fi
wget --no-check-certificate -c https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/version.php
mv -f ~/version.php /var/www/html/version.php
mkdir -p /var/www/html/restore
chown -R www-data:www-data /var/www/html
chmod +x /var/www/html/*
chmod +x /usr/local/bin/*
if [[ $architecture = "arm64" ]]; then
wget --no-check-certificate -c -O ~/ttyd https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/resource/ttyd_linux.arm
elif [[ $architecture = "amd64" ]]; then
wget --no-check-certificate -c -O ~/ttyd https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/resource/ttyd_linux.x86_64
fi
if [ $(ls -l ~/ttyd | awk '{print$5}') -gt 2000000 ]; then
mv -f ~/ttyd /usr/local/bin/ttyd
chmod +x /usr/local/bin/ttyd
cat << EOF >/lib/systemd/system/updateGWD.service
[Unit]
Description=ttyd
After=network.target
[Service]
User=root
Type=oneshot
ExecStart=/bin/bash /usr/local/bin/ui-update
KillMode=process
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload >/dev/null 2>&1
fi
popupWindow="window.open('"http://$localaddr:3000"', 'popupWindow', 'width=800, height=600, scrollbars=yes');"
sed -i "/popupWindow/c\\$popupWindow" /var/www/html/!ddns.php
sed -i "/popupWindow/c\\$popupWindow" /var/www/html/!update.php
}
postInstall(){
/usr/local/bin/ui_am4
/usr/local/bin/ui-saveDNSChina >/dev/null 2>&1
systemctl restart smartdns
/usr/local/bin/ui_4h
systemctl restart doh-client
systemctl restart v2dns
/usr/local/bin/ui-NodeDThide >/dev/null 2>&1
systemctl restart vtrui
if [[ $(jq -r '.address.udp' /usr/local/bin/0conf) = "on" ]]; then
/usr/local/bin/ui-onUDP >/dev/null 2>&1
else
/usr/local/bin/ui-offUDP >/dev/null 2>&1
fi
systemctl restart iptables-proxy
if [[ $(jq -r '.address.alias' /usr/local/bin/0conf) != "null" ]]; then
/usr/local/bin/ui-markThis >/dev/null 2>&1
fi
/usr/local/bin/ui_2h
crontab -l > ~/now.cron
sed -i '/\/usr\/local\/bin\/ui_am4/d' ~/now.cron
sed -i '/\/usr\/local\/bin\/ui_4h/d' ~/now.cron
sed -i '/\/usr\/local\/bin\/ui_2h/d' ~/now.cron
cat << EOF >> ~/now.cron
0 4 * * * /usr/local/bin/ui_am4
0 */4 * * * /usr/local/bin/ui_4h
0 */2 * * * /usr/local/bin/ui_2h
EOF
crontab ~/now.cron
rm -rf ~/now.cron
}
installGWD(){
green "========================="
green " de_GWD local IP address"
green "========================="
read localaddr
green "========================="
green " Upstream route IP address"
green "========================="
read gatewayaddr
green "========================="
green " DoH"
green "========================="
read doh1
green "========================="
green " V2ray domain"
green "========================="
read v2servn
green "========================="
green " V2ray UUID"
green "========================="
read uuidnum
green "========================="
green " Path"
green "========================="
read v2path
cd ~
doh2=$doh1
domain=$(echo $v2servn | cut -d: -f1)
port=$(echo $v2servn | cut -d: -f2)
portCheck=$(echo $port | grep '^[0-9]\+$')
if [[ -z $portCheck ]]; then
port="443"
fi
ethernetnum=$(ip --oneline link show up | grep -v "lo" | awk '{print$2;exit}' | cut -d':' -f1 | cut -d'@' -f1)
piholePW="0000000000000000000000000000000000000000000000000000000000000000"
cat << EOF >/etc/network/interfaces
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
auto $ethernetnum
iface $ethernetnum inet static
address $localaddr
netmask 255.255.255.0
gateway $gatewayaddr
EOF
preInstall
installSmartDNS
installDOH
installV2ray
cd ~
wget --no-check-certificate -c https://bgp.space/china.html
sed -i '1,/BEGIN/d' ~/china.html
sed -i '/END/,$d' ~/china.html
sed -i 's/<br>//g' ~/china.html
mv -f ~/china.html /usr/local/bin/IPchnroute
cp -f /usr/local/bin/IPchnroute /usr/local/bin/chnrouteSET
sed -i 's/^/add chnroute &/g' /usr/local/bin/chnrouteSET
sed -i '1i\create chnroute hash:net family inet hashsize 2048 maxelem 65535' /usr/local/bin/chnrouteSET
installIptablesProxy
installDep
installPihole
piholeSet