Page 1 of 1

Disconnect/Connect script date time always the same - bug

Posted: Tue Feb 18, 2020 5:19 pm
by hmota
Hey guys.

I got a nice openvpn server configuration and today I was looking into logs and I just saw the Client Connect Date Time (ex: 15:00:02) its the same as the Client Disconnect Date Time (ex: 15:00:02).

This is bug and I can't figure out how to solve this.

Server.conf

Code: Select all

port 443
proto tcp
dev tun
user nobody
group nogroup
persist-key
persist-tun
keepalive 10 120
topology subnet
management localhost 5555
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
#push "dhcp-option DNS 168.63.129.16"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
push "redirect-gateway def1 bypass-dhcp"
dh none
script-security 2
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf
ecdh-curve prime256v1
tls-crypt tls-crypt.key 0
crl-verify crl.pem
ca ca.crt
cert SERVER_XXX.crt
key SERVER_XXX.key
auth SHA256
cipher AES-128-GCM
ncp-ciphers AES-128-GCM
tls-server
tls-version-min 1.2
tls-cipher TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256
client-connect /etc/openvpn/scripts/connect.sh
client-disconnect /etc/openvpn/scripts/disconnect.sh
status /var/log/openvpn/status.log
verb 3
Connect.sh

Code: Select all

#!/bin/sh

bytesReceived=$bytes_received
bytesSent=$bytes_sent
user=$common_name
duration=$time_duration
realIp=$trusted_ip
loginDate=$time_ascii
ipVpn=$ifconfig_pool_remote_ip

mysql -u swk -p'PASSWORD' -e "use DATABASE; INSERT INTO logsAuth (userIp, userPublicIp, userName, loginDate) VALUES ('$ipVpn', '$realIp', '$user', '$loginDate'); UPDATE users SET userIp = '$ipVpn', verified = '1' WHERE userName = '$user' ORDER BY ID DESC LIMIT 1;"
Disconnect.sh

Code: Select all

#!/bin/sh

bytesReceived=$bytes_received
bytesSent=$bytes_sent
duration=$time_duration
logoutDate=$time_ascii
user=$common_name

mysql -u swk -p'PASSWORD' -e "use DATABASE; UPDATE logsAuth SET logoutDate = '$logoutDate', durationTime = '$duration', bytesSent = '$bytesSent', bytesReceived = '$bytesReceived' WHERE userName = '$user' ORDER BY ID DESC LIMIT 1;"

The duration time of a client session is right and working well. But the logout date its always the same as the login date, but how?

Mysql row log of client connect/disconnect

Code: Select all

ID      userIp       userPublicIp      userName  loginDate                  LogoutDate                 Duration Time  bytesSent Bytes Received
6	10.8.0.2	83.240.X.X	admin	Tue Feb 18 16:56:57 2020	Tue Feb 18 16:56:57 2020	37	19629	16777
As you can see the date is always the same! I changed the logoutDate=$time_ascii to a random string like "test" and it will be always test so I think the connect script its not overwritting nothing.

How can I solve this?

Thanks in advance,
Henrique

Re: Disconnect/Connect script date time always the same - bug

Posted: Tue Feb 18, 2020 5:52 pm
by d2t93y7c
The code that determines $time_ascii is not known to us. Whatever that code is (some script?), it probably needs to be re-run again before Disconnect.sh is executed. Or rather, this unknown script probably needs to be integrated into your Connect.sh and Disconnect.sh scripts. Then in your *.sh scripts set a local variable like so "local time_ascii" etc. Or you can ask the people on stackexchange.

Re: Disconnect/Connect script date time always the same - bug

Posted: Tue Feb 18, 2020 5:59 pm
by hmota
The time_ascii is a env variable that OpenVpn recommend to use on scripts disconnect/connect. It was working perfectly but stopped working and I don't know why..

Re: Disconnect/Connect script date time always the same - bug

Posted: Tue Feb 18, 2020 6:06 pm
by Pippin
Did you update OpenVPN and it stopped working?

Re: Disconnect/Connect script date time always the same - bug

Posted: Tue Feb 18, 2020 6:08 pm
by hmota
OpenVpn is working well!
I don't know why that env variable is bugged but I just figured out.
Just added this

Code: Select all

date=$(date '+%Y-%m-%d %H:%M:%S')
But the time_ascii and time_unix its bugged.. atleast I got another way to fix it :)

Re: Disconnect/Connect script date time always the same - bug

Posted: Tue Feb 18, 2020 6:19 pm
by Pippin
hmota wrote:
Tue Feb 18, 2020 5:59 pm
It was working perfectly but stopped working and I don't know why..
That's why I asked if you updated OpenVPN.....
Something changed if it was working perfectly...

Re: Disconnect/Connect script date time always the same - bug

Posted: Wed Feb 19, 2020 9:14 am
by hmota
Pippin wrote:
Tue Feb 18, 2020 6:19 pm
hmota wrote:
Tue Feb 18, 2020 5:59 pm
It was working perfectly but stopped working and I don't know why..
That's why I asked if you updated OpenVPN.....
Something changed if it was working perfectly...
I mean the openvpn server was always working good. The env variables (time_ascii) was working good too but stopped working, not the openvpn server buddy :)

Re: Disconnect/Connect script date time always the same - bug

Posted: Sat Mar 28, 2020 8:17 pm
by atreyumu
Hi, how did you get the data out?
I have activated the management port but I don't know how to get the data.