-
Notifications
You must be signed in to change notification settings - Fork 49
/
easymesh.sh
781 lines (651 loc) · 21 KB
/
easymesh.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
#!/bin/bash
# Check if the script is run as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
sleep 1
exit 1
fi
#color codes
GREEN="\033[0;32m"
CYAN="\033[0;36m"
WHITE="\033[1;37m"
RESET="\033[0m"
MAGENTA="\033[0;35m"
# just press key to continue
press_key(){
read -p "Press Enter to continue..."
}
# Define a function to colorize text
colorize() {
local color="$1"
local text="$2"
local style="${3:-normal}"
# Define ANSI color codes
local black="\033[30m"
local red="\033[31m"
local green="\033[32m"
local yellow="\033[33m"
local blue="\033[34m"
local magenta="\033[35m"
local cyan="\033[36m"
local white="\033[37m"
local reset="\033[0m"
# Define ANSI style codes
local normal="\033[0m"
local bold="\033[1m"
local underline="\033[4m"
# Select color code
local color_code
case $color in
black) color_code=$black ;;
red) color_code=$red ;;
green) color_code=$green ;;
yellow) color_code=$yellow ;;
blue) color_code=$blue ;;
magenta) color_code=$magenta ;;
cyan) color_code=$cyan ;;
white) color_code=$white ;;
*) color_code=$reset ;; # Default case, no color
esac
# Select style code
local style_code
case $style in
bold) style_code=$bold ;;
underline) style_code=$underline ;;
normal | *) style_code=$normal ;; # Default case, normal text
esac
# Print the colored and styled text
echo -e "${style_code}${color_code}${text}${reset}"
}
install_easytier() {
# Define the directory and files
DEST_DIR="/root/easytier"
FILE1="easytier-core"
FILE2="easytier-cli"
#URL_X86="https://github.com/EasyTier/EasyTier/releases/download/v1.1.0/easytier-x86_64-unknown-linux-musl-v1.1.0.zip"
#URL_ARM_SOFT="https://github.com/EasyTier/EasyTier/releases/download/v1.1.0/easytier-armv7-unknown-linux-musleabi-v1.1.0.zip"
#URL_ARM_HARD="https://github.com/EasyTier/EasyTier/releases/download/v1.1.0/easytier-armv7-unknown-linux-musleabihf-v1.1.0.zip"
#New Version
URL_X86="https://github.com/Musixal/Easy-Mesh/raw/main/core/v1.2.0/easytier-linux-x86_64/"
URL_ARM_SOFT="https://github.com/Musixal/Easy-Mesh/raw/main/core/v1.2.0/easytier-linux-armv7/"
URL_ARM_HARD="https://github.com/Musixal/Easy-Mesh/raw/main/core/v1.2.0/easytier-linux-armv7hf/"
# Check if the directory exists
if [ -d "$DEST_DIR" ]; then
# Check if the files exist
if [ -f "$DEST_DIR/$FILE1" ] && [ -f "$DEST_DIR/$FILE2" ]; then
colorize green "EasyMesh Core Installed" bold
return 0
fi
fi
# Detect the system architecture
ARCH=$(uname -m)
if [ "$ARCH" = "x86_64" ]; then
URL=$URL_X86
elif [ "$ARCH" = "armv7l" ] || [ "$ARCH" = "aarch64" ]; then
if [ "$(ldd /bin/ls | grep -c 'armhf')" -eq 1 ]; then
URL=$URL_ARM_HARD
else
URL=$URL_ARM_SOFT
fi
else
colorize red "Unsupported architecture: $ARCH\n" bold
return 1
fi
mkdir -p $DEST_DIR &> /dev/null
colorize yellow "Downloading EasyMesh Core...\n"
curl -Ls "$URL/easytier-cli" -o "$DEST_DIR/easytier-cli"
curl -Ls "$URL/easytier-core" -o "$DEST_DIR/easytier-core"
if [ -f "$DEST_DIR/$FILE1" ] && [ -f "$DEST_DIR/$FILE2" ]; then
chmod +x "$DEST_DIR/easytier-cli"
chmod +x "$DEST_DIR/easytier-core"
colorize green "EasyMesh Core Installed Successfully...\n" bold
sleep 1
return 0
else
colorize red "Failed to install EasyMesh Core...\n" bold
exit 1
fi
}
# Call the function
install_easytier
generate_random_secret() {
openssl rand -hex 6
}
#Var
EASY_CLIENT='/root/easytier/easytier-cli'
SERVICE_FILE="/etc/systemd/system/easymesh.service"
connect_network_pool(){
clear
colorize cyan "Connect to the Mesh Network" bold
echo
colorize yellow "Leave the peer addresses blank to enable reverse mode.
Ws and wss modes are not recommended for iran's network environment.
Try disable multi-thread mode if your mesh network is unstable.
UDP mode is more stable rather than tcp mode.
"
echo
read -p "[-] Enter Peer IPv4/IPv6 Addresses (separate multiple addresses by ','): " PEER_ADDRESSES
read -p "[*] Enter Local IPv4 Address (e.g., 10.144.144.1): " IP_ADDRESS
if [ -z $IP_ADDRESS ]; then
colorize red "Null value. aborting..."
sleep 2
return 1
fi
read -r -p "[*] Enter Hostname (e.g., Hetnzer): " HOSTNAME
if [ -z $HOSTNAME ]; then
colorize red "Null value. aborting..."
sleep 2
return 1
fi
read -p "[-] Enter Tunnel Port (Default 2090): " PORT
if [ -z $PORT ]; then
colorize red "Default port is 2090..."
PORT='2090'
fi
echo ''
NETWORK_SECRET=$(generate_random_secret)
colorize cyan "[✓] Generated Network Secret: $NETWORK_SECRET" bold
while true; do
read -p "[*] Enter Network Secret (recommend using a strong password): " NETWORK_SECRET
if [[ -n $NETWORK_SECRET ]]; then
break
else
colorize red "Network secret cannot be empty. Please enter a valid secret.\n"
fi
done
echo ''
colorize green "[-] Select Default Protocol:" bold
echo "1) tcp"
echo "2) udp"
echo "3) ws"
echo "4) wss"
read -p "[*] Select your desired protocol (e.g., 1 for tcp): " PROTOCOL_CHOICE
case $PROTOCOL_CHOICE in
1) DEFAULT_PROTOCOL="tcp" ;;
2) DEFAULT_PROTOCOL="udp" ;;
3) DEFAULT_PROTOCOL="ws" ;;
4) DEFAULT_PROTOCOL="wss" ;;
*) colorize red "Invalid choice. Defaulting to tcp." ; DEFAULT_PROTOCOL="tcp" ;;
esac
echo
read -p "[-] Enable encryption? (yes/no): " ENCRYPTION_CHOICE
case $ENCRYPTION_CHOICE in
[Nn]*)
ENCRYPTION_OPTION="--disable-encryption"
colorize yellow "Encryption is disabled"
;;
*)
ENCRYPTION_OPTION=""
colorize yellow "Encryption is enabled"
;;
esac
echo
read -p "[-] Enable multi-thread? (yes/no): " MULTI_THREAD
case $MULTI_THREAD in
[Nn]*)
MULTI_THREAD=""
colorize yellow "Multi-thread is disabled"
;;
*)
MULTI_THREAD="--multi-thread"
colorize yellow "Multi-thread is enabled"
;;
esac
echo
read -p "[-] Enable IPv6? (yes/no): " IPV6_MODE
case $IPV6_MODE in
[Nn]*)
IPV6_MODE="--disable-ipv6"
colorize yellow "IPv6 is disabled"
;;
*)
IPV6_MODE=""
colorize yellow "IPv6 is enabled"
;;
esac
echo
IFS=',' read -ra ADDR_ARRAY <<< "$PEER_ADDRESSES"
PROCESSED_ADDRESSES=()
for ADDRESS in "${ADDR_ARRAY[@]}"; do
ADDRESS=$(echo $ADDRESS | xargs)
if [[ "$ADDRESS" == *:* ]]; then
if [[ "$ADDRESS" != \[*\] ]]; then
ADDRESS="[$ADDRESS]"
fi
fi
if [ ! -z "$ADDRESS" ]; then
PROCESSED_ADDRESSES+=("${DEFAULT_PROTOCOL}://${ADDRESS}:${PORT}")
fi
done
JOINED_ADDRESSES=$(IFS=' '; echo "${PROCESSED_ADDRESSES[*]}")
if [ ! -z "$JOINED_ADDRESSES" ]; then
PEER_ADDRESS="--peers ${JOINED_ADDRESSES}"
fi
LISTENERS="--listeners ${DEFAULT_PROTOCOL}://[::]:${PORT} ${DEFAULT_PROTOCOL}://0.0.0.0:${PORT}"
SERVICE_FILE="/etc/systemd/system/easymesh.service"
cat > $SERVICE_FILE <<EOF
[Unit]
Description=EasyMesh Network Service
After=network.target
[Service]
ExecStart=/root/easytier/easytier-core -i $IP_ADDRESS $PEER_ADDRESS --hostname $HOSTNAME --network-secret $NETWORK_SECRET --default-protocol $DEFAULT_PROTOCOL $LISTENERS $MULTI_THREAD $ENCRYPTION_OPTION $IPV6_MODE
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd, enable and start the service
sudo systemctl daemon-reload &> /dev/null
sudo systemctl enable easymesh.service &> /dev/null
sudo systemctl start easymesh.service &> /dev/null
colorize green "EasyMesh Network Service Started.\n" bold
press_key
}
display_peers()
{
watch -n1 $EASY_CLIENT peer
}
display_routes(){
watch -n1 $EASY_CLIENT route
}
peer_center(){
watch -n1 $EASY_CLIENT peer-center
}
restart_easymesh_service() {
echo ''
if [[ ! -f $SERVICE_FILE ]]; then
colorize red " EasyMesh service does not exists." bold
sleep 1
return 1
fi
colorize yellow " Restarting EasyMesh service...\n" bold
sudo systemctl restart easymesh.service &> /dev/null
if [[ $? -eq 0 ]]; then
colorize green " EasyMesh service restarted successfully." bold
else
colorize red " Failed to restart EasyMesh service." bold
fi
echo ''
read -p " Press Enter to continue..."
}
remove_easymesh_service() {
echo
if [[ ! -f $SERVICE_FILE ]]; then
colorize red " EasyMesh service does not exists." bold
sleep 1
return 1
fi
colorize yellow " Stopping EasyMesh service..." bold
sudo systemctl stop easymesh.service &> /dev/null
if [[ $? -eq 0 ]]; then
colorize green " EasyMesh service stopped successfully.\n"
else
colorize red " Failed to stop EasyMesh service.\n"
sleep 2
return 1
fi
colorize yellow " Disabling EasyMesh service..." bold
sudo systemctl disable easymesh.service &> /dev/null
if [[ $? -eq 0 ]]; then
colorize green " EasyMesh service disabled successfully.\n"
else
colorize red " Failed to disable EasyMesh service.\n"
sleep 2
return 1
fi
colorize yellow " Removing EasyMesh service..." bold
sudo rm /etc/systemd/system/easymesh.service &> /dev/null
if [[ $? -eq 0 ]]; then
colorize green " EasyMesh service removed successfully.\n"
else
colorize red " Failed to remove EasyMesh service.\n"
sleep 2
return 1
fi
colorize yellow " Reloading systemd daemon..." bold
sudo systemctl daemon-reload
if [[ $? -eq 0 ]]; then
colorize green " Systemd daemon reloaded successfully.\n"
else
colorize red " Failed to reload systemd daemon.\n"
sleep 2
return 1
fi
read -p " Press Enter to continue..."
}
show_network_secret() {
echo ''
if [[ -f $SERVICE_FILE ]]; then
NETWORK_SECRET=$(grep -oP '(?<=--network-secret )[^ ]+' $SERVICE_FILE)
if [[ -n $NETWORK_SECRET ]]; then
colorize cyan " Network Secret Key: $NETWORK_SECRET" bold
else
colorize red " Network Secret key not found" bold
fi
else
colorize red " EasyMesh service does not exists." bold
fi
echo ''
read -p " Press Enter to continue..."
}
view_service_status() {
if [[ ! -f $SERVICE_FILE ]]; then
colorize red " EasyMesh service does not exists." bold
sleep 1
return 1
fi
clear
sudo systemctl status easymesh.service
}
set_watchdog(){
clear
view_watchdog_status
echo "---------------------------------------------"
echo
colorize cyan "Select your option:" bold
colorize green "1) Create watchdog service"
colorize red "2) Stop & remove watchdog service"
colorize yellow "3) View Logs"
colorize reset "4) Back"
echo ''
read -p "Enter your choice: " CHOICE
case $CHOICE in
1) start_watchdog ;;
2) stop_watchdog ;;
3) view_logs ;;
4) return 0;;
*) colorize red "Invalid option!" bold && sleep 1 && return 1;;
esac
}
start_watchdog(){
clear
colorize cyan "Important: You can check the status of the service \nand restart it if the latency is higher than a certain limit. \nI recommend to run it only on one server and preferably outside (Kharej) server" bold
echo ''
read -p "Enter the local IP address to monitor: " IP_ADDRESS
read -p "Enter the latency threshold in ms (200): " LATENCY_THRESHOLD
read -p "Enter the time between checks in seconds (8): " CHECK_INTERVAL
stop_watchdog
touch /etc/monitor.sh /etc/monitor.log &> /dev/null
cat << EOF | sudo tee /etc/monitor.sh > /dev/null
#!/bin/bash
# Configuration
IP_ADDRESS="$IP_ADDRESS"
LATENCY_THRESHOLD=$LATENCY_THRESHOLD
CHECK_INTERVAL=$CHECK_INTERVAL
SERVICE_NAME="easymesh.service"
LOG_FILE="/etc/monitor.log"
# Function to restart the service
restart_service() {
local restart_time=\$(date +"%Y-%m-%d %H:%M:%S")
sudo systemctl restart "\$SERVICE_NAME"
if [ \$? -eq 0 ]; then
echo "\$restart_time: Service \$SERVICE_NAME restarted successfully." >> "\$LOG_FILE"
else
echo "\$restart_time: Failed to restart service \$SERVICE_NAME." >> "\$LOG_FILE"
fi
}
# Function to calculate average latency
calculate_average_latency() {
local latencies=(\$(ping -c 3 -W 2 -i 0.2 "\$IP_ADDRESS" | grep 'time=' | sed -n 's/.*time=\([0-9.]*\) ms.*/\1/p'))
local total_latency=0
local count=\${#latencies[@]}
for latency in "\${latencies[@]}"; do
total_latency=\$(echo "\$total_latency + \$latency" | bc)
done
if [ \$count -gt 0 ]; then
local average_latency=\$(echo "scale=2; \$total_latency / \$count" | bc)
echo \$average_latency
else
echo 0
fi
}
# Main monitoring loop
while true; do
# Calculate average latency
AVG_LATENCY=\$(calculate_average_latency)
if [ "\$AVG_LATENCY" == "0" ]; then
echo "\$(date +"%Y-%m-%d %H:%M:%S"): Failed to ping \$IP_ADDRESS. Restarting service..." >> "\$LOG_FILE"
restart_service
else
LATENCY_INT=\${AVG_LATENCY%.*} # Convert latency to integer for comparison
if [ "\$LATENCY_INT" -gt "\$LATENCY_THRESHOLD" ]; then
echo "\$(date +"%Y-%m-%d %H:%M:%S"): Average latency \$AVG_LATENCY ms exceeds threshold of \$LATENCY_THRESHOLD ms. Restarting service..." >> "\$LOG_FILE"
restart_service
fi
fi
# Wait for the specified interval before checking again
sleep "\$CHECK_INTERVAL"
done
EOF
echo
colorize yellow "Creating a service for watchdog" bold
echo
SERVICE_FILE="/etc/systemd/system/easymesh-watchdog.service"
cat > $SERVICE_FILE <<EOF
[Unit]
Description=EasyMesh Watchdog Service
After=network.target
[Service]
ExecStart=/bin/bash /etc/monitor.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# Execute the script in the background
systemctl daemon-reload >/dev/null 2>&1
systemctl enable --now easymesh-watchdog.service
echo
colorize green "Watchdog service started successfully" bold
echo
press_key
}
# Function to stop the watchdog
stop_watchdog() {
echo
SERVICE_FILE="/etc/systemd/system/easymesh-watchdog.service"
if [[ ! -f $SERVICE_FILE ]]; then
colorize red "Watchdog service does not exists." bold
sleep 1
return 1
fi
systemctl disable --now easymesh-watchdog.service &> /dev/null
rm -f /etc/monitor.sh /etc/monitor.log &> /dev/null
rm -f "$SERVICE_FILE" &> /dev/null
systemctl daemon-reload &> /dev/null
colorize yellow "Watchdog service stopped and removed successfully" bold
echo
sleep 2
}
view_watchdog_status(){
if systemctl is-active --quiet "easymesh-watchdog.service"; then
colorize green " Watchdog service is running" bold
else
colorize red " Watchdog service is not running" bold
fi
}
# Function to view logs
view_logs() {
if [ -f /etc/monitor.log ]; then
less +G /etc/monitor.log
else
echo ''
colorize yellow "No logs found.\n" bold
press_key
fi
}
# Function to add cron-tab job
add_cron_job() {
echo
local service_name="easymesh.service"
# Prompt user to choose a restart time interval
colorize cyan "Select the restart time interval:" bold
echo
echo "1. Every 30th minute"
echo "2. Every 1 hour"
echo "3. Every 2 hours"
echo "4. Every 4 hours"
echo "5. Every 6 hours"
echo "6. Every 12 hours"
echo "7. Every 24 hours"
echo
read -p "Enter your choice: " time_choice
# Validate user input for restart time interval
case $time_choice in
1)
restart_time="*/30 * * * *"
;;
2)
restart_time="0 * * * *"
;;
3)
restart_time="0 */2 * * *"
;;
4)
restart_time="0 */4 * * *"
;;
5)
restart_time="0 */6 * * *"
;;
6)
restart_time="0 */12 * * *"
;;
7)
restart_time="0 0 * * *"
;;
*)
echo -e "${RED}Invalid choice. Please enter a number between 1 and 7.${NC}\n"
sleep 2
return 1
;;
esac
# remove cronjob created by this script
delete_cron_job > /dev/null 2>&1
# Path to reset file
local reset_path="/root/easytier/reset.sh"
#add cron job to kill the running easymesh processes
cat << EOF > "$reset_path"
#! /bin/bash
pids=\$(pgrep easytier)
sudo kill -9 \$pids
sudo systemctl daemon-reload
sudo systemctl restart $service_name
EOF
# make it +x
chmod +x "$reset_path"
# Save existing crontab to a temporary file
crontab -l > /tmp/crontab.tmp
# Append the new cron job to the temporary file
echo "$restart_time $reset_path #$service_name" >> /tmp/crontab.tmp
# Install the modified crontab from the temporary file
crontab /tmp/crontab.tmp
# Remove the temporary file
rm /tmp/crontab.tmp
echo
colorize green "Cron-job added successfully to restart the service '$service_name'." bold
sleep 2
}
delete_cron_job() {
echo
local service_name="easymesh.service"
local reset_path="/root/easytier/reset.sh"
crontab -l | grep -v "#$service_name" | crontab -
rm -f "$reset_path" >/dev/null 2>&1
colorize green "Cron job for $service_name deleted successfully." bold
sleep 2
}
set_cronjob(){
clear
colorize cyan "Cron-job setting menu" bold
echo
colorize green "1) Add a new cronjob"
colorize red "2) Delete existing cronjob"
colorize reset "3) Return..."
echo
echo -ne "Select you option [1-3]: "
read -r choice
case $choice in
1) add_cron_job ;;
2) delete_cron_job ;;
3) return 0 ;;
*) colorize red "Invalid option!" && sleep 1 && return 1 ;;
esac
}
check_core_status(){
DEST_DIR="/root/easytier"
FILE1="easytier-core"
FILE2="easytier-cli"
if [ -f "$DEST_DIR/$FILE1" ] && [ -f "$DEST_DIR/$FILE2" ]; then
colorize green "EasyMesh Core Installed" bold
return 0
else
colorize red "EasyMesh Core not found" bold
return 1
fi
}
# New function to remove core
remove_easymesh_core(){
echo
if [[ ! -d '/root/easytier' ]]; then
colorize red " EasyMesh directory not found." bold
sleep 2
return 1
fi
rm -rf /root/easytier &> /dev/null
colorize green " Easymesh core deleted successfully." bold
sleep 2
}
# Function to display menu
display_menu() {
clear
# Print the header with colors
echo -e " ${CYAN}╔════════════════════════════════════════╗"
echo -e " ║ 🌐 ${WHITE}EasyMesh ${CYAN}║"
echo -e " ║ ${WHITE}VPN Network Solution ${CYAN}║"
echo -e " ╠════════════════════════════════════════╣"
echo -e " ║ ${WHITE}Version: 0.97 beta ${CYAN}║"
echo -e " ║ ${WHITE}Telegram Channel: @Gozar_Xray ${CYAN}║"
echo -e " ║ ${WHITE}GitHub: github.com/Musixal/easy-mesh ${CYAN}║"
echo -e " ╠════════════════════════════════════════╣${RESET}"
echo -e " ║ $(check_core_status) ║"
echo -e " ╚════════════════════════════════════════╝"
echo ''
colorize green " [1] Connect to the Mesh Network" bold
colorize yellow " [2] Display Peers"
colorize cyan " [3] Display Routes"
colorize reset " [4] Peer-Center"
colorize reset " [5] Display Secret Key"
colorize reset " [6] View Service Status"
colorize reset " [7] Set Watchdog [Auto-Restarter]"
colorize reset " [8] Cron-jon setting"
colorize yellow " [9] Restart Service"
colorize red " [10] Remove Service"
colorize magenta " [11] Remove Core"
echo -e " [0] Exit"
echo ''
}
# Function to read user input
read_option() {
echo -e "\t-------------------------------"
echo -en "\t${MAGENTA}\033[1mEnter your choice:${RESET} "
read -p '' choice
case $choice in
1) connect_network_pool ;;
2) display_peers ;;
3) display_routes ;;
4) peer_center ;;
5) show_network_secret ;;
6) view_service_status ;;
7) set_watchdog ;;
8) set_cronjob ;;
9) restart_easymesh_service ;;
10) remove_easymesh_service ;;
11) remove_easymesh_core ;;
0) exit 0 ;;
*) colorize red " Invalid option!" bold && sleep 1 ;;
esac
}
# Main script
while true
do
display_menu
read_option
done