forked from laoz77/trojan-gfw-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vps.sh
3459 lines (3330 loc) · 115 KB
/
vps.sh
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
#MIT License
#
#Copyright (c) 2019-2020 JohnRosen
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
#Run me with:
#apt-get update && apt-get install sudo curl -y && sudo bash -c "$(curl -fsSL https://raw.githubusercontent.com/johnrosen1/vpstoolbox/master/vps.sh)"
# _ _ _
#__ ___ __ ___| |_ ___ ___ | | |__ _____ __
#\ \ / / '_ \/ __| __/ _ \ / _ \| | '_ \ / _ \ \/ /
# \ V /| |_) \__ \ || (_) | (_) | | |_) | (_) > <
# \_/ | .__/|___/\__\___/ \___/|_|_.__/ \___/_/\_\
# |_|
clear
set +e
if [[ $(id -u) != 0 ]]; then
echo Please run this script as root.
exit 1
fi
if [[ $(uname -m 2> /dev/null) != x86_64 ]]; then
echo Please run this script on x86_64 machine.
exit 1
fi
if [[ $(free -m | grep Mem | awk '{print $2}' 2> /dev/null) -le "480" ]]; then
echo Please run this script on machine with more than 512MB free ram.
exit 1
fi
if [[ $(df $PWD | awk '/[0-9]%/{print $(NF-2)}' 2> /dev/null) -le "3000000" ]]; then
echo Please run this script on machine with more than 3G free disk space.
exit 1
fi
colorEcho(){
set +e
COLOR=$1
echo -e "\033[${COLOR}${@:2}\033[0m"
}
if [[ -f /etc/init.d/aegis ]] || [[ -f /etc/systemd/system/aliyun.service ]]; then
colorEcho ${INFO} "Uninstall Aliyun aegis ing"
echo "" > /etc/motd
iptables -I INPUT -s 140.205.201.0/28 -j DROP
iptables -I INPUT -s 140.205.201.16/29 -j DROP
iptables -I INPUT -s 140.205.201.32/28 -j DROP
iptables -I INPUT -s 140.205.225.192/29 -j DROP
iptables -I INPUT -s 140.205.225.200/30 -j DROP
iptables -I INPUT -s 140.205.225.184/29 -j DROP
iptables -I INPUT -s 140.205.225.183/32 -j DROP
iptables -I INPUT -s 140.205.225.206/32 -j DROP
iptables -I INPUT -s 140.205.225.205/32 -j DROP
iptables -I INPUT -s 140.205.225.195/32 -j DROP
iptables -I INPUT -s 140.205.225.204/32 -j DROP
systemctl stop aegis
systemctl stop CmsGoAgent.service
systemctl stop aliyun
systemctl stop cloud-config
systemctl stop cloud-final
systemctl stop cloud-init-local.service
systemctl stop cloud-init
systemctl stop ecs_mq
systemctl stop exim4
systemctl stop apparmor
systemctl stop sysstat
systemctl disable aegis
systemctl disable CmsGoAgent.service
systemctl disable aliyun
systemctl disable cloud-config
systemctl disable cloud-final
systemctl disable cloud-init-local.service
systemctl disable cloud-init
systemctl disable ecs_mq
systemctl disable exim4
systemctl disable apparmor
systemctl disable sysstat
killall -9 aegis_cli >/dev/null 2>&1
killall -9 aegis_update >/dev/null 2>&1
killall -9 aegis_cli >/dev/null 2>&1
killall -9 AliYunDun >/dev/null 2>&1
killall -9 AliHids >/dev/null 2>&1
killall -9 AliHips >/dev/null 2>&1
killall -9 AliYunDunUpdate >/dev/null 2>&1
rm -rf /etc/init.d/aegis
rm -rf /etc/systemd/system/CmsGoAgent*
rm -rf /etc/systemd/system/aliyun*
rm -rf /lib/systemd/system/cloud*
rm -rf /lib/systemd/system/ecs_mq*
rm -rf /usr/local/aegis
rm -rf /usr/local/cloudmonitor
rm -rf /usr/sbin/aliyun_installer
rm -rf /usr/sbin/aliyun-service
rm -rf /usr/sbin/aliyun-service.backup
rm -rf /sbin/ecs_mq_rps_rfs
for ((var=2; var<=5; var++)) do
if [ -d "/etc/rc${var}.d/" ];then
rm -rf "/etc/rc${var}.d/S80aegis"
elif [ -d "/etc/rc.d/rc${var}.d" ];then
rm -rf "/etc/rc.d/rc${var}.d/S80aegis"
fi
done
apt-get purge sysstat exim4 chrony aliyun-assist telnet -y
systemctl daemon-reload
if [[ $(lsb_release -cs) == stretch ]]; then
cat > '/etc/apt/sources.list' << EOF
#------------------------------------------------------------------------------#
# OFFICIAL DEBIAN REPOS
#------------------------------------------------------------------------------#
###### Debian Main Repos
deb http://deb.debian.org/debian/ oldstable main contrib non-free
deb-src http://deb.debian.org/debian/ oldstable main contrib non-free
deb http://deb.debian.org/debian/ oldstable-updates main contrib non-free
deb-src http://deb.debian.org/debian/ oldstable-updates main contrib non-free
deb http://deb.debian.org/debian-security oldstable/updates main
deb-src http://deb.debian.org/debian-security oldstable/updates main
deb http://ftp.debian.org/debian stretch-backports main
deb-src http://ftp.debian.org/debian stretch-backports main
EOF
fi
if [[ $(lsb_release -cs) == bionic ]]; then
cat > '/etc/apt/sources.list' << EOF
#------------------------------------------------------------------------------#
# OFFICIAL UBUNTU REPOS #
#------------------------------------------------------------------------------#
###### Ubuntu Main Repos
deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
###### Ubuntu Update Repos
deb http://us.archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse
EOF
echo "nameserver 1.1.1.1" > '/etc/resolv.conf'
fi
fi
#######color code############
ERROR="31m" # Error message
SUCCESS="32m" # Success message
WARNING="33m" # Warning message
INFO="36m" # Info message
LINK="92m" # Share Link Message
#############################
cipher_server="ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384"
cipher_client="ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:AES128-SHA:AES256-SHA:DES-CBC3-SHA"
#############################
systeminfo(){
neofetch
#colorEcho ${INFO} "System Info"
#olorEcho ${INFO} "1. CPU INFO"
#colorEcho ${INFO} "model name: $( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' )"
#colorEcho ${INFO} "cpu cores: $( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo ) core(s)"
#colorEcho ${INFO} "cpu freqency: $( awk -F'[ :]' '/cpu MHz/ {print $4;exit}' /proc/cpuinfo ) MHz"
#colorEcho ${INFO} "2. RAM INFO"
#colorEcho ${INFO} "Total ram: $( free -m | awk '/Mem/ {print $2}' ) MB"
#colorEcho ${INFO} "3. DISK INFO"
#colorEcho ${INFO} "Total disk space: $( df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem|udev|docker' | awk '{print $2}' )"
#colorEcho ${INFO} "4. OS INFO"
#colorEcho ${INFO} "${dist}"
echo -e "-------------------------------System Information----------------------------"
echo -e "Hostname:\t\t"`hostname`
echo -e "uptime:\t\t\t"`uptime | awk '{print $3,$4}' | sed 's/,//'`
echo -e "Manufacturer:\t\t"`cat /sys/class/dmi/id/chassis_vendor`
echo -e "Product Name:\t\t"`cat /sys/class/dmi/id/product_name`
echo -e "Version:\t\t"`cat /sys/class/dmi/id/product_version`
echo -e "Serial Number:\t\t"`cat /sys/class/dmi/id/product_serial`
echo -e "Machine Type:\t\t"`vserver=$(lscpu | grep Hypervisor | wc -l); if [ $vserver -gt 0 ]; then echo "VM"; else echo "Physical"; fi`
echo -e "Operating System:\t"`hostnamectl | grep "Operating System" | cut -d ' ' -f5-`
echo -e "Kernel:\t\t\t"`uname -r`
echo -e "Architecture:\t\t"`arch`
echo -e "Processor Name:\t\t"`awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//'`
echo -e "Active User:\t\t"`w | cut -d ' ' -f1 | grep -v USER | xargs -n1`
echo -e "System Main IP:\t\t"`hostname -I`
echo -e "-----------------------------------------------------------------------------"
echo -e "-------------------------------IP Information----------------------------"
echo -e "ip:\t\t"`jq -r '.ip' "/root/.trojan/ip.json"`
echo -e "city:\t\t"`jq -r '.city' "/root/.trojan/ip.json"`
echo -e "region:\t\t"`jq -r '.region' "/root/.trojan/ip.json"`
echo -e "country:\t"`jq -r '.country' "/root/.trojan/ip.json"`
echo -e "loc:\t\t"`jq -r '.loc' "/root/.trojan/ip.json"`
echo -e "org:\t\t"`jq -r '.org' "/root/.trojan/ip.json"`
echo -e "postal:\t\t"`jq -r '.postal' "/root/.trojan/ip.json"`
echo -e "timezone:\t"`jq -r '.timezone' "/root/.trojan/ip.json"`
echo -e "-----------------------------------------------------------------------------"
if [[ -f /root/.trojan/ipv6.json ]]; then
echo -e "-------------------------------IPv6 Information----------------------------"
echo -e "ip:\t\t"$(jq -r '.ip' "/root/.trojan/ipv6.json")
echo -e "city:\t\t"$(jq -r '.city' "/root/.trojan/ipv6.json")
echo -e "region:\t\t"$(jq -r '.region' "/root/.trojan/ipv6.json")
echo -e "country:\t"$(jq -r '.country' "/root/.trojan/ipv6.json")
echo -e "loc:\t\t"$(jq -r '.loc' "/root/.trojan/ipv6.json")
echo -e "org:\t\t"$(jq -r '.org' "/root/.trojan/ipv6.json")
echo -e "postal:\t\t"$(jq -r '.postal' "/root/.trojan/ipv6.json")
echo -e "timezone:\t"$(jq -r '.timezone' "/root/.trojan/ipv6.json")
fi
}
#############################
setlanguage(){
set +e
if [[ ! -d /root/.trojan/ ]]; then
mkdir /root/.trojan/
fi
if [[ -f /root/.trojan/language.json ]]; then
language="$( jq -r '.language' "/root/.trojan/language.json" )"
fi
while [[ -z $language ]]; do
export LANGUAGE="C.UTF-8"
export LANG="C.UTF-8"
export LC_ALL="C.UTF-8"
if (whiptail --title "System Language Setting" --yes-button "中文" --no-button "English" --yesno "使用中文或英文(Use Chinese or English)?" 8 78); then
chattr -i /etc/locale.gen
cat > '/etc/locale.gen' << EOF
zh_TW.UTF-8 UTF-8
en_US.UTF-8 UTF-8
EOF
language="cn"
locale-gen
update-locale
chattr -i /etc/default/locale
cat > '/etc/default/locale' << EOF
LANGUAGE="zh_TW.UTF-8"
LANG="zh_TW.UTF-8"
LC_ALL="zh_TW.UTF-8"
EOF
apt-get install manpages-zh -y
cat > '/root/.trojan/language.json' << EOF
{
"language": "$language"
}
EOF
else
chattr -i /etc/locale.gen
cat > '/etc/locale.gen' << EOF
zh_TW.UTF-8 UTF-8
en_US.UTF-8 UTF-8
EOF
language="en"
locale-gen
update-locale
chattr -i /etc/default/locale
cat > '/etc/default/locale' << EOF
LANGUAGE="en_US.UTF-8"
LANG="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
EOF
cat > '/root/.trojan/language.json' << EOF
{
"language": "$language"
}
EOF
fi
done
if [[ $language == "cn" ]]; then
export LANGUAGE="zh_TW.UTF-8"
export LANG="zh_TW.UTF-8"
export LC_ALL="zh_TW.UTF-8"
else
export LANGUAGE="en_US.UTF-8"
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
fi
}
#############################
installacme(){
set +e
curl -s https://get.acme.sh | sh
if [[ $? != 0 ]]; then
colorEcho ${ERROR} "Install acme.sh fail,please check your internet availability!!!"
exit 1
fi
~/.acme.sh/acme.sh --upgrade --auto-upgrade
}
#########Domain resolve verification###################
isresolved(){
if [ $# = 2 ]
then
myip2=$2
else
myip2=`curl -s http://dynamicdns.park-your-domain.com/getip`
fi
ips=(`nslookup $1 1.1.1.1 | grep -v 1.1.1.1 | grep Address | cut -d " " -f 2`)
for ip in "${ips[@]}"
do
if [ $ip == $myip ] || [ $ip == $myipv6 ] || [[ $ip == $localip ]]
then
return 0
else
continue
fi
done
return 1
}
########################################################
issuecert(){
set +e
clear
colorEcho ${INFO} "申请(issuing) let\'s encrypt certificate"
if [[ -f /root/.acme.sh/${domain}_ecc/fullchain.cer ]] && [[ -f /root/.acme.sh/${domain}_ecc/${domain}.key ]] || [[ ${othercert} == 1 ]]; then
TERM=ansi whiptail --title "证书已有,跳过申请" --infobox "证书已有,跳过申请。。。" 8 78
else
rm -rf /etc/nginx/sites-available/* &
rm -rf /etc/nginx/sites-enabled/* &
rm -rf /etc/nginx/conf.d/*
touch /etc/nginx/conf.d/default.conf
cat > '/etc/nginx/conf.d/default.conf' << EOF
server {
listen 80;
listen [::]:80;
server_name $domain;
root /usr/share/nginx/html;
}
EOF
nginx -t
systemctl start nginx
installacme
clear
colorEcho ${INFO} "测试证书申请ing(test issuing) let\'s encrypt certificate"
~/.acme.sh/acme.sh --issue --nginx -d $domain -k ec-256 --force --test --log --reloadcmd "systemctl reload trojan || true && nginx -s reload"
if [[ $? != 0 ]]; then
colorEcho ${ERROR} "证书申请测试失败,请检查VPS控制面板防火墙(80 443)是否打开!!!"
colorEcho ${ERROR} "请访问https://letsencrypt.status.io/检测Let's encrypt服务是否正常!!!"
colorEcho ${ERROR} "Domain verification fail,Pleae Open port 80 443 on VPS panel !!!"
exit 1
fi
clear
colorEcho ${INFO} "正式证书申请ing(issuing) let\'s encrypt certificate"
~/.acme.sh/acme.sh --issue --nginx -d $domain -k ec-256 --force --log --reloadcmd "systemctl reload trojan || true && nginx -s reload"
if [[ $? != 0 ]]; then
colorEcho ${ERROR} "证书申请测试失败,请检查VPS控制面板防火墙(80 443)是否打开!!!"
colorEcho ${ERROR} "请访问https://letsencrypt.status.io/检测Let's encrypt服务是否正常!!!"
colorEcho ${ERROR} "Domain verification fail,Pleae Open port 80 443 on VPS panel !!!"
exit 1
fi
chmod +r /root/.acme.sh/${domain}_ecc/fullchain.cer
chmod +r /root/.acme.sh/${domain}_ecc/${domain}.key
fi
}
###############User input################
prasejson(){
set +e
cat > '/root/.trojan/config.json' << EOF
{
"installed": "1",
"domain": "$domain",
"password1": "$password1",
"password2": "$password2",
"qbtpath": "$qbtpath",
"trackerpath": "$trackerpath",
"trackerstatuspath": "$trackerstatuspath",
"ariapath": "$ariapath",
"ariapasswd": "$ariapasswd",
"filepath": "$filepath",
"netdatapath": "$netdatapath",
"tor_name": "$tor_name"
}
EOF
}
################################################
readconfig(){
domain="$( jq -r '.domain' "/root/.trojan/config.json" )"
password1="$( jq -r '.password1' "/root/.trojan/config.json" )"
password2="$( jq -r '.password2' "/root/.trojan/config.json" )"
qbtpath="$( jq -r '.qbtpath' "/root/.trojan/config.json" )"
trackerpath="$( jq -r '.trackerpath' "/root/.trojan/config.json" )"
trackerstatuspath="$( jq -r '.username' "/root/.trojan/config.json" )"
ariapath="$( jq -r '.ariapath' "/root/.trojan/config.json" )"
ariapasswd="$( jq -r '.ariapasswd' "/root/.trojan/config.json" )"
filepath="$( jq -r '.filepath' "/root/.trojan/config.json" )"
netdatapath="$( jq -r '.netdatapath' "/root/.trojan/config.json" )"
tor_name="$( jq -r '.tor_name' "/root/.trojan/config.json" )"
}
####################################
userinput(){
set +e
if [ ! -f /root/.trojan/config.json ]; then
cat > '/root/.trojan/config.json' << EOF
{
"installed": "0"
}
EOF
fi
install_status="$( jq -r '.installed' "/root/.trojan/config.json" )"
clear
if [[ ${install_status} == 1 ]]; then
whiptail --title "Installed" --msgbox "Installed,reading configuration" 8 78
readconfig
fi
whiptail --clear --ok-button "吾意已決 立即執行" --backtitle "Hi , Please choose carefully!" --title "User choice" --checklist --separate-output --nocancel "Please press space to choose carefully !!!" 24 52 16 \
"Back" "返回上级菜单(Back to main menu)" off \
"系统" "System" on \
"1" "System Upgrade" on \
"2" "Enable BBR(TCP-Turbo)" on \
"3" "Docker" on \
"代理" "Proxy" on \
"4" "Trojan-GFW" on \
"5" "Dnscrypt-proxy(Dns encryption)" on \
"下载" "Download" on \
"6" "Qbittorrent(Bittorrent Client)" off \
"7" "Bt-Tracker(Node.js Version)" on \
"8" "Aria2" on \
"9" "Filebrowser(File manager)" on \
"状态" "Status" on \
"10" "Netdata(Server status monitor)" on \
"测速" "Speedtest" on \
"11" "Speedtest(Docker Version)" on \
"数据库" "Database" on \
"12" "MariaDB" on \
"其他" "Others" on \
"13" "OPENSSL" off \
"14" "Tor-Relay" off \
"15" "Enable TLS1.3 only" off 2>results
while read choice
do
case $choice in
Back)
advancedMenu
break
;;
1)
system_upgrade=1
;;
2)
install_bbr=1
;;
3)
install_docker=1
;;
4)
install_trojan=1
;;
5)
dnsmasq_install=1
;;
6)
install_qbt=1
;;
7)
install_tracker=1
;;
8)
install_aria=1
;;
9)
install_file=1
;;
10)
install_netdata=1
;;
11)
install_speedtest=1
;;
12)
install_mariadb=1
;;
13)
install_openssl=1
;;
14)
install_tor=1
;;
15)
tls13only=1
;;
*)
;;
esac
done < results
####################################
if [[ ${system_upgrade} == 1 ]]; then
if [[ $(lsb_release -cs) == stretch ]]; then
if (whiptail --title "System Upgrade" --yesno "Upgrade to Debian 10?" 8 78); then
debian10_install=1
fi
fi
if [[ $(lsb_release -cs) == jessie ]]; then
if (whiptail --title "System Upgrade" --yesno "Upgrade to Debian 9?" 8 78); then
debian9_install=1
fi
fi
if [[ $(lsb_release -cs) == xenial ]]; then
if (whiptail --title "System Upgrade" --yesno "Upgrade to Ubuntu 18.04?" 8 78); then
ubuntu18_install=1
fi
fi
fi
#####################################
while [[ -z ${domain} ]]; do
domain=$(whiptail --inputbox --nocancel "Please enter your domain(请輸入你的域名)(请先完成A/AAAA解析 https://dnschecker.org/)" 8 78 --title "Domain input" 3>&1 1>&2 2>&3)
done
hostnamectl set-hostname $domain
if grep -q "${domain}" /etc/hosts
then
:
else
echo "" >> /etc/hosts
echo "${myip} ${domain}" >> /etc/hosts
fi
if [[ ${install_trojan} = 1 ]]; then
while [[ -z ${password1} ]]; do
password1=$(whiptail --passwordbox --nocancel "Trojan-GFW Password One(若不確定,請直接回車,会随机生成)" 8 78 --title "password1 input" 3>&1 1>&2 2>&3)
if [[ -z ${password1} ]]; then
password1=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 10 ; echo '' )
fi
done
while [[ -z ${password2} ]]; do
password2=$(whiptail --passwordbox --nocancel "Trojan-GFW Password Two(若不確定,請直接回車,会随机生成)" 8 78 --title "password2 input" 3>&1 1>&2 2>&3)
if [[ -z ${password2} ]]; then
password2=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 10 ; echo '' )
fi
done
fi
###################################
if [[ $install_qbt = 1 ]]; then
while [[ -z $qbtpath ]]; do
qbtpath=$(whiptail --inputbox --nocancel "Qbittorrent Path(路径)" 8 78 /${password1}_qbt/ --title "Qbittorrent path input" 3>&1 1>&2 2>&3)
done
fi
#####################################
if [[ $install_tracker == 1 ]]; then
while [[ -z ${trackerpath} ]]; do
trackerpath=$(whiptail --inputbox --nocancel "Bittorrent-Tracker Path(路径)" 8 78 /announce --title "Bittorrent-Tracker path input" 3>&1 1>&2 2>&3)
done
while [[ -z ${trackerstatuspath} ]]; do
trackerstatuspath=$(whiptail --inputbox --nocancel "Bittorrent-Tracker Status Path(状态路径)" 8 78 /${password1}_tracker --title "Bittorrent-Tracker status path input" 3>&1 1>&2 2>&3)
done
fi
####################################
if [[ ${install_aria} == 1 ]]; then
ariaport=$(shuf -i 10000-19000 -n 1)
while [[ -z ${ariapath} ]]; do
ariapath=$(whiptail --inputbox --nocancel "Aria2 RPC Path(路径)" 8 78 /${password1}_aria2/ --title "Aria2 path input" 3>&1 1>&2 2>&3)
done
while [[ -z $ariapasswd ]]; do
ariapasswd=$(whiptail --passwordbox --nocancel "Aria2 rpc token(密码)" 8 78 --title "Aria2 rpc token input" 3>&1 1>&2 2>&3)
if [[ -z ${ariapasswd} ]]; then
ariapasswd=$(head /dev/urandom | tr -dc 0-9 | head -c 10 ; echo '' )
fi
done
fi
####################################
if [[ ${install_file} = 1 ]]; then
while [[ -z ${filepath} ]]; do
filepath=$(whiptail --inputbox --nocancel "Filebrowser路径" 8 78 /${password1}_file/ --title "Filebrowser path input" 3>&1 1>&2 2>&3)
done
fi
####################################
if [[ ${install_netdata} = 1 ]]; then
while [[ -z ${netdatapath} ]]; do
netdatapath=$(whiptail --inputbox --nocancel "Netdata路径" 8 78 /${password1}_netdata/ --title "Netdata path input" 3>&1 1>&2 2>&3)
done
fi
####################################
if [[ ${install_tor} = 1 ]]; then
while [[ -z ${tor_name} ]]; do
tor_name=$(whiptail --inputbox --nocancel "Tor nickname" 8 78 --title "tor nickname input" 3>&1 1>&2 2>&3)
if [[ -z ${tor_name} ]]; then
tor_name="myrelay"
fi
done
fi
####################################
if [[ -f /etc/trojan/trojan.crt ]] && [[ -f /etc/trojan/trojan.key ]] && [[ -n /etc/trojan/trojan.crt ]] || [[ -f /root/.acme.sh/${domain}_ecc/fullchain.cer ]]; then
TERM=ansi whiptail --title "证书已有,跳过申请" --infobox "证书已有,跳过申请。。。" 8 78
else
if (whiptail --title "api" --yesno "使用 (use) api申请证书(to issue certificate)?" 8 78); then
dns_api=1
APIOPTION=$(whiptail --nocancel --clear --ok-button "吾意已決 立即執行" --title "API choose" --menu --separate-output "域名(domain)API:請按方向键來選擇(Use Arrow key to choose)" 15 78 6 \
"1" "Cloudflare" \
"2" "Namesilo" \
"3" "Aliyun" \
"4" "DNSPod.cn" \
"5" "CloudXNS.com" \
"back" "返回" 3>&1 1>&2 2>&3)
case $APIOPTION in
1)
while [[ -z ${CF_Key} ]] || [[ -z ${CF_Email} ]]; do
CF_Key=$(whiptail --passwordbox --nocancel "https://dash.cloudflare.com/profile/api-tokens,快輸入你CF Global Key併按回車" 8 78 --title "CF_Key input" 3>&1 1>&2 2>&3)
CF_Email=$(whiptail --inputbox --nocancel "https://dash.cloudflare.com/profile,快輸入你CF_Email併按回車" 8 78 --title "CF_Key input" 3>&1 1>&2 2>&3)
done
export CF_Key="$CF_Key"
export CF_Email="$CF_Email"
installacme
~/.acme.sh/acme.sh --issue --dns dns_cf -d $domain -k ec-256 --force --log --reloadcmd "systemctl reload trojan || true && nginx -s reload || true"
;;
2)
while [[ -z $Namesilo_Key ]]; do
Namesilo_Key=$(whiptail --passwordbox --nocancel "https://www.namesilo.com/account_api.php,快輸入你的Namesilo_Key併按回車" 8 78 --title "Namesilo_Key input" 3>&1 1>&2 2>&3)
done
export Namesilo_Key="$Namesilo_Key"
installacme
~/.acme.sh/acme.sh --issue --dns dns_namesilo --dnssleep 900 -d $domain -k ec-256 --force --log --reloadcmd "systemctl reload trojan || true && nginx -s reload || true"
;;
3)
while [[ -z $Ali_Key ]] || [[ -z $Ali_Secret ]]; do
Ali_Key=$(whiptail --passwordbox --nocancel "https://ak-console.aliyun.com/#/accesskey,快輸入你的Ali_Key併按回車" 8 78 --title "Ali_Key input" 3>&1 1>&2 2>&3)
Ali_Secret=$(whiptail --passwordbox --nocancel "https://ak-console.aliyun.com/#/accesskey,快輸入你的Ali_Secret併按回車" 8 78 --title "Ali_Secret input" 3>&1 1>&2 2>&3)
done
export Ali_Key="$Ali_Key"
export Ali_Secret="$Ali_Secret"
installacme
~/.acme.sh/acme.sh --issue --dns dns_ali -d $domain -k ec-256 --force --log --reloadcmd "systemctl reload trojan || true && nginx -s reload || true"
;;
4)
while [[ -z $DP_Id ]] || [[ -z $DP_Key ]]; do
DP_Id=$(whiptail --passwordbox --nocancel "DNSPod.cn,快輸入你的DP_Id併按回車" 8 78 --title "DP_Id input" 3>&1 1>&2 2>&3)
DP_Key=$(whiptail --passwordbox --nocancel "DNSPod.cn,快輸入你的DP_Key併按回車" 8 78 --title "DP_Key input" 3>&1 1>&2 2>&3)
done
export DP_Id="$DP_Id"
export DP_Key="$DP_Key"
installacme
~/.acme.sh/acme.sh --issue --dns dns_dp -d $domain -k ec-256 --force --log --reloadcmd "systemctl reload trojan || true && nginx -s reload || true"
;;
5)
while [[ -z $CX_Key ]] || [[ -z $CX_Secret ]]; do
CX_Key=$(whiptail --passwordbox --nocancel "CloudXNS.com,快輸入你的CX_Key併按回車" 8 78 --title "CX_Key input" 3>&1 1>&2 2>&3)
CX_Secret=$(whiptail --passwordbox --nocancel "CloudXNS.com,快輸入你的CX_Secret併按回車" 8 78 --title "CX_Secret input" 3>&1 1>&2 2>&3)
done
export CX_Key="$CX_Key"
export CX_Secret="$CX_Secret"
installacme
~/.acme.sh/acme.sh --issue --dns dns_cx -d $domain -k ec-256 --force --log --reloadcmd "systemctl reload trojan || true && nginx -s reload || true"
;;
back)
userinput
break
;;
*)
;;
esac
if [[ $? != 0 ]]; then
colorEcho ${ERROR} "证书申请失败,请检查域名是否正确"
colorEcho ${ERROR} "certificate issue fail,Pleae enter correct domain"
exit 1
fi
fi
fi
}
###############OS detect####################
osdist(){
set +e
colorEcho ${INFO} "初始化中(initializing)"
if cat /etc/*release | grep ^NAME | grep -q Ubuntu; then
dist=ubuntu
pack="apt-get -y -q"
apt-get update -q
export DEBIAN_FRONTEND=noninteractive
apt-get install whiptail curl locales lsb-release jq lsof neofetch -y -q
elif cat /etc/*release | grep ^NAME | grep -q Debian; then
dist=debian
pack="apt-get -y -q"
apt-get update -q
export DEBIAN_FRONTEND=noninteractive
apt-get install whiptail curl locales lsb-release jq lsof neofetch -y -q
else
TERM=ansi whiptail --title "OS not SUPPORTED" --infobox "OS NOT SUPPORTED!" 8 78
exit 1;
fi
}
##############Upgrade system optional########
upgradesystem(){
set +e
if [[ $dist == ubuntu ]]; then
export UBUNTU_FRONTEND=noninteractive
if [[ $ubuntu18_install == 1 ]]; then
cat > '/etc/apt/sources.list' << EOF
#------------------------------------------------------------------------------#
# OFFICIAL UBUNTU REPOS #
#------------------------------------------------------------------------------#
###### Ubuntu Main Repos
deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
###### Ubuntu Update Repos
deb http://us.archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse
EOF
fi
apt-get update --fix-missing
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get upgrade -q -y'
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -q -y'
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -q -y'
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt --fix-broken install -y'
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get autoremove -qq -y'
clear
elif [[ $dist == debian ]]; then
export DEBIAN_FRONTEND=noninteractive
apt-get update --fix-missing
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get upgrade -q -y'
if [[ ${debian10_install} == 1 ]]; then
cat > '/etc/apt/sources.list' << EOF
#------------------------------------------------------------------------------#
# OFFICIAL DEBIAN REPOS
#------------------------------------------------------------------------------#
###### Debian Main Repos
deb http://deb.debian.org/debian/ stable main contrib non-free
deb-src http://deb.debian.org/debian/ stable main contrib non-free
deb http://deb.debian.org/debian/ stable-updates main contrib non-free
deb-src http://deb.debian.org/debian/ stable-updates main contrib non-free
deb http://deb.debian.org/debian-security stable/updates main
deb-src http://deb.debian.org/debian-security stable/updates main
deb http://ftp.debian.org/debian buster-backports main
deb-src http://ftp.debian.org/debian buster-backports main
EOF
fi
if [[ ${debian9_install} == 1 ]]; then
cat > '/etc/apt/sources.list' << EOF
#------------------------------------------------------------------------------#
# OFFICIAL DEBIAN REPOS
#------------------------------------------------------------------------------#
###### Debian Main Repos
deb http://deb.debian.org/debian/ oldstable main contrib non-free
deb-src http://deb.debian.org/debian/ oldstable main contrib non-free
deb http://deb.debian.org/debian/ oldstable-updates main contrib non-free
deb-src http://deb.debian.org/debian/ oldstable-updates main contrib non-free
deb http://deb.debian.org/debian-security oldstable/updates main
deb-src http://deb.debian.org/debian-security oldstable/updates main
deb http://ftp.debian.org/debian stretch-backports main
deb-src http://ftp.debian.org/debian stretch-backports main
EOF
fi
apt-get update --fix-missing
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get upgrade -q -y'
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -q -y'
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -q -y'
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt --fix-broken install -y'
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get autoremove -qq -y'
clear
else
clear
TERM=ansi whiptail --title "error can't upgrade system" --infobox "error can't upgrade system" 8 78
exit 1;
fi
}
#############Install NGINX################
installnginx(){
if [[ ! -f /etc/apt/sources.list.d/nginx.list ]]; then
clear
colorEcho ${INFO} "Install Nginx ing"
curl -LO --progress-bar https://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key
rm -rf nginx_signing.key
touch /etc/apt/sources.list.d/nginx.list
cat > '/etc/apt/sources.list.d/nginx.list' << EOF
deb https://nginx.org/packages/mainline/$dist/ $(lsb_release -cs) nginx
deb-src https://nginx.org/packages/mainline/$dist/ $(lsb_release -cs) nginx
EOF
apt-get purge nginx -qq -y
apt-get update -q
apt-get install nginx -q -y
fi
cat > '/lib/systemd/system/nginx.service' << EOF
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT \$MAINPID
PrivateTmp=true
LimitNOFILE=51200
LimitNPROC=51200
Restart=on-failure
RestartSec=3s
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable nginx
cat > '/etc/nginx/nginx.conf' << EOF
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 51200;
use epoll;
multi_accept on;
}
http {
proxy_intercept_errors on;
proxy_socket_keepalive on;
proxy_http_version 1.1;
http2_push_preload on;
aio threads;
charset UTF-8;
tcp_nodelay on;
tcp_nopush on;
server_tokens off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status $body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
sendfile on;
gzip on;
gzip_proxied any;
gzip_types *;
gzip_comp_level 9;
include /etc/nginx/conf.d/*.conf;
}
EOF
clear
}
#########Open ports########################
openfirewall(){
set +e
colorEcho ${INFO} "设置 firewall"
#policy
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
ip6tables -P INPUT ACCEPT
ip6tables -P FORWARD ACCEPT
ip6tables -P OUTPUT ACCEPT
#flash
iptables -F
ip6tables -F
#block
iptables -I INPUT -s 36.110.236.68/16 -j DROP
iptables -I INPUT -s 114.114.112.0/21 -j DROP
iptables -I INPUT -s 1.2.4.0/24 -j DROP
iptables -I OUTPUT -d 36.110.236.68/16 -j DROP
iptables -I OUTPUT -d 114.114.112.0/21 -j DROP
iptables -I OUTPUT -d 1.2.4.0/24 -j DROP
iptables -I OUTPUT -p tcp -m tcp --dport 5222 -j DROP
iptables -I OUTPUT -p udp -m udp --dport 5222 -j DROP
iptables -I OUTPUT -p tcp -m tcp --dport 1723 -j DROP
iptables -I OUTPUT -p udp -m udp --dport 1723 -j DROP
iptables -I OUTPUT -p tcp -m tcp --dport 1701 -j DROP
iptables -I OUTPUT -p udp -m udp --dport 1701 -j DROP
iptables -I OUTPUT -p tcp -m tcp --dport 500 -j DROP
iptables -I OUTPUT -p udp -m udp --dport 500 -j DROP
#keep connected
iptables -A INPUT -p tcp -m tcp --tcp-flags ALL FIN,PSH,URG -j DROP
iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
iptables -A INPUT -p tcp -m conntrack --ctstate NEW -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -j DROP
iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
ip6tables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
#icmp
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
ip6tables -A INPUT -p icmpv6 --icmpv6-type echo-request -j ACCEPT
ip6tables -A OUTPUT -p icmpv6 --icmpv6-type echo-reply -j ACCEPT
#iptables -m owner --uid-owner trojan -A OUTPUT -d 127.0.0.0/8 -j REJECT
#iptables -m owner --uid-owner trojan -A OUTPUT -d 192.168.0.0/16 -j REJECT
#iptables -m owner --uid-owner trojan -A OUTPUT -d 10.0.0.0/8 -j REJECT
#iptables -m owner --uid-owner trojan -A OUTPUT --dport 53 -j ACCEPT
#iptables -m owner --uid-owner trojan -A OUTPUT -d 127.0.0.0/8 --dport 80 -j ACCEPT
#iptables -m owner --uid-owner trojan -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#tcp
iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
#udp
iptables -A INPUT -p udp -m udp --dport 443 -j ACCEPT
iptables -A INPUT -p udp -m udp --dport 80 -j ACCEPT
iptables -A OUTPUT -j ACCEPT
#iptables -I FORWARD -j DROP
#tcp6
ip6tables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT
ip6tables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
#udp6
ip6tables -A INPUT -p udp -m udp --dport 443 -j ACCEPT
ip6tables -A INPUT -p udp -m udp --dport 80 -j ACCEPT
ip6tables -A OUTPUT -j ACCEPT
#ip6tables -I FORWARD -j DROP
if [[ $install_qbt == 1 ]]; then
iptables -A INPUT -p tcp -m tcp --dport 8999 -j ACCEPT
ip6tables -A INPUT -p tcp -m tcp --dport 8999 -j ACCEPT
iptables -A INPUT -p udp -m udp --dport 8999 -j ACCEPT
ip6tables -A INPUT -p udp -m udp --dport 8999 -j ACCEPT
fi
if [[ $install_tracker == 1 ]]; then
iptables -A INPUT -p tcp -m tcp --dport 8000 -j ACCEPT
ip6tables -A INPUT -p tcp -m tcp --dport 8000 -j ACCEPT
iptables -A INPUT -p udp -m udp --dport 8000 -j ACCEPT
ip6tables -A INPUT -p udp -m udp --dport 8000 -j ACCEPT
fi
if [[ $install_aria == 1 ]]; then
iptables -A INPUT -p tcp -m tcp --dport ${ariaport} -j ACCEPT
ip6tables -A INPUT -p tcp -m tcp --dport ${ariaport} -j ACCEPT
iptables -A INPUT -p udp -m udp --dport ${ariaport} -j ACCEPT
ip6tables -A INPUT -p udp -m udp --dport ${ariaport} -j ACCEPT
fi
if [[ $dist == debian ]]; then
export DEBIAN_FRONTEND=noninteractive
apt-get install iptables-persistent -qq -y > /dev/null
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6
elif [[ $dist == ubuntu ]]; then
export DEBIAN_FRONTEND=noninteractive
ufw allow http
ufw allow https
ufw allow ${ariaport}
apt-get install iptables-persistent -qq -y > /dev/null
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6
else
clear
TERM=ansi whiptail --title "error can't install iptables-persistent" --infobox "error can't install iptables-persistent" 8 78
exit 1;
fi
}
##########install dependencies#############
installdependency(){
set +e
colorEcho ${INFO} "Updating system"
$pack update
if [[ $install_status == 0 ]]; then
if [ -f /etc/trojan/*.crt ]; then
othercert=1
mv /etc/trojan/*.crt /etc/trojan/trojan.crt
fi
if [ -f /etc/trojan/*.key ]; then
mv /etc/trojan/*.key /etc/trojan/trojan.key
fi
if [[ $(systemctl is-active caddy) == active ]]; then
systemctl stop caddy
systemctl disable caddy
fi
if [[ $(systemctl is-active apache2) == active ]]; then
systemctl stop apache2
systemctl disable apache2
fi
if [[ $(systemctl is-active httpd) == active ]]; then
systemctl stop httpd
systemctl disable httpd
fi
(echo >/dev/tcp/localhost/80) &>/dev/null && echo "TCP port 80 open" && kill $(lsof -t -i:80) || echo "Moving on"
(echo >/dev/tcp/localhost/80) &>/dev/null && echo "TCP port 443 open" && kill $(lsof -t -i:443) || echo "Moving on"
fi
###########################################
if [[ $system_upgrade = 1 ]]; then
upgradesystem
fi
###########################################
if [[ $install_bbr == 1 ]]; then
colorEcho ${INFO} "Enabling TCP-BBR boost"
#iii=$(ip link | awk -F: '$0 !~ "lo|vir|wl|^[^0-9]"{print $2;getline}' | cut -c2-999)
cat > '/etc/sysctl.d/99-sysctl.conf' << EOF
#!!! Do not change these settings unless you know what you are doing !!!