-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddvpn-syd
executable file
·118 lines (96 loc) · 2.42 KB
/
ddvpn-syd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
# nicked from http://www.heitorlessa.com/connecting-your-linux-to-a-cisco-anyconnect-ssl-part-2/
# originally an init script, have converted to ask for a user/pass
# It's a bit rough and takes things on faith. Stick it in /usr/local/bin
# also, now needs root
#
# Description: Basic script to connect to a SSL VPN using Openconnect
#
# Info: Created by Heitor Lessa - 22/04/2013
# www.heitorlessa.com
#
# Path variables
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# VPN Variables
#IFACE="sslinterface"
#VPN_USER="your_user"
VPN_HOST="au1.cloud-vpn.net"
VPN_NAME="DimData VPN"
#VPN_PASS="your_pass"
PID="/var/run/openconnect.pid"
TEMP_LOG="/tmp/openconnect_status.log"
PROGNAME="$(basename $0)"
INFO="
Usage: $PROGNAME (start|stop|status|restart)
"
if [[ $EUID -ne 0 ]]; then
echo "'$PROGNAME' needs to be run as root/sudo. Aborting."
exit 1
fi
# Connect to Cisco SSL VPN using passwords from stdin (passed by VPN_PASS variable created prior)
function connect_vpn(){
if [ -f $PID ]
then
printf "\nOpenconnect is already running\n"
exit 1
else
echo -e "$VPN_NAME username: \c"
read -r VPN_USER
echo -e "$VPN_NAME password: \c"
read -r -s VPN_PASS
#echo ${VPN_PASS} | openconnect -b --interface=${IFACE} --user=${VPN_USER} --no-dtls ${VPN_HOST} --passwd-on-stdin > $TEMP_LOG 2>&1
echo ${VPN_PASS} | openconnect -b --user=${VPN_USER} --no-dtls ${VPN_HOST} --passwd-on-stdin > $TEMP_LOG 2>&1
if [ "$?" != 0 ]; then
echo -e "\nOpenconnect failed to start... (wrong user or pass?)"
exit 3
fi
if $(grep -i failed $TEMP_LOG)
then
printf "\nOpenconnect failed to start!\n"
cat $TEMP_LOG
exit 2
else
touch $PID
printf "\nOpenconnect started!\n"
fi
fi
}
# Check if openconnect is running through PID file
function check_openconnect(){
if [ -f $PID ]
then
printf "\nOpenconnect is running!\n"
else
printf "\nOpenconnect is stopped\n"
fi
}
# Confirm if PID file exists, then kill it immediately
function kill_openconnect(){
if [ -f $PID ]
then
echo "Killing Openconnect..."
rm -f $PID >/dev/null 2>&1
kill -9 $(pgrep openconnect) >/dev/null 2>&1
else
printf "\nOpenconnect is not running!\n"
fi
}
case "$1" in
start)
connect_vpn
;;
stop)
kill_openconnect
;;
status)
check_openconnect
;;
restart)
$0 stop
$0 start
;;
*)
echo "$INFO"
exit 0
;;
esac