Skip to content

Add flag to toggle autofilling the password #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ sudo ln -s ~/.lazy-connect/lazy-connect /usr/local/bin/lazy-connect
lazy-connect - Shell function to fuzzy search an IPSec VPN by name
and connect to it automatically.

-i - Initialize lazy-connect.
Stores the secret and VPN list to ~/.config/lazy-connect/
-r - refresh vpn list in ~/.config/lazy-connect
-h - Show this help
-i - Initialize lazy-connect. Stores the TOTP secret and VPN list.
-r - Refresh vpn list in ~/.config/lazy-connect .
-n - Do not fill the password automatically. Instead copy the password to clipboard.
-h - Show this help.
```

### YubiKey Support
Expand Down
31 changes: 21 additions & 10 deletions lazy-connect
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ USAGE:
lazy-connect - Shell function to fuzzy search an IPSec VPN by name
and connect to it automatically.

-i - Initialize lazy-connect. Stores the TOTP secret and VPN list
-r - Refresh vpn list in ~/.config/lazy-connect
-h - Show this help
-i - Initialize lazy-connect. Stores the TOTP secret and VPN list.
-r - Refresh vpn list in ~/.config/lazy-connect .
-n - Do not fill the password automatically. Instead copy the password to clipboard.
-h - Show this help.
EOF
}

Expand Down Expand Up @@ -95,6 +96,7 @@ function _lazy_connect_get_totp() {
function _lazy_connect() {
vpn_name=$1
_lazy_connect_get_totp $2
local autofill=$3

if [ -z "$password" ]; then
case $TOTP_MODE in
Expand All @@ -107,19 +109,23 @@ function _lazy_connect() {
return 1
;;
esac
elif [ "$autofill" == "false" ]; then
echo -n "$password" | pbcopy
fi

osascript <<EOF
on connectVpn(vpnName, password)
on connectVpn(vpnName, password, autofill)
tell application "System Events"
tell process "SystemUIServer"
set vpnMenu to (menu bar item 1 of menu bar 1 where description is "VPN")
tell vpnMenu to click
try
click menu item vpnName of menu 1 of vpnMenu
delay 2
keystroke password
keystroke return
if autofill is equal to "true" then
delay 2
keystroke password
keystroke return
end if
on error errorStr
if errorStr does not contain "Can’t get menu item" and errorStr does not contain vpnName then
display dialog errorStr
Expand All @@ -129,15 +135,16 @@ function _lazy_connect() {
end tell
end connectVpn

connectVpn("$vpn_name", "$password")
connectVpn("$vpn_name", "$password", "$autofill")
EOF
}

function lazy-connect() {
local OPTIND
local autofill="true"
mkdir -p $_lazy_connect_config_dir

while getopts "iruh" opt; do
while getopts "irnh" opt; do
case $opt in
h)
_lazy_connect_usage
Expand All @@ -152,6 +159,10 @@ function lazy-connect() {
_lazy_connect_vpn_refresh
return 0
;;
n)
autofill="false"
shift $((OPTIND - 1))
;;
\?)
echo "Invalid Option: -$OPTARG."
_lazy_connect_usage
Expand All @@ -173,7 +184,7 @@ function lazy-connect() {

vpn_name=$(cat $_lazy_connect_config_dir/vpns |
fzf --height=10 --ansi --reverse --query "$*" --select-1)
[ -z "$vpn_name" ] || _lazy_connect "$vpn_name" "$secret"
[ -z "$vpn_name" ] || _lazy_connect "$vpn_name" "$secret" "$autofill"
}

lazy-connect "$@"