-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathmenu.sh
More file actions
1252 lines (1113 loc) · 50.1 KB
/
menu.sh
File metadata and controls
1252 lines (1113 loc) · 50.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
source /etc/hysteria/core/scripts/utils.sh
source /etc/hysteria/core/scripts/path.sh
source /etc/hysteria/core/scripts/services_status.sh >/dev/null 2>&1
check_services() {
for service in "${services[@]}"; do
service_base_name=$(basename "$service" .service)
display_name=$(echo "$service_base_name" | sed -E 's/([^-]+)-?/\u\1/g')
if systemctl is-active --quiet "$service"; then
echo -e "${NC}${display_name}:${green} Active${NC}"
else
echo -e "${NC}${display_name}:${red} Inactive${NC}"
fi
done
}
hysteria2_install_handler() {
if systemctl is-active --quiet hysteria-server.service; then
echo "The hysteria-server.service is currently active."
echo "If you need to update the core, please use the 'Update Core' option."
return
fi
while true; do
read -p "Enter the SNI (default: bts.com): " sni
sni=${sni:-bts.com}
read -p "Enter the port number you want to use: " port
if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
echo "Invalid port number. Please enter a number between 1 and 65535."
else
break
fi
done
python3 $CLI_PATH install-hysteria2 --port "$port" --sni "$sni"
cat <<EOF > /etc/hysteria/.configs.env
SNI=$sni
EOF
python3 $CLI_PATH ip-address
}
hysteria2_add_user_handler() {
while true; do
read -p "Enter the username: " username
if [[ "$username" =~ ^[a-zA-Z0-9_-]+$ ]]; then
if [[ -n $(python3 $CLI_PATH get-user -u "$username" 2>/dev/null) ]]; then
echo -e "${red}Error:${NC} Username already exists. Please choose another username."
else
break
fi
else
echo -e "${red}Error:${NC} Username can only contain letters and numbers."
fi
done
read -p "Enter the traffic limit (in GB): " traffic_limit_GB
read -p "Enter the expiration days: " expiration_days
local unlimited_arg=""
while true; do
read -p "Exempt user from IP limit checks (unlimited IP)? (y/n) [n]: " unlimited_choice
case "$unlimited_choice" in
y|Y) unlimited_arg="--unlimited"; break ;;
n|N|"") break ;;
*) echo -e "${red}Error:${NC} Please answer 'y' or 'n'." ;;
esac
done
creation_date=$(date +%Y-%m-%d)
python3 $CLI_PATH add-user --username "$username" --traffic-limit "$traffic_limit_GB" --expiration-days "$expiration_days" --creation-date "$creation_date" $unlimited_arg
}
hysteria2_edit_user_handler() {
prompt_for_input() {
local prompt_message="$1"
local validation_regex="$2"
local default_value="$3"
local input_variable_name="$4"
while true; do
read -p "$prompt_message" input
if [[ -z "$input" ]]; then
input="$default_value"
fi
if [[ "$input" =~ $validation_regex ]]; then
eval "$input_variable_name='$input'"
break
else
echo -e "${red}Error:${NC} Invalid input. Please try again."
fi
done
}
prompt_for_input "Enter the username you want to edit: " '^[a-zA-Z0-9_-]+$' '' username
user_exists_output=$(python3 $CLI_PATH get-user -u "$username" 2>&1)
if [[ -z "$user_exists_output" ]]; then
echo -e "${red}Error:${NC} User '$username' not found or an error occurred."
return 1
fi
prompt_for_input "Enter the new username (leave empty to keep the current username): " '^[a-zA-Z0-9_-]*$' '' new_username
prompt_for_input "Enter the new traffic limit (in GB) (leave empty to keep the current limit): " '^[0-9]*$' '' new_traffic_limit_GB
prompt_for_input "Enter the new expiration days (leave empty to keep the current expiration days): " '^[0-9]*$' '' new_expiration_days
while true; do
read -p "Do you want to generate a new password? (y/n) [n]: " renew_password
case "$renew_password" in
y|Y) renew_password=true; break ;;
n|N|"") renew_password=false; break ;;
*) echo -e "${red}Error:${NC} Please answer 'y' or 'n'." ;;
esac
done
while true; do
read -p "Do you want to generate a new creation date? (y/n) [n]: " renew_creation_date
case "$renew_creation_date" in
y|Y) renew_creation_date=true; break ;;
n|N|"") renew_creation_date=false; break ;;
*) echo -e "${red}Error:${NC} Please answer 'y' or 'n'." ;;
esac
done
local blocked_arg=""
while true; do
read -p "Change user block status? ([b]lock/[u]nblock/[s]kip) [s]: " block_user
case "$block_user" in
b|B) blocked_arg="--blocked"; break ;;
u|U) blocked_arg="--unblocked"; break ;;
s|S|"") break ;;
*) echo -e "${red}Error:${NC} Please answer 'b', 'u', or 's'." ;;
esac
done
local ip_limit_arg=""
while true; do
read -p "Change IP limit status? ([u]nlimited/[l]imited/[s]kip) [s]: " ip_limit_status
case "$ip_limit_status" in
u|U) ip_limit_arg="--unlimited-ip"; break ;;
l|L) ip_limit_arg="--limited-ip"; break ;;
s|S|"") break ;;
*) echo -e "${red}Error:${NC} Please answer 'u', 'l', or 's'." ;;
esac
done
args=()
if [[ -n "$new_username" ]]; then args+=("--new-username" "$new_username"); fi
if [[ -n "$new_traffic_limit_GB" ]]; then args+=("--new-traffic-limit" "$new_traffic_limit_GB"); fi
if [[ -n "$new_expiration_days" ]]; then args+=("--new-expiration-days" "$new_expiration_days"); fi
if [[ "$renew_password" == "true" ]]; then args+=("--renew-password"); fi
if [[ "$renew_creation_date" == "true" ]]; then args+=("--renew-creation-date"); fi
if [[ -n "$blocked_arg" ]]; then args+=("$blocked_arg"); fi
if [[ -n "$ip_limit_arg" ]]; then args+=("$ip_limit_arg"); fi
python3 $CLI_PATH edit-user --username "$username" "${args[@]}"
}
hysteria2_remove_user_handler() {
while true; do
read -p "Enter the username: " username
if [[ "$username" =~ ^[a-zA-Z0-9_-]+$ ]]; then
break
else
echo -e "${red}Error:${NC} Username can only contain letters and numbers."
fi
done
python3 $CLI_PATH remove-user "$username"
}
hysteria2_get_user_handler() {
while true; do
read -p "Enter the username: " username
if [[ "$username" =~ ^[a-zA-Z0-9_-]+$ ]]; then
break
else
echo -e "${red}Error:${NC} Username can only contain letters and numbers."
fi
done
user_data=$(python3 "$CLI_PATH" get-user --username "$username" 2>/dev/null)
local exit_code=$?
if [[ $exit_code -ne 0 || -z "$user_data" ]]; then
echo -e "${red}Error:${NC} User '$username' not found or invalid response."
return 1
fi
if ! echo "$user_data" | jq -e . > /dev/null 2>&1; then
echo -e "${red}Error:${NC} Received invalid data for user '$username'."
return 1
fi
password=$(echo "$user_data" | jq -r '.password // "N/A"')
max_download_bytes=$(echo "$user_data" | jq -r '.max_download_bytes // 0')
upload_bytes=$(echo "$user_data" | jq -r '.upload_bytes // 0')
download_bytes=$(echo "$user_data" | jq -r '.download_bytes // 0')
account_creation_date=$(echo "$user_data" | jq -r '.account_creation_date // "N/A"')
expiration_days=$(echo "$user_data" | jq -r '.expiration_days // 0')
blocked=$(echo "$user_data" | jq -r '.blocked // false')
status=$(echo "$user_data" | jq -r '.status // "N/A"')
total_usage=$((upload_bytes + download_bytes))
max_download_gb=$(echo "scale=2; $max_download_bytes / 1073741824" | bc)
upload_gb=$(echo "scale=2; $upload_bytes / 1073741824" | bc)
download_gb=$(echo "scale=2; $download_bytes / 1073741824" | bc)
total_usage_gb=$(echo "scale=2; $total_usage / 1073741824" | bc)
local expiration_date_str="N/A"
local used_days_str="N/A"
if [[ "$account_creation_date" != "N/A" ]]; then
expiration_date_str=$(date -d "$account_creation_date + $expiration_days days" +"%Y-%m-%d")
current_date=$(date +"%Y-%m-%d")
used_days=$(( ( $(date -d "$current_date" +%s) - $(date -d "$account_creation_date" +%s) ) / 86400 ))
if [[ $used_days -lt 0 ]]; then
used_days=0
fi
if [[ $used_days -gt $expiration_days ]]; then
used_days=$expiration_days
fi
used_days_str=$used_days
fi
echo -e "${green}User Details:${NC}"
echo -e "Username: $username"
echo -e "Password: $password"
echo -e "Total Traffic: $max_download_gb GB"
echo -e "Total Usage: $total_usage_gb GB"
echo -e "Time Expiration: $expiration_date_str ($used_days_str/$expiration_days Days)"
echo -e "Blocked: $blocked"
echo -e "Status: $status"
}
hysteria2_list_users_handler() {
users_json=$(python3 $CLI_PATH list-users 2>/dev/null)
local exit_code=$?
if [ $exit_code -ne 0 ] || [ -z "$users_json" ]; then
echo -e "${red}Error:${NC} Failed to list users."
return 1
fi
if ! echo "$users_json" | jq -e . > /dev/null 2>&1; then
echo -e "${red}Error:${NC} Received invalid data while listing users."
return 1
fi
user_count=$(echo "$users_json" | jq 'length')
if [ "$user_count" -eq 0 ]; then
echo -e "${yellow}No users found.${NC}"
return 1
fi
printf "%-20s %-20s %-15s %-20s %-30s %-10s %-15s %-15s %-15s\n" \
"Username" "Traffic(GB)" "Expiry(Days)" "Created" "Password" "Blocked" "Status" "Down(MB)" "Up(MB)"
echo "$users_json" | jq -r '.[] |
[.username,
(if .max_download_bytes == 0 then "Unlimited" else (.max_download_bytes / 1073741824 | tostring) end),
(if .expiration_days == 0 then "Never" else (.expiration_days | tostring) end),
(.account_creation_date // "N/A"),
.password,
.blocked,
.status,
((.download_bytes // 0) / 1048576 | floor),
((.upload_bytes // 0) / 1048576 | floor)] |
@tsv' | \
while IFS=$'\t' read -r username traffic expiry created password blocked status down up; do
printf "%-20s %-20s %-15s %-20s %-30s %-10s %-15s %-15s %-15s\n" \
"$username" "$traffic" "$expiry" "$created" "$password" "$blocked" "$status" "$down" "$up"
done
}
hysteria2_reset_user_handler() {
while true; do
read -p "Enter the username: " username
if [[ "$username" =~ ^[a-zA-Z0-9_-]+$ ]]; then
break
else
echo -e "${red}Error:${NC} Username can only contain letters and numbers."
fi
done
python3 $CLI_PATH reset-user --username "$username"
}
hysteria2_show_user_uri_handler() {
check_service_active() {
systemctl is-active --quiet "$1"
}
while true; do
read -p "Enter the username: " username
if [[ "$username" =~ ^[a-zA-Z0-9_-]+$ ]]; then
break
else
echo -e "${red}Error:${NC} Username can only contain letters and numbers."
fi
done
flags=""
if check_service_active "hysteria-singbox.service"; then
flags+=" -s"
fi
if check_service_active "hysteria-normal-sub.service"; then
flags+=" -n"
fi
if [[ -n "$flags" ]]; then
python3 $CLI_PATH show-user-uri -u "$username" -a -qr $flags
else
python3 $CLI_PATH show-user-uri -u "$username" -a -qr
fi
}
hysteria2_change_port_handler() {
while true; do
read -p "Enter the new port number you want to use: " port
if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
echo "Invalid port number. Please enter a number between 1 and 65535."
else
break
fi
done
python3 $CLI_PATH change-hysteria2-port --port "$port"
}
hysteria2_change_sni_handler() {
while true; do
read -p "Enter the new SNI (e.g., example.com): " sni
if [[ "$sni" =~ ^[a-zA-Z0-9.]+$ ]]; then
break
else
echo -e "${red}Error:${NC} SNI can only contain letters, numbers, and dots."
fi
done
python3 $CLI_PATH change-hysteria2-sni --sni "$sni"
if systemctl is-active --quiet hysteria-singbox.service; then
systemctl restart hysteria-singbox.service
fi
}
edit_ips() {
while true; do
echo "======================================"
echo " IP/Domain Address Manager "
echo "======================================"
echo "1. Change IPv4 or Domain"
echo "2. Change IPv6 or Domain"
echo "0. Back"
echo "======================================"
read -p "Enter your choice [0-2]: " choice
case $choice in
1)
read -p "Enter the new IPv4 address or domain: " new_ip4_or_domain
if [[ $new_ip4_or_domain =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
if [[ $(echo "$new_ip4_or_domain" | awk -F. '{for (i=1;i<=NF;i++) if ($i>255) exit 1}') ]]; then
echo "Error: Invalid IPv4 address. Values must be between 0 and 255."
else
python3 "$CLI_PATH" ip-address --edit -4 "$new_ip4_or_domain"
echo "IPv4 address has been updated to $new_ip4_or_domain."
fi
elif [[ $new_ip4_or_domain =~ ^[a-zA-Z0-9.-]+$ ]] && [[ ! $new_ip4_or_domain =~ [/:] ]]; then
python3 "$CLI_PATH" ip-address --edit -4 "$new_ip4_or_domain"
echo "Domain has been updated to $new_ip4_or_domain."
else
echo "Error: Invalid IPv4 or domain format."
fi
break
;;
2)
read -p "Enter the new IPv6 address or domain: " new_ip6_or_domain
if [[ $new_ip6_or_domain =~ ^(([0-9a-fA-F]{1,4}:){7}([0-9a-fA-F]{1,4}|:)|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$ ]]; then
python3 "$CLI_PATH" ip-address --edit -6 "$new_ip6_or_domain"
echo "IPv6 address has been updated to $new_ip6_or_domain."
elif [[ $new_ip6_or_domain =~ ^[a-zA-Z0-9.-]+$ ]] && [[ ! $new_ip6_or_domain =~ [/:] ]]; then
python3 "$CLI_PATH" ip-address --edit -6 "$new_ip6_or_domain"
echo "Domain has been updated to $new_ip6_or_domain."
else
echo "Error: Invalid IPv6 or domain format."
fi
break
;;
0)
break
;;
*)
echo "Invalid option. Please try again."
break
;;
esac
echo "======================================"
read -p "Press Enter to continue..."
done
}
hysteria_upgrade(){
bash <(curl https://raw.githubusercontent.com/ReturnFI/Blitz/main/upgrade.sh)
}
warp_configure_handler() {
local service_name="wg-quick@wgcf.service"
if systemctl is-active --quiet "$service_name"; then
echo -e "${cyan}=== WARP Status ===${NC}"
status_json=$(python3 $CLI_PATH warp-status)
all_traffic=$(echo "$status_json" | grep -o '"all_traffic_via_warp": *[^,}]*' | cut -d':' -f2 | tr -d ' "')
popular_sites=$(echo "$status_json" | grep -o '"popular_sites_via_warp": *[^,}]*' | cut -d':' -f2 | tr -d ' "')
domestic_sites_via_warp=$(echo "$status_json" | grep -o '"domestic_sites_via_warp": *[^,}]*' | cut -d':' -f2 | tr -d ' "')
block_adult=$(echo "$status_json" | grep -o '"block_adult_content": *[^,}]*' | cut -d':' -f2 | tr -d ' "')
display_status() {
local label="$1"
local status_val="$2"
if [ "$status_val" = "true" ]; then
echo -e " ${green}✓${NC} $label: ${green}Enabled${NC}"
else
echo -e " ${red}✗${NC} $label: ${red}Disabled${NC}"
fi
}
display_status "All Traffic via WARP" "$all_traffic"
display_status "Popular Sites via WARP" "$popular_sites"
display_status "Domestic Sites via WARP" "$domestic_sites_via_warp"
display_status "Block Adult Content" "$block_adult"
echo -e "${cyan}==================${NC}"
echo
echo "Configure WARP Options (Toggle):"
echo "1. All traffic via WARP"
echo "2. Popular sites via WARP"
echo "3. Domestic sites (WARP/Reject)"
echo "4. Block adult content"
echo "5. WARP Status Profile (IP etc.)"
echo "6. Change WARP IP address"
echo "7. Switch to WARP Plus"
echo "8. Switch to Normal WARP"
echo "0. Cancel"
read -p "Select an option to toggle: " option
case $option in
1)
target_state=$([ "$all_traffic" = "true" ] && echo "off" || echo "on")
python3 $CLI_PATH configure-warp --set-all "$target_state" ;;
2)
target_state=$([ "$popular_sites" = "true" ] && echo "off" || echo "on")
python3 $CLI_PATH configure-warp --set-popular-sites "$target_state" ;;
3)
target_state=$([ "$domestic_sites_via_warp" = "true" ] && echo "off" || echo "on")
python3 $CLI_PATH configure-warp --set-domestic-sites "$target_state" ;;
4)
target_state=$([ "$block_adult" = "true" ] && echo "off" || echo "on")
python3 $CLI_PATH configure-warp --set-block-adult-sites "$target_state" ;;
5)
current_ip=$(python3 $CLI_PATH warp-status | grep -o '"ip": *"[^"]*"' | cut -d':' -f2- | tr -d '" ')
if [ -z "$current_ip" ]; then
current_ip=$(curl -s --interface wgcf --connect-timeout 1 http://v4.ident.me || echo "N/A")
fi
cd /etc/warp/ && wgcf status
echo
echo -e "${yellow}Warp IP:${NC} ${cyan}${current_ip}${NC}"
;;
6)
old_ip=$(curl -s --interface wgcf --connect-timeout 1 http://v4.ident.me || echo "N/A")
echo -e "${yellow}Current IP:${NC} ${cyan}$old_ip${NC}"
echo "Restarting $service_name to attempt IP change..."
systemctl restart "$service_name"
echo -n "Waiting for service to restart"
for i in {1..5}; do
echo -n "."
sleep 1
done
echo
new_ip=$(curl -s --interface wgcf --connect-timeout 1 http://v4.ident.me || echo "N/A")
echo -e "${yellow}New IP:${NC} ${green}$new_ip${NC}"
if [ "$old_ip" != "N/A" ] && [ "$new_ip" != "N/A" ] && [ "$old_ip" != "$new_ip" ]; then
echo -e "${green}✓ IP address changed successfully${NC}"
elif [ "$old_ip" = "$new_ip" ] && [ "$old_ip" != "N/A" ]; then
echo -e "${yellow}⚠ IP address remained the same${NC}"
else
echo -e "${red}✗ Could not verify IP change.${NC}"
fi
;;
7)
echo -e "${yellow}Switching to WARP Plus...${NC}"
read -p "Enter your WARP Plus license key: " warp_key
if [ -z "$warp_key" ]; then
echo -e "${red}Error: WARP Plus key is required.${NC}"
else
echo "Stopping WARP service..."
systemctl stop "$service_name" 2>/dev/null
cd /etc/warp/ || { echo -e "${red}Failed to change directory to /etc/warp/${NC}"; return 1; }
echo "Updating WARP Plus configuration..."
WGCF_LICENSE_KEY="$warp_key" wgcf update
if [ $? -eq 0 ]; then
echo "Starting WARP service..."
systemctl start "$service_name"
echo -e "${green}✓ Successfully switched to WARP Plus${NC}"
python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1
else
echo -e "${red}✗ Failed to update WARP Plus configuration${NC}"
systemctl start "$service_name"
fi
fi
;;
8)
echo -e "${yellow}Switching to Normal WARP...${NC}"
echo "This will create a new WARP account. Continue? (y/N)"
read -p "" confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
echo "Stopping WARP service..."
systemctl stop "$service_name" 2>/dev/null
cd /etc/warp/ || { echo -e "${red}Failed to change directory to /etc/warp/${NC}"; return 1; }
echo "Creating new WARP account..."
rm -f wgcf-account.toml
yes | wgcf register
if [ $? -eq 0 ]; then
echo "Starting WARP service..."
systemctl start "$service_name"
echo -e "${green}✓ Successfully switched to Normal WARP with new account${NC}"
python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1
else
echo -e "${red}✗ Failed to register new WARP account${NC}"
systemctl start "$service_name"
fi
else
echo -e "${yellow}Operation canceled${NC}"
fi
;;
0) echo "WARP configuration canceled." ;;
*) echo -e "${red}Invalid option. Please try again.${NC}" ;;
esac
else
echo -e "${red}$service_name is not active. Please start the service before configuring WARP.${NC}"
fi
}
telegram_bot_handler() {
while true; do
echo -e "${cyan}1.${NC} Start Telegram bot service"
echo -e "${red}2.${NC} Stop Telegram bot service"
echo "0. Back"
read -p "Choose an option: " option
case $option in
1)
if systemctl is-active --quiet hysteria-telegram-bot.service; then
echo "The hysteria-telegram-bot.service is already active."
else
while true; do
read -e -p "Enter the Telegram bot token: " token
if [ -z "$token" ]; then
echo "Token cannot be empty. Please try again."
else
break
fi
done
while true; do
read -e -p "Enter the admin IDs (comma-separated): " admin_ids
if [[ ! "$admin_ids" =~ ^[0-9,]+$ ]]; then
echo "Admin IDs can only contain numbers and commas. Please try again."
elif [ -z "$admin_ids" ]; then
echo "Admin IDs cannot be empty. Please try again."
else
break
fi
done
python3 $CLI_PATH telegram -a start -t "$token" -aid "$admin_ids"
fi
;;
2)
python3 $CLI_PATH telegram -a stop
;;
0)
break
;;
*)
echo "Invalid option. Please try again."
;;
esac
done
}
singbox_handler() {
echo -e "${red} Deprecated${NC}"
}
normalsub_handler() {
while true; do
echo -e "${cyan}1.${NC} Start Normal-Sub service"
echo -e "${red}2.${NC} Stop Normal-Sub service"
echo -e "${yellow}3.${NC} Change SUBPATH"
echo "0. Back"
read -p "Choose an option: " option
case $option in
1)
if systemctl is-active --quiet hysteria-normal-sub.service; then
echo "The hysteria-normal-sub.service is already active."
else
while true; do
read -e -p "Enter the domain name for the SSL certificate: " domain
if [ -z "$domain" ]; then
echo "Domain name cannot be empty. Please try again."
else
break
fi
done
while true; do
read -e -p "Enter the port number for the service: " port
if [ -z "$port" ]; then
echo "Port number cannot be empty. Please try again."
elif ! [[ "$port" =~ ^[0-9]+$ ]]; then
echo "Port must be a number. Please try again."
else
break
fi
done
python3 $CLI_PATH normal-sub -a start -d "$domain" -p "$port"
fi
;;
2)
if ! systemctl is-active --quiet hysteria-normal-sub.service; then
echo "The hysteria-normal-sub.service is already inactive."
else
python3 $CLI_PATH normal-sub -a stop
fi
;;
3)
if ! systemctl is-active --quiet hysteria-normal-sub.service; then
echo "Error: The hysteria-normal-sub.service is not active. Start the service first."
continue
fi
while true; do
read -e -p "Enter new SUBPATH (Must include Uppercase, Lowercase, and Numbers): " subpath
if [[ -z "$subpath" ]]; then
echo "Error: SUBPATH cannot be empty. Please try again."
elif ! [[ "$subpath" =~ [A-Z] ]] || ! [[ "$subpath" =~ [a-z] ]] || ! [[ "$subpath" =~ [0-9] ]]; then
echo "Error: SUBPATH must include at least one uppercase letter, one lowercase letter, and one number."
else
python3 $CLI_PATH normal-sub -a edit_subpath -sp "$subpath"
break
fi
done
;;
0)
break
;;
*)
echo "Invalid option. Please try again."
;;
esac
done
}
webpanel_handler() {
service_status=$(python3 "$CLI_PATH" get-webpanel-services-status)
echo -e "${cyan}Services Status:${NC}"
echo "$service_status"
echo ""
while true; do
echo -e "${cyan}1.${NC} Start WebPanel service"
echo -e "${red}2.${NC} Stop WebPanel service"
echo -e "${cyan}3.${NC} Get WebPanel URL"
echo -e "${cyan}4.${NC} Show API Token"
echo -e "${yellow}5.${NC} Reset WebPanel Credentials"
echo -e "${yellow}6.${NC} Change Domain/Port"
echo -e "${yellow}7.${NC} Change Root Path"
echo -e "${yellow}8.${NC} Change Session Expiration"
echo "0. Back"
read -p "Choose an option: " option
case $option in
1)
if systemctl is-active --quiet hysteria-webpanel.service; then
echo "The hysteria-webpanel.service is already active."
else
while true; do
read -e -p "Enter the domain name for the SSL certificate: " domain
if [ -z "$domain" ]; then
echo "Domain name cannot be empty. Please try again."
else
break
fi
done
while true; do
read -e -p "Enter the port number for the service: " port
if [ -z "$port" ]; then
echo "Port number cannot be empty. Please try again."
elif ! [[ "$port" =~ ^[0-9]+$ ]]; then
echo "Port must be a number. Please try again."
else
break
fi
done
while true; do
read -e -p "Enter the admin username: " admin_username
if [ -z "$admin_username" ]; then
echo "Admin username cannot be empty. Please try again."
else
break
fi
done
while true; do
read -sp "Enter the admin password: " admin_password
echo ""
if [ -z "$admin_password" ]; then
echo "Admin password cannot be empty. Please try again."
continue
fi
local check_password
read -sp "Enter the admin password again: " check_password
echo ""
if [ -z "$check_password" ]; then
echo "Admin password cannot be empty. Please try again."
continue
fi
if [ "$check_password" == "$admin_password" ]; then
echo "Password is set!"
break
fi
echo "Passwords did NOT match. Please try again."
done
python3 $CLI_PATH webpanel -a start -d "$domain" -p "$port" -au "$admin_username" -ap "$admin_password"
fi
;;
2)
if ! systemctl is-active --quiet hysteria-webpanel.service; then
echo "The hysteria-webpanel.service is already inactive."
else
python3 $CLI_PATH webpanel -a stop
fi
;;
3)
url=$(python3 $CLI_PATH get-webpanel-url)
echo "-------------------------------"
echo "$url"
echo "-------------------------------"
;;
4)
api_token=$(python3 $CLI_PATH get-webpanel-api-token)
echo "-------------------------------"
echo "$api_token"
echo "-------------------------------"
;;
5)
if ! systemctl is-active --quiet hysteria-webpanel.service; then
echo -e "${red}WebPanel service is not running. Cannot reset credentials.${NC}"
else
read -e -p "Enter new admin username (leave blank to keep current): " new_username
read -e -p "Enter new admin password (leave blank to keep current): " new_password
echo
if [ -z "$new_username" ] && [ -z "$new_password" ]; then
echo -e "${yellow}No changes specified. Aborting.${NC}"
else
local cmd_args=("-u" "$new_username")
if [ -n "$new_password" ]; then
cmd_args+=("-p" "$new_password")
fi
if [ -z "$new_username" ]; then
cmd_args=()
if [ -n "$new_password" ]; then
cmd_args+=("-p" "$new_password")
fi
fi
echo "Attempting to reset credentials..."
python3 "$CLI_PATH" reset-webpanel-creds "${cmd_args[@]}"
fi
fi
;;
6)
if ! systemctl is-active --quiet hysteria-webpanel.service; then
echo -e "${red}WebPanel service is not running. Cannot perform this action.${NC}"
else
read -e -p "Enter new domain (leave blank to keep current): " new_domain
read -e -p "Enter new port (leave blank to keep current): " new_port
if [ -z "$new_domain" ] && [ -z "$new_port" ]; then
echo -e "${yellow}No changes specified. Aborting.${NC}"
else
local cmd_args=()
if [ -n "$new_domain" ]; then
cmd_args+=("--domain" "$new_domain")
fi
if [ -n "$new_port" ]; then
cmd_args+=("--port" "$new_port")
fi
echo "Attempting to change domain/port..."
python3 "$CLI_PATH" change-webpanel-domain-port "${cmd_args[@]}"
fi
fi
;;
7)
if ! systemctl is-active --quiet hysteria-webpanel.service; then
echo -e "${red}WebPanel service is not running. Cannot perform this action.${NC}"
else
read -e -p "Enter new root path (leave blank for random): " new_root_path
local cmd_args=()
if [ -n "$new_root_path" ]; then
cmd_args+=("--path" "$new_root_path")
fi
echo "Attempting to change root path..."
python3 "$CLI_PATH" change-webpanel-root "${cmd_args[@]}"
fi
;;
8)
if ! systemctl is-active --quiet hysteria-webpanel.service; then
echo -e "${red}WebPanel service is not running. Cannot perform this action.${NC}"
else
while true; do
read -e -p "Enter new session expiration in minutes: " new_minutes
if [[ "$new_minutes" =~ ^[0-9]+$ ]]; then
break
else
echo -e "${red}Error:${NC} Please enter a valid number."
fi
done
echo "Attempting to change session expiration..."
python3 "$CLI_PATH" change-webpanel-exp --minutes "$new_minutes"
fi
;;
0)
break
;;
*)
echo "Invalid option. Please try again."
;;
esac
done
}
obfs_handler() {
while true; do
echo -e "${cyan}1.${NC} Remove Obfs"
echo -e "${red}2.${NC} Generating new Obfs"
echo "0. Back"
read -p "Choose an option: " option
case $option in
1)
python3 $CLI_PATH manage_obfs -r
;;
2)
status=$(python3 $CLI_PATH masquerade -s)
if [[ "$status" == "Enabled" ]]; then
echo -e "${red}Error:${NC} Cannot use Obfs when masquerade is enabled."
else
python3 $CLI_PATH manage_obfs -g
fi
;;
0)
break
;;
*)
echo "Invalid option. Please try again."
;;
esac
done
}
geo_update_handler() {
echo "Configure Geo Update Options:"
echo "1. Update Iran Geo Files"
echo "2. Update China Geo Files"
echo "3. Update Russia Geo Files"
echo "4. Check Current Geo Files"
echo "0. Cancel"
read -p "Select an option: " option
case $option in
1)
echo "Updating Iran Geo Files..."
python3 $CLI_PATH update-geo --country iran
;;
2)
echo "Updating China Geo Files..."
python3 $CLI_PATH update-geo --country china
;;
3)
echo "Updating Russia Geo Files..."
python3 $CLI_PATH update-geo --country russia
;;
4)
echo "Current Geo Files Information:"
echo "--------------------------"
if [ -f "/etc/hysteria/geosite.dat" ]; then
echo "GeoSite File:"
ls -lh /etc/hysteria/geosite.dat
echo "Last modified: $(stat -c %y /etc/hysteria/geosite.dat)"
else
echo "GeoSite file not found!"
fi
echo
if [ -f "/etc/hysteria/geoip.dat" ]; then
echo "GeoIP File:"
ls -lh /etc/hysteria/geoip.dat
echo "Last modified: $(stat -c %y /etc/hysteria/geoip.dat)"
else
echo "GeoIP file not found!"
fi
;;
0)
echo "Geo update configuration canceled."
;;
*)
echo "Invalid option. Please try again."
;;
esac
}
masquerade_handler() {
while true; do
status=$(python3 $CLI_PATH masquerade -s)
echo "--------------------------"
if [ "$status" == "Enabled" ]; then
echo -e "Masquerade Status: ${green}${status}${NC}"
else
echo -e "Masquerade Status: ${red}${status}${NC}"
fi
echo "--------------------------"
echo -e "${cyan}1.${NC} Enable Masquerade"
echo -e "${cyan}2.${NC} Remove Masquerade"
echo "0. Back"
read -p "Choose an option: " option
case $option in
1)
obfs_status=$(python3 $CLI_PATH manage_obfs --check 2>/dev/null)
if [[ "$obfs_status" == "OBFS is active." ]]; then
echo -e "${red}Error:${NC} Cannot enable Masquerade while OBFS is active. Please disable OBFS first."
else
python3 $CLI_PATH masquerade -e
fi
;;
2)
python3 $CLI_PATH masquerade -r
;;
0)
break
;;
*)
echo "Invalid option. Please try again."
;;
esac
done
}
ip_limit_handler() {