#server.conf
log /etc/openvpn/openvpn.log
log-append /etc/openvpn/openvpn.log
client-connect ./connect.sh
client-disconnect ./disconnect.sh
##
chmod 755 connect.sh
chmod 755 disconnect.sh
##connect.sh
#!/bin/sh
DB='openvpn'
DBADMIN='root'
PASSWD='xxxxxxx'
#!/bin/sh
DB='openvpn'
DBADMIN='root'
PASSWD='123456'
mysql -uDBADMIN−pPASSWD -e "INSERT into log (start_time,trusted_ip,trusted_port,protocol,remote_ip,remote_netmask,username)values(now(),'trustedip′,trusted_port,'proto′,′ifconfig_pool_remote_ip','ifconfigpoolnetmask′,′common_name')" $DB
##disconnect.sh
#!/bin/sh
DB='openvpn'
DBADMIN='root'
PASSWD='xmrbi3967968@'
mysql -uDBADMIN−pPASSWD -e "UPDATE openvpn.log SET end_time=now(),bytes_received=bytesreceived,bytessent=bytes_sent WHERE trusted_ip='trustedip′andtrustedport=trusted_port and remote_ip='ifconfigpoolremoteip′andremotenetmask=′ifconfig_pool_netmask' and username='commonname′"DB
##openvpn.log表
| username | varchar(32) | NO | MUL | NULL
| start_time | timestamp | NO | MUL | CURRENT_TIMESTAMP
| end_time | timestamp | NO | MUL | 0000-00-00 00:00:00
| trusted_ip | varchar(64) | YES | | NULL
| trusted_port | int(10) | YES | | NULL
| protocol | varchar(16) | YES | | NULL
| remote_ip | varchar(64) | YES | | NULL
| remote_netmask | varchar(64) | YES | | NULL
| bytes_received | bigint(20) | YES | | 0
| bytes_sent | bigint(20) | YES | | 0
| status | int(10) | NO | | 1