Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    List connected OpenVPN Users like Status / Openvpn from a shell script

    Scheduled Pinned Locked Moved OpenVPN
    3 Posts 3 Posters 2.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mleone87
      last edited by

      Hi,
      I was thinking if there is a way to get the list of connected user to all openvpn servers, like Status / Open page, from a shell script
      (my idea is to integrate this in zabbix)

      Thanks!

      GertjanG 1 Reply Last reply Reply Quote 0
      • D
        D4R4
        last edited by

        This would be very useful. I am also very interested in this as it will allow my organization to monitor connected remote users.

        1 Reply Last reply Reply Quote 0
        • GertjanG
          Gertjan @mleone87
          last edited by Gertjan

          @mleone87 said in List connected OpenVPN Users like Status / Openvpn from a shell script:

          Status / Open page

          You mean the Status / OpenVPN ? Or the OpenVPN widget ?
          The page Status / OpenVPN - which is a PHP script file, contains the answer.
          You will find on line 54 :

          ...
          $clients = openvpn_get_active_clients();
          ....
          

          When you check that function, it's here /etc/inc/openvp,n.php, you will see that the GUI (php) is questioning the openvpn process by connecting to it's socket, and sending command a get a list with all the details.

          Check for yourself :
          Find the socket name of your OpenVPN server instance, it's here /var/etc/openvpn/. There will be a one or more files called serverx.sock where x is the OpenVPN server instance.
          Now, presume you have only one instance, so x is "1"

          telnet -u /var/etc/openvpn/server1.sock
          

          and type the command

          state
          

          On each line you have the details of a connected user. Pipe this rsult through a "wc -l" command to get the number of lines = number of connected users.

          Type quit to exit the connection.

          Use the OpenVPN manual to know how to talk to the OpenVPN process.

          Up to you to script it all out.
          You can use the Status / OpenVPN php file and OpenVPN widget php file as a guide line.

          No "help me" PM's please. Use the forum, the community will thank you.
          Edit : and where are the logs ??

          1 Reply Last reply Reply Quote 1
          • First post
            Last post
          Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.