forked from vveg26/sing-box-reality-hysteria2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
beta.sh
1834 lines (1743 loc) · 58.3 KB
/
beta.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
# delay print
print_with_delay() {
text="$1"
delay="$2"
for ((i = 0; i < ${#text}; i++)); do
printf "%s" "${text:$i:1}"
sleep "$delay"
done
echo
}
# colorful text
warning() { echo -e "\033[31m\033[01m$*\033[0m"; } # 红色
error() { echo -e "\033[31m\033[01m$*\033[0m" && exit 1; } # 红色
info() { echo -e "\033[32m\033[01m$*\033[0m"; } # 绿色
hint() { echo -e "\033[33m\033[01m$*\033[0m"; } # 黄色
#show system and singbox info
show_status(){
singbox_pid=$(pgrep sing-box)
singbox_status=$(systemctl is-active sing-box)
if [ "$singbox_status" == "active" ]; then
cpu_usage=$(ps -p $singbox_pid -o %cpu | tail -n 1)
memory_usage_mb=$(( $(ps -p "$singbox_pid" -o rss | tail -n 1) / 1024 ))
p_latest_version_tag=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r '[.[] | select(.prerelease==true)][0].tag_name')
latest_version_tag=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r '[.[] | select(.prerelease==false)][0].tag_name')
latest_version=${latest_version_tag#v} # Remove 'v' prefix from version number
p_latest_version=${p_latest_version_tag#v} # Remove 'v' prefix from version number
iswarp=$(grep '^WARP_ENABLE=' /root/sbox/config | cut -d'=' -f2)
hyhop=$(grep '^HY_HOPPING=' /root/sbox/config | cut -d'=' -f2)
warning "SING-BOX服务状态信息:"
hint "========================="
info "状态: 运行中"
info "CPU 占用: $cpu_usage%"
info "内存 占用: ${memory_usage_mb}MB"
info "singbox测试版最新版本: $p_latest_version"
info "singbox正式版最新版本: $latest_version"
info "singbox当前版本(输入4管理切换): $(/root/sbox/sing-box version 2>/dev/null | awk '/version/{print $NF}')"
info "warp流媒体解锁(输入6管理): $(if [ "$iswarp" == "TRUE" ]; then echo "开启"; else echo "关闭"; fi)"
info "hy2端口跳跃(输入7管理): $(if [ "$hyhop" == "TRUE" ]; then echo "开启"; else echo "关闭"; fi)"
hint "========================="
else
warning "SING-BOX 未运行!"
fi
}
download_cloudflared(){
arch=$(uname -m)
# Map architecture names
case ${arch} in
x86_64)
cf_arch="amd64"
;;
aarch64)
cf_arch="arm64"
;;
armv7l)
cf_arch="arm"
;;
esac
# install cloudflared linux
cf_url="https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-${cf_arch}"
curl -sLo "/root/sbox/cloudflared-linux" "$cf_url"
chmod +x /root/sbox/cloudflared-linux
echo ""
}
#show notice
show_notice() {
local message="$1"
local reset="\e[0m"
local bold="\e[1m"
local terminal_width=$(tput cols)
local line=""
local padding=$(( (terminal_width - ${#message}) / 2 ))
local padded_message="$(printf "%*s%s" $padding '' "$message")"
for ((i=1; i<=terminal_width; i++)); do
line+="*"
done
warning "${bold}${line}${reset}"
echo ""
warning "${bold}${padded_message}${reset}"
echo ""
warning "${bold}${line}${reset}"
}
#install pkgs
install_pkgs() {
# Install qrencode, jq, and iptables if not already installed
local pkgs=("qrencode" "jq" "iptables")
for pkg in "${pkgs[@]}"; do
if command -v "$pkg" &> /dev/null; then
echo "$pkg is already installed."
else
echo "Installing $pkg..."
if command -v apt &> /dev/null; then
sudo apt update > /dev/null 2>&1 && sudo apt install -y "$pkg" > /dev/null 2>&1
elif command -v yum &> /dev/null; then
sudo yum install -y "$pkg"
elif command -v dnf &> /dev/null; then
sudo dnf install -y "$pkg"
else
error "Unable to install $pkg. Please install it manually and rerun the script."
fi
echo "$pkg has been installed."
fi
done
}
install_shortcut() {
cat > /root/sbox/mianyang.sh << EOF
#!/usr/bin/env bash
bash <(curl -fsSL https://github.com/vveg26/sing-box-reality-hysteria2/raw/main/beta.sh) \$1
EOF
chmod +x /root/sbox/mianyang.sh
ln -sf /root/sbox/mianyang.sh /usr/bin/mianyang
}
reload_singbox(){
if /root/sbox/sing-box check -c /root/sbox/sbconfig_server.json; then
echo "检查配置文件成功,重启服务..."
systemctl reload sing-box
else
error "配置文件检查错误"
fi
}
install_singbox(){
echo "请选择需要安装的SING-BOX版本:"
echo "1. 正式版"
echo "2. 测试版"
read -p "输入你的选项 (1-2, 默认: 1): " version_choice
version_choice=${version_choice:-1}
# Set the tag based on user choice
if [ "$version_choice" -eq 2 ]; then
echo "Installing Alpha version..."
latest_version_tag=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r '[.[] | select(.prerelease==true)][0].tag_name')
else
echo "Installing Stable version..."
latest_version_tag=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r '[.[] | select(.prerelease==false)][0].tag_name')
fi
# No need to fetch the latest version tag again, it's already set based on user choice
latest_version=${latest_version_tag#v} # Remove 'v' prefix from version number
echo "Latest version: $latest_version"
# Detect server architecture
arch=$(uname -m)
echo "本机架构为: $arch"
case ${arch} in
x86_64) arch="amd64" ;;
aarch64) arch="arm64" ;;
armv7l) arch="armv7" ;;
esac
# latest_version_tag=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | grep -Po '"tag_name": "\K.*?(?=")' | sort -V | tail -n 1)
# latest_version=${latest_version_tag#v}
echo "最新版本为: $latest_version"
package_name="sing-box-${latest_version}-linux-${arch}"
url="https://github.com/SagerNet/sing-box/releases/download/${latest_version_tag}/${package_name}.tar.gz"
curl -sLo "/root/${package_name}.tar.gz" "$url"
tar -xzf "/root/${package_name}.tar.gz" -C /root
mv "/root/${package_name}/sing-box" /root/sbox
rm -r "/root/${package_name}.tar.gz" "/root/${package_name}"
chown root:root /root/sbox/sing-box
chmod +x /root/sbox/sing-box
}
change_singbox(){
echo "切换SING-BOX版本..."
echo ""
# Extract the current version
current_version_tag=$(/root/sbox/sing-box version | grep 'sing-box version' | awk '{print $3}')
# Fetch the latest stable and alpha version tags
latest_stable_version=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r '[.[] | select(.prerelease==false)][0].tag_name')
latest_alpha_version=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r '[.[] | select(.prerelease==true)][0].tag_name')
# Determine current version type (stable or alpha)
if [[ $current_version_tag == *"-alpha"* || $current_version_tag == *"-rc"* || $current_version_tag == *"-beta"* ]]; then
echo "当前为测试版,准备切换为最新正式版..."
echo ""
new_version_tag=$latest_stable_version
else
echo "当前为正式版,准备切换为最新测试版..."
echo ""
new_version_tag=$latest_alpha_version
fi
# Stop the service before updating
systemctl stop sing-box
# Download and replace the binary
arch=$(uname -m)
case $arch in
x86_64) arch="amd64" ;;
aarch64) arch="arm64" ;;
armv7l) arch="armv7" ;;
esac
package_name="sing-box-${new_version_tag#v}-linux-${arch}"
url="https://github.com/SagerNet/sing-box/releases/download/${new_version_tag}/${package_name}.tar.gz"
curl -sLo "/root/${package_name}.tar.gz" "$url"
tar -xzf "/root/${package_name}.tar.gz" -C /root
mv "/root/${package_name}/sing-box" /root/sbox/sing-box
# Cleanup the package
rm -r "/root/${package_name}.tar.gz" "/root/${package_name}"
# Set the permissions
chown root:root /root/sbox/sing-box
chmod +x /root/sbox/sing-box
# Restart the service with the new binary
systemctl daemon-reload
systemctl start sing-box
echo "Version switched and service restarted with the new binary."
echo ""
}
generate_port() {
while :; do
port=$((RANDOM % 10001 + 10000))
read -p "请输入协议监听端口(默认随机生成): " user_input
port=${user_input:-$port}
ss -tuln | grep -q ":$port\b" || { echo "$port"; return $port; }
echo "端口 $port 被占用,请输入其他端口"
done
}
modify_port() {
local current_port="$1"
while :; do
read -p "请输入需要修改的端口,默认随机生成 (当前端口为: $current_port): " modified_port
modified_port=${modified_port:-$current_port}
if [ "$modified_port" -eq "$current_port" ]; then
break
fi
if ss -tuln | grep -q ":$modified_port\b"; then
echo "端口 $port 被占用,请输入其他端口"
else
break
fi
done
echo "$modified_port"
}
# client configuration
show_client_configuration() {
# get ip
server_ip=$(grep -o "SERVER_IP='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
public_key=$(grep -o "PUBLIC_KEY='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
# reality
reality_port=$(jq -r '.inbounds[] | select(.tag == "vless-in") | .listen_port' /root/sbox/sbconfig_server.json)
reality_uuid=$(jq -r '.inbounds[] | select(.tag == "vless-in") | .users[0].uuid' /root/sbox/sbconfig_server.json)
reality_server_name=$(jq -r '.inbounds[] | select(.tag == "vless-in") | .tls.server_name' /root/sbox/sbconfig_server.json)
short_id=$(jq -r '.inbounds[] | select(.tag == "vless-in") | .tls.reality.short_id[0]' /root/sbox/sbconfig_server.json)
#聚合reality
reality_link="vless://$reality_uuid@$server_ip:$reality_port?encryption=none&flow=xtls-rprx-vision&security=reality&sni=$reality_server_name&fp=chrome&pbk=$public_key&sid=$short_id&type=tcp&headerType=none#SING-BOX-REALITY"
echo ""
show_notice "Vision Reality通用链接 二维码 通用参数"
echo ""
info "通用链接如下"
echo ""
echo "$reality_link"
echo ""
info "二维码如下"
echo ""
qrencode -t UTF8 $reality_link
echo ""
info "客户端通用参数如下"
echo ""
echo "服务器ip: $server_ip"
echo "监听端口: $reality_port"
echo "UUID: $reality_uuid"
echo "域名SNI: $reality_server_name"
echo "Public Key: $public_key"
echo "Short ID: $short_id"
echo ""
# hy2
hy_port=$(jq -r '.inbounds[] | select(.tag == "hy2-in") | .listen_port' /root/sbox/sbconfig_server.json)
hy_server_name=$(grep -o "HY_SERVER_NAME='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
hy_password=$(jq -r '.inbounds[] | select(.tag == "hy2-in") | .users[0].password' /root/sbox/sbconfig_server.json)
# Generate the hy link
# Generate the hy link
ishopping=$(grep '^HY_HOPPING=' /root/sbox/config | cut -d'=' -f2)
if [ "$ishopping" = "FALSE" ]; then
hy2_link="hysteria2://$hy_password@$server_ip:$hy_port?insecure=1&sni=$hy_server_name"
else
iptables_rule=$(iptables -t nat -L -n -v | grep "udp" | grep -oP 'dpts:\K\d+:\d+')
ipv6tables_rule=$(ip6tables -t nat -L -n -v | grep "udp" | grep -oP 'dpts:\K\d+:\d+')
if [ -z "$iptables_rule" ] && [ -z "$ipv6tables_rule" ]; then
echo "未找到端口范围。"
exit 1
fi
output_range="${iptables_rule:-$ipv6tables_rule}"
formatted_range=$(echo "$output_range" | sed 's/:/-/')
hy2_link="hysteria2://$hy_password@$server_ip:$hy_port?insecure=1&sni=$hy_server_name&mport=${hy_port},${formatted_range}"
fi
echo ""
echo ""
show_notice "Hysteria2通用链接 二维码 通用参数"
echo ""
info "通用链接如下"
echo ""
echo "$hy2_link"
echo ""
info "二维码如下"
echo ""
qrencode -t UTF8 $hy2_link
echo ""
info "客户端通用参数如下"
echo ""
echo "服务器ip: $server_ip"
echo "端口号: $hy_port"
if [ "$ishopping" = "FALSE" ]; then
echo "端口跳跃未开启"
else
echo "跳跃端口为${formatted_range}"
fi
echo "密码password: $hy_password"
echo "域名SNI: $hy_server_name"
echo "跳过证书验证(允许不安全): True"
echo ""
echo ""
sleep 2
if [ -f "/root/sbox/argo.log" ]; then
cat /root/sbox/argo.log | grep trycloudflare.com | awk 'NR==2{print}' | awk -F// '{print $2}' | awk '{print $1}' | xargs -I {} sed -i "s/ARGO_DOMAIN='.*'/ARGO_DOMAIN='{}'/g" /root/sbox/config
rm -f /root/sbox/argo.log
fi
#argo域名
argo_domain=$(grep -o "ARGO_DOMAIN='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
vmess_uuid=$(jq -r '.inbounds[] | select(.tag == "vmess-in") | .users[0].uuid' /root/sbox/sbconfig_server.json)
ws_path=$(jq -r '.inbounds[] | select(.tag == "vmess-in") | .transport.path' /root/sbox/sbconfig_server.json)
vmesswss_link='vmess://'$(echo '{"add":"icook.hk","aid":"0","host":"'$argo_domain'","id":"'$vmess_uuid'","net":"ws","path":"'${ws_path}?ed=2048'","port":"443","ps":"sing-box-vmess-tls","tls":"tls","type":"none","v":"2"}' | base64 -w 0)
vmessws_link='vmess://'$(echo '{"add":"icook.hk","aid":"0","host":"'$argo_domain'","id":"'$vmess_uuid'","net":"ws","path":"'${ws_path}?ed=2048'","port":"80","ps":"sing-box-vmess","tls":"","type":"none","v":"2"}' | base64 -w 0)
echo ""
echo ""
show_notice "vmess ws(s) 通用链接和二维码"
echo ""
echo ""
info "vmess wss通用链接,替换icook.hk为自己的优选ip可获得极致体验"
echo ""
echo "$vmesswss_link"
echo ""
info "vmess wss二维码"
echo ""
qrencode -t UTF8 $vmesswss_link
echo ""
info "上述链接为wss 端口 443 可改为 2053 2083 2087 2096 8443"
echo ""
info "vmess ws链接,替换icook.hk为自己的优选ip可获得极致体验"
echo ""
echo "$vmessws_link"
echo ""
info "vmess ws 二维码"
echo ""
qrencode -t UTF8 $vmessws_link
echo ""
info "上述链接为ws 端口 80 可改为 8080 8880 2052 2082 2086 2095"
echo ""
echo ""
show_notice "clash-meta配置参数"
cat << EOF
port: 7890
allow-lan: true
mode: rule
log-level: info
unified-delay: true
global-client-fingerprint: chrome
ipv6: true
dns:
enable: true
listen: :53
ipv6: true
enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16
default-nameserver:
- 223.5.5.5
- 8.8.8.8
nameserver:
- https://dns.alidns.com/dns-query
- https://doh.pub/dns-query
fallback:
- https://1.0.0.1/dns-query
- tls://dns.google
fallback-filter:
geoip: true
geoip-code: CN
ipcidr:
- 240.0.0.0/4
proxies:
- name: Reality
type: vless
server: $server_ip
port: $reality_port
uuid: $reality_uuid
network: tcp
udp: true
tls: true
flow: xtls-rprx-vision
servername: $reality_server_name
client-fingerprint: chrome
reality-opts:
public-key: $public_key
short-id: $short_id
- name: Hysteria2
type: hysteria2
server: $server_ip
port: $hy_port
# up和down均不写或为0则使用BBR流控
# up: "30 Mbps" # 若不写单位,默认为 Mbps
# down: "200 Mbps" # 若不写单位,默认为 Mbps
password: $hy_password
sni: $hy_server_name
skip-cert-verify: true
alpn:
- h3
- name: Vmess
type: vmess
server: icook.hk
port: 443
uuid: $vmess_uuid
alterId: 0
cipher: auto
udp: true
tls: true
client-fingerprint: chrome
skip-cert-verify: true
servername: $argo_domain
network: ws
ws-opts:
path: /${ws_path}?ed=2048
headers:
Host: $argo_domain
proxy-groups:
- name: 节点选择
type: select
proxies:
- 自动选择
- Reality
- Hysteria2
- Vmess
- DIRECT
- name: 自动选择
type: url-test #选出延迟最低的机场节点
proxies:
- Reality
- Hysteria2
- Vmess
url: "http://www.gstatic.com/generate_204"
interval: 300
tolerance: 50
rules:
- GEOIP,LAN,DIRECT
- GEOIP,CN,DIRECT
- MATCH,节点选择
EOF
show_notice "sing-box1.8.0及以上客户端配置参数"
cat << EOF
{
"log": {
"level": "debug",
"timestamp": true
},
"experimental": {
"clash_api": {
"external_controller": "127.0.0.1:9090",
"external_ui_download_url": "",
"external_ui_download_detour": "",
"external_ui": "ui",
"secret": "",
"default_mode": "rule"
},
"cache_file": {
"enabled": true,
"store_fakeip": false
}
},
"dns": {
"servers": [
{
"tag": "proxyDns",
"address": "https://8.8.8.8/dns-query",
"detour": "proxy"
},
{
"tag": "localDns",
"address": "https://223.5.5.5/dns-query",
"detour": "direct"
},
{
"tag": "block",
"address": "rcode://success"
},
{
"tag": "remote",
"address": "fakeip"
}
],
"rules": [
{
"domain": [
"ghproxy.com",
"cdn.jsdelivr.net",
"testingcf.jsdelivr.net"
],
"server": "localDns"
},
{
"rule_set": "geosite-category-ads-all",
"server": "block"
},
{
"outbound": "any",
"server": "localDns",
"disable_cache": true
},
{
"rule_set": "geosite-cn",
"server": "localDns"
},
{
"clash_mode": "direct",
"server": "localDns"
},
{
"clash_mode": "global",
"server": "proxyDns"
},
{
"rule_set": "geosite-geolocation-!cn",
"server": "proxyDns"
},
{
"query_type": [
"A",
"AAAA"
],
"server": "remote"
}
],
"fakeip": {
"enabled": true,
"inet4_range": "198.18.0.0/15",
"inet6_range": "fc00::/18"
},
"independent_cache": true,
"strategy": "ipv4_only"
},
"inbounds": [
{
"type": "tun",
"inet4_address": "172.19.0.1/30",
"mtu": 9000,
"auto_route": true,
"strict_route": true,
"sniff": true,
"endpoint_independent_nat": false,
"stack": "system",
"platform": {
"http_proxy": {
"enabled": true,
"server": "127.0.0.1",
"server_port": 2080
}
}
},
{
"type": "mixed",
"listen": "127.0.0.1",
"listen_port": 2080,
"sniff": true,
"users": []
}
],
"outbounds": [
{
"tag": "proxy",
"type": "selector",
"outbounds": [
"auto",
"direct",
"sing-box-reality",
"sing-box-hysteria2",
"sing-box-vmess"
]
},
{
"type": "vless",
"tag": "sing-box-reality",
"uuid": "$reality_uuid",
"flow": "xtls-rprx-vision",
"packet_encoding": "xudp",
"server": "$server_ip",
"server_port": $reality_port,
"tls": {
"enabled": true,
"server_name": "$reality_server_name",
"utls": {
"enabled": true,
"fingerprint": "chrome"
},
"reality": {
"enabled": true,
"public_key": "$public_key",
"short_id": "$short_id"
}
}
},
{
"type": "hysteria2",
"server": "$server_ip",
"server_port": $hy_port,
"tag": "sing-box-hysteria2",
"up_mbps": 100,
"down_mbps": 100,
"password": "$hy_password",
"tls": {
"enabled": true,
"server_name": "$hy_server_name",
"insecure": true,
"alpn": [
"h3"
]
}
},
{
"server": "icook.hk",
"server_port": 443,
"tag": "sing-box-vmess",
"tls": {
"enabled": true,
"server_name": "$argo_domain",
"insecure": true,
"utls": {
"enabled": true,
"fingerprint": "chrome"
}
},
"packet_encoding": "packetaddr",
"transport": {
"headers": {
"Host": [
"$argo_domain"
]
},
"path": "$ws_path",
"type": "ws",
"max_early_data": 2048,
"early_data_header_name": "Sec-WebSocket-Protocol"
},
"type": "vmess",
"security": "auto",
"uuid": "$vmess_uuid"
},
{
"tag": "direct",
"type": "direct"
},
{
"tag": "block",
"type": "block"
},
{
"tag": "dns-out",
"type": "dns"
},
{
"tag": "auto",
"type": "urltest",
"outbounds": [
"sing-box-reality",
"sing-box-hysteria2",
"sing-box-vmess"
],
"url": "http://www.gstatic.com/generate_204",
"interval": "1m",
"tolerance": 50
},
{
"tag": "WeChat",
"type": "selector",
"outbounds": [
"direct",
"sing-box-reality",
"sing-box-hysteria2",
"sing-box-vmess"
]
},
{
"tag": "Apple",
"type": "selector",
"outbounds": [
"direct",
"sing-box-reality",
"sing-box-hysteria2",
"sing-box-vmess"
]
},
{
"tag": "Microsoft",
"type": "selector",
"outbounds": [
"direct",
"sing-box-reality",
"sing-box-hysteria2",
"sing-box-vmess"
]
}
],
"route": {
"auto_detect_interface": true,
"final": "proxy",
"rules": [
{
"protocol": "dns",
"outbound": "dns-out"
},
{
"network": "udp",
"port": 443,
"outbound": "block"
},
{
"rule_set": "geosite-category-ads-all",
"outbound": "block"
},
{
"clash_mode": "direct",
"outbound": "direct"
},
{
"clash_mode": "global",
"outbound": "proxy"
},
{
"domain": [
"clash.razord.top",
"yacd.metacubex.one",
"yacd.haishan.me",
"d.metacubex.one"
],
"outbound": "direct"
},
{
"rule_set": "geosite-wechat",
"outbound": "WeChat"
},
{
"rule_set": "geosite-geolocation-!cn",
"outbound": "proxy"
},
{
"ip_is_private": true,
"outbound": "direct"
},
{
"rule_set": "geoip-cn",
"outbound": "direct"
},
{
"rule_set": "geosite-cn",
"outbound": "direct"
},
{
"rule_set": "geosite-apple",
"outbound": "Apple"
},
{
"rule_set": "geosite-microsoft",
"outbound": "Microsoft"
}
],
"rule_set": [
{
"tag": "geoip-cn",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geoip/cn.srs",
"download_detour": "direct"
},
{
"tag": "geosite-cn",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/cn.srs",
"download_detour": "direct"
},
{
"tag": "geosite-geolocation-!cn",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/geolocation-!cn.srs",
"download_detour": "direct"
},
{
"tag": "geosite-category-ads-all",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/category-ads-all.srs",
"download_detour": "direct"
},
{
"tag": "geosite-wechat",
"type": "remote",
"format": "source",
"url": "https://testingcf.jsdelivr.net/gh/Toperlock/sing-box-geosite@main/wechat.json",
"download_detour": "direct"
},
{
"tag": "geosite-apple",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/apple.srs",
"download_detour": "direct"
},
{
"tag": "geosite-microsoft",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/microsoft.srs",
"download_detour": "direct"
}
]
}
}
EOF
}
#enable bbr
enable_bbr() {
# temporary workaround for installing bbr
bash <(curl -L -s https://raw.githubusercontent.com/teddysun/across/master/bbr.sh)
echo ""
}
modify_singbox() {
#modifying reality configuration
echo ""
warning "开始修改reality端口号和域名"
reality_current_port=$(jq -r '.inbounds[] | select(.tag == "vless-in") | .listen_port' /root/sbox/sbconfig_server.json)
reality_port=$(modify_port "$reality_current_port")
reality_current_server_name=$(jq -r '.inbounds[] | select(.tag == "vless-in") | .tls.server_name' /root/sbox/sbconfig_server.json)
reality_server_name="$reality_current_server_name"
while :; do
read -p "请输入需要偷取证书的网站,必须支持 TLS 1.3 and HTTP/2 (默认: $reality_server_name): " input_server_name
reality_server_name=${input_server_name:-$reality_server_name}
if curl --tlsv1.3 --http2 -sI "https://$reality_server_name" | grep -q "HTTP/2"; then
break
else
echo "域名 $reality_server_name 不支持 TLS 1.3 或 HTTP/2,请重新输入."
fi
done
echo "域名 $reality_server_name 符合."
echo ""
# modifying hysteria2 configuration
warning "开始修改hysteria2端口号"
hy_current_port=$(jq -r '.inbounds[] | select(.tag == "hy2-in") | .listen_port' /root/sbox/sbconfig_server.json)
hy_port=$(modify_port "$hy_current_port")
# 修改sing-box
jq --arg reality_port "$reality_port" \
--arg hy_port "$hy_port" \
--arg reality_server_name "$reality_server_name" \
'
(.inbounds[] | select(.tag == "vless-in") | .listen_port) |= ($reality_port | tonumber) |
(.inbounds[] | select(.tag == "hy2-in") | .listen_port) |= ($hy_port | tonumber) |
(.inbounds[] | select(.tag == "vless-in") | .tls.server_name) |= $reality_server_name |
(.inbounds[] | select(.tag == "vless-in") | .tls.reality.handshake.server) |= $reality_server_name
' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
echo ""
reload_singbox
echo ""
}
uninstall_singbox() {
warning "开始卸载..."
disable_hy2hopping
# Stop and disable services
systemctl stop sing-box argo
systemctl disable sing-box argo > /dev/null 2>&1
# Remove service files
rm -f /etc/systemd/system/sing-box.service
rm -f /etc/systemd/system/argo.service
# Remove configuration and executable files
rm -f /root/sbox/sbconfig_server.json
rm -f /root/sbox/sing-box
rm -f /usr/bin/mianyang
rm -f /root/sbox/mianyang.sh
rm -f /root/sbox/cloudflared-linux
rm -f /root/sbox/self-cert/private.key
rm -f /root/sbox/self-cert/cert.pem
rm -f /root/sbox/config
# Remove directories
rm -rf /root/sbox/self-cert/
rm -rf /root/sbox/
echo "卸载完成"
}
process_warp(){
while :; do
iswarp=$(grep '^WARP_ENABLE=' /root/sbox/config | cut -d'=' -f2)
if [ "$iswarp" = "FALSE" ]; then
warning "warp分流未开启,是否开启(默认解锁openai和奈飞)"
read -p "是否开启? (y/n 默认为y): " confirm
confirm=${confirm:-"y"}
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
enable_warp
else
break
fi
else
warp_option=$(awk -F= '/^WARP_OPTION/{gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}' /root/sbox/config)
case $warp_option in
0)
current_option="手动分流(使用geosite和domain分流)"
;;
1)
current_option="全局分流(接管所有流量)"
;;
*)
current_option="unknow!"
;;
esac
warp_mode=$(awk -F= '/^WARP_MODE/{gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}' /root/sbox/config)
case $warp_mode in
0)
current_mode="Ipv6优先"
current_mode1="warp-IPv6-prefer-out"
;;
1)
current_mode="Ipv4优先"
current_mode1="warp-IPv4-prefer-out"
;;
2)
current_mode="Ipv6仅允许"
current_mode1="warp-IPv6-out"
;;
3)
current_mode="Ipv4仅允许"
current_mode1="warp-IPv4-out"
;;
*)
current_option="unknow!"
;;
esac
echo ""
warning "warp分流已经开启"
echo ""
hint "当前模式为: $current_mode"
hint "当前状态为: $current_option"
echo ""
info "请选择选项:"
echo ""
info "1. 切换为手动分流(geosite和domain分流)"
info "2. 切换为全局分流(接管所有流量)"
info "3. 设置手动分流规则(geosite和domain分流)"
info "4. 切换为warp策略"
info "5. 删除warp解锁"
info "0. 退出"
echo ""
read -p "请输入对应数字(0-5): " warp_input
case $warp_input in
1)
jq '.route.final = "direct"' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
sed -i "s/WARP_OPTION=.*/WARP_OPTION=0/" /root/sbox/config
reload_singbox
;;
2)
jq --arg current_mode1 "$current_mode1" '.route.final = $current_mode1' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
sed -i "s/WARP_OPTION=.*/WARP_OPTION=1/" /root/sbox/config
reload_singbox
;;
4)
while :; do