Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    OpenVPN Connection Email Notifications

    Scheduled Pinned Locked Moved OpenVPN
    6 Posts 4 Posters 6.4k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      clifford64
      last edited by

      Hello

      I have very little experience with php and packages in pfsense. In the past, I have used OpenVPN on an ubuntu host and ssmtp to send email notifications on connect and disconnect. I have seen a couple of posts about this sort of thing, but when trying to run the email commands manually, nothing comes through. I currently have the normal smtp settings setup and working within the pfsense notifications settings. Can anyone provide in depth instructions on what I need to configure and where to get email notifications on connect and disconnect?

      Thanks.

      1 Reply Last reply Reply Quote 0
      • GertjanG
        Gertjan
        last edited by

        Hi !

        Experience isn't an issue here.
        I have close to none, and worked something out in a couple of minutes.

        Google will bring you very quickly to something like this : https://askubuntu.com/questions/28733/how-do-i-run-a-script-after-openvpn-has-connected-successfully - see the last reply.
        It's states :

        # nano /etc/openvpn/server.conf
        .... 
        script-security 2
        client-connect /etc/openvpn/up.sh
        ....
        

        ( I have to admit that I have a copy of the OpenVPN server 'manual' - you can't use OpenVPN without it anyway - and it was mentioned in there ).

        For pfSense, this would be :

        90d54e60-76af-4177-8796-ff4ca9fc1fe3-image.png

        Now, all you need is this notify.sh file.

        I needed to figure out how a mail is send from pfSense.
        That was far more easy as one might think.
        All is here : /etc/inc/notify.inc

        I wrote this file :

        #!/usr/local/bin/php -q
        <?php
        
                require_once("/etc/inc/notices.inc");
                notify_all_remote("VPN Connected");
        ?>
        

        I put it in /root/ called it notify.sh and gave it exe rights.

        chmod +x /root/notify.sh
        

        I connected to my pfSense OpenVPN .... and received a mail.

        Before you ask : yes, I guess it's possible to know what IP, what user etc is connecting. This means : diving into the OpenVPN manual again, etc.

        No "help me" PM's please. Use the forum, the community will thank you.
        Edit : and where are the logs ??

        C 1 Reply Last reply Reply Quote 2
        • C
          clifford64
          last edited by clifford64

          I was able to get it working from your instructions. Thank you.

          1 Reply Last reply Reply Quote 0
          • C
            cofee @Gertjan
            last edited by

            @Gertjan

            Hi,

            What you wrote, is a nice example. The principle of using the built-in notify is great. General messaging, with fixed content, works fine. But I can't put variables in the message. Please tell me how I can insert the values of $ {common_name} or ${untrusted_ip} into the message.

            Thanks

            1 Reply Last reply Reply Quote 0
            • noplanN
              noplan
              last edited by

              in other words the way it was written down here

              Link to post on this forum

              C 1 Reply Last reply Reply Quote 0
              • C
                cofee @noplan
                last edited by

                @noplan

                This link is very helpful, thank you!

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.