OpenVPN connected-disconnected users log



  • 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



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



  • 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



  • let me know how do you twek the script



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



  • 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.



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



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



  • @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!


Log in to reply