forked from Soroushnk/Astro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Astro.sh
1844 lines (1671 loc) · 93.1 KB
/
Astro.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
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
GRAY='\033[0;37m'
NC='\033[0m' # No Color
#Check if user is root
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root"
sleep .5
su -s /bin/bash -c "$0 $*" root
exit 1
fi
echo "Running as root..."
sleep .5
clear
while true; do
clear
echo -e "${YELLOW}+--------------------------------------------------+${NC}"
echo -e "${YELLOW}| |${NC}"
echo -e "${GREEN}|${GREEN} ______ _____ ${GREEN}|${NC}"
echo -e "${BLUE}|${GREEN} ___ |________ /_____________ ${BLUE}|${NC}"
echo -e "${BLUE}|${GREEN} __ /| |_ ___/ __/_ ___/ __ \ ${BLUE}|${NC}"
echo -e "${BLUE}|${GREEN} _ ___ |(__ )/ / _ _ / / /_/ / ${BLUE}|${NC}"
echo -e "${BLUE}|${GREEN} /_/ |_/____/ \__/ /_/ \____/ ${BLUE}|${NC}"
echo -e "${BLUE}| ${RED}ver 1.2 ${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${NC} B Y ${BLUE}|${NC}"
echo -e "${BLUE}|${NC} A T O M I C B O Y S ${BLUE}|${NC}"
echo -e "${BLUE}| --------------------------- |${NC}"
echo -e "${BLUE}| ${YELLOW}Main Menu${BLUE} |${NC}"
echo -e "${YELLOW}|--------------------------------------------------|${NC}"
echo -e "${BLUE}| |${NC}"
echo -e "${BLUE}|${GREEN} ------------ Server Tools ------------ ${BLUE}|${NC}"
echo -e "${BLUE}| |${NC}"
echo -e "${BLUE}|${YELLOW} 1.${NC} ${CYAN}Update server and install dependences${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW} 2.${NC} ${GRAY}Change SSH port${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW} 3.${NC} ${CYAN}Add user (for SSH)${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW} 4.${NC} ${GRAY}Server Backup${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW} 5.${NC} ${CYAN}Tunnel two server using IPtables${NC} ${BLUE}|${NC}" # TODO add multiplie methods
echo -e "${BLUE}|${YELLOW} 6.${NC} ${GRAY}View system usage${NC} ${BLUE}|${NC}" # update that
echo -e "${BLUE}|${YELLOW} 7.${NC} ${CYAN}change reposiroy${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW} 8.${NC} ${GRAY}change nameserver${NC} ${BLUE}|${NC}"
echo -e "${BLUE}| |${NC}"
echo -e "${GREEN}| --------------- V2ray -------------- |${NC}"
echo -e "${BLUE}| |${NC}"
echo -e "${BLUE}|${YELLOW} 9.${NC} ${GRAY}Install panel${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW} 10.${NC} ${CYAN}reality.ez${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW} 11.${NC} ${GRAY}Manage X-UI${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW} 12.${NC} ${CYAN}Install and config ssl ${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW} 13.${NC} ${GRAY}Reality Protocol${NC} ${BLUE}|${NC}"
echo -e "${BLUE}| |${NC}"
echo -e "${GREEN}| ------------ VPN configure ----------- |${NC}"
echo -e "${BLUE}| |${NC}"
echo -e "${BLUE}|${YELLOW}14.${NC} ${CYAN}Cisco anyconnect${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW}15.${NC} ${GRAY}Install OpenVPN${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW}16.${NC} ${CYAN}Set up Outline${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW}17.${NC} ${GRAY}Set up wiregaurd${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW}18.${NC} ${CYAN}Set up IPsec VPN(L2TP/IKEV2)${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW}19.${NC} ${GRAY}Install Mtproto proxy${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW}20.${NC} ${GRAY}SSH panel${NC} ${BLUE}|${NC}"
echo -e "${BLUE}| |${NC}"
echo -e "${GREEN}| ------------ Side tools ------------- |${NC}"
echo -e "${BLUE}| |${NC}"
echo -e "${BLUE}|${YELLOW}21.${NC} ${CYAN}Google Recapcha Fix${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW}22.${NC} ${GRAY}Cloudflare white IP scanner${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW}23.${NC} ${CYAN}Speedtest${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW}24.${NC} ${GRAY}Install and config WordPress${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW}25.${NC} ${CYAN}Reverse proxy(UNDER development)${NC} ${BLUE}|${NC}"
echo -e "${BLUE}| |${NC}"
echo -e "${GREEN}| ---------------- other -------------- |${NC}"
echo -e "${BLUE}| |${NC}"
echo -e "${BLUE}|${YELLOW}26.${NC} ${GREEN}CREDITS${NC} ${BLUE}|${NC}"
echo -e "${BLUE}|${YELLOW}0.${NC} ${RED}QUIT${NC} ${BLUE}|${NC}"
echo -e "${GREEN}| |${NC}"
echo -e "${YELLOW}| |${NC}"
echo -e "${YELLOW}+--------------------------------------------------+${NC}"
echo -e ""
echo -e "${GREEN}Please choose an option:${NC}"
echo -e ""
read -p "Enter option number: " choice
case $choice in
#UPDATE SEVER
1)
echo -e "${GREEN}Updating server...${NC}"
echo ""
apt update && apt upgrade -y
sudo apt install git wget curl ufw wget
echo ""
echo -e "Press ${RED}ENTER${NC} to continue"
read -s -n 1
;;
2)
echo -e "${GREEN}Changing SSH port...${NC}"
echo ""
read -p "Enter a new port number: " new_port
sed -i "s/#Port 22/Port $new_port/" /etc/ssh/sshd_config
sed -i "s/#Port/Port/" /etc/ssh/sshd_config
systemctl restart sshd.service
ufw allow $new_port/tcp
echo ""
echo -e "Press ${RED}ENTER${NC} to continue"
read -s -n 1
;;
3)
echo -e "${GREEN}Adding user...${NC}"
echo ""
read -p "Enter username: " username
adduser $username
echo ""
echo -e "Press ${RED}ENTER${NC} to continue"
read -s -n 1
;;
4)
# Function to prompt user for source server details
function get_source_details {
read -p "Enter the hostname of the source server: " SRC_HOST
read -p "Enter the username of the source server: " SRC_USER
read -s -p "Enter the password of the source server: " SRC_PASS
echo
}
# Function to prompt user for destination server details
function get_destination_details {
read -p "Enter the hostname of the destination server: " DEST_HOST
read -p "Enter the username of the destination server: " DEST_USER
read -s -p "Enter the password of the destination server: " DEST_PASS
echo
}
# Function to prompt user for backup destination directory
function get_backup_directory {
read -p "Enter the backup destination directory (default: /backups): " BACKUP_DIR
BACKUP_DIR=${BACKUP_DIR:-/backups}
}
# Function to transfer backup to destination server
function transfer_backup {
read -p "Enter the name of the backup file to transfer: " backup_file
sshpass -p "$DEST_PASS" scp "$BACKUP_DIR/$backup_file" "$DEST_USER"@"$DEST_HOST:$BACKUP_DIR"
read -p "Backup transferred successfully. Do you want to restore it on the destination server? (y/n): " restore_backup
if [[ "$restore_backup" == "y" ]]; then
restore_backup_on_destination
fi
}
# Function to restore backup on destination server
function restore_backup_on_destination {
read -p "Enter the name of the backup file to restore: " backup_file
sshpass -p "$DEST_PASS" ssh "$DEST_USER"@"$DEST_HOST" "tar xzf $BACKUP_DIR/$backup_file -C /"
echo "Backup restored successfully on the destination server."
read -p "Press Enter to continue."
}
# Main menu loop
while true; do
clear
echo "Menu:"
echo "1. Enter source server details"
echo "2. Enter destination server details"
echo "3. Enter backup destination directory"
echo "4. Install rsnapshot"
echo "5. Configure rsnapshot"
echo "6. Take snapshot"
echo "7. Transfer backup to destination server"
echo "8. Exit"
read -p "Enter your choice: " choice
case $choice in
1)
get_source_details
;;
2)
get_destination_details
;;
3)
get_backup_directory
;;
4)
echo "Installing rsnapshot..."
apt-get update
apt-get install -y rsnapshot
echo "Rsnapshot installed successfully."
read -p "Press Enter to continue."
;;
5)
echo "Configuring rsnapshot..."
# Backup source directories
echo "backup /etc/ localhost/" >> /etc/rsnapshot.conf
echo "backup /etc/x-ui localhost/" >> /etc/rsnapshot.conf
echo "backup /etc/oscerv localhost/" >> /etc/rsnapshot.conf
echo "backup /home/ localhost/" >> /etc/rsnapshot.conf
echo "backup /var/log/ localhost/" >> /etc/rsnapshot.conf
# Backup destination directory
echo "snapshot_root $BACKUP_DIR/" >> /etc/rsnapshot.conf
# Backup intervals
echo "interval hourly 6" >> /etc/rsnapshot.conf
echo "interval daily 7" >> /etc/rsnapshot.conf
echo "interval weekly 4" >> /etc/rsnapshot.conf
echo "interval monthly 3" >> /etc/rsnapshot.conf
echo "Rsnapshot configured successfully."
read -p "Press Enter to continue."
;;
6)
echo "Taking snapshot..."
rsnapshot hourly
echo "Snapshot taken successfully."
read -p "Press Enter to continue."
;;
7)
transfer_backup
;;
8)
echo "Exiting program."
break
;;
*)
echo "Invalid choice. Please try again."
read -p "Press Enter to continue."
;;
esac
done
;;
5)
# Function to add the iptables commands to crontab
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
GRAY='\033[0;37m'
NC='\033[0m' # No Color
while true; do
clear
# show options to user
echo -e "${YELLOW}1.${NC} ${YELLOW}Install iptables${NC}"
echo -e "${YELLOW}2.${NC} ${NC}Display forwarding table${NC}"
echo -e "${YELLOW}3.${NC} ${GREEN}Set up a tunnel${NC}"
echo -e "${YELLOW}4.${NC} ${RED}Delete a tunnel${NC}"
echo -e "${YELLOW}5.${NC} ${NC}1.${NC}Add commands to crontab"
echo -e "${RED}6.${NC} ${BLUE}Back to main menu${NC}"
echo " "
echo "Please choose an option:"
# read user input
read choice
# run appropriate function based on user choice
case $choice in
1)
sudo apt-get update
sudo apt-get install iptables
echo -e "Press ${RED}ENTER${NC} to continue"
read -s -n 1
;;
2)
# Add code to display forwarding table|
iptables -L -n -t nat
;;
3)
echo "Please enter the Iran IP for the tunnel:"
read iran_ip
echo "Please enter the Kharej IP for the tunnel:"
read kharej_ip
echo "Please enter the SSH port (default is 22):"
read ssh_port
sudo sysctl net.ipv4.ip_forward=1
sudo iptables -t nat -A PREROUTING -p tcp -d "$iran_ip" --dport $ssh_port -j DNAT --to-destination "$iran_ip"
sudo iptables -t nat -A PREROUTING -j DNAT -d "$iran_ip" --to-destination "$kharej_ip"
sudo iptables -t nat -A POSTROUTING -j MASQUERADE
echo "Do you want to add the commands to crontab for automatic execution on server reboot? (y/n)"
read add_to_crontab_choice
if [ "$add_to_crontab_choice" == "y" ] || [ "$add_to_crontab_choice" == "Y" ]; then
(crontab -l ; echo "@reboot sudo sysctl net.ipv4.ip_forward=1 && sudo iptables -t nat -A PREROUTING -p tcp --dport $ssh_port -j DNAT --to-destination \"$iran_ip\" && sudo iptables -t nat -A PREROUTING -j DNAT --to-destination \"$kharej_ip\" && sudo iptables -t nat -A POSTROUTING -j MASQUERADE") | crontab -
echo "The iptables commands have been added to the crontab for automatic execution on server reboot."
fi
echo -e "Press ${RED}ENTER${NC} to continue"
read -s -n 1
;;
4)
echo "Please enter the Iran IP for the tunnel to delete:"
read iran_ip
echo "Please enter the Kharej IP for the tunnel to delete:"
read kharej_ip
echo "Please enter the SSH port (default is 22):"
read ssh_port
sudo sysctl net.ipv4.ip_forward=1
sudo iptables -t nat -D PREROUTING -p tcp --dport $ssh_port -j DNAT --to-destination "$iran_ip"
sudo iptables -t nat -D PREROUTING -j DNAT --to-destination "$kharej_ip"
sudo iptables -t nat -D POSTROUTING -j MASQUERADE
echo -e "Press ${RED}ENTER${NC} to continue"
read -s -n 1
;;
5)
(crontab -l ; echo "@reboot sudo sysctl net.ipv4.ip_forward=1 && sudo iptables -t nat -A PREROUTING -p tcp --dport $ssh_port -j DNAT --to-destination \"$iran_ip\" && sudo iptables -t nat -A PREROUTING -j DNAT --to-destination \"$kharej_ip\" && sudo iptables -t nat -A POSTROUTING -j MASQUERADE") | crontab -
echo "The iptables commands have been added to the crontab for automatic execution on server reboot."
echo -e "Press ${RED}ENTER${NC} to continue"
read -s -n 1
;;
6)
break
;;
*)
echo "Invalid choice"
;;
esac
done
echo -e "Press ${RED}ENTER${NC} to continue"
read -s -n 1
;;
6)
# Function to wait for user input and return to menu
function return_to_menu {
read -n1 -r -p "Press any key to return to the menu..."
}
# Function to display the process table
function display_process_table {
# Print table header with color
printf "${YELLOW}%-20s %-10s %-10s %-10s${NC}\n" "Program Name" "CPU Usage" "RAM Usage" "Network Usage"
while true; do
# Get process information with ps command
ps_output=$(ps -e -o comm,%cpu,%mem --sort=-%cpu | head -n 6)
# Extract specific columns with awk command
awk_output=$(echo "$ps_output" | awk '{printf "%-20s %-10s %-10s\n", $1, $2, $3}')
# Get network usage with sar command
sar_output=$(sar -n DEV 1 1 | awk '/ens/ {printf "%-10s", $5}')
# Clear screen and print table header with color
clear
printf "${YELLOW}%-20s %-10s %-10s %-10s${NC}\n" "Program Name" "CPU Usage" "RAM Usage" "Network Usage"
# Print table with color
printf "${GREEN}%s${NC} ${RED}%s${NC}\n" "$awk_output" "$sar_output"
# Wait for 5 seconds before next iteration
sleep 1
done
}
# Print initial menu
while true; do
clear
echo "Please select an option:"
echo "1. View process table"
echo "2. Quit"
read -n1 -r option
case $option in
1)
display_process_table
return_to_menu
;;
2)
# Quit the script
exit 0
;;
*)
# Handle invalid input
echo "Invalid option selected. Please try again."
return_to_menu
;;
esac
done
echo -e "Press ${RED}ENTER${NC} to continue"
read -s -n 1
;;
7)
# Define colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Define menu
menu="
${GREEN}+--------------------------------------------+
¦ ${BLUE}UBUNTU MIRROR SERVER SELECTOR${GREEN} ¦
¦--------------------------------------------¦
¦ ${YELLOW}1${NC}. Select a mirror server ${GREEN} ¦
¦ ${YELLOW}2${NC}. Restore default mirror servers ${GREEN} ¦
¦ ${YELLOW}3${NC}. Display current mirror server ${GREEN} ¦
¦ ${RED}0${NC}. Exit ${GREEN} ¦
+--------------------------------------------+
"
# Define mirror server URLs
main_url="http://archive.ubuntu.com/ubuntu/"
us_url="http://us.archive.ubuntu.com/ubuntu/"
ca_url="http://ca.archive.ubuntu.com/ubuntu/"
uk_url="http://gb.archive.ubuntu.com/ubuntu/"
de_url="http://de.archive.ubuntu.com/ubuntu/"
tr_url="http://ftp.linux.org.tr/ubuntu/"
# Function to update the mirror server URLs in sources.list file
update_mirror_server() {
local server_choice="$1"
case "$server_choice" in
1) sudo sed -i 's|^deb.*http://.*ubuntu.com/ubuntu/|deb '$main_url'|g' /etc/apt/sources.list ;;
2) sudo sed -i 's|^deb.*http://.*ubuntu.com/ubuntu/|deb '$us_url'|g' /etc/apt/sources.list ;;
3) sudo sed -i 's|^deb.*http://.*ubuntu.com/ubuntu/|deb '$ca_url'|g' /etc/apt/sources.list ;;
4) sudo sed -i 's|^deb.*http://.*ubuntu.com/ubuntu/|deb '$uk_url'|g' /etc/apt/sources.list ;;
5) sudo sed -i 's|^deb.*http://.*ubuntu.com/ubuntu/|deb '$de_url'|g' /etc/apt/sources.list ;;
6) sudo sed -i 's|^deb.*http://.*ubuntu.com/ubuntu/|deb '$tr_url'|g' /etc/apt/sources.list ;;
esac
}
# Display menu and read user's choice
while true; do
clear # Clear the screen before displaying the menu
echo -e "$menu"
read -p "Enter your choice: " choice
case "$choice" in
1)
echo -e "${GREEN}Select a mirror server:${NC}"
echo -e " ${YELLOW}1${NC}. Main server: ${main_url}"
echo -e " ${YELLOW}2${NC}. US server: ${us_url}"
echo -e " ${YELLOW}3${NC}. Canada server: ${ca_url}"
echo -e " ${YELLOW}4${NC}. UK server: ${uk_url}"
echo -e " ${YELLOW}5${NC}. Germany server: ${de_url}"
echo -e " ${YELLOW}6${NC}. Turkey server: ${tr_url}"
read -p "Enter your choice (0-6): " server_choice
# Validate user input
if [[ "$server_choice" =~ ^[0-6]$ ]]; then
echo -e "You selected ${YELLOW}${server_choice}${NC}."
read -p "Are you sure you want to update the mirror server? (Y/N): " confirm_choice
if [[ "$confirm_choice" =~ ^[Yy]$ ]]; then
update_mirror_server "$server_choice"
echo -e "${GREEN}Mirror server updated successfully!${NC}"
else
echo -e "${RED}Mirror server update cancelled.${NC}"
fi
else
echo -e "${RED}Invalid choice. Try again.${NC}"
fi
;;
2)
echo -e "${GREEN}Restoring default mirror server URLs...${NC}"
sudo sed -i 's|^deb.*http://.*ubuntu.com/ubuntu/|deb '$main_url'|g' /etc/apt/sources.list
echo -e "${GREEN}Default mirror server URLs restored successfully!${NC}"
;;
3)
echo -e "${GREEN}Current mirror server URL:${NC}"
grep -oP '(?<=^deb ).*(?=/ubuntu/)' /etc/apt/sources.list
;;
0)
echo -e "${RED}Exiting...${NC}"
exit 0
;;
*)
echo -e "${RED}Invalid choice. Try again.${NC}"
;;
esac
read -p "Press Enter to continue..."
done
echo -e "Press ${RED}ENTER${NC} to continue"
read -s -n 1
;;
8)
# Color variables
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Backup and restore original resolv.conf
BACKUP_FILE="/etc/resolv.conf.bak"
# Function to display the current nameservers
function display_nameservers() {
echo -e "${YELLOW}Current nameservers:${NC}"
awk '/nameserver/ {printf "%-3s %s\n", NR".", $2}' /etc/resolv.conf
}
# Function to change nameserver
function change_nameserver() {
# Display current nameservers
display_nameservers
# Prompt for the nameserver number to change
read -p "Enter the number of the nameserver you want to change: " number
# Check if the entered number is valid
if ! [[ "$number" =~ ^[0-9]+$ ]]; then
echo -e "${RED}Invalid number. Please try again.${NC}"
return
fi
# Get the existing nameserver value
existing_nameserver=$(awk -v line_number="$number" 'NR == line_number {print $2}' /etc/resolv.conf)
# Check if the entered number is within range
if [ -z "$existing_nameserver" ]; then
echo -e "${RED}Invalid number. Please try again.${NC}"
return
fi
# Prompt for the new nameserver
read -p "Enter the new nameserver: " new_nameserver
# Validate the new nameserver format
if ! grep -Pq '^(\d{1,3}\.){3}\d{1,3}$' <<< "$new_nameserver"; then
echo -e "${RED}Invalid IP address format. Please try again.${NC}"
return
fi
# Backup original resolv.conf
cp /etc/resolv.conf "$BACKUP_FILE"
# Change the nameserver in resolv.conf
sudo sed -i "s/$existing_nameserver/$new_nameserver/" /etc/resolv.conf
echo -e "${GREEN}Nameserver $number changed from $existing_nameserver to $new_nameserver.${NC}"
}
# Function to add additional nameservers
function add_nameservers() {
# Prompt for new nameservers
read -p "Enter the additional nameserver(s) separated by space: " additional_nameservers
# Add new nameservers to resolv.conf
for ns in $additional_nameservers; do
if grep -Fxq "nameserver $ns" /etc/resolv.conf; then
echo -e "${YELLOW}Nameserver $ns already exists.${NC}"
else
echo "nameserver $ns" | sudo tee -a /etc/resolv.conf > /dev/null
fi
done
echo -e "${GREEN}Additional nameservers added successfully.${NC}"
}
# Main menu
while true; do
echo -e "${BLUE}-------------------"
echo " MENU"
echo -e "-------------------${NC}"
echo -e "${YELLOW}1. Display Nameservers"
echo -e "2. Change Nameserver"
echo -e "3. Add Additional Nameservers"
echo -e "4. Quit${NC}"
echo -e "${BLUE}-------------------${NC}"
read -p "Enter your choice: " option
case $option in
1)
clear
display_nameservers
read -p "Press Enter to continue..."
;;
2)
clear
change_nameserver
read -p "Press Enter to continue..."
;;
3)
clear
add_nameservers
read -p "Press Enter to continue..."
;;
4)
clear
echo -e "${RED}Exiting...${NC}"
# Restore original resolv.conf from backup
if [ -f "$BACKUP_FILE" ]; then
sudo mv "$BACKUP_FILE" /etc/resolv.conf
echo -e "${GREEN}Original resolv.conf restored.${NC}"
fi
break
;;
*)
echo -e "${RED}Invalid option. Please try again.${NC}"
read -p "Press Enter to continue..."
;;
esac
clear
done
echo -e "Press ${RED}ENTER${NC} to continue"
read -s -n 1
;;
# INSTALL X-UI PANEL
9)
while true; do
clear
echo "Please choose a panel to install:"
echo -e "${YELLOW}1.${NC} ${GRAY}hossein assadi's x-ui${NC}"
echo -e "${YELLOW}2.${NC} ${GREEN}vaxilu (original)${NC}"
echo -e "${YELLOW}3.${NC} ${GRAY}hiddify${NC}"
echo -e "${YELLOW}4.${NC} ${GRAY}alireza0 x-ui${NC}"
echo -e "${YELLOW}5.${NC} ${GRAY}3x-ui (MHSanaei)${NC}"
echo -e "${YELLOW}6.${NC} ${GRAY}kafka x-ui${NC}"
echo -e "${YELLOW}7.${NC} ${GRAY}marzban${NC}"
echo -e "${YELLOW}8.${NC} ${RED}Back to Main Menu${NC}"
echo -e""
read -p "Enter option number: " panel_choice
case $panel_choice in
1)
echo -e "${GREEN}Installing panel...${NC}"
echo ""
bash <(curl -Ls https://raw.githubusercontent.com/hossinasaadi/x-ui/master/install.sh)
;;
2)
echo -e "${GREEN}Installing panel...${NC}"
echo ""
bash <(curl -Ls https://raw.githubusercontent.com/vaxilu/x-ui/master/install.sh)
;;
3)
echo -e "${GREEN}Installing panel...${NC}"
echo ""
bash -c "$(curl -Lfo- https://raw.githubusercontent.com/hiddify/hiddify-config/main/common/download_install.sh)"
;;
4)
echo -e "${GREEN}Installing panel...${NC}"
echo ""
bash <(curl -Ls https://raw.githubusercontent.com/alireza0/x-ui/master/install.sh)
;;
5)
echo -e "${GREEN}Installing panel...${NC}"
echo ""
bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh)
;;
6)
echo -e "${GREEN}Installing panel...${NC}"
echo ""
bash <(curl -Ls https://raw.githubusercontent.com/FranzKafkaYu/x-ui/master/install.sh)
;;
7)
echo -e "${GREEN}Installing docker and downloading panel...${NC}"
# Download and install Docker
curl -fsSL https://get.docker.com | sh
# Download and extract the Marzban examples archive
wget -qO- https://github.com/Gozargah/Marzban-examples/releases/latest/download/fully-single-port.tar.gz | tar xz --xform 's/fully-single-port/marzban/' && cd marzban
# Start the Docker Compose environment
docker-compose up -d
# Stop and restart the Docker Compose environment
cd marzban
docker-compose down
docker-compose up -d
;;
8)
break
;;
*)
echo "Invalid panel choice"
;;
esac
done
echo -e "Press ${RED}ENTER${NC} to continue"
read -s -n 1
;;
10)
# Function to read user input with default value
function read_input {
read -p "$1 [$2]: " input
echo "${input:-$2}"
}
# Function to read user choice from a list of options
function read_choice {
PS3="$1: "
select choice in "${@:2}"; do
if [[ -n $choice ]]; then
echo "$choice"
break
fi
done
}
# Function to start the script with default options
function quick_start {
bash <(curl -sL https://raw.githubusercontent.com/aleskxyz/reality-ezpz/master/reality-ezpz.sh)
}
# Function to run the script with user inputs
function manual_configuration {
transport=$(read_choice "Select transport protocol" "tcp" "http" "grpc" "ws")
domain=$(read_input "Enter domain to use as SNI" "www.google.com")
server=$(read_input "Enter IP address or domain name of server" "")
core=$(read_choice "Select core" "sing-box" "xray")
security=$(read_choice "Select type of TLS encryption" "reality" "letsencrypt" "selfsigned")
menu=$(read_input "Show menu? (y/n)" "n")
bash <(curl -sL https://raw.githubusercontent.com/aleskxyz/reality-ezpz/master/reality-ezpz.sh) \
-t "$transport" \
-d "$domain" \
--server "$server" \
-c "$core" \
--security "$security"
}
# Function to manage the script configuration
function manage_configuration {
while true; do
clear
echo -e "\e[92m=============================="
echo " Manage Configuration "
echo "==============================\e[0m"
echo "Select an option:"
echo "1. Add User"
echo "2. List Users"
echo "3. Delete User"
echo "4. Show Server Configuration"
echo "5. Enable Telegram Bot"
echo "6. Restore Default Configuration"
echo "7. Restart Services"
echo "8. Enable SafeNet"
echo "9. Enable Cloudflare Warp"
echo "10. Show Script Menu"
echo "11. Back"
read choice
case $choice in
1)
add_user=$(read_input "Enter username for new user")
bash <(curl -sL https://raw.githubusercontent.com/aleskxyz/reality-ezpz/master/reality-ezpz.sh) \
--add-user "$add_user"
;;
2)
bash <(curl -sL https://raw.githubusercontent.com/aleskxyz/reality-ezpz/master/reality-ezpz.sh) \
--list-users
;;
3)
delete_user=$(read_input "Enter username to delete")
bash <(curl -sL https://raw.githubusercontent.com/aleskxyz/reality-ezpz/master/reality-ezpz.sh) \
--delete-user "$delete_user"
;;
4)
bash <(curl -sL https://raw.githubusercontent.com/aleskxyz/reality-ezpz/master/reality-ezpz.sh) \
--show-server-config
;;
5)
tgbot_token=$(read_input "Enter Telegram bot token")
tgbot_admins=$(read_input "Enter Telegram bot admins (comma separated list of usernames without leading '@')")
bash <(curl -sL https://raw.githubusercontent.com/aleskxyz/reality-ezpz/master/reality-ezpz.sh) \
--enable-tgbot "$tgbot_token" --tgbot-token "$tgbot_token" --tgbot-admins "$tgbot_admins"
;;
6)
bash <(curl -sL https://raw.githubusercontent.com/aleskxyz/reality-ezpz/master/reality-ezpz.sh) \
--default
;;
7)
bash <(curl -sL https://raw.githubusercontent.com/aleskxyz/reality-ezpz/master/reality-ezpz.sh) \
--restart
;;
8)
bash <(curl -sL https://raw.githubusercontent.com/aleskxyz/reality-ezpz/master/reality-ezpz.sh) \
--enable-safenet
;;
9)
bash <(curl -sL https://raw.githubusercontent.com/aleskxyz/reality-ezpz/master/reality-ezpz.sh) \
--enable-warp
;;
10)
bash <(curl -sL https://raw.githubusercontent.com/aleskxyz/reality-ezpz/master/reality-ezpz.sh) \
-m
;;
11)
break
;;
*)
echo "Invalid choice."
;;
esac
done
}
# Main script logic
while true; do
clear
echo -e "\e[95m=============================="
echo " My Awesome Script Menu "
echo "==============================\e[0m"
echo "Select an option:"
echo -e "\e[92m1. Quick Start"
echo "2. Manual Configuration"
echo "3. Manage Configuration"
echo "4. Show Script Menu"
echo -e "5. Exit\e[0m"
read choice
case $choice in
1)
quick_start
;;
2)
manual_configuration
;;
3)
manage_configuration
;;
4)
bash <(curl -sL https://raw.githubusercontent.com/aleskxyz/reality-ezpz/master/reality-ezpz.sh) --m
;;
5)
exit 0
;;
*)
echo "Invalid choice. Press Enter to continue..."
read
;;
esac
done
;;
11)
# Define menu
menu="
${GREEN}╔════════════════════════════════════════════╗
║ ${BLUE}X-UI COMMAND MENU${GREEN} ║
╠════════════════════════════════════════════╣
║ ${YELLOW}1${NC}. Enter control menu ${GREEN}║
║ ${YELLOW}2${NC}. Start X-UI ${GREEN}║
║ ${YELLOW}3${NC}. Stop X-UI ${GREEN}║
║ ${YELLOW}4${NC}. Restart X-UI ${GREEN}║
║ ${YELLOW}5${NC}. Show X-UI status ${GREEN}║
║ ${YELLOW}6${NC}. Enable X-UI on system startup ${GREEN}║
║ ${YELLOW}7${NC}. Disable X-UI on system startup ${GREEN}║
║ ${YELLOW}8${NC}. Check X-UI logs ${GREEN}║
║ ${YELLOW}9${NC}. Update X-UI ${GREEN}║
║ ${YELLOW}10${NC}. Install X-UI ${GREEN}║
║ ${YELLOW}11${NC}. Uninstall X-UI ${GREEN}║
║ ${RED}0${NC}. back to main menu ${GREEN}║
╚════════════════════════════════════════════╝
"
# Display menu and read user's choice
while true; do
echo -e "$menu"
read -p "Enter your choice: " choice
case "$choice" in
1)
echo -e "${GREEN}Entering control menu...${NC}"
x-ui
;;
2)
echo -e "${GREEN}Starting X-UI...${NC}"
x-ui start
;;
3)
echo -e "${GREEN}Stopping X-UI...${NC}"
x-ui stop
;;
4)
echo -e "${GREEN}Restarting X-UI...${NC}"
x-ui restart
;;
5)
echo -e "${GREEN}Showing X-UI status...${NC}"
x-ui status
;;
6)
echo -e "${GREEN}Enabling X-UI on system startup...${NC}"
x-ui enable
;;
7)
echo -e "${GREEN}Disabling X-UI on system startup...${NC}"
x-ui disable
;;
8)
echo -e "${GREEN}Checking X-UI logs...${NC}"
x-ui log
;;
9)
echo -e "${GREEN}Updating X-UI...${NC}"
x-ui update
;;
10)
echo -e "${GREEN}Installing X-UI...${NC}"
x-ui install
;;
11)
echo -e "${GREEN}Uninstalling X-UI...${NC}"
x-ui uninstall
;;
0)
echo -e "${RED}Exiting...${NC}"
break
;;
*)
echo -e "${RED}Invalid choice. Try again.${NC}"
;;
esac
# Wait for user to press Enter before redisplaying menu
read -p "Press Enter to continue..."
done
echo -e "Press ${RED}ENTER${NC} to continue"
read -s -n 1
;;
# DOWNLOADS ACME
12)
echo -e "${GREEN}Installing Acme Script...${NC}"
apt install socat
echo ""
curl https://get.acme.sh | sh
echo ""
echo -e "${GREEN}Configuring Acme...${NC}"
echo ""
sleep 1
echo "Configuring Acme Script..."
echo ""
# GET CERTIFICATE FOR DOMAIN
~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
echo ""
read -p "Enter email address: " email
~/.acme.sh/acme.sh --register-account -m $email
echo ""
read -p "Enter domain name: " domain
~/.acme.sh/acme.sh --issue -d $domain --standalone
~/.acme.sh/acme.sh --installcert -d $domain --key-file /root/private.key --fullchain-file /root/cert.crt
echo ""
echo -e "Press ${RED}ENTER${NC} to continue"
read -s -n 1
;;
13)
# Define a function to display the menu
function display_menu {
clear
echo "Select an option:"
echo "1. Normal Install"
#echo "2. Install with Docker"
echo "2. Uninstall (normal install only)"
echo "3. Quit"
echo
}
# Call the function to display the menu initially
display_menu
# Loop until the user selects the Quit option
while true; do
# Read the user's choice from the command line
read -p "Enter choice [1-4]: " choice
# Handle the user's choice
case $choice in
1)
echo "Performing normal installation..."
bash -c "$(curl -L https://raw.githubusercontent.com/sajjaddg/xray-reality/master/install.sh)"
;;
899)
echo "Performing installation with Docker..."
curl -fsSL https://get.docker.com | sh
git clone https://github.com/sajjaddg/xray-reality && cd xray-reality
docker build -t xrayreality .
docker run -d --name xrayreality -p443:443 xrayreality
docker exec -it xrayreality cat /root/test.url
docker exec -it xrayreality sh -c 'qrencode -s 120 -t ANSIUTF8 $(cat /root/test.url)'
;;
2)
echo "Performing uninstallation..."
bash -c "$(curl -L https://raw.githubusercontent.com/sajjaddg/xray-reality/master/uninstall.sh)"
;;
3)
echo "Goodbye!"
break
;;
*)
echo "Invalid choice. Please try again."
;;
esac