shervinsahba / polybar-vpn-controller

Polybar module for VPN control. Set up for Mullvad VPN but modifiable for others.
MIT License
62 stars 12 forks source link

NordVPN version #4

Open hartzan opened 4 years ago

hartzan commented 4 years ago

Hi,

here https://gist.github.com/hartzan/b85644cb30799c98a449814c234f6953 you can find my version for NordVPN. Geoip stuff is not needed, NordVPN status message contains IP,country and city. Unfortunately there is no 2-letter country code so it might happen that all letters are not visible? I guess it's not perfect but works for me :-)

shervinsahba commented 4 years ago

Cool. I'm glad that the bulk of the script worked for Nord. Thanks for sharing hartzan!

Now time to think of a good way to merge these additions :)

shervinsahba commented 4 years ago

Could you paste the output of nordvpn status when it is disconnected and again when it's connected?

hartzan commented 4 years ago

Here you are:

nordvpn status Status: Disconnected

nordvpn status Status: Connected Current server: fi126.nordvpn.com Country: Finland City: Helsinki Your new IP: 196.196.203.67 Current technology: NordLynx Transfer: 42.00 KiB received, 26.96 KiB sent Uptime: 9 seconds

jamc-code commented 4 years ago

I'm going to work on a small python program to:

  1. Take a country name as an argument
  2. Match and return it's county code with dictionaries

The script could then be called inside vpn_module.sh for quick conversion. If it would be easier or quicker in bash let me know!

shervinsahba commented 4 years ago

@sudo-julia Sounds good! Yeah, that'd be clean. Seems like that would clean up about half the differences in code between Mullvad and Nord and set the script up for future services.

We have these basic utility differences, shown below, which I was thinking may be best kept in a setup file the user could run to swap out relevant pieces with sed commands. I imagine most users would be able to code them in manually, but it'd be nice to swap via a script. Do you think that makes sense?

## [Set VPN commands]. 

#MULLVAD
VPN_CONNECT="mullvad connect"
VPN_DISCONNECT="mullvad disconnect"
VPN_GET_STATUS="mullvad status"
VPN_SET_LOCATION="mullvad relay set location"

#NORD
VPN_CONNECT="nordvpn c"               # could use connect instead of c
VPN_DISCONNECT="nordvpn d"         # could use disconnect
VPN_GET_STATUS="nordvpn status"
VPN_SET_LOCATION="nordvpn c"      # this is the main one that differs

## [Set VPN status parsing]

#MULLVAD
VPN_STATUS="$($VPN_GET_STATUS | cut -d' ' -f3)" 
CONNECTED=Connected
CONNECTING=Connecting

#NORD
VPN_STATUS="$($VPN_GET_STATUS | sed -n 1p | cut -c 21-29)"  # could use cut -d' ' -f2. In either case, this differs.
CONNECTED=Connected
CONNECTING=                         # I'm unsure if Nord has a Connecting state

And then there is the regional information, which if I understand, your suggestion should let us manage much more efficiently.

#MULLVAD
COUNTRIES=("Albania (al)" "Australia (au)" "Austria (at)" "Belgium (be)" "Brazil (br)" "Bulgaria (bg)" "Canada (ca)" "Czech Republic (cz)" "Denmark (dk)" "Finland (fi)" "France (fr)" "Germany (de)" "Greece (gr)" "Hong Kong (hk)" "Hungary (hu)" "Ireland (ie)" "Israel (il)" "Italy (it)" "Japan (jp)" "Latvia (lv)" "Luxembourg (lu)" "Moldova (md)" "Netherlands (nl)" "New Zealand (nz)" "Norway (no)" "Poland (pl)" "Romania (ro)" "Serbia (rs)" "Singapore (sg)" "Spain (es)" "Sweden (se)" "Switzerland (ch)" "UK (gb)" "United Arab Emirates (ae)" "USA (us)")
COUNTRY_CODES=("al" "au" "at" "be" "br" "bg" "ca" "cz" "dk" "fi" "fr" "de" "gr" "hk" "hu" "ie" "il" "it" "jp" "lv" "lu" "md" "nl" "nz" "no" "pl" "ro" "rs" "sg" "es" "se" "ch" "gb" "ae" "us")

#NORD
COUNTRIES=("Albania" "Argentina" "Australia" "Austria" "Belgium" "Bosnia" "Brazil" "Bulgaria" "Canada" "Chile" "Costa Rica" "Croatia" "Cyprus" "Czech Republic" "Denmark" "Estonia" "Finland" "France" "Georgia" "Germany" "Greece" "Hong Kong" "Hungary" "Iceland" "India" "Indonesia" "Ireland" "Israel" "Italy" "Japan" "Latvia" "Luxembourg" "Macedonia" "Malaysia" "Mexico" "Moldova" "Netherlands" "New Zealand" "Norway" "Poland" "Portugal" "Romania" "Serbia" "Singapore" "Slovakia" "Slovenia" "South Africa" "South Korea" "Spain" "Sweden" "Switzerland" "Taiwan" "Thailand" "Turkey" "Ukraine" "United Arab Emirates" "United Kingdom" "United States" "Vietnam")

## Concatenate favorite and country arrays

#MULLVAD
VPN_CODES=("${VPN_LOCATIONS[@]}")
VPN_CODES+=("${COUNTRY_CODES[@]}")
VPN_LOCATIONS+=("${COUNTRIES[@]}")

#NORD
VPN_LOCATIONS+=("${COUNTRIES[@]}")
VPN_CODES=("${VPN_LOCATIONS[@]}")

Thanks!

jamc-code commented 4 years ago

Hey! Being able to swap variables with a script sounds like a really good idea. I think it's great to have options that are able to be configured without having to open the main script, which could be daunting for newer users even though the way you laid it out is super accessible.

If you check my fork the python script is up and running, I just got lost at where to integrate it in vpn_module.sh once I completed it (lmao). As of now, it takes a country name by arg, which is found with awk filtering a vpn status command (for portability), and returns the associated country code. Let me know exactly how that should be placed in the main script. I also might update it real quick to also return country name if country code is given but I'm not 100% sure if that would be useful. Let me know what you think and where it can be improved! Have a good one.