forked from deathline94/sing-REALITY-Box
-
Notifications
You must be signed in to change notification settings - Fork 62
/
tcp-brutal-reality.sh
1467 lines (1398 loc) · 47.1 KB
/
tcp-brutal-reality.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)
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)"
hint "========================="
else
warning "SING-BOX 未运行!"
fi
}
#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/tcp-brutal-reality.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 beta singbox
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-brutal-in") | .listen_port' /root/sbox/sbconfig_server.json)
reality_uuid=$(jq -r '.inbounds[] | select(.tag == "vless-brutal-in") | .users[0].uuid' /root/sbox/sbconfig_server.json)
reality_server_name=$(jq -r '.inbounds[] | select(.tag == "vless-brutal-in") | .tls.server_name' /root/sbox/sbconfig_server.json)
short_id=$(jq -r '.inbounds[] | select(.tag == "vless-brutal-in") | .tls.reality.short_id[0]' /root/sbox/sbconfig_server.json)
brutal_up=$(grep -o "BRUTAL_UP='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
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-brutal"
]
},
{
"type": "vless",
"tag": "sing-box-reality-brutal",
"uuid": "$reality_uuid",
"packet_encoding": "xudp",
"server": "$server_ip",
"server_port": $reality_port,
"flow": "",
"tls": {
"enabled": true,
"server_name": "$reality_server_name",
"utls": {
"enabled": true,
"fingerprint": "chrome"
},
"reality": {
"enabled": true,
"public_key": "$public_key",
"short_id": "$short_id"
}
},
"multiplex": {
"enabled": true,
"protocol": "h2mux",
"max_connections": 1,
"min_streams": 4,
"padding": true,
"brutal": {
"enabled": true,
"up_mbps": 50, //上行速度,windows,macos不会生效所以可随便写
"down_mbps": $brutal_up //下行速度,对应服务器的下行速度,当然可自行修改
}
}
},
{
"tag": "direct",
"type": "direct"
},
{
"tag": "block",
"type": "block"
},
{
"tag": "dns-out",
"type": "dns"
},
{
"tag": "auto",
"type": "urltest",
"outbounds": [
"sing-box-reality-brutal"
],
"url": "http://www.gstatic.com/generate_204",
"interval": "1m",
"tolerance": 50
},
{
"tag": "WeChat",
"type": "selector",
"outbounds": [
"direct",
"sing-box-reality-brutal"
]
},
{
"tag": "Apple",
"type": "selector",
"outbounds": [
"direct",
"sing-box-reality-brutal"
]
},
{
"tag": "Microsoft",
"type": "selector",
"outbounds": [
"direct",
"sing-box-reality-brutal"
]
}
],
"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
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-Brutal
type: vless
server: $server_ip
port: $reality_port
uuid: $reality_uuid
network: tcp
udp: true
tls: true
flow:
servername: $reality_server_name
client-fingerprint: chrome
reality-opts:
public-key: $public_key
short-id: $short_id
smux:
enabled: true
protocol: h2mux
max-connections: 1
min-streams: 4
padding: true
brutal-opts:
enabled: true
up: 50
down: $brutal_up
proxy-groups:
- name: 节点选择
type: select
proxies:
- 自动选择
- Reality-Brutal
- name: 自动选择
type: url-test #选出延迟最低的机场节点
proxies:
- Reality-Brutal
url: "http://www.gstatic.com/generate_204"
interval: 300
tolerance: 50
rules:
- GEOIP,LAN,DIRECT
- GEOIP,CN,DIRECT
- MATCH,节点选择
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端口号和域名"
info "brutal port"
reality_brutal_current_port=$(jq -r '.inbounds[] | select(.tag == "vless-brutal-in") | .listen_port' /root/sbox/sbconfig_server.json)
reality_brutal_port=$(modify_port "$reality_brutal_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 符合."
current_up=$(grep -o "BRUTAL_UP='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
read -p "请输入上行带宽up,对应客户端下行带宽 (当前为 $current_up): " brutal_up
brutal_up=${brutal_up:-$current_up}
current_down=$(grep -o "BRUTAL_DOWN='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
read -p "请输入下行带宽down (当前为 $current_down): " brutal_down
brutal_down=${brutal_down:-$current_down}
echo ""
# 修改sing-box
jq --arg reality_brutal_port "$reality_brutal_port" \
--arg hy_port "$hy_port" \
--arg reality_server_name "$reality_server_name" \
--arg brutal_up "$brutal_up" \
--arg brutal_down "$brutal_down" \
'
(.inbounds[] | select(.tag == "vless-brutal-in") | .listen_port) |= ($reality_brutal_port | tonumber) |
(.inbounds[] | select(.tag == "vless-brutal-in") | .tls.server_name) |= $reality_server_name |
(.inbounds[] | select(.tag == "vless-brutal-in") | .tls.reality.handshake.server) |= $reality_server_name |
(.inbounds[] | select(.tag == "vless-brutal-in") | .multiplex.brutal.up_mbps) |= ($brutal_up | tonumber) |
(.inbounds[] | select(.tag == "vless-brutal-in") | .multiplex.brutal.down_mbps) |= ($brutal_down | tonumber)
' /root/sbox/sbconfig_server.json > /root/sbox/temp.json && mv /root/sbox/temp.json /root/sbox/sbconfig_server.json
echo ""
reload_singbox
echo ""
}
install_brutal(){
bash <(curl -fsSL https://tcp.hy2.sh/)
}
uninstall_singbox() {
warning "开始卸载..."
# Stop and disable services
systemctl stop sing-box
systemctl disable sing-box > /dev/null 2>&1
# Remove service files
rm -f /etc/systemd/system/sing-box.service
# Remove configuration and executable files
rm -f /root/sbox/sbconfig_server.json
rm -f /root/sbox/sing-box
rm -f /root/sbox/mianyang.sh
rm -f /usr/bin/mianyang
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
warning "请选择需要切换的warp策略"
echo ""
hint "当前状态为: $current_option"
echo ""
info "请选择切换的选项:"
echo ""
info "1. Ipv6优先(默认)"
info "2. Ipv4优先"
info "3. 仅允许Ipv6"
info "4. 仅允许Ipv4"
info "0. 退出"
echo ""
read -p "请输入对应数字(0-4): " user_input
user_input=${user_input:-1}
case $user_input in
1)
warp_out="warp-IPv6-prefer-out"
sed -i "s/WARP_MODE=.*/WARP_MODE=0/" /root/sbox/config
break
;;
2)
warp_out="warp-IPv4-prefer-out"
sed -i "s/WARP_MODE=.*/WARP_MODE=1/" /root/sbox/config
break
;;
3)
warp_out="warp-IPv6-out"
sed -i "s/WARP_MODE=.*/WARP_MODE=2/" /root/sbox/config
break
;;
4)
warp_out="warp-IPv4-out"
sed -i "s/WARP_MODE=.*/WARP_MODE=3/" /root/sbox/config
break
;;
0)
# Exit the loop if option 0 is selected
echo "退出warp"
exit 0
;;
*)
# Handle invalid input
echo "无效的输入,请重新输入"
;;
esac
done
jq --arg warp_out "$warp_out" '.route.rules[].outbound |= $warp_out' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
if [ "$warp_option" -ne 0 ]; then
jq --arg warp_out "$warp_out" '.route.final = $warp_out' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
fi
reload_singbox
;;
3)
info "请选择:"
echo ""
info "1. 手动添加geosite分流(适配singbox1.8.0)"
info "2. 手动添加域名关键字匹配分流"
info "0. 退出"
echo ""
read -p "请输入对应数字(0-2): " user_input
case $user_input in
1)
while :; do
echo ""
warning "geosite分流为: "
#域名关键字为
jq '.route.rules[] | select(.rule_set) | .rule_set' /root/sbox/sbconfig_server.json
info "请选择操作:"
echo "1. 添加geosite"
echo "2. 删除geosite"
echo "0. 退出"
echo ""
read -p "请输入对应数字(0-2): " user_input
case $user_input in
1)
#add domain
read -p "请输入要添加的域名关键字(若要添加geosite-openai,输入openai): " new_keyword
url="https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/$new_keyword.srs"
formatted_keyword="geosite-$new_keyword"
# 检查是否存在相同的 geosite 关键字
if jq --arg formatted_keyword "$formatted_keyword" '.route.rules[0].rule_set | any(. == $formatted_keyword)' /root/sbox/sbconfig_server.json | grep -q "true"; then
echo "geosite已存在,不添加重复项: $formatted_keyword"
else
http_status=$(curl -s -o /dev/null -w "%{http_code}" "$url")
if [ "$http_status" -eq 200 ]; then
# 如果不存在,则添加
new_rule='{
"tag": "'"$formatted_keyword"'",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/'"$new_keyword"'.srs",
"download_detour": "direct"
}'
jq --arg formatted_keyword "$formatted_keyword" '.route.rules[0].rule_set += [$formatted_keyword]' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
jq --argjson new_rule "$new_rule" '.route.rule_set += [$new_rule]' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
echo "geosite已添加: $new_rule"
else
echo "geosite srs文件不存在,请重新输入..."
fi
fi
;;
2)
#delete domain keywords
read -p "请输入要删除的域名关键字(若要删除geosite-openai,输入openai) " keyword_to_delete
formatted_keyword="geosite-$keyword_to_delete"
if jq --arg formatted_keyword "$formatted_keyword" '.route.rules[0].rule_set | any(. == $formatted_keyword)' /root/sbox/sbconfig_server.json | grep -q "true"; then
jq --arg formatted_keyword "$formatted_keyword" '.route.rules[0].rule_set -= [$formatted_keyword]' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
#卸载ruleset
jq --arg formatted_keyword "$formatted_keyword" 'del(.route.rule_set[] | select(.tag == $formatted_keyword))' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
echo "域名关键字已删除: $formatted_keyword"
else
echo "域名关键字不存在,不执行删除操作: $formatted_keyword"
fi
;;
0)
echo "退出"
break
;;
*)
echo "无效的输入,请重新输入"
;;
esac
done
break
;;
2)
while :; do
echo ""
warning "域名关键字为: "
#域名关键字为
jq '.route.rules[] | select(.domain_keyword) | .domain_keyword' /root/sbox/sbconfig_server.json
info "请选择操作:"
echo "1. 添加域名关键字"
echo "2. 删除域名关键字"
echo "0. 退出"
echo ""
read -p "请输入对应数字(0-2): " user_input
case $user_input in
1)
#add domain keywords
read -p "请输入要添加的域名关键字: " new_keyword
if jq --arg new_keyword "$new_keyword" '.route.rules[1].domain_keyword | any(. == $new_keyword)' /root/sbox/sbconfig_server.json | grep -q "true"; then
echo "域名关键字已存在,不添加重复项: $new_keyword"
else
jq --arg new_keyword "$new_keyword" '.route.rules[1].domain_keyword += [$new_keyword]' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
echo "域名关键字已添加: $new_keyword"
fi
;;
2)
#delete domain keywords
read -p "请输入要删除的域名关键字: " keyword_to_delete
if jq --arg keyword_to_delete "$keyword_to_delete" '.route.rules[1].domain_keyword | any(. == $keyword_to_delete)' /root/sbox/sbconfig_server.json | grep -q "true"; then
jq --arg keyword_to_delete "$keyword_to_delete" '.route.rules[1].domain_keyword -= [$keyword_to_delete]' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
echo "域名关键字已删除: $keyword_to_delete"
else
echo "域名关键字不存在,不执行删除操作: $keyword_to_delete"
fi
;;
0)
echo "退出"
break
;;
*)
echo "无效的输入,请重新输入"
;;
esac
done
break
;;
0)
# Exit the loop if option 0 is selected
echo "退出"
exit 0
;;
*)
# Handle invalid input
echo "无效的输入"
;;
esac
reload_singbox
break
;;
5)
disable_warp
break
;;
*)
echo "退出"
break