-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpn
71 lines (66 loc) · 1.69 KB
/
vpn
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
#!/bin/bash
tf=~/.vpnconfig
if [ ! -e $tf ]; then
touch $tf
fi
pidfile="/tmp/openconnect-pid"
case "$1" in
start)
if ! grep -q username "$tf" || ! grep -q password "$tf" || ! grep -q url "$tf"; then
echo "First run: sudo vpn config"
exit 1
fi
username=$(grep "username :" $tf | awk '{print $3;}')
password=$(grep "password :" $tf | awk '{print $3;}')
url=$(grep "url :" $tf | awk '{print $3;}')
echo "$password" | openconnect -b --pid-file=$pidfile --user=$username $url --servercert sha256:d1988b24b9455378e624d87fc91c1696598b5303b43eb0695a51a33f9c20830f
exit 1
;;
stop)
cat $pidfile | xargs kill -2
exit 1
;;
config)
printf "Which one do you want to config:\n(1)Username and Password\n(2)Server url\n(3)Both\n"
read ti
if (( ti == 1 || ti == 3));
then
if grep -q username "$tf"; then
read -p 'Enter your vpn username: ' username
sed -i "/username/d" $tf
echo username : $username >> $tf
else
read -p 'Enter your vpn username: ' username
echo username : $username >> $tf
fi
if grep -q password "$tf"; then
echo -n 'Enter your vpn password: '
read -s password
echo
sed -i "/password/d" $tf
echo password : $password >> $tf
else
echo -n 'Enter your vpn password: '
read -s password
echo
echo password : $password >> $tf
fi
fi
if (( ti == 2 || ti == 3 ));
then
if grep -q url "$tf"; then
read -p 'Enter your vpn server url: ' url
sed -i "/url/d" $tf
echo url : $url >> $tf
else
read -p 'Enter your vpn url: ' url
echo url : $url >> $tf
fi
fi
exit 1
;;
*)
echo "$0 <start|stop|config>"
exit 1
esac
# Created By AliYazdi75