-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathextstats.sh
executable file
·1936 lines (1737 loc) · 54.1 KB
/
extstats.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/sh
#####################################################
## ##
## __ _____ __ __ ##
## ___ _ __ / /_/ ___/ / /_ ____ _ / /_ _____ ##
## / _ \ | |/_// __/\__ \ / __// __ `// __// ___/ ##
## / __/_> < / /_ ___/ // /_ / /_/ // /_ (__ ) ##
## \___//_/|_| \__//____/ \__/ \__,_/ \__//____/ ##
## ##
## Corgan - Stefan Knaak 2020 ##
## ##
#####################################################
## ##
## https://github.com/corgan2222/extstats ##
## ##
#####################################################
### Start of script variables ###
readonly SCRIPT_NAME="extstats"
readonly SCRIPT_NAME_LOWER=$(echo $SCRIPT_NAME | tr 'A-Z' 'a-z' | sed 's/d//')
readonly SCRIPT_DIR="/jffs/addons/$SCRIPT_NAME_LOWER.d"
readonly SCRIPT_CONF="$SCRIPT_DIR/config.conf"
readonly SCRIPT_VERSION="v0.4.0"
readonly SCRIPT_BRANCH="master"
readonly SCRIPT_REPO="https://raw.githubusercontent.com/corgan2222/""$SCRIPT_NAME""/""$SCRIPT_BRANCH"
readonly DHCP_HOSTNAMESMAC="/opt/tmp/dhcp_clients_mac.txt"
readonly DHCP_HOSTNAMESMAC_CSV="/opt/tmp/dhcp_clients_mac.csv"
readonly DHCP_HOSTNAMESMAC_SB_IP="/opt/tmp/dhcp_clients_mac_sb_ip.txt"
readonly DHCP_HOSTNAMESMAC_SB_MAC="/opt/tmp/dhcp_clients_mac_sb_mac.txt"
readonly DHCP_HOSTNAMESMAC_SB_HOST="/opt/tmp/dhcp_clients_mac_sb_host.txt"
readonly DHCP_EXTERNAL="/opt/tmp/dhcp_external.csv"
[ -z "$(nvram get odmpid)" ] && ROUTER_MODEL=$(nvram get productid) || ROUTER_MODEL=$(nvram get odmpid)
[ -f /opt/bin/sqlite3 ] && SQLITE3_PATH=/opt/bin/sqlite3 || SQLITE3_PATH=/usr/sbin/sqlite3
### End of script variables ###
readConfigData()
{
if [ -f "$SCRIPT_CONF" ]; then
EXTS_URL=$(grep "EXTS_URL" "$SCRIPT_CONF" | cut -f2 -d"=")
EXTS_DATABASE=$(grep "EXTS_DATABASE" "$SCRIPT_CONF" | cut -f2 -d"=")
EXTS_USERNAME=$(grep "EXTS_USERNAME" "$SCRIPT_CONF" | cut -f2 -d"=")
EXTS_PASSWORD=$(grep "EXTS_PASSWORD" "$SCRIPT_CONF" | cut -f2 -d"=")
EXTS_USESSH=$(grep "EXTS_USESSH" "$SCRIPT_CONF" | cut -f2 -d"=")
EXTS_NOVERIFIY=$(grep "EXTS_NOVERIFIY" "$SCRIPT_CONF" | cut -f2 -d"=")
EXTS_PORT=$(grep "EXTS_PORT" "$SCRIPT_CONF" | cut -f2 -d"=")
EXTS_MAC_LIST_URL=$(grep "EXTS_MAC_LIST_URL" "$SCRIPT_CONF" | cut -f2 -d"=")
#https for influx
if [ "$EXTS_USESSH" != "false" ]; then HTTP="https"; else HTTP="http"; fi
if [ "$EXTS_NOVERIFIY" == "true" ]; then VERIFIY="-k"; fi #ignore ssl error
#only for Mesh
EXTS_SSH_USER=$(grep "EXTS_SSH_USER" "$SCRIPT_CONF" | cut -f2 -d"=")
EXTS_SSH_PW=$(grep "EXTS_SSH_PW" "$SCRIPT_CONF" | cut -f2 -d"=")
CURL_OPTIONS="${VERIFIY} -POST" #get is deprecated
UN_COUNT=$(echo $EXTS_PASSWORD | wc -m)
UP_COUNT=$(echo $EXTS_PASSWORD | wc -m)
if [[ ${UP_COUNT} -gt 1 ]]; then EXTS_PW_STRING=":${EXTS_PASSWORD}"; fi
if [[ ${UN_COUNT} -gt 1 ]]; then EXTS_USER_STRING="-u ${EXTS_USERNAME}"; fi
CURL_USER="${EXTS_USER_STRING}${EXTS_PW_STRING}"
TEST_URL="${HTTP}://${EXTS_URL}:${EXTS_PORT}"
fi
}
readConfigData
### Start of output format variables ###
readonly CRIT="\\e[41m"
readonly ERR="\\e[31m"
readonly WARN="\\e[33m"
readonly PASS="\\e[32m"
### End of output format variables ###
# $1 = print to syslog, $2 = message to print, $3 = log level
Print_Output(){
if [ "$1" = "true" ]; then
logger -t "$SCRIPT_NAME" "$2"
printf "\\e[1m$3%s: $2\\e[0m\\n\\n" "$SCRIPT_NAME"
else
printf "\\e[1m$3%s: $2\\e[0m\\n\\n" "$SCRIPT_NAME"
fi
}
### Code for this function courtesy of https://github.com/decoderman- credit to @thelonelycoder ###
Firmware_Version_Check(){
echo "$1" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
}
############################################################################
### Code for these functions inspired by https://github.com/Adamm00 - credit to @Adamm ###
Check_Lock(){
if [ -f "/tmp/$SCRIPT_NAME.lock" ]; then
ageoflock=$(($(date +%s) - $(date +%s -r /tmp/$SCRIPT_NAME.lock)))
if [ "$ageoflock" -gt 60 ]; then
Print_Output "true" "Stale lock file found (>60 seconds old) - purging lock" "$ERR"
kill "$(sed -n '1p' /tmp/$SCRIPT_NAME.lock)" >/dev/null 2>&1
Clear_Lock
echo "$$" > "/tmp/$SCRIPT_NAME.lock"
return 0
else
Print_Output "true" "Lock file found (age: $ageoflock seconds) - ping test likely currently running" "$ERR"
if [ -z "$1" ]; then
exit 1
else
return 1
fi
fi
else
echo "$$" > "/tmp/$SCRIPT_NAME.lock"
return 0
fi
}
Clear_Lock(){
rm -f "/tmp/$SCRIPT_NAME.lock" 2>/dev/null
return 0
}
Update_File(){
tmpfile="/tmp/$1"
Download_File "$SCRIPT_REPO/$1" "$tmpfile"
if ! diff -q "$tmpfile" "$SCRIPT_DIR/$1" >/dev/null 2>&1; then
Download_File "$SCRIPT_REPO/$1" "$SCRIPT_DIR/$1"
chmod 0755 "$SCRIPT_DIR/$1"
Print_Output "true" "New version of $1 downloaded" "$PASS"
fi
rm -f "$tmpfile"
}
Update_Version(){
if [ -z "$1" ]; then
doupdate="false"
localver=$(grep "SCRIPT_VERSION=" /jffs/scripts/"$SCRIPT_NAME" | grep -m1 -oE 'v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})')
/usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME.sh" | grep -qF "corgan2222" || { Print_Output "true" "404 error detected - stopping update" "$ERR"; return 1; }
serverver=$(/usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME.sh" | grep "SCRIPT_VERSION=" | grep -m1 -oE 'v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})')
if [ "$localver" != "$serverver" ]; then
doupdate="version"
else
localmd5="$(md5sum "/jffs/scripts/$SCRIPT_NAME" | awk '{print $1}')"
remotemd5="$(curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME.sh" | md5sum | awk '{print $1}')"
if [ "$localmd5" != "$remotemd5" ]; then
doupdate="md5"
fi
fi
if [ "$doupdate" = "version" ]; then
Print_Output "true" "New version of $SCRIPT_NAME available - updating to $serverver" "$PASS"
elif [ "$doupdate" = "md5" ]; then
Print_Output "true" "MD5 hash of $SCRIPT_NAME does not match - downloading updated $serverver" "$PASS"
fi
Update_File "export.sh"
Update_File "export_py.py"
Update_File "helper_dhcpstaticlist.sh"
Update_File "mod_basic.sh"
Update_File "mod_client_traffic.sh"
Update_File "mod_constats.sh"
Update_File "mod_ping_ext.sh"
Update_File "mod_spdstats.sh"
Update_File "mod_trafficAnalyzer.sh"
Update_File "mod_vpn_client.sh"
Update_File "mod_wifi_clients.sh"
Update_File "mod_meshinfo.sh"
if [ "$doupdate" != "false" ]; then
/usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME.sh" -o "/jffs/scripts/$SCRIPT_NAME" && Print_Output "true" "$SCRIPT_NAME successfully updated"
chmod 0755 /jffs/scripts/"$SCRIPT_NAME"
Clear_Lock
exit 0
else
Print_Output "true" "No new version - latest is $localver" "$WARN"
Clear_Lock
fi
fi
case "$1" in
force)
serverver=$(/usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME.sh" | grep "SCRIPT_VERSION=" | grep -m1 -oE 'v[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})')
Print_Output "true" "Downloading latest version ($serverver) of $SCRIPT_NAME" "$PASS"
Update_File "export.sh"
Update_File "export_py.py"
Update_File "helper_dhcpstaticlist.sh"
Update_File "mod_basic.sh"
Update_File "mod_client_traffic.sh"
Update_File "mod_constats.sh"
Update_File "mod_ping_ext.sh"
Update_File "mod_spdstats.sh"
Update_File "mod_trafficAnalyzer.sh"
Update_File "mod_vpn_client.sh"
Update_File "mod_wifi_clients.sh"
Update_File "mod_meshinfo.sh"
/usr/sbin/curl -fsL --retry 3 "$SCRIPT_REPO/$SCRIPT_NAME.sh" -o "/jffs/scripts/$SCRIPT_NAME" && Print_Output "true" "$SCRIPT_NAME successfully updated"
chmod 0755 /jffs/scripts/"$SCRIPT_NAME"
Clear_Lock
exit 0
;;
esac
}
############################################################################
Validate_Number(){
if [ "$2" -eq "$2" ] 2>/dev/null; then
return 0
else
formatted="$(echo "$1" | sed -e 's/|/ /g')"
if [ -z "$3" ]; then
Print_Output "false" "$formatted - $2 is not a number" "$ERR"
fi
return 1
fi
}
Download_File(){
/usr/sbin/curl -fsL --retry 3 "$1" -o "$2"
}
Create_Dirs(){
if [ ! -d "$SCRIPT_DIR" ]; then
mkdir -p "$SCRIPT_DIR"
fi
if [ -f "/jffs/configs/extstats.conf" ]; then
mv "/jffs/configs/extstats.conf" "$SCRIPT_DIR/extstats.conf"
fi
if [ -f "/jffs/configs/extstats.conf.default" ]; then
mv "/jffs/configs/extstats.conf.default" "$SCRIPT_DIR/extstats.conf.default"
fi
}
Conf_Exists(){
if [ -f "$SCRIPT_CONF" ]; then
dos2unix "$SCRIPT_CONF"
chmod 0644 "$SCRIPT_CONF"
sed -i -e 's/"//g' "$SCRIPT_CONF"
return 0
else
{ echo "EXTS_DATABASE=telegraf"; echo "EXTS_USERNAME="; echo "EXTS_PASSWORD="; echo "EXTS_USESSH=false" ; echo "EXTS_URL=" ; echo "EXTS_PORT=8086"; echo "EXTS_BASIC_ENABLED=false"; echo "EXTS_WIFI_ENABLED=false"; echo "EXTS_TRAFFIC_ENABLED=false"; echo "EXTS_NTPMERLIN_ENABLED=false"; echo "EXTS_SPDSTATS_ENABLED=false"; echo "EXTS_VPN_ENABLED=false"; echo "EXTS_TRAFFIC_ANALYZER_ENABLED=false"; echo "EXTS_NOVERIFIY=false"; } >> "$SCRIPT_CONF"
return 1
fi
}
Auto_ServiceEvent(){
case $1 in
create)
if [ -f /jffs/scripts/service-event ]; then
STARTUPLINECOUNT=$(grep -c '# '"$SCRIPT_NAME" /jffs/scripts/service-event)
# shellcheck disable=SC2016
STARTUPLINECOUNTEX=$(grep -cx "/jffs/scripts/$SCRIPT_NAME_LOWER generate"' "$1" "$2" &'' # '"$SCRIPT_NAME" /jffs/scripts/service-event)
if [ "$STARTUPLINECOUNT" -gt 1 ] || { [ "$STARTUPLINECOUNTEX" -eq 0 ] && [ "$STARTUPLINECOUNT" -gt 0 ]; }; then
sed -i -e '/# '"$SCRIPT_NAME"'/d' /jffs/scripts/service-event
fi
if [ "$STARTUPLINECOUNTEX" -eq 0 ]; then
# shellcheck disable=SC2016
echo "/jffs/scripts/$SCRIPT_NAME_LOWER generate"' "$1" "$2" &'' # '"$SCRIPT_NAME" >> /jffs/scripts/service-event
fi
else
echo "#!/bin/sh" > /jffs/scripts/service-event
echo "" >> /jffs/scripts/service-event
# shellcheck disable=SC2016
echo "/jffs/scripts/$SCRIPT_NAME_LOWER generate"' "$1" "$2" &'' # '"$SCRIPT_NAME" >> /jffs/scripts/service-event
chmod 0755 /jffs/scripts/service-event
fi
;;
delete)
if [ -f /jffs/scripts/service-event ]; then
STARTUPLINECOUNT=$(grep -c '# '"$SCRIPT_NAME" /jffs/scripts/service-event)
if [ "$STARTUPLINECOUNT" -gt 0 ]; then
sed -i -e '/# '"$SCRIPT_NAME"'/d' /jffs/scripts/service-event
fi
fi
;;
esac
}
Shortcut_EXTS(){
case $1 in
create)
if [ -d "/opt/bin" ] && [ ! -f "/opt/bin/$SCRIPT_NAME" ] && [ -f "/jffs/scripts/$SCRIPT_NAME" ]; then
ln -s /jffs/scripts/"$SCRIPT_NAME" /opt/bin
chmod 0755 /opt/bin/"$SCRIPT_NAME"
fi
;;
delete)
if [ -f "/opt/bin/$SCRIPT_NAME" ]; then
rm -f /opt/bin/"$SCRIPT_NAME"
fi
;;
esac
}
PressEnter(){
while true; do
printf "Press enter to continue..."
read -r "key"
case "$key" in
*)
break
;;
esac
done
return 0
}
exts_basic(){
case $1 in
enable)
sed -i 's/^EXTS_BASIC_ENABLED.*$/EXTS_BASIC_ENABLED=true/' "$SCRIPT_CONF"
Auto_Cron create "cron_mod_basic" 2>/dev/null
;;
disable)
sed -i 's/^EXTS_BASIC_ENABLED.*$/EXTS_BASIC_ENABLED=false/' "$SCRIPT_CONF"
Auto_Cron delete "cron_mod_basic" 2>/dev/null
;;
check)
EXTS_BASIC_ENABLED=$(grep "EXTS_BASIC_ENABLED" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ "$EXTS_BASIC_ENABLED" = "true" ]; then return 0; else return 1; fi
;;
esac
}
exts_wifi(){
case $1 in
enable)
sed -i 's/^EXTS_WIFI_ENABLED.*$/EXTS_WIFI_ENABLED=true/' "$SCRIPT_CONF"
Auto_Cron create "cron_mod_wifi_clients" 2>/dev/null
;;
disable)
sed -i 's/^EXTS_WIFI_ENABLED.*$/EXTS_WIFI_ENABLED=false/' "$SCRIPT_CONF"
Auto_Cron delete "cron_mod_wifi_clients" 2>/dev/null
;;
check)
EXTS_WIFI_ENABLED=$(grep "EXTS_WIFI_ENABLED" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ "$EXTS_WIFI_ENABLED" = "true" ]; then return 0; else return 1; fi
;;
esac
}
exts_traffic(){
case $1 in
enable)
sed -i 's/^EXTS_TRAFFIC_ENABLED.*$/EXTS_TRAFFIC_ENABLED=true/' "$SCRIPT_CONF"
Auto_Cron create "cron_mod_client_traffic_setup" 2>/dev/null
Auto_Cron create "cron_mod_client_traffic_update" 2>/dev/null
;;
disable)
sed -i 's/^EXTS_TRAFFIC_ENABLED.*$/EXTS_TRAFFIC_ENABLED=false/' "$SCRIPT_CONF"
Auto_Cron delete "cron_mod_client_traffic_setup" 2>/dev/null
Auto_Cron delete "cron_mod_client_traffic_update" 2>/dev/null
;;
check)
EXTS_TRAFFIC_ENABLED=$(grep "EXTS_TRAFFIC_ENABLED" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ "$EXTS_TRAFFIC_ENABLED" = "true" ]; then return 0; else return 1; fi
;;
esac
}
exts_ntpmerlin(){
case $1 in
enable)
sed -i 's/^EXTS_NTPMERLIN_ENABLED.*$/EXTS_NTPMERLIN_ENABLED=true/' "$SCRIPT_CONF"
Auto_Cron create "cron_mod_constats" 2>/dev/null
;;
disable)
sed -i 's/^EXTS_NTPMERLIN_ENABLED.*$/EXTS_NTPMERLIN_ENABLED=false/' "$SCRIPT_CONF"
Auto_Cron delete "cron_mod_constats" 2>/dev/null
;;
check)
EXTS_NTPMERLIN_ENABLED=$(grep "EXTS_NTPMERLIN_ENABLED" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ "$EXTS_NTPMERLIN_ENABLED" = "true" ]; then return 0; else return 1; fi
;;
esac
}
exts_traffic_analyzer(){
case $1 in
enable)
sed -i 's/^EXTS_TRAFFIC_ANALYZER_ENABLED.*$/EXTS_TRAFFIC_ANALYZER_ENABLED=true/' "$SCRIPT_CONF"
Auto_Cron create "cron_mod_trafficAnalyzer" 2>/dev/null
;;
disable)
sed -i 's/^EXTS_TRAFFIC_ANALYZER_ENABLED.*$/EXTS_TRAFFIC_ANALYZER_ENABLED=false/' "$SCRIPT_CONF"
Auto_Cron delete "cron_mod_trafficAnalyzer" 2>/dev/null
;;
check)
EXTS_TRAFFIC_ANALYZER_ENABLED=$(grep "EXTS_TRAFFIC_ANALYZER_ENABLED" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ "$EXTS_TRAFFIC_ANALYZER_ENABLED" = "true" ]; then return 0; else return 1; fi
;;
esac
}
exts_spdstats(){
case $1 in
enable)
sed -i 's/^EXTS_SPDSTATS_ENABLED.*$/EXTS_SPDSTATS_ENABLED=true/' "$SCRIPT_CONF"
Auto_Cron create "cron_mod_spdstats" 2>/dev/null
;;
disable)
sed -i 's/^EXTS_SPDSTATS_ENABLED.*$/EXTS_SPDSTATS_ENABLED=false/' "$SCRIPT_CONF"
Auto_Cron delete "cron_mod_spdstats" 2>/dev/null
;;
check)
EXTS_SPDSTATS_ENABLED=$(grep "EXTS_SPDSTATS_ENABLED" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ "$EXTS_SPDSTATS_ENABLED" = "true" ]; then return 0; else return 1; fi
;;
esac
}
exts_vpn(){
case $1 in
enable)
sed -i 's/^EXTS_VPN_ENABLED.*$/EXTS_VPN_ENABLED=true/' "$SCRIPT_CONF"
Auto_Cron create "cron_mod_vpn_client" 2>/dev/null
;;
disable)
sed -i 's/^EXTS_VPN_ENABLED.*$/EXTS_VPN_ENABLED=false/' "$SCRIPT_CONF"
Auto_Cron delete "cron_mod_vpn_client" 2>/dev/null
;;
check)
EXTS_VPN_ENABLED=$(grep "EXTS_VPN_ENABLED" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ "$EXTS_VPN_ENABLED" = "true" ]; then return 0; else return 1; fi
;;
esac
}
exts_meshinfo(){
case $1 in
enable)
sed -i 's/^EXTS_MESHINFO_ENABLED.*$/EXTS_MESHINFO_ENABLED=true/' "$SCRIPT_CONF"
Auto_Cron create "cron_mod_meshinfo" 2>/dev/null
;;
disable)
sed -i 's/^EXTS_MESHINFO_ENABLED.*$/EXTS_MESHINFO_ENABLED=false/' "$SCRIPT_CONF"
Auto_Cron delete "cron_mod_meshinfo" 2>/dev/null
;;
check)
EXTS_MESHINFO_ENABLED=$(grep "EXTS_MESHINFO_ENABLED" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ "$EXTS_MESHINFO_ENABLED" = "true" ]; then return 0; else return 1; fi
;;
esac
}
exts_URL(){
case "$1" in
update)
if [ "$URL" != "exit" ]; then
sed -i 's/^EXTS_URL.*$/EXTS_URL='"$SERVERURL"'/' "$SCRIPT_CONF"
else
return 1
fi
;;
disable)
sed -i 's/^EXTS_URL.*$/EXTS_URL=/' "$SCRIPT_CONF"
;;
check)
EXTS_URL=$(grep "EXTS_URL" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ -z "$EXTS_URL" ]; then return 1; else return 0; fi
;;
list)
EXTS_URL=$(grep "EXTS_URL" "$SCRIPT_CONF" | cut -f2 -d"=")
echo "$EXTS_URL"
;;
esac
}
exts_Database(){
case "$1" in
update)
if [ "$DATABASE" != "exit" ]; then
sed -i 's/^EXTS_DATABASE.*$/EXTS_DATABASE='"$DATABASE"'/' "$SCRIPT_CONF"
else
return 1
fi
;;
disable)
sed -i 's/^EXTS_DATABASE.*$/EXTS_DATABASE=/' "$SCRIPT_CONF"
;;
check)
EXTS_DATABASE=$(grep "EXTS_DATABASE" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ -z "$EXTS_DATABASE" ]; then return 1; else return 0; fi
;;
list)
EXTS_DATABASE=$(grep "EXTS_DATABASE" "$SCRIPT_CONF" | cut -f2 -d"=")
echo "$EXTS_DATABASE"
;;
esac
}
exts_Port(){
case "$1" in
update)
if [ "$PORT" != "exit" ]; then
sed -i 's/^EXTS_PORT.*$/EXTS_PORT='"$PORT"'/' "$SCRIPT_CONF"
else
return 1
fi
;;
disable)
sed -i 's/^EXTS_PORT.*$/EXTS_PORT=/' "$SCRIPT_CONF"
;;
check)
EXTS_PORT=$(grep "EXTS_PORT" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ -z "$EXTS_PORT" ]; then return 1; else return 0; fi
;;
list)
EXTS_PORT=$(grep "EXTS_PORT" "$SCRIPT_CONF" | cut -f2 -d"=")
echo "$EXTS_PORT"
;;
esac
}
exts_Username(){
case "$1" in
update)
if [ "$USERNAME" != "exit" ]; then
sed -i 's/^EXTS_USERNAME.*$/EXTS_USERNAME='"$USERNAME"'/' "$SCRIPT_CONF"
else
return 1
fi
;;
disable)
sed -i 's/^EXTS_USERNAME.*$/EXTS_USERNAME=/' "$SCRIPT_CONF"
;;
check)
EXTS_USERNAME=$(grep "EXTS_USERNAME" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ -z "$EXTS_USERNAME" ]; then return 1; else return 0; fi
;;
list)
EXTS_DATABASE=$(grep "EXTS_USERNAME" "$SCRIPT_CONF" | cut -f2 -d"=")
echo "$EXTS_USERNAME"
;;
esac
}
exts_Password(){
case "$1" in
update)
if [ "$PASSWORD" != "exit" ]; then
sed -i 's/^EXTS_PASSWORD.*$/EXTS_PASSWORD='"$PASSWORD"'/' "$SCRIPT_CONF"
else
return 1
fi
;;
disable)
sed -i 's/^EXTS_PASSWORD.*$/EXTS_PASSWORD=/' "$SCRIPT_CONF"
;;
check)
EXTS_PASSWORD=$(grep "EXTS_PASSWORD" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ -z "$EXTS_PASSWORD" ]; then return 1; else return 0; fi
;;
list)
EXTS_PASSWORD=$(grep "EXTS_PASSWORD" "$SCRIPT_CONF" | cut -f2 -d"=")
echo "$EXTS_PASSWORD"
;;
esac
}
exts_Usessh(){
case "$1" in
enable)
sed -i 's/^EXTS_USESSH.*$/EXTS_USESSH=true/' "$SCRIPT_CONF"
;;
disable)
sed -i 's/^EXTS_USESSH.*$/EXTS_USESSH=false/' "$SCRIPT_CONF"
;;
check)
EXTS_USESSH=$(grep "EXTS_USESSH" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ -z "$EXTS_USESSH" ]; then return 1; else return 0; fi
;;
list)
EXTS_USESSH=$(grep "EXTS_USESSH" "$SCRIPT_CONF" | cut -f2 -d"=")
echo "$EXTS_USESSH"
;;
esac
}
exts_noverify(){
case "$1" in
enable)
sed -i 's/^EXTS_NOVERIFIY.*$/EXTS_NOVERIFIY=true/' "$SCRIPT_CONF"
;;
disable)
sed -i 's/^EXTS_NOVERIFIY.*$/EXTS_NOVERIFIY=false/' "$SCRIPT_CONF"
;;
check)
EXTS_NOVERIFIY=$(grep "EXTS_NOVERIFIY" "$SCRIPT_CONF" | cut -f2 -d"=")
if [ -z "$EXTS_NOVERIFIY" ]; then return 1; else return 0; fi
;;
list)
EXTS_NOVERIFIY=$(grep "EXTS_NOVERIFIY" "$SCRIPT_CONF" | cut -f2 -d"=")
echo "$EXTS_NOVERIFIY"
;;
esac
}
Menu_EditDatabase(){
exitmenu="false"
ScriptHeader
while true; do
printf "\\n\\e[1mPlease enter the influxDB Server (like server.com or 127.0.0.1) WITHOUT PORT!! :\\e[0m\\n"
read -r "URL"
if [ "$URL" = "e" ]; then
exitmenu="exit"
break
else
if [ -z "$URL" ] ; then
printf "\\n\\e[31mPlease enter a valid Server\\e[0m\\n"
else
SERVERURL="$URL"
exts_URL update "$URL"
printf "\\n"
break
fi
fi
done
if [ "$exitmenu" != "exit" ]; then
while true; do
printf "\\n\\e[1mPlease enter the influxDB Database Port (like 8086) :\\e[0m\\n"
read -r "PORT"
if [ "$PORT" = "e" ]; then
exitmenu="exit"
break
else
if [ -z "$PORT" ] ; then
printf "\\n\\e[31mPlease enter a valid Port\\e[0m\\n"
else
EXTS_PORT="$DATABASE"
exts_Port update "$PORT"
printf "\\n"
break
fi
fi
done
fi
if [ "$exitmenu" != "exit" ]; then
while true; do
printf "\\n\\e[1mPlease enter the influxDB Username (like telegraf or Admin) :\\e[0m\\n"
read -r "USERNAME"
if [ "$USERNAME" = "e" ]; then
exitmenu="exit"
break
else
if [ -z "$USERNAME" ] ; then
printf "\\n\\e[31mPlease enter a valid Username\\e[0m\\n"
else
EXTS_USERNAME="$USERNAME"
exts_Username update "$USERNAME"
printf "\\n"
break
fi
fi
done
fi
if [ "$exitmenu" != "exit" ]; then
while true; do
printf "\\n\\e[1mUse SSH (y/n)\\e[0m\\n"
read -r "USESSH"
case "$USESSH" in
y|Y)
EXTS_USESSH="true"
exts_Usessh enable
printf "\\n"
break
;;
*)
EXTS_USESSH="false"
exts_Usessh disable
break
;;
esac
done
fi
if [ "$exitmenu" != "exit" ]; then
while true; do
printf "\\n\\e[1mDont verify SSL (if you want use SSL without correct certificate) (y/n)\\e[0m\\n"
read -r "NOVERIFIY"
case "$NOVERIFIY" in
y|Y)
EXTS_NOVERIFIY="true"
exts_noverify enable
printf "\\n"
break
;;
*)
EXTS_NOVERIFIY="false"
exts_noverify disable
break
;;
esac
done
fi
if [ "$exitmenu" != "exit" ]; then
while true; do
printf "\\n\\e[1mPlease enter the influxDB Password :\\e[0m\\n"
read -r "PASSWORD"
if [ "$PASSWORD" = "e" ]; then
exitmenu="exit"
break
else
EXTS_PASSWORD="$PASSWORD"
exts_Password update "$PASSWORD"
printf "\\n"
break
fi
done
fi
if [ "$exitmenu" != "exit" ]; then
while true; do
printf "\\n\\e[1mCreate a new Database (y) or use existing (n)\\e[0m\\n"
read -r "newDatabase"
case "$newDatabase" in
y|Y)
CREATEDB="true"
printf "\\n"
break
;;
*)
CREATEDB="FALSE"
break
;;
esac
done
fi
if [ "$exitmenu" != "exit" ]; then
while true; do
printf "\\n\\e[1mPlease enter the influxDB Database Name (like telegraf or routerData) :\\e[0m\\n"
read -r "DATABASE"
if [ "$DATABASE" = "e" ]; then
exitmenu="exit"
break
else
if [ -z "$DATABASE" ] ; then
printf "\\n\\e[31mPlease enter a valid Database Name\\e[0m\\n"
else
EXTS_DATABASE="$DATABASE"
exts_Database update "$DATABASE"
if [ "$CREATEDB" = "true" ]; then
if [ "$USESSH" != "false" ]; then HTTP="https"; else HTTP="http"; fi
if [ "$NOVERIFIY" == "true" ]; then VERIFIY="-k"; fi #ignore ssl error
CURL_OPTIONS="${VERIFIY} -POST" #get is deprecated
CURL_USER="-u ${USERNAME}:${PASSWORD}"
INFLUX_URL="${HTTP}://${URL}:${PORT}"
curl -is ${INFLUX_URL}/query ${CURL_USER} --data-urlencode "q=CREATE DATABASE ${DATABASE}"
break
readConfigData
ScriptHeader
MainMenu
fi
printf "\\n"
break
fi
fi
done
fi
# if [ "$exitmenu" != "exit" ]; then
# TestSchedule "update" "$starthour" "$endhour" "$startminute"
# fi
Clear_Lock
}
pingDB(){
readConfigData
PING_RESPONSE=$(curl -is ${TEST_URL}/ping)
response_header=$(echo "${PING_RESPONSE}" | head -1)
response_header_int=$(echo "${PING_RESPONSE}" | head -1 | awk '{print $2}' )
case "$response_header_int" in
100) # extstats: HTTP/1.1 204 No Content
return 1
break
;;
204) # extstats: HTTP/1.1 204 No Content
#printf "$response_header_int \\n $response_header \\n"
#printf "Testing Database Conection $ on ${TEST_URL}/ping \\n\\n"
return 0
break
;;
*)
return 1
break
;;
esac
}
test_DB()
{
CURDATE=`date +%s`
printf "Testing Database Conection on ${TEST_URL} \\n\\n"
curl -sL -I ${TEST_URL}/ping
#printf "creating database\\n"
CURL_CMD="${CURL_OPTIONS} ${TEST_URL}/query ${CURL_USER} --data-urlencode q=CREATE DATABASE extstats_testDB"
#CURL_CMD="${CURL_OPTIONS} ${TEST_URL}/query ${CURL_USER} --data-urlencode q=CREATE DATABASE ${EXTS_DATABASE}"
echo "curl $CURL_CMD"
#curl ${CURL_OPTIONS} ${TEST_URL}/query ${CURL_USER} --data-urlencode "q=CREATE DATABASE extstats_testDB"
#printf "\\ncreating retention policy\n"
#curl ${CURL_OPTIONS} ${TEST_URL}/query ${CURL_USER} --data-urlencode "q=CREATE RETENTION POLICY myrp ON ${EXTS_DATABASE} DURATION 365d REPLICATION 1 DEFAULT"
printf "\\nshowing Databases q=SHOW DATABASES \\n"
curl ${CURL_OPTIONS} ${TEST_URL}/query ${CURL_USER} --data-urlencode "q=SHOW DATABASES"
printf "\\nInsert Test Data in DB ${EXTS_DATABASE}\\n"
CURDATE=`date +%s`
data="router.test,host=router 24=1,50=100 ${CURDATE}000000000"
#curl ${CURL_OPTIONS} "${TEST_URL}/write?db=${EXTS_DATABASE} ${CURL_USER}" --data-binary "${data}"
curl -is ${CURL_OPTIONS} -XPOST "${TEST_URL}/write?db=${EXTS_DATABASE}&u=${EXTS_USERNAME}&p=${EXTS_PASSWORD}" --data-binary "${data}"
printf "\\nSHOW MEASUREMENTS from DB ${EXTS_DATABASE}\\n"
curl ${CURL_OPTIONS} ${TEST_URL}/query ${CURL_USER} --data-urlencode "db=${EXTS_DATABASE}" --data-urlencode "q=SHOW MEASUREMENTS" --data-urlencode "pretty=true"
printf "\\nSHOW SERIES from DB ${EXTS_DATABASE}\\n"
curl ${CURL_OPTIONS} ${TEST_URL}/query ${CURL_USER} --data-urlencode "db=${EXTS_DATABASE}" --data-urlencode "q=SHOW SERIES" --data-urlencode "pretty=true"
printf "\nRemove Test Database\n"
curl ${CURL_OPTIONS} ${TEST_URL}/query ${CURL_USER} --data-urlencode "q=DROP DATABASE extstats_testDB"
printf "\\n "
Clear_Lock
}
db_stats(){
printf "\\nSHOW MEASUREMENTS from DB ${EXTS_DATABASE}\\n\\n"
MEASUREMENTS_JSON=$(curl -s ${CURL_OPTIONS} ${TEST_URL}/query ${CURL_USER} --data-urlencode "db=${EXTS_DATABASE}" --data-urlencode "q=SHOW MEASUREMENTS" --data-urlencode "pretty=true")
MEASUREMENTS_STRINGS="$(echo "$MEASUREMENTS_JSON" | jq --compact-output '.results[].series[].values[]')"
for col in $MEASUREMENTS_STRINGS ; do
MEASUREMENT=$(echo "$col" | sed 's/"//g' | sed 's/\[//g' | sed 's/\]//g')
MEASUREMENT_STRINGS=$(curl -s ${CURL_OPTIONS} ${TEST_URL}/query ${CURL_USER} --data-urlencode "db=${EXTS_DATABASE}" --data-urlencode "q=SELECT count(*) FROM \"${EXTS_DATABASE}\".\"autogen\".\"${MEASUREMENT}\"" --data-urlencode "pretty=true")
MEASUREMENT_COUNT="$(echo "$MEASUREMENT_STRINGS" | jq --compact-output '.results[].series[].values[0][1]')"
echo "$MEASUREMENT: $MEASUREMENT_COUNT entrys"
done
}
ScriptHeader(){
clear
#pingDB
EXTS_URL=$(grep "EXTS_URL" "$SCRIPT_CONF" | cut -f2 -d"=")
EXTS_DATABASE=$(grep "EXTS_DATABASE" "$SCRIPT_CONF" | cut -f2 -d"=")
EXTS_USERNAME=$(grep "EXTS_USERNAME" "$SCRIPT_CONF" | cut -f2 -d"=")
EXTS_PASSWORD=$(grep "EXTS_PASSWORD" "$SCRIPT_CONF" | cut -f2 -d"=")
EXTS_USESSH=$(grep "EXTS_USESSH" "$SCRIPT_CONF" | cut -f2 -d"=")
EXTS_PORT=$(grep "EXTS_PORT" "$SCRIPT_CONF" | cut -f2 -d"=")
printf "\\e[1m#######################################################\\e[0m\\n"
printf "\\e[1m## __ _____ __ __ ##\\e[0m\\n"
printf "\\e[1m## ___ _ __ / /_/ ___/ / /_ ____ _ / /_ _____ ##\\e[0m\\n"
printf "\\e[1m## / _ \ | |/_// __/\__ \ / __// __ // __// ___/ ##\\e[0m\\n"
printf "\\e[1m## / __/_> < / /_ ___/ // /_ / /_/ // /_ (__ ) ##\\e[0m\\n"
printf "\\e[1m## \___//_/|_| \__//____/ \__/ \__,_/ \__//____/ ##\\e[0m\\n"
printf "\\e[1m## ##\\e[0m\\n"
printf "\\e[1m#######################################################\\e[0m\\n"
printf "\\e[1m## ##\\e[0m\\n"
printf "\\e[1m## %s on %-9s ##\\e[0m\\n" "$SCRIPT_VERSION" "$ROUTER_MODEL"
printf "\\e[1m## ##\\e[0m\\n"
printf "\\e[1m## https://github.com/corgan2222/extstats ##\\e[0m\\n"
printf "\\e[1m## Corgan - Stefan Knaak 2020 ##\\e[0m\\n"
printf "\\e[1m## ##\\e[0m\\n"
printf "\\e[1m#######################################################\\e[0m\\n"
printf "\\e[1m Config %s \\e[0m\\n" "$SCRIPT_DIR/extstats.conf"
printf "\\e[1m URL %s %s@%s \\e[0m\\n" "$TEST_URL" "$EXTS_USERNAME" "$EXTS_DATABASE"
printf "\\e[1m USESSH [%s] NO VERIFY [%s] \\e[0m\\n" "$EXTS_USESSH" "$EXTS_NOVERIFIY"
#printf "\\e[1m## Password %s \\e[0m\\n" "$EXTS_PASSWORD"
printf "\\e[1m#######################################################\\e[0m\\n"
printf "\\n"
}
MainMenu(){
EXTS_BASIC_ENABLED=""
EXTS_WIFI_ENABLED=""
EXTS_TRAFFIC_ENABLED=""
EXTS_TRAFFIC_ANALYZER_ENABLED=""
EXTS_NTPMERLIN_ENABLED=""
EXTS_SPDSTATS_ENABLED=""
EXTS_VPN_ENABLED=""
EXTS_MESHINFO_ENABLED=""
if exts_basic check; then EXTS_BASIC_ENABLED="[Enabled] "; else EXTS_BASIC_ENABLED="[Disabled]"; fi
if exts_wifi check; then EXTS_WIFI_ENABLED="[Enabled] "; else EXTS_WIFI_ENABLED="[Disabled]"; fi
if exts_traffic check; then EXTS_TRAFFIC_ENABLED="[Enabled] "; else EXTS_TRAFFIC_ENABLED="[Disabled]"; fi
if exts_traffic_analyzer check; then EXTS_TRAFFIC_ANALYZER_ENABLED="[Enabled] "; else EXTS_TRAFFIC_ANALYZER_ENABLED="[Disabled]"; fi
if exts_ntpmerlin check; then EXTS_NTPMERLIN_ENABLED="[Enabled] "; else EXTS_NTPMERLIN_ENABLED="[Disabled]"; fi
if exts_spdstats check; then EXTS_SPDSTATS_ENABLED="[Enabled] "; else EXTS_SPDSTATS_ENABLED="[Disabled]"; fi
if exts_vpn check; then EXTS_VPN_ENABLED="[Enabled] "; else EXTS_VPN_ENABLED="[Disabled]"; fi
if exts_meshinfo check; then EXTS_MESHINFO_ENABLED="[Enabled] "; else EXTS_MESHINFO_ENABLED="[Disabled]"; fi
#client traffic
#1 * * * * /mnt/routerUSB/scripts/scripts/asuswrt/metrics2influx/router_client_traffic.sh setup #TtInit#
#15 * * * * /mnt/routerUSB/scripts/scripts/asuswrt/metrics2influx/router_TrafficAnalyzer_influx.sh update #Traffic#
#spdMerlin - Speedtest
#30 * * * * /mnt/routerUSB/scripts/scripts/asuswrt/metrics2influx/router_spdstats_influx.sh update #spdstats#
#constats - connmon - Internet Uptime Monitoring
#45 * * * * /mnt/routerUSB/scripts/scripts/asuswrt/metrics2influx/router_constats_influx.sh update #connstats#
printf "\\e[1mDatabase\\e[0m\\n"
printf "1. Setup external Database (influxDB only atm)\\n\\n"
if pingDB; then
printf "\\e[1mSelect the data you want to export to an external Database\\e[0m\\n"
printf "2. %s Toogle basic stats (CPU, MEM, Temps, Net) \\n" "$EXTS_BASIC_ENABLED"
printf "3. %s Toogle wifi stats\\n" "$EXTS_WIFI_ENABLED"
printf "4. %s Toogle Traffic by Client stats\\n" "$EXTS_TRAFFIC_ENABLED"
printf "5. %s Toogle Traffic Analyzer stats \\n" "$EXTS_TRAFFIC_ANALYZER_ENABLED"
printf "6. %s Toogle Connmon Stats (Uptime Monitoring)\\n" "$EXTS_NTPMERLIN_ENABLED"
printf "7. %s Toogle spdMerlin Stats (Speedtest)\\n" "$EXTS_SPDSTATS_ENABLED"
printf "8. %s Toogle VPN stats\\n" "$EXTS_VPN_ENABLED"
printf "9. %s Toogle MeshInfo (experimental)\\n" "$EXTS_MESHINFO_ENABLED"
printf "\\n\\e[1mTest\\e[0m\\n"
printf "db. Show Database entrys\\n"
printf "t1. Test Database conection\\n"
printf "t2. Test basic stats \\n"
printf "t3. Test wifi stats \\n"
printf "t4. Test Traffic by Client \\n"
printf "t5. Test Traffic Analyzer \\n"
printf "t6. Test Connmon Stats \\n"
printf "t7. Test spdStats \\n"
printf "t8. Test VPN stats \\n"
printf "t9. Test MeshInfo (experimental) \\n\\n"
printf "t10. Test all \\n"
if [ ! -z "$EXTS_MAC_LIST_URL" ] ; then
printf "t11. Get new external DHCP Mac list \\n"
fi
else
printf "\\n\\e[1mCant ping Database! Please setup Database (1)\\e[0m\\n"
fi
printf "\\n\\e[1mDebug\\e[0m\\n"
printf "d. Show DHCP Client list \\n"
printf "h. Htop\\n\\n"
printf "\\e[1mOther\\e[0m\\n"
printf "x. Check Requirements\\n"
printf "u. Check for updates\\n"
printf "uf. Update %s with latest version (force update)\\n\\n" "$SCRIPT_NAME"
printf "e. Exit %s\\n\\n" "$SCRIPT_NAME"
printf "z. Uninstall %s\\n" "$SCRIPT_NAME"
printf "\\n"
printf "\\e[1m#####################################################\\e[0m\\n"
printf "\\n"
while true; do
printf "Choose an option: "