I'm developing a website for managing OpenVPN users with Django framework. But I need to know is there any way to extract active users from OpenVPN? My server is running Ubuntu 12.04.
I'm developing a website for managing OpenVPN users with Django framework. But I need to know is there any way to extract active users from OpenVPN? My server is running Ubuntu 12.04.
There should be a status log you can look at to show you, mine is, for examle:
cat /etc/openvpn/openvpn-status.log
EDIT:
As an alternative, adding the flag
--management IP port [pw-file]
or adding that same directive to yourserver.conf
, for example:management localhost 7505
This would allow you to telnet to that port and offer you a list of commands to run:
telnet localhost 7505
help
To complete @sekrett answer :
It will keep running, it's not a "regular" kill, just a request to print some stats.
Displayed statistics are very readable. Sample output :
I got the same need myself and the easiest solution I found out was to use as mentioned telnet to connect to the management interface(you'll have to add :management localhost 6666, in the server config file) .
To get the exact number of client you can do :
Then you'll get lot of logs :
In my case since I have a very large number of client, using the log file is definitely not very practical.
I manage our companys OpenVPN servers and the way I see active connections is like this,
add to /etc/openvpn/server.conf
restart openvpn server
add an OpenVPN Monitor Python package - this will run via a Gunicorn web server and show active connections,
create a virtual env (not required but good practice with py packages)
install required packages
add a Monitor config file
start the web server that will show active connections,
To stop monitor
to see active connections, go to the public IP of your VPN server
make sure to configure proper firewall for port 80, whitelist only trusted inbound IPs
You can also send usr2 signal to openvpn process to make it write statistic information to syslog. This is safe, you don't need to reboot in case you did not enable management interface before.
Just use sacli with the following command. This will list the connected VPN clients.
To see all the IPs use this option. ./sacli VPNStatus
I made a litte script that can either do a one time check or be set to keep monitoring with specified intervalls.
I hink this is better than monitoring the /etc/openvpn/openvpn-status.log since this is really slow to update. Maybe there's a way to adjust the intervalls in some settings BUT, I only need to monitor the vpn connections sometimes. Not 24/7. Also its quite a messy log.
This script is on the OpenVPN server. Only tested on Ubuntu 20.04
One time run just do:
To keep monitoring with a 20 second intervall:
Save this to .sh file (example oven-activity.sh):
Make sure to change the VPN subnet to match yours.
There is no doubt room for improvements but im not a script genius. I needed it to see when colleagues where using the VPN so that I could see if it was safe to reboot the server. And if so, I could see who was online and call them to ask if it was ok to restart without interrupting their work.
Hey @perfecto25 I followed your steps for hosting the OpenVPN monitor, it is working, but now I am curious about adding one more security layer on top of it.
Is there a way to add user authentication to hosted OpenVPN monitor tool on gunicorn, as it contains vulnerable user information?