Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    • Register
    • Login
    Introducing Netgate Nexus: Multi-Instance Management at Your Fingertips.

    OpenVPN connected-disconnected users log

    Scheduled Pinned Locked Moved General pfSense Questions
    9 Posts 3 Posters 3.1k Views 2 Watching
    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.
    • S
      sonico87
      last edited by

      Hi everyone:

      We  have a roadwarrior openvpn service in our company. I need to report how long time the users are connected to the vpn. The hour of users connected and the hour the users disconnected. I have a rsyslog in other server, so I can read the openvpn log daily, and I cleaned the "trash info" with an excel macro and extract the info that I need, but how can I get a report of the connect-disconnect hours of the users in automatic mode like this?

      User        Connect    Disconnect
      ALONSO  08:00        10:45
      ALONSO  12:33        18:42
      MARIA      20:11        23:09

      Do you have any idea?

      I hope you can help me.

      Regards

      1 Reply Last reply
      Reply Quote 0
      • M
        mfbart
        last edited by

        Hallo, someone have solved your question? I've the same needed

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

          done but with email ...

          #!/usr/local/bin/php -q
          <?php
          	require_once("/etc/inc/notices.inc");
          	$local_connect_value = " \n user_name: " . getenv('common_name') . " \n vpn_client_ip: " . getenv('ifconfig_pool_remote_ip') ." connected from " . getenv('trusted_ip') . " on " . date('F j, Y, g:i a');
          	if ( strrchr (__FILE__ , 'disconnect') ) {
          	$local_connect_value .= ", \n duration : " . round(((getenv('time_duration'))/3600),2) . "  hours, or " . round(((getenv('time_duration'))/60),2) . "  minutes, or " . getenv('time_duration') . "  seconds,\n upload from vpn-client (received) : " . round(((getenv('bytes_received'))/1048576),2) . " MB, \n download to vpn-client (send) : " . round(((getenv('bytes_sent'))/1048576),2) ." MB. \n DISCONNECTED.";
          	}
          	notify_all_remote($local_connect_value);
          ?>
          

          the script is called in openVPN server
          31811e2a-0a24-4db3-a156-363932eeac30-grafik.png

          output
          c91d2ac8-e261-45ad-8bd2-c9bf34d82754-grafik.png

          see also here
          https://forum.netgate.com/topic/151351/email-notification-openvpn-client-connect-common-name/26

          noplanN M 2 Replies Last reply
          Reply Quote 0
          • noplanN
            noplan @noplan
            last edited by

            let me know how do you twek the script

            1 Reply Last reply
            Reply Quote 0
            • M
              mfbart
              last edited by

              tks for reply! I will try and then I will post comment.

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

                workin here like a charm ..
                only problem i get mails for every client even for the trusted ones
                so a tweak if ip (stored in txt file) is trusted do not send mail else send would be fine.

                1 Reply Last reply
                Reply Quote 0
                • M
                  mfbart
                  last edited by

                  OK, your script run very good!
                  thank you for all.

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

                    @mfbart
                    do not forgett to upvote 8181a894-5e27-4048-9431-688445130bd6-grafik.png

                    1 Reply Last reply
                    Reply Quote 0
                    • M
                      mfbart @noplan
                      last edited by

                      @noplan said in OpenVPN connected-disconnected users log:

                      done but with email ...

                      #!/usr/local/bin/php -q
                      <?php
                      	require_once("/etc/inc/notices.inc");
                      	$local_connect_value = " \n user_name: " . getenv('common_name') . " \n vpn_client_ip: " . getenv('ifconfig_pool_remote_ip') ." connected from " . getenv('trusted_ip') . " on " . date('F j, Y, g:i a');
                      	if ( strrchr (__FILE__ , 'disconnect') ) {
                      	$local_connect_value .= ", \n duration : " . round(((getenv('time_duration'))/3600),2) . "  hours, or " . round(((getenv('time_duration'))/60),2) . "  minutes, or " . getenv('time_duration') . "  seconds,\n upload from vpn-client (received) : " . round(((getenv('bytes_received'))/1048576),2) . " MB, \n download to vpn-client (send) : " . round(((getenv('bytes_sent'))/1048576),2) ." MB. \n DISCONNECTED.";
                      	}
                      	notify_all_remote($local_connect_value);
                      ?>
                      

                      the script is called in openVPN server
                      31811e2a-0a24-4db3-a156-363932eeac30-grafik.png

                      output
                      c91d2ac8-e261-45ad-8bd2-c9bf34d82754-grafik.png

                      see also here
                      https://forum.netgate.com/topic/151351/email-notification-openvpn-client-connect-common-name/26

                      very good works!

                      1 Reply Last reply
                      Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • First post
                        Last post
                      Copyright 2026 Rubicon Communications LLC (Netgate). All rights reserved.
                      Privacy Policy · Cookie Policy