NordVPN add all ovpn servers to nmcli and {gnome || kde}


This is simple script for import many ovpn config together with a password to nmcli . In current 0.1 version import  only NordVpn.com configs  .
How it`s work.

Script finding  all ovpn files in directory and result assign to variable “a”

a=$(ls *.ovpn)
if [[ `echo $a | wc | awk '{print $2}'` -eq 0 ]]; then
 echo "Ovpn filne in $PWD do not found "
 exit 1
fi

While iterating variable a line by line

printf '%s\n' "$a" | while IFS= read -r line
do
...
done

Prepare short name is it more readable  in gnome

conname=$(echo $line | awk  -F "." '{print $1"-"$4}')

import first file to nmcli  and grab uuid by awk

uuidcon=$(nmcli connection import type openvpn  file  $line |  awk 'match($0,  /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/) {print substr($0, RSTART, RLENGTH)}')

modify name and add username , password to new connection

  nmcli con mod uuid $uuidcon connection.id $conname +vpn.data "username=$USERNAMEFORVPN" vpn.secrets password="$PASSWFORVPN"

Required

I tested script at fedora 25 and NetworkManager.x86_64  v  1:1.4.4-3.fc25,  awk

NetworkManager.x86_64                                    1:1.4.4-3.fc25
NetworkManager-openvpn.x86_64                 1:1.2.8-1.fc25
NetworkManager-openvpn-gnome.x86_64 1:1.2.8-1.fc25

Example usage

Important username and password must be in quotes.


 ./importnordvpn -u "myemail@examplemail.com" -p "P44SSwoRd"
 #or
 ./importnordvpn -u "myemail@examplemail.com" -p "P44SSwoRd" -d Download/configs/
# get configs from Nordvpn webside [-g]
 ./importnordvpn -u "myemail@examplemail.com" -p "P44SSwoRd" -g</pre>
# if you want clean configuration
./importnordvpn -c
# clean configuration and load new
./importnordvpn -c -u "myemail@examplemail.com" -p "P44SSwoRd" -d Download/configs/</pre>
# clean configuration and load new from network
./importnordvpn -c -u "myemail@examplemail.com" -p "P44SSwoRd" -g

Script

Look for new version on github :

https://github.com/dzaczek/blogscripts/blob/master/importnordvpn.sh

Example effect:

Thousand  servers imported ready for use

nordvpn-gnome

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s