openvpn --client-connect example script

Good day all

I require a --client-connecting script and --client-disconnect script.

My issue: is that I am unable to find an example anywhere, I have been searching for the past 4 hours.

I have only come across this from the OpenVPN archive back in 2006 and a couple of requests for examples, but no recent example has been found.

Going through the doc pages and looking at the options and evironment variables, I feel lost.

If anyone is willing to share/impart their knowledge through an intuituve example, I would very much apppreciate it.


Solution 1:

Actually on server side inside the configuration file you can use:

# server vpn interface is up
up "/script/server_up.sh"

# server vpn interface is going down
down "/script/server_down.sh"

# client connected to VPN server
client-connect "/script/client_connect.sh"

# client disconnected from VPN server
client-disconnect "/script/client_disconnect.sh"

On client side you will use:

# Client connected to VPN server
up "/script/connected.sh"

# Client disconnected from VPN server
down "/script/disconnected.sh"

OpenVPN will pass a lot of environmental variables to your shell script that you can use for whatever you want.