-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjuniper.sh
executable file
·69 lines (61 loc) · 1.79 KB
/
juniper.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
63
64
65
66
67
68
#!/bin/bash
host2connect=dummy
port2connect=0
if [[ $@ =~ "--help" || $# -eq 0 ]]; then
echo -e "run with \njuniper.sh start or \n\
juniper.sh start -u/--username foo or \n\
juniper.sh stop\n\
you can also provide a hostname (with -h/--host) and/or a port (with -p/--port) to connect to. But You probably want to edit the script and set it here"
exit 0
fi
start_stop=$(echo "$1" | tr "A-Z" "a-z")
if [[ $start_stop = "start" || $start_stop = "stop" ]];then
shift
else
echo "start or stop musst be the first parameter"
exit 1
fi
while [[ $# > 1 ]]
do
key="$1"
shift
case $key in
-u|--username)
VPN_USER="$1"
shift
;;
-h|--host)
host2connect="$1"
shift
;;
-p|--port)
port2connect="$1"
shift
;;
*)
;;
esac
done
cd /usr/local/nc
if [[ $start_stop = "stop" ]]; then
./ncsvc -K
else
if [[ $port2connect -eq 0 || $host2connect == "dummy" ]]; then
echo "$host2connect:$port2connect will not work - promised. Start with -h/--host and -p/--port or change script"
exit 1
fi
VPN_USER=${VPN_USER:-$USER}
REALM=$(curl -sL https://$host2connect:$port2connect | sed -rn 's;.*name="realm".*value="(.*)".*;\1;p')
openssl s_client -connect $host2connect":"$port2connect <<<"" 2>&1 | sed -ne '/BEGIN CERTIFICATE/,/END CERTIFICATE/p' | openssl x509 -out ~/cert.der -outform der
stty -echo
read -p "Password: " passwd; echo
stty echo
./ncsvc -L 5 -l 5 -h $host2connect -u $VPN_USER -p $passwd -r $REALM -f ~/cert.der > /dev/null 2>&1 &
sleep 5;
if [[ $(ifconfig tun0 > /dev/null 2>&1 ; echo $?) -eq 0 ]]; then
echo "connected to $host2connect"
else
echo "something went wrong connecting to $host2connect. Check ~/.juniper_networks/network_connect/ncsvc.log"
./ncsvc -K
fi
fi