@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
[image: 1586988274205-31811e2a-0a24-4db3-a156-363932eeac30-grafik.png]
output
[image: 1586988379170-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!