-
Notifications
You must be signed in to change notification settings - Fork 1
/
uptimebot
1545 lines (1446 loc) · 64.1 KB
/
uptimebot
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
#############################################################################
# Version 1.4.2-RELEASE (22-08-2023)
#############################################################################
#############################################################################
# Copyright 2021-2023 Nozel/Sebas Veeke. Licenced under a Creative Commons
# Attribution-NonCommercial-ShareAlike 4.0 International License.
#
# See https://creativecommons.org/licenses/by-nc-sa/4.0/
#
# Contact:
# > e-mail [email protected]
# > GitHub nozel-org
#############################################################################
#############################################################################
# VARIABLES
#############################################################################
# uptimebot version
UPTIMEBOT_VERSION='1.4.2'
# check whether uptimebot.conf is available and source it
if [ -f /usr/local/etc/uptimebot/uptimebot.conf ]; then
# populate all usable variables to have defaults and check validity later on
UPTIMEBOT_LOG='0'
UPTIMEBOT_DATABASE='0'
UPTIMEBOT_DELAY='0'
UPTIMEBOT_TLS_ALERT='0'
PING_LOG='0'
PING_TELEGRAM='0'
PORT_LOG='0'
PORT_TELEGRAM='0'
HTTP_LOG='0'
HTTP_TELEGRAM='0'
DNS_LOG='0'
DNS_TELEGRAM='0'
TLS_LOG='0'
TLS_TELEGRAM='0'
TOR_LOG='0'
TOR_TELEGRAM='0'
ALL_LOG='0'
ALL_TELEGRAM='0'
TELEGRAM_TOKEN='0'
TELEGRAM_CHAT='0'
# and source backupbot.conf
. /usr/local/etc/uptimebot/uptimebot.conf
# populate required variables when they are not set
if [ "${UPTIMEBOT_LOG}" = '0' ]; then
UPTIMEBOT_LOG="/var/log/uptimebot.log"
fi
if [ "${UPTIMEBOT_DATABASE}" = '0' ]; then
UPTIMEBOT_DATABASE="/usr/local/etc/uptimebot/targets.conf"
fi
if [ "${UPTIMEBOT_DELAY}" = '0' ]; then
UPTIMEBOT_DELAY='0.5'
fi
if [ "${UPTIMEBOT_TLS_ALERT}" = '0' ]; then
UPTIMEBOT_TLS_ALERT='7'
fi
if [ "${PING_LOG}" = '0' ]; then
PING_LOG='NO'
fi
if [ "${PING_TELEGRAM}" = '0' ]; then
PING_TELEGRAM='NO'
fi
if [ "${PORT_LOG}" = '0' ]; then
PORT_LOG='NO'
fi
if [ "${PORT_TELEGRAM}" = '0' ]; then
PORT_TELEGRAM='NO'
fi
if [ "${HTTP_LOG}" = '0' ]; then
HTTP_LOG='NO'
fi
if [ "${HTTP_TELEGRAM}" = '0' ]; then
HTTP_TELEGRAM='NO'
fi
if [ "${DNS_LOG}" = '0' ]; then
DNS_LOG='NO'
fi
if [ "${DNS_TELEGRAM}" = '0' ]; then
DNS_TELEGRAM='NO'
fi
if [ "${TLS_LOG}" = '0' ]; then
TLS_LOG='NO'
fi
if [ "${TLS_TELEGRAM}" = '0' ]; then
TLS_TELEGRAM='NO'
fi
if [ "${TOR_LOG}" = '0' ]; then
TOR_LOG='NO'
fi
if [ "${TOR_TELEGRAM}" = '0' ]; then
TOR_TELEGRAM='NO'
fi
if [ "${ALL_LOG}" = '0' ]; then
ALL_LOG='NO'
fi
if [ "${ALL_TELEGRAM}" = '0' ]; then
ALL_TELEGRAM='NO'
fi
if [ "${TELEGRAM_TOKEN}" = '0' ] || [ "${TELEGRAM_CHAT}" = '0' ]; then
METHOD_TELEGRAM='0'
else
METHOD_TELEGRAM='1'
fi
else
UPTIMEBOT_LOG="/var/log/uptimebot.log"
UPTIMEBOT_DATABASE='/usr/local/etc/uptimebot/targets.conf'
UPTIMEBOT_DELAY='0.5'
fi
####################################################################################################
# ARGUMENT HANDLING
####################################################################################################
# populate validation variables with zeros for validation
ARGUMENT_OPTION='0'
ARGUMENT_FEATURE='0'
ARGUMENT_METHOD='0'
ARGUMENT_VERSION='0'
ARGUMENT_HELP='0'
ARGUMENT_CHECK='0'
ARGUMENT_CRON='0'
ARGUMENT_PING='0'
ARGUMENT_PORT='0'
ARGUMENT_HTTP='0'
ARGUMENT_DNS='0'
ARGUMENT_TLS='0'
ARGUMENT_TOR='0'
ARGUMENT_ALL='0'
ARGUMENT_LIST='0'
ARGUMENT_LOG='0'
ARGUMENT_CLI='0'
ARGUMENT_TELEGRAM='0'
# watch arguments
while test -n "$1"; do
case "$1" in
# options
--version|-version|version|--v|-v|v)
ARGUMENT_VERSION='1'
ARGUMENT_OPTION='1'
shift
;;
--help|-help|help|--h|-h|h)
ARGUMENT_HELP='1'
ARGUMENT_OPTION='1'
shift
;;
--check|-check|check)
ARGUMENT_CHECK='1'
ARGUMENT_OPTION='1'
shift
;;
--cron|-cron|cron)
ARGUMENT_CRON='1'
ARGUMENT_OPTION='1'
shift
;;
# features
--ping|ping)
ARGUMENT_PING='1'
ARGUMENT_FEATURE='1'
shift
;;
--port|port)
ARGUMENT_PORT='1'
ARGUMENT_FEATURE='1'
shift
;;
--http|http)
ARGUMENT_HTTP='1'
ARGUMENT_FEATURE='1'
shift
;;
--dns|dns)
ARGUMENT_DNS='1'
ARGUMENT_FEATURE='1'
shift
;;
--tls|tls)
ARGUMENT_TLS='1'
ARGUMENT_FEATURE='1'
shift
;;
--tor|tor)
ARGUMENT_TOR='1'
ARGUMENT_FEATURE='1'
shift
;;
--all|all)
ARGUMENT_ALL='1'
ARGUMENT_FEATURE='1'
shift
;;
# methods
--list|list)
ARGUMENT_LIST='1'
ARGUMENT_METHOD='1'
shift
;;
--log|log|-l|l)
ARGUMENT_LOG='1'
ARGUMENT_METHOD='1'
shift
;;
--cli|cli|-c|c)
ARGUMENT_CLI='1'
ARGUMENT_METHOD='1'
shift
;;
--telegram|telegram|-t|t)
ARGUMENT_TELEGRAM='1'
ARGUMENT_METHOD='1'
shift
;;
# other
*)
ARGUMENT_NONE='1'
shift
;;
esac
done
####################################################################################################
# ERROR FUNCTIONS
####################################################################################################
error_curl_not_installed() {
printf "uptimebot: curl not installed.\n"
printf "use 'pkg install curl' or install curl from ports.\n"
exit 1
}
error_invalid_argument() {
printf "uptimebot: invalid argument used.\nUse 'uptimebot --help' for a list of valid arguments.\n"
exit 1
}
error_more_than_one_feature() {
printf "uptimebot: only one uptimebot feature can be used at a time.\nUse 'uptimebot --help' for a list of valid arguments.\n"
exit 1
}
error_more_than_one_method() {
printf "uptimebot: only one uptimebot method can be used at a time.\nUse 'uptimebot --help' for a list of valid arguments.\n"
exit 1
}
error_method_not_supported() {
printf "uptimebot: the chosen method isn't supported for the chosen feature.\n"
exit 1
}
error_no_entries_found() {
printf "uptimebot: no relevant entries found for this method.\n"
exit 1
}
error_telegram_not_configured() {
printf "uptimebot: Telegram is nog configured properly, can't use method Telegram.\n"
exit 1
}
####################################################################################################
# REQUIREMENT FUNCTIONS
####################################################################################################
requirement_curl() {
# show error when curl cannot be found (which probably means the user has not installed curl)
if [ ! "$(command -v curl)" ]; then
error_curl_not_installed
fi
}
uptimebot_argument_validate() {
# combine argument categories
ARGUMENT_FEATURES_COMBINED="$((ARGUMENT_PING + ARGUMENT_PORT + ARGUMENT_HTTP + ARGUMENT_DNS + ARGUMENT_TLS + ARGUMENT_TOR + ARGUMENT_ALL))"
ARGUMENT_METHOD_COMBINED="$((ARGUMENT_LIST + ARGUMENT_LOG + ARGUMENT_CLI + ARGUMENT_TELEGRAM))"
if [ "${ARGUMENT_NONE}" = '1' ]; then
error_invalid_argument
# validate amount of selected features and return error when more than 1 feature is selected
elif [ "${ARGUMENT_FEATURES_COMBINED}" -gt '1' ]; then
error_more_than_one_feature
# validate amount of selected methods and return error when more than 1 feature is selected
elif [ "${ARGUMENT_METHOD_COMBINED}" -gt '1' ]; then
error_more_than_one_method
fi
# can't use telegram argument when telegram is not configured
if [ "${ARGUMENT_TELEGRAM}" = '1' ] && [ "${METHOD_TELEGRAM}" = '0' ]; then
error_telegram_not_configured
fi
}
####################################################################################################
# GENERAL FUNCTIONS
####################################################################################################
option_version() {
printf "Uptimebot %s\n" "${UPTIMEBOT_VERSION}"
printf "Copyright (C) 2021-2022 Nozel.\n"
printf "License CC Attribution-NonCommercial-ShareAlike 4.0 Int.\n\n"
printf "Written by Sebas Veeke\n"
# exit when done
exit 0
}
option_help() {
printf "Usage:\n"
printf " uptimebot [feature]... [method]...\n"
printf " uptimebot [option]...\n\n"
printf "Features:\n"
printf " --ping Monitor IP address status\n"
printf " --port Monitor port status\n"
printf " --http Monitor HTTP webserver status\n"
printf " --dns Monitor DNS records status\n"
printf " --tls Monitor expiration date for TLS certs\n"
#printf " --tor Monitor Tor Relay availability\n"
printf " --all Monitor all configured Features\n\n"
printf "Methods:\n"
printf " --list (default) Output configured rules to cli\n"
printf " --log Start monitoring and only output to log\n"
printf " --cli Start monitoring and output to log and cli\n"
printf " --telegram Start monitoring and output to log and Telegram\n\n"
printf "Options:\n"
printf " --check Checks monitoring target list for validity\n"
printf " --cron Effectuate cron changes from uptimebot config\n"
printf " --help Display this help and exit\n"
printf " --version Display version information and exit\n"
# exit when done
exit 0
}
option_check() {
# PING checks amount of arguments and whether IP addresses are used
# PORT checks amount of arguments and whether the port is a number
# HTTP, DNS and TLS checks amount of arguments only
DIVIDER="============================================================================="
HEADER="\n %-5s %-5s %-8s %-8s %-36s\n"
FORMAT=" %-5s %-5s %-8s %-8s %-36s\n"
WIDTH="77"
printf "${HEADER}" "CHECK" "LINE" "FEATURE" "STATUS" "ERROR"
printf "%${WIDTH}.${WIDTH}s\n" "${DIVIDER}"
LINE_NUMBER='0'
while read -r line; do
LINE_NUMBER="$(( LINE_NUMBER + 1 ))"
LINE_PREFACE="$(echo "${line}" | awk '{print $1;}')"
if [ "${LINE_PREFACE}" = 'ping' ]; then
if [ "$(echo "${line}" | wc -w)" -eq '2' ]; then
if [ "$(echo "${line}" | awk '{print $2;}')" != "${1#*[0-9].[0-9]}" ] || [ "$(echo "${line}" | awk '{print $2;}')" != "${1#*:[0-9a-fA-F]}" ]; then
printf "${FORMAT}" "[i]" "${LINE_NUMBER}" "PING" "PASS" ""
else
printf "${FORMAT}" "[!]" "${LINE_NUMBER}" "PING" "ERROR" "NO VALID IP"
fi
else
printf "${FORMAT}" "[!]" "${LINE_NUMBER}" "PING" "ERROR" "Wrong amount of arguments"
fi
elif [ "${LINE_PREFACE}" = 'port4' ] || [ "${LINE_PREFACE}" = 'port6' ] || [ "${LINE_PREFACE}" = 'port4i' ] || [ "${LINE_PREFACE}" = 'port6i' ]; then
if [ "$(echo "${line}" | wc -w)" -eq '3' ]; then
if [ "$(echo "${line}" | awk '{print $3;}')" -eq "$(echo "${line}" | awk '{print $3;}')" ] 2> /dev/null ; then
printf "${FORMAT}" "[i]" "${LINE_NUMBER}" "PORT" "PASS" ""
else
printf "${FORMAT}" "[!]" "${LINE_NUMBER}" "PORT" "ERROR" "Port not recognized"
fi
else
printf "${FORMAT}" "[!]" "${LINE_NUMBER}" "PORT" "ERROR" "Wrong amount of arguments"
fi
elif [ "${LINE_PREFACE}" = 'http4' ] || [ "${LINE_PREFACE}" = 'http6' ] || [ "${LINE_PREFACE}" = 'https4' ] || [ "${LINE_PREFACE}" = 'https6' ]; then
if [ "$(echo "${line}" | wc -w)" -eq '2' ]; then
printf "${FORMAT}" "[i]" "${LINE_NUMBER}" "HTTP" "PASS" ""
else
printf "${FORMAT}" "[!]" "${LINE_NUMBER}" "HTTP" "ERROR" "Wrong amount of arguments"
fi
elif [ "${LINE_PREFACE}" = 'a' ] || [ "${LINE_PREFACE}" = 'aaaa' ] || [ "${LINE_PREFACE}" = 'cname' ] || [ "${LINE_PREFACE}" = 'txt' ] || \
[ "${LINE_PREFACE}" = 'mx' ] || [ "${LINE_PREFACE}" = 'ns' ] || [ "${LINE_PREFACE}" = 'soa' ] || [ "${LINE_PREFACE}" = 'ptr' ]; then
if [ "$(echo "${line}" | wc -w)" -eq '3' ]; then
printf "${FORMAT}" "[i]" "${LINE_NUMBER}" "DNS" "PASS" ""
else
printf "${FORMAT}" "[!]" "${LINE_NUMBER}" "DNS" "ERROR" "Wrong amount of arguments"
fi
elif [ "${LINE_PREFACE}" = 'tls' ]; then
if [ "$(echo "${line}" | wc -w)" -eq '2' ]; then
printf "${FORMAT}" "[i]" "${LINE_NUMBER}" "TLS" "PASS" ""
else
printf "${FORMAT}" "[!]" "${LINE_NUMBER}" "TLS" "ERROR" "Wrong amount of arguments"
fi
fi
done < ${UPTIMEBOT_DATABASE}
}
option_cron() {
printf "[1] Removing old uptimebot cronjob\n"
rm -f /etc/cron.d/uptimebot
if [ "${PING_LOG}" = 'NO' ] && [ "${PING_TELEGRAM}" = 'NO' ] && \
[ "${PORT_LOG}" = 'NO' ] && [ "${PORT_TELEGRAM}" = 'NO' ] && \
[ "${HTTP_LOG}" = 'NO' ] && [ "${HTTP_TELEGRAM}" = 'NO' ] && \
[ "${DNS_LOG}" = 'NO' ] && [ "${DNS_TELEGRAM}" = 'NO' ] && \
[ "${TLS_LOG}" = 'NO' ] && [ "${TLS_TELEGRAM}" = 'NO' ] && \
[ "${TOR_LOG}" = 'NO' ] && [ "${TOR_TELEGRAM}" = 'NO' ] && \
[ "${ALL_LOG}" = 'NO' ] && [ "${ALL_TELEGRAM}" = 'NO' ]; then
printf "[2] No automated tasks to add.\n"
printf "All done!\n"
else
printf "[2] Adding configured automated tasks for:\n"
if [ "${PING_TELEGRAM}" = 'YES' ]; then
printf " - ping to Telegram on cron schedule %s\n" "${PING_CRON}"
printf "%s root /usr/local/bin/uptimebot --ping --telegram\n" "${PING_CRON}" >> /etc/cron.d/uptimebot
elif [ "${PING_LOG}" = 'YES' ]; then
printf " - ping to log on cron schedule %s\n" "${PING_CRON}"
printf "%s root /usr/local/bin/uptimebot --ping --log\n" "${PING_CRON}" >> /etc/cron.d/uptimebot
fi
if [ "${PORT_TELEGRAM}" = 'YES' ]; then
printf " - port to Telegram on cron schedule %s\n" "${PORT_CRON}"
printf "%s root /usr/local/bin/uptimebot --port --telegram\n" "${PORT_CRON}" >> /etc/cron.d/uptimebot
elif [ "${PORT_LOG}" = 'YES' ]; then
printf " - port to log on cron schedule %s\n" "${PORT_CRON}"
printf "%s root /usr/local/bin/uptimebot --port --log\n" "${PORT_CRON}" >> /etc/cron.d/uptimebot
fi
if [ "${HTTP_TELEGRAM}" = 'YES' ]; then
printf " - HTTP to Telegram on cron schedule %s\n" "${HTTP_CRON}"
printf "%s root /usr/local/bin/uptimebot --http --telegram\n" "${HTTP_CRON}" >> /etc/cron.d/uptimebot
elif [ "${HTTP_LOG}" = 'YES' ]; then
printf " - HTTP to log on cron schedule %s\n" "${HTTP_CRON}"
printf "%s root /usr/local/bin/uptimebot --http --log\n" "${HTTP_CRON}" >> /etc/cron.d/uptimebot
fi
if [ "${DNS_TELEGRAM}" = 'YES' ]; then
printf " - DNS to Telegram on cron schedule %s\n" "${DNS_CRON}"
printf "%s root /usr/local/bin/uptimebot --dns --telegram\n" "${DNS_CRON}" >> /etc/cron.d/uptimebot
elif [ "${DNS_LOG}" = 'YES' ]; then
printf " - DNS to log on cron schedule %s\n" "${DNS_CRON}"
printf "%s root /usr/local/bin/uptimebot --dns --log\n" "${DNS_CRON}" >> /etc/cron.d/uptimebot
fi
if [ "${TLS_TELEGRAM}" = 'YES' ]; then
printf " - TLS to Telegram on cron schedule %s\n" "${TLS_CRON}"
printf "%s root /usr/local/bin/uptimebot --tls --telegram\n" "${TLS_CRON}" >> /etc/cron.d/uptimebot
elif [ "${TLS_LOG}" = 'YES' ]; then
printf " - TLS to log on cron schedule %s\n" "${TLS_CRON}"
printf "%s root /usr/local/bin/uptimebot --tls --log\n" "${TLS_CRON}" >> /etc/cron.d/uptimebot
fi
if [ "${TOR_TELEGRAM}" = 'YES' ]; then
printf " - TOR to Telegram on cron schedule %s\n" "${TOR_CRON}"
printf "%s root /usr/local/bin/uptimebot --tor --telegram\n" "${TOR_CRON}" >> /etc/cron.d/uptimebot
elif [ "${TOR_LOG}" = 'YES' ]; then
printf " - TOR to log on cron schedule %s\n" "${TOR_CRON}"
printf "%s root /usr/local/bin/uptimebot --tor --log\n" "${TOR_CRON}" >> /etc/cron.d/uptimebot
fi
if [ "${ALL_TELEGRAM}" = 'YES' ]; then
printf " - ALL to Telegram on cron schedule %s\n" "${ALL_CRON}"
printf "%s root /usr/local/bin/uptimebot --all --telegram\n" "${ALL_CRON}" >> /etc/cron.d/uptimebot
elif [ "${ALL_LOG}" = 'YES' ]; then
printf " - ALL to log on cron schedule %s\n" "${ALL_CRON}"
printf "%s root /usr/local/bin/uptimebot --all --logon\n" "${ALL_CRON}" >> /etc/cron.d/uptimebot
fi
printf "All done! Your new schedule can be found in /etc/cron.d/uptimebot.\n"
fi
# exit when done
exit 0
}
####################################################################################################
# SUPPORT FUNCTIONS
####################################################################################################
slow_down() {
sleep "${UPTIMEBOT_DELAY}"
}
check_ip_version() {
if [ "${1}" != "${1#*[0-9].[0-9]}" ]; then
IP_VERSION='4'
elif [ "${1}" != "${1#*:[0-9a-fA-F]}" ]; then
IP_VERSION='6'
else
printf "uptimebot: error: IP address not recognized.\n"
fi
}
send_error_to_log() {
DATE="$(date +%Y-%m-%d)"
TIME="$(date +%H:%M:%S)"
printf "[%s][%s][ERROR]%s %s %s\n" "${DATE}" "${TIME}" "${1}" "${2}" "${3}" >> ${UPTIMEBOT_LOG}
}
send_error_to_telegram() {
CURRENT_FEATURE="$(echo "${line}" | awk '{print $1;}')"
if [ "${CURRENT_FEATURE}" = 'ping' ]; then
TELEGRAM_EMOJI='%f0%9f%94%a5'
elif [ "${CURRENT_FEATURE}" = 'port4' ]; then
TELEGRAM_EMOJI='%f0%9f%94%a5'
elif [ "${CURRENT_FEATURE}" = 'port6' ]; then
TELEGRAM_EMOJI='%f0%9f%94%a5'
elif [ "${CURRENT_FEATURE}" = 'http4' ]; then
TELEGRAM_EMOJI='%f0%9f%94%a5'
elif [ "${CURRENT_FEATURE}" = 'http6' ]; then
TELEGRAM_EMOJI='%f0%9f%94%a5'
elif [ "${CURRENT_FEATURE}" = 'https4' ]; then
TELEGRAM_EMOJI='%f0%9f%94%a5'
elif [ "${CURRENT_FEATURE}" = 'https6' ]; then
TELEGRAM_EMOJI='%f0%9f%94%a5'
elif [ "${CURRENT_FEATURE}" = 'a' ]; then
TELEGRAM_EMOJI='%e2%9a%a0'
elif [ "${CURRENT_FEATURE}" = 'aaaa' ]; then
TELEGRAM_EMOJI='%e2%9a%a0'
elif [ "${CURRENT_FEATURE}" = 'cname' ]; then
TELEGRAM_EMOJI='%e2%9a%a0'
elif [ "${CURRENT_FEATURE}" = 'txt' ]; then
TELEGRAM_EMOJI='%e2%9a%a0'
elif [ "${CURRENT_FEATURE}" = 'mx' ]; then
TELEGRAM_EMOJI='%e2%9a%a0'
elif [ "${CURRENT_FEATURE}" = 'ns' ]; then
TELEGRAM_EMOJI='%e2%9a%a0'
elif [ "${CURRENT_FEATURE}" = 'soa' ]; then
TELEGRAM_EMOJI='%e2%9a%a0'
elif [ "${CURRENT_FEATURE}" = 'ptr' ]; then
TELEGRAM_EMOJI='%e2%9a%a0'
elif [ "${CURRENT_FEATURE}" = 'tls' ]; then
TELEGRAM_EMOJI='%e2%8f%b1'
elif [ "${CURRENT_FEATURE}" = 'tor' ]; then
TELEGRAM_EMOJI='%f0%9f%94%a5'
fi
TELEGRAM_MESSAGE="$(echo -e "${TELEGRAM_EMOJI} <b>${1}</b>\n${2} ${3}")"
method_telegram
}
####################################################################################################
# FEATURE FUNCTIONS
####################################################################################################
feature_ping_list() {
PROTOCOL_PING='0'
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'ping' ]; then
PROTOCOL_PING='1'
fi
done < ${UPTIMEBOT_DATABASE}
if [ "${PROTOCOL_PING}" -eq '1' ]; then
DIVIDER="============================================================================="
HEADER="\n %-5s %-8s %-36s\n"
FORMAT=" %-5s %-8s %-36s\n"
WIDTH="77"
printf "${HEADER}" "PING" "IP" "IP ADDRESS"
printf "%${WIDTH}.${WIDTH}s\n" "${DIVIDER}"
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'ping' ]; then
IP_ADDRESS="$(echo "${line}" | awk '{print $2;}')"
check_ip_version "${IP_ADDRESS}"
printf "${FORMAT}" "[*]" "IPv${IP_VERSION}" "${IP_ADDRESS}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
}
feature_port_list() {
PROTOCOL_PORT4='0'
PROTOCOL_PORT6='0'
PROTOCOL_PORT4_INVERSE='0'
PROTOCOL_PORT6_INVERSE='0'
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'port4' ]; then
PROTOCOL_PORT4='1'
fi
if [ "$(echo "${line}" | awk '{print $1;}')" = 'port6' ]; then
PROTOCOL_PORT6='1'
fi
if [ "$(echo "${line}" | awk '{print $1;}')" = 'port4i' ]; then
PROTOCOL_PORT4_INVERSE='1'
fi
if [ "$(echo "${line}" | awk '{print $1;}')" = 'port6i' ]; then
PROTOCOL_PORT6_INVERSE='1'
fi
done < ${UPTIMEBOT_DATABASE}
if [ "${PROTOCOL_PORT4}" -eq '1' ] || [ "${PROTOCOL_PORT6}" -eq '1' ] || \
[ "${PROTOCOL_PORT4_INVERSE}" -eq '1' ] || [ "${PROTOCOL_PORT6_INVERSE}" -eq '1' ]; then
DIVIDER="============================================================================="
HEADER="\n %-5s %-8s %-8s %-8s %-36s\n"
FORMAT=" %-5s %-8s %-8s %-8s %-36s\n"
WIDTH="77"
printf "${HEADER}" "PORT" "IP" "PORT" "TEST" "HOST"
printf "%${WIDTH}.${WIDTH}s\n" "${DIVIDER}"
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'port4' ]; then
HOST="$(echo "${line}" | awk '{print $2;}')"
PORT_NUMBER="$(echo "${line}" | awk '{print $3;}')"
printf "${FORMAT}" "[*]" "IPv4" "${PORT_NUMBER}" "OPEN" "${HOST}"
fi
done < ${UPTIMEBOT_DATABASE}
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'port6' ]; then
HOST="$(echo "${line}" | awk '{print $2;}')"
PORT_NUMBER="$(echo "${line}" | awk '{print $3;}')"
printf "${FORMAT}" "[*]" "IPv6" "${PORT_NUMBER}" "OPEN" "${HOST}"
fi
done < ${UPTIMEBOT_DATABASE}
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'port4i' ]; then
HOST="$(echo "${line}" | awk '{print $2;}')"
PORT_NUMBER="$(echo "${line}" | awk '{print $3;}')"
printf "${FORMAT}" "[*]" "IPv4" "${PORT_NUMBER}" "CLOSED" "${HOST}"
fi
done < ${UPTIMEBOT_DATABASE}
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'port6i' ]; then
HOST="$(echo "${line}" | awk '{print $2;}')"
PORT_NUMBER="$(echo "${line}" | awk '{print $3;}')"
printf "${FORMAT}" "[*]" "IPv6" "${PORT_NUMBER}" "CLOSED" "${HOST}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
}
feature_http_list() {
PROTOCOL_HTTP4='0'
PROTOCOL_HTTP6='0'
PROTOCOL_HTTPS4='0'
PROTOCOL_HTTPS6='0'
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'http4' ]; then
PROTOCOL_HTTP4='1'
fi
if [ "$(echo "${line}" | awk '{print $1;}')" = 'http6' ]; then
PROTOCOL_HTTP6='1'
fi
if [ "$(echo "${line}" | awk '{print $1;}')" = 'https4' ]; then
PROTOCOL_HTTPS4='1'
fi
if [ "$(echo "${line}" | awk '{print $1;}')" = 'https6' ]; then
PROTOCOL_HTTPS6='1'
fi
done < ${UPTIMEBOT_DATABASE}
if [ "${PROTOCOL_HTTP4}" -eq '1' ] || [ "${PROTOCOL_HTTP6}" -eq '1' ] || \
[ "${PROTOCOL_HTTPS4}" -eq '1' ] || [ "${PROTOCOL_HTTPS6}" -eq '1' ]; then
DIVIDER="============================================================================="
HEADER="\n %-5s %-8s %-8s %-36s\n"
FORMAT=" %-5s %-8s %-8s %-36s\n"
WIDTH="77"
printf "${HEADER}" "HTTP" "IP" "PROTO" "HOST"
printf "%${WIDTH}.${WIDTH}s\n" "${DIVIDER}"
if [ "${PROTOCOL_HTTP4}" -eq '1' ]; then
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'http4' ]; then
DOMAIN_NAME="$(echo "${line}" | awk '{print $2;}')"
printf "${FORMAT}" "[*]" "IPv4" "HTTP" "${DOMAIN_NAME}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
if [ "${PROTOCOL_HTTP6}" -eq '1' ]; then
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'http6' ]; then
DOMAIN_NAME="$(echo "${line}" | awk '{print $2;}')"
printf "${FORMAT}" "[*]" "IPv6" "HTTP" "${DOMAIN_NAME}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
if [ "${PROTOCOL_HTTPS4}" -eq '1' ]; then
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'https4' ]; then
DOMAIN_NAME="$(echo "${line}" | awk '{print $2;}')"
printf "${FORMAT}" "[*]" "IPv4" "HTTPS" "${DOMAIN_NAME}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
if [ "${PROTOCOL_HTTPS6}" -eq '1' ]; then
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'https6' ]; then
DOMAIN_NAME="$(echo "${line}" | awk '{print $2;}')"
printf "${FORMAT}" "[*]" "IPv6" "HTTPS" "${DOMAIN_NAME}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
fi
}
feature_dns_list() {
PROTOCOL_DNS_A='0'
PROTOCOL_DNS_AAAA='0'
PROTOCOL_DNS_CNAME='0'
PROTOCOL_DNS_TXT='0'
PROTOCOL_DNS_MX='0'
PROTOCOL_DNS_NS='0'
PROTOCOL_DNS_SOA='0'
PROTOCOL_DNS_PTR='0'
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'a' ]; then
PROTOCOL_DNS_A='1'
fi
if [ "$(echo "${line}" | awk '{print $1;}')" = 'aaaa' ]; then
PROTOCOL_DNS_AAAA='1'
fi
if [ "$(echo "${line}" | awk '{print $1;}')" = 'cname' ]; then
PROTOCOL_DNS_CNAME='1'
fi
if [ "$(echo "${line}" | awk '{print $1;}')" = 'txt' ]; then
PROTOCOL_DNS_TXT='1'
fi
if [ "$(echo "${line}" | awk '{print $1;}')" = 'mx' ]; then
PROTOCOL_DNS_MX='1'
fi
if [ "$(echo "${line}" | awk '{print $1;}')" = 'ns' ]; then
PROTOCOL_DNS_NS='1'
fi
if [ "$(echo "${line}" | awk '{print $1;}')" = 'soa' ]; then
PROTOCOL_DNS_SOA='1'
fi
if [ "$(echo "${line}" | awk '{print $1;}')" = 'ptr' ]; then
PROTOCOL_DNS_PTR='1'
fi
done < ${UPTIMEBOT_DATABASE}
if [ "${PROTOCOL_DNS_A}" -eq '1' ] || [ "${PROTOCOL_DNS_AAAA}" -eq '1' ] || [ "${PROTOCOL_DNS_CNAME}" -eq '1' ] || [ "${PROTOCOL_DNS_TXT}" -eq '1' ] || \
[ "${PROTOCOL_DNS_MX}" -eq '1' ] || [ "${PROTOCOL_DNS_NS}" -eq '1' ] || [ "${PROTOCOL_DNS_SOA}" -eq '1' ] || [ "${PROTOCOL_DNS_PTR}" -eq '1' ]; then
DIVIDER="============================================================================="
HEADER="\n %-5s %-8s %-36s %-36s\n"
FORMAT=" %-5s %-8s %-36s %-36s\n"
WIDTH="77"
printf "${HEADER}" "DNS" "TYPE" "DOMAIN" "ENTRY"
printf "%${WIDTH}.${WIDTH}s\n" "${DIVIDER}"
if [ "${PROTOCOL_DNS_A}" -eq '1' ]; then
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'a' ]; then
DOMAIN_NAME="$(echo "${line}" | awk '{print $2;}')"
ENTRY="$(echo "${line}" | awk '{print $3;}')"
printf "${FORMAT}" "[*]" "A" "${DOMAIN_NAME}" "${ENTRY}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
if [ "${PROTOCOL_DNS_AAAA}" -eq '1' ]; then
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'aaaa' ]; then
DOMAIN_NAME="$(echo "${line}" | awk '{print $2;}')"
ENTRY="$(echo "${line}" | awk '{print $3;}')"
printf "${FORMAT}" "[*]" "AAAA" "${DOMAIN_NAME}" "${ENTRY}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
if [ "${PROTOCOL_DNS_CNAME}" -eq '1' ]; then
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'cname' ]; then
DOMAIN_NAME="$(echo "${line}" | awk '{print $2;}')"
ENTRY="$(echo "${line}" | awk '{print $3;}')"
printf "${FORMAT}" "[*]" "CNAME" "${DOMAIN_NAME}" "${ENTRY}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
if [ "${PROTOCOL_DNS_TXT}" -eq '1' ]; then
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'txt' ]; then
DOMAIN_NAME="$(echo "${line}" | awk '{print $2;}')"
ENTRY="$(echo "${line}" | awk '{print $3;}')"
printf "${FORMAT}" "[*]" "TXT" "${DOMAIN_NAME}" "${ENTRY}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
if [ "${PROTOCOL_DNS_MX}" -eq '1' ]; then
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'mx' ]; then
DOMAIN_NAME="$(echo "${line}" | awk '{print $2;}')"
ENTRY="$(echo "${line}" | awk '{print $3;}')"
printf "${FORMAT}" "[*]" "MX" "${DOMAIN_NAME}" "${ENTRY}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
if [ "${PROTOCOL_DNS_NS}" -eq '1' ]; then
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'ns' ]; then
DOMAIN_NAME="$(echo "${line}" | awk '{print $2;}')"
ENTRY="$(echo "${line}" | awk '{print $3;}')"
printf "${FORMAT}" "[*]" "NS" "${DOMAIN_NAME}" "${ENTRY}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
if [ "${PROTOCOL_DNS_SOA}" -eq '1' ]; then
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'soa' ]; then
DOMAIN_NAME="$(echo "${line}" | awk '{print $2;}')"
ENTRY="$(echo "${line}" | awk '{print $3;}')"
printf "${FORMAT}" "[*]" "SOA" "${DOMAIN_NAME}" "${ENTRY}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
if [ "${PROTOCOL_DNS_PTR}" -eq '1' ]; then
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'ptr' ]; then
DOMAIN_NAME="$(echo "${line}" | awk '{print $2;}')"
ENTRY="$(echo "${line}" | awk '{print $3;}')"
printf "${FORMAT}" "[*]" "PTR" "${DOMAIN_NAME}" "${ENTRY}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
fi
}
feature_tls_list() {
PROTOCOL_TLS='0'
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'tls' ]; then
PROTOCOL_TLS='1'
fi
done < ${UPTIMEBOT_DATABASE}
if [ "${PROTOCOL_TLS}" -eq '1' ]; then
DIVIDER="============================================================================="
HEADER="\n %-5s %-36s\n"
FORMAT=" %-5s %-36s\n"
WIDTH="77"
printf "${HEADER}" "DOMAIN NAME"
printf "%${WIDTH}.${WIDTH}s\n" "${DIVIDER}"
if [ "${PROTOCOL_TLS}" -eq '1' ]; then
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'tls' ]; then
DOMAIN_NAME="$(echo "${line}" | awk '{print $2;}')"
printf "${FORMAT}" "[*]" "${DOMAIN_NAME}"
fi
done < ${UPTIMEBOT_DATABASE}
fi
fi
}
feature_tor_list() {
printf ''
}
feature_all_list() {
feature_ping_list
feature_port_list
feature_http_list
feature_dns_list
feature_tls_list
#feature_tor_list
}
feature_ping() {
PROTOCOL_PING='0'
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'ping' ]; then
PROTOCOL_PING='1'
fi
done < ${UPTIMEBOT_DATABASE}
if [ "${PROTOCOL_PING}" -eq '1' ]; then
if [ "${ARGUMENT_CLI}" -eq '1' ]; then
DIVIDER="============================================================================="
HEADER="\n %-5s %-8s %-8s %-36s\n"
FORMAT=" %-5s %-8s %-8s %-36s\n"
WIDTH="77"
printf "${HEADER}" "PING" "STATUS" "IP" "IP ADDRESS"
printf "%${WIDTH}.${WIDTH}s\n" "${DIVIDER}"
fi
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'ping' ]; then
slow_down
IP_ADDRESS="$(echo "${line}" | awk '{print $2;}')"
check_ip_version "${IP_ADDRESS}"
if [ "${IP_VERSION}" -eq '4' ]; then
if ! ping -q -c1 -t2 "${IP_ADDRESS}" > /dev/null 2>&1; then
if ! ping -q -c1 -t2 "${IP_ADDRESS}" > /dev/null 2>&1; then
send_error_to_log "[PING][IPv4]" "${IP_ADDRESS}"
if [ "${ARGUMENT_CLI}" -eq '1' ]; then
printf "${FORMAT}" "[!]" "ERROR" "IPv4" "${IP_ADDRESS}"
elif [ "${ARGUMENT_TELEGRAM}" -eq '1' ]; then
send_error_to_telegram "[PING][IPv4]" "${IP_ADDRESS}"
fi
fi
else
if [ "${ARGUMENT_CLI}" -eq '1' ]; then
printf "${FORMAT}" "[i]" "OK" "IPv4" "${IP_ADDRESS}"
fi
fi
elif [ "${IP_VERSION}" -eq '6' ]; then
if ! ping6 -q -c1 -t2 "${IP_ADDRESS}" > /dev/null 2>&1; then
if ! ping6 -q -c1 -t2 "${IP_ADDRESS}" > /dev/null 2>&1; then
send_error_to_log "[PING][IPv6]" "${IP_ADDRESS}"
if [ "${ARGUMENT_CLI}" -eq '1' ]; then
printf "${FORMAT}" "[!]" "ERROR" "IPv6" "${IP_ADDRESS}"
elif [ "${ARGUMENT_TELEGRAM}" -eq '1' ]; then
send_error_to_telegram "[PING][IPv6]" "${IP_ADDRESS}"
fi
fi
else
if [ "${ARGUMENT_CLI}" -eq '1' ]; then
printf "${FORMAT}" "[i]" "OK" "IPv6" "${IP_ADDRESS}"
fi
fi
fi
fi
done < ${UPTIMEBOT_DATABASE}
fi
}
feature_port() {
PROTOCOL_PORT4='0'
PROTOCOL_PORT6='0'
PROTOCOL_PORT4_INVERSE='0'
PROTOCOL_PORT6_INVERSE='0'
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'port4' ]; then
PROTOCOL_PORT4='1'
fi
if [ "$(echo "${line}" | awk '{print $1;}')" = 'port6' ]; then
PROTOCOL_PORT6='1'
fi
done < ${UPTIMEBOT_DATABASE}
if [ "${PROTOCOL_PORT4}" -eq '1' ] || [ "${PROTOCOL_PORT6}" -eq '1' ] || \
[ "${PROTOCOL_PORT4_INVERSE}" -eq '1' ] || [ "${PROTOCOL_PORT6_INVERSE}" -eq '1' ]; then
if [ "${ARGUMENT_CLI}" -eq '1' ]; then
DIVIDER="============================================================================="
HEADER="\n %-5s %-8s %-8s %-8s %-36s\n"
FORMAT=" %-5s %-8s %-8s %-8s %-36s\n"
WIDTH="77"
printf "${HEADER}" "PORT" "STATUS" "IP" "NR" "HOST"
printf "%${WIDTH}.${WIDTH}s\n" "${DIVIDER}"
fi
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'port4' ]; then
slow_down
HOST="$(echo "${line}" | awk '{print $2;}')"
PORT_NUMBER="$(echo "${line}" | awk '{print $3;}')"
if ! nc -4zw2 "${HOST}" "${PORT_NUMBER}" > /dev/null 2>&1; then
send_error_to_log "[PORT][${PORT_NUMBER}][IPv4]" "${HOST}:${PORT_NUMBER}"
if [ "${ARGUMENT_CLI}" -eq '1' ]; then
printf "${FORMAT}" "[!]" "ERROR" "IPv4" "${PORT_NUMBER}" "${HOST}"
elif [ "${ARGUMENT_TELEGRAM}" -eq '1' ]; then
send_error_to_telegram "[PORT][IPv4]" "${HOST}:${PORT_NUMBER}"
fi
else
if [ "${ARGUMENT_CLI}" -eq '1' ]; then
printf "${FORMAT}" "[i]" "OK" "IPv4" "${PORT_NUMBER}" "${HOST}"
fi
fi
fi
done < ${UPTIMEBOT_DATABASE}
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'port6' ]; then
slow_down
HOST="$(echo "${line}" | awk '{print $2;}')"
PORT_NUMBER="$(echo "${line}" | awk '{print $3;}')"
if ! nc -6zw2 "${HOST}" "${PORT_NUMBER}" > /dev/null 2>&1; then
send_error_to_log "[PORT][${PORT_NUMBER}][IPv6]" "${HOST}:${PORT_NUMBER}"
if [ "${ARGUMENT_CLI}" -eq '1' ]; then
printf "${FORMAT}" "[!]" "ERROR" "IPv6" "${PORT_NUMBER}" "${HOST}"
elif [ "${ARGUMENT_TELEGRAM}" -eq '1' ]; then
send_error_to_telegram "[PORT][IPv6]" "${HOST}:${PORT_NUMBER}"
fi
else
if [ "${ARGUMENT_CLI}" -eq '1' ]; then
printf "${FORMAT}" "[i]" "OK" "IPv6" "${PORT_NUMBER}" "${HOST}"
fi
fi
fi
done < ${UPTIMEBOT_DATABASE}
while read -r line; do
if [ "$(echo "${line}" | awk '{print $1;}')" = 'port4i' ]; then
slow_down
HOST="$(echo "${line}" | awk '{print $2;}')"
PORT_NUMBER="$(echo "${line}" | awk '{print $3;}')"
if nc -4zw2 "${HOST}" "${PORT_NUMBER}" > /dev/null 2>&1; then
send_error_to_log "[PORT][${PORT_NUMBER}][IPv4]" "${HOST}:${PORT_NUMBER}"
if [ "${ARGUMENT_CLI}" -eq '1' ]; then
printf "${FORMAT}" "[!]" "ERROR" "IPv4" "${PORT_NUMBER}" "${HOST}"
elif [ "${ARGUMENT_TELEGRAM}" -eq '1' ]; then
send_error_to_telegram "[PORT][IPv4]" "${HOST}:${PORT_NUMBER}"
fi