Added rest of features
This commit is contained in:
parent
069cbe1732
commit
ed6881f8b6
87
vpnctl
Executable file
87
vpnctl
Executable file
@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
if [[ $EUID -eq 0 ]]; then
|
||||
root=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"
|
||||
echo "info|status - This shows the status of the connection"
|
||||
}
|
||||
|
||||
function weAreConnected () {
|
||||
if [ -f $tmpfile ]
|
||||
then
|
||||
echo "We are connected to `cat $tmpfile`"
|
||||
# if [[ $1 == "stop" ]]
|
||||
# then
|
||||
# systemctl stop openvpn-client@`cat $tmpfile`
|
||||
# fi
|
||||
|
||||
case $1 in
|
||||
"stop")
|
||||
if [[ $root -eq 1 ]]
|
||||
then
|
||||
echo "Stopping VPN Connection"
|
||||
systemctl stop openvpn-client@`cat $tmpfile`
|
||||
echo "Removing connectedto file"
|
||||
rm -f $tmpfile
|
||||
else
|
||||
sudo vpnctl $1
|
||||
fi
|
||||
;;
|
||||
"info")
|
||||
systemctl status openvpn-client@`cat $tmpfile`
|
||||
;;
|
||||
"status")
|
||||
systemctl status openvpn-client@`cat $tmpfile`
|
||||
;;
|
||||
*)
|
||||
helpertext
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function notConnected () {
|
||||
#TODO All funtions here require root so I should move this to a single check
|
||||
case $1 in
|
||||
"list")
|
||||
if [[ $root -eq 1 ]]
|
||||
then
|
||||
ls /etc/openvpn/client
|
||||
else
|
||||
sudo vpnctl $1
|
||||
fi
|
||||
;;
|
||||
"connect")
|
||||
if [[ $root -eq 1 ]]
|
||||
then
|
||||
systemctl start openvpn-client@$2
|
||||
echo $2 > $tmpfile
|
||||
else
|
||||
sudo vpnctl $1 $2
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "use 'vpn connect DESTINATION'"
|
||||
vpnctl list
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
|
||||
}
|
||||
|
||||
## Check for tunnel device to see if we are connected
|
||||
if [ -d /sys/class/net/tun0 ]
|
||||
then
|
||||
weAreConnected $1
|
||||
else
|
||||
notConnected $1 $2
|
||||
fi
|
||||
43
vpnnew.sh
43
vpnnew.sh
@ -1,43 +0,0 @@
|
||||
#!/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
|
||||
# systemctl stop openvpn-client@`cat $tmpfile`
|
||||
# fi
|
||||
|
||||
case $1 in
|
||||
"stop")
|
||||
echo "Stopping VPN Connection"
|
||||
systemctl stop openvpn-client@`cat $tmpfile`
|
||||
;;
|
||||
*)
|
||||
helpertext
|
||||
esac
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
## Check for tunnel device to see if we are connected
|
||||
if [ -d /sys/class/net/tun0 ]
|
||||
then
|
||||
weAreConnected $1
|
||||
else
|
||||
connected=0
|
||||
fi
|
||||
Loading…
x
Reference in New Issue
Block a user