/
nordlist.sh
5253 lines (5252 loc) · 194 KB
/
nordlist.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/bash
# shellcheck disable=SC2129,SC2154
# individual redirects, var assigned
#
# Tested with NordVPN Version 3.18.1 on Linux Mint 21.3
# May 17, 2024
#
# This script works with the NordVPN Linux CLI. I started
# writing it to save some keystrokes on my Home Theatre PC.
# It keeps evolving and is still a work in progress. Bash
# scripting is new to me and I'm learning as I go. I added a
# lot of comments to help fellow newbies customize the script.
#
# Screenshots:
# https://github.com/ph202107/nordlist/tree/main/screenshots
#
# https://github.com/ph202107/nordlist
# /u/pennyhoard20 on reddit
# Suggestions/feedback welcome
#
# =====================================================================
# Instructions
# =============
#
# 1) Save as nordlist.sh
# For convenience I use a directory in my PATH (echo $PATH)
# eg. /home/username/.local/bin/nordlist.sh
# 2) Make the script executable with
# "chmod +x nordlist.sh"
# 3) To generate ASCII images and to use NordVPN API functions
# these small programs are required
# eg. "sudo apt install figlet lolcat curl jq"
# 4) At the terminal run "nordlist.sh"
# (Or "./nordlist.sh" from the directory if it's not in $PATH)
#
# =====================================================================
# Other Programs Used
# ====================
#
# wireguard-tools Tools-WireGuard (function wireguard_gen)
# speedtest-cli Tools-Speed Tests (function speedtest_menu)
# iperf3 Meshnet-Speed Tests (function speedtest_iperf3)
# highlight Settings-Script (function script_info)
#
# "sudo apt install wireguard wireguard-tools speedtest-cli iperf3 highlight"
#
# For VPN On/Off status on the desktop I use the Linux Mint Cinnamon
# applet "Bash Sensors". Highly recommended for Cinnamon DE users.
# Screenshot: https://github.com/ph202107/nordlist/blob/main/screenshots
# When the status icon is clicked, it will launch this script in a new
# terminal. The config is in the "Notes" at the bottom of the script.
#
# =====================================================================
# Sudo Usage
# ===========
#
# These functions will ask for a sudo password:
# - function restart_service
# - function iptables_status
# - function iptables_flush
# - function wireguard_gen
# - function customdns_menu "Flush DNS Cache"
#
# =====================================================================
# Customization
# ==============
#
# Specify your P2P preferred location. (Optional)
# eg. p2pwhere="Canada" or p2pwhere="Toronto"
p2pwhere=""
#
# Specify your Obfuscated_Servers location. (Optional)
# The location must support obfuscation.
# eg. obwhere="United_States" or obwhere="Los_Angeles"
obwhere=""
#
# Specify the first hop to use for Double_VPN. (Optional)
# The location must have Double_VPN servers available.
# eg. dblwhere="United_Kingdom" or dblwhere="Sweden"
dblwhere=""
#
# Specify your Onion_Over_VPN location. (Optional)
# Typically Netherlands and Switzerland are available (~3 servers total)
# eg. torwhere="Netherlands" or torwhere="Switzerland"
torwhere=""
#
# Specify your Dedicated_IP location. (Optional)
# If you have a Dedicated IP you can specify your server, eg. "ca1692"
# Otherwise you can connect to the server group in a supported region.
# eg. dediwhere="Tokyo" or dediwhere="Johannesburg"
dediwhere=""
#
# Specify your Auto-Connect location. (Optional)
# eg. acwhere="Australia" or acwhere="Sydney"
# When obfuscate is enabled, the location must support obfuscation.
acwhere=""
#
# Specify your Custom-DNS servers with a description.
# Can specify up to 3 IP addresses separated by a space.
default_dns="103.86.96.100 103.86.99.100"; dnsdesc="Nord"
#
# Specify a VPN hostname to use for testing while the VPN is off.
# For example the VPN server configured on a local router.
# Can still enter any hostname later, this is just a default choice.
default_vpnhost="ca1576.nordvpn.com"
#
# Specify any hostname to lookup when testing DNS response time.
# Can also enter a different hostname later.
default_dnshost="reddit.com"
#
# Confirm the location of the NordVPN changelog on your system.
nordchangelog="/usr/share/doc/nordvpn/changelog.Debian.gz"
#
# Save incoming Meshnet file transfers into this folder.
# Note: $USER will automatically translate to your username.
# Use the absolute path, no trailing slash (/)
meshnetdir="/home/$USER/Downloads"
#
# Save generated WireGuard config files into this folder.
# Use the absolute path, no trailing slash (/)
wgdir="/home/$USER/Downloads"
#
# Specify the absolute path and filename to save a copy of the
# nordvpnd.service logs. Create the file in: Settings - Logs
nordlogfile="/home/$USER/Downloads/nord_logs.txt"
#
# Specify the absolute path and filename to store a .json of all the
# NordVPN servers (about 20MB). Avoids API server timeouts. Create the
# list at: Tools - NordVPN API - All VPN Servers
nordserversfile="/home/$USER/Downloads/nord_allservers.json"
#
# Specify the absolute path and filename to store a local list of your
# favorite NordVPN servers. eg. Low ping servers or streaming servers.
# Create the list in: 'Favorites'
nordfavoritesfile="/home/$USER/Downloads/nord_favorites.txt"
#
# Change the terminal window titlebar text while the script is running.
# Leave this blank to keep the titlebar unchanged.
titlebartext="NORD"
#
# When changing servers disconnect the VPN first, then connect to the
# new server. "y" or "n"
disconnect="n"
#
# Always 'Rate Server' when disconnecting via the main menu. "y" or "n"
rate_prompt="y"
#
# Ask to pause the VPN when disconnecting via the main menu
# (disconnect and automatically reconnect). "y" or "n"
pause_prompt="y"
#
# Specify the default number of minutes to pause the VPN.
default_pause="5"
#
# Show the logo (ASCII and stats) when the script exits. "y" or "n"
exitlogo="y"
#
# Always enable the Kill Switch (and Firewall) when the script exits
# and the VPN is connected. "y" or "n"
exitkillswitch="n"
#
# Ping the connected server when the script exits. "y" or "n"
exitping="n"
#
# Query the current server load when the script exits. "y" or "n"
# Requires 'curl' 'jq' and the local 'nordserversfile' mentioned above.
exitload="n"
#
# Show your external IP address when the script exits. "y" or "n"
# Requires 'curl' and 'jq'. Connects to ipinfo.io.
exitip="n"
#
# Reload the "Bash Sensors" Cinnamon applet when the script exits.
# Only for the Cinnamon DE with "Bash Sensors" installed. "y" or "n"
exitappletb="n"
#
# Reload the "Network Manager" Cinnamon applet when the script exits.
# This removes duplicate "nordlynx" entries from the applet. "y" or "n"
exitappletn="n"
#
# Open http links in a new Firefox window. "y" or "n"
# Choose "n" to use the default browser or method.
newfirefox="n"
#
# Specify the number of pings to send when pinging a destination.
pingcount="3"
#
# Set 'menuwidth' to your terminal width or lower. This will compact
# the menus horizontally. ("Countries" and "Favorites" excluded.)
# Leave blank to have the menu width change with the window size.
menuwidth="80"
#
# Choose the maximum number of characters for country names in the
# "Countries" menu. Shortens long names so the menu fits better in the
# terminal window. Minimum is "6". Leave blank to disable.
charlimit="12"
#
# Choosing 'Exit' in a submenu will take you to the main menu.
# Entering this value while in a submenu will return you to the default
# parent menu. Also works with most (y/n) prompts to exit the prompt.
# To avoid conflicts avoid using any number other than zero, or
# the letters y,n,c,e,s. eg. upmenu="0" or upmenu="b"
upmenu="0"
#
# =====================================================================
# Fast Options
# =============
#
# Fast options speed up the script by automatically answering 'yes'
# to prompts. Would recommend trying the script to see how it operates
# before enabling these options.
#
# Choose "y" or "n"
#
# Return to the main menu without prompting "Press any key..."
fast1="n"
#
# Automatically change these settings without prompting: Firewall,
# Routing, Analytics, KillSwitch, TPLite, Notify, AutoConnect, IPv6,
# LAN-Discovery
fast2="n"
#
# Automatically change these settings which also disconnect the VPN:
# Technology, Protocol, Obfuscate
fast3="n"
#
# Automatically disconnect, change settings, and connect to these
# groups: Obfuscated, Double-VPN, Onion+VPN, P2P, Dedicated-IP
fast4="n"
#
# Always enable the Kill Switch (& Firewall) when connecting to groups.
# (Does not apply when connecting through the "All_Groups" menu.)
fast5="n"
#
# Always choose the same protocol when asked to choose TCP or UDP.
# (Unless changing the setting through Settings - Protocol.)
fast6="n" # "y" or "n"
fast6p="UDP" # specify the protocol. fast6p="UDP" or fast6p="TCP"
#
# When choosing a country from the 'Countries' menu, immediately
# connect to that country instead of choosing a city.
fast7="n"
#
# By default the [F] indicator will be set when any of the 'fast'
# options are enabled.
# Modify 'allfast' if you want to display the [F] indicator only when
# specific 'fast' options are enabled.
allfast=("$fast1" "$fast2" "$fast3" "$fast4" "$fast5" "$fast6" "$fast7")
#
# =====================================================================
# Virtual Servers
# ================
#
# Countries and Cities listed here will be labelled as (Virtual).
# Refer to: https://nordvpn.com/blog/new-nordvpn-virtual-servers/
# This list is subject to change and must be updated manually.
# Retrieve an updated list in "Tools - NordVPN API - All VPN Servers"
nordvirtual=(
"Accra" "Algeria" "Algiers" "Andorra" "Andorra_la_Vella" "Armenia" "Astana" "Asuncion" "Azerbaijan" "Bahamas" "Baku" "Bandar_Seri_Begawan" "Bangkok" "Bangladesh" "Beirut" "Belize" "Belmopan" "Bermuda" "Bhutan" "Bolivia" "Brunei_Darussalam" "Cairo" "Cambodia" "Caracas" "Cayman_Islands" "Colombo" "Costa_Rica" "Dhaka" "Dominican_Republic" "Douglas" "Ecuador" "Egypt" "El_Salvador" "George_Town" "Ghana" "Greenland" "Guam" "Guatemala" "Guatemala_City" "Hagatna" "Hamilton" "Hanoi" "Ho_Chi_Minh_City" "Honduras" "India" "Isle_of_Man" "Jamaica" "Jersey" "Karachi" "Kathmandu" "Kazakhstan" "Kenya" "Kingston" "Lagos" "Lao_People's_Democratic_Republic" "La_Paz" "Lebanon" "Liechtenstein" "Lima" "Malta" "Manila" "Monaco" "Mongolia" "Monte_Carlo" "Montenegro" "Montevideo" "Morocco" "Mumbai" "Myanmar" "Nairobi" "Nassau" "Naypyidaw" "Nepal" "Nigeria" "Nuuk" "Pakistan" "Panama" "Panama_City" "Papua_New_Guinea" "Paraguay" "Peru" "Philippines" "Phnom_Penh" "Podgorica" "Port_Moresby" "Port_of_Spain" "Puerto_Rico" "Quito" "Rabat" "Saint_Helier" "San_Jose" "San_Juan" "San_Salvador" "Santo_Domingo" "Sri_Lanka" "Tashkent" "Tegucigalpa" "Thailand" "Thimphu" "Trinidad_and_Tobago" "Ulaanbaatar" "Uruguay" "Uzbekistan" "Vaduz" "Valletta" "Venezuela" "Vientiane" "Vietnam" "Yerevan"
)
#
# =====================================================================
# Visual Options
# ===============
#
# Change the main menu figlet ASCII style in "function ascii_custom"
# Change the figlet ASCII style for headings in "function heading"
# Change the text and indicator colors in "function set_colors"
#
# =====================================================================
# Allowlist & Default Settings
# =============================
#
# Add your allowlist commands to "function allowlist_commands"
# Set up a default NordVPN config in "function set_defaults"
#
# =====================================================================
# Main Menu
# ==========
#
# The Main Menu starts on line 4799 (function main_menu).
# Configure the first ten main menu items to suit your needs.
#
# Enjoy!
#
# ==End================================================================
#
function allowlist_commands {
# Add your allowlist configuration commands here.
# Enter one command per line.
# allowlist_start (keep this line as-is)
#
#nordvpn allowlist remove all
#nordvpn allowlist add subnet 192.168.1.0/24
#
# allowlist_end (keep this line as-is)
echo
}
function set_defaults {
echo
echo -e "${LColor}Apply the default configuration.${Color_Off}"
echo
# Calling this function can be useful to change multiple settings
# at once and get back to a typical configuration.
#
# Configure as needed and comment-out the line below.
echo -e "${WColor}** 'function set_defaults' not configured **${Color_Off}"; echo; return
#
# Notes:
# - The VPN will be disconnected
# - Kill Switch requires Firewall
# - NordLynx is UDP only
# - Obfuscate requires OpenVPN
# - TPLite disables CustomDNS and vice versa
# - LAN-Discovery will remove private subnets from Allowlist
#
# For each setting uncomment one of the two choices (or neither).
#
if [[ "$firewall" == "disabled" ]]; then nordvpn set firewall enabled; fi
#if [[ "$firewall" == "enabled" ]]; then nordvpn set firewall disabled; fi
#
if [[ "$killswitch" == "disabled" ]]; then nordvpn set killswitch enabled; fi
#if [[ "$killswitch" == "enabled" ]]; then nordvpn set killswitch disabled; fi
#
disconnect_vpn "force"
#
if [[ "$technology" == "openvpn" ]]; then if [[ "$protocol" == "TCP" ]]; then nordvpn set protocol UDP; fi; nordvpn set technology nordlynx; set_vars; fi
#if [[ "$technology" == "nordlynx" ]]; then nordvpn set technology openvpn; set_vars; fi
#
if [[ "$protocol" == "TCP" ]]; then nordvpn set protocol UDP; fi
#if [[ "$protocol" == "UDP" ]]; then nordvpn set protocol TCP; fi
#
if [[ "$routing" == "disabled" ]]; then nordvpn set routing enabled; fi
#if [[ "$routing" == "enabled" ]]; then nordvpn set routing disabled; fi
#
#if [[ "$analytics" == "disabled" ]]; then nordvpn set analytics enabled; fi
#if [[ "$analytics" == "enabled" ]]; then nordvpn set analytics disabled; fi
#
#if [[ "$tplite" == "disabled" ]]; then nordvpn set threatprotectionlite enabled; fi
if [[ "$tplite" == "enabled" ]]; then nordvpn set threatprotectionlite disabled; fi
#
#if [[ "$obfuscate" == "disabled" ]]; then nordvpn set obfuscate enabled; fi
if [[ "$obfuscate" == "enabled" ]]; then nordvpn set obfuscate disabled; fi
#
#if [[ "$notify" == "disabled" ]]; then nordvpn set notify enabled; fi
if [[ "$notify" == "enabled" ]]; then nordvpn set notify disabled; fi
#
#if [[ "$autoconnect" == "disabled" ]]; then nordvpn set autoconnect enabled $acwhere; fi
if [[ "$autoconnect" == "enabled" ]]; then nordvpn set autoconnect disabled; fi
#
#if [[ "$ipversion6" == "disabled" ]]; then nordvpn set ipv6 enabled; fi
if [[ "$ipversion6" == "enabled" ]]; then nordvpn set ipv6 disabled; fi
#
#if [[ "$meshnet" == "disabled" ]]; then nordvpn set meshnet enabled; fi
#if [[ "$meshnet" == "enabled" ]]; then nordvpn set meshnet disabled; fi
#
#if [[ "$customdns" == "disabled" ]]; then nordvpn set dns $default_dns; fi
#if [[ "$customdns" != "disabled" ]]; then nordvpn set dns disabled; fi
#
#if [[ "$landiscovery" == "disabled" ]]; then nordvpn set lan-discovery enabled; fi
#if [[ "$landiscovery" == "enabled" ]]; then nordvpn set lan-discovery disabled; fi
#
echo
}
function ascii_static {
# This ASCII will display above the main menu if figlet or lolcat is not installed.
# You can also use your own ASCII art and specify "ascii_static" in "function main_logo".
# Change the color in "function set_colors".
echo -ne "${ASColor}"
#
cat << "EOF"
_ _ ___ ______ _ _
| \ | | ___ _ __ __| \ \ / / _ \| \ | |
| \| |/ _ \| '__/ _' |\ \ / /| |_) | \| |
| |\ | (_) | | | (_| | \ V / | __/| |\ |
|_| \_|\___/|_| \__,_| \_/ |_| |_| \_|
EOF
#
echo -ne "${Color_Off}"
}
function ascii_custom {
if ! (( "$figlet_exists" )) || ! (( "$lolcat_exists" )); then
ascii_static
return
fi
# This ASCII is displayed above the main menu. Any text or variable(s) can be used.
# eg. "$city", "$country", "$transferd", "NordVPN", "$HOSTNAME", "$(date)", etc.
#
asciitext="$city"
#
if (( "$meshrouting" )); then
# when routing through meshnet
asciitext="Meshnet Routing"
fi
if [[ "$connected" == "connected" ]]; then
# Add or remove any figlet fonts, arrange from largest to smallest or by preference.
for figletfont in slant standard smslant small none
do
if [[ "$figletfont" == "none" ]]; then
# If no ascii fonts will fit then print regular text.
echo
echo "====== ${asciitext^^} ======" | lolcat -p 0.7
#echo -e "${H1Color}====== ${asciitext^^} ======${Color_Off}"
echo
elif (( "$(tput cols)" > "$(wc -L <<< "$(figlet -w 999 -f "$figletfont" "$asciitext")")" )); then
# Check the current terminal width, and the width required for the ascii font.
figlet -t -f "$figletfont" "$asciitext" | lolcat
break
fi
done
else
# style when disconnected
figlet -t -f "standard" "NordVPN"
fi
}
function main_logo {
# the ascii and stats shown above the main_menu and on script exit
set_vars
if [[ "$1" != "stats_only" ]]; then
# Specify ascii_static or ascii_custom on the line below.
ascii_custom
fi
if (( "$meshrouting" )); then
echo -e "$connectedcl ${SVColor}$nordhost ${IPColor}$ipaddr${Color_Off}"
else
echo -e "$connectedcl ${CIColor}$city ${COColor}$country ${SVColor}$server ${IPColor}$ipaddr ${Color_Off}$fav"
fi
echo -e "$techpro$fw$rt$an$ks$tp$ob$no$ac$ip6$mn$dns$ld$al$fst$sshi"
echo -e "$transferc ${UPColor}$uptime${Color_Off}"
if [[ -n $transferc ]]; then echo; fi
# all indicators: $techpro$fw$rt$an$ks$tp$ob$no$ac$ip6$mn$dns$ld$al$fst$sshi
}
function heading {
# The text or ASCII that displays after a menu selection is made.
# $1 = heading text
# $2 = "txt" - use regular text instead of figlet
# $3 = "alt" - use alternate color for regular text
#
clear -x
if ! (( "$figlet_exists" )) || ! (( "$lolcat_exists" )) || [[ "$2" == "txt" ]]; then
echo
if [[ "$3" == "alt" ]]; then
echo -e "${H2Color}=== $1 ===${Color_Off}"
else
echo -e "${H1Color}=== $1 ===${Color_Off}"
fi
echo
else
# Add or remove any figlet fonts, arrange from largest to smallest or by preference.
for figletfont in slant standard smslant small none
do
if [[ "$figletfont" == "none" ]]; then
# If no ascii fonts will fit then print regular text.
echo
echo -e "${H1Color}=== $1 ===${Color_Off}"
echo
elif (( "$(tput cols)" > "$(wc -L <<< "$(figlet -w 999 -f "$figletfont" "$1")")" )); then
# Check the current terminal width, and the width required for the ascii font.
figlet -t -f "$figletfont" "$1" | lolcat -p 1000
break
fi
done
fi
if [[ "$1" == "Countries" ]] || [[ "$1" == "Favorites" ]]; then
return
else
COLUMNS="$menuwidth"
fi
}
function set_colors {
#
# shellcheck disable=SC2034
# supress warning about unused color variables
{
# Regular
Black='\033[0;30m'
Red='\033[0;31m'
Green='\033[0;32m'
Yellow='\033[0;33m'
Blue='\033[0;34m'
Purple='\033[0;35m'
Cyan='\033[0;36m'
White='\033[0;97m'
#
# Light
LGrey='\033[0;37m'
DGrey='\033[0;90m' # Dark
LRed='\033[0;91m'
LGreen='\033[0;92m'
LYellow='\033[0;93m'
LBlue='\033[0;94m'
LPurple='\033[0;95m'
LCyan='\033[0;96m'
#
# Bold
BBlack='\033[1;30m'
BRed='\033[1;31m'
BGreen='\033[1;32m'
BYellow='\033[1;33m'
BBlue='\033[1;34m'
BPurple='\033[1;35m'
BCyan='\033[1;36m'
BWhite='\033[1;37m'
#
# Underline
UBlack='\033[4;30m'
URed='\033[4;31m'
UGreen='\033[4;32m'
UYellow='\033[4;33m'
UBlue='\033[4;34m'
UPurple='\033[4;35m'
UCyan='\033[4;36m'
UWhite='\033[4;37m'
#
# Background
# eg: ${White}${On_Red} = White text on red background
On_Black='\033[40m'
On_Red='\033[41m'
On_Green='\033[42m'
On_Yellow='\033[43m'
On_Blue='\033[44m'
On_Purple='\033[45m'
On_Cyan='\033[46m'
On_White='\033[47m'
#
Color_Off='\033[0m'
}
#
# ============== Change colors here if needed. ====================
#
EColor=${LGreen} # Enabled text
EIColor=${BGreen} # Enabled indicator
DColor=${LRed} # Disabled text
DIColor=${BRed} # Disabled indicator
FColor=${LYellow} # [F]ast text
FIColor=${BYellow} # [F]ast indicator
TColor=${BPurple} # Technology and Protocol text
TIColor=${BPurple} # Technology and Protocol indicator
#
WColor=${BRed} # Warnings, errors, disconnects
LColor=${LCyan} # 'Changes' lists and key info text
ASColor=${BBlue} # Color for the ascii_static image
H1Color=${LGreen} # Non-figlet headings
H2Color=${LCyan} # Non-figlet headings alternate
# main_logo
CNColor=${LGreen} # Connected status
DNColor=${LRed} # Disconnected status
CIColor=${Color_Off} # City name
COColor=${Color_Off} # Country name
SVColor=${Color_Off} # Server name
IPColor=${Color_Off} # IP address
FVColor=${LCyan} # Favorite|Dedicated-IP|Virtual label
DLColor=${Green} # Download stat
ULColor=${Yellow} # Upload stat
UPColor=${Cyan} # Uptime stat
#
}
#
# =====================================================================
# =====================================================================
#
function nstatus_search {
# search the nstatus array by line
# $1 = search string
# $2 = "line" - return the entire line
#
if [[ "$2" == "line" ]]; then
printf '%s\n' "${nstatus[@]}" | grep -i "$1"
else
# the last field using <colon><space> as delimiter
# some elements may have spaces eg Los Angeles, United States
printf '%s\n' "${nstatus[@]}" | grep -i "$1" | awk -F': ' '{print $NF}'
fi
}
function nsettings_search {
# search the nsettings array by line
# $1 = search string
# $2 = "line" - return the entire line
#
if [[ "$2" == "line" ]]; then
printf '%s\n' "${nsettings[@]}" | grep -i "$1"
else
# the last field using <space> as delimiter
printf '%s\n' "${nsettings[@]}" | grep -i "$1" | awk -F' ' '{print $NF}'
fi
}
function set_vars {
# Store info in arrays (BASH v4)
readarray -t nstatus < <( nordvpn status | tr -d '\r' )
readarray -t nsettings < <( nordvpn settings | tr -d '\r' | tr '[:upper:]' '[:lower:]' )
#
# "nordvpn status"
# When disconnected, $connected is the only variable from nstatus
# When meshnet is enabled, the transfer stats will not be zeroed on VPN reconnect.
connected=$( nstatus_search "Status" | tr '[:upper:]' '[:lower:]' )
nordhost=$( nstatus_search "Hostname" )
server=$( echo "$nordhost" | cut -f1 -d'.' )
country=$( nstatus_search "Country" )
city=$( nstatus_search "City" )
ipaddr=$( nstatus_search "IP:" )
protocol2=$( nstatus_search "protocol" | tr '[:lower:]' '[:upper:]' )
transferd=$( nstatus_search "Transfer" "line" | cut -f 2-3 -d' ' ) # download stat with units
transferu=$( nstatus_search "Transfer" "line" | cut -f 5-6 -d' ' ) # upload stat with units
uptime=$( nstatus_search "Uptime" "line" | cut -f 1-9 -d' ' )
#
# "nordvpn settings"
# $protocol and $obfuscate are not listed when using NordLynx
technology=$( nsettings_search "Technology" )
protocol=$( nsettings_search "Protocol" | tr '[:lower:]' '[:upper:]' )
firewall=$( nsettings_search "Firewall:" )
fwmark=$( nsettings_search "Firewall Mark" )
routing=$( nsettings_search "Routing" )
analytics=$( nsettings_search "Analytics" )
killswitch=$( nsettings_search "Kill" )
tplite=$( nsettings_search "Threat" )
obfuscate=$( nsettings_search "Obfuscate" )
notify=$( nsettings_search "Notify" )
autoconnect=$( nsettings_search "Auto" )
ipversion6=$( nsettings_search "IPv6" )
meshnet=$( nsettings_search "Meshnet" | tr -d '\n' )
customdns=$( nsettings_search "DNS" ) # disabled or not=disabled
dns_servers=$( nsettings_search "DNS" "line" | tr '[:lower:]' '[:upper:]' ) # Server IPs, includes "DNS: "
landiscovery=$( nsettings_search "Discover" )
allowlist=$( printf '%s\n' "${nsettings[@]}" | grep -A100 -i "allowlist" )
#
# Prefer common spelling.
if [[ "$technology" == "openvpn" ]]; then technologyd="OpenVPN"
elif [[ "$technology" == "nordlynx" ]]; then technologyd="NordLynx"
fi
technologydc="${TColor}$technologyd${Color_Off}"
#
# To display the protocol for either Technology whether connected or disconnected.
if [[ "$connected" == "connected" ]]; then protocold="$protocol2"
elif [[ "$technology" == "nordlynx" ]]; then protocold="UDP"
else protocold="$protocol"
fi
protocoldc="${TColor}$protocold${Color_Off}"
#
techpro="${TIColor}[$technologyd $protocold]${Color_Off}"
#
if [[ "$connected" == "connected" ]]; then
connectedc="${CNColor}$connected${Color_Off}"
connectedcl="${CNColor}${connected^}${Color_Off}:"
transferc="${DLColor}\u25bc $transferd ${ULColor} \u25b2 $transferu ${Color_Off}"
else
connectedc="${DNColor}$connected${Color_Off}"
connectedcl="${DNColor}${connected^}${Color_Off}"
transferc=""
fi
#
if [[ "$firewall" == "enabled" ]]; then
fw="${EIColor}[FW]${Color_Off}"
firewallc="${EColor}$firewall${Color_Off}"
else
fw="${DIColor}[FW]${Color_Off}"
firewallc="${DColor}$firewall${Color_Off}"
fi
#
if [[ "$routing" == "enabled" ]]; then
rt="${EIColor}[RT]${Color_Off}"
routingc="${EColor}$routing${Color_Off}"
else
rt="${DIColor}[RT]${Color_Off}"
routingc="${DColor}$routing${Color_Off}"
fi
#
if [[ "$analytics" == "enabled" ]]; then
an="${EIColor}[AN]${Color_Off}"
else
an="${DIColor}[AN]${Color_Off}"
fi
#
if [[ "$killswitch" == "enabled" ]]; then
ks="${EIColor}[KS]${Color_Off}"
killswitchc="${EColor}$killswitch${Color_Off}"
else
ks="${DIColor}[KS]${Color_Off}"
killswitchc="${DColor}$killswitch${Color_Off}"
fi
#
if [[ "$tplite" == "enabled" ]]; then
tp="${EIColor}[TP]${Color_Off}"
else
tp="${DIColor}[TP]${Color_Off}"
fi
#
if [[ "$obfuscate" == "enabled" ]]; then
ob="${EIColor}[OB]${Color_Off}"
obfuscatec="${EColor}$obfuscate${Color_Off}"
else
ob="${DIColor}[OB]${Color_Off}"
obfuscatec="${DColor}$obfuscate${Color_Off}"
fi
#
if [[ "$notify" == "enabled" ]]; then
no="${EIColor}[NO]${Color_Off}"
else
no="${DIColor}[NO]${Color_Off}"
fi
#
if [[ "$autoconnect" == "enabled" ]]; then
ac="${EIColor}[AC]${Color_Off}"
else
ac="${DIColor}[AC]${Color_Off}"
fi
#
if [[ "$ipversion6" == "enabled" ]]; then
ip6="${EIColor}[IP6]${Color_Off}"
else
ip6="${DIColor}[IP6]${Color_Off}"
fi
#
if [[ "$meshnet" == "enabled" ]]; then
mn="${EIColor}[MN]${Color_Off}"
meshnetc="${EColor}$meshnet${Color_Off}"
else
mn="${DIColor}[MN]${Color_Off}"
meshnetc="${DColor}$meshnet${Color_Off}"
fi
#
if [[ "$customdns" == "disabled" ]]; then # reversed
dns="${DIColor}[DNS]${Color_Off}"
else
dns="${EIColor}[DNS]${Color_Off}"
fi
#
if [[ "$landiscovery" == "enabled" ]]; then
ld="${EIColor}[LD]${Color_Off}"
landiscoveryc="${EColor}$landiscovery${Color_Off}"
else
ld="${DIColor}[LD]${Color_Off}"
landiscoveryc="${DColor}$landiscovery${Color_Off}"
fi
#
if [[ -n "${allowlist[*]}" ]]; then # not empty
al="${EIColor}[AL]${Color_Off}"
else
al="${DIColor}[AL]${Color_Off}"
fi
#
if [[ ${allfast[*]} =~ [Yy] ]]; then
fst="${FIColor}[F]${Color_Off}"
else
fst=""
fi
#
if (( "$usingssh" )); then
sshi="${DIColor}[${FIColor}SSH${DIColor}]${Color_Off}"
else
sshi=""
fi
#
if [[ "$connected" == "connected" ]] && [[ "$meshnet" == "enabled" ]] && [[ "$nordhost" != *"nordvpn.com"* ]]; then
meshrouting="1"
else
meshrouting=""
fi
#
if [[ "$connected" == "connected" ]] && [[ "$technology" == "openvpn" ]] && [[ "$server" == "$dediwhere" ]]; then
fav="${FVColor}(Dedicated-IP)${Color_Off}"
elif [[ "$connected" == "connected" ]] && [[ -f "$nordfavoritesfile" ]] && grep -q -i "$server" "$nordfavoritesfile"; then
fav="${FVColor}(Favorite)${Color_Off}"
elif [[ "$connected" == "connected" ]] && printf "%s\n" "${nordvirtual[@],,}" | grep -q -x -i "$(echo "${city,,}" | tr ' ' '_')"; then
fav="${FVColor}(Virtual)${Color_Off}"
else
fav=""
fi
}
function disconnect_vpn {
# $1 = "force" - force a disconnect
# $2 = "check_ks" - prompt to disable the killswitch
#
echo
if [[ "$disconnect" =~ ^[Yy]$ ]] || [[ "$1" == "force" ]]; then
set_vars
if [[ "$connected" == "connected" ]]; then
if [[ "$2" == "check_ks" ]] && [[ "$killswitch" == "enabled" ]]; then
echo -e "${WColor}** Reminder **${Color_Off}"
change_setting "killswitch" "back"
fi
echo -e "${WColor}** Disconnect **${Color_Off}"
echo
nordvpn disconnect; wait
echo
fi
fi
}
function ipinfo_curl {
echo -n "External IP: "
response=$( timeout 6 curl --silent "https://ipinfo.io/" )
#
extip=$(echo "$response" | jq -r '.ip | if . == null then empty else . end')
exthost=$(echo "$response" | jq -r '.hostname | if . == null then empty else . end')
extorg=$(echo "$response" | jq -r '.org | if . == null then empty else . end')
extcity=$(echo "$response" | jq -r '.city | if . == null then empty else . end')
extregion=$(echo "$response" | jq -r '.region | if . == null then empty else . end')
extcountry=$(echo "$response" | jq -r '.country | if . == null then empty else . end')
extlimit=$(echo "$response" | jq -r '.error.title | if . == null then empty else . end')
#
if [[ -n "$extip" ]]; then
echo -e "${IPColor}$extip $exthost${Color_Off}"
echo -e "${SVColor}$extorg ${CIColor}$extcity $extregion ${COColor}$extcountry${Color_Off}"
echo
elif [[ -n "$extlimit" ]]; then
echo -e "${WColor}$extlimit${Color_Off}"
echo
else
set_vars
echo -n "Request timed out"
if [[ "$connected" != "connected" ]] && [[ "$killswitch" == "enabled" ]]; then
echo -ne " - $ks"
fi
echo; echo
fi
}
function status {
reload_applet
echo
nordvpn settings
echo
nordvpn status
echo
if [[ "$exitlogo" =~ ^[Yy]$ ]]; then
clear -x
main_logo
else
set_vars
fi
if [[ "$connected" == "connected" ]]; then
if [[ "$exitkillswitch" =~ ^[Yy]$ ]] && [[ "$killswitch" == "disabled" ]]; then
echo -e "${FColor}(exitkillswitch) - Always enable the Kill Switch.${Color_Off}"
killswitch_enable
if [[ "$exitlogo" =~ ^[Yy]$ ]]; then
echo -e "${FColor}Updating the logo.${Color_Off}"
clear -x
main_logo
fi
fi
if [[ "$exitping" =~ ^[Yy]$ ]]; then
if [[ "$technology" == "openvpn" ]]; then
echo -ne "$technologydc - Ping the External IP"
if [[ ! "$exitip" =~ ^[Yy]$ ]]; then
echo -ne " (Set ${FColor}exitip=\"y\"${Color_Off} to enable)"
fi
echo
else
ping_host "$ipaddr" "stats" "$nordhost"
fi
echo
fi
if [[ "$exitload" =~ ^[Yy]$ ]]; then
server_load
fi
fi
if [[ "$exitip" =~ ^[Yy]$ ]]; then
ipinfo_curl
if [[ "$connected" == "connected" ]] && [[ "$exitping" =~ ^[Yy]$ ]] && [[ -n "$extip" ]]; then
if [[ "$technology" == "openvpn" ]] || (( "$meshrouting" )); then
# ping the external IP when using OpenVPN or Meshnet Routing
ping_host "$extip" "stats" "External IP"
echo
elif [[ "$server" == *"-"* ]] && [[ "$server" != *"onion"* ]] && [[ "$server" != *"napps"* ]]; then
# ping both hops of Double-VPN servers when using NordLynx
ping_host "$extip" "stats" "Double-VPN"
echo
fi
fi
fi
date
echo
}
function reload_applet {
# reload Cinnamon Desktop applets
#
if (( "$usingssh" )); then return; fi
if [[ "$exitappletb" =~ ^[Yy]$ ]]; then
# reload 'bash-sensors@pkkk'
dbus-send --session --dest=org.Cinnamon.LookingGlass --type=method_call /org/Cinnamon/LookingGlass org.Cinnamon.LookingGlass.ReloadExtension string:'bash-sensors@pkkk' string:'APPLET'
wait
fi
if [[ "$exitappletn" =~ ^[Yy]$ ]]; then
# reload 'network@cinnamon.org' (to remove extra 'nordlynx' entries)
dbus-send --session --dest=org.Cinnamon.LookingGlass --type=method_call /org/Cinnamon/LookingGlass org.Cinnamon.LookingGlass.ReloadExtension string:'network@cinnamon.org' string:'APPLET'
wait
fi
}
function ping_host {
# $1 = destination
# $2 = "stats" - display the stats only, with a label
# $2 = "show" - display the ping command first
# $3 = the label used with "stats"
#
if [[ "$2" == "stats" ]]; then
echo -ne "${LColor}($3) ${Color_Off}"
ping -c "$pingcount" -q "$1" | grep -A4 -i "statistics"
elif [[ "$2" == "show" ]]; then
echo -e "${LColor}ping -c $pingcount $1${Color_Off}"
echo
ping -c "$pingcount" "$1"
echo
else
ping -c "$pingcount" "$1"
fi
}
function disconnect_warning {
set_vars
if [[ "$connected" == "connected" ]]; then
echo -e "${WColor}** Changing this setting will disconnect the VPN **${Color_Off}"
echo
fi
}
function openlink {
# $1 = URL or link to open
# $2 = "ask" - ask first
# $3 = "exit" - exit after opening
#
if (( "$usingssh" )); then
echo
echo -e "$sshi ${FColor}The script is running over SSH${Color_Off}"
echo
fi
if [[ "$2" == "ask" ]] || (( "$usingssh" )); then
read -n 1 -r -p "$(echo -e "Open ${EColor}$1${Color_Off} ? (y/n) ")"; echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
return
fi
fi
if [[ "$1" =~ ^https?:// ]] && [[ "$newfirefox" =~ ^[Yy]$ ]] && ! (( "$usingssh" )); then
nohup "$(command -v firefox)" --new-window "$1" > /dev/null 2>&1 &
else
nohup xdg-open "$1" > /dev/null 2>&1 &
fi
if [[ "$3" == "exit" ]]; then
echo
exit
fi
# https://github.com/suan/local-open
}
function countdown_timer {
# Adds about 15s per hour but close enough.
# $1 = time in seconds
#
echo -e "Type ${LColor}R${Color_Off} to quit the timer and resume."
echo
echo "Countdown:"
for ((i="$1"; i>=0; i--))
do
days=$(( "$i" / 86400 ))
if (( days >= 1 )); then
echo -ne " $days days and $(date -u -d "@$i" +%H:%M:%S)\033[0K\r"
else
echo -ne " $(date -u -d "@$i" +%H:%M:%S)\033[0K\r"
fi
read -t 1 -n 1 -r -s countinput
if [[ "$countinput" =~ ^[Rr]$ ]]; then
echo -e " ${WColor}Quit${Color_Off}\033[0K\r"
break
fi
done
echo
}
function parent_menu {
# $1 = $1 or $2 (back) of the calling function - disable upmenu if a return is required
# "Main" "Country" "Settings" "Group" "Tools" "Nord API" "Meshnet" "Favorites" "All Servers" "Speed Test"
#
if [[ "$REPLY" == "$upmenu" ]]; then
if [[ "$1" == "back" ]]; then
echo
echo -e "${FColor}(upmenu) - N/A - The function needs to return.${Color_Off}"
echo
else
echo
echo -e "${FColor}(upmenu) - Return to the $parent menu.${Color_Off}"
case "$parent" in
"Main") main_menu;;
"Country") country_menu;;
"Settings") settings_menu;;
"Group") group_menu;;
"Tools") tools_menu;;
"Nord API") nordapi_menu;;
"Meshnet") meshnet_menu;;
"Favorites") favorites_menu;;
"All Servers") allservers_menu;;
"Speed Test") speedtest_menu;;
esac
fi
fi
}
function invalid_option {
# $1 = total menu items
# $2 = $parent - name of parent menu
#
echo
echo -e "${WColor}** Invalid option: $REPLY${Color_Off}"
echo
echo "Select any number from 1-$1, or enter $upmenu"
if [[ "$2" == "TopMenu" ]]; then
echo " $upmenu = Reload the Main menu"
echo " $1 = Exit the script"