How can I record in a log when users connect and disconnect, and rotate the log every 24 hours.

How to customize and extend your OpenVPN installation.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Post Reply
xivexell
OpenVpn Newbie
Posts: 1
Joined: Mon Jan 17, 2022 5:39 pm

How can I record in a log when users connect and disconnect, and rotate the log every 24 hours.

Post by xivexell » Mon Jan 17, 2022 6:44 pm

I want to monitor when a user connects or disconnects to my VPN, I tried to use --up and --client-connect, but it doesn´t work, Could someone help me, please? I'm already stuck for 2 weeks

my server.conf
server
1
management localhost 5555
2
proto udp
3
dev tun
4
ca ca.crt
5
cert server.crt
6
key server.key
7
dh none
8
server 10.8.0.0 255.255.255.0
9
ifconfig-pool-persist /var/log/openvpn/ipp.txt
10
push "route 213.169.0.0 255.255.248.0"
11
push "route 192.168.112.0 255.255.255.0"
12
push "dhcp-option DNS 213.169.1.105"
13
keepalive 10 120
14
tls-crypt ta.key
15
cipher AES-256-GCM
16
auth SHA256
17
user nobody
18
group nogroup
19
persist-key
20
persist-tun
21
status /var/log/openvpn/openvpn-status.log
22
script-security 3
23
up /etc/openvpn/scripts/clientconnect.sh
24
log-append /var/log/openvpn/openvpn.log
25
verb 4
26
explicit-exit-notify 1


my oepnvpn-server@.service
server
1
[Unit]
2
Description=OpenVPN service for %I
3
After=network-online.target
4
Wants=network-online.target
5
Documentation=man:openvpn(8)
6
Documentation=https://community.openvpn.net/openvpn/w ... n24ManPage
7
Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO
8
[Service]
9
Type=notify
10
PrivateTmp=false
11
WorkingDirectory=/etc/openvpn/server
12
ExecStart=/usr/sbin/openvpn --script-security 3 --up /etc/openvpn/scripts/clientconnect.sh --status %t/openvpn-server/status-%i.log --status-version 2 --config %i.conf
13
CapabilityBoundingSet=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_OVERRIDE CAP_AUDIT_WRITE
14
LimitNPROC=10
15
DeviceAllow=/dev/null rw
16
DeviceAllow=/dev/net/tun rw
17
KillMode=process
18
RestartSec=5s
19
Restart=on-failure
20
[Install]
21
WantedBy=multi-user.target


my script clientconnect.sh
server
1
NOW=`(date '+%H:%M:%S - %d-%m-%Y')`
2
echo $NOW, $common_name $trusted_ip, $trusted_port >> /var/log/openvpn/usuarios.txt
3
exit 0

my usuarios.txt only has this:
server
1
12:29:41 - 17-01-2022, ,
2
12:33:25 - 17-01-2022, ,
3
13:52:20 - 17-01-2022, ,
4
13:53:05 - 17-01-2022, ,
5
13:54:57 - 17-01-2022, ,
6
13:55:23 - 17-01-2022, ,
7
13:55:23 - 17-01-2022, ,
8
13:58:18 - 17-01-2022, ,
9
14:03:08 - 17-01-2022, ,
10
14:04:58 - 17-01-2022, ,
11
14:32:43 - 17-01-2022, ,

TinCanTech
OpenVPN Protagonist
Posts: 11139
Joined: Fri Jun 03, 2016 1:17 pm

Re: How can I record in a log when users connect and disconnect, and rotate the log every 24 hours.

Post by TinCanTech » Mon Jan 17, 2022 8:10 pm

xivexell wrote:
Mon Jan 17, 2022 6:44 pm
I want to monitor when a user connects or disconnects to my VPN
Try this: https://github.com/TinCanTech/easy-tls

and rotate the log every 24 hours.

Remove this:

Code: Select all

log-append /var/log/openvpn/openvpn.log
Let systemd take care of it.

Post Reply