Each time a client (dis)connects to the OpenVPN server of pfSense a new Telegram notification will be sent.
Under "VPN" > "Servers" > your server > "Advanced Configuration" > "Custom Options" add the following lines.
client-connect /root/openvpn-telegram.sh
client-disconnect /root/openvpn-telegram.sh
script-security 2
Shell script to be created on the pfSense box. Access via SSH to the box and type nano /root/openvpn-telegram.sh
Remember changing the <TOKEN>
and the <CHAT_ID>
variables with your own values.
#!/bin/sh
MYDATE=$(/bin/date +'%Y/%m/%d %H:%M:%S')
if [ "$script_type" = "client-connect" ]; then
/usr/local/bin/curl -s -k "https://api.telegram.org/bot<TOKEN>/sendMessage" -d text="$MYDATE - VPN connection established. Username $common_name with external IP address $trusted_ip obtains internal IP address $ifconfig_pool_remote_ip." -d chat_id=<CHAT_ID>
elif [ "$script_type" = "client-disconnect" ]; then
/usr/local/bin/curl -s -k "https://api.telegram.org/bot<TOKEN>/sendMessage" -d text="$MYDATE - VPN connection terminated. Username $common_name with external IP address $trusted_ip frees internal IP address $ifconfig_pool_remote_ip." -d chat_id=<CHAT_ID>
fi
exit 0
It's workin in the 2.6.0 version?
Because the error is generate in the log OpenVPN: WARNING: Failed running command (--client-connect): could not execute external program