Added basic checks and the ability to stop the VPN

This commit is contained in:
Benjamyn Love 2018-07-09 12:06:57 +10:00
parent c53b242508
commit 069cbe1732
2 changed files with 27 additions and 4 deletions

View File

@ -0,0 +1,3 @@
Very basic openvpn-client management script.
Note this is bad and I do feel bad.

View File

@ -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