summaryrefslogtreecommitdiff
path: root/src/completion/list_openvpn_clients.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-08-17 02:07:07 +0200
committerChristian Poessinger <christian@poessinger.com>2019-08-17 02:07:07 +0200
commit1fea0d1cd6232033bde839642446fad162f6f8c8 (patch)
treeceb3f9cecb00709959bba96d9241d2bfe73bf1cf /src/completion/list_openvpn_clients.py
parent1fd513bb0ada9b892a790c2fd26537a19976a589 (diff)
downloadvyos-1x-1fea0d1cd6232033bde839642446fad162f6f8c8.tar.gz
vyos-1x-1fea0d1cd6232033bde839642446fad162f6f8c8.zip
openvpn: T1548: add op-mode command for resetting client
vyos@vyos:~$ run reset openvpn client client1
Diffstat (limited to 'src/completion/list_openvpn_clients.py')
-rwxr-xr-xsrc/completion/list_openvpn_clients.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/completion/list_openvpn_clients.py b/src/completion/list_openvpn_clients.py
new file mode 100755
index 000000000..828ce6b5e
--- /dev/null
+++ b/src/completion/list_openvpn_clients.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2019 VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+import sys
+import argparse
+
+from vyos.interfaces import list_interfaces_of_type
+
+def get_client_from_interface(interface):
+ clients = []
+ with open('/opt/vyatta/etc/openvpn/status/' + interface + '.status', 'r') as f:
+ dump = False
+ for line in f:
+ if line.startswith("Common Name,"):
+ dump = True
+ continue
+ if line.startswith("ROUTING TABLE"):
+ dump = False
+ continue
+ if dump:
+ # client entry in this file looks like
+ # client1,172.18.202.10:47495,2957,2851,Sat Aug 17 00:07:11 2019
+ # we are only interested in the client name 'client1'
+ clients.append(line.split(',')[0])
+
+ return clients
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-i", "--interface", type=str, help="List connected clients per interface")
+ parser.add_argument("-a", "--all", action='store_true', help="List all connected OpenVPN clients")
+ args = parser.parse_args()
+
+ clients = []
+
+ if args.interface:
+ clients = get_client_from_interface(args.interface)
+ elif args.all:
+ for interface in list_interfaces_of_type("openvpn"):
+ clients += get_client_from_interface(interface)
+
+ print(" ".join(clients))
+