Email notification if have connection OpenVPN



  • Hello,
    Is it  possible the pfSense OpenVPN server sent me email on every connection? Is pfSense able to send mail on every OpenVPN successful connection ?


  • Rebel Alliance Developer Netgate

    There is not currently a hook for e-mail notification there. It could be added without too much effort, at least a manual hacky way. A proper setup with a GUI option and so on would be a bit more complex.

    Have a look at the OpenVPN auth script in /var/etc/



  • Can i have example?

    [2.2.4-RELEASE][admin@pfsense]/root: ls /var/etc/
    apinger.conf                inetd.conf                  openvpn                     resolv.conf
    cert.pem                    l2tp-vpn                    openvpn-csc                 resolvconf.conf
    filterdns.conf              lighty-webConfigurator.conf radvd.conf                  squid.passwd
    hosts                       ntpd.conf                   relayd.conf                 syslog.conf
    
    

  • Rebel Alliance Developer Netgate

    I forgot things got shifted around, it's now at /etc/inc/openvpn.auth-user.php



  • Hi,
    I don't know if you already find it, but it was my same request.
    To do that I just modify the connect and disconnect script on openvpn on pfsense 2.2.4

    /usr/local/sbin/openvpn.attributes.sh

    and add the line on connect and disconnect:

    /bin/echo "Connexion de ${common_name} date" | /usr/local/bin/php /usr/local/bin/mail.php -s"Connexion de ${common_name} date"

    Best regards,



  • Just to let you all know that if sending email fail ( because can't deliver email - mail server offline… ) the vpn connection will fail ( after established ) and clients will not be able to connect ever... I had to debug this problem today...



  • @s_moffa@securex.ch:

    Hi,
    I don't know if you already find it, but it was my same request.
    To do that I just modify the connect and disconnect script on openvpn on pfsense 2.2.4

    /usr/local/sbin/openvpn.attributes.sh

    and add the line on connect and disconnect:

    /bin/echo "Connexion de ${common_name} date" | /usr/local/bin/php /usr/local/bin/mail.php -s"Connexion de ${common_name} date"

    Best regards,

    Hello again.
    Now my version is 2.4.2-RELEASE (amd64) FreeBSD 11.1-RELEASE-p4
    and my /usr/local/sbin/openvpn.attributes.sh has

    
    #!/bin/sh
    #
    # openvpn.attributes.sh
    #
    # part of pfSense (https://www.pfsense.org)
    # Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
    # All rights reserved.
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    # http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    
    if [ "$script_type" = "client-connect" ]; then
            if [ -f /tmp/$common_name ]; then
                    /bin/cat /tmp/$common_name > $1
                    /bin/rm /tmp/$common_name
            fi
    elif [ "$script_type" = "client-disconnect" ]; then
            command="/sbin/pfctl -a 'openvpn/$common_name' -F rules"
            eval $command
            /sbin/pfctl -k $ifconfig_pool_remote_ip
            /sbin/pfctl -K $ifconfig_pool_remote_ip
    /usr/local/sbin/openvpn.attributes.sh
    fi
    
    exit 0
    
    

    how it should be done?


Log in to reply