This script is intended to be used with Open VPN as the client-connect
and client-disconnect
scripts, to send an email using Mailgun to a certain address when a client connects or disconnects.
To install this, copy the below file to /etc/openvpn/statuschange.sh
, replace the to
email with your own, the and the from
email, the URL, and the API key with your own Mailgun login. (I use the sandbox because I didn't feel like messing with DNS.)
Then, add the following to /etc/openvpn/server.conf
:
client-connect /etc/openvpn/statuschange.sh
client-disconnect /etc/openvpn/statuschange.sh
script-security 2
The first two lines should be self-explanatory; the third allows Open VPN to call "user-defined scripts," which is technically somewhat unsafe.
Finally, tell the Open VPN daemon to reload its configuration: sudo service openvpn reload
(or comparable). Try connecting and disconnecting to the VPN; it should send an email on both events.