User Tools

Site Tools

This documentation is no longer maintained by the Turris team (although it can be used by the community to share content). The current official documentation is at docs.turris.cz.

OpenVPN - client connect / disconnect notification

In this updated tutorial, which is a result of a discussion in the Turris Forum , we use the function create_notification, which sends the message according to the settings in the administration Foris, section Maintenance

Tutorial assumes, you have installed OpenVPN

1) in file /etc/config/openvpn add following lines:

If you are using Foris openVPN plugin, add it to the section config openvpn 'server_turris

option script_security '2'
option client_connect '/etc/openvpn/up.sh'
option client_disconnect '/etc/openvpn/down.sh'

2) create file /etc/openvpn/up.sh

up.sh
#!/bin/bash
message="$(echo -e "${common_name} connected      to: ${HOSTNAME} \\nRemote:  ${untrusted_ip} \\nVirtual: ${ifconfig_pool_remote_ip}")"
/usr/bin/create_notification -s news "${message}"
/usr/bin/notifier
exit 0

3) create file /etc/openvpn/down.sh

down.sh
#!/bin/bash
message="$(echo -e "${common_name} disconnected from: ${HOSTNAME} \\nRemote:  ${untrusted_ip} \\nVirtual: ${ifconfig_pool_remote_ip}")"
/usr/bin/create_notification -s news "${message}"
/usr/bin/notifier
exit 0

4) set permission 0755 for scripts

chmod 0755 /etc/openvpn/up.sh

chmod 0755 /etc/openvpn/down.sh

5) make sure files are backed-up

If you want to include these extra scripts in the backups of the router, add /etc/openvpn directory to the /etc/config/backups. Something like:

  config generate generate
       list dirs "/etc/openvpn"

6) restart OpenVPN

/etc/init.d/openvpn restart