-
Notifications
You must be signed in to change notification settings - Fork 1
/
vpnmon-r3-1.3.7.sh
4335 lines (3928 loc) · 189 KB
/
vpnmon-r3-1.3.7.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-R3 v1.3.7 (VPNMON-R3.SH) is an all-in-one script that is optimized to maintain multiple VPN connections and is
# able to provide for the capabilities to randomly reconnect using a specified server list containing the servers of your
# choice. Special care has been taken to ensure that only the VPN connections you want to have monitored are tended to.
# This script will check the health of up to 5 VPN connections on a regular interval to see if monitored VPN conenctions
# are connected, and sends a ping to a host of your choice through each active connection. If it finds that a connection
# has been lost, it will execute a series of commands that will kill that single VPN client, and randomly picks one of
# your specified servers to reconnect to for each VPN client.
# Last Modified: 2024-Oct-18
#Preferred standard router binaries path
export PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH"
#Static Variables - please do not change
version="1.3.7" # Version tracker
beta=0 # Beta switch
screenshotmode=0 # Switch to present bogus info for screenshots
apppath="/jffs/scripts/vpnmon-r3.sh" # Static path to the app
logfile="/jffs/addons/vpnmon-r3.d/vpnmon-r3.log" # Static path to the log
dlverpath="/jffs/addons/vpnmon-r3.d/version.txt" # Static path to the version file
config="/jffs/addons/vpnmon-r3.d/vpnmon-r3.cfg" # Static path to the config file
lockfile="/jffs/addons/vpnmon-r3.d/resetlock.txt" # Static path to the reset lock file
availableslots="1 2 3 4 5" # Available slots tracker
logsize=2000 # Log file size in rows
timerloop=60 # Timer loop in sec
schedule=0 # Scheduler enable y/n
schedulehrs=1 # Scheduler hours
schedulemin=0 # Scheduler mins
autostart=0 # Auto start on router reboot y/n
unboundclient=0 # Unbound bound to VPN client slot#
ResolverTimer=1 # Timer to give DNS resolver time to settle
vpnping=0 # Tracking VPN Tunnel Pings
refreshserverlists=0 # Tracking Automated Custom VPN Server List Reset
monitorwan=0 # Tracking WAN/Dual WAN Monitoring
lockactive=0 # Check for active locks
bypassscreentimer=0 # Check to see if screen timer can be bypassed
pingreset=500 # Maximum ping in ms before reset
updateskynet=0 # Check for VPN IP whitelisting in Skynet
amtmemailsuccess=0 # AMTM Email Success Message Option
amtmemailfailure=0 # AMTM Email Failure Message Option
timeoutcmd="" # For "timeout" cmd for "nvram" calls
timeoutsec="" # For "timeout" cmd for "nvram" calls
timeoutlng="" # For "timeout" cmd for "nvram" calls
hideoptions=1 # Hide/Show menu options flag
##-------------------------------------##
## Added by Martinski W. [2024-Oct-05] ##
##-------------------------------------##
readonly PING_HOST_Deflt="8.8.8.8"
readonly IPv4octet_RegEx="([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"
readonly IPv4addrs_RegEx="(${IPv4octet_RegEx}\.){3}${IPv4octet_RegEx}"
LAN_HostName=""
PINGHOST="$PING_HOST_Deflt" # Ping host
## Custom Email Library Notification Variables ##
readonly scriptFileName="${0##*/}"
readonly scriptFileNTag="${scriptFileName%.*}"
readonly CEM_LIB_TAG="master"
readonly CEM_LIB_URL="https://raw.githubusercontent.com/Martinski4GitHub/CustomMiscUtils/${CEM_LIB_TAG}/EMail"
readonly CUSTOM_EMAIL_LIBDir="/jffs/addons/shared-libs"
readonly CUSTOM_EMAIL_LIBName="CustomEMailFunctions.lib.sh"
readonly CUSTOM_EMAIL_LIBFile="${CUSTOM_EMAIL_LIBDir}/$CUSTOM_EMAIL_LIBName"
# 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"
# -------------------------------------------------------------------------------------------------------------------------
# blackwhite is a simple function that removes all color attributes
blackwhite()
{
CBlack=""
InvBlack=""
CRed=""
InvRed=""
CGreen=""
InvGreen=""
CDkGray=""
InvDkGray=""
InvLtGray=""
CYellow=""
InvYellow=""
CBlue=""
InvBlue=""
CMagenta=""
CCyan=""
InvCyan=""
CWhite=""
InvWhite=""
CClear=""
}
# -------------------------------------------------------------------------------------------------------------------------
# LogoNM is a function that displays the VPNMON-R3 script name in a cool ASCII font without menu options
logoNM () {
clear
echo ""
echo ""
echo ""
echo -e "${CDkGray} _ ______ _ ____ _______ _ __ ____ _____"
echo -e " | | / / __ \/ | / / |/ / __ \/ | / / / __ \__ /"
echo -e " | | / / /_/ / |/ / /|_/ / / / / |/ /_____/ /_/ //_ < "
echo -e " | |/ / ____/ /| / / / / /_/ / /| /_____/ _, _/__/ / "
echo -e " |___/_/ /_/ |_/_/ /_/\____/_/ |_/ /_/ |_/____/ v$version"
echo ""
echo ""
printf "\r ${CGreen} [ INITIALIZING ] ${CClear}"
sleep 2
clear
echo ""
echo ""
echo ""
echo -e "${CYellow} _ ______ _ ____ _______ _ __ ____ _____"
echo -e " | | / / __ \/ | / / |/ / __ \/ | / / / __ \__ /"
echo -e " | | / / /_/ / |/ / /|_/ / / / / |/ /_____/ /_/ //_ < "
echo -e " | |/ / ____/ /| / / / / /_/ / /| /_____/ _, _/__/ / "
echo -e " |___/_/ /_/ |_/_/ /_/\____/_/ |_/ /_/ |_/____/ v$version"
echo ""
echo ""
printf "\r ${CGreen}[ INITIALIZING ... DONE ]${CClear}"
sleep 1
printf "\r ${CGreen} [ LOADING... ] ${CClear}"
sleep 2
}
logoNMexit () {
clear
echo ""
echo ""
echo ""
echo -e "${CYellow} _ ______ _ ____ _______ _ __ ____ _____"
echo -e " | | / / __ \/ | / / |/ / __ \/ | / / / __ \__ /"
echo -e " | | / / /_/ / |/ / /|_/ / / / / |/ /_____/ /_/ //_ < "
echo -e " | |/ / ____/ /| / / / / /_/ / /| /_____/ _, _/__/ / "
echo -e " |___/_/ /_/ |_/_/ /_/\____/_/ |_/ /_/ |_/____/ v$version"
echo ""
echo ""
printf "\r ${CGreen} [ SHUTTING DOWN ] ${CClear}"
sleep 2
clear
echo ""
echo ""
echo ""
echo -e "${CDkGray} _ ______ _ ____ _______ _ __ ____ _____"
echo -e " | | / / __ \/ | / / |/ / __ \/ | / / / __ \__ /"
echo -e " | | / / /_/ / |/ / /|_/ / / / / |/ /_____/ /_/ //_ < "
echo -e " | |/ / ____/ /| / / / / /_/ / /| /_____/ _, _/__/ / "
echo -e " |___/_/ /_/ |_/_/ /_/\____/_/ |_/ /_/ |_/____/ v$version"
echo ""
echo ""
printf "\r ${CGreen} [ SHUTTING DOWN ] ${CClear}"
sleep 1
printf "\r ${CDkGray} [ GOODBYE... ] ${CClear}\n\n"
sleep 2
}
# -------------------------------------------------------------------------------------------------------------------------
# Promptyn is a simple function that accepts y/n input
promptyn () { # No defaults, just y or n
while true; do
read -p '[y/n]? ' YESNO
case "$YESNO" in
[Yy]* ) return 0 ;;
[Nn]* ) return 1 ;;
* ) echo -e "\nPlease answer y or n.";;
esac
done
}
# -------------------------------------------------------------------------------------------------------------------------
# Spinner is a script that provides a small indicator on the screen to show script activity
spinner()
{
spins=$1
spin=0
totalspins=$((spins / 4))
while [ $spin -le $totalspins ]; do
for spinchar in / - \\ \|; do
printf "\r$spinchar"
sleep 1
done
spin=$((spin+1))
done
printf "\r"
}
# -------------------------------------------------------------------------------------------------------------------------
# Preparebar and Progressbar is a script that provides a nice progressbar to show script activity
preparebar()
{
barlen="$1"
barspaces="$(printf "%*s" "$1")"
barchars="$(printf "%*s" "$1" | tr ' ' "$2")"
}
##----------------------------------------##
## Modified by Martinski W. [2024-Oct-17] ##
##----------------------------------------##
progressbaroverride()
{
insertspc=" "
bypasswancheck=0
_GetPercent_() { printf "%.1f" "$(echo "$1" | awk "{print $1}")" ; }
if [ "$1" -eq -1 ]
then
printf "\r $barspaces\r"
else
if [ $# -gt 6 ] && [ -n "$7" ] && [ "$1" -ge "$7" ]
then
barch="$(($7*barlen/$2))"
barsp="$((barlen-barch))"
percnt="$(_GetPercent_ "(100*$1/$2)")"
else
barch="$(($1*barlen/$2))"
barsp="$((barlen-barch))"
percnt="$(_GetPercent_ "(100*$1/$2)")"
fi
if [ $# -gt 5 ] && [ -n "$6" ]; then AltNum="$6" ; else AltNum="$1" ; fi
if [ "$5" = "Standard" ]
then
printf " ${CWhite}${InvDkGray}%3d${4} /%5.1f%%${CClear} [${CGreen}e${CClear}=Exit] [Selection? ${InvGreen} ${CClear}${CGreen}]\r${CClear}" "$AltNum" "$percnt"
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
[1]) echo ""; restartvpn 1; restartrouting; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[2]) echo ""; restartvpn 2; restartrouting; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[3]) echo ""; restartvpn 3; restartrouting; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[4]) echo ""; restartvpn 4; restartrouting; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[5]) echo ""; restartvpn 5; restartrouting; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[\!]) echo ""; killunmonvpn 1; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[\@]) echo ""; killunmonvpn 2; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[\#]) echo ""; killunmonvpn 3; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[\$]) echo ""; killunmonvpn 4; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[\%]) echo ""; killunmonvpn 5; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[Aa]) autostart;;
[Cc]) vsetup;;
[Ee]) logoNMexit; echo -e "${CClear}\n"; exit 0;;
[Hh]) timerreset=1; hideoptions=1;;
[Ii]) amtmevents;;
[Ll]) vlogs;;
[Mm]) vpnslots;;
[Pp]) maxping;;
[Rr]) schedulevpnreset;;
[Ss]) timerreset=1; hideoptions=0;;
[Tt]) timerloopconfig;;
[Uu]) vpnserverlistautomation;;
[Vv]) vpnserverlistmaint;;
[Xx]) uninstallr2;;
*) ;; ##IGNORE INVALID key presses ##
esac
bypasswancheck=1
fi
}
progressbarpause()
{
insertspc=" "
bypasswancheck=0
if [ "$1" -eq -1 ]
then
printf "\r $barspaces\r"
else
if [ $# -gt 6 ] && [ -n "$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 [ $# -gt 5 ] && [ -n "$6" ]; then AltNum="$6" ; else AltNum="$1" ; fi
if [ "$5" = "Standard" ]
then
printf " ${CWhite}${InvDkGray}Continuing Reset in $AltNum/5...${CClear} [${CGreen}p${CClear}=Pause] [${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
[Pp]) vpause;;
[Ee]) logoNMexit; echo -e "${CClear}\n"; exit 0;;
esac
bypasswancheck=1
fi
}
# -------------------------------------------------------------------------------------------------------------------------
# This function optionally uninstalls VPNMON-R2 if still found present on local router
uninstallr2()
{
if [ -f /jffs/scripts/vpnmon-r2.sh ]
then
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} VPNMON-R2 Uninstall Utility ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} This utility allows you to uninstall VPNMON-R2. NOTE: Please know that VPNMON-R2"
echo -e "${InvGreen} ${CClear} development is ceasing, and product support will be sunset in the very near future."
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} VPNMON-R2 was still found installed on your router. This menu gives you the option"
echo -e "${InvGreen} ${CClear} to launch (if needed) or uninstall the old legacy VPNMON-R2. Thank you!"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
printf "${CClear}Please select? (${CGreen}u${CClear}=UNinstall R2, ${CGreen}r${CClear}=Run R2, ${CGreen}e${CClear}=Exit)"
read -p ": " SelectR2
case $SelectR2 in
[Uu])
echo -e "\n${CClear}Please type 'Y' to validate you wish to proceed with the uninstall of VPNMON-R2.${CClear}"
if promptyn "(y/n): "
then
echo -e "\n${CClear}Uninstalling VPNMON-R2 components...${CClear}"
if [ "$(cat /jffs/addons/vpnmon-r2.d/vpnmon-r2.cfg | grep "UpdateUnbound" | cut -d '=' -f 2-)" = "1" ]
then
# Delete all additions made to files to enable Unbound over VPN functionality
echo ""
echo -e "\n${CClear}Unbinding Unbound from VPN..."
# Disable vpn functionality with Unbound
sh /jffs/addons/unbound/unbound_manager.sh vpn=disable >/dev/null 2>&1
# Remove Unbound failsafe in post-mount
if [ -f /jffs/scripts/post-mount ]; then
sed -i -e '/vpn=disable/d' /jffs/scripts/post-mount >/dev/null 2>&1
fi
# Remove Unbound VPN helper script in openvpn-event
if [ -f /jffs/scripts/openvpn-event ]; then
sed -i -e '/unbound_DNS_via_OVPN.sh/d' /jffs/scripts/openvpn-event >/dev/null 2>&1
fi
# Remove RPDB Rules added to nat-start
if [ -f /jffs/scripts/nat-start ]; then
sed -i -e '/Added by vpnmon-r2/d' /jffs/scripts/nat-start >/dev/null 2>&1
fi
# Remove the unbound_DNS_via_OVPN.sh file
if [ -f /jffs/addons/unbound/unbound_DNS_via_OVPN.sh ]; then
rm /jffs/addons/unbound/unbound_DNS_via_OVPN.sh
fi
echo -e "\n${CClear}If Unbound-over-VPN is enabled on VPNMON-R3, you may need to disable/re-enable"
echo -e "this feature under the setup/configuration menu again. Conflicts may have"
echo -e "arisen with both products having this feature enabled."
fi
echo -e "\n${CClear}Removing VPNMON-R2 Files..."
# Remove R2 Files
rm -f -r /jffs/addons/vpnmon-r2.d
rm -f /jffs/scripts/vpnmon-r2.sh
if [ -f /jffs/scripts/post-mount ]; then
sed -i -e '/vpnmon-r2.sh/d' /jffs/scripts/post-mount >/dev/null 2>&1
fi
echo -e "\n${CClear}VPNMON-R2 has been uninstalled...${CClear}"
echo ""
read -rsp $'Press any key to continue...\n' -n1 key
timer="$timerloop"
echo -e "${CClear}\n"
return
else
timer="$timerloop"
echo -e "${CClear}\n"
return
fi
;;
[Rr]) exec sh /jffs/scripts/vpnmon-r2.sh -setup; exit 0;;
[Ee]) timer="$timerloop" ; echo -e "${CClear}\n"; return;;
esac
fi
}
# -------------------------------------------------------------------------------------------------------------------------
# This function presents an Operational Menu in a Pause state, usually during VPN slot errors which give you a 5 second
# opportunity to pause in order to make any particular changes that might help your situation
vpause()
{
while true
do
if [ "$availableslots" = "1 2" ]
then
clear
displayopsmenu
printf "${CClear}Please select? (${CGreen}n${CClear}=UNpause, ${CGreen}e${CClear}=Exit)"
read -p ": " SelectSlot
case $SelectSlot in
[1]) echo ""; restartvpn 1; sendmessage 0 "VPN Reset" 1; restartrouting; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[2]) echo ""; restartvpn 2; sendmessage 0 "VPN Reset" 2; restartrouting; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[\!]) echo ""; killunmonvpn 1; sendmessage 0 "VPN Killed" 1; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[\@]) echo ""; killunmonvpn 2; sendmessage 0 "VPN Killed" 2; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[Aa]) autostart;;
[Cc]) vsetup;;
[Ee]) echo -e "${CClear}\n"; exit 0;;
[Ii]) amtmevents;;
[Ll]) vlogs;;
[Mm]) vpnslots;;
[Pp]) maxping;;
[Rr]) schedulevpnreset;;
[Tt]) timerloopconfig;;
[Uu]) vpnserverlistautomation;;
[Vv]) vpnserverlistmaint;;
[Nn]) exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
*) exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
esac
elif [ "$availableslots" = "1 2 3 4 5" ]
then
clear
displayopsmenu
printf "${CClear}Please select? (${CGreen}n${CClear}=UNpause, ${CGreen}e${CClear}=Exit)"
read -p ": " SelectSlot
case $SelectSlot in
[1]) echo ""; restartvpn 1; sendmessage 0 "VPN Reset" 1; restartrouting; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[2]) echo ""; restartvpn 2; sendmessage 0 "VPN Reset" 2; restartrouting; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[3]) echo ""; restartvpn 3; sendmessage 0 "VPN Reset" 3; restartrouting; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[4]) echo ""; restartvpn 4; sendmessage 0 "VPN Reset" 4; restartrouting; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[5]) echo ""; restartvpn 5; sendmessage 0 "VPN Reset" 5; restartrouting; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[\!]) echo ""; killunmonvpn 1; sendmessage 0 "VPN Killed" 1; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[\@]) echo ""; killunmonvpn 2; sendmessage 0 "VPN Killed" 2; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[\#]) echo ""; killunmonvpn 3; sendmessage 0 "VPN Killed" 3; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[\$]) echo ""; killunmonvpn 4; sendmessage 0 "VPN Killed" 4; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[\%]) echo ""; killunmonvpn 5; sendmessage 0 "VPN Killed" 5; exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
[Aa]) autostart;;
[Cc]) vsetup;;
[Ee]) echo -e "${CClear}\n"; exit 0;;
[Ii]) amtmevents;;
[Ll]) vlogs;;
[Mm]) vpnslots;;
[Pp]) maxping;;
[Rr]) schedulevpnreset;;
[Tt]) timerloopconfig;;
[Uu]) vpnserverlistautomation;;
[Vv]) vpnserverlistmaint;;
[Nn]) exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
*) exec sh /jffs/scripts/vpnmon-r3.sh -noswitch;;
esac
fi
done
}
# -------------------------------------------------------------------------------------------------------------------------
# creates needed config files if they don't exist
createconfigs()
{
# Fix older versions using incorrect client slots
if [ "$availableslots" = "1 2 3" ]
then
availableslots="1 2"
rm -f /jffs/addons/vpnmon-r3.d/vr3clients.txt
rm -f /jffs/addons/vpnmon-r3.d/vr3timers.txt
saveconfig
fi
# Create initial vr3clients.txt & vr3timers.txt file
if [ ! -f /jffs/addons/vpnmon-r3.d/vr3clients.txt ]
then
if [ "$availableslots" = "1 2" ]
then
{ echo 'VPN1=0'
echo 'VPN2=0'
} > /jffs/addons/vpnmon-r3.d/vr3clients.txt
elif [ "$availableslots" = "1 2 3 4 5" ]
then
{ echo 'VPN1=0'
echo 'VPN2=0'
echo 'VPN3=0'
echo 'VPN4=0'
echo 'VPN5=0'
} > /jffs/addons/vpnmon-r3.d/vr3clients.txt
fi
fi
if [ ! -f /jffs/addons/vpnmon-r3.d/vr3timers.txt ]
then
if [ "$availableslots" = "1 2" ]
then
{ echo 'VPNTIMER1=0'
echo 'VPNTIMER2=0'
} > /jffs/addons/vpnmon-r3.d/vr3timers.txt
elif [ "$availableslots" = "1 2 3 4 5" ]
then
{ echo 'VPNTIMER1=0'
echo 'VPNTIMER2=0'
echo 'VPNTIMER3=0'
echo 'VPNTIMER4=0'
echo 'VPNTIMER5=0'
} > /jffs/addons/vpnmon-r3.d/vr3timers.txt
fi
fi
}
##-------------------------------------##
## Added by Martinski W. [2024-Oct-05] ##
##-------------------------------------##
_SetUpTimeoutCmdVars_()
{
# If the timeout utility is available then use it #
if [ -z "${timeoutcmd:+xSETx}" ] && [ -f "/opt/bin/timeout" ]
then
timeoutcmd="timeout "
timeoutsec="10"
timeoutlng="60"
fi
}
##-------------------------------------##
## Added by Martinski W. [2024-Oct-05] ##
##-------------------------------------##
_SetLAN_HostName_()
{
[ -z "${LAN_HostName:+xSETx}" ] && \
LAN_HostName="$($timeoutcmd$timeoutsec nvram get lan_hostname)"
}
_GetLAN_HostName_()
{ _SetLAN_HostName_ ; echo "$LAN_HostName" ; }
# -------------------------------------------------------------------------------------------------------------------------
# vsetup provide a menu interface to allow for initial component installs, uninstall, etc.
##----------------------------------------##
## Modified by Martinski W. [2024-Oct-05] ##
##----------------------------------------##
vsetup()
{
_SetUpTimeoutCmdVars_
while true
do
clear # Initial Setup
if [ ! -f "$config" ]; then # Write /jffs/addons/vpnmon-r3.d/vpnmon-r3.cfg
saveconfig
fi
createconfigs
echo -e "${InvGreen} ${InvDkGray}${CWhite} VPNMON-R3 Main Setup and Configuration Menu ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Please choose from the various options below, which allow you to perform high level${CClear}"
echo -e "${InvGreen} ${CClear} actions in the management of the VPNMON-R3 script.${CClear}"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(1)${CClear} : Custom configuration options for VPNMON-R3${CClear}"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(2)${CClear} : Force reinstall Entware dependencies${CClear}"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(3)${CClear} : Check for latest updates${CClear}"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(4)${CClear} : Uninstall VPNMON-R3${CClear}"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} | ${CClear}"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(e)${CClear} : Exit${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
read -p "Please select? (1-4, e=Exit): " SelectSlot
case $SelectSlot in
1) # Check for existence of entware, and if so proceed and install the timeout package, then run vpnmon-r3 -config
clear
if [ -f "/opt/bin/timeout" ] && [ -f "/opt/sbin/screen" ] && [ -f "/opt/bin/jq" ]
then
vconfig
else
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} Install Dependencies ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Missing dependencies required by VPNMON-R3 will be installed during this process."
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
echo -e "VPNMON-R3 has some dependencies in order to function correctly, namely, CoreUtils-Timeout"
echo -e "JQ, and the Screen utility. These utilities require you to have Entware already installed"
echo -e "using the AMTM tool. If Entware is present, the Timeout, JQ and Screen utilities will"
echo -e "automatically be downloaded and installed during this process."
echo ""
echo -e "${CGreen}CoreUtils-Timeout${CClear} is a utility that provides more stability for certain routers (like"
echo -e "the RT-AC86U) which has a tendency to randomly hang scripts running on this router model."
echo ""
echo -e "${CGreen}JQuery${CClear} is a utility for querying data across the internet through the the means of"
echo -e "APIs for the purposes of interacting with the various VPN providers to get a list"
echo -e "of available VPN hosts in the selected location(s)."
echo ""
echo -e "${CGreen}Screen${CClear} is a utility that allows you to run SSH scripts in a standalone environment"
echo -e "directly on the router itself, instead of running your commands or a script from a network-"
echo -e "attached SSH client. This can provide greater stability due to it running on the router"
echo -e "itself."
echo ""
[ -z "$($timeoutcmd$timeoutsec nvram get odmpid)" ] && RouterModel="$($timeoutcmd$timeoutsec nvram get productid)" || RouterModel="$($timeoutcmd$timeoutsec nvram get odmpid)" # Thanks @thelonelycoder for this logic
echo -e "Your router model is: ${CGreen}$RouterModel${CClear}"
echo ""
echo -e "Ready to install?"
if promptyn " (y/n): "
then
if [ -d "/opt" ]; then # Does entware exist? If yes proceed, if no error out.
echo ""
echo -e "\n${CClear}Updating Entware Packages..."
echo ""
opkg update
echo ""
echo -e "Installing Entware ${CGreen}CoreUtils-Timeout${CClear} Package...${CClear}"
echo ""
opkg install coreutils-timeout
echo ""
echo -e "Installing Entware ${CGreen}JQuery${CClear} Package...${CClear}"
echo ""
opkg install jq
echo ""
echo -e "Installing Entware ${CGreen}Screen${CClear} Package...${CClear}"
echo ""
opkg install screen
echo ""
echo -e "Install completed..."
echo ""
read -rsp $'Press any key to continue...\n' -n1 key
echo ""
echo -e "Executing Configuration Utility..."
sleep 2
vconfig
else
clear
echo -e "${CRed}ERROR: Entware was not found on this router...${CClear}"
echo -e "Please install Entware using the AMTM utility before proceeding..."
echo ""
read -rsp $'Press any key to continue...\n' -n1 key
fi
else
echo ""
echo -e "\nExecuting Configuration Utility..."
sleep 2
vconfig
fi
fi
;;
2) # Force re-install the CoreUtils timeout/screen package
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} Re-install Dependencies ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Missing dependencies required by VPNMON-R3 will be re-installed during this process."
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
echo -e "Would you like to re-install the CoreUtils-Timeout, JQ and the Screen utility? These"
echo -e "utilities require you to have Entware already installed using the AMTM tool. If Entware"
echo -e "is present, the Timeout and Screen utilities will be uninstalled, downloaded and re-"
echo -e "installed during this setup process..."
echo ""
echo -e "${CGreen}CoreUtils-Timeout${CClear} is a utility that provides more stability for certain routers (like"
echo -e "the RT-AC86U) which has a tendency to randomly hang scripts running on this router"
echo -e "model."
echo ""
echo -e "${CGreen}JQuery${CClear} is a utility for querying data across the internet through the the means of"
echo -e "APIs for the purposes of interacting with the various VPN providers to get a list"
echo -e "of available VPN hosts in the selected location(s)."
echo ""
echo -e "${CGreen}Screen${CClear} is a utility that allows you to run SSH scripts in a standalone environment"
echo -e "directly on the router itself, instead of running your commands or a script from a"
echo -e "network-attached SSH client. This can provide greater stability due to it running on"
echo -e "the router itself."
echo ""
[ -z "$($timeoutcmd$timeoutsec nvram get odmpid)" ] && RouterModel="$($timeoutcmd$timeoutsec nvram get productid)" || RouterModel="$($timeoutcmd$timeoutsec nvram get odmpid)" # Thanks @thelonelycoder for this logic
echo -e "Your router model is: ${CGreen}$RouterModel${CClear}"
echo ""
echo -e "Force Re-install?"
if promptyn "[y/n]: "
then
if [ -d "/opt" ]; then # Does entware exist? If yes proceed, if no error out.
echo ""
echo -e "\nUpdating Entware Packages..."
echo ""
opkg update
echo ""
echo -e "Force Re-installing Entware ${CGreen}CoreUtils-Timeout${CClear} Package..."
echo ""
opkg install --force-reinstall coreutils-timeout
echo ""
echo -e "Force Re-installing Entware ${CGreen}JQuery${CClear} Package..."
echo ""
opkg install --force-reinstall . jq
echo ""
echo -e "Force Re-installing Entware ${CGreen}Screen${CClear} Package..."
echo ""
opkg install --force-reinstall screen
echo ""
echo -e "Re-install completed..."
echo ""
read -rsp $'Press any key to continue...\n' -n1 key
else
clear
echo -e "${CRed}ERROR: Entware was not found on this router...${CClear}"
echo -e "Please install Entware using the AMTM utility before proceeding..."
echo ""
read -rsp $'Press any key to continue...\n' -n1 key
fi
fi
;;
3) vupdate;;
4) vuninstall;;
[Ee])
echo ""
timer="$timerloop"
break;;
esac
done
}
# -------------------------------------------------------------------------------------------------------------------------
# vconfig is a function that provides a UI to choose various options for vpnmon-r3
##----------------------------------------##
## Modified by Martinski W. [2024-Oct-05] ##
##----------------------------------------##
vconfig()
{
_SetUpTimeoutCmdVars_
# Grab the VPNMON-R3 config file and read it in
if [ -f "$config" ]
then
source "$config"
else
clear
echo -e "${CRed}ERROR: VPNMON-R3 is not configured. Please run 'vpnmon-r3.sh -setup' first."
echo ""
echo -e "$(date +'%b %d %Y %X') $(_GetLAN_HostName_) VPNMON-R3[$$] - ERROR: VPNMON-R3 config file not found. Please run the setup/configuration utility" >> $logfile
echo -e "${CClear}"
exit 1
fi
while true
do
if [ "$unboundclient" -eq 0 ]; then
unboundclientexp="Disabled"
else
unboundclientexp="Enabled, VPN$unboundclient"
fi
if [ "$refreshserverlists" -eq 0 ]; then
refreshserverlistsdisp="Disabled"
else
refreshserverlistsdisp="Enabled"
fi
if [ "$monitorwan" -eq 0 ]; then
monitorwandisp="Disabled"
else
monitorwandisp="Enabled"
fi
if [ "$updateskynet" -eq 0 ]; then
updateskynetdisp="Disabled"
else
updateskynetdisp="Enabled"
fi
if [ "$amtmemailsuccess" == "0" ] && [ "$amtmemailfailure" == "0" ]; then
amtmemailsuccfaildisp="Disabled"
elif [ "$amtmemailsuccess" == "1" ] && [ "$amtmemailfailure" == "0" ]; then
amtmemailsuccfaildisp="Success"
elif [ "$amtmemailsuccess" == "0" ] && [ "$amtmemailfailure" == "1" ]; then
amtmemailsuccfaildisp="Failure"
elif [ "$amtmemailsuccess" == "1" ] && [ "$amtmemailfailure" == "1" ]; then
amtmemailsuccfaildisp="Success, Failure"
else
amtmemailsuccfaildisp="Disabled"
fi
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} VPNMON-R3 Configuration Options ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Please choose from the various options below, which allow you to modify certain${CClear}"
echo -e "${InvGreen} ${CClear} customizable parameters that affect the operation of this script.${CClear}"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(1)${CClear} : Number of VPN Client Slots available : ${CGreen}$availableslots"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(2)${CClear} : Custom PING host to determine VPN health : ${CGreen}$PINGHOST"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(3)${CClear} : Custom Event Log size (rows) : ${CGreen}$logsize"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(4)${CClear} : Unbound DNS Lookups over VPN Integration : ${CGreen}$unboundclientexp"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(5)${CClear} : Refresh Custom Server Lists on -RESET Switch : ${CGreen}$refreshserverlistsdisp"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(6)${CClear} : Provide additional WAN/Dual WAN monitoring : ${CGreen}$monitorwandisp"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(7)${CClear} : Whitelist VPN Server IP Lists in Skynet : ${CGreen}$updateskynetdisp"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(8)${CClear} : AMTM Email Notifications on Success/Failure : ${CGreen}$amtmemailsuccfaildisp"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite} | ${CClear}"
echo -e "${InvGreen} ${CClear} ${InvDkGray}${CWhite}(e)${CClear} : Exit${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
read -p "Please select? (1-8, e=Exit): " SelectSlot
case $SelectSlot in
1)
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} Number of VPN Client Slots Available on Router ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Please indicate how many VPN client slots your router is configured with. Certain${CClear}"
echo -e "${InvGreen} ${CClear} older model routers (RT-AC68U) can only handle a maximum of 2 client slots, while${CClear}"
echo -e "${InvGreen} ${CClear} the vast majority of newer models can handle 5."
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (Default = 5 VPN client slots)${CClear}"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo
echo -e "${CClear}Current: ${CGreen}$availableslots${CClear}" ; echo
read -p "Please enter value (2 or 5)? (e=Exit): " newAvailableSlots
if [ "$newAvailableSlots" = "2" ]
then
availableslots="1 2"
echo -e "$(date +'%b %d %Y %X') $(_GetLAN_HostName_) VPNMON-R3[$$] - INFO: New Available VPN Client Slot Configuration saved as: $availableslots" >> $logfile
rm -f /jffs/addons/vpnmon-r3.d/vr3clients.txt
rm -f /jffs/addons/vpnmon-r3.d/vr3timers.txt
saveconfig
createconfigs
elif [ "$newAvailableSlots" = "5" ]
then
availableslots="1 2 3 4 5"
echo -e "$(date +'%b %d %Y %X') $(_GetLAN_HostName_) VPNMON-R3[$$] - INFO: New Available VPN Client Slot Configuration saved as: $availableslots" >> $logfile
rm -f /jffs/addons/vpnmon-r3.d/vr3clients.txt
rm -f /jffs/addons/vpnmon-r3.d/vr3timers.txt
saveconfig
createconfigs
elif [ "$newAvailableSlots" = "e" ]
then
echo -e "\n[Exiting]"; sleep 2
else
previousValue="$availableslots"
availableslots="${availableslots:=1 2 3 4 5}"
[ "$availableslots" != "$previousValue" ] && \
echo -e "$(date +'%b %d %Y %X') $(_GetLAN_HostName_) VPNMON-R3[$$] - INFO: New Available VPN Client Slot Configuration saved as: $availableslots" >> $logfile
rm -f /jffs/addons/vpnmon-r3.d/vr3clients.txt
rm -f /jffs/addons/vpnmon-r3.d/vr3timers.txt
saveconfig
createconfigs
fi
;;
2)
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} Custom PING Host (to determine VPN health) ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Please indicate which host you want to PING in order to determine VPN Client health.${CClear}"
echo -e "${InvGreen} ${CClear} By default, the script will ping $PING_HOST_Deflt (Google DNS) as it's reliable, fairly${CClear}"
echo -e "${InvGreen} ${CClear} standard, and typically available globally. You can change this depending on your"
echo -e "${InvGreen} ${CClear} local access and connectivity situation."
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (Default = ${PING_HOST_Deflt})${CClear}"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo
echo -e "${CClear}Current: ${CGreen}${PINGHOST}${CClear}" ; echo
read -p "Please enter valid IPv4 address? (e=Exit): " newPingHost
if [ "$newPingHost" = "e" ]
then
echo -e "\n[Exiting]"; sleep 2
elif [ -n "$newPingHost" ] && echo "$newPingHost" | grep -qE "^${IPv4addrs_RegEx}$"
then
PINGHOST="$newPingHost"
echo -e "$(date +'%b %d %Y %X') $(_GetLAN_HostName_) VPNMON-R3[$$] - INFO: New custom PING host entered: $PINGHOST" >> $logfile
saveconfig
else
previousValue="$PINGHOST"
PINGHOST="${PINGHOST:=$PING_HOST_Deflt}"
[ "$PINGHOST" != "$previousValue" ] && \
echo -e "$(date +'%b %d %Y %X') $(_GetLAN_HostName_) VPNMON-R3[$$] - INFO: New custom PING host entered: $PINGHOST" >> $logfile
saveconfig
fi
;;
3)
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} Custom Event Log Size ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Please indicate below how large you would like your Event Log to grow. I'm a poet${CClear}"
echo -e "${InvGreen} ${CClear} and didn't even know it. By default, with 2000 rows, you will have many months of${CClear}"
echo -e "${InvGreen} ${CClear} Event Log data."
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Use 0 to Disable, max number of rows is 9999. (Default = 2000)"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo
echo -e "${CClear}Current: ${CGreen}$logsize${CClear}" ; echo
read -p "Please enter Log Size (in rows)? (0-9999, e=Exit): " newLogSize
if [ "$newLogSize" = "e" ]
then
echo -e "\n[Exiting]"; sleep 2
elif echo "$newLogSize" | grep -qE "^(0|[1-9][0-9]{0,3})$" && \
[ "$newLogSize" -ge 0 ] && [ "$newLogSize" -le 9999 ]
then
logsize="$newLogSize"
echo -e "$(date +'%b %d %Y %X') $(_GetLAN_HostName_) VPNMON-R3[$$] - INFO: New custom Event Log Size entered (in rows): $logsize" >> $logfile
saveconfig
else
previousValue="$logsize"
logsize="${logsize:=2000}"
[ "$logsize" != "$previousValue" ] && \
echo -e "$(date +'%b %d %Y %X') $(_GetLAN_HostName_) VPNMON-R3[$$] - INFO: New custom Event Log Size entered (in rows): $logsize" >> $logfile
saveconfig
fi
;;
4)
while true; do
clear
echo -e "${InvGreen} ${InvDkGray}${CWhite} Unbound DNS Lookups over VPN Integration ${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} Please indicate if you would like to enable an integration with Unbound which allows${CClear}"
echo -e "${InvGreen} ${CClear} you to force any DNS lookups that Unbound would normally handle, but over your VPN${CClear}"
echo -e "${InvGreen} ${CClear} connection, essentially allowing you to appear as your own DNS resolver. DNS resolver${CClear}"
echo -e "${InvGreen} ${CClear} traffic generated by Unbound is unencrypted as it queries DNS Root Servers by default.${CClear}"
echo -e "${InvGreen} ${CClear} This integration encrypts your DNS Resolver traffic up to your Public VPN IP address,${CClear}"
echo -e "${InvGreen} ${CClear} after which it goes unencrypted to the DNS Root Servers, preventing any ISP or other${CClear}"
echo -e "${InvGreen} ${CClear} traffic inspection snooping when sending this across your WAN connection.${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} IMPORTANT: This integration will only work with 1 primary VPN connection that is${CClear}"
echo -e "${InvGreen} ${CClear} designated as the connection that will carry DNS resolution traffic. This integration${CClear}"
echo -e "${InvGreen} ${CClear} will work when multiple VPN connections are running, but the other VPN connections may${CClear}"
echo -e "${InvGreen} ${CClear} not be able to utilize the Unbound functionality, and considered standalone. You will${CClear}"
echo -e "${InvGreen} ${CClear} need to identify one VPN Client Slot that will remain on at all times. This integration${CClear}"
echo -e "${InvGreen} ${CClear} requires additional scripts and configurations to get it working correctly. Please know${CClear}"
echo -e "${InvGreen} ${CClear} that multiple files will either be downloaded or modified, and may increase the${CClear}"
echo -e "${InvGreen} ${CClear} complexity in troubleshooting DNS lookup issues.${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} ${CRed}WARNING: As of around March 1 2024, the Unbound integration no longer works with the${CClear}"
echo -e "${InvGreen} ${CClear} ${CRed}NordVPN Service due to possible blocking on their end. This service continues to work${CClear}"
echo -e "${InvGreen} ${CClear} ${CRed}as advertised with other VPN Providers, like AirVPN. Use at your own risk.${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} ${CGreen}Requirements:"
echo -e "${InvGreen} ${CClear} ${CGreen}1. Unbound must already be installed and functioning (AMTM)"
echo -e "${InvGreen} ${CClear} ${CGreen}2. One static VPN Slot must be designated for Unbound-over-VPN use"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} ${CGreen}These files will be downloaded or modified:"
echo -e "${InvGreen} ${CClear} ${CGreen}1. /jffs/scripts/nat-start (modified)"
echo -e "${InvGreen} ${CClear} ${CGreen}2. /jffs/scripts/openvpn-event (modified)"
echo -e "${InvGreen} ${CClear} ${CGreen}3. /jffs/scripts/post-mount (modified)"
echo -e "${InvGreen} ${CClear} ${CGreen}4. /jffs/addons/unbound/unbound_DNS_via_OVPN.sh (downloaded)"
echo -e "${InvGreen} ${CClear} ${CGreen}5. Required router reboot - please don't forget to do so!${CClear}"
echo -e "${InvGreen} ${CClear}"
echo -e "${InvGreen} ${CClear} (Default = 0 / Disabled)${CClear}"
echo -e "${InvGreen} ${CClear}${CDkGray}---------------------------------------------------------------------------------------${CClear}"
echo ""
if [ $unboundclient -eq 0 ]; then
unboundclientexp="Disabled"
else
unboundclientexp="Enabled, VPN$unboundclient"
fi
echo -e "${CClear}Current: ${CGreen}$unboundclientexp${CClear}"
echo ""
read -p "Please enter value (Disabled=0, VPN Client=1-5)? (e=Exit): " unboundovervpn
if [ ! -d "/jffs/addons/unbound" ]; then
echo ""
echo -e "${CRed}[Unbound was not detected on this system. Exiting...]${CClear}"
echo -e "$(date +'%b %d %Y %X') $(_GetLAN_HostName_) VPNMON-R3[$$] - WARNING: Unbound was not detected on this system." >> $logfile
unboundclient=0
saveconfig
sleep 3
break
fi