-
Notifications
You must be signed in to change notification settings - Fork 65
/
tblick-info.sh
executable file
·46 lines (40 loc) · 1.68 KB
/
tblick-info.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
#!/bin/bash
CONFNAME="$1"
VPERR=""
# Junk below mostly copied from Tunnelblick client.2.up.tunnelblick.sh
TBCONFIG="/Users/$USER/Library/Application Support/Tunnelblick/Configurations/$1.tblk/Contents/Resources/config.ovpn"
if [ ! -f "$TBCONFIG" ]; then
TBCONFIG="/Library/Application Support/Tunnelblick/Shared/$1.tblk/Contents/Resources/config.ovpn"
fi
if [ -f "$TBCONFIG" ]; then
TBALTPREFIX="/Library/Application Support/Tunnelblick/Users/"
TBALTPREFIXLEN="${#TBALTPREFIX}"
TBCONFIGSTART="${TBCONFIG:0:$TBALTPREFIXLEN}"
if [ "$TBCONFIGSTART" = "$TBALTPREFIX" ] ; then
TBBASE="${TBCONFIG:$TBALTPREFIXLEN}"
TBSUFFIX="${TBBASE#*/}"
TBUSERNAME="${TBBASE%%/*}"
TBCONFIG="/Users/$TBUSERNAME/Library/Application Support/Tunnelblick/Configurations/$TBSUFFIX"
fi
CONFIG_PATH_DASHES_SLASHES="$(echo "${TBCONFIG}" | sed -e 's/-/--/g' | sed -e 's/\//-S/g')"
# Determine IP adddress and Tunnel name of most recent connection
LF=$(find "/Library/Application Support/Tunnelblick/Logs/" -type f -iname "${CONFIG_PATH_DASHES_SLASHES}*.openvpn.log")
if [ -f "$LF" ]; then
LINE=$(cat "$LF" | grep -E "ifconfig utun[0-9]+ [0-9]+" | tail -1)
if [ "$LINE" == "" ]; then
VPERR="Config '$CONFNAME' does not appear to have ever connected"
else
IPADDR=$(echo $LINE| cut -d \ -f 5)
TUN=$(echo $LINE| cut -d \ -f 4)
fi
else
VPERR="Config '$CONFNAME' does not have any log"
fi
else
VPERR="Config '$CONFNAME' does not appear to exist in Tunnelblick"
fi
echo "{"
echo " \"err\": \"$VPERR\","
echo " \"ipAddr\": \"$IPADDR\","
echo " \"tunName\": \"$TUN\""
echo "}"