From 069cbe17328632be39b3190a265fc9ae03c0e5b2 Mon Sep 17 00:00:00 2001 From: Benjamyn Love Date: Mon, 9 Jul 2018 12:06:57 +1000 Subject: [PATCH] Added basic checks and the ability to stop the VPN --- README.md | 3 +++ vpnnew.sh | 28 ++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e69de29..9112573 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,3 @@ +Very basic openvpn-client management script. + +Note this is bad and I do feel bad. diff --git a/vpnnew.sh b/vpnnew.sh index 0ba6234..4d09710 100755 --- a/vpnnew.sh +++ b/vpnnew.sh @@ -1,15 +1,35 @@ #!/bin/bash +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root" + exit 1 +fi + tmpfile="/tmp/connectedto" vpnconfpath="/etc/openvpn/client" +function helpertext () { +echo "VPN Manager Help Text" +echo "When connected yo have the following options" +echo "stop - This stopps the VPN connection" +} + function weAreConnected () { if [ -f $tmpfile ] then echo "We are connected to `cat $tmpfile`" - if [[ $1 == "stop" ]] - then +# if [[ $1 == "stop" ]] +# then +# systemctl stop openvpn-client@`cat $tmpfile` +# fi + +case $1 in + "stop") + echo "Stopping VPN Connection" systemctl stop openvpn-client@`cat $tmpfile` - fi + ;; + *) + helpertext +esac fi } @@ -17,7 +37,7 @@ fi ## Check for tunnel device to see if we are connected if [ -d /sys/class/net/tun0 ] then - weAreConnected + weAreConnected $1 else connected=0 fi