From fdb474235a8ce7fd0d5cc9fd74e5c880eb2093e6 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 17 Aug 2019 00:02:11 +0200 Subject: openvpn: T1548: add op-mode command for key generation --- op-mode-definitions/openvpn.xml | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 op-mode-definitions/openvpn.xml (limited to 'op-mode-definitions/openvpn.xml') diff --git a/op-mode-definitions/openvpn.xml b/op-mode-definitions/openvpn.xml new file mode 100644 index 000000000..44f8e01e9 --- /dev/null +++ b/op-mode-definitions/openvpn.xml @@ -0,0 +1,48 @@ + + + + + + + OpenVPN key generation tool + + + + + Generate shared-secret key with specified file name + + <filename> + + + + result=1; + key_path=$4 + full_path= + + # Prepend /config/auth if the path is not absolute + if echo $key_path | egrep -ve '^/.*' > /dev/null; then + full_path=/config/auth/$key_path + else + full_path=$key_path + fi + + key_dir=`dirname $full_path` + if [ ! -d $key_dir ]; then + echo "Directory $key_dir does not exist!" + exit 1 + fi + + echo "Generating OpenVPN key to $full_path" + sudo /usr/sbin/openvpn --genkey --secret "$full_path" + result=$? + if [ $result = 0 ]; then + echo "Your new local OpenVPN key has been generated" + fi + /usr/libexec/vyos/validators/file-exists --directory /config/auth "$full_path" + + + + + + + -- cgit v1.2.3 From 1fea0d1cd6232033bde839642446fad162f6f8c8 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 17 Aug 2019 02:07:07 +0200 Subject: openvpn: T1548: add op-mode command for resetting client vyos@vyos:~$ run reset openvpn client client1 --- op-mode-definitions/openvpn.xml | 17 ++++++++++ src/completion/list_openvpn_clients.py | 57 ++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100755 src/completion/list_openvpn_clients.py (limited to 'op-mode-definitions/openvpn.xml') diff --git a/op-mode-definitions/openvpn.xml b/op-mode-definitions/openvpn.xml index 44f8e01e9..9c9c3b3ad 100644 --- a/op-mode-definitions/openvpn.xml +++ b/op-mode-definitions/openvpn.xml @@ -45,4 +45,21 @@ + + + + + + + Reset specified OpenVPN client + + + + + echo kill $4 | socat - UNIX-CONNECT:/tmp/openvpn-mgmt-intf > /dev/null + + + + + 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 . + +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)) + -- cgit v1.2.3 From dbffd657b46fe0edcba67141bf87173448043b70 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 17 Aug 2019 02:15:51 +0200 Subject: openvpn: T1548: add op-mode command for resetting vyos@vyos:~$ reset openvpn interface vtun10 --- op-mode-definitions/openvpn.xml | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'op-mode-definitions/openvpn.xml') diff --git a/op-mode-definitions/openvpn.xml b/op-mode-definitions/openvpn.xml index 9c9c3b3ad..4a7f985e9 100644 --- a/op-mode-definitions/openvpn.xml +++ b/op-mode-definitions/openvpn.xml @@ -58,6 +58,15 @@ echo kill $4 | socat - UNIX-CONNECT:/tmp/openvpn-mgmt-intf > /dev/null + + + Reset OpenVPN process on interface + + + + + sudo kill -SIGUSR1 $(cat /var/run/openvpn/$4.pid) + -- cgit v1.2.3