-
Notifications
You must be signed in to change notification settings - Fork 56
/
naiveproxy.sh
714 lines (714 loc) · 29.2 KB
/
naiveproxy.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
#!/bin/bash
export LANG=en_US.UTF-8
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
blue='\033[0;36m'
bblue='\033[0;34m'
plain='\033[0m'
red(){ echo -e "\033[31m\033[01m$1\033[0m";}
green(){ echo -e "\033[32m\033[01m$1\033[0m";}
yellow(){ echo -e "\033[33m\033[01m$1\033[0m";}
blue(){ echo -e "\033[36m\033[01m$1\033[0m";}
white(){ echo -e "\033[37m\033[01m$1\033[0m";}
readp(){ read -p "$(yellow "$1")" $2;}
[[ $EUID -ne 0 ]] && yellow "Please run the script in root mode" && exit
#[[ -e /etc/hosts ]] && grep -qE '^ *172.65.251.78 gitlab.com' /etc/hosts || echo -e '\n172.65.251.78 gitlab.com' >> /etc/hosts
if [[ -f /etc/redhat-release ]]; then
release="Centos"
elif cat /etc/issue | grep -q -E -i "debian"; then
release="Debian"
elif cat /etc/issue | grep -q -E -i "ubuntu"; then
release="Ubuntu"
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
release="Centos"
elif cat /proc/version | grep -q -E -i "debian"; then
release="Debian"
elif cat /proc/version | grep -q -E -i "ubuntu"; then
release="Ubuntu"
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
release="Centos"
else
red "The script does not support the current system, please choose to use Ubuntu, Debian, Centos system." && exit
fi
vsid=$(grep -i version_id /etc/os-release | cut -d \" -f2 | cut -d . -f1)
op=$(cat /etc/redhat-release 2>/dev/null || cat /etc/os-release 2>/dev/null | grep -i pretty_name | cut -d \" -f2)
if [[ $(echo "$op" | grep -i -E "arch|alpine") ]]; then
red "The script does not support the current $op system, please choose to use Ubuntu, Debian, Centos system." && exit
fi
latcore=v`curl -Ls https://data.jsdelivr.com/v1/package/gh/klzgrad/naiveproxy | sed -n 4p | tr -d ',"' | awk '{print $1}'`
inscore=`cat /etc/caddy/version 2>/dev/null | head -n 1`
insV=$(cat /etc/caddy/v 2>/dev/null)
latestV=$(curl -sL https://gitlab.com/rwkgyg/naiveproxy-yg/-/raw/main/version | awk -F "update content" 'NR>2 {print $1; exit}')
version=$(uname -r | cut -d "-" -f1)
vi=$(systemd-detect-virt 2>/dev/null)
bit=$(uname -m)
if [[ $bit = x86_64 ]]; then
cpu=amd64
elif [[ $bit = aarch64 ]]; then
cpu=arm64
else
red "Currently the script does not support the $bit architecture" && exit
fi
if [[ -n $(sysctl net.ipv4.tcp_congestion_control 2>/dev/null | awk -F ' ' '{print $3}') ]]; then
bbr=`sysctl net.ipv4.tcp_congestion_control | awk -F ' ' '{print $3}'`
elif [[ -n $(ping 10.0.0.2 -c 2 | grep ttl) ]]; then
bbr="Openvz version bbr-plus"
else
bbr="Openvz/Lxc"
fi
if [ ! -f nayg_update ]; then
green "Install the necessary dependencies of the Naiveproxy-yg script for the first time..."
if [[ -z $vi ]]; then
apt update iproute2 systemctl -y
fi
update(){
if [ -x "$(command -v apt-get)" ]; then
apt update -y
elif [ -x "$(command -v yum)" ]; then
yum update -y && yum install epel-release -y
elif [ -x "$(command -v dnf)" ]; then
dnf update -y
fi
}
if [[ $release = Centos && ${vsid} =~ 8 ]]; then
cd /etc/yum.repos.d/ && mkdir backup && mv *repo backup/
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
sed -i -e "s|mirrors.cloud.aliyuncs.com|mirrors.aliyun.com|g " /etc/yum.repos.d/CentOS-*
sed -i -e "s|releasever|releasever-stream|g" /etc/yum.repos.d/CentOS-*
yum clean all && yum makecache
cd
fi
update
packages=("curl" "openssl" "jq" "tar" "qrencode" "wget" "cron")
inspackages=("curl" "openssl" "jq" "tar" "qrencode" "wget" "cron")
for i in "${!packages[@]}"; do
package="${packages[$i]}"
inspackage="${inspackages[$i]}"
if ! command -v "$package" &> /dev/null; then
if [ -x "$(command -v apt-get)" ]; then
apt-get install -y "$inspackage"
elif [ -x "$(command -v yum)" ]; then
yum install -y "$inspackage"
elif [ -x "$(command -v dnf)" ]; then
dnf install -y "$inspackage"
fi
fi
done
if [ -x "$(command -v yum)" ] || [ -x "$(command -v dnf)" ]; then
if [ -x "$(command -v yum)" ]; then
yum install -y cronie
elif [ -x "$(command -v dnf)" ]; then
dnf install -y cronie
fi
fi
update
touch nayg_update
fi
if [[ $vi = openvz ]]; then
TUN=$(cat /dev/net/tun 2>&1)
if [[ ! $TUN =~ 'in bad state' ]] && [[ ! $TUN =~ '处于错误状态' ]] && [[ ! $TUN =~ 'Die Dateizugriffsnummer ist in schlechter Verfassung' ]]; then
red "It is detected that TUN is not enabled. Now try to add TUN support." && sleep 4
cd /dev && mkdir net && mknod net/tun c 10 200 && chmod 0666 net/tun
TUN=$(cat /dev/net/tun 2>&1)
if [[ ! $TUN =~ 'in bad state' ]] && [[ ! $TUN =~ '处于错误状态' ]] && [[ ! $TUN =~ 'Die Dateizugriffsnummer ist in schlechter Verfassung' ]]; then
green "Failed to add TUN support. It is recommended to communicate with the VPS manufacturer or enable background settings." && exit
else
echo '#!/bin/bash' > /root/tun.sh && echo 'cd /dev && mkdir net && mknod net/tun c 10 200 && chmod 0666 net/tun' >> /root/tun.sh && chmod +x /root/tun.sh
grep -qE "^ *@reboot root bash /root/tun.sh >/dev/null 2>&1" /etc/crontab || echo "@reboot root bash /root/tun.sh >/dev/null 2>&1" >> /etc/crontab
green "TUN guard function has been started"
fi
fi
fi
v4v6(){
v4=$(curl -s4m5 icanhazip.com -k)
v6=$(curl -s6m5 icanhazip.com -k)
}
warpcheck(){
wgcfv6=$(curl -s6m5 https://www.cloudflare.com/cdn-cgi/trace -k | grep warp | cut -d= -f2)
wgcfv4=$(curl -s4m5 https://www.cloudflare.com/cdn-cgi/trace -k | grep warp | cut -d= -f2)
}
v6(){
warpcheck
if [[ ! $wgcfv4 =~ on|plus && ! $wgcfv6 =~ on|plus ]]; then
v4=$(curl -s4m5 icanhazip.com -k)
if [ -z $v4 ]; then
yellow "Pure IPV6 VPS detected, add DNS64"
echo -e "nameserver 2a00:1098:2b::1\nnameserver 2a00:1098:2c::1\nnameserver 2a01:4f8:c2c:123f::1" > /etc/resolv.conf
fi
fi
}
close(){
systemctl stop firewalld.service >/dev/null 2>&1
systemctl disable firewalld.service >/dev/null 2>&1
setenforce 0 >/dev/null 2>&1
ufw disable >/dev/null 2>&1
iptables -P INPUT ACCEPT >/dev/null 2>&1
iptables -P FORWARD ACCEPT >/dev/null 2>&1
iptables -P OUTPUT ACCEPT >/dev/null 2>&1
iptables -t mangle -F >/dev/null 2>&1
iptables -F >/dev/null 2>&1
iptables -X >/dev/null 2>&1
netfilter-persistent save >/dev/null 2>&1
if [[ -n $(apachectl -v 2>/dev/null) ]]; then
systemctl stop httpd.service >/dev/null 2>&1
systemctl disable httpd.service >/dev/null 2>&1
service apache2 stop >/dev/null 2>&1
systemctl disable apache2 >/dev/null 2>&1
fi
sleep 1
blue "Execute open port and close firewall."
echo "----------------------------------------------------"
}
openyn(){
red "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
readp "Do you want to open the port and close the firewall? \n1. Yes, execute (press enter to default)\n2. No, I will do it manually\nPlease select:" action
if [[ -z $action ]] || [[ "$action" = "1" ]]; then
close
elif [[ "$action" = "2" ]]; then
echo
else
red "Input error, please choose again" && openyn
fi
}
forwardproxy(){
go env -w GO111MODULE=on
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
~/go/bin/xcaddy build --with github.com/caddyserver/forwardproxy@caddy2=github.com/klzgrad/forwardproxy@naive
}
rest(){
if [[ ! -f /root/caddy ]]; then
red "caddy2-naiveproxy build failed and the script exited" && exit
fi
chmod +x caddy
mv caddy /usr/bin/
}
inscaddynaive(){
echo
naygvsion=`curl -sL https://gitlab.com/rwkgyg/naiveproxy-yg/-/raw/main/version | head -n 1`
yellow "1. Please choose to install or update the naiveproxy kernel method:"
readp "1. Compiled caddy2-naiveproxy version: $naygvsion (quick installation, highly recommended, press Enter to default)\n2. Online compiled caddy2-naiveproxy version: $latcore (slow installation, compilation failure may occur)\nPlease select:" chcaddynaive
if [ -z "$chcaddynaive" ] || [ $chcaddynaive == "1" ]; then
cd /root
wget -qN https://gitlab.com/rwkgyg/naiveproxy-yg/raw/main/caddy2-naive-linux-${cpu}.tar.gz
wget -qN https://gitlab.com/rwkgyg/naiveproxy-yg/raw/main/version
tar zxvf caddy2-naive-linux-${cpu}.tar.gz
rm caddy2-naive-linux-${cpu}.tar.gz -f
cd
rest
elif [ $chcaddynaive == "2" ]; then
if [[ $release = Centos ]] && [[ ${vsid} =~ 8 ]]; then
green "Centos 8 system recommends using the compiled caddy2-naiveproxy version" && inscaddynaive
fi
cd /root
if [[ $release = Centos ]]; then
rpm --import https://mirror.go-repo.io/centos/RPM-GPG-KEY-GO-REPO
curl -s https://mirror.go-repo.io/centos/go-repo.repo | tee /etc/yum.repos.d/go-repo.repo
yum install golang && forwardproxy
elif [[ $release = Debian ]]; then
apt install software-properties-common -y
apt update
$GOLANG_VERSION = `curl -Ls https://golang.google.cn/dl/ | grep -oE "go[0-9.]+.linux-$cpu.tar.gz" | head -n 1 | cut -c3-8`
wget -c https://golang.google.cn/dl/go$GOLANG_VERSION.linux-$cpu.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go$GOLANG_VERSION.linux-$cpu.tar.gz
echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
source /etc/profile
forwardproxy
else
apt install software-properties-common -y
add-apt-repository ppa:longsleep/golang-backports
apt update
apt install golang-go && forwardproxy
fi
cd
rest
lastvsion=v`curl -Ls https://data.jsdelivr.com/v1/package/gh/klzgrad/naiveproxy | sed -n 4p | tr -d ',"' | awk '{print $1}'`
echo $lastvsion > /root/version
else
red "Input error, please choose again" && inscaddynaive
fi
version(){
if [[ ! -d /etc/caddy/ ]]; then
mkdir /etc/caddy >/dev/null 2>&1
fi
mv version /etc/caddy/
}
version
echo "----------------------------------------------------"
}
inscertificate(){
echo
yellow "2. The application method for Naiveproxy protocol certificate is as follows:"
readp "1. acme one-click certificate application script (supports regular 80 port mode and dns api mode), the certificate applied with this script will be automatically recognized (return to default)\n2. Customized certificate path (not /root/ygkkkca path) \nPlease select:" certificate
if [ -z "${certificate}" ] || [ $certificate == "1" ]; then
if [[ -f /root/ygkkkca/cert.crt && -f /root/ygkkkca/private.key ]] && [[ -s /root/ygkkkca/cert.crt && -s /root/ygkkkca/private.key ]] && [[ -f /root/ygkkkca/ca.log ]]; then
blue "After testing, I have used this acme script to apply for a certificate before."
readp "1. Use the original certificate directly (press Enter to default)\n2. Delete the original certificate and apply for a new certificate\nPlease choose:" certacme
if [ -z "${certacme}" ] || [ $certacme == "1" ]; then
ym=$(cat /root/ygkkkca/ca.log)
blue "Detected domain name: $ym, directly referenced"
elif [ $certacme == "2" ]; then
curl https://get.acme.sh | sh
bash /root/.acme.sh/acme.sh --uninstall
rm -rf /root/ygkkkca
rm -rf ~/.acme.sh acme.sh
sed -i '/--cron/d' /etc/crontab
[[ -z $(/root/.acme.sh/acme.sh -v 2>/dev/null) ]] && green "acme.sh is uninstalled" || red "acme.sh uninstallation failed"
sleep 2
bash <(curl -Ls https://raw.githubusercontent.com/hrostami/aio-proxy/master/acme-eng.sh)
ym=$(cat /root/ygkkkca/ca.log)
if [[ ! -f /root/ygkkkca/cert.crt && ! -f /root/ygkkkca/private.key ]] && [[ ! -s /root/ygkkkca/cert.crt && ! -s /root/ygkkkca/private.key ]]; then
red "The certificate application failed and the script exited" && exit
fi
fi
else
bash <(curl -Ls https://raw.githubusercontent.com/hrostami/aio-proxy/master/acme-eng.sh)
ym=$(cat /root/ygkkkca/ca.log)
if [[ ! -f /root/ygkkkca/cert.crt && ! -f /root/ygkkkca/private.key ]] && [[ ! -s /root/ygkkkca/cert.crt && ! -s /root/ygkkkca/private.key ]]; then
red "The certificate application failed and the script exited" && exit
fi
fi
certificatec='/root/ygkkkca/cert.crt'
certificatep='/root/ygkkkca/private.key'
elif [ $certificate == "2" ]; then
readp "Please enter the path to the placed public key file crt (/a/b/……/cert.crt):" cerroad
blue "The path of the public key file crt: $cerroad"
readp "Please enter the path to the placed key file key (/a/b/……/private.key):" keyroad
blue "Path to key file key: $keyroad"
certificatec=$cerroad
certificatep=$keyroad
readp "Please enter the resolved domain name:" ym
blue "Resolved domain name: $ym"
else
red "Input error, please choose again" && inscertificate
fi
echo "----------------------------------------------------"
}
insport(){
echo
readp "3. Set the Naiveproxy port [1-65535] (press Enter to skip to a random port between 2000-65535):" port
if [[ -z $port ]]; then
port=$(shuf -i 2000-65535 -n 1)
until [[ -z $(ss -tunlp | grep -w tcp | awk '{print $5}' | sed 's/.*://g' | grep -w "$port") ]]
do
[[ -n $(ss -tunlp | grep -w tcp | awk '{print $5}' | sed 's/.*://g' | grep -w "$port") ]] && yellow "\nThe port is occupied, please re-enter the port." && readp "Custom port:" port
done
else
until [[ -z $(ss -tunlp | grep -w tcp | awk '{print $5}' | sed 's/.*://g' | grep -w "$port") ]]
do
[[ -n $(ss -tunlp | grep -w tcp | awk '{print $5}' | sed 's/.*://g' | grep -w "$port") ]] && yellow "\nThe port is occupied, please re-enter the port." && readp "Custom port:" port
done
fi
blue "Confirmed port: $port"
echo "----------------------------------------------------"
}
insuser(){
echo
readp "4. Set the user name, which must be more than 3 characters (press Enter to skip to random 3 characters):" user
if [[ -z ${user} ]]; then
user=`date +%s%N |md5sum | cut -c 1-3`
else
if [[ 3 -ge ${#user} ]]; then
until [[ 3 -le ${#user} ]]
do
[[ 3 -ge ${#user} ]] && yellow "\nThe username must be more than 3 characters! please enter again" && readp "\nSet username:" user
done
fi
fi
blue "Confirmed username: ${user}"
echo "----------------------------------------------------"
}
inspswd(){
echo
readp "5. Set a password, which must be more than 5 characters (press Enter to skip to a random 5 characters):" pswd
if [[ -z ${pswd} ]]; then
pswd=`date +%s%N |md5sum | cut -c 1-5`
else
if [[ 5 -ge ${#pswd} ]]; then
until [[ 5 -le ${#pswd} ]]
do
[[ 5 -ge ${#pswd} ]] && yellow "\nThe username must be more than 5 characters! please enter again" && readp "\nSet password:" pswd
done
fi
fi
blue "Confirmed password: ${pswd}"
echo "----------------------------------------------------"
}
insweb(){
echo
readp "6. Set the camouflage URL. Note: Do not bring http(s):// (Enter to skip, the default is Yongge’s blog address: ygkkk.blogspot.com):" web
if [[ -z ${web} ]]; then
naweb=ygkkk.blogspot.com
else
naweb=$web
fi
blue "Confirmed disguised URL: ${naweb}"
echo "----------------------------------------------------"
}
insconfig(){
echo
readp "7. Set caddy2-naiveproxy listening port [1-65535] (press Enter to skip to a random port between 2000-65535):" caddyport
if [[ -z $caddyport ]]; then
caddyport=$(shuf -i 2000-65535 -n 1)
if [[ $caddyport == $port ]]; then
yellow "\nThe port is occupied, please re-enter the port." && readp "Custom caddy2-naiveproxy listening port:" caddyport
fi
until [[ -z $(ss -tunlp | grep -w tcp | awk '{print $5}' | sed 's/.*://g' | grep -w "$caddyport") ]]
do
[[ -n $(ss -tunlp | grep -w tcp | awk '{print $5}' | sed 's/.*://g' | grep -w "$caddyport") ]] && yellow "\nThe port is occupied, please re-enter the port." && readp "Custom port:" caddyport
done
else
until [[ -z $(ss -tunlp | grep -w tcp | awk '{print $5}' | sed 's/.*://g' | grep -w "$caddyport") ]]
do
[[ -n $(ss -tunlp | grep -w tcp | awk '{print $5}' | sed 's/.*://g' | grep -w "$caddyport") ]] && yellow "\nThe port is occupied, please re-enter the port." && readp "Custom port:" caddyport
done
fi
blue "Confirmed port: $caddyport\n"
green "Set the configuration file and service process of naiveproxy...\n"
mkdir /root/naive >/dev/null 2>&1
mkdir /etc/caddy >/dev/null 2>&1
cat << EOF >/etc/caddy/Caddyfile
{
http_port $caddyport
}
:$port, $ym:$port {
tls ${certificatec} ${certificatep}
route {
forward_proxy {
basic_auth ${user} ${pswd}
hide_ip
hide_via
probe_resistance
}
reverse_proxy https://$naweb {
header_up Host {upstream_hostport}
header_up X-Forwarded-Host {host}
}
}
}
EOF
cat <<EOF > /root/naive/v2rayn.json
{
"listen": "socks://127.0.0.1:1080",
"proxy": "https://${user}:${pswd}@${ym}:$port"
}
EOF
cat << EOF >/etc/systemd/system/caddy.service
[Unit]
Description=YGKKK-Caddy2-naiveproxy
Documentation=https://gitlab.com/rwkgyg/naiveproxy-yg
After=network.target network-online.target
Requires=network-online.target
[Service]
User=root
Group=root
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
PrivateTmp=false
NoNewPrivileges=yes
ProtectHome=false
ProtectSystem=false
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable caddy >/dev/null 2>&1
systemctl start caddy
}
stclre(){
if [[ ! -f '/etc/caddy/Caddyfile' ]]; then
green "naiveproxy is not installed properly" && exit
fi
green "The naiveproxy service performs the following operations"
readp "1. Restart\n2. Shut down\n0. Return to the upper level\nPlease select:" action
if [[ $action == "1" ]]; then
systemctl enable caddy
systemctl start caddy
systemctl restart caddy
green "naiveproxy service restart\n"
elif [[ $action == "2" ]]; then
systemctl stop caddy
systemctl disable caddy
green "naiveproxy service is closed\n"
else
na
fi
}
changeserv(){
if [[ -z $(systemctl status caddy 2>/dev/null | grep -w active) && ! -f '/etc/caddy/Caddyfile' ]]; then
red "naiveproxy is not installed properly" && exit
fi
green "The naiveproxy configuration change options are as follows:"
readp "1. Add or delete multi-port reuse (one port is added each time it is executed)\n2. Change the main port\n3. Change the user name\n4. Change the password\n5. Re-apply for a certificate or change the certificate path\n6. Change the disguised web page \n0. Return to the upper level\nPlease select:" choose
if [ $choose == "1" ];then
duoport
elif [ $choose == "2" ];then
changeport
elif [ $choose == "3" ];then
changeuser
elif [ $choose == "4" ];then
changepswd
elif [ $choose == "5" ];then
inscertificate
oldcer=`cat /etc/caddy/Caddyfile 2>/dev/null | sed -n 5p | awk '{print $2}'`
oldkey=`cat /etc/caddy/Caddyfile 2>/dev/null | sed -n 5p | awk '{print $3}'`
sed -i "s#$oldcer#${certificatec}#g" /etc/caddy/Caddyfile
sed -i "s#$oldkey#${certificatep}#g" /etc/caddy/Caddyfile
sed -i "s#$oldcer#${certificatec}#g" /etc/caddy/reCaddyfile
sed -i "s#$oldkey#${certificatep}#g" /etc/caddy/reCaddyfile
oldym=`cat /etc/caddy/Caddyfile 2>/dev/null | sed -n 4p | awk '{print $2}'| awk -F":" '{print $1}'`
sed -i "s/$oldym/${ym}/g" /etc/caddy/Caddyfile /etc/caddy/reCaddyfile /root/naive/URL.txt /root/naive/v2rayn.json
sussnaiveproxy
elif [ $choose == "6" ];then
changeweb
else
na
fi
}
duoport(){
naiveports=`cat /etc/caddy/Caddyfile 2>/dev/null | awk '{print $1}' | grep : | tr -d ',:'`
green "\nThe port currently being used by naiveproxy:"
blue "$naiveports"
readp "\n1. Add multi-port multiplexing\n2. Restore only one main port\n0. Return to the upper layer\nPlease select:" choose
if [ $choose == "1" ]; then
oldport1=`cat /etc/caddy/reCaddyfile 2>/dev/null | sed -n 4p | awk '{print $1}'| tr -d ',:'`
insport
sed -i "s/$oldport1/$port/g" /etc/caddy/reCaddyfile
cat /etc/caddy/reCaddyfile 2>/dev/null | tail -15 >> /etc/caddy/Caddyfile
sussnaiveproxy
elif [ $choose == "2" ]; then
sed -i '19,$d' /etc/caddy/Caddyfile 2>/dev/null
sussnaiveproxy
else
changeserv
fi
}
changeuser(){
olduserc=`cat /etc/caddy/Caddyfile 2>/dev/null | sed -n 8p | awk '{print $2}'`
echo
blue "Username currently in use: $olduserc"
echo
insuser
sed -i "s/$olduserc/${user}/g" /etc/caddy/Caddyfile /etc/caddy/reCaddyfile /root/naive/URL.txt /root/naive/v2rayn.json
sussnaiveproxy
}
changepswd(){
oldpswdc=`cat /etc/caddy/Caddyfile 2>/dev/null | sed -n 8p | awk '{print $3}'`
echo
blue "Password currently in use: $oldpswdc"
echo
inspswd
sed -i "s/$oldpswdc/${pswd}/g" /etc/caddy/Caddyfile /etc/caddy/reCaddyfile /root/naive/URL.txt /root/naive/v2rayn.json
sussnaiveproxy
}
changeport(){
oldport1=`cat /etc/caddy/Caddyfile 2>/dev/null | sed -n 4p | awk '{print $1}'| tr -d ',:'`
echo
blue "Main port currently in use: $oldport1"
echo
insport
sed -i "s/$oldport1/$port/g" /etc/caddy/Caddyfile /root/naive/v2rayn.json /root/naive/URL.txt
sussnaiveproxy
}
changeweb(){
oldweb=`cat /etc/caddy/Caddyfile 2>/dev/null | sed -n 13p | awk '{print $2}'`
echo
blue "Currently using the disguised URL: $oldweb"
echo
insweb
sed -i "s/$oldweb/$naweb/g" /etc/caddy/Caddyfile /etc/caddy/reCaddyfile
sussnaiveproxy
}
acme(){
bash <(curl -L -s https://raw.githubusercontent.com/hrostami/aio-proxy/master/acme-eng.sh)
}
cfwarp(){
bash <(curl -Ls https://raw.githubusercontent.com/hrostami/aio-proxy/master/warp.sh)
}
bbr(){
bash <(curl -L -s https://raw.githubusercontent.com/teddysun/across/master/bbr.sh)
}
lnna(){
curl -sL -o /usr/bin/na https://raw.githubusercontent.com/hrostami/aio-proxy/master/naiveproxy.sh
chmod +x /usr/bin/na
}
upnayg(){
if [[ ! -f '/etc/caddy/Caddyfile' ]]; then
red "Naiveproxy-yg is not installed properly" && exit
fi
lnna
curl -sL https://gitlab.com/rwkgyg/naiveproxy-yg/-/raw/main/version | awk -F "update content" 'NR>2 {print $1; exit}' > /etc/caddy/v
green "Naiveproxy-yg installation script upgraded successfully" && sleep 5 && na
}
upnaive(){
if [[ -z $(systemctl status caddy 2>/dev/null | grep -w active) && ! -f '/etc/caddy/Caddyfile' ]]; then
red "naiveproxy is not installed properly" && exit
fi
green "\nUpgrade naiveproxy kernel version\n"
inscaddynaive
systemctl restart caddy
green "naiveproxy kernel version upgraded successfully" && na
}
unins(){
systemctl stop caddy >/dev/null 2>&1
systemctl disable caddy >/dev/null 2>&1
rm -f /etc/systemd/system/caddy.service
rm -rf /usr/bin/caddy /etc/caddy /root/naive /usr/bin/na /root/nayg_update
green "naiveproxy uninstallation completed!"
}
sussnaiveproxy(){
systemctl restart caddy
if [[ -n $(systemctl status caddy 2>/dev/null | grep -w active) && -f '/etc/caddy/Caddyfile' ]]; then
green "The naiveproxy service started successfully" && naiveproxyshare
else
red "The naiveproxy service failed to start. Please run systemctl status caddy to view the service status and provide feedback. The script exits." && exit
fi
}
naiveproxyshare(){
if [[ -z $(systemctl status caddy 2>/dev/null | grep -w active) && ! -f '/etc/caddy/Caddyfile' ]]; then
red "naiveproxy is not installed properly" && exit
fi
red "======================================================================================"
naiveports=`cat /etc/caddy/Caddyfile 2>/dev/null | awk '{print $1}' | grep : | tr -d ',:'`
green "\nThe port currently being used by naiveproxy:" && sleep 2
blue "$naiveports\n"
green "The content of the current v2rayn client configuration file v2rayn.json is as follows, saved to /root/naive/v2rayn.json\n"
yellow "$(cat /root/naive/v2rayn.json)\n" && sleep 2
green "The current naiveproxy node sharing link is as follows, save it to /root/naive/URL.txt"
yellow "$(cat /root/naive/URL.txt)\n" && sleep 2
green "The current naiveproxy node QR code sharing link is as follows (Nekobox)"
qrencode -o - -t ANSIUTF8 "$(cat /root/naive/URL.txt)"
}
insna(){
if [[ -f '/etc/caddy/Caddyfile' ]]; then
green "Naiveproxy has been installed. Please perform the uninstall function before reinstalling." && exit
fi
rm -f /etc/systemd/system/caddy.service
rm -rf /usr/bin/caddy /etc/caddy /root/naive /usr/bin/na
v6 ; openyn ; inscaddynaive ; inscertificate ; insport ; insuser ; inspswd ; insweb ; insconfig
if [[ -n $(systemctl status caddy 2>/dev/null | grep -w active) && -f '/etc/caddy/Caddyfile' ]]; then
green "The naiveproxy service started successfully"
lnna
curl -sL https://gitlab.com/rwkgyg/naiveproxy-yg/-/raw/main/version | awk -F "update content" 'NR>2 {print $1; exit}' > /etc/caddy/v
cp -f /etc/caddy/Caddyfile /etc/caddy/reCaddyfile >/dev/null 2>&1
if [[ ! $vi =~ lxc|openvz ]]; then
sysctl -w net.core.rmem_max=8000000 >/dev/null 2>&1
sysctl -p >/dev/null 2>&1
fi
else
red "The naiveproxy service failed to start. Please run systemctl status caddy to view the service status and provide feedback. The script exits." && exit
fi
red "======================================================================================"
url="naive+https://${user}:${pswd}@${ym}:$port?padding=true#Naive-$(hostname)"
echo ${url} > /root/naive/URL.txt
green "\nnaiveproxy proxy service installation is complete, the shortcut to generate the script is na" && sleep 3
green "\nv2rayn client configuration file v2rayn.json is saved to /root/naive/v2rayn.json\n"
yellow "$(cat /root/naive/v2rayn.json)\n"
green "Share the link and save it to /root/naive/URL.txt" && sleep 3
yellow "${url}\n"
green "The QR code sharing link is as follows (Nekobox)" && sleep 2
qrencode -o - -t ANSIUTF8 "$(cat /root/naive/URL.txt)"
}
nalog(){
echo
red "To exit Naiveproxy log viewing, please press Ctrl+c"
echo
journalctl -u caddy --output cat -f
}
clear
green "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo -e "${bblue} ░██ ░██ ░██ ██ ██ ░█${plain}█ ░██ ░██ ░██ ░█${red}█ ░██${plain} "
echo -e "${bblue} ░██ ░██ ░██ ░░██${plain} ░██ ░██ ░██ ░██${red} ░██ ░██${plain} "
echo -e "${bblue} ░██ ░██ ░██ ${plain} ░██ ██ ░██ █${red}█ ░██ ██ ${plain} "
echo -e "${bblue} ░██ ░${plain}██ ░██ ██ ░██ ██ ░█${red}█ ██ ░██ ██ ${plain} "
echo -e "${bblue} ░██ ${plain} ░██ ░░██ ░██ ░██ ░${red}██ ░██ ░██ ░██ ${plain} "
echo -e "${bblue} ░█${plain}█ ░██ ██ ██ ░██ ░░${red}██ ░██ ░░██ ░██ ░░██ ${plain} "
green "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
white "Yongge Github project: github.com/yonggekkk"
white "Yongge Blogger Blog: ygkkk.blogspot.com"
white "Brother Yong’s YouTube channel: www.youtube.com/@ygkkk"
yellow "Translated by Hosy: https://github.com/hrostami"
green "After the Naiveproxy-yg script is installed successfully, the shortcut to enter the script again is na"
red "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
green " 1. Install Naiveproxy"
green " 2. Uninstall Naiveproxy"
white "----------------------------------------------------------------------------------"
green " 3. Change configuration (multi-port reuse, user name and password, certificate, disguised web page)"
green " 4. Close and restart Naiveproxy"
green " 5. Update Naiveproxy-yg installation script"
green " 6. Update Naiveproxy kernel version"
white "----------------------------------------------------------------------------------"
green " 7. Display Naiveproxy sharing link, V2rayN configuration file, and QR code"
green " 8. Check the Naiveproxy operation log"
green " 9. Manage Acme to apply for a domain name certificate"
green "10. Manage Warp to view Netflix and ChatGPT unlock status"
green "11. One-click original BBR+FQ acceleration"
green " 0. Exit script"
red "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
if [ -f /etc/caddy/v ]; then
if [ "$insV" = "$latestV" ]; then
echo -e "The latest version of the current Naiveproxy-yg script: ${bblue}${insV}${plain} (already installed)"
else
echo -e "Current Naiveproxy-yg script version number: ${bblue}${insV}${plain}"
echo -e "The latest Naiveproxy-yg script version number detected: ${yellow}${latestV}${plain} (can select 5 for update)"
echo -e "${yellow}$(curl -sL https://gitlab.com/rwkgyg/naiveproxy-yg/-/raw/main/version | awk -F "update content" 'NR>2 {print $1}')${plain}"
fi
else
echo -e "Current Naiveproxy-yg script version number: ${bblue}${latestV}${plain}"
echo -e "Please select 1 first to install the Naiveproxy-yg script"
fi
if [ -f /etc/caddy/v ]; then
if [ "$inscore" = "$latcore" ]; then
echo -e "Current Naiveproxy latest kernel version: ${bblue}${inscore}${plain} (installed)"
else
echo -e "Currently Naiveproxy has installed kernel version: ${bblue}${inscore}${plain}"
echo -e "The latest Naiveproxy kernel version detected: ${yellow}${latcore}${plain} (optional 6 for update)"
fi
fi
red "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo -e "The VPS status is as follows:"
echo -e "System:$blue$op$plain \c";echo -e "Kernel:$blue$version$plain \c";echo -e "Processor:$blue$cpu$plain \c";echo -e "Virtualization:$blue$vi$plain \c";echo -e "BBR algorithm:$blue$bbr$plain"
v4v6
if [[ "$v6" == "2a09"* ]]; then
w6="【WARP】"
fi
if [[ "$v4" == "104.28"* ]]; then
w4="【WARP】"
fi
if [[ -z $v4 ]]; then
vps_ipv4='无IPV4'
vps_ipv6="$v6"
elif [[ -n $v4 && -n $v6 ]]; then
vps_ipv4="$v4"
vps_ipv6="$v6"
else
vps_ipv4="$v4"
vps_ipv6='无IPV6'
fi
echo -e "Local IPV4 address: $blue$vps_ipv4$w4$plain Local IPV6 address: $blue$vps_ipv6$w6$plain"
naiveports=$(cat /etc/caddy/Caddyfile 2>/dev/null | awk '{print $1}' | grep : | tr -d ',:' | tr '\n' ' ')
if [[ -n $(systemctl status caddy 2>/dev/null | grep -w active) && -f '/etc/caddy/Caddyfile' ]]; then
echo -e "Naiveproxy status: $green running $plain Proxy ports: $green $naiveports$plain"
elif [[ -z $(systemctl status caddy 2>/dev/null | grep -w active) && -f '/etc/caddy/Caddyfile' ]]; then
echo -e "Naiveproxy status: $yellow has not been started. You can choose 4 to restart. If it is still the same, choose 8 to view the log and give feedback. It is recommended to uninstall and reinstall Naiveproxy-yg$plain."
else
echo -e "Naiveproxy status: $red is not installed $plain"
fi
red "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo
readp "Please enter a number [0-11]:" Input
case "$Input" in
1 ) insna;;
2 ) unins;;
3 ) changeserv;;
4 ) stclre;;
5 ) upnayg;;
6 ) upnaive;;
7 ) naiveproxyshare;;
8 ) nalog;;
9 ) acme;;
10 ) cfwarp;;
11 ) bbr;;
* ) exit;;
esac