-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect-vpn
executable file
·47 lines (37 loc) · 1.51 KB
/
connect-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
#!/bin/bash
cd $(dirname $0)
ANYDIR=$(pwd)
ICODIR=$(echo ${ANYDIR#*/} | tr '/' ':')
VPNUSER=$(test -e auth && head -1 auth)
if [ -z "${VPNUSER}" ]; then
result=$(osascript -e "display dialog \"VPN username:\" with title \"AnyVPN\" with icon file \"${ICODIR}:user.png\" default answer \"\" buttons {\"Cancel\", \"Continue\"} default button \"Continue\"")
if echo $result | grep Continue; then
VPNUSER=$(echo $result | cut -d: -f3)
else
exit
fi
fi
VPNPASS=$(test -e auth && sed -n '2p' auth)
if [ -z "$VPNPASS" ]; then
kbd_history=$(defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleInputSourceHistory | grep Name | head -2 | cut -d= -f2 | sort -r | tr -d ' .";')
xkbswitch-macosx/xkbswitch -s com.apple.keylayout.US
result=$(osascript -e "display dialog \"VPN password:\" with title \"AnyVPN\" with icon file \"${ICODIR}:pass.png\" default answer \"\" buttons {\"Cancel\", \"Continue\"} default button \"Continue\" with hidden answer")
for name in $kbd_history; do xkbswitch-macosx/xkbswitch -s com.apple.keylayout.$name; done
if echo $result | grep Continue; then
VPNPASS=$(echo $result | cut -d: -f3)
else
exit
fi
fi
sudo /opt/homebrew/sbin/openvpn \
--config $ANYDIR/config.ovpn \
--script-security 2 \
--daemon \
--log $ANYDIR/openvpn.log \
--route-up $ANYDIR/up \
--down $ANYDIR/down \
--auth-user-pass \
--management-query-passwords \
--management $ANYDIR/socket unix
echo "username Auth $VPNUSER" | nc -U socket
echo "password Auth $VPNPASS" | nc -U socket