/
vpnmon-r2-2.64.sh
5850 lines (5130 loc) · 277 KB
/
vpnmon-r2-2.64.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
# VPNMON-R2 v2.64 (VPNMON-R2.SH) is an all-in-one script that is optimized for NordVPN, SurfShark VPN and Perfect Privacy
# VPN services. It can also compliment @JackYaz's VPNMGR program to maintain a NordVPN/PIA/WeVPN setup, and is able to
# function perfectly in a standalone environment with your own personal VPN service. This script will check the health of
# (up to) 5 VPN connections on a regular interval to see if one is connected, and sends a ping to a host of your choice
# through the active connection. If it finds that connection has been lost, it will execute a series of commands that will
# kill all VPN clients, will optionally whitelist all NordVPN/PerfectPrivacy VPN servers in the Skynet Firewall, and
# randomly picks one of your (up to) 5 VPN Clients to connect to. One of VPNMON-R2's unique features is called
# "SuperRandom", where it will randomly assign VPN endpoints for a random county (or your choice) to your VPN slots, and
# randomly connect to one of these. It will now also test your WAN connection, and put itself into standby until the WAN
# is restored before reconnecting your VPN connections.
# -------------------------------------------------------------------------------------------------------------------------
# Usage and configuration Guide - *UPDATED*
# -------------------------------------------------------------------------------------------------------------------------
# All previous user-selectable options are now available through the Configuration Utility. You may access and run this
# utility by running "vpnmon-r2 -setup". Once configured, a "vpnmon-r2.cfg" file will be written to your
# /jffs/addons/vpnmon-r2.d/ folder containing the options you have selected. Once everything looks good, you are able to
# run VPNMON-R2 for under normal monitoring conditions using this command: "vpnmon-r2 -monitor". Please note this change
# for any current automations you may have in place. To easily view the log file, enter: "vpnmon-r2 -log". You will be
# prompted as new updates become available going forward with v1.2. Use "vpnmon-r2 -update" to update the script. If
# you want to learn about other functions, use "vpnmon-r2 -h or -help".
# -------------------------------------------------------------------------------------------------------------------------
# Shellcheck exclusions
# -------------------------------------------------------------------------------------------------------------------------
# shellcheck disable=SC2034
# shellcheck disable=SC3037
# shellcheck disable=SC2162
# shellcheck disable=SC3045
# shellcheck disable=SC2183
# shellcheck disable=SC2086
# shellcheck disable=SC3014
# shellcheck disable=SC2059
# shellcheck disable=SC2002
# shellcheck disable=SC2004
# shellcheck disable=SC3028
# shellcheck disable=SC2140
# shellcheck disable=SC3046
# shellcheck disable=SC1090
# -------------------------------------------------------------------------------------------------------------------------
# System Variables (Do not change beyond this point or this may change the programs ability to function correctly)
# -------------------------------------------------------------------------------------------------------------------------
Version="2.64" # Current version of VPNMON-R2
Beta=0 # Beta Testmode on/off
DLVersion="0.0" # Current version of VPNMON-R2 from source repository
LOCKFILE="/jffs/scripts/VRSTLock.txt" # Predefined lockfile that VPNMON-R2 creates when it resets the VPN so
# that VPNMON-R2 does not interfere during an external reset
RSTFILE="/jffs/addons/vpnmon-r2.d/vpnmon-rst.log" # Logfile containing the last date/time a VPN reset was performed. Else,
# the latest date/time that VPNMON-R2 restarted will be shown.
LOGFILE="/jffs/addons/vpnmon-r2.d/vpnmon-r2.log" # Logfile path/name that captures important date/time events - change
APPPATH="/jffs/scripts/vpnmon-r2.sh" # Path to the location of vpnmon-r2.sh
CFGPATH="/jffs/addons/vpnmon-r2.d/vpnmon-r2.cfg" # Path to the location of vpnmon-r2.cfg
DLVERPATH="/jffs/addons/vpnmon-r2.d/version.txt" # Path to downloaded version from the source repository
YAZFI_CONFIG_PATH="/jffs/addons/YazFi.d/config" # Path to the YazFi guest network(s) config file
APPSTATUS="/jffs/addons/vpnmon-r2.d/appstatus.txt" # Path to the current status of VPNMON-R2
LockFound=0 # Lockfile variable for VPN resets
PauseLockFound=0 # Lockfile variable for pause and resumes
StopLockFound=0 # Lockfile variable for stops
WAN1OverrideLock=0 # Lockfile variable for WAN1 vpn connection overrides
NewScreen=0 # Screen variable to determine if it's new or reused
connState=2 # Status = 2 means VPN is connected, 1 = connecting, 0 = not connected
BASE=1 # Random numbers start at BASE up to N, ie. 1..3
STATUS=0 # Tracks whether or not a ping was successful
VPNCLCNT=0 # Tracks to make sure there are not multiple connections running
CURRCLNT=0 # Tracks which VPN client is currently active
CNT=0 # Counter
FromUI=0 # Tracks selections made from the UI
AVGPING=0 # Average ping value
MINPING=100 # Minimum ping value in ms before a reset takes place
USELOWESTSLOT=1 # Option to select either random VPN slot connections, or using the one
# with the lowest PING
FORCEDRESET=0 # Variable tracks whether a forced reset is initiated through the UI
LOWPINGCOUNT=0 # Counter for the number of tries before switching to lower ping server
PINGCHANCES=5 # Number of chances your current connection gets before reconnecting to
IGNOREHIGHPING=0 # Ignore high ping rule if running on WAN1 failover mode faster server
RecommendedServer=0 # Tracks NordVPN Closest/lowest latency Recommended Server Option
WAN1Override=1 # Tracks WAN1 Overrides preventing VPN connections while WAN1 is active
UpdateUnbound=0 # Tracks whether to update Unbound with the current VPN slot
UnboundReset=0 # Tracks whether to reset VPN if Unbound becomes out of sync with WAN IP
ResolverTimer=1 # Timer to give the DNS resolver check time to settle before getting its value
SPIN=15 # 15-second Spin timer
state1=0 # Initialize the VPN connection states for VPN Clients 1-5
state2=0
state3=0
state4=0
state5=0
START=$(date +%s) # Start a timer to determine intervals of VPN resets
EXTERNALRESET=0 # Option for external reset capabilities
EXT_SOURCE="None" # External reset file URL location
EXTINTERVAL=900 # Timer interval for tracking external file resets
DelayStartup=0 # Tracking the delayed startup timer
AUTOSTART=0 # Tracking if VPNMON-R2 will auto start on router reboot
TRIMLOGS=0 # Tracking log sizes for trimming functionality
MAXLOGSIZE=1000
CURRLOGSIZE=0
SKIPPROGRESS=0 # Variable to skip the progress bar
VPNIP="Unassigned" # Tracking VPN IP for city location display. API gives you 1K lookups
# per day, and is optimized to only lookup city location after a reset
vpnresettripped=0 # Tracking whether a VPN Reset is tripped due to a WAN outage
WAN0IP="Unassigned" # Tracking WAN IP for city location display
WAN1IP="Unassigned" # Tracking WAN IP for city location display
ICANHAZIP="" # Variable for tracking public facing VPN IP
VPNLOAD=0 # Variable tracks the NordVPN server load
AVGPING=0 # Variable tracks average ping time
PINGLOW=0 # Variable tracks lowest ping time
PINGHIGH=0 # Variable tracks highest ping time
SHOWSTATS=0 # Tracks whether you want to show stats on/off if you like minimalism
rxbytes=0 # Variables to capture and measure TX/RX rates on VPN Tunnel
txbytes=0
txrxbytes=0
rxgbytes=0
txgbytes=0
oldrxbytes=0
newrxbytes=0
oldtxbytes=0
newtxbytes=0
SyncYazFi=0 # Variables that track whether or not to sythe active VPN slot with
YF24GN1=0 # user-selectable YazFi guest networks
YF24GN2=0
YF24GN3=0
YF5GN1=0
YF5GN2=0
YF5GN3=0
YF52GN1=0
YF52GN2=0
YF52GN3=0
UseSurfShark=0 # Variables for SurfShark VPN
SurfSharkMultipleCountries=0
SurfSharkCountry="United States"
SurfSharkCountry2=""
SurfSharkCountry3=""
SurfSharkSuperRandom=0
SurfSharkLoadReset=50
UsePP=0 # Variables for Perfect Privacy VPN
PPMultipleCountries=0
PPCountry="United States"
PPCountry2=""
PPCountry3=""
PPSuperRandom=0
PPLoadReset=50
UseWeVPN=0 # Variables for WeVPN
WeVPNMultipleCountries=0
WeVPNCountry="USA"
WeVPNCountry2=""
WeVPNCountry3=""
WeVPNSuperRandom=0
WeVPNLoadReset=50
UseAirVPN=0 # Variables for AirVPN
AirVPNMultipleCountries=0
AirVPNCountry="United States"
AirVPNCountry2=""
AirVPNCountry3=""
AirVPNSuperRandom=0
AirVPNLoadReset=50
# Color variables
CBlack="\e[1;30m"
InvBlack="\e[1;40m"
CRed="\e[1;31m"
InvRed="\e[1;41m"
CGreen="\e[1;32m"
InvGreen="\e[1;42m"
CDkGray="\e[1;90m"
InvDkGray="\e[1;100m"
InvLtGray="\e[1;47m"
CYellow="\e[1;33m"
InvYellow="\e[1;43m"
CBlue="\e[1;34m"
InvBlue="\e[1;44m"
CMagenta="\e[1;35m"
CCyan="\e[1;36m"
InvCyan="\e[1;46m"
CWhite="\e[1;37m"
InvWhite="\e[1;107m"
CClear="\e[0m"
#Preferred standard router binaries path
export PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH"
# -------------------------------------------------------------------------------------------------------------------------
# Functions
# -------------------------------------------------------------------------------------------------------------------------
# Logo is a function that displays the VPNMON-R2 script name in a cool ASCII font
logo () {
echo -e "${CYellow} _ ______ _ ____ _______ _ __ ____ ___ "
echo -e " | | / / __ \/ | / / |/ / __ \/ | / / / __ \__ \ ${CGreen}v$Version${CYellow}"
echo -e " | | / / /_/ / |/ / /|_/ / / / / |/ /_____/ /_/ /_/ / "
echo -e " | |/ / ____/ /| / / / / /_/ / /| /_____/ _, _/ __/ "
echo -e " |___/_/ /_/ |_/_/ /_/\____/_/ |_/ /_/ |_/____/ "
echo ""
}
# -------------------------------------------------------------------------------------------------------------------------
# Promptyn is a function that helps return a 0 or 1 from a Y/N question from the configuration utility.
promptYesn () { # Enter defaults Yes
while true; do
read -p " [Y/n]? " yn
case $yn in
[Yy] ) echo -e "${CGreen} Using: Yes${CClear}";return 0 ;;
[Nn] ) echo -e "${CGreen} Using: No${CClear}";return 1 ;;
"" ) echo -e "${CGreen} Using: Yes${CClear}";return 0 ;;
* ) echo -e "\n Please answer y or n, or Enter to accept default value.";;
esac
done
}
promptyNo () { # Enter defaults No
while true; do
read -p " [y/N]? " yn
case $yn in
[Yy] ) echo -e "${CGreen} Using: Yes${CClear}";return 0 ;;
[Nn] ) echo -e "${CGreen} Using: No${CClear}";return 1 ;;
"" ) echo -e "${CGreen} Using: No${CClear}";return 1 ;;
* ) echo -e "\n Please answer y or n, or Enter to accept default value.";;
esac
done
}
promptyn () { # No defaults, just y or n
while true; do
read -p "$1" -n 1 -r yn
case "${yn}" in
[Yy]* ) return 0 ;;
[Nn]* ) return 1 ;;
* ) echo -e "\n Please answer y or n.";;
esac
done
}
# -------------------------------------------------------------------------------------------------------------------------
# Spinner is a script that provides a small indicator on the screen to show script activity
spinner() {
i=0
j=$((SPIN / 4))
while [ $i -le $j ]; do
for s in / - \\ \|; do
printf "\r $s"
sleep 1
done
i=$((i+1))
done
printf "\r"
}
# -------------------------------------------------------------------------------------------------------------------------
# Preparebar and Progressbar is a script that provides a nice progressbar to show script activity
preparebar() {
# $1 - bar length
# $2 - bar char
barlen=$1
barspaces=$(printf "%*s" "$1")
barchars=$(printf "%*s" "$1" | tr ' ' "$2")
}
progressbar() {
# $1 - number (-1 for clearing the bar)
# $2 - max number
if [ $1 -eq -1 ]; then
printf "\r $barspaces\r"
else
barch=$(($1*barlen/$2))
barsp=$((barlen-barch))
progr=$((100*$1/$2))
if [ $progr -le 60 ]; then
printf "${CGreen}\r [%.${barch}s%.${barsp}s]${CClear} ${CWhite}${InvDkGray}${i}s / ${progr}%%\r${CClear}" "$barchars" "$barspaces"
elif [ $progr -gt 60 ] && [ $progr -le 85 ]; then
printf "${CYellow}\r [%.${barch}s%.${barsp}s]${CClear} ${CWhite}${InvDkGray}${i}s / ${progr}%%\r${CClear}" "$barchars" "$barspaces"
else
printf "${CRed}\r [%.${barch}s%.${barsp}s]${CClear} ${CWhite}${InvDkGray}${i}s / ${progr}%%\r${CClear}" "$barchars" "$barspaces"
fi
fi
# Borrowed this wonderful keypress capturing mechanism from @Eibgrad... thank you! :)
key_press=''; read -rsn1 -t 1 key_press < "$(tty 0>&2)"
if [ $key_press ]; then
case $key_press in
[Ss]) FromUI=1; (vsetup); source $CFGPATH; echo -e "${CGreen} [Returning to the Main UI momentarily] "; sleep 1; FromUI=0; i=$INTERVAL;;
[Rr]) echo -e "${CGreen} [Reset Queued] "; sleep 1; FORCEDRESET=1; i=$INTERVAL; ICANHAZIP="Probing"; resetcheck; ResolverTimer=1;;
[Bb]) (bossmode);;
'e') # Exit gracefully
echo -e "${CClear}"
{ echo 'EXITED'
echo $LastSlotUsed
} > $APPSTATUS
exit 0
;;
esac
fi
}
progressbarnotification()
{
insertspc=" "
bypasswancheck=0
if [ $1 -eq -1 ]; then
printf "\r $barspaces\r"
else
if [ ! -z $7 ] && [ $1 -ge $7 ]; then
barch=$(($7*barlen/$2))
barsp=$((barlen-barch))
progr=$((100*$1/$2))
else
barch=$(($1*barlen/$2))
barsp=$((barlen-barch))
progr=$((100*$1/$2))
fi
if [ ! -z $6 ]; then AltNum=$6; else AltNum=$1; fi
if [ "$5" == "Standard" ]; then
printf " ${CWhite}${InvDkGray}Executing VPNMON-R2 in $AltNum/30...${CClear} [${CGreen}s${CClear}=Setup] [${CGreen}e${CClear}=Exit] [Selection? ${InvGreen} ${CClear}${CGreen}]\r${CClear}" "$barchars" "$barspaces"
fi
fi
# Borrowed this wonderful keypress capturing mechanism from @Eibgrad... thank you! :)
key_press=''; read -rsn1 -t 1 key_press < "$(tty 0>&2)"
if [ $key_press ]; then
case $key_press in
[Ss]) vsetup;;
[Ee]) timer=30;;
esac
fi
}
# -------------------------------------------------------------------------------------------------------------------------
# bossmode is a function that immediately switches your screen to a word processing screen in case your boss comes around
# the corner, so it looks like you're actually doing work instead of staring at the VPNMON-R2 UI. ;) Please note: VPNMON-R2
# is in a paused state when you enter Boss-Mode until you exit with an 'e'
bossmode() {
clear
echo -e "${InvCyan} ${CRed}WordStar ${CBlack}C:\ASUS\MERLINFW.WS [1] |${CClear}"
echo -e "${InvGreen} ${CBlack}<B><K>249 Insert P1 L4 V10.00\" C13 H1.25\" +${CClear}"
echo -e "${InvDkGray} ${InvCyan}${CBlack}MS Body Copy ${InvDkGray} ${InvCyan}COURIER PC 12 ${InvDkGray} ${InvCyan} B ${InvDkGray} ${InvCyan} I ${InvDkGray} ${InvCyan} U ${InvDkGray} ${InvCyan}<*>${InvDkGray} ${InvWhite} L ${InvDkGray} ${InvCyan} C ${InvDkGray} ${InvCyan} R ${InvDkGray} ${InvCyan} J ${InvDkGray} ${InvCyan}|1${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CWhite} |${CClear}"
echo -e "${InvBlack}${CWhite} A S U S W R T - M E R L I N P R O J E C T ${InvLtGray} ${CClear}"
echo -e "${InvBlack}${CCyan} by${CWhite} Eric Sauvageau ${CCyan} aka ${CWhite} RMerlin ${InvDkGray} ${CClear}"
echo -e "${InvBlack} ${InvDkGray} ${CClear}"
echo -e "${InvBlack} ${CCyan}\"A brief stroll through the history of the project...\" ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CWhite} |${CClear}"
echo -e "${InvBlack}${CWhite}==============================================================================W ${CClear}"
echo -e "${InvBlack}${CCyan} ***About*** ${CWhite}|${CClear}"
echo -e "${InvBlack}${CCyan} Asuswrt-Merlin is an alternative, customized version of that firmware. ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan}Developed by Eric Sauvageau, its primary goals are to enhance the existing ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan}firmware without bringing any radical changes, and to fix some of the known ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan}issues and limitations, while maintaining the same level of performance as the ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan}original firmware. This means Asuswrt-Merlin retains full support for NAT ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan}acceleration (sometimes referred to as \"hardware acceleration\"), enhanced ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan}NTFS performance (through the proprietary #drivers used by Asus from either ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan}Paragon or Tuxera), and the Asus exclusive features such as AiCloud or the ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan}Trend Micro-powered AiProtection. New feature addition is very low on the ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan}list of priorities for for this project. ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan} ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan} ***AddOns*** ${InvDkGray} ${CClear}"
echo -e "${InvGreen}${CBlack}Asuswrt-Merlin has a rich ecosystem that consists of third party developed add-${InvDkGray} ${CClear}"
echo -e "${InvGreen}${CBlack}ons, which can enhance the router with features like ad blocking or connection ${InvDkGray} ${CClear}"
echo -e "${InvGreen}${CBlack}monitoring.${InvBlack}${CCyan} You find more info in the AddOns support forum at SNBForums. ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan} ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan} ***Features*** ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan}With a few rare exceptions, Asuswrt-Merlin retains the features from the ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan}original stock Asus firmware. In addition, the following features have been ${InvDkGray} ${CClear}"
echo -e "${InvBlack}${CCyan}added or enhanced: ${CWhite}|${CClear}"
while true; do
key_press=''; read -rsn1 -t 1 key_press < "$(tty 0>&2)"
if [ $key_press ]; then
case $key_press in
[Ee]) echo -e "${InvBlack}${CCyan} [The boss is gone! Stealthily returning to VPNMON-R2...]"; echo -e "${CClear}"; exit 0;;
esac
fi
done
}
# -------------------------------------------------------------------------------------------------------------------------
# Trimlogs is a function that does exactly what you think it does - it, uh... trims the logs. LOL
trimlogs() {
if [ "$TRIMLOGS" == "1" ]
then
CURRLOGSIZE=$(wc -l $LOGFILE | awk '{ print $1 }' ) # Determine the number of rows in the log
if [ $CURRLOGSIZE -gt $MAXLOGSIZE ] # If it's bigger than the max allowed, tail/trim it!
then
echo "$(tail -$MAXLOGSIZE $LOGFILE)" > $LOGFILE
echo -e "$(date) - VPNMON-R2 - Trimmed the log file down to $MAXLOGSIZE lines" >> $LOGFILE
fi
fi
}
# -------------------------------------------------------------------------------------------------------------------------
# FnLastSlotUsed is a function that determines lastslot used for roundrobin and appstatus.txt reporting
FnLastSlotUsed() {
LastSlotUsed=$(cat $APPSTATUS | sed -n '2p') 2>&1
if [ -z $LastSlotUsed ]; then LastSlotUsed=$N; fi
if [ $N == "1" ]; then
NextSlotUsed=1
fi
if [ $N == "2" ]; then
if [ "$LastSlotUsed" == "1" ]; then
NextSlotUsed=2
elif [ "$LastSlotUsed" == "2" ]; then
NextSlotUsed=1
fi
fi
if [ $N == "3" ]; then
if [ "$LastSlotUsed" == "1" ]; then
NextSlotUsed=2
elif [ "$LastSlotUsed" == "2" ]; then
NextSlotUsed=3
elif [ "$LastSlotUsed" == "3" ]; then
NextSlotUsed=1
fi
fi
if [ $N == "4" ]; then
if [ "$LastSlotUsed" == "1" ]; then
NextSlotUsed=2
elif [ "$LastSlotUsed" == "2" ]; then
NextSlotUsed=3
elif [ "$LastSlotUsed" == "3" ]; then
NextSlotUsed=4
elif [ "$LastSlotUsed" == "4" ]; then
NextSlotUsed=1
fi
fi
if [ $N == "5" ]; then
if [ "$LastSlotUsed" == "1" ]; then
NextSlotUsed=2
elif [ "$LastSlotUsed" == "2" ]; then
NextSlotUsed=3
elif [ "$LastSlotUsed" == "3" ]; then
NextSlotUsed=4
elif [ "$LastSlotUsed" == "4" ]; then
NextSlotUsed=5
elif [ "$LastSlotUsed" == "5" ]; then
NextSlotUsed=1
fi
fi
}
# -------------------------------------------------------------------------------------------------------------------------
# This function was "borrowed" graciously from @dave14305 from his FlexQoS script to determine the active WAN connection.
# Thanks much for your troubleshooting help as we tackled how to best derive the active WAN interface, Dave!
get_wan_setting() {
local varname varval
varname="${1}"
prefixes="wan0_ wan1_"
if [ "$($timeoutcmd$timeoutsec nvram get wans_mode)" = "lb" ] ; then
for prefix in $prefixes; do
state="$($timeoutcmd$timeoutsec nvram get "${prefix}"state_t)"
sbstate="$($timeoutcmd$timeoutsec nvram get "${prefix}"sbstate_t)"
auxstate="$($timeoutcmd$timeoutsec nvram get "${prefix}"auxstate_t)"
# is_wan_connect()
[ "${state}" = "2" ] || continue
[ "${sbstate}" = "0" ] || continue
[ "${auxstate}" = "0" ] || [ "${auxstate}" = "2" ] || continue
# get_wan_ifname()
proto="$($timeoutcmd$timeoutsec nvram get "${prefix}"proto)"
if [ "${proto}" = "pppoe" ] || [ "${proto}" = "pptp" ] || [ "${proto}" = "l2tp" ] ; then
varval="$($timeoutcmd$timeoutsec nvram get "${prefix}"pppoe_"${varname}")"
else
varval="$($timeoutcmd$timeoutsec nvram get "${prefix}""${varname}")"
fi
done
else
for prefix in $prefixes; do
primary="$($timeoutcmd$timeoutsec nvram get "${prefix}"primary)"
[ "${primary}" = "1" ] && break
done
proto="$($timeoutcmd$timeoutsec nvram get "${prefix}"proto)"
if [ "${proto}" = "pppoe" ] || [ "${proto}" = "pptp" ] || [ "${proto}" = "l2tp" ] ; then
varval="$($timeoutcmd$timeoutsec nvram get "${prefix}"pppoe_"${varname}")"
else
varval="$($timeoutcmd$timeoutsec nvram get "${prefix}""${varname}")"
fi
fi
printf "%s" "${varval}"
} # get_wan_setting
# Separated these out to get the ifname for a dual-wan/failover situation where both WAN connections are on
get_wan_setting0() {
local varname varval
varname="${1}"
prefixes="wan0_"
if [ "$($timeoutcmd$timeoutsec nvram get wans_mode)" = "lb" ] ; then
for prefix in $prefixes; do
state="$($timeoutcmd$timeoutsec nvram get "${prefix}"state_t)"
sbstate="$($timeoutcmd$timeoutsec nvram get "${prefix}"sbstate_t)"
auxstate="$($timeoutcmd$timeoutsec nvram get "${prefix}"auxstate_t)"
# is_wan_connect()
[ "${state}" = "2" ] || continue
[ "${sbstate}" = "0" ] || continue
[ "${auxstate}" = "0" ] || [ "${auxstate}" = "2" ] || continue
# get_wan_ifname()
proto="$($timeoutcmd$timeoutsec nvram get "${prefix}"proto)"
if [ "${proto}" = "pppoe" ] || [ "${proto}" = "pptp" ] || [ "${proto}" = "l2tp" ] ; then
varval="$($timeoutcmd$timeoutsec nvram get "${prefix}"pppoe_"${varname}")"
else
varval="$($timeoutcmd$timeoutsec nvram get "${prefix}""${varname}")"
fi
done
else
for prefix in $prefixes; do
primary="$($timeoutcmd$timeoutsec nvram get "${prefix}"primary)"
[ "${primary}" = "1" ] && break
done
proto="$($timeoutcmd$timeoutsec nvram get "${prefix}"proto)"
if [ "${proto}" = "pppoe" ] || [ "${proto}" = "pptp" ] || [ "${proto}" = "l2tp" ] ; then
varval="$($timeoutcmd$timeoutsec nvram get "${prefix}"pppoe_"${varname}")"
else
varval="$($timeoutcmd$timeoutsec nvram get "${prefix}""${varname}")"
fi
fi
printf "%s" "${varval}"
} # get_wan_setting
# Separated these out to get the ifname for a dual-wan/failover situation where both WAN connections are on
get_wan_setting1() {
local varname varval
varname="${1}"
prefixes="wan1_"
if [ "$($timeoutcmd$timeoutsec nvram get wans_mode)" = "lb" ] ; then
for prefix in $prefixes; do
state="$($timeoutcmd$timeoutsec nvram get "${prefix}"state_t)"
sbstate="$($timeoutcmd$timeoutsec nvram get "${prefix}"sbstate_t)"
auxstate="$($timeoutcmd$timeoutsec nvram get "${prefix}"auxstate_t)"
# is_wan_connect()
[ "${state}" = "2" ] || continue
[ "${sbstate}" = "0" ] || continue
[ "${auxstate}" = "0" ] || [ "${auxstate}" = "2" ] || continue
# get_wan_ifname()
proto="$($timeoutcmd$timeoutsec nvram get "${prefix}"proto)"
if [ "${proto}" = "pppoe" ] || [ "${proto}" = "pptp" ] || [ "${proto}" = "l2tp" ] ; then
varval="$($timeoutcmd$timeoutsec nvram get "${prefix}"pppoe_"${varname}")"
else
varval="$($timeoutcmd$timeoutsec nvram get "${prefix}""${varname}")"
fi
done
else
for prefix in $prefixes; do
primary="$($timeoutcmd$timeoutsec nvram get "${prefix}"primary)"
[ "${primary}" = "1" ] && break
done
proto="$($timeoutcmd$timeoutsec nvram get "${prefix}"proto)"
if [ "${proto}" = "pppoe" ] || [ "${proto}" = "pptp" ] || [ "${proto}" = "l2tp" ] ; then
varval="$($timeoutcmd$timeoutsec nvram get "${prefix}"pppoe_"${varname}")"
else
varval="$($timeoutcmd$timeoutsec nvram get "${prefix}""${varname}")"
fi
fi
printf "%s" "${varval}"
} # get_wan_setting
# -------------------------------------------------------------------------------------------------------------------------
# Updatecheck is a function that downloads the latest update version file, and compares it with what's currently installed
updatecheck () {
# Download the latest version file from the source repository
curl --silent --retry 3 --connect-timeout 3 --max-time 6 --retry-delay 1 --retry-all-errors "https://raw.githubusercontent.com/ViktorJp/VPNMON-R2/master/version.txt" -o "/jffs/addons/vpnmon-r2.d/version.txt"
if [ -f $DLVERPATH ]
then
# Read in its contents for the current version file
DLVersion=$(cat $DLVERPATH)
# Compare the new version with the old version and log it
if [ "$Beta" == "1" ]; then # Check if Dev/Beta Mode is enabled and disable notification message
UpdateNotify=0
elif [ "$DLVersion" != "$Version" ]; then
UpdateNotify="Update available: v$Version -> v$DLVersion | VPNMON-R3 - Upgrade now!"
echo -e "$(date) - VPNMON-R2 - A new update (v$DLVersion) is available to download" >> $LOGFILE
else
UpdateNotify="VPNMON-R3 available - Upgrade now!"
fi
fi
}
# -------------------------------------------------------------------------------------------------------------------------
# Checkwan is a function that checks the viability of the current WAN connection and will loop until the WAN connection is restored.
checkwan () {
# Using Google's 8.8.8.8 server to test for WAN connectivity over verified SSL Handshake
wandownbreakertrip=0
WAN_ELAPSED_TIME=0
testssl=8.8.8.8
# Show that we're testing the WAN connection
if [ "$1" == "Loop" ]
then
printf "\r${InvYellow} ${CClear}${CYellow} [Checking WAN Connectivity]..."
elif [ "$1" = "Reset" ]
then
printf "${CYellow}\r [Checking WAN Connectivity]..."
fi
#Run main checkwan loop
while true; do
# Start a timer to see how long this takes to add to the TX/RX Calculations
WAN_START_TIME=$(date +%s)
#DUALWANMODE=$($timeoutcmd$timeoutsec nvram get wans_mode)
# Check the actual WAN State from NVRAM before running connectivity test, or insert itself into loop after failing an SSL handshake test
if [ "$($timeoutcmd$timeoutsec nvram get wan0_state_t)" -eq 2 ] || [ "$($timeoutcmd$timeoutsec nvram get wan1_state_t)" -eq 2 ]
then
# Test the active WAN connection using 443 and verifying a handshake... if this fails, then the WAN connection is most likely down... or Google is down ;)
if ($timeoutcmd$timeoutlng nc -w3 $testssl 443 >/dev/null 2>&1 && echo | $timeoutcmd$timeoutlng openssl s_client -connect $testssl:443 >/dev/null 2>&1 |awk 'handshake && $1 == "Verification" { if ($2=="OK") exit; exit 1 } $1 $2 == "SSLhandshake" { handshake = 1 }') >/dev/null 2>&1
then
if [ "$1" == "Loop" ]
then
printf "\r${InvGreen} ${CClear}${CGreen} [Checking WAN Connectivity]...ACTIVE"
sleep 1
printf "\33[2K\r"
elif [ "$1" = "Reset" ]
then
printf "${CGreen}\r [Checking WAN Connectivity]...ACTIVE"
sleep 1
echo -e "\n"
fi
WAN_END_TIME=$(date +%s)
WAN_ELAPSED_TIME=$(( WAN_END_TIME - WAN_START_TIME ))
return
else
wandownbreakertrip=1
echo -e "$(date) - VPNMON-R2 ----------> ERROR: WAN CONNECTIVITY ISSUE DETECTED" >> $LOGFILE
fi
else
wandownbreakertrip=1
echo -e "$(date) - VPNMON-R2 ----------> ERROR: WAN CONNECTIVITY ISSUE DETECTED" >> $LOGFILE
fi
if [ "$wandownbreakertrip" == "1" ]
then
# The WAN is most likely down, and keep looping through until NVRAM reports that it's back up
while [ "$wandownbreakertrip" == "1" ]; do
if [ "$RESETSWITCH" == "1" ] || [ -f "$LOCKFILE" ]
then
echo ""
echo ""
echo -e "${CRed} ERROR: WAN DOWN... VPN Reset is terminating."
echo -e "$(date) - VPNMON-R2 ----------> ERROR: WAN CONNECTIVITY ISSUE DETECTED. VPN RESET TERMINATED." >> $LOGFILE
RESETSWITCH=0
rm $LOCKFILE >/dev/null 2>&1
sleep 2
clear
fi
# Preemptively kill all the VPN Clients incase they're trying to reconnect on their own
i=0
while [ $i -ne $N ]
do
i=$(($i+1))
service stop_vpnclient$i >/dev/null 2>&1
done
# Continue to test for WAN connectivity while in this loop. If it comes back up, break out of the loop and reset VPN
if [ "$($timeoutcmd$timeoutsec nvram get wan0_state_t)" -ne 2 ] && [ "$($timeoutcmd$timeoutsec nvram get wan1_state_t)" -ne 2 ]
then
# Continue to loop and retest the WAN every 15 seconds
SPIN=15
echo -e "$(date) - VPNMON-R2 ----------> ERROR: WAN DOWN" >> $LOGFILE
clear
logo
echo -e "${CRed} ---------------------> ERROR: WAN DOWN <---------------------"
echo ""
echo -e "${CRed} VPNMON-R2 is unable to detect a stable WAN connection. Please"
echo -e "${CRed} check with your ISP, or reset your modem to re-establish a"
echo -e "${CRed} stable connection.${CClear}\n"
spinner
wandownbreakertrip=1
else
wandownbreakertrip=2
break
fi
done
fi
# If the WAN was down, and now it has just reset, then run a VPN Reset, and try to establish a new VPN connection
if [ "$wandownbreakertrip" == "2" ]
then
echo -e "$(date) - VPNMON-R2 - WAN Link Detected -- Trying to reconnect/Reset VPN" >> $LOGFILE
wandownbreakertrip=0
vpnresettripped=1
clear
logo
echo -e "${CRed} ---------------------> ERROR: WAN DOWN <---------------------"
echo ""
echo -e "${CGreen} WAN Link/Modem Detected... waiting 300 seconds to reconnect"
echo -e "${CGreen} and for general connectivity to stabilize."
echo ""
SPIN=300
spinner
echo ""
echo -e "$(date +%s)" > $RSTFILE
START=$(cat $RSTFILE)
echo ""
vpnreset
fi
done
}
# -------------------------------------------------------------------------------------------------------------------------
# resetcheck tests for 5 major reset scenarios:
# (1) Lost connection,
# (2) Multiple connections,
# (3) High VPN Server Load,
# (4) High Ping,
# (5) VPN Client identified with a lower ping than the current connection
# (6) Force reset through the UI
# (7) External reset using a user-defined file available on the internet
# (8) Unbound public DNS Resolver IP goes out of sync with the public VPN IP
# ...and reset the VPN connection
# -------------------------------------------------------------------------------------------------------------------------
resetcheck () {
# If STATUS remains 0 then we've lost our connection, reset the VPN
if [ $STATUS -eq 0 ]; then
clear
logo
echo -e "\n${CRed} VPN$CURRCLNT Connection has failed. Executing VPN Reset${CClear}\n"
echo -e "$(date) - VPNMON-R2 ----------> ERROR: VPN$CURRCLNT Connection failed - Executing VPN Reset" >> $LOGFILE
vpnreset
SKIPPROGRESS=1
echo -e "$(date) - VPNMON-R2 - Resuming normal operations" >> $LOGFILE
echo -e "$(date +%s)" > $RSTFILE
START=$(cat $RSTFILE)
PINGLOW=0 # Reset ping time history variables
PINGHIGH=0
ICANHAZIP=""
ResolverTimer=1
oldrxbytes=0 # Reset Stats
oldtxbytes=0
newrxbytes=0
newtxbytes=0
return
fi
# If VPNCLCNT is greater than 1 there are multiple connections running, reset the VPN
if [ $VPNCLCNT -gt 1 ]; then
clear
logo
echo -e "\n${CRed} Multiple VPN Client Connections detected. Executing VPN Reset${CClear}\n"
echo -e "$(date) - VPNMON-R2 ----------> ERROR: Multiple VPN Client Connections detected - Executing VPN Reset" >> $LOGFILE
vpnreset
SKIPPROGRESS=1
echo -e "$(date) - VPNMON-R2 - Resuming normal operations" >> $LOGFILE
echo -e "$(date +%s)" > $RSTFILE
START=$(cat $RSTFILE)
PINGLOW=0 # Reset ping time history variables
PINGHIGH=0
ICANHAZIP=""
ResolverTimer=1
oldrxbytes=0 # Reset Stats
oldtxbytes=0
newrxbytes=0
newtxbytes=0
return
fi
# If the NordVPN/SurfShark/PP Server load is greater than the set variable, reset the VPN and hopefully find a better server
if [ $NordVPNLoadReset -le $VPNLOAD ] || [ $SurfSharkLoadReset -le $VPNLOAD ] || [ $PPLoadReset -le $VPNLOAD ]; then
clear
logo
if [ $UseNordVPN -eq 1 ];then
echo -e "\n${CRed} NordVPN Server Load is higher than $NordVPNLoadReset %. Executing VPN Reset."
echo -e " VPNMON-R2 is executing VPN Reset${CClear}\n"
echo -e "$(date) - VPNMON-R2 ----------> WARNING: NordVPN Server Load > $NordVPNLoadReset% - Executing VPN Reset" >> $LOGFILE
fi
if [ $UseSurfShark -eq 1 ];then
echo -e "\n${CRed} SurfShark Server Load is higher than $SurfSharkLoadReset %. Executing VPN Reset."
echo -e " VPNMON-R2 is executing VPN Reset${CClear}\n"
echo -e "$(date) - VPNMON-R2 ----------> WARNING: SurfShark Server Load > $SurfSharkLoadReset% - Executing VPN Reset" >> $LOGFILE
fi
if [ $UsePP -eq 1 ];then
echo -e "\n${CRed} Perfect Privacy Server Load is higher than $PPLoadReset %. Executing VPN Reset."
echo -e " VPNMON-R2 is executing VPN Reset${CClear}\n"
echo -e "$(date) - VPNMON-R2 ----------> WARNING: Perfect Privacy Server Load > $PPLoadReset% - Executing VPN Reset" >> $LOGFILE
fi
if [ $UseAirVPN -eq 1 ];then
echo -e "\n${CRed} AirVPN Server Load is higher than $AirVPNLoadReset %. Executing VPN Reset."
echo -e " VPNMON-R2 is executing VPN Reset${CClear}\n"
echo -e "$(date) - VPNMON-R2 ----------> WARNING: AirVPN Server Load > $AirVPNLoadReset% - Executing VPN Reset" >> $LOGFILE
fi
vpnreset
SKIPPROGRESS=1
echo -e "$(date) - VPNMON-R2 - Resuming normal operations" >> $LOGFILE
echo -e "$(date +%s)" > $RSTFILE
START=$(cat $RSTFILE)
PINGLOW=0 # Reset ping time history variables
PINGHIGH=0
ICANHAZIP=""
ResolverTimer=1
oldrxbytes=0 # Reset Stats
oldtxbytes=0
newrxbytes=0
newtxbytes=0
return
fi
# If the AVGPING average ping across the tunnel is greater than the set variable, reset the VPN and hopefully land on a server with lesser ping times
if [ "${AVGPING%.*}" -gt "$MINPING" ] && [ "$IGNOREHIGHPING" == "0" ]; then
clear
logo
echo -e "\n${CRed} Average PING $AVGPING ms across VPN tunnel $CURRCLNT is > $MINPING ms. Executing VPN Reset${CClear}\n"
echo -e "$(date) - VPNMON-R2 ----------> WARNING: Average PING of $AVGPING ms across VPN tunnel $CURRCLNT > $MINPING ms - Executing VPN Reset" >> $LOGFILE
vpnreset
SKIPPROGRESS=1
echo -e "$(date) - VPNMON-R2 - Resuming normal operations" >> $LOGFILE
echo -e "$(date +%s)" > $RSTFILE
START=$(cat $RSTFILE)
PINGLOW=0 # Reset ping time history variables
PINGHIGH=0
ICANHAZIP=""
ResolverTimer=1
oldrxbytes=0 # Reset Stats
oldtxbytes=0
newrxbytes=0
newtxbytes=0
return
else
IGNOREHIGHPING=0
fi
# If a different VPN slot has a lower ping than the current connection, then don't randomize and reset it to that VPN slot with lowest ping value
if [ "$USELOWESTSLOT" == "1" ]; then
if [ "$LOWEST" != "$CURRCLNT" ]; then
LOWPINGCOUNT=$(($LOWPINGCOUNT+1))
if [ $LOWPINGCOUNT -le $PINGCHANCES ]; then
echo -e "${InvRed} ${CClear}${CRed} WARNING:${CYellow} Switching to faster ${InvDkGray}${CWhite}VPN$LOWEST Client${CClear}${CYellow} after $(($PINGCHANCES-$LOWPINGCOUNT)) more chances"
else
clear
logo
echo -e "\n${CRed} Switching to faster VPN$LOWEST Client with PING $LOWESTPING ms. Executing VPN Reset${CClear}\n"
echo -e "$(date) - VPNMON-R2 ----------> WARNING: Switching to faster VPN$LOWEST Client with PING $LOWESTPING ms- Executing VPN Reset" >> $LOGFILE
vpnresetlowestping
SKIPPROGRESS=1
LOWPINGCOUNT=0
echo -e "$(date) - VPNMON-R2 - Resuming normal operations" >> $LOGFILE
echo -e "$(date +%s)" > $RSTFILE
START=$(cat $RSTFILE)
PINGLOW=0 # Reset ping time history variables
PINGHIGH=0
ICANHAZIP=""
ResolverTimer=1
oldrxbytes=0 # Reset Stats
oldtxbytes=0
newrxbytes=0
newtxbytes=0
return
fi
else
LOWPINGCOUNT=0
fi
fi
# If a force reset command has been received by the UI, then go through a regular reset
if [ "$FORCEDRESET" == "1" ]; then
clear
logo
echo -e "\n${CRed} Forced reset captured through UI, VPNMON-R2 is executing VPN Reset${CClear}\n"
echo -e "$(date) - VPNMON-R2 ----------> INFO: Forced reset captured through UI - Executing VPN Reset" >> $LOGFILE
vpnreset
SKIPPROGRESS=1
FORCEDRESET=0
echo -e "$(date) - VPNMON-R2 - Resuming normal operations" >> $LOGFILE
echo -e "$(date +%s)" > $RSTFILE
START=$(cat $RSTFILE)
PINGLOW=0 # Reset ping time history variables
PINGHIGH=0
ICANHAZIP=""
ResolverTimer=1
oldrxbytes=0 # Reset Stats
oldtxbytes=0
newrxbytes=0
newtxbytes=0
return
fi
# If an externet file on the internet indicates RESET or REBOOT, then proceed with a regular reset/reboot
if [ "$EXTERNALRESET" == "1" ]; then
EXT_END_TIME=$(date +%s)
EXT_ELAPSED_TIME=$(( EXT_END_TIME - EXT_START_TIME ))
if [ $EXT_ELAPSED_TIME -ge $EXTINTERVAL ]; then
EXT_EVENT=$(curl --silent --retry 3 --connect-timeout 3 --max-time 6 --retry-delay 1 --retry-all-errors $EXT_SOURCE | sed -n '1p') 2>&1
if [ "$EXT_EVENT" == "RESET" ]; then
clear
logo
echo -e "\n${CRed} Forced reset through external file, VPNMON-R2 is executing VPN Reset${CClear}\n"
echo -e "$(date) - VPNMON-R2 ----------> INFO: Forced reset through external file - Executing VPN Reset" >> $LOGFILE
SPIN=15
echo -e "${CGreen} [Reset commencing in $SPIN seconds]...${CClear}\n"
spinner
vpnreset
SKIPPROGRESS=1
FORCEDRESET=0
echo -e "$(date) - VPNMON-R2 - Resuming normal operations" >> $LOGFILE
echo -e "$(date +%s)" > $RSTFILE
START=$(cat $RSTFILE)
PINGLOW=0 # Reset ping time history variables
PINGHIGH=0
ICANHAZIP=""
ResolverTimer=1
oldrxbytes=0 # Reset Stats
oldtxbytes=0
newrxbytes=0
newtxbytes=0
#Track External Reset Timer
EXT_ELAPSED_TIME=0
EXT_START_TIME=$(date +%s)
return
elif [ "$EXT_EVENT" == "REBOOT" ]; then
clear