Note: I can not be completely sure if this will work to keep you 100% safe since testing it is beyond the scope of my current knowledge base and abilities.
I wrote a bash script to check the VPN status and do stuff if the connection is lost. Please feel free to edit this script and use it to your advantage. This script was written and tested on Ubuntu 11.04, but should work on other versions of Ubuntu.
The script does the following 3 steps:
(script link at bottom of this post)
1.) Starts up a VPN and checks if it is active,
You will need to change the UUID listed on line 15 to match the UUID of your VPN connection. To obtain your VPN connections UUID, manually connect your VPN, make sure its connected, then enter the following on a command line:2.) If the VPN connection is active it start a program of the users choice
nmcli -p con status
The long string of numbers and digits under the title UUID and next to your VPN connection name is the UUID of your VPN connection. Use this number to replace the one on line 15 of the script.
(You choose a program by replacing line 21 where it states:3.) Continuously checks the VPN state. If the connection is broken then it pauses the program chosen by the user in step 2 above, reconnects the VPN, then restarts the program chosen by the user in step 2 above, if the VPN connection is not broken then it just keeps checking the status of the VPN connection.
with a program of your choice such as
or whatever program you want the script to run. Note the "&" symbol is necessary for the script to keep running after starting your program)
To run the script:
After you name and save it to a location of your choice (see: final note of this post below), you must:
1.) Make it executable by right clicking on the script file and selecting "properties" -> "permissions" -> then place a check mark in the check-box labelled "Execute [x] Allow executing file as program", then close the properties window.
2.) At this point you can optionally create a launcher icon for it from the main menu by:
2.a) selecting "system" -> "preferences" -> "main menu".
2.b) From here, select "Internet" from the list of Menus in the left hand pain.
2.c) Then select "new item" on the upper right, and fill in the following:
Type: Application in Terminal3.) Optionally you can select an icon for the launcher by clicking on the icon. (either create one, choose one from some source, or download one)
Name: VPN and application monitor
Command: the name of the file and location where you saved the script
(Example: in my case the command is "~/Archives/OS.Scripts.Bash/vpn1.sh")
4.) Then close this window, and go to the main menu -> "internet" -> "VPN and application monitor" to start the script.
5.) Alternatively you could just run it from the command line, but I like having the icon to click on.
To shut down the script, you'll have to do the following in this order:
1.) Manually shut down the application you chose to run (See: the note for Step 2. in the section above titled "I wrote a bash script that does the following:")
2.) Then use CTRL+C to exit the script in the terminal window.
3.) Then manually disconnect your VPN.
Notes: The script waits 5 seconds after the connection is established before it starts the application chosen by the user, there is another 5 second delay between connection attempts so the script isn't blasting the VPN with connection requests. So please be patient if you choose to use this script.
There are also a few other programs and things you can do to make your VPN a little more secure depending on how paranoid you are. You can read about them here:
Script Link (See the last post on this thread):
Note: Just copy the contents of the code window and save it to a file called "vpn.sh" or whatever you want to call it noting that the extension ".sh" is important for the OS to recognise this file as a bash script.
I hope this was helpful and if not, then at least somewhat informative.