-
Notifications
You must be signed in to change notification settings - Fork 0
/
juniper-vpn-connect.sh
executable file
·62 lines (51 loc) · 1.89 KB
/
juniper-vpn-connect.sh
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
#!/bin/bash
# Juniper VPN Script based on openconnect
#
# The following packages are required for this to work:
# gksu zenity libssl-dev libxml2-dev vpnc-scripts
#
# As well as a custom build of openconnect:
#
# wget ftp://ftp.infradead.org/pub/openconnect/openconnect-7.06.tar.gz
# tar xzf openconnect-7.06.tar.gz{
# cd openconnect-7.06
# ./configure --with-vpnc-script=/usr/share/vpnc-scripts/vpnc-script
# make
# sudo make install
VPN_URL=
if [[ "${1}" = "start" ]]; then
PID=$(ps aux | grep ${VPN_URL} | grep -v grep | awk '{ print $2 }')
if [[ ! -z "${PID}" ]]; then
zenity --error --title="Juniper VPN" --text="VPN already connected."
exit 1
fi
if [[ ! "$(whoami)" = "root" ]]; then
gksu -D "VPN Connection" -u root "${0} ${1} $(whoami)"
fi
if [[ -z "${2}" ]]; then
exit 0
fi
export LD_LIBRARY_PATH=/usr/local/lib
PROCESS_USERNAME="${2}"
DIALOG_OUTPUT=$(zenity --password --username --title="Juniper VPN" --ok-label=Connect)
DIALOG_OUTPUT=($(echo "${DIALOG_OUTPUT}" | tr '|' '\n'))
LOGIN_USERNAME=${DIALOG_OUTPUT[0]}
LOGIN_PASSWORD=${DIALOG_OUTPUT[1]}
yes | zenity --progress --no-cancel --pulsate --title="Juniper VPN" --width 350 --text="Connecting..." --auto-close &>/dev/null &
PROGRESS_PID=$!
echo ${LOGIN_PASSWORD} | /usr/local/sbin/openconnect --juniper "${VPN_URL}" -U "${PROCESS_USERNAME}" -b -l --timestamp -u "${LOGIN_USERNAME}" --no-cert-check --passwd-on-stdin &>/dev/null
RESULT=$?
kill ${PROGRESS_PID} 2>/dev/null
if [[ ! "${RESULT}" = "0" ]]; then
zenity --error --title="Juniper VPN" --text="Unable to connect. Check syslog for details." &>/dev/null
else
zenity --info --title="Juniper VPN" --text="Connection complete." &>/dev/null
fi
elif [[ "${1}" = "stop" ]]; then
PID=$(ps aux | grep ${VPN_URL} | grep -v grep | awk '{ print $2 }')
if [[ ! -z "${PID}" ]]; then
kill ${PID}
else
zenity --error --title="Juniper VPN" --text="VPN is not running."
fi
fi