0 comment

How to create OpenVPN config files for Witopia

I use a Dell laptop with Ubuntu 15.04 and the VPN NetworkManager seems to be sort of broken. So I guessed I just resort to plain old OpenVPN Config files. And since I’m a very lazy guy I wanted to have some sort of script generating all that stuff for me. First of all you need a prototype template for the config file. There is one that comes with the downloadable zip from Witopa and is called “SampleConfig.txt”. Copy that to “prototype.txt” and change the line



remote SERVERNAME 1194

Our script will later on replace the “SERVERNAME” with the actual Witopia VPN server names. In the directory where “prototype.txt” lives, create a subdirectory and put the crypto files from the Witopia zip in. These are: ca.crt, ta.key, USERNAME.crt, USERNAME.key. “USERNAME” will be your username (think you guessed that :)
Now create in the prototype directory a file called “” with the following content:


rm -f data/*.ovpn

serverlist=`curl -s | sed -e "s/<[^>]*>//g" | egrep "^vpn"`

for server in $serverlist;
  filename=data/`echo $server | cut -d . -f 2 - | sed 's/\([a-z]\)\([a-z]*\)/\U\1\L\2/g'`.ovpn;
  echo "Generating $filename";
  cat prototype.txt | sed "s/SERVERNAME/$server/g" > $filename

Line 3 cleans up the data directory for the files to come. Line 5 grabs the web page with the VPN server pages from, eliminates the HTML stuff via sed and greps lines starting with “vpn”. Then we loop through the server list and create an OpenVPN config file in data/ for each server, named “City.ovpn”. First we need to build the filename by grabbing the second field of the server name like “”. We cut the city name out and capitalize the first character. This is my personal preference, you can just leave it lower case if you like. Last part is replacing “SERVERNAME” with the actual server naame via sed and putting it in a file with the freshly created name. Thats it.

But if you are as lazy as me you also would like to have a start script which only needs the name of a city to connect you. Here we go:


city=`echo $1 | sed "s/\.ovpn//g" | tr '[:upper:]' '[:lower:]' | sed 's/\([a-z]\)\([a-z]*\)/\U\1\L\2/g'`

if [ -e "$filename" ]
  echo "Starting OpenVPN with $city"
  sudo openvpn --client --config $filename --ca ca.crt

This script called “” resides in the data/ directory takes one argument: the name of a city or of a *.ovpn config file. So valid start script calls are:

./ munich
./ Munich
./ munich.ovpn
./ Munich.ovpn
./ MUNICH.ovpn

As you can see line 3 of the script cuts out the city name, casts all characters to lower case and capitalizes the first character. Then we (re-)add the extension “.ovpn” in line 4 and if there is a config file with that name we start the openvpn client. We need to do that as root user so you problably will need to enter your root password when the openvpn is sudoed.

Thats it, folks. Happy networking :)

Leave a Reply

Required fields are marked *.