Skip to content

Commit 4e67534

Browse files
committed
Add support for mojave
1 parent db7d9b1 commit 4e67534

File tree

1 file changed

+84
-1
lines changed

1 file changed

+84
-1
lines changed

lazy-connect

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,81 @@ function _lazy_connect() {
139139
EOF
140140
}
141141

142+
function _lazy_connect_mojave() {
143+
vpn_name=$1
144+
osx_vpn_name="${vpn_name/Connect /}, Not Connected"
145+
146+
_lazy_connect_get_totp $2
147+
local autofill=$3
148+
149+
if [ -z "$password" ]; then
150+
case $TOTP_MODE in
151+
oathtool)
152+
echo "Error: Unable to generate otp using oathtool."
153+
return 1
154+
;;
155+
yubikey)
156+
echo "Error: No YubiKey found."
157+
return 1
158+
;;
159+
esac
160+
elif [ "$autofill" == "false" ]; then
161+
echo -n "$password" | pbcopy
162+
fi
163+
164+
osascript <<EOF
165+
on connectVpn(vpnName, password, autofill)
166+
tell application "System Preferences"
167+
reveal pane "Network"
168+
activate
169+
170+
tell application "System Events"
171+
tell process "System Preferences"
172+
tell window 1
173+
repeat with r in rows of table 1 of scroll area 1
174+
175+
if (value of attribute "AXValue" of static text 1 of r as string) is equal to "$osx_vpn_name" then
176+
select r
177+
end if
178+
end repeat
179+
180+
tell group 1
181+
click button "Authentication Settings…"
182+
end tell
183+
184+
tell sheet 1
185+
set focused of text field 2 to true
186+
set value of text field 2 to "$password"
187+
click button "Ok"
188+
end tell
189+
190+
click button "Apply"
191+
192+
delay 1
193+
tell group 1
194+
click button "Connect"
195+
end tell
196+
197+
end tell
198+
end tell
199+
end tell
200+
201+
quit
202+
end tell
203+
end connectVpn
204+
205+
connectVpn("$osx_vpn_name", "$password", "$autofill")
206+
EOF
207+
}
208+
209+
version_lte() {
210+
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
211+
}
212+
213+
version_lt() {
214+
[ "$1" = "$2" ] && return 1 || version_lte $1 $2
215+
}
216+
142217
function lazy-connect() {
143218
local OPTIND
144219
local autofill="true"
@@ -184,7 +259,15 @@ function lazy-connect() {
184259

185260
vpn_name=$(cat $_lazy_connect_config_dir/vpns |
186261
fzf --height=10 --ansi --reverse --query "$*" --select-1)
187-
[ -z "$vpn_name" ] || _lazy_connect "$vpn_name" "$secret" "$autofill"
262+
263+
mac_version=$(sw_vers -productVersion)
264+
is_less_than_mojave=$(version_lt $mac_version 10.14 && echo "yes" || echo "no")
265+
if [ $is_less_than_mojave = "yes" ]; then
266+
[ -z "$vpn_name" ] || _lazy_connect "$vpn_name" "$secret" "$autofill"
267+
else
268+
[ -z "$vpn_name" ] || _lazy_connect_mojave "$vpn_name" "$secret" "$autofill"
269+
fi
270+
188271
}
189272

190273
lazy-connect "$@"

0 commit comments

Comments
 (0)